Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -46,4 +48,9 @@ public List<TypeInstrumentation> typeInstrumentations() {
new MeterInstrumentation(),
new TimerInstrumentation());
}

@Override
public boolean isIndyReady() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -22,4 +24,9 @@ public DropwizardInstrumentationModule() {
public List<TypeInstrumentation> typeInstrumentations() {
return singletonList(new DropwizardRendererInstrumentation());
}

@Override
public boolean isIndyReady() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Loading