Skip to content

Commit 22e27d8

Browse files
committed
Optimize codes
1 parent 52c2421 commit 22e27d8

File tree

1 file changed

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

1 file changed

+6
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import io.opentelemetry.context.propagation.TextMapGetter;
99
import java.lang.reflect.Method;
10+
import java.util.Collections;
1011
import java.util.Map;
1112
import org.apache.dubbo.rpc.RpcInvocation;
1213

@@ -17,17 +18,19 @@ enum DubboHeadersGetter implements TextMapGetter<DubboRequest> {
1718
@SuppressWarnings("unchecked") // unchecked for 2.7.6, 2.7.7
1819
public Iterable<String> keys(DubboRequest request) {
1920
RpcInvocation invocation = request.invocation();
20-
// In 2.7.6, 2.7.7, the StringToObjectMap implementation does not correctly retrieve the keySet,
21-
// so always call getObjectAttachments when it is present.
2221
try {
22+
// In 2.7.6, 2.7.7, the StringToObjectMap implementation does not correctly retrieve the keySet.
23+
// Therefore, it's advisable to always call getObjectAttachments when it is available.
2324
Method getObjectAttachmentsMethod = invocation.getClass().getMethod("getObjectAttachments");
2425
if (getObjectAttachmentsMethod != null) {
2526
return ((Map<String, Object>) getObjectAttachmentsMethod.invoke(invocation)).keySet();
27+
} else {
28+
return invocation.getAttachments().keySet();
2629
}
2730
} catch (Exception e) {
2831
// ignore
2932
}
30-
return invocation.getAttachments().keySet();
33+
return Collections.emptyList();
3134
}
3235

3336
@Override

0 commit comments

Comments
 (0)