diff --git a/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboHeadersGetter.java b/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboHeadersGetter.java index 17e46d2d6286..9a91dc25d791 100644 --- a/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboHeadersGetter.java +++ b/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboHeadersGetter.java @@ -8,18 +8,20 @@ import io.opentelemetry.context.propagation.TextMapGetter; import java.lang.reflect.Method; import java.util.Map; +import java.util.Set; import org.apache.dubbo.rpc.RpcInvocation; enum DubboHeadersGetter implements TextMapGetter { INSTANCE; @Override - @SuppressWarnings("unchecked") // unchecked for dubbo 2.7.6 + @SuppressWarnings("unchecked") // unchecked for 2.7.6, 2.7.7 public Iterable keys(DubboRequest request) { RpcInvocation invocation = request.invocation(); Map attachments = invocation.getAttachments(); - // in 2.7.6+, type of attachments is StringToObjectMap, it doesn't contain keySet method. - if ("ObjectToStringMap".equals(attachments.getClass().getSimpleName())) { + Set keys = invocation.getAttachments().keySet(); + // In 2.7.6, 2.7.7, the StringToObjectMap implementation does not correctly retrieve the keySet. + if (keys.size() == 0 && "ObjectToStringMap".equals(attachments.getClass().getSimpleName())) { Method getObjectAttachmentsMethod = null; try { getObjectAttachmentsMethod = invocation.getClass().getMethod("getObjectAttachments"); @@ -28,7 +30,7 @@ public Iterable keys(DubboRequest request) { // ignore } } - return invocation.getAttachments().keySet(); + return keys; } @Override