Skip to content

Commit

Permalink
Resolve the issue of failing to retrieve attachments in dubbo 2.7.6+
Browse files Browse the repository at this point in the history
  • Loading branch information
steverao committed Dec 31, 2024
1 parent d69fd1a commit 0ac1bc6
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,29 @@
package io.opentelemetry.instrumentation.apachedubbo.v2_7;

import io.opentelemetry.context.propagation.TextMapGetter;
import java.lang.reflect.Method;
import java.util.Map;
import org.apache.dubbo.rpc.RpcInvocation;

enum DubboHeadersGetter implements TextMapGetter<DubboRequest> {
INSTANCE;

@Override
@SuppressWarnings("deprecation") // deprecation for dubbo 3.2.15
public Iterable<String> keys(DubboRequest request) {
return request.invocation().getAttachments().keySet();
RpcInvocation invocation = request.invocation();
Map<String, String> attachments = invocation.getAttachments();
// in 2.7.6+, type of attachments is StringToObjectMap, it doesn't contains keySet method.
if ("ObjectToStringMap".equals(attachments.getClass().getSimpleName())) {
Method getObjectAttachmentsMethod = null;
try {
getObjectAttachmentsMethod = invocation.getClass().getMethod("getObjectAttachments");
return ((Map<String, Object>) getObjectAttachmentsMethod.invoke(invocation)).keySet();
} catch (Exception e) {
// ignore
}
}
return invocation.getAttachments().keySet();
}

@Override
Expand Down

0 comments on commit 0ac1bc6

Please sign in to comment.