Update jsp-2.3 to new agent api
MODIFY
dd-java-agent/instrumentation/jsp-2.3/src/main/java/datadog/trace/instrumentation/jsp/JSPDecorator.java
dd-java-agent/instrumentation/jsp-2.3/src/main/java/datadog/trace/instrumentation/jsp/JSPDecorator.java
@@ -2,8 +2,8 @@ package datadog.trace.instrumentation.jsp;
import datadog.trace.agent.decorator.BaseDecorator;
import datadog.trace.api.DDTags;
-import io.opentracing.Scope;
-import io.opentracing.Span;
+import datadog.trace.instrumentation.api.AgentScope;
+import datadog.trace.instrumentation.api.AgentSpan;
import java.net.URI;
import java.net.URISyntaxException;
import javax.servlet.RequestDispatcher;
@@ -30,9 +30,9 @@ public class JSPDecorator extends BaseDecorator {
return "jsp-http-servlet";
}
- public void onCompile(final Scope scope, final JspCompilationContext jspCompilationContext) {
+ public void onCompile(final AgentScope scope, final JspCompilationContext jspCompilationContext) {
if (jspCompilationContext != null) {
- final Span span = scope.span();
+ final AgentSpan span = scope.span();
span.setTag(DDTags.RESOURCE_NAME, jspCompilationContext.getJspFile());
if (jspCompilationContext.getServletContext() != null) {
@@ -46,8 +46,7 @@ public class JSPDecorator extends BaseDecorator {
}
}
- public void onRender(final Scope scope, final HttpServletRequest req) {
- final Span span = scope.span();
+ public void onRender(final AgentSpan span, final HttpServletRequest req) {
// get the JSP file name being rendered in an include action
final Object includeServletPath = req.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH);
String resourceName = req.getServletPath();

MODIFY
dd-java-agent/instrumentation/jsp-2.3/src/main/java/datadog/trace/instrumentation/jsp/JSPInstrumentation.java
dd-java-agent/instrumentation/jsp-2.3/src/main/java/datadog/trace/instrumentation/jsp/JSPInstrumentation.java
package datadog.trace.instrumentation.jsp;
import static datadog.trace.agent.tooling.ByteBuddyElementMatchers.safeHasSuperType;
+import static datadog.trace.instrumentation.api.AgentTracer.activateSpan;
+import static datadog.trace.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.instrumentation.jsp.JSPDecorator.DECORATE;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
@@ -11,8 +13,8 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import com.google.auto.service.AutoService;
import datadog.trace.agent.tooling.Instrumenter;
-import io.opentracing.Scope;
-import io.opentracing.util.GlobalTracer;
+import datadog.trace.instrumentation.api.AgentScope;
+import datadog.trace.instrumentation.api.AgentSpan;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import net.bytebuddy.asm.Advice;
@@ -52,22 +54,20 @@ public final class JSPInstrumentation extends Instrumenter.Default {
public static class HttpJspPageAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
- public static Scope startSpan(
+ public static AgentScope onEnter(
@Advice.This final Object obj, @Advice.Argument(0) final HttpServletRequest req) {
- final Scope scope =
- GlobalTracer.get()
- .buildSpan("jsp.render")
- .withTag("span.origin.type", obj.getClass().getSimpleName())
- .withTag("servlet.context", req.getContextPath())
- .startActive(true);
- DECORATE.afterStart(scope);
- DECORATE.onRender(scope, req);
- return scope;
+ final AgentSpan span =
+ startSpan("jsp.render")
+ .setTag("span.origin.type", obj.getClass().getSimpleName())
+ .setTag("servlet.context", req.getContextPath());
+ DECORATE.afterStart(span);
+ DECORATE.onRender(span, req);
+ return activateSpan(span, true);
}
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void stopSpan(
- @Advice.Enter final Scope scope, @Advice.Thrown final Throwable throwable) {
+ @Advice.Enter final AgentScope scope, @Advice.Thrown final Throwable throwable) {
DECORATE.onError(scope, throwable);
DECORATE.beforeFinish(scope);
scope.close();

MODIFY
dd-java-agent/instrumentation/jsp-2.3/src/main/java/datadog/trace/instrumentation/jsp/JasperJSPCompilationContextInstrumentation.java
dd-java-agent/instrumentation/jsp-2.3/src/main/java/datadog/trace/instrumentation/jsp/JasperJSPCompilationContextInstrumentation.java
package datadog.trace.instrumentation.jsp;
+import static datadog.trace.instrumentation.api.AgentTracer.activateSpan;
+import static datadog.trace.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.instrumentation.jsp.JSPDecorator.DECORATE;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
@@ -8,8 +10,8 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
import com.google.auto.service.AutoService;
import datadog.trace.agent.tooling.Instrumenter;
-import io.opentracing.Scope;
-import io.opentracing.util.GlobalTracer;
+import datadog.trace.instrumentation.api.AgentScope;
+import datadog.trace.instrumentation.api.AgentSpan;
import java.util.Map;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
@@ -46,16 +48,16 @@ public final class JasperJSPCompilationContextInstrumentation extends Instrument
public static class JasperJspCompilationContext {
@Advice.OnMethodEnter(suppress = Throwable.class)
- public static Scope startSpan() {
- final Scope scope = GlobalTracer.get().buildSpan("jsp.compile").startActive(true);
- DECORATE.afterStart(scope);
- return scope;
+ public static AgentScope onEnter() {
+ final AgentSpan span = startSpan("jsp.compile");
+ DECORATE.afterStart(span);
+ return activateSpan(span, true);
}
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void stopSpan(
@Advice.This final JspCompilationContext jspCompilationContext,
- @Advice.Enter final Scope scope,
+ @Advice.Enter final AgentScope scope,
@Advice.Thrown final Throwable throwable) {
DECORATE.onCompile(scope, jspCompilationContext);
// ^ Decorate on return because additional properties are available

Update jsp-2.3 to new agent api