Remove test dependency on GlobalTracer
MODIFY
dd-java-agent/instrumentation/hibernate/core-3.3/src/test/groovy/SessionTest.groovy
dd-java-agent/instrumentation/hibernate/core-3.3/src/test/groovy/SessionTest.groovy
import datadog.trace.api.DDSpanTypes
-import io.opentracing.Scope
-import io.opentracing.Tracer
+import datadog.trace.instrumentation.api.AgentScope
import io.opentracing.tag.Tags
-import io.opentracing.util.GlobalTracer
import org.hibernate.*
import spock.lang.Shared
+import static datadog.trace.instrumentation.api.AgentTracer.activateSpan
+import static datadog.trace.instrumentation.api.AgentTracer.startSpan
+
class SessionTest extends AbstractHibernateTest {
@Shared
@@ -484,9 +485,7 @@ class SessionTest extends AbstractHibernateTest {
def "test hibernate overlapping Sessions"() {
setup:
- Tracer tracer = GlobalTracer.get()
-
- Scope scope = tracer.buildSpan("overlapping Sessions").startActive(true)
+ AgentScope scope = activateSpan(startSpan("overlapping Sessions"), true)
def session1 = sessionFactory.openSession()
session1.beginTransaction()

MODIFY
dd-java-agent/instrumentation/hibernate/core-4.0/src/test/groovy/SessionTest.groovy
dd-java-agent/instrumentation/hibernate/core-4.0/src/test/groovy/SessionTest.groovy
import datadog.trace.api.DDSpanTypes
-import io.opentracing.Scope
-import io.opentracing.Tracer
+import datadog.trace.instrumentation.api.AgentScope
import io.opentracing.tag.Tags
-import io.opentracing.util.GlobalTracer
import org.hibernate.*
import spock.lang.Shared
+import static datadog.trace.instrumentation.api.AgentTracer.activateSpan
+import static datadog.trace.instrumentation.api.AgentTracer.startSpan
+
class SessionTest extends AbstractHibernateTest {
@Shared
@@ -417,9 +418,7 @@ class SessionTest extends AbstractHibernateTest {
def "test hibernate overlapping Sessions"() {
setup:
- Tracer tracer = GlobalTracer.get()
-
- Scope scope = tracer.buildSpan("overlapping Sessions").startActive(true)
+ AgentScope scope = activateSpan(startSpan("overlapping Sessions"), true)
def session1 = sessionFactory.openSession()
session1.beginTransaction()

MODIFY
dd-java-agent/instrumentation/http-url-connection/src/test/groovy/HttpUrlConnectionTest.groovy
dd-java-agent/instrumentation/http-url-connection/src/test/groovy/HttpUrlConnectionTest.groovy
@@ -3,13 +3,13 @@ import datadog.trace.api.Config
import datadog.trace.api.DDSpanTypes
import datadog.trace.instrumentation.http_url_connection.HttpUrlConnectionDecorator
import io.opentracing.tag.Tags
-import io.opentracing.util.GlobalTracer
import spock.lang.Ignore
import spock.lang.Requires
import sun.net.www.protocol.https.HttpsURLConnectionImpl
import static datadog.trace.agent.test.utils.ConfigUtils.withConfigOverride
import static datadog.trace.agent.test.utils.TraceUtils.runUnderTrace
+import static datadog.trace.instrumentation.api.AgentTracer.activeScope
import static datadog.trace.instrumentation.http_url_connection.HttpUrlConnectionInstrumentation.HttpUrlState.OPERATION_NAME
class HttpUrlConnectionTest extends HttpClientTest<HttpUrlConnectionDecorator> {
@@ -25,9 +25,9 @@ class HttpUrlConnectionTest extends HttpClientTest<HttpUrlConnectionDecorator> {
headers.each { connection.setRequestProperty(it.key, it.value) }
connection.setRequestProperty("Connection", "close")
connection.useCaches = true
- def parentSpan = GlobalTracer.get().scopeManager().active()
+ def parentSpan = activeScope()
def stream = connection.inputStream
- assert GlobalTracer.get().scopeManager().active() == parentSpan
+ assert activeScope() == parentSpan
stream.readLines()
stream.close()
callback?.call()
@@ -55,7 +55,7 @@ class HttpUrlConnectionTest extends HttpClientTest<HttpUrlConnectionDecorator> {
runUnderTrace("someTrace") {
HttpURLConnection connection = url.openConnection()
connection.useCaches = useCaches
- assert GlobalTracer.get().scopeManager().active() != null
+ assert activeScope() != null
def stream = connection.inputStream
def lines = stream.readLines()
stream.close()
@@ -65,7 +65,7 @@ class HttpUrlConnectionTest extends HttpClientTest<HttpUrlConnectionDecorator> {
// call again to ensure the cycling is ok
connection = url.openConnection()
connection.useCaches = useCaches
- assert GlobalTracer.get().scopeManager().active() != null
+ assert activeScope() != null
assert connection.getResponseCode() == STATUS // call before input stream to test alternate behavior
connection.inputStream
stream = connection.inputStream // one more to ensure state is working
@@ -141,7 +141,7 @@ class HttpUrlConnectionTest extends HttpClientTest<HttpUrlConnectionDecorator> {
HttpURLConnection connection = url.openConnection()
connection.useCaches = useCaches
connection.addRequestProperty("is-dd-server", "false")
- assert GlobalTracer.get().scopeManager().active() != null
+ assert activeScope() != null
def stream = connection.inputStream
connection.inputStream // one more to ensure state is working
def lines = stream.readLines()
@@ -153,7 +153,7 @@ class HttpUrlConnectionTest extends HttpClientTest<HttpUrlConnectionDecorator> {
connection = url.openConnection()
connection.useCaches = useCaches
connection.addRequestProperty("is-dd-server", "false")
- assert GlobalTracer.get().scopeManager().active() != null
+ assert activeScope() != null
assert connection.getResponseCode() == STATUS // call before input stream to test alternate behavior
stream = connection.inputStream
lines = stream.readLines()
@@ -226,7 +226,7 @@ class HttpUrlConnectionTest extends HttpClientTest<HttpUrlConnectionDecorator> {
HttpURLConnection connection = url.openConnection()
connection.setRequestProperty("Connection", "close")
connection.addRequestProperty("is-dd-server", "false")
- assert GlobalTracer.get().scopeManager().active() != null
+ assert activeScope() != null
assert connection.getResponseCode() == STATUS
return connection
}

MODIFY
dd-java-agent/instrumentation/http-url-connection/src/test/groovy/HttpUrlConnectionUseCachesFalseTest.groovy
dd-java-agent/instrumentation/http-url-connection/src/test/groovy/HttpUrlConnectionUseCachesFalseTest.groovy
import datadog.trace.agent.test.base.HttpClientTest
import datadog.trace.instrumentation.http_url_connection.HttpUrlConnectionDecorator
-import io.opentracing.util.GlobalTracer
+
+import static datadog.trace.instrumentation.api.AgentTracer.activeScope
class HttpUrlConnectionUseCachesFalseTest extends HttpClientTest<HttpUrlConnectionDecorator> {
@@ -12,9 +13,9 @@ class HttpUrlConnectionUseCachesFalseTest extends HttpClientTest<HttpUrlConnecti
headers.each { connection.setRequestProperty(it.key, it.value) }
connection.setRequestProperty("Connection", "close")
connection.useCaches = false
- def parentSpan = GlobalTracer.get().scopeManager().active()
+ def parentSpan = activeScope()
def stream = connection.inputStream
- assert GlobalTracer.get().scopeManager().active() == parentSpan
+ assert activeScope() == parentSpan
stream.readLines()
stream.close()
callback?.call()

MODIFY
dd-java-agent/instrumentation/http-url-connection/src/test/groovy/UrlConnectionTest.groovy
dd-java-agent/instrumentation/http-url-connection/src/test/groovy/UrlConnectionTest.groovy
@@ -4,11 +4,11 @@ import datadog.trace.api.DDSpanTypes
import datadog.trace.bootstrap.DatadogClassLoader
import datadog.trace.instrumentation.http_url_connection.UrlInstrumentation
import io.opentracing.tag.Tags
-import io.opentracing.util.GlobalTracer
import static datadog.trace.agent.test.utils.ConfigUtils.withConfigOverride
import static datadog.trace.agent.test.utils.PortUtils.UNUSABLE_PORT
import static datadog.trace.agent.test.utils.TraceUtils.runUnderTrace
+import static datadog.trace.instrumentation.api.AgentTracer.activeScope
import static datadog.trace.instrumentation.http_url_connection.HttpUrlConnectionInstrumentation.HttpUrlState.OPERATION_NAME
class UrlConnectionTest extends AgentTestRunner {
@@ -20,7 +20,7 @@ class UrlConnectionTest extends AgentTestRunner {
URLConnection connection = url.openConnection()
connection.setConnectTimeout(10000)
connection.setReadTimeout(10000)
- assert GlobalTracer.get().scopeManager().active() != null
+ assert activeScope() != null
connection.inputStream
}
}

MODIFY
dd-java-agent/instrumentation/java-concurrent/akka-2.5-testing/src/test/groovy/AkkaExecutorInstrumentationTest.groovy
dd-java-agent/instrumentation/java-concurrent/akka-2.5-testing/src/test/groovy/AkkaExecutorInstrumentationTest.groovy
import akka.dispatch.forkjoin.ForkJoinPool
import akka.dispatch.forkjoin.ForkJoinTask
import datadog.opentracing.DDSpan
-import datadog.opentracing.scopemanager.ContinuableScope
import datadog.trace.agent.test.AgentTestRunner
import datadog.trace.api.Trace
-import io.opentracing.util.GlobalTracer
import spock.lang.Shared
import java.lang.reflect.InvocationTargetException
@@ -15,6 +13,8 @@ import java.util.concurrent.RejectedExecutionException
import java.util.concurrent.ThreadPoolExecutor
import java.util.concurrent.TimeUnit
+import static datadog.trace.instrumentation.api.AgentTracer.activeScope
+
/**
* Test executor instrumentation for Akka specific classes.
* This is to large extent a copy of ExecutorInstrumentationTest.
@@ -43,7 +43,7 @@ class AkkaExecutorInstrumentationTest extends AgentTestRunner {
@Override
@Trace(operationName = "parent")
void run() {
- ((ContinuableScope) GlobalTracer.get().scopeManager().active()).setAsyncPropagation(true)
+ activeScope().setAsyncPropagation(true)
// this child will have a span
m(pool, new AkkaAsyncChild())
// this child won't
@@ -91,7 +91,7 @@ class AkkaExecutorInstrumentationTest extends AgentTestRunner {
@Override
@Trace(operationName = "parent")
void run() {
- ((ContinuableScope) GlobalTracer.get().scopeManager().active()).setAsyncPropagation(true)
+ activeScope().setAsyncPropagation(true)
try {
for (int i = 0; i < 20; ++i) {
// Our current instrumentation instrumentation does not behave very well

MODIFY
dd-java-agent/instrumentation/java-concurrent/akka-testing/src/test/scala/AkkaActors.scala
dd-java-agent/instrumentation/java-concurrent/akka-testing/src/test/scala/AkkaActors.scala
@@ -2,8 +2,7 @@ import akka.actor.{Actor, ActorLogging, ActorRef, ActorSystem, Props}
import akka.pattern.ask
import akka.util.Timeout
import datadog.trace.api.Trace
-import datadog.trace.context.TraceScope
-import io.opentracing.util.GlobalTracer
+import datadog.trace.instrumentation.api.AgentTracer.{activeScope, activeSpan}
import scala.concurrent.duration._
@@ -21,7 +20,7 @@ object AkkaActors {
@Trace
def tracedChild(opName: String): Unit = {
- GlobalTracer.get().activeSpan().setOperationName(opName)
+ activeSpan().setSpanName(opName)
}
}
@@ -34,21 +33,21 @@ class AkkaActors {
@Trace
def basicTell(): Unit = {
- GlobalTracer.get().scopeManager().active().asInstanceOf[TraceScope].setAsyncPropagation(true)
+ activeScope().setAsyncPropagation(true)
howdyGreeter ! WhoToGreet("Akka")
howdyGreeter ! Greet
}
@Trace
def basicAsk(): Unit = {
- GlobalTracer.get().scopeManager().active().asInstanceOf[TraceScope].setAsyncPropagation(true)
+ activeScope().setAsyncPropagation(true)
howdyGreeter ! WhoToGreet("Akka")
howdyGreeter ? Greet
}
@Trace
def basicForward(): Unit = {
- GlobalTracer.get().scopeManager().active().asInstanceOf[TraceScope].setAsyncPropagation(true)
+ activeScope().setAsyncPropagation(true)
helloGreeter ! WhoToGreet("Akka")
helloGreeter ? Greet
}

MODIFY
dd-java-agent/instrumentation/java-concurrent/kotlin-testing/src/test/kotlin/KotlinCoroutineTests.kt
dd-java-agent/instrumentation/java-concurrent/kotlin-testing/src/test/kotlin/KotlinCoroutineTests.kt
import datadog.trace.api.Trace
-import datadog.trace.context.TraceScope
-import io.opentracing.Scope
-import io.opentracing.util.GlobalTracer
+import datadog.trace.instrumentation.api.AgentTracer.activeScope
+import datadog.trace.instrumentation.api.AgentTracer.activeSpan
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.*
import kotlinx.coroutines.selects.select
@@ -126,15 +125,12 @@ class KotlinCoroutineTests(private val dispatcher: CoroutineDispatcher) {
@Trace
fun tracedChild(opName: String){
- GlobalTracer.get().activeSpan().setOperationName(opName)
+ activeSpan().setSpanName(opName)
}
private fun <T> runTest(asyncPropagation: Boolean = true, block: suspend CoroutineScope.()->T ): T {
- GlobalTracer.get().scopeManager().active().setAsyncPropagation(asyncPropagation)
+ activeScope().setAsyncPropagation(asyncPropagation)
return runBlocking(dispatcher,block = block)
}
-
- private fun Scope.setAsyncPropagation(value: Boolean): Unit =
- (this as TraceScope).setAsyncPropagation(value)
}

MODIFY
dd-java-agent/instrumentation/java-concurrent/scala-testing/src/test/groovy/ScalaExecutorInstrumentationTest.groovy
dd-java-agent/instrumentation/java-concurrent/scala-testing/src/test/groovy/ScalaExecutorInstrumentationTest.groovy
import datadog.opentracing.DDSpan
-import datadog.opentracing.scopemanager.ContinuableScope
import datadog.trace.agent.test.AgentTestRunner
import datadog.trace.api.Trace
-import io.opentracing.util.GlobalTracer
import scala.concurrent.forkjoin.ForkJoinPool
import scala.concurrent.forkjoin.ForkJoinTask
import spock.lang.Shared
@@ -15,6 +13,8 @@ import java.util.concurrent.RejectedExecutionException
import java.util.concurrent.ThreadPoolExecutor
import java.util.concurrent.TimeUnit
+import static datadog.trace.instrumentation.api.AgentTracer.activeScope
+
/**
* Test executor instrumentation for Scala specific classes.
* This is to large extent a copy of ExecutorInstrumentationTest.
@@ -43,7 +43,7 @@ class ScalaExecutorInstrumentationTest extends AgentTestRunner {
@Override
@Trace(operationName = "parent")
void run() {
- ((ContinuableScope) GlobalTracer.get().scopeManager().active()).setAsyncPropagation(true)
+ activeScope().setAsyncPropagation(true)
// this child will have a span
m(pool, new ScalaAsyncChild())
// this child won't
@@ -91,7 +91,7 @@ class ScalaExecutorInstrumentationTest extends AgentTestRunner {
@Override
@Trace(operationName = "parent")
void run() {
- ((ContinuableScope) GlobalTracer.get().scopeManager().active()).setAsyncPropagation(true)
+ activeScope().setAsyncPropagation(true)
try {
for (int i = 0; i < 20; ++i) {
// Our current instrumentation instrumentation does not behave very well

MODIFY
dd-java-agent/instrumentation/java-concurrent/scala-testing/src/test/scala/ScalaConcurrentTests.scala
dd-java-agent/instrumentation/java-concurrent/scala-testing/src/test/scala/ScalaConcurrentTests.scala
import datadog.trace.api.Trace
-import datadog.trace.context.TraceScope
-import io.opentracing.util.GlobalTracer
+import datadog.trace.instrumentation.api.AgentTracer.{activeScope, activeSpan}
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
@@ -13,7 +12,7 @@ class ScalaConcurrentTests {
*/
@Trace
def traceWithFutureAndCallbacks(): Integer = {
- GlobalTracer.get().scopeManager().active().asInstanceOf[TraceScope].setAsyncPropagation(true)
+ activeScope().setAsyncPropagation(true)
val goodFuture: Future[Integer] = Future {
tracedChild("goodFuture")
1
@@ -34,7 +33,7 @@ class ScalaConcurrentTests {
@Trace
def tracedAcrossThreadsWithNoTrace(): Integer = {
- GlobalTracer.get().scopeManager().active().asInstanceOf[TraceScope].setAsyncPropagation(true)
+ activeScope().setAsyncPropagation(true)
val goodFuture: Future[Integer] = Future {
1
}
@@ -54,7 +53,7 @@ class ScalaConcurrentTests {
*/
@Trace
def traceWithPromises(): Integer = {
- GlobalTracer.get().scopeManager().active().asInstanceOf[TraceScope].setAsyncPropagation(true)
+ activeScope().setAsyncPropagation(true)
val keptPromise = Promise[Boolean]()
val brokenPromise = Promise[Boolean]()
val afterPromise = keptPromise.future
@@ -87,7 +86,7 @@ class ScalaConcurrentTests {
*/
@Trace
def tracedWithFutureFirstCompletions(): Integer = {
- GlobalTracer.get().scopeManager().active().asInstanceOf[TraceScope].setAsyncPropagation(true)
+ activeScope().setAsyncPropagation(true)
val completedVal = Future.firstCompletedOf(
List(
Future {
@@ -111,7 +110,7 @@ class ScalaConcurrentTests {
*/
@Trace
def tracedTimeout(): Integer = {
- GlobalTracer.get().scopeManager().active().asInstanceOf[TraceScope].setAsyncPropagation(true)
+ activeScope().setAsyncPropagation(true)
val f: Future[String] = Future {
tracedChild("timeoutChild")
while (true) {
@@ -130,6 +129,6 @@ class ScalaConcurrentTests {
@Trace
def tracedChild(opName: String): Unit = {
- GlobalTracer.get().activeSpan().setOperationName(opName)
+ activeSpan().setSpanName(opName)
}
}

MODIFY
dd-java-agent/instrumentation/java-concurrent/src/slickTest/groovy/CompletableFutureTest.groovy
dd-java-agent/instrumentation/java-concurrent/src/slickTest/groovy/CompletableFutureTest.groovy
import datadog.opentracing.DDSpan
-import datadog.opentracing.scopemanager.ContinuableScope
import datadog.trace.agent.test.AgentTestRunner
import datadog.trace.api.Trace
-import io.opentracing.util.GlobalTracer
import java.util.concurrent.ArrayBlockingQueue
import java.util.concurrent.CompletableFuture
@@ -11,6 +9,8 @@ import java.util.concurrent.TimeUnit
import java.util.function.Function
import java.util.function.Supplier
+import static datadog.trace.instrumentation.api.AgentTracer.activeScope
+
/**
* Note: ideally this should live with the rest of ExecutorInstrumentationTest,
* but this code needs java8 so we put it here for now.
@@ -42,7 +42,7 @@ class CompletableFutureTest extends AgentTestRunner {
@Override
@Trace(operationName = "parent")
CompletableFuture<String> get() {
- ((ContinuableScope) GlobalTracer.get().scopeManager().active()).setAsyncPropagation(true)
+ activeScope().setAsyncPropagation(true)
return CompletableFuture.supplyAsync(supplier, pool)
.thenCompose({ s -> CompletableFuture.supplyAsync(new AppendingSupplier(s), differentPool) })
.thenApply(function)

MODIFY
dd-java-agent/instrumentation/java-concurrent/src/slickTest/scala/SlickUtils.scala
dd-java-agent/instrumentation/java-concurrent/src/slickTest/scala/SlickUtils.scala
import datadog.trace.api.Trace
-import datadog.trace.context.TraceScope
-import io.opentracing.util.GlobalTracer
+import datadog.trace.instrumentation.api.AgentTracer.activeScope
import slick.jdbc.H2Profile.api._
import scala.concurrent.duration.Duration
@@ -22,7 +21,7 @@ class SlickUtils {
@Trace
def startQuery(query: String): Future[Vector[Int]] = {
- GlobalTracer.get().scopeManager().active().asInstanceOf[TraceScope].setAsyncPropagation(true)
+ activeScope().setAsyncPropagation(true)
database.run(sql"#$query".as[Int])
}

MODIFY
dd-java-agent/instrumentation/java-concurrent/src/test/groovy/ExecutorInstrumentationTest.groovy
dd-java-agent/instrumentation/java-concurrent/src/test/groovy/ExecutorInstrumentationTest.groovy
import datadog.opentracing.DDSpan
-import datadog.opentracing.scopemanager.ContinuableScope
import datadog.trace.agent.test.AgentTestRunner
import datadog.trace.agent.test.utils.ConfigUtils
import datadog.trace.api.Trace
import datadog.trace.bootstrap.instrumentation.java.concurrent.CallableWrapper
import datadog.trace.bootstrap.instrumentation.java.concurrent.RunnableWrapper
-import io.opentracing.util.GlobalTracer
import spock.lang.Shared
import java.lang.reflect.InvocationTargetException
@@ -25,6 +23,7 @@ import java.util.concurrent.ThreadPoolExecutor
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException
+import static datadog.trace.instrumentation.api.AgentTracer.activeScope
import static org.junit.Assume.assumeTrue
class ExecutorInstrumentationTest extends AgentTestRunner {
@@ -70,7 +69,7 @@ class ExecutorInstrumentationTest extends AgentTestRunner {
@Override
@Trace(operationName = "parent")
void run() {
- ((ContinuableScope) GlobalTracer.get().scopeManager().active()).setAsyncPropagation(true)
+ activeScope().setAsyncPropagation(true)
// this child will have a span
m(pool, new JavaAsyncChild())
// this child won't
@@ -151,7 +150,7 @@ class ExecutorInstrumentationTest extends AgentTestRunner {
@Override
@Trace(operationName = "parent")
void run() {
- ((ContinuableScope) GlobalTracer.get().scopeManager().active()).setAsyncPropagation(true)
+ activeScope().setAsyncPropagation(true)
m(pool, w(child))
}
}.run()
@@ -195,7 +194,7 @@ class ExecutorInstrumentationTest extends AgentTestRunner {
@Override
@Trace(operationName = "parent")
void run() {
- ((ContinuableScope) GlobalTracer.get().scopeManager().active()).setAsyncPropagation(true)
+ activeScope().setAsyncPropagation(true)
try {
for (int i = 0; i < 20; ++i) {
// Our current instrumentation instrumentation does not behave very well

MODIFY
dd-java-agent/instrumentation/trace-annotation/src/test/java/dd/test/trace/annotation/SayTracedHello.java
dd-java-agent/instrumentation/trace-annotation/src/test/java/dd/test/trace/annotation/SayTracedHello.java
package dd.test.trace.annotation;
+import static datadog.trace.instrumentation.api.AgentTracer.activeSpan;
+
import datadog.trace.api.DDTags;
import datadog.trace.api.Trace;
-import io.opentracing.tag.StringTag;
-import io.opentracing.util.GlobalTracer;
import java.util.concurrent.Callable;
public class SayTracedHello {
@Trace
public static String sayHello() {
- new StringTag(DDTags.SERVICE_NAME)
- .set(GlobalTracer.get().scopeManager().active().span(), "test");
+ activeSpan().setTag(DDTags.SERVICE_NAME, "test");
return "hello!";
}
@Trace(resourceName = "WORLD")
public static String sayHelloOnlyResourceSet() {
- new StringTag(DDTags.SERVICE_NAME)
- .set(GlobalTracer.get().scopeManager().active().span(), "test");
+ activeSpan().setTag(DDTags.SERVICE_NAME, "test");
return "hello!";
}
@Trace(operationName = "SAY_HA")
public static String sayHA() {
- new StringTag(DDTags.SERVICE_NAME)
- .set(GlobalTracer.get().scopeManager().active().span(), "test");
- new StringTag(DDTags.SPAN_TYPE).set(GlobalTracer.get().scopeManager().active().span(), "DB");
+ activeSpan().setTag(DDTags.SERVICE_NAME, "test");
+ activeSpan().setTag(DDTags.SPAN_TYPE, "DB");
return "HA!!";
}
@Trace(operationName = "SAY_HA", resourceName = "EARTH")
public static String sayHAWithResource() {
- new StringTag(DDTags.SERVICE_NAME)
- .set(GlobalTracer.get().scopeManager().active().span(), "test");
- new StringTag(DDTags.SPAN_TYPE).set(GlobalTracer.get().scopeManager().active().span(), "DB");
+ activeSpan().setTag(DDTags.SERVICE_NAME, "test");
+ activeSpan().setTag(DDTags.SPAN_TYPE, "DB");
return "HA EARTH!!";
}
@Trace(operationName = "NEW_TRACE")
public static String sayHELLOsayHA() {
- new StringTag(DDTags.SERVICE_NAME)
- .set(GlobalTracer.get().scopeManager().active().span(), "test2");
+ activeSpan().setTag(DDTags.SERVICE_NAME, "test2");
return sayHello() + sayHA();
}
@Trace(operationName = "NEW_TRACE", resourceName = "WORLD")
public static String sayHELLOsayHAWithResource() {
- new StringTag(DDTags.SERVICE_NAME)
- .set(GlobalTracer.get().scopeManager().active().span(), "test2");
+ activeSpan().setTag(DDTags.SERVICE_NAME, "test2");
return sayHello() + sayHA();
}
@Trace(operationName = "NEW_TRACE", resourceName = "WORLD")
public static String sayHELLOsayHAMixedResourceChildren() {
- new StringTag(DDTags.SERVICE_NAME)
- .set(GlobalTracer.get().scopeManager().active().span(), "test2");
+ activeSpan().setTag(DDTags.SERVICE_NAME, "test2");
return sayHello() + sayHAWithResource();
}

MODIFY
dd-java-agent/instrumentation/twilio/src/test/groovy/test/TwilioClientTest.groovy
dd-java-agent/instrumentation/twilio/src/test/groovy/test/TwilioClientTest.groovy
@@ -13,7 +13,6 @@ import com.twilio.type.PhoneNumber
import datadog.trace.agent.test.AgentTestRunner
import datadog.trace.api.DDSpanTypes
import io.opentracing.tag.Tags
-import io.opentracing.util.GlobalTracer
import org.apache.http.HttpEntity
import org.apache.http.HttpStatus
import org.apache.http.StatusLine
@@ -24,6 +23,11 @@ import org.apache.http.impl.client.HttpClientBuilder
import java.util.concurrent.ExecutionException
import java.util.concurrent.TimeUnit
+import static datadog.trace.instrumentation.api.AgentTracer.activateSpan
+import static datadog.trace.instrumentation.api.AgentTracer.activeScope
+import static datadog.trace.instrumentation.api.AgentTracer.activeSpan
+import static datadog.trace.instrumentation.api.AgentTracer.startSpan
+
class TwilioClientTest extends AgentTestRunner {
final static String ACCOUNT_SID = "abc"
@@ -110,7 +114,7 @@ class TwilioClientTest extends AgentTestRunner {
1 * twilioRestClient.request(_) >> new Response(new ByteArrayInputStream(MESSAGE_RESPONSE_BODY.getBytes()), 200)
- GlobalTracer.get().buildSpan("test").startActive(true)
+ activateSpan(startSpan("test"), true)
Message message = Message.creator(
new PhoneNumber("+1 555 720 5913"), // To number
@@ -118,7 +122,7 @@ class TwilioClientTest extends AgentTestRunner {
"Hello world!" // SMS body
).create(twilioRestClient)
- def scope = GlobalTracer.get().scopeManager().active()
+ def scope = activeScope()
if (scope) {
scope.close()
}
@@ -162,7 +166,7 @@ class TwilioClientTest extends AgentTestRunner {
1 * twilioRestClient.request(_) >> new Response(new ByteArrayInputStream(CALL_RESPONSE_BODY.getBytes()), 200)
- GlobalTracer.get().buildSpan("test").startActive(true)
+ activateSpan(startSpan("test"), true)
Call call = Call.creator(
new PhoneNumber("+15558881234"), // To number
@@ -172,7 +176,7 @@ class TwilioClientTest extends AgentTestRunner {
new URI("http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient")
).create(twilioRestClient)
- def scope = GlobalTracer.get().scopeManager().active()
+ def scope = activeScope()
if (scope) {
scope.close()
}
@@ -240,7 +244,7 @@ class TwilioClientTest extends AgentTestRunner {
.httpClient(networkHttpClient)
.build()
- GlobalTracer.get().buildSpan("test").startActive(true)
+ activateSpan(startSpan("test"), true)
Message message = Message.creator(
new PhoneNumber("+1 555 720 5913"), // To number
@@ -248,7 +252,7 @@ class TwilioClientTest extends AgentTestRunner {
"Hello world!" // SMS body
).create(realTwilioRestClient)
- def scope = GlobalTracer.get().scopeManager().active()
+ def scope = activeScope()
if (scope) {
scope.close()
}
@@ -339,7 +343,7 @@ class TwilioClientTest extends AgentTestRunner {
.httpClient(networkHttpClient)
.build()
- GlobalTracer.get().buildSpan("test").startActive(true)
+ activateSpan(startSpan("test"), true)
Message message = Message.creator(
new PhoneNumber("+1 555 720 5913"), // To number
@@ -347,7 +351,7 @@ class TwilioClientTest extends AgentTestRunner {
"Hello world!" // SMS body
).create(realTwilioRestClient)
- def scope = GlobalTracer.get().scopeManager().active()
+ def scope = activeScope()
if (scope) {
scope.close()
}
@@ -445,7 +449,7 @@ class TwilioClientTest extends AgentTestRunner {
.httpClient(networkHttpClient)
.build()
- GlobalTracer.get().buildSpan("test").startActive(true)
+ activateSpan(startSpan("test"), true)
ListenableFuture<Message> future = Message.creator(
new PhoneNumber("+1 555 720 5913"), // To number
@@ -459,9 +463,9 @@ class TwilioClientTest extends AgentTestRunner {
} finally {
// Give the future callback a chance to run
Thread.sleep(1000)
- def scope = GlobalTracer.get().scopeManager().active()
+ def scope = activeScope()
if (scope) {
- scope.span().finish()
+ activeSpan().finish()
scope.close()
}
}
@@ -543,7 +547,7 @@ class TwilioClientTest extends AgentTestRunner {
1 * twilioRestClient.request(_) >> new Response(new ByteArrayInputStream(ERROR_RESPONSE_BODY.getBytes()), 500)
- GlobalTracer.get().buildSpan("test").startActive(true)
+ activateSpan(startSpan("test"), true)
when:
Message.creator(
@@ -555,7 +559,7 @@ class TwilioClientTest extends AgentTestRunner {
then:
thrown(ApiException)
- def scope = GlobalTracer.get().scopeManager().active()
+ def scope = activeScope()
if (scope) {
scope.close()
}
@@ -629,7 +633,7 @@ class TwilioClientTest extends AgentTestRunner {
when:
- GlobalTracer.get().buildSpan("test").startActive(true)
+ activateSpan(startSpan("test"), true)
ListenableFuture<Message> future = Message.creator(
new PhoneNumber("+1 555 720 5913"), // To number
@@ -643,9 +647,9 @@ class TwilioClientTest extends AgentTestRunner {
} finally {
// Give the future callback a chance to run
Thread.sleep(1000)
- def scope = GlobalTracer.get().scopeManager().active()
+ def scope = activeScope()
if (scope) {
- scope.span().finish()
+ activeSpan().finish()
scope.close()
}
}
@@ -716,7 +720,7 @@ class TwilioClientTest extends AgentTestRunner {
1 * twilioRestClient.request(_) >> new Response(new ByteArrayInputStream(ERROR_RESPONSE_BODY.getBytes()), 500)
- GlobalTracer.get().buildSpan("test").startActive(true)
+ activateSpan(startSpan("test"), true)
ListenableFuture<Message> future = Message.creator(
new PhoneNumber("+1 555 720 5913"), // To number
@@ -732,7 +736,7 @@ class TwilioClientTest extends AgentTestRunner {
} finally {
Thread.sleep(1000)
- def scope = GlobalTracer.get().scopeManager().active()
+ def scope = activeScope()
if (scope) {
scope.close()
}

Remove test dependency on GlobalTracer