Update java-concurrent to new agent api
MODIFY
dd-java-agent/instrumentation/java-concurrent/src/main/java/datadog/trace/instrumentation/java/concurrent/AkkaExecutorInstrumentation.java
dd-java-agent/instrumentation/java-concurrent/src/main/java/datadog/trace/instrumentation/java/concurrent/AkkaExecutorInstrumentation.java
package datadog.trace.instrumentation.java.concurrent;
+import static datadog.trace.instrumentation.api.AgentTracer.activeScope;
import static net.bytebuddy.matcher.ElementMatchers.nameMatches;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
@@ -11,8 +12,6 @@ import datadog.trace.bootstrap.ContextStore;
import datadog.trace.bootstrap.InstrumentationContext;
import datadog.trace.bootstrap.instrumentation.java.concurrent.State;
import datadog.trace.context.TraceScope;
-import io.opentracing.Scope;
-import io.opentracing.util.GlobalTracer;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -60,11 +59,11 @@ public final class AkkaExecutorInstrumentation extends AbstractExecutorInstrumen
public static State enterJobSubmit(
@Advice.This final Executor executor,
@Advice.Argument(value = 0, readOnly = false) final ForkJoinTask task) {
- final Scope scope = GlobalTracer.get().scopeManager().active();
+ final TraceScope scope = activeScope();
if (ExecutorInstrumentationUtils.shouldAttachStateToTask(task, executor)) {
final ContextStore<ForkJoinTask, State> contextStore =
InstrumentationContext.get(ForkJoinTask.class, State.class);
- return ExecutorInstrumentationUtils.setupState(contextStore, task, (TraceScope) scope);
+ return ExecutorInstrumentationUtils.setupState(contextStore, task, scope);
}
return null;
}

