Fix dropwizard instrumentation (#1607)
* Fix dropwizard instrumentation * Fix others too
This commit is contained in:
parent
7f36dd1617
commit
087a9cbc4e
|
@ -0,0 +1,26 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.javaagent.instrumentation.dropwizardviews;
|
||||||
|
|
||||||
|
import io.opentelemetry.api.trace.Span;
|
||||||
|
import io.opentelemetry.instrumentation.api.tracer.BaseTracer;
|
||||||
|
|
||||||
|
public class DropwizardTracer extends BaseTracer {
|
||||||
|
private static final DropwizardTracer TRACER = new DropwizardTracer();
|
||||||
|
|
||||||
|
public static DropwizardTracer tracer() {
|
||||||
|
return TRACER;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Span startSpan(String spanName) {
|
||||||
|
return super.startSpan(spanName, Span.Kind.INTERNAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getInstrumentationName() {
|
||||||
|
return "io.opentelemetry.auto.dropwizard-views-0.7";
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
package io.opentelemetry.javaagent.instrumentation.dropwizardviews;
|
package io.opentelemetry.javaagent.instrumentation.dropwizardviews;
|
||||||
|
|
||||||
|
import static io.opentelemetry.javaagent.instrumentation.dropwizardviews.DropwizardTracer.tracer;
|
||||||
import static io.opentelemetry.javaagent.tooling.ClassLoaderMatcher.hasClassesNamed;
|
import static io.opentelemetry.javaagent.tooling.ClassLoaderMatcher.hasClassesNamed;
|
||||||
import static io.opentelemetry.javaagent.tooling.bytebuddy.matcher.AgentElementMatchers.implementsInterface;
|
import static io.opentelemetry.javaagent.tooling.bytebuddy.matcher.AgentElementMatchers.implementsInterface;
|
||||||
import static java.util.Collections.singletonList;
|
import static java.util.Collections.singletonList;
|
||||||
|
@ -16,11 +17,7 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||||
|
|
||||||
import com.google.auto.service.AutoService;
|
import com.google.auto.service.AutoService;
|
||||||
import io.dropwizard.views.View;
|
import io.dropwizard.views.View;
|
||||||
import io.opentelemetry.api.OpenTelemetry;
|
|
||||||
import io.opentelemetry.api.trace.Span;
|
import io.opentelemetry.api.trace.Span;
|
||||||
import io.opentelemetry.api.trace.StatusCode;
|
|
||||||
import io.opentelemetry.api.trace.Tracer;
|
|
||||||
import io.opentelemetry.instrumentation.api.decorator.BaseDecorator;
|
|
||||||
import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge;
|
import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge;
|
||||||
import io.opentelemetry.javaagent.instrumentation.api.SpanWithScope;
|
import io.opentelemetry.javaagent.instrumentation.api.SpanWithScope;
|
||||||
import io.opentelemetry.javaagent.tooling.InstrumentationModule;
|
import io.opentelemetry.javaagent.tooling.InstrumentationModule;
|
||||||
|
@ -43,6 +40,11 @@ public final class DropwizardViewInstrumentationModule extends InstrumentationMo
|
||||||
return singletonList(new ViewRendererInstrumentation());
|
return singletonList(new ViewRendererInstrumentation());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] helperClassNames() {
|
||||||
|
return new String[] {packageName + ".DropwizardTracer"};
|
||||||
|
}
|
||||||
|
|
||||||
private static final class ViewRendererInstrumentation implements TypeInstrumentation {
|
private static final class ViewRendererInstrumentation implements TypeInstrumentation {
|
||||||
@Override
|
@Override
|
||||||
public ElementMatcher<ClassLoader> classLoaderMatcher() {
|
public ElementMatcher<ClassLoader> classLoaderMatcher() {
|
||||||
|
@ -67,19 +69,13 @@ public final class DropwizardViewInstrumentationModule extends InstrumentationMo
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class RenderAdvice {
|
public static class RenderAdvice {
|
||||||
private static final Tracer TRACER =
|
|
||||||
OpenTelemetry.getGlobalTracer("io.opentelemetry.auto.dropwizard-views-0.7");
|
|
||||||
|
|
||||||
public static Tracer tracer() {
|
|
||||||
return TRACER;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||||
public static SpanWithScope onEnter(@Advice.Argument(0) View view) {
|
public static SpanWithScope onEnter(@Advice.Argument(0) View view) {
|
||||||
if (!Java8BytecodeBridge.currentSpan().getSpanContext().isValid()) {
|
if (!Java8BytecodeBridge.currentSpan().getSpanContext().isValid()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Span span = tracer().spanBuilder("Render " + view.getTemplateName()).startSpan();
|
Span span = tracer().startSpan("Render " + view.getTemplateName());
|
||||||
return new SpanWithScope(span, span.makeCurrent());
|
return new SpanWithScope(span, span.makeCurrent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,11 +86,11 @@ public final class DropwizardViewInstrumentationModule extends InstrumentationMo
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Span span = spanWithScope.getSpan();
|
Span span = spanWithScope.getSpan();
|
||||||
if (throwable != null) {
|
if (throwable == null) {
|
||||||
span.setStatus(StatusCode.ERROR);
|
tracer().end(span);
|
||||||
BaseDecorator.addThrowable(span, throwable);
|
} else {
|
||||||
|
tracer().endExceptionally(span, throwable);
|
||||||
}
|
}
|
||||||
span.end();
|
|
||||||
spanWithScope.closeScope();
|
spanWithScope.closeScope();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ public class HibernateInstrumentationModule extends InstrumentationModule {
|
||||||
return new String[] {
|
return new String[] {
|
||||||
"io.opentelemetry.javaagent.instrumentation.hibernate.SessionMethodUtils",
|
"io.opentelemetry.javaagent.instrumentation.hibernate.SessionMethodUtils",
|
||||||
"io.opentelemetry.javaagent.instrumentation.hibernate.HibernateDecorator",
|
"io.opentelemetry.javaagent.instrumentation.hibernate.HibernateDecorator",
|
||||||
|
packageName + ".V3Advice",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ public class HibernateInstrumentationModule extends InstrumentationModule {
|
||||||
return new String[] {
|
return new String[] {
|
||||||
"io.opentelemetry.javaagent.instrumentation.hibernate.SessionMethodUtils",
|
"io.opentelemetry.javaagent.instrumentation.hibernate.SessionMethodUtils",
|
||||||
"io.opentelemetry.javaagent.instrumentation.hibernate.HibernateDecorator",
|
"io.opentelemetry.javaagent.instrumentation.hibernate.HibernateDecorator",
|
||||||
|
packageName + ".V4Advice",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,8 @@ public class NettyInstrumentationModule extends InstrumentationModule {
|
||||||
packageName + ".server.NettyRequestExtractAdapter",
|
packageName + ".server.NettyRequestExtractAdapter",
|
||||||
packageName + ".server.HttpServerRequestTracingHandler",
|
packageName + ".server.HttpServerRequestTracingHandler",
|
||||||
packageName + ".server.HttpServerResponseTracingHandler",
|
packageName + ".server.HttpServerResponseTracingHandler",
|
||||||
packageName + ".server.HttpServerTracingHandler"
|
packageName + ".server.HttpServerTracingHandler",
|
||||||
|
packageName + ".AbstractNettyAdvice"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue