Skip to content

Commit 065372d

Browse files
committed
Address review comments
1 parent b10b471 commit 065372d

File tree

1 file changed

+15
-5
lines changed
  • instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7

1 file changed

+15
-5
lines changed

instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboHeadersGetter.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,20 @@
1515
enum DubboHeadersGetter implements TextMapGetter<DubboRequest> {
1616
INSTANCE;
1717

18-
private static final MethodHandles.Lookup lookup = MethodHandles.lookup();
18+
private static final MethodHandle GET_OBJECT_ATTACHMENTS;
19+
20+
static {
21+
MethodHandles.Lookup lookup = MethodHandles.lookup();
22+
MethodHandle getObjectAttachments = null;
23+
try {
24+
getObjectAttachments =
25+
lookup.findStatic(
26+
RpcInvocation.class, "getObjectAttachments", MethodType.methodType(void.class));
27+
} catch (Throwable t) {
28+
// ignore
29+
}
30+
GET_OBJECT_ATTACHMENTS = getObjectAttachments;
31+
}
1932

2033
@Override
2134
@SuppressWarnings("unchecked") // unchecked for 2.7.6, 2.7.7
@@ -24,10 +37,7 @@ public Iterable<String> keys(DubboRequest request) {
2437
try {
2538
// In 2.7.6, 2.7.7, the StringToObjectMap implementation does not correctly retrieve the
2639
// keySet. Therefore, it's advisable to always call getObjectAttachments when it is available.
27-
MethodHandle getObjectAttachments =
28-
lookup.findStatic(
29-
RpcInvocation.class, "getObjectAttachments", MethodType.methodType(void.class));
30-
return ((Map<String, Object>) getObjectAttachments.invoke(invocation)).keySet();
40+
return ((Map<String, Object>) GET_OBJECT_ATTACHMENTS.invoke(invocation)).keySet();
3141
} catch (Throwable t) {
3242
// ignore
3343
}

0 commit comments

Comments
 (0)