MODIFY
dd-java-agent/instrumentation/java-concurrent/src/main/java/datadog/trace/instrumentation/java/concurrent/AsyncPropagatingDisableInstrumentation.java
dd-java-agent/instrumentation/java-concurrent/src/main/java/datadog/trace/instrumentation/java/concurrent/AsyncPropagatingDisableInstrumentation.java
package datadog.trace.instrumentation.java.concurrent;
import static datadog.trace.agent.tooling.ByteBuddyElementMatchers.safeHasSuperType;
+import static datadog.trace.instrumentation.api.AgentTracer.activateSpan;
+import static datadog.trace.instrumentation.api.AgentTracer.activeScope;
+import static datadog.trace.instrumentation.api.AgentTracer.noopSpan;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.named;
@@ -8,10 +11,7 @@ import com.google.auto.service.AutoService;
import com.google.common.collect.ImmutableMap;
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.context.TraceScope;
-import io.opentracing.Scope;
-import io.opentracing.ScopeManager;
-import io.opentracing.noop.NoopSpan;
-import io.opentracing.util.GlobalTracer;
+import datadog.trace.instrumentation.api.AgentScope;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import net.bytebuddy.agent.builder.AgentBuilder;
@@ -85,17 +85,16 @@ public final class AsyncPropagatingDisableInstrumentation implements Instrumente
public static class DisableAsyncAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
- public static Scope enter() {
- final ScopeManager scopeManager = GlobalTracer.get().scopeManager();
- final Scope scope = scopeManager.active();
- if (scope instanceof TraceScope && ((TraceScope) scope).isAsyncPropagating()) {
- return scopeManager.activate(NoopSpan.INSTANCE, false);
+ public static AgentScope enter() {
+ final TraceScope scope = activeScope();
+ if (scope != null && scope.isAsyncPropagating()) {
+ return activateSpan(noopSpan(), false);
}
return null;
}
@Advice.OnMethodExit(suppress = Throwable.class)
- public static void exit(@Advice.Enter final Scope scope) {
+ public static void exit(@Advice.Enter final AgentScope scope) {
if (scope != null) {
scope.close();
}

MODIFY
dd-java-agent/instrumentation/java-concurrent/src/main/java/datadog/trace/instrumentation/java/concurrent/ExecutorInstrumentationUtils.java
dd-java-agent/instrumentation/java-concurrent/src/main/java/datadog/trace/instrumentation/java/concurrent/ExecutorInstrumentationUtils.java
package datadog.trace.instrumentation.java.concurrent;
+import static datadog.trace.instrumentation.api.AgentTracer.activeScope;
+
import datadog.trace.bootstrap.ContextStore;
import datadog.trace.bootstrap.WeakMap;
import datadog.trace.bootstrap.instrumentation.java.concurrent.CallableWrapper;
import datadog.trace.bootstrap.instrumentation.java.concurrent.RunnableWrapper;
import datadog.trace.bootstrap.instrumentation.java.concurrent.State;
import datadog.trace.context.TraceScope;
-import io.opentracing.Scope;
-import io.opentracing.util.GlobalTracer;
import java.util.concurrent.Executor;
import lombok.extern.slf4j.Slf4j;
@@ -26,9 +26,9 @@ public class ExecutorInstrumentationUtils {
* @return true iff given task object should be wrapped
*/
public static boolean shouldAttachStateToTask(final Object task, final Executor executor) {
- final Scope scope = GlobalTracer.get().scopeManager().active();
- return (scope instanceof TraceScope
- && ((TraceScope) scope).isAsyncPropagating()
+ final TraceScope scope = activeScope();
+ return (scope != null
+ && scope.isAsyncPropagating()
&& task != null
&& !ExecutorInstrumentationUtils.isExecutorDisabledForThisTask(executor, task));
}

MODIFY
dd-java-agent/instrumentation/java-concurrent/src/main/java/datadog/trace/instrumentation/java/concurrent/JavaExecutorInstrumentation.java
dd-java-agent/instrumentation/java-concurrent/src/main/java/datadog/trace/instrumentation/java/concurrent/JavaExecutorInstrumentation.java
package datadog.trace.instrumentation.java.concurrent;
+import static datadog.trace.instrumentation.api.AgentTracer.activeScope;
import static net.bytebuddy.matcher.ElementMatchers.nameMatches;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
@@ -12,8 +13,6 @@ import datadog.trace.bootstrap.instrumentation.java.concurrent.CallableWrapper;
import datadog.trace.bootstrap.instrumentation.java.concurrent.RunnableWrapper;
import datadog.trace.bootstrap.instrumentation.java.concurrent.State;
import datadog.trace.context.TraceScope;
-import io.opentracing.Scope;
-import io.opentracing.util.GlobalTracer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -79,7 +78,7 @@ public final class JavaExecutorInstrumentation extends AbstractExecutorInstrumen
public static State enterJobSubmit(
@Advice.This final Executor executor,
@Advice.Argument(value = 0, readOnly = false) Runnable task) {
- final Scope scope = GlobalTracer.get().scopeManager().active();
+ final TraceScope scope = activeScope();
final Runnable newTask = RunnableWrapper.wrapIfNeeded(task);
// It is important to check potentially wrapped task if we can instrument task in this
// executor. Some executors do not support wrapped tasks.
@@ -87,7 +86,7 @@ public final class JavaExecutorInstrumentation extends AbstractExecutorInstrumen
task = newTask;
final ContextStore<Runnable, State> contextStore =
InstrumentationContext.get(Runnable.class, State.class);
- return ExecutorInstrumentationUtils.setupState(contextStore, newTask, (TraceScope) scope);
+ return ExecutorInstrumentationUtils.setupState(contextStore, newTask, scope);
}
return null;
}
@@ -107,11 +106,11 @@ public final class JavaExecutorInstrumentation extends AbstractExecutorInstrumen
public static State enterJobSubmit(
@Advice.This final Executor executor,
@Advice.Argument(value = 0, readOnly = false) final ForkJoinTask task) {
- final Scope scope = GlobalTracer.get().scopeManager().active();
+ final TraceScope scope = activeScope();
if (ExecutorInstrumentationUtils.shouldAttachStateToTask(task, executor)) {
final ContextStore<ForkJoinTask, State> contextStore =
InstrumentationContext.get(ForkJoinTask.class, State.class);
- return ExecutorInstrumentationUtils.setupState(contextStore, task, (TraceScope) scope);
+ return ExecutorInstrumentationUtils.setupState(contextStore, task, scope);
}
return null;
}
@@ -131,7 +130,7 @@ public final class JavaExecutorInstrumentation extends AbstractExecutorInstrumen
public static State enterJobSubmit(
@Advice.This final Executor executor,
@Advice.Argument(value = 0, readOnly = false) Runnable task) {
- final Scope scope = GlobalTracer.get().scopeManager().active();
+ final TraceScope scope = activeScope();
final Runnable newTask = RunnableWrapper.wrapIfNeeded(task);
// It is important to check potentially wrapped task if we can instrument task in this
// executor. Some executors do not support wrapped tasks.
@@ -139,7 +138,7 @@ public final class JavaExecutorInstrumentation extends AbstractExecutorInstrumen
task = newTask;
final ContextStore<Runnable, State> contextStore =
InstrumentationContext.get(Runnable.class, State.class);
- return ExecutorInstrumentationUtils.setupState(contextStore, newTask, (TraceScope) scope);
+ return ExecutorInstrumentationUtils.setupState(contextStore, newTask, scope);
}
return null;
}
@@ -165,7 +164,7 @@ public final class JavaExecutorInstrumentation extends AbstractExecutorInstrumen
public static State enterJobSubmit(
@Advice.This final Executor executor,
@Advice.Argument(value = 0, readOnly = false) Callable task) {
- final Scope scope = GlobalTracer.get().scopeManager().active();
+ final TraceScope scope = activeScope();
final Callable newTask = CallableWrapper.wrapIfNeeded(task);
// It is important to check potentially wrapped task if we can instrument task in this
// executor. Some executors do not support wrapped tasks.
@@ -173,7 +172,7 @@ public final class JavaExecutorInstrumentation extends AbstractExecutorInstrumen
task = newTask;
final ContextStore<Callable, State> contextStore =
InstrumentationContext.get(Callable.class, State.class);
- return ExecutorInstrumentationUtils.setupState(contextStore, newTask, (TraceScope) scope);
+ return ExecutorInstrumentationUtils.setupState(contextStore, newTask, scope);
}
return null;
}
@@ -199,10 +198,8 @@ public final class JavaExecutorInstrumentation extends AbstractExecutorInstrumen
public static Collection<?> submitEnter(
@Advice.This final Executor executor,
@Advice.Argument(value = 0, readOnly = false) Collection<? extends Callable<?>> tasks) {
- final Scope scope = GlobalTracer.get().scopeManager().active();
- if (scope instanceof TraceScope
- && ((TraceScope) scope).isAsyncPropagating()
- && tasks != null) {
+ final TraceScope scope = activeScope();
+ if (scope != null && scope.isAsyncPropagating() && tasks != null) {
final Collection<Callable<?>> wrappedTasks = new ArrayList<>(tasks.size());
for (final Callable<?> task : tasks) {
if (task != null) {
@@ -213,7 +210,7 @@ public final class JavaExecutorInstrumentation extends AbstractExecutorInstrumen
wrappedTasks.add(newTask);
final ContextStore<Callable, State> contextStore =
InstrumentationContext.get(Callable.class, State.class);
- ExecutorInstrumentationUtils.setupState(contextStore, newTask, (TraceScope) scope);
+ ExecutorInstrumentationUtils.setupState(contextStore, newTask, scope);
}
}
}

MODIFY
dd-java-agent/instrumentation/java-concurrent/src/main/java/datadog/trace/instrumentation/java/concurrent/ScalaExecutorInstrumentation.java
dd-java-agent/instrumentation/java-concurrent/src/main/java/datadog/trace/instrumentation/java/concurrent/ScalaExecutorInstrumentation.java
package datadog.trace.instrumentation.java.concurrent;
+import static datadog.trace.instrumentation.api.AgentTracer.activeScope;
import static net.bytebuddy.matcher.ElementMatchers.nameMatches;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
@@ -10,8 +11,6 @@ import datadog.trace.bootstrap.ContextStore;
import datadog.trace.bootstrap.InstrumentationContext;
import datadog.trace.bootstrap.instrumentation.java.concurrent.State;
import datadog.trace.context.TraceScope;
-import io.opentracing.Scope;
-import io.opentracing.util.GlobalTracer;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -60,11 +59,11 @@ public final class ScalaExecutorInstrumentation extends AbstractExecutorInstrume
public static State enterJobSubmit(
@Advice.This final Executor executor,
@Advice.Argument(value = 0, readOnly = false) final ForkJoinTask task) {
- final Scope scope = GlobalTracer.get().scopeManager().active();
+ final TraceScope scope = activeScope();
if (ExecutorInstrumentationUtils.shouldAttachStateToTask(task, executor)) {
final ContextStore<ForkJoinTask, State> contextStore =
InstrumentationContext.get(ForkJoinTask.class, State.class);
- return ExecutorInstrumentationUtils.setupState(contextStore, task, (TraceScope) scope);
+ return ExecutorInstrumentationUtils.setupState(contextStore, task, scope);
}
return null;
}

Update java-concurrent to new agent api