Skip to content
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

add missing createTracerShim function #4988

Merged
merged 3 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.api.trace.TracerProvider;
import io.opentelemetry.context.propagation.TextMapPropagator;

/**
* Factory for creating an OpenTracing {@link io.opentracing.Tracer} that is implemented using the
Expand Down Expand Up @@ -64,6 +65,21 @@ public static io.opentracing.Tracer createTracerShim(OpenTelemetry openTelemetry
.build());
}

/**
* Creates a {@code io.opentracing.Tracer} shim using the provided {@code TracerProvider} and
* {@code TextMapPropagator} instance.
*
* @param provider the {@code TracerProvider} instance used to create this shim.
* @param propagator the {@code TextMapPropagator} instance used to create this shim.
* @return a {@code io.opentracing.Tracer}.
*/
public static io.opentracing.Tracer createTracerShim(
TracerProvider provider, TextMapPropagator propagator) {
return createTracerShim(
getTracer(provider),
OpenTracingPropagators.builder().setTextMap(propagator).setHttpHeaders(propagator).build());
}

private static Tracer getTracer(TracerProvider tracerProvider) {
return tracerProvider.get("opentracing-shim");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,15 @@ void createTracerShim_withPropagators() {
assertThat(tracerShim.propagators().textMapPropagator()).isSameAs(textMapPropagator);
assertThat(tracerShim.propagators().httpHeadersPropagator()).isSameAs(httpHeadersPropagator);
}

@Test
void createTracerShim_withTraceProviderAndPropagator() {
TextMapPropagator textMapPropagator = new CustomTextMapPropagator();
SdkTracerProvider sdk = SdkTracerProvider.builder().build();
TracerShim tracerShim = (TracerShim) OpenTracingShim.createTracerShim(sdk, textMapPropagator);

assertThat(tracerShim.propagators().httpHeadersPropagator()).isSameAs(textMapPropagator);
assertThat(tracerShim.propagators().textMapPropagator()).isSameAs(textMapPropagator);
assertThat(tracerShim.tracer()).isSameAs(sdk.get("opentracing-shim"));
}
}