Remove deprecated BaseTracer#extractWithGlobalPropagators() methods
MODIFY
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/BaseTracer.java
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/BaseTracer.java
@@ -56,8 +56,7 @@ public abstract class BaseTracer {
protected final ContextPropagators propagators;
public BaseTracer() {
- tracer = GlobalOpenTelemetry.getTracer(getInstrumentationName(), getVersion());
- propagators = GlobalOpenTelemetry.getPropagators();
+ this(GlobalOpenTelemetry.get());
}
/**
@@ -229,25 +228,10 @@ public abstract class BaseTracer {
span.recordException(throwable);
}
- /**
- * Do extraction with the propagators from the GlobalOpenTelemetry instance. Not recommended.
- *
- * @deprecated We should eliminate all static usages so we can use the non-global propagators.
- */
- @Deprecated
- public static <C> Context extractWithGlobalPropagators(C carrier, TextMapGetter<C> getter) {
- return extract(GlobalOpenTelemetry.getPropagators(), carrier, getter);
- }
-
public <C> Context extract(C carrier, TextMapGetter<C> getter) {
- return extract(propagators, carrier, getter);
- }
-
- private static <C> Context extract(
- ContextPropagators propagators, C carrier, TextMapGetter<C> getter) {
ContextPropagationDebug.debugContextLeakIfEnabled();
- // Using Context.ROOT here may be quite unexpected, but the reason is simple.
+ // Using Context.root() here may be quite unexpected, but the reason is simple.
// We want either span context extracted from the carrier or invalid one.
// We DO NOT want any span context potentially lingering in the current context.
return propagators.getTextMapPropagator().extract(Context.root(), carrier, getter);

MODIFY
instrumentation/rmi/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rmi/context/ContextPayload.java
instrumentation/rmi/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rmi/context/ContextPayload.java
package io.opentelemetry.javaagent.instrumentation.rmi.context;
import io.opentelemetry.api.GlobalOpenTelemetry;
-import io.opentelemetry.api.trace.Span;
-import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.propagation.TextMapGetter;
import io.opentelemetry.context.propagation.TextMapSetter;
@@ -24,13 +22,6 @@ public class ContextPayload {
private static final Logger log = LoggerFactory.getLogger(ContextPayload.class);
- private static final Tracer TRACER =
- GlobalOpenTelemetry.getTracer("io.opentelemetry.javaagent.rmi");
-
- public static Tracer tracer() {
- return TRACER;
- }
-
private final Map<String, String> context;
public static final ExtractAdapter GETTER = new ExtractAdapter();
public static final InjectAdapter SETTER = new InjectAdapter();
@@ -43,9 +34,8 @@ public class ContextPayload {
this.context = context;
}
- public static ContextPayload from(Span span) {
+ public static ContextPayload from(Context context) {
ContextPayload payload = new ContextPayload();
- Context context = Context.current().with(span);
GlobalOpenTelemetry.getPropagators().getTextMapPropagator().inject(context, payload, SETTER);
return payload;
}

MODIFY
instrumentation/rmi/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rmi/context/ContextPropagator.java
instrumentation/rmi/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rmi/context/ContextPropagator.java
package io.opentelemetry.javaagent.instrumentation.rmi.context;
-import io.opentelemetry.api.trace.Span;
+import io.opentelemetry.context.Context;
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
import java.io.IOException;
import java.io.ObjectOutput;
@@ -48,9 +48,9 @@ public class ContextPropagator {
}
public void attemptToPropagateContext(
- ContextStore<Connection, Boolean> knownConnections, Connection c, Span span) {
+ ContextStore<Connection, Boolean> knownConnections, Connection c, Context context) {
if (checkIfContextCanBePassed(knownConnections, c)) {
- if (!syntheticCall(c, ContextPayload.from(span), CONTEXT_PAYLOAD_OPERATION_ID)) {
+ if (!syntheticCall(c, ContextPayload.from(context), CONTEXT_PAYLOAD_OPERATION_ID)) {
log.debug("Couldn't send context payload");
}
}

MODIFY
instrumentation/rmi/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rmi/context/client/RmiClientContextInstrumentation.java
instrumentation/rmi/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rmi/context/client/RmiClientContextInstrumentation.java
@@ -13,6 +13,7 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import io.opentelemetry.api.trace.Span;
+import io.opentelemetry.context.Context;
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge;
@@ -71,7 +72,8 @@ public class RmiClientContextInstrumentation implements TypeInstrumentation {
if (PROPAGATOR.isRmiInternalObject(id)) {
return;
}
- Span activeSpan = Java8BytecodeBridge.currentSpan();
+ Context currentContext = Java8BytecodeBridge.currentContext();
+ Span activeSpan = Java8BytecodeBridge.spanFromContext(currentContext);
if (!activeSpan.getSpanContext().isValid()) {
return;
}
@@ -79,7 +81,7 @@ public class RmiClientContextInstrumentation implements TypeInstrumentation {
ContextStore<Connection, Boolean> knownConnections =
InstrumentationContext.get(Connection.class, Boolean.class);
- PROPAGATOR.attemptToPropagateContext(knownConnections, c, activeSpan);
+ PROPAGATOR.attemptToPropagateContext(knownConnections, c, currentContext);
}
}
}

MODIFY
instrumentation/rmi/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rmi/context/server/ContextDispatcher.java
instrumentation/rmi/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rmi/context/server/ContextDispatcher.java
package io.opentelemetry.javaagent.instrumentation.rmi.context.server;
-import static io.opentelemetry.instrumentation.api.tracer.BaseTracer.extractWithGlobalPropagators;
import static io.opentelemetry.javaagent.instrumentation.api.rmi.ThreadLocalContext.THREAD_LOCAL_CONTEXT;
import static io.opentelemetry.javaagent.instrumentation.rmi.context.ContextPayload.GETTER;
import static io.opentelemetry.javaagent.instrumentation.rmi.context.ContextPropagator.CONTEXT_CALL_ID;
import static io.opentelemetry.javaagent.instrumentation.rmi.context.ContextPropagator.PROPAGATOR;
+import static io.opentelemetry.javaagent.instrumentation.rmi.server.RmiServerTracer.tracer;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanContext;
@@ -50,7 +50,7 @@ public class ContextDispatcher implements Dispatcher {
if (PROPAGATOR.isOperationWithPayload(operationId)) {
ContextPayload payload = ContextPayload.read(in);
if (payload != null) {
- Context context = extractWithGlobalPropagators(payload, GETTER);
+ Context context = tracer().extract(payload, GETTER);
SpanContext spanContext = Span.fromContext(context).getSpanContext();
if (spanContext.isValid()) {
THREAD_LOCAL_CONTEXT.set(context);

Remove deprecated BaseTracer#extractWithGlobalPropagators() methods (#2452)