Skip to content

Commit a9e1180

Browse files
committed
Optimize codes
1 parent 3cd545e commit a9e1180

File tree

1 file changed

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

1 file changed

+6
-4
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,20 @@
88
import io.opentelemetry.context.propagation.TextMapGetter;
99
import java.lang.reflect.Method;
1010
import java.util.Map;
11+
import java.util.Set;
1112
import org.apache.dubbo.rpc.RpcInvocation;
1213

1314
enum DubboHeadersGetter implements TextMapGetter<DubboRequest> {
1415
INSTANCE;
1516

1617
@Override
17-
@SuppressWarnings("unchecked") // unchecked for dubbo 2.7.6
18+
@SuppressWarnings("unchecked") // unchecked for 2.7.6, 2.7.7
1819
public Iterable<String> keys(DubboRequest request) {
1920
RpcInvocation invocation = request.invocation();
2021
Map<String, String> attachments = invocation.getAttachments();
21-
// in 2.7.6+, type of attachments is StringToObjectMap, it doesn't contain keySet method.
22-
if ("ObjectToStringMap".equals(attachments.getClass().getSimpleName())) {
22+
Set<String> keys = invocation.getAttachments().keySet();
23+
// In 2.7.6, 2.7.7, the StringToObjectMap implementation does not correctly retrieve the keySet.
24+
if (keys.size() == 0 && "ObjectToStringMap".equals(attachments.getClass().getSimpleName())) {
2325
Method getObjectAttachmentsMethod = null;
2426
try {
2527
getObjectAttachmentsMethod = invocation.getClass().getMethod("getObjectAttachments");
@@ -28,7 +30,7 @@ public Iterable<String> keys(DubboRequest request) {
2830
// ignore
2931
}
3032
}
31-
return invocation.getAttachments().keySet();
33+
return keys;
3234
}
3335

3436
@Override

0 commit comments

Comments
 (0)