Update dropwizard to new agent api
This commit is contained in:
parent
44f06ed3b5
commit
4ca63b7440
|
@ -1,7 +1,8 @@
|
||||||
package datadog.trace.instrumentation.dropwizard.view;
|
package datadog.trace.instrumentation.dropwizard.view;
|
||||||
|
|
||||||
import static datadog.trace.agent.tooling.ByteBuddyElementMatchers.safeHasSuperType;
|
import static datadog.trace.agent.tooling.ByteBuddyElementMatchers.safeHasSuperType;
|
||||||
import static io.opentracing.log.Fields.ERROR_OBJECT;
|
import static datadog.trace.instrumentation.api.AgentTracer.activateSpan;
|
||||||
|
import static datadog.trace.instrumentation.api.AgentTracer.startSpan;
|
||||||
import static java.util.Collections.singletonMap;
|
import static java.util.Collections.singletonMap;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
|
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
|
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
|
||||||
|
@ -13,12 +14,10 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||||
import com.google.auto.service.AutoService;
|
import com.google.auto.service.AutoService;
|
||||||
import datadog.trace.agent.tooling.Instrumenter;
|
import datadog.trace.agent.tooling.Instrumenter;
|
||||||
import datadog.trace.api.DDTags;
|
import datadog.trace.api.DDTags;
|
||||||
|
import datadog.trace.instrumentation.api.AgentScope;
|
||||||
|
import datadog.trace.instrumentation.api.AgentSpan;
|
||||||
import io.dropwizard.views.View;
|
import io.dropwizard.views.View;
|
||||||
import io.opentracing.Scope;
|
|
||||||
import io.opentracing.Span;
|
|
||||||
import io.opentracing.tag.Tags;
|
import io.opentracing.tag.Tags;
|
||||||
import io.opentracing.util.GlobalTracer;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import net.bytebuddy.asm.Advice;
|
import net.bytebuddy.asm.Advice;
|
||||||
import net.bytebuddy.description.method.MethodDescription;
|
import net.bytebuddy.description.method.MethodDescription;
|
||||||
|
@ -50,28 +49,24 @@ public final class DropwizardViewInstrumentation extends Instrumenter.Default {
|
||||||
public static class RenderAdvice {
|
public static class RenderAdvice {
|
||||||
|
|
||||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||||
public static Scope startSpan(
|
public static AgentScope onEnter(
|
||||||
@Advice.This final Object obj, @Advice.Argument(0) final View view) {
|
@Advice.This final Object obj, @Advice.Argument(0) final View view) {
|
||||||
final Scope scope =
|
final AgentSpan span =
|
||||||
GlobalTracer.get()
|
startSpan("view.render")
|
||||||
.buildSpan("view.render")
|
.setTag(DDTags.RESOURCE_NAME, "View " + view.getTemplateName())
|
||||||
.withTag(DDTags.RESOURCE_NAME, "View " + view.getTemplateName())
|
.setTag(Tags.COMPONENT.getKey(), "dropwizard-view")
|
||||||
.withTag(Tags.COMPONENT.getKey(), "dropwizard-view")
|
.setTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER)
|
||||||
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER)
|
.setTag("span.origin.type", obj.getClass().getSimpleName());
|
||||||
.withTag("span.origin.type", obj.getClass().getSimpleName())
|
return activateSpan(span, true);
|
||||||
.startActive(true);
|
|
||||||
|
|
||||||
return scope;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
||||||
public static void stopSpan(
|
public static void stopSpan(
|
||||||
@Advice.Enter final Scope scope, @Advice.Thrown final Throwable throwable) {
|
@Advice.Enter final AgentScope scope, @Advice.Thrown final Throwable throwable) {
|
||||||
|
final AgentSpan span = scope.span();
|
||||||
final Span span = scope.span();
|
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
Tags.ERROR.set(span, Boolean.TRUE);
|
span.setError(true);
|
||||||
span.log(Collections.singletonMap(ERROR_OBJECT, throwable));
|
span.addThrowable(throwable);
|
||||||
}
|
}
|
||||||
scope.close();
|
scope.close();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue