Add OpenTelemetry parameter constructors to all api Tracer classes
MODIFY
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/DatabaseClientTracer.java
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/DatabaseClientTracer.java
@@ -7,10 +7,9 @@ package io.opentelemetry.instrumentation.api.tracer;
import static io.opentelemetry.api.trace.SpanKind.CLIENT;
-import io.opentelemetry.api.GlobalOpenTelemetry;
+import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.StatusCode;
-import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.tracer.utils.NetPeerUtils;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
@@ -21,10 +20,10 @@ public abstract class DatabaseClientTracer<CONNECTION, QUERY> extends BaseTracer
protected static final String DB_QUERY = "DB Query";
- protected final Tracer tracer;
+ public DatabaseClientTracer() {}
- public DatabaseClientTracer() {
- tracer = GlobalOpenTelemetry.getTracer(getInstrumentationName(), getVersion());
+ public DatabaseClientTracer(OpenTelemetry openTelemetry) {
+ super(openTelemetry);
}
public boolean shouldStartSpan(Context parentContext) {

MODIFY
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/RpcClientTracer.java
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/RpcClientTracer.java
package io.opentelemetry.instrumentation.api.tracer;
+import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.trace.Tracer;
public abstract class RpcClientTracer extends BaseTracer {
protected RpcClientTracer() {}
+ /**
+ * Prefer to pass in an OpenTelemetry instance, rather than just a Tracer, so you don't have to
+ * use the GlobalOpenTelemetry Propagator instance.
+ *
+ * @deprecated prefer to pass in an OpenTelemetry instance, instead.
+ */
+ @Deprecated
protected RpcClientTracer(Tracer tracer) {
super(tracer);
}
+ protected RpcClientTracer(OpenTelemetry openTelemetry) {
+ super(openTelemetry);
+ }
+
protected abstract String getRpcSystem();
}

MODIFY
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/RpcServerTracer.java
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/RpcServerTracer.java
package io.opentelemetry.instrumentation.api.tracer;
+import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.propagation.TextMapPropagator;
@@ -12,9 +13,20 @@ public abstract class RpcServerTracer<REQUEST> extends BaseTracer {
protected RpcServerTracer() {}
+ /**
+ * Prefer to pass in an OpenTelemetry instance, rather than just a Tracer, so you don't have to
+ * use the GlobalOpenTelemetry Propagator instance.
+ *
+ * @deprecated prefer to pass in an OpenTelemetry instance, instead.
+ */
+ @Deprecated
protected RpcServerTracer(Tracer tracer) {
super(tracer);
}
+ protected RpcServerTracer(OpenTelemetry openTelemetry) {
+ super(openTelemetry);
+ }
+
protected abstract TextMapPropagator.Getter<REQUEST> getGetter();
}

Add OpenTelemetry parameter constructors to all api Tracer classes (#2233)