-
Notifications
You must be signed in to change notification settings - Fork 858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make extended tracer easier to use #6943
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1dd60fa
make extended tracer easier to use
zeitlinger 7548c2d
make extended tracer easier to use
zeitlinger d37d633
add usage test
zeitlinger f4b6c41
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
jack-berg 036fe9f
Add additional unit test
jack-berg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
sdk/trace/src/testIncubating/java/io/opentelemetry/sdk/trace/ExtendedTracerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.sdk.trace; | ||
|
||
import static io.opentelemetry.sdk.internal.ScopeConfiguratorBuilder.nameEquals; | ||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; | ||
import static io.opentelemetry.sdk.trace.internal.TracerConfig.disabled; | ||
|
||
import io.opentelemetry.api.incubator.trace.ExtendedSpanBuilder; | ||
import io.opentelemetry.api.incubator.trace.ExtendedTracer; | ||
import io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter; | ||
import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Stream; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
class ExtendedTracerTest { | ||
|
||
/** | ||
* {@link ExtendedTracer#spanBuilder(String)} delegates to {@link SdkTracer#spanBuilder(String)} | ||
* and casts the result to {@link ExtendedSpanBuilder}. Therefore, we need to confirm that {@link | ||
* SdkTracer#spanBuilder(String)} correctly returns {@link ExtendedSpanBuilder} and not {@link | ||
* io.opentelemetry.api.trace.SpanBuilder} in all cases, else the user will get {@link | ||
* ClassCastException}. | ||
*/ | ||
@ParameterizedTest | ||
@MethodSource("spanBuilderArgs") | ||
void spanBuilder(Supplier<ExtendedSpanBuilder> spanBuilderSupplier) { | ||
ExtendedSpanBuilder spanBuilder = spanBuilderSupplier.get(); | ||
assertThat(spanBuilder).isInstanceOf(ExtendedSpanBuilder.class); | ||
} | ||
|
||
private static Stream<Arguments> spanBuilderArgs() { | ||
SdkTracerProvider tracerProvider = | ||
SdkTracerProvider.builder() | ||
.addSpanProcessor(SimpleSpanProcessor.create(InMemorySpanExporter.create())) | ||
.addTracerConfiguratorCondition(nameEquals("tracerB"), disabled()) | ||
.build(); | ||
|
||
ExtendedTracer tracerA = (ExtendedTracer) tracerProvider.get("tracerA"); | ||
ExtendedTracer tracerB = (ExtendedTracer) tracerProvider.get("tracerB"); | ||
|
||
SdkTracerProvider tracerProvider2 = | ||
SdkTracerProvider.builder() | ||
.addSpanProcessor(SimpleSpanProcessor.create(InMemorySpanExporter.create())) | ||
.build(); | ||
ExtendedTracer tracerC = (ExtendedTracer) tracerProvider.get("tracerC"); | ||
tracerProvider2.shutdown(); | ||
|
||
return Stream.of( | ||
// Simple case | ||
Arguments.of(spanBuilderSupplier(() -> tracerA.spanBuilder("span"))), | ||
// Disabled tracer | ||
Arguments.of(spanBuilderSupplier(() -> tracerB.spanBuilder("span"))), | ||
// Invalid span name | ||
Arguments.of(spanBuilderSupplier(() -> tracerB.spanBuilder(null))), | ||
Arguments.of(spanBuilderSupplier(() -> tracerB.spanBuilder(" "))), | ||
// Shutdown tracer provider | ||
Arguments.of(spanBuilderSupplier(() -> tracerC.spanBuilder("span")))); | ||
} | ||
|
||
private static Supplier<ExtendedSpanBuilder> spanBuilderSupplier( | ||
Supplier<ExtendedSpanBuilder> spanBuilderSupplier) { | ||
return spanBuilderSupplier; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merged main, and added some additional tests to confirm this.