diff --git a/instrumentation/dropwizard/dropwizard-metrics-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/dropwizardmetrics/DropwizardMetricsInstrumentationModule.java b/instrumentation/dropwizard/dropwizard-metrics-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/dropwizardmetrics/DropwizardMetricsInstrumentationModule.java index 4ab8d92e57c9..fdbd19a42ebe 100644 --- a/instrumentation/dropwizard/dropwizard-metrics-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/dropwizardmetrics/DropwizardMetricsInstrumentationModule.java +++ b/instrumentation/dropwizard/dropwizard-metrics-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/dropwizardmetrics/DropwizardMetricsInstrumentationModule.java @@ -12,12 +12,14 @@ import com.google.auto.service.AutoService; import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; +import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import java.util.List; import net.bytebuddy.matcher.ElementMatcher; @AutoService(InstrumentationModule.class) -public class DropwizardMetricsInstrumentationModule extends InstrumentationModule { +public class DropwizardMetricsInstrumentationModule extends InstrumentationModule + implements ExperimentalInstrumentationModule { public DropwizardMetricsInstrumentationModule() { super("dropwizard-metrics", "dropwizard-metrics-4.0"); @@ -46,4 +48,9 @@ public List typeInstrumentations() { new MeterInstrumentation(), new TimerInstrumentation()); } + + @Override + public boolean isIndyReady() { + return true; + } } diff --git a/instrumentation/dropwizard/dropwizard-views-0.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/dropwizardviews/DropwizardInstrumentationModule.java b/instrumentation/dropwizard/dropwizard-views-0.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/dropwizardviews/DropwizardInstrumentationModule.java index 6f7b985ee7a4..3c876b2f21f4 100644 --- a/instrumentation/dropwizard/dropwizard-views-0.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/dropwizardviews/DropwizardInstrumentationModule.java +++ b/instrumentation/dropwizard/dropwizard-views-0.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/dropwizardviews/DropwizardInstrumentationModule.java @@ -10,10 +10,12 @@ import com.google.auto.service.AutoService; import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; +import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule; import java.util.List; @AutoService(InstrumentationModule.class) -public class DropwizardInstrumentationModule extends InstrumentationModule { +public class DropwizardInstrumentationModule extends InstrumentationModule + implements ExperimentalInstrumentationModule { public DropwizardInstrumentationModule() { super("dropwizard-views", "dropwizard-views-0.7"); } @@ -22,4 +24,9 @@ public DropwizardInstrumentationModule() { public List typeInstrumentations() { return singletonList(new DropwizardRendererInstrumentation()); } + + @Override + public boolean isIndyReady() { + return true; + } } diff --git a/instrumentation/dropwizard/dropwizard-views-0.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/dropwizardviews/DropwizardRendererInstrumentation.java b/instrumentation/dropwizard/dropwizard-views-0.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/dropwizardviews/DropwizardRendererInstrumentation.java index 2b1332155c67..eab800b9e17c 100644 --- a/instrumentation/dropwizard/dropwizard-views-0.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/dropwizardviews/DropwizardRendererInstrumentation.java +++ b/instrumentation/dropwizard/dropwizard-views-0.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/dropwizardviews/DropwizardRendererInstrumentation.java @@ -14,11 +14,12 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument; import io.dropwizard.views.View; +import io.opentelemetry.api.trace.Span; import io.opentelemetry.context.Context; import io.opentelemetry.context.Scope; -import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; +import javax.annotation.Nullable; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.matcher.ElementMatcher; @@ -47,37 +48,50 @@ public void transform(TypeTransformer transformer) { @SuppressWarnings("unused") public static class RenderAdvice { - @Advice.OnMethodEnter(suppress = Throwable.class) - public static void onEnter( - @Advice.Argument(0) View view, - @Advice.Local("otelContext") Context context, - @Advice.Local("otelScope") Scope scope) { + public static class AdviceScope { + private final Context context; + private final Scope scope; + + private AdviceScope(Context context, Scope scope) { + this.context = context; + this.scope = scope; + } - Context parentContext = Java8BytecodeBridge.currentContext(); + @Nullable + public static AdviceScope start(View view) { + Context parentContext = Context.current(); - // don't start a new top-level span - if (!Java8BytecodeBridge.spanFromContext(parentContext).getSpanContext().isValid()) { - return; + // don't start a new top-level span + if (!Span.fromContext(parentContext).getSpanContext().isValid()) { + return null; + } + if (!instrumenter().shouldStart(parentContext, view)) { + return null; + } + + Context context = instrumenter().start(parentContext, view); + return new AdviceScope(context, context.makeCurrent()); } - if (!instrumenter().shouldStart(parentContext, view)) { - return; + + public void end(View view, @Nullable Throwable throwable) { + scope.close(); + instrumenter().end(context, view, null, throwable); } + } - context = instrumenter().start(parentContext, view); - scope = context.makeCurrent(); + @Advice.OnMethodEnter(suppress = Throwable.class) + public static AdviceScope onEnter(@Advice.Argument(0) View view) { + return AdviceScope.start(view); } @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) public static void stopSpan( @Advice.Argument(0) View view, - @Advice.Thrown Throwable throwable, - @Advice.Local("otelContext") Context context, - @Advice.Local("otelScope") Scope scope) { - if (scope == null) { - return; + @Advice.Thrown @Nullable Throwable throwable, + @Advice.Enter @Nullable AdviceScope adviceScope) { + if (adviceScope != null) { + adviceScope.end(view, throwable); } - scope.close(); - instrumenter().end(context, view, null, throwable); } } }