Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve the issue of failing to retrieve attachments in dubbo 2.7.6 and 2.7.7 #12982

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,31 @@
package io.opentelemetry.instrumentation.apachedubbo.v2_7;

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<DubboRequest> {
INSTANCE;

@Override
@SuppressWarnings("deprecation") // deprecation for dubbo 3.2.15
@SuppressWarnings("unchecked") // unchecked for 2.7.6, 2.7.7
public Iterable<String> keys(DubboRequest request) {
return request.invocation().getAttachments().keySet();
RpcInvocation invocation = request.invocation();
steverao marked this conversation as resolved.
Show resolved Hide resolved
Map<String, String> attachments = invocation.getAttachments();
Set<String> 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");
return ((Map<String, Object>) getObjectAttachmentsMethod.invoke(invocation)).keySet();
} catch (Exception e) {
// ignore
}
}
return keys;
}

@Override
Expand Down
Loading