Update jax-rs-annotations-1 to new agent api
MODIFY
dd-java-agent/instrumentation/jax-rs-annotations-1/src/main/java/datadog/trace/instrumentation/jaxrs1/JaxRsAnnotationsDecorator.java
dd-java-agent/instrumentation/jax-rs-annotations-1/src/main/java/datadog/trace/instrumentation/jaxrs1/JaxRsAnnotationsDecorator.java
@@ -6,8 +6,7 @@ import datadog.trace.agent.decorator.BaseDecorator;
import datadog.trace.api.DDSpanTypes;
import datadog.trace.api.DDTags;
import datadog.trace.bootstrap.WeakMap;
-import io.opentracing.Scope;
-import io.opentracing.Span;
+import datadog.trace.instrumentation.api.AgentSpan;
import io.opentracing.tag.Tags;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
@@ -37,11 +36,10 @@ public class JaxRsAnnotationsDecorator extends BaseDecorator {
return "jax-rs-controller";
}
- public void onControllerStart(final Scope scope, final Scope parent, final Method method) {
+ public void onControllerStart(final AgentSpan span, final AgentSpan parent, final Method method) {
final String resourceName = getPathResourceName(method);
updateParent(parent, resourceName);
- final Span span = scope.span();
span.setTag(DDTags.SPAN_TYPE, DDSpanTypes.HTTP_SERVER);
// When jax-rs is the root, we want to name using the path, otherwise use the class/method.
@@ -53,12 +51,11 @@ public class JaxRsAnnotationsDecorator extends BaseDecorator {
}
}
- private void updateParent(final Scope scope, final String resourceName) {
- if (scope == null) {
+ private void updateParent(final AgentSpan span, final String resourceName) {
+ if (span == null) {
return;
}
- final Span span = scope.span();
- Tags.COMPONENT.set(span, "jax-rs");
+ span.setTag(Tags.COMPONENT.getKey(), "jax-rs");
if (!resourceName.isEmpty()) {
span.setTag(DDTags.RESOURCE_NAME, resourceName);

MODIFY
dd-java-agent/instrumentation/jax-rs-annotations-1/src/main/java/datadog/trace/instrumentation/jaxrs1/JaxRsAnnotationsInstrumentation.java
dd-java-agent/instrumentation/jax-rs-annotations-1/src/main/java/datadog/trace/instrumentation/jaxrs1/JaxRsAnnotationsInstrumentation.java
@@ -2,6 +2,9 @@ package datadog.trace.instrumentation.jaxrs1;
import static datadog.trace.agent.tooling.ByteBuddyElementMatchers.safeHasSuperType;
import static datadog.trace.agent.tooling.ClassLoaderMatcher.classLoaderHasClasses;
+import static datadog.trace.instrumentation.api.AgentTracer.activateSpan;
+import static datadog.trace.instrumentation.api.AgentTracer.activeSpan;
+import static datadog.trace.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.instrumentation.jaxrs1.JaxRsAnnotationsDecorator.DECORATE;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.declaresMethod;
@@ -11,10 +14,8 @@ import static net.bytebuddy.matcher.ElementMatchers.not;
import com.google.auto.service.AutoService;
import datadog.trace.agent.tooling.Instrumenter;
-import datadog.trace.context.TraceScope;
-import io.opentracing.Scope;
-import io.opentracing.Tracer;
-import io.opentracing.util.GlobalTracer;
+import datadog.trace.instrumentation.api.AgentScope;
+import datadog.trace.instrumentation.api.AgentSpan;
import java.lang.reflect.Method;
import java.util.Map;
import net.bytebuddy.asm.Advice;
@@ -68,25 +69,25 @@ public final class JaxRsAnnotationsInstrumentation extends Instrumenter.Default
public static class JaxRsAnnotationsAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
- public static Scope nameSpan(@Advice.Origin final Method method) {
- final Tracer tracer = GlobalTracer.get();
+ public static AgentScope nameSpan(@Advice.Origin final Method method) {
// Rename the parent span according to the path represented by these annotations.
- final Scope parent = tracer.scopeManager().active();
- final Scope scope = tracer.buildSpan(JAX_ENDPOINT_OPERATION_NAME).startActive(true);
+ final AgentSpan parent = activeSpan();
- if (scope instanceof TraceScope) {
- ((TraceScope) scope).setAsyncPropagation(true);
- }
+ final AgentSpan span = startSpan(JAX_ENDPOINT_OPERATION_NAME);
+ DECORATE.onControllerStart(span, parent, method);
+ DECORATE.afterStart(span);
- DECORATE.onControllerStart(scope, parent, method);
- return DECORATE.afterStart(scope);
+ final AgentScope scope = activateSpan(span, true);
+ scope.setAsyncPropagation(true);
+ return scope;
}
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void stopSpan(
- @Advice.Enter final Scope scope, @Advice.Thrown final Throwable throwable) {
- DECORATE.onError(scope, throwable);
- DECORATE.beforeFinish(scope);
+ @Advice.Enter final AgentScope scope, @Advice.Thrown final Throwable throwable) {
+ final AgentSpan span = scope.span();
+ DECORATE.onError(span, throwable);
+ DECORATE.beforeFinish(span);
scope.close();
}
}

Update jax-rs-annotations-1 to new agent api