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

Minimize public surface area of OpenTracingShim #5110

Merged
merged 1 commit into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@

package io.opentelemetry.opentracingshim;

import io.opentelemetry.api.GlobalOpenTelemetry;
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 All @@ -18,66 +17,33 @@ public final class OpenTracingShim {
private OpenTracingShim() {}

/**
* Creates a {@code io.opentracing.Tracer} shim out of {@code
* GlobalOpenTelemetry.getTracerProvider()} and {@code GlobalOpenTelemetry.getPropagators()}.
*
* @return a {@code io.opentracing.Tracer}.
*/
public static io.opentracing.Tracer createTracerShim() {
return createTracerShim(getTracer(GlobalOpenTelemetry.getTracerProvider()));
}

/**
* Creates a {@code io.opentracing.Tracer} shim using provided Tracer instance and {@code
* GlobalOpenTelemetry.getPropagators()}.
*
* @return a {@code io.opentracing.Tracer}.
*/
public static io.opentracing.Tracer createTracerShim(Tracer tracer) {
return createTracerShim(tracer, OpenTracingPropagators.builder().build());
}

/**
* Creates a {@code io.opentracing.Tracer} shim using provided Tracer instance and {@code
* OpenTracingPropagators} instance.
*
* @return a {@code io.opentracing.Tracer}.
* @since 1.1.0
*/
public static io.opentracing.Tracer createTracerShim(
Tracer tracer, OpenTracingPropagators propagators) {
return new TracerShim(tracer, propagators);
}

/**
* Creates a {@code io.opentracing.Tracer} shim using the provided OpenTelemetry instance.
* Creates a {@code io.opentracing.Tracer} shim using the provided {@link OpenTelemetry} instance.
* Uses the {@link TracerProvider} and {@link TextMapPropagator} associated with the {@link
* OpenTelemetry} instance.
*
* @param openTelemetry the {@code OpenTelemetry} instance used to create this shim.
* @return a {@code io.opentracing.Tracer}.
*/
public static io.opentracing.Tracer createTracerShim(OpenTelemetry openTelemetry) {
return createTracerShim(
getTracer(openTelemetry.getTracerProvider()),
OpenTracingPropagators.builder()
.setTextMap(openTelemetry.getPropagators().getTextMapPropagator())
.setHttpHeaders(openTelemetry.getPropagators().getTextMapPropagator())
.build());
TextMapPropagator propagator = openTelemetry.getPropagators().getTextMapPropagator();
return createTracerShim(openTelemetry.getTracerProvider(), propagator, propagator);
}

/**
* 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 propagators the {@code OpenTracingPropagators} instance used to create this shim.
* @param textMapPropagator the propagator used for {@link
* io.opentracing.propagation.Format.Builtin#TEXT_MAP} format.
* @param httpPropagator the propagator used for {@link
* io.opentracing.propagation.Format.Builtin#HTTP_HEADERS} format.
* @return a {@code io.opentracing.Tracer}.
*/
public static io.opentracing.Tracer createTracerShim(
TracerProvider provider, OpenTracingPropagators propagators) {
return createTracerShim(getTracer(provider), propagators);
}

private static Tracer getTracer(TracerProvider tracerProvider) {
return tracerProvider.get("opentracing-shim");
TracerProvider provider,
TextMapPropagator textMapPropagator,
TextMapPropagator httpPropagator) {
return new TracerShim(provider.get("opentracing-shim"), textMapPropagator, httpPropagator);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@ final class Propagation {
private static final TextMapSetter SETTER_INSTANCE = new TextMapSetter();
private static final TextMapGetter GETTER_INSTANCE = new TextMapGetter();

private final OpenTracingPropagators propagators;
private final TextMapPropagator textMapPropagator;
private final TextMapPropagator httpPropagator;

Propagation(OpenTracingPropagators propagators) {
this.propagators = propagators;
}

// Visible for testing
OpenTracingPropagators propagators() {
return propagators;
Propagation(TextMapPropagator textMapPropagator, TextMapPropagator httpPropagator) {
this.textMapPropagator = textMapPropagator;
this.httpPropagator = httpPropagator;
}

<C> void injectTextMap(SpanContextShim contextShim, Format<C> format, TextMapInject carrier) {
Expand Down Expand Up @@ -56,11 +53,12 @@ <C> SpanContextShim extractTextMap(Format<C> format, TextMapExtract carrier) {
return new SpanContextShim(span.getSpanContext(), baggage);
}

private <C> TextMapPropagator getPropagator(Format<C> format) {
// Visible for testing
<C> TextMapPropagator getPropagator(Format<C> format) {
if (format == Format.Builtin.HTTP_HEADERS) {
return propagators.httpHeadersPropagator();
return httpPropagator;
}
return propagators.textMapPropagator();
return textMapPropagator;
}

static final class TextMapSetter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.opentracingshim;

import io.opentelemetry.context.propagation.TextMapPropagator;
import io.opentracing.Scope;
import io.opentracing.ScopeManager;
import io.opentracing.Span;
Expand All @@ -26,9 +27,11 @@ final class TracerShim implements Tracer {
private volatile boolean isClosed;

TracerShim(
io.opentelemetry.api.trace.Tracer tracer, OpenTracingPropagators openTracingPropagators) {
io.opentelemetry.api.trace.Tracer tracer,
TextMapPropagator textMapPropagator,
TextMapPropagator httpPropagator) {
this.tracer = tracer;
this.propagation = new Propagation(openTracingPropagators);
this.propagation = new Propagation(textMapPropagator, httpPropagator);
this.scopeManagerShim = new ScopeManagerShim();
}

Expand Down

This file was deleted.

Loading