Skip to content

Commit 70531f5

Browse files
committed
don't use context customizer
1 parent b32fb50 commit 70531f5

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/instrumentationannotations/AnnotationSingletons.java

+6-13
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import application.io.opentelemetry.instrumentation.annotations.WithSpan;
1111
import io.opentelemetry.api.GlobalOpenTelemetry;
12-
import io.opentelemetry.api.common.Attributes;
1312
import io.opentelemetry.api.trace.SpanKind;
1413
import io.opentelemetry.context.Context;
1514
import io.opentelemetry.instrumentation.api.annotation.support.MethodSpanAttributesExtractor;
@@ -67,7 +66,6 @@ private static Instrumenter<Method, Object> createInstrumenter() {
6766
INSTRUMENTATION_NAME,
6867
AnnotationSingletons::spanNameFromMethod)
6968
.addAttributesExtractor(CodeAttributesExtractor.create(MethodCodeAttributesGetter.INSTANCE))
70-
.addContextCustomizer(AnnotationSingletons::inheritContextFromMethod)
7169
.buildInstrumenter(AnnotationSingletons::spanKindFromMethod);
7270
}
7371

@@ -83,7 +81,6 @@ private static Instrumenter<MethodRequest, Object> createInstrumenterWithAttribu
8381
MethodRequest::method,
8482
WithSpanParameterAttributeNamesExtractor.INSTANCE,
8583
MethodRequest::args))
86-
.addContextCustomizer(AnnotationSingletons::inheritContextFromMethodRequest)
8784
.buildInstrumenter(AnnotationSingletons::spanKindFromMethodRequest);
8885
}
8986

@@ -126,27 +123,23 @@ private static String spanNameFromMethod(Method method) {
126123
return spanName;
127124
}
128125

129-
private static Context inheritContextFromMethodRequest(
130-
Context context, MethodRequest request, Attributes attributes) {
131-
return inheritContextFromMethod(context, request.method(), attributes);
126+
public static Context getContextForMethod(Method method) {
127+
return inheritContextFromMethod(method) ? Context.current() : Context.root();
132128
}
133129

134-
private static Context inheritContextFromMethod(
135-
Context context, Method method, Attributes attributes) {
130+
private static boolean inheritContextFromMethod(Method method) {
136131
if (inheritContextMethodHandle == null) {
137-
return context;
132+
return true;
138133
}
139134

140135
WithSpan annotation = method.getDeclaredAnnotation(WithSpan.class);
141-
142-
boolean inheritContext = true;
143136
try {
144-
inheritContext = (boolean) inheritContextMethodHandle.invoke(annotation);
137+
return (boolean) inheritContextMethodHandle.invoke(annotation);
145138
} catch (Throwable ignore) {
146139
// ignore
147140
}
148141

149-
return inheritContext ? context : Context.root();
142+
return true;
150143
}
151144

152145
private AnnotationSingletons() {}

instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/instrumentationannotations/WithSpanInstrumentation.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import io.opentelemetry.context.Scope;
2020
import io.opentelemetry.instrumentation.api.annotation.support.async.AsyncOperationEndSupport;
2121
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
22-
import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge;
2322
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
2423
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
2524
import java.lang.reflect.Method;
@@ -91,7 +90,7 @@ public static void onEnter(
9190
method = originMethod;
9291

9392
Instrumenter<Method, Object> instrumenter = instrumenter();
94-
Context current = Java8BytecodeBridge.currentContext();
93+
Context current = AnnotationSingletons.getContextForMethod(method);
9594

9695
if (instrumenter.shouldStart(current, method)) {
9796
context = instrumenter.start(current, method);
@@ -134,7 +133,7 @@ public static void onEnter(
134133
method = originMethod;
135134

136135
Instrumenter<MethodRequest, Object> instrumenter = instrumenterWithAttributes();
137-
Context current = Java8BytecodeBridge.currentContext();
136+
Context current = AnnotationSingletons.getContextForMethod(method);
138137
request = new MethodRequest(method, args);
139138

140139
if (instrumenter.shouldStart(current, request)) {

0 commit comments

Comments
 (0)