Register TracerBridge in TracerInstaller instead of DDTracer init
MODIFY
dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/TracerInstaller.java
dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/TracerInstaller.java
package datadog.trace.agent.tooling;
import datadog.opentracing.DDTracer;
-import io.opentracing.Tracer;
+import datadog.trace.context.TracerBridge;
import io.opentracing.util.GlobalTracer;
import lombok.extern.slf4j.Slf4j;
@@ -10,11 +10,12 @@ public class TracerInstaller {
/** Register a global tracer if no global tracer is already registered. */
public static synchronized void installGlobalTracer() {
if (!GlobalTracer.isRegistered()) {
- final Tracer resolved = new DDTracer();
+ final DDTracer tracer = new DDTracer();
try {
- GlobalTracer.register(resolved);
+ GlobalTracer.register(tracer);
+ TracerBridge.registerIfAbsent(tracer);
} catch (final RuntimeException re) {
- log.warn("Failed to register tracer '" + resolved + "'", re);
+ log.warn("Failed to register tracer '" + tracer + "'", re);
}
} else {
log.debug("GlobalTracer already registered.");

MODIFY
dd-java-agent/testing/src/main/java/datadog/trace/agent/test/AgentTestRunner.java
dd-java-agent/testing/src/main/java/datadog/trace/agent/test/AgentTestRunner.java
@@ -9,6 +9,7 @@ import datadog.trace.agent.tooling.AgentInstaller;
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.common.writer.ListWriter;
import datadog.trace.common.writer.Writer;
+import datadog.trace.context.TracerBridge;
import io.opentracing.Tracer;
import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.Instrumentation;
@@ -84,6 +85,7 @@ public abstract class AgentTestRunner extends Specification {
};
TEST_TRACER = new DDTracer(TEST_WRITER);
TestUtils.registerOrReplaceGlobalTracer((Tracer) TEST_TRACER);
+ TracerBridge.registerIfAbsent((DDTracer) TEST_TRACER);
}
protected static Tracer getTestTracer() {

MODIFY
dd-trace-ot/src/main/java/datadog/opentracing/DDTracer.java
dd-trace-ot/src/main/java/datadog/opentracing/DDTracer.java
@@ -162,8 +162,6 @@ public class DDTracer implements io.opentracing.Tracer, Closeable, TracerBridge.
addDecorator(decorator);
}
- TracerBridge.registerIfAbsent(this);
-
log.info("New instance: {}", this);
}

MODIFY
dd-trace-ot/src/test/groovy/datadog/opentracing/TraceInterceptorTest.groovy
dd-trace-ot/src/test/groovy/datadog/opentracing/TraceInterceptorTest.groovy
@@ -147,6 +147,7 @@ class TraceInterceptorTest extends Specification {
def "register interceptor through bridge" () {
setup:
+ TracerBridge.registerIfAbsent(tracer)
def interceptor = new TraceInterceptor() {
@Override
Collection<? extends MutableSpan> onTraceComplete(Collection<? extends MutableSpan> trace) {
@@ -161,5 +162,6 @@ class TraceInterceptorTest extends Specification {
expect:
TracerBridge.addTraceInterceptor(interceptor)
+ tracer.interceptors.contains(interceptor)
}
}

Register TracerBridge in TracerInstaller instead of DDTracer init