Fix scopemanager comaptability for OT 0.33.0
Also add simple regression test.
MODIFY
dd-trace-ot/dd-trace-ot.gradle
dd-trace-ot/dd-trace-ot.gradle
@@ -21,7 +21,8 @@ excludedClassesCoverage += [
apply plugin: 'org.unbroken-dome.test-sets'
testSets {
- compatabilityTest
+ ot31CompatabilityTest
+ ot33CompatabilityTest
traceAgentTest
}
@@ -50,14 +51,34 @@ dependencies {
testCompile group: 'com.github.stefanbirkner', name: 'system-rules', version: '1.17.1'
traceAgentTestCompile deps.testcontainers
+
+ ot31CompatabilityTestCompile group: 'io.opentracing', name: 'opentracing-api', version: '0.31.0'
+ ot31CompatabilityTestCompile group: 'io.opentracing', name: 'opentracing-util', version: '0.31.0'
+ ot31CompatabilityTestCompile group: 'io.opentracing', name: 'opentracing-noop', version: '0.31.0'
+
+ ot33CompatabilityTestCompile group: 'io.opentracing', name: 'opentracing-api', version: '0.33.0'
+ ot33CompatabilityTestCompile group: 'io.opentracing', name: 'opentracing-util', version: '0.33.0'
+ ot33CompatabilityTestCompile group: 'io.opentracing', name: 'opentracing-noop', version: '0.33.0'
}
-[configurations.compatabilityTestCompile, configurations.compatabilityTestRuntime].each {
+[configurations.ot31CompatabilityTestCompile, configurations.ot31CompatabilityTestRuntime].each {
it.resolutionStrategy {
force group: 'io.opentracing', name: 'opentracing-api', version: '0.31.0'
+ force group: 'io.opentracing', name: 'opentracing-util', version: '0.31.0'
+ force group: 'io.opentracing', name: 'opentracing-noop', version: '0.31.0'
+ }
+}
+[configurations.ot33CompatabilityTestCompile, configurations.ot33CompatabilityTestRuntime].each {
+ it.resolutionStrategy {
+ force group: 'io.opentracing', name: 'opentracing-api', version: '0.33.0'
+ force group: 'io.opentracing', name: 'opentracing-util', version: '0.33.0'
+ force group: 'io.opentracing', name: 'opentracing-noop', version: '0.33.0'
}
}
+test.finalizedBy ot31CompatabilityTest
+test.finalizedBy ot33CompatabilityTest
+
jmh {
// include = [".*URLAsResourceNameBenchmark"]
// include = ['some regular expression'] // include pattern (regular expression) for benchmarks to be executed

MODIFY
dd-trace-ot/src/main/java/datadog/opentracing/scopemanager/ContextualScopeManager.java
dd-trace-ot/src/main/java/datadog/opentracing/scopemanager/ContextualScopeManager.java
@@ -11,7 +11,7 @@ import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.CopyOnWriteArrayList;
public class ContextualScopeManager implements ScopeManager {
- static final ThreadLocal<Scope> tlsScope = new ThreadLocal<>();
+ static final ThreadLocal<DDScope> tlsScope = new ThreadLocal<>();
final Deque<ScopeContext> scopeContexts = new ConcurrentLinkedDeque<>();
final List<ScopeListener> scopeListeners = new CopyOnWriteArrayList<>();
@@ -46,7 +46,12 @@ public class ContextualScopeManager implements ScopeManager {
@Override
public Span activeSpan() {
- final Scope active = active();
+ for (final ScopeContext csm : scopeContexts) {
+ if (csm.inContext()) {
+ return csm.activeSpan();
+ }
+ }
+ final DDScope active = tlsScope.get();
return active == null ? null : active.span();
}

MODIFY
dd-trace-ot/src/main/java/datadog/opentracing/scopemanager/ContinuableScope.java
dd-trace-ot/src/main/java/datadog/opentracing/scopemanager/ContinuableScope.java
@@ -5,7 +5,6 @@ import datadog.opentracing.DDSpanContext;
import datadog.opentracing.PendingTrace;
import datadog.trace.context.ScopeListener;
import datadog.trace.context.TraceScope;
-import io.opentracing.Scope;
import java.io.Closeable;
import java.lang.ref.WeakReference;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -13,7 +12,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import lombok.extern.slf4j.Slf4j;
@Slf4j
-public class ContinuableScope implements Scope, TraceScope {
+public class ContinuableScope implements DDScope, TraceScope {
/** ScopeManager holding the thread-local to this scope. */
private final ContextualScopeManager scopeManager;
/**
@@ -25,7 +24,7 @@ public class ContinuableScope implements Scope, TraceScope {
/** Count of open scope and continuations */
private final AtomicInteger openCount;
/** Scope to placed in the thread local after close. May be null. */
- private final Scope toRestore;
+ private final DDScope toRestore;
/** Continuation that created this scope. May be null. */
private final Continuation continuation;
/** Flag to propagate this scope across async boundaries. */

ADD
dd-trace-ot/src/main/java/datadog/opentracing/scopemanager/DDScope.java
+package datadog.opentracing.scopemanager;
+
+import io.opentracing.Scope;
+import io.opentracing.Span;
+
+// Intentionally package private.
+interface DDScope extends Scope {
+ @Override
+ Span span();
+}

MODIFY
dd-trace-ot/src/main/java/datadog/opentracing/scopemanager/SimpleScope.java
dd-trace-ot/src/main/java/datadog/opentracing/scopemanager/SimpleScope.java
package datadog.opentracing.scopemanager;
import datadog.trace.context.ScopeListener;
-import io.opentracing.Scope;
import io.opentracing.Span;
/** Simple scope implementation which does not propagate across threads. */
-public class SimpleScope implements Scope {
+public class SimpleScope implements DDScope {
private final ContextualScopeManager scopeManager;
private final Span spanUnderScope;
private final boolean finishOnClose;
- private final Scope toRestore;
+ private final DDScope toRestore;
public SimpleScope(
final ContextualScopeManager scopeManager,

RENAME
dd-trace-ot/src/compatabilityTest/groovy/OT31ApiTest.groovy
dd-trace-ot/src/ot31CompatabilityTest/groovy/OT31ApiTest.groovy
ADD
dd-trace-ot/src/ot33CompatabilityTest/groovy/OT33ApiTest.groovy
+import datadog.opentracing.DDSpan
+import datadog.opentracing.DDTracer
+import datadog.trace.common.writer.ListWriter
+import datadog.trace.util.test.DDSpecification
+import io.opentracing.Tracer
+import spock.lang.Subject
+
+import static datadog.trace.agent.test.asserts.ListWriterAssert.assertTraces
+import static datadog.trace.agent.test.utils.TraceUtils.basicSpan
+
+// This test focuses on things that are different between OpenTracing API 0.32.0 and 0.33.0
+class OT33ApiTest extends DDSpecification {
+ static final WRITER = new ListWriter()
+
+ @Subject
+ Tracer tracer = new DDTracer(WRITER)
+
+ def "test start"() {
+ when:
+ def span = tracer.buildSpan("some name").start()
+ def scope = tracer.activateSpan(span)
+ scope.close()
+
+ then:
+ (scope.span() as DDSpan).isFinished() == false
+ assertTraces(WRITER, 0) {}
+
+ when:
+ span.finish()
+
+ then:
+ assertTraces(WRITER, 1) {
+ trace(0, 1) {
+ basicSpan(it, 0, "some name")
+ }
+ }
+ }
+
+ def "test scopemanager"() {
+ setup:
+ def span = tracer.buildSpan("some name").start()
+
+ when:
+ tracer.scopeManager().activate(span) != null
+
+ then:
+ tracer.activeSpan() == span
+ }
+}

Fix scopemanager comaptability for OT 0.33.0

Also add simple regression test.