Rename TracerBridge and Provider
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 datadog.trace.context.TracerBridge;
-import io.opentracing.util.GlobalTracer;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class TracerInstaller {
/** Register a global tracer if no global tracer is already registered. */
public static synchronized void installGlobalTracer() {
- if (!GlobalTracer.isRegistered()) {
+ if (!io.opentracing.util.GlobalTracer.isRegistered()) {
final DDTracer tracer = new DDTracer();
try {
- GlobalTracer.register(tracer);
- TracerBridge.registerIfAbsent(tracer);
+ io.opentracing.util.GlobalTracer.register(tracer);
+ datadog.trace.api.GlobalTracer.registerIfAbsent(tracer);
} catch (final RuntimeException re) {
log.warn("Failed to register tracer '" + tracer + "'", re);
}
@@ -24,7 +22,10 @@ public class TracerInstaller {
public static void logVersionInfo() {
VersionLogger.logAllVersions();
- log.debug(GlobalTracer.class.getName() + " loaded on " + GlobalTracer.class.getClassLoader());
+ log.debug(
+ io.opentracing.util.GlobalTracer.class.getName()
+ + " loaded on "
+ + io.opentracing.util.GlobalTracer.class.getClassLoader());
log.debug(
AgentInstaller.class.getName() + " loaded on " + AgentInstaller.class.getClassLoader());
}

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
@@ -7,9 +7,9 @@ import datadog.opentracing.DDSpan;
import datadog.opentracing.DDTracer;
import datadog.trace.agent.tooling.AgentInstaller;
import datadog.trace.agent.tooling.Instrumenter;
+import datadog.trace.api.GlobalTracer;
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;
@@ -85,7 +85,7 @@ public abstract class AgentTestRunner extends Specification {
};
TEST_TRACER = new DDTracer(TEST_WRITER);
TestUtils.registerOrReplaceGlobalTracer((Tracer) TEST_TRACER);
- TracerBridge.registerIfAbsent((DDTracer) TEST_TRACER);
+ GlobalTracer.registerIfAbsent((DDTracer) TEST_TRACER);
}
protected static Tracer getTestTracer() {

MODIFY
dd-trace-api/src/main/java/datadog/trace/api/CorrelationIdentifier.java
dd-trace-api/src/main/java/datadog/trace/api/CorrelationIdentifier.java
package datadog.trace.api;
-import datadog.trace.context.TracerBridge;
-
/**
* Utility class to access the active trace and span ids.
*
@@ -9,29 +7,10 @@ import datadog.trace.context.TracerBridge;
*/
public class CorrelationIdentifier {
public static String getTraceId() {
- return TracerBridge.get().getTraceId();
+ return GlobalTracer.get().getTraceId();
}
public static String getSpanId() {
- return TracerBridge.get().getSpanId();
- }
-
- public interface Provider {
- String getTraceId();
-
- String getSpanId();
-
- Provider NO_OP =
- new Provider() {
- @Override
- public String getTraceId() {
- return "0";
- }
-
- @Override
- public String getSpanId() {
- return "0";
- }
- };
+ return GlobalTracer.get().getSpanId();
}
}

ADD
dd-trace-api/src/main/java/datadog/trace/api/GlobalTracer.java
+package datadog.trace.api;
+
+import datadog.trace.api.interceptor.TraceInterceptor;
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * A global reference to the registered Datadog tracer.
+ *
+ * <p>OpenTracing's GlobalTracer cannot be cast to its DDTracer implementation, so this class exists
+ * to provide a global window to datadog-specific features.
+ */
+public class GlobalTracer {
+ private static final Tracer NO_OP =
+ new Tracer() {
+ @Override
+ public String getTraceId() {
+ return "0";
+ }
+
+ @Override
+ public String getSpanId() {
+ return "0";
+ }
+
+ @Override
+ public boolean addTraceInterceptor(TraceInterceptor traceInterceptor) {
+ return false;
+ }
+ };
+ private static final AtomicReference<Tracer> provider = new AtomicReference<>(NO_OP);
+
+ public static void registerIfAbsent(Tracer p) {
+ if (p != null && p != NO_OP) {
+ provider.compareAndSet(NO_OP, p);
+ }
+ }
+
+ public static Tracer get() {
+ return provider.get();
+ }
+}

ADD
dd-trace-api/src/main/java/datadog/trace/api/Tracer.java
+package datadog.trace.api;
+
+import datadog.trace.api.interceptor.TraceInterceptor;
+
+/** A class with Datadog tracer features. */
+public interface Tracer {
+
+ /** Get the trace id of the active trace. Returns 0 if there is no active trace. */
+ String getTraceId();
+
+ /**
+ * Get the span id of the active span of the active trace. Returns 0 if there is no active trace.
+ */
+ String getSpanId();
+
+ /**
+ * Add a new interceptor to the tracer. Interceptors with duplicate priority to existing ones are
+ * ignored.
+ *
+ * @param traceInterceptor
+ * @return false if an interceptor with same priority exists.
+ */
+ boolean addTraceInterceptor(TraceInterceptor traceInterceptor);
+}

DELETE
dd-trace-api/src/main/java/datadog/trace/context/TracerBridge.java
-package datadog.trace.context;
-
-import datadog.trace.api.interceptor.TraceInterceptor;
-import java.util.concurrent.atomic.AtomicReference;
-
-/** A global reference to the registered Datadog tracer. */
-public class TracerBridge {
- private static final AtomicReference<Provider> provider = new AtomicReference<>(Provider.NO_OP);
-
- public static void registerIfAbsent(Provider p) {
- if (p != null && p != Provider.NO_OP) {
- provider.compareAndSet(Provider.NO_OP, p);
- }
- }
-
- public static Provider get() {
- return provider.get();
- }
-
- /**
- * Add a new interceptor to the tracer. Interceptors with duplicate priority to existing ones are
- * ignored.
- *
- * @param traceInterceptor
- * @return false if an interceptor with same priority exists.
- */
- public static boolean addTraceInterceptor(TraceInterceptor traceInterceptor) {
- return get().addTraceInterceptor(traceInterceptor);
- }
-
- public interface Provider {
- String getTraceId();
-
- String getSpanId();
-
- /**
- * Add a new interceptor to the tracer. Interceptors with duplicate priority to existing ones
- * are ignored.
- *
- * @param traceInterceptor
- * @return false if an interceptor with same priority exists.
- */
- boolean addTraceInterceptor(TraceInterceptor traceInterceptor);
-
- Provider NO_OP =
- new Provider() {
- @Override
- public String getTraceId() {
- return "0";
- }
-
- @Override
- public String getSpanId() {
- return "0";
- }
-
- @Override
- public boolean addTraceInterceptor(TraceInterceptor traceInterceptor) {
- return false;
- }
- };
- }
-}

MODIFY
dd-trace-ot/src/main/java/datadog/opentracing/DDTracer.java
dd-trace-ot/src/main/java/datadog/opentracing/DDTracer.java
@@ -23,7 +23,6 @@ import datadog.trace.common.sampling.Sampler;
import datadog.trace.common.writer.DDAgentWriter;
import datadog.trace.common.writer.DDApi;
import datadog.trace.common.writer.Writer;
-import datadog.trace.context.TracerBridge;
import io.opentracing.Scope;
import io.opentracing.ScopeManager;
import io.opentracing.Span;
@@ -49,7 +48,7 @@ import lombok.extern.slf4j.Slf4j;
/** DDTracer makes it easy to send traces and span to DD using the OpenTracing API. */
@Slf4j
-public class DDTracer implements io.opentracing.Tracer, Closeable, TracerBridge.Provider {
+public class DDTracer implements io.opentracing.Tracer, Closeable, datadog.trace.api.Tracer {
public static final String UNASSIGNED_DEFAULT_SERVICE_NAME = "unnamed-java-app";

MODIFY
dd-trace-ot/src/test/groovy/datadog/opentracing/TraceInterceptorTest.groovy
dd-trace-ot/src/test/groovy/datadog/opentracing/TraceInterceptorTest.groovy
@@ -3,7 +3,7 @@ package datadog.opentracing
import datadog.trace.api.interceptor.MutableSpan
import datadog.trace.api.interceptor.TraceInterceptor
import datadog.trace.common.writer.ListWriter
-import datadog.trace.context.TracerBridge
+import datadog.trace.api.GlobalTracer
import spock.lang.Specification
import java.util.concurrent.atomic.AtomicBoolean
@@ -147,7 +147,7 @@ class TraceInterceptorTest extends Specification {
def "register interceptor through bridge" () {
setup:
- TracerBridge.registerIfAbsent(tracer)
+ GlobalTracer.registerIfAbsent(tracer)
def interceptor = new TraceInterceptor() {
@Override
Collection<? extends MutableSpan> onTraceComplete(Collection<? extends MutableSpan> trace) {
@@ -161,7 +161,7 @@ class TraceInterceptorTest extends Specification {
}
expect:
- TracerBridge.addTraceInterceptor(interceptor)
+ GlobalTracer.get().addTraceInterceptor(interceptor)
tracer.interceptors.contains(interceptor)
}
}

Rename TracerBridge and Provider