Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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 @@ -26,6 +26,7 @@
import java.util.Collection;
import java.util.Map;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.asm.Advice.AssignReturned;
import net.bytebuddy.description.enumeration.EnumerationDescription;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.implementation.bytecode.assign.Assigner;
Expand Down Expand Up @@ -91,42 +92,46 @@ public void transform(TypeTransformer transformer) {
@SuppressWarnings("unused")
public static class MethodAdvice {

public static class AdviceLocals {
public MethodAndType classAndMethod;
public Context context;
public Scope scope;
}

@Advice.OnMethodEnter(suppress = Throwable.class)
public static void onEnter(
public static AdviceLocals onEnter(
@MethodSpanKind SpanKind spanKind,
@Advice.Origin("#t") Class<?> declaringClass,
@Advice.Origin("#m") String methodName,
@Advice.Local("otelMethod") MethodAndType classAndMethod,
@Advice.Local("otelContext") Context context,
@Advice.Local("otelScope") Scope scope) {
@Advice.Origin("#m") String methodName) {

AdviceLocals locals = new AdviceLocals();
Context parentContext = currentContext();
classAndMethod =
locals.classAndMethod =
MethodAndType.create(ClassAndMethod.create(declaringClass, methodName), spanKind);

if (!instrumenter().shouldStart(parentContext, classAndMethod)) {
return;
if (!instrumenter().shouldStart(parentContext, locals.classAndMethod)) {
return locals;
}

context = instrumenter().start(parentContext, classAndMethod);
scope = context.makeCurrent();
locals.context = instrumenter().start(parentContext, locals.classAndMethod);
locals.scope = locals.context.makeCurrent();
return locals;
}

@AssignReturned.ToReturned
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void stopSpan(
public static Object stopSpan(
@MethodReturnType Class<?> methodReturnType,
@Advice.Local("otelMethod") MethodAndType classAndMethod,
@Advice.Local("otelContext") Context context,
@Advice.Local("otelScope") Scope scope,
@Advice.Return(typing = Assigner.Typing.DYNAMIC, readOnly = false) Object returnValue,
@Advice.Thrown Throwable throwable) {
if (scope == null) {
return;
@Advice.Return(typing = Assigner.Typing.DYNAMIC) Object returnValue,
@Advice.Thrown Throwable throwable,
@Advice.Enter AdviceLocals locals) {
if (locals.scope == null) {
return returnValue;
}
scope.close();
locals.scope.close();

returnValue =
AsyncOperationEndSupport.create(instrumenter(), Void.class, methodReturnType)
.asyncEnd(context, classAndMethod, returnValue, throwable);
return AsyncOperationEndSupport.create(instrumenter(), Void.class, methodReturnType)
.asyncEnd(locals.context, locals.classAndMethod, returnValue, throwable);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
import io.opentelemetry.javaagent.bootstrap.internal.AgentInstrumentationConfig;
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.javaagent.tooling.config.MethodsConfigurationParser;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

@AutoService(InstrumentationModule.class)
public class MethodInstrumentationModule extends InstrumentationModule {
public class MethodInstrumentationModule extends InstrumentationModule
implements ExperimentalInstrumentationModule {

private static final String TRACE_METHODS_CONFIG = "otel.instrumentation.methods.include";

Expand Down Expand Up @@ -66,4 +68,9 @@ private static List<TypeInstrumentation> parseConfigProperties() {
public List<TypeInstrumentation> typeInstrumentations() {
return typeInstrumentations;
}

@Override
public boolean isIndyReady() {
return true;
}
}
Loading