8
8
import io .opentelemetry .api .trace .SpanKind ;
9
9
import io .opentelemetry .instrumentation .annotations .WithSpan ;
10
10
import io .opentelemetry .instrumentation .api .semconv .util .SpanNames ;
11
- import java .lang .invoke .MethodHandle ;
12
- import java .lang .invoke .MethodHandles ;
13
- import java .lang .invoke .MethodType ;
14
11
import java .lang .reflect .Method ;
15
- import javax .annotation .Nullable ;
16
12
import org .aspectj .lang .JoinPoint ;
17
13
import org .aspectj .lang .reflect .MethodSignature ;
18
14
@@ -68,22 +64,6 @@ interface Factory {
68
64
69
65
static final class InstrumentationAnnotationFactory implements Factory {
70
66
71
- // The reason for using reflection here is that it needs to be compatible with the old version
72
- // of @WithSpan annotation that does not include the inheritContext option to avoid
73
- // NoSuchMethodError
74
- private static MethodHandle inheritContextMethodHandle = null ;
75
-
76
- static {
77
- try {
78
- inheritContextMethodHandle =
79
- MethodHandles .publicLookup ()
80
- .findVirtual (
81
- WithSpan .class , "inheritContext" , MethodType .methodType (boolean .class ));
82
- } catch (NoSuchMethodException | IllegalAccessException ignore ) {
83
- // ignore
84
- }
85
- }
86
-
87
67
@ Override
88
68
public JoinPointRequest create (JoinPoint joinPoint ) {
89
69
MethodSignature methodSignature = (MethodSignature ) joinPoint .getSignature ();
@@ -96,21 +76,9 @@ public JoinPointRequest create(JoinPoint joinPoint) {
96
76
WithSpan annotation = method .getDeclaredAnnotation (WithSpan .class );
97
77
String spanName = annotation != null ? annotation .value () : "" ;
98
78
SpanKind spanKind = annotation != null ? annotation .kind () : SpanKind .INTERNAL ;
79
+ boolean inheritContext = annotation == null || annotation .inheritContext ();
99
80
100
- return new JoinPointRequest (
101
- joinPoint , method , spanName , spanKind , inheritContextValueFrom (annotation ));
102
- }
103
-
104
- private static boolean inheritContextValueFrom (@ Nullable WithSpan annotation ) {
105
- if (annotation == null || inheritContextMethodHandle == null ) {
106
- return true ;
107
- }
108
-
109
- try {
110
- return (boolean ) inheritContextMethodHandle .invoke (annotation );
111
- } catch (Throwable ignore ) {
112
- return true ;
113
- }
81
+ return new JoinPointRequest (joinPoint , method , spanName , spanKind , inheritContext );
114
82
}
115
83
}
116
84
}
0 commit comments