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

[#noissue]dubbo bugfix: cross-process propagation #8411

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void before(Object target, Object[] args) {
return;
}

final RpcInvocation invocation = (RpcInvocation) args[0];
final RpcContext context = RpcContext.getContext();

if (trace.canSampled()) {
final SpanEventRecorder recorder = trace.traceBlockBegin();
Expand All @@ -79,17 +79,17 @@ public void before(Object target, Object[] args) {
// Finally, pass some tracing data to the server.
// How to put them in a message is protocol specific.
// This example assumes that the target protocol message can include any metadata (like HTTP headers).
setAttachment(invocation, ApacheDubboConstants.META_TRANSACTION_ID, nextId.getTransactionId());
setAttachment(invocation, ApacheDubboConstants.META_SPAN_ID, Long.toString(nextId.getSpanId()));
setAttachment(invocation, ApacheDubboConstants.META_PARENT_SPAN_ID, Long.toString(nextId.getParentSpanId()));
setAttachment(invocation, ApacheDubboConstants.META_PARENT_APPLICATION_TYPE, Short.toString(traceContext.getServerTypeCode()));
setAttachment(invocation, ApacheDubboConstants.META_PARENT_APPLICATION_NAME, traceContext.getApplicationName());
setAttachment(invocation, ApacheDubboConstants.META_FLAGS, Short.toString(nextId.getFlags()));

setAttachment(invocation, ApacheDubboConstants.META_HOST, getHostAddress(invocation));
setAttachment(context, ApacheDubboConstants.META_TRANSACTION_ID, nextId.getTransactionId());
setAttachment(context, ApacheDubboConstants.META_SPAN_ID, Long.toString(nextId.getSpanId()));
setAttachment(context, ApacheDubboConstants.META_PARENT_SPAN_ID, Long.toString(nextId.getParentSpanId()));
setAttachment(context, ApacheDubboConstants.META_PARENT_APPLICATION_TYPE, Short.toString(traceContext.getServerTypeCode()));
setAttachment(context, ApacheDubboConstants.META_PARENT_APPLICATION_NAME, traceContext.getApplicationName());
setAttachment(context, ApacheDubboConstants.META_FLAGS, Short.toString(nextId.getFlags()));

setAttachment(context, ApacheDubboConstants.META_HOST, getHostAddress((RpcInvocation) args[0]));
} else {
// If sampling this transaction is disabled, pass only that infomation to the server.
setAttachment(invocation, ApacheDubboConstants.META_DO_NOT_TRACE, "1");
setAttachment(context, ApacheDubboConstants.META_DO_NOT_TRACE, "1");
}
}

Expand All @@ -98,8 +98,8 @@ private String getHostAddress(RpcInvocation invocation) {
return HostAndPort.toHostAndPortString(url.getHost(), url.getPort());
}

private void setAttachment(RpcInvocation invocation, String name, String value) {
invocation.setAttachment(name, value);
private void setAttachment(RpcContext context, String name, String value) {
context.setAttachment(name, value);
if (isDebug) {
logger.debug("Set attachment {}={}", name, value);
}
Expand All @@ -122,7 +122,6 @@ public void after(Object target, Object[] args, Object result, Throwable throwab
}

try {
final RpcInvocation invocation = (RpcInvocation) args[0];
final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
recorder.recordApi(descriptor);
if (throwable == null) {
Expand All @@ -132,7 +131,7 @@ public void after(Object target, Object[] args, Object result, Throwable throwab

// Optionally, record the destination id (logical name of server. e.g. DB name)
recorder.recordDestinationId(endPoint);
recorder.recordAttribute(ApacheDubboConstants.DUBBO_ARGS_ANNOTATION_KEY, invocation.getArguments());
recorder.recordAttribute(ApacheDubboConstants.DUBBO_ARGS_ANNOTATION_KEY, ((RpcInvocation) args[0]).getArguments());
recorder.recordAttribute(ApacheDubboConstants.DUBBO_RESULT_ANNOTATION_KEY, result);
} else {
recorder.recordException(throwable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ private Trace readRequestTrace(Object target, Object[] args) {
return traceContext.disableSampling();
}

final RpcInvocation invocation = (RpcInvocation) args[0];
final RpcContext context = RpcContext.getContext();
// If this transaction is not traceable, mark as disabled.
if (invocation.getAttachment(ApacheDubboConstants.META_DO_NOT_TRACE) != null) {
if (context.getAttachment(ApacheDubboConstants.META_DO_NOT_TRACE) != null) {
return traceContext.disableSampling();
}
final String transactionId = invocation.getAttachment(ApacheDubboConstants.META_TRANSACTION_ID);
final String transactionId = context.getAttachment(ApacheDubboConstants.META_TRANSACTION_ID);
// If there's no trasanction id, a new trasaction begins here.
// FIXME There seems to be cases where the invoke method is called after a span is already created.
// We'll have to check if a trace object already exists and create a span event instead of a span in that case.
Expand All @@ -84,9 +84,9 @@ private Trace readRequestTrace(Object target, Object[] args) {
}

// otherwise, continue tracing with given data.
final long parentSpanID = NumberUtils.parseLong(invocation.getAttachment(ApacheDubboConstants.META_PARENT_SPAN_ID), SpanId.NULL);
final long spanID = NumberUtils.parseLong(invocation.getAttachment(ApacheDubboConstants.META_SPAN_ID), SpanId.NULL);
final short flags = NumberUtils.parseShort(invocation.getAttachment(ApacheDubboConstants.META_FLAGS), (short) 0);
final long parentSpanID = NumberUtils.parseLong(context.getAttachment(ApacheDubboConstants.META_PARENT_SPAN_ID), SpanId.NULL);
final long spanID = NumberUtils.parseLong(context.getAttachment(ApacheDubboConstants.META_SPAN_ID), SpanId.NULL);
final short flags = NumberUtils.parseShort(context.getAttachment(ApacheDubboConstants.META_FLAGS), (short) 0);
final TraceId traceId = traceContext.createTraceId(transactionId, parentSpanID, spanID, flags);

return traceContext.continueTraceObject(traceId);
Expand All @@ -107,12 +107,12 @@ private void recordRequest(SpanRecorder recorder, Object target, Object[] args)

// If this transaction did not begin here, record parent(client who sent this request) information
if (!recorder.isRoot()) {
final String parentApplicationName = invocation.getAttachment(ApacheDubboConstants.META_PARENT_APPLICATION_NAME);
final String parentApplicationName = rpcContext.getAttachment(ApacheDubboConstants.META_PARENT_APPLICATION_NAME);
if (parentApplicationName != null) {
final short parentApplicationType = NumberUtils.parseShort(invocation.getAttachment(ApacheDubboConstants.META_PARENT_APPLICATION_TYPE), ServiceType.UNDEFINED.getCode());
final short parentApplicationType = NumberUtils.parseShort(rpcContext.getAttachment(ApacheDubboConstants.META_PARENT_APPLICATION_TYPE), ServiceType.UNDEFINED.getCode());
recorder.recordParentApplication(parentApplicationName, parentApplicationType);

final String host = invocation.getAttachment(ApacheDubboConstants.META_HOST);
final String host = rpcContext.getAttachment(ApacheDubboConstants.META_HOST);
if (host != null) {
recorder.recordAcceptorHost(host);
} else {
Expand Down Expand Up @@ -190,10 +190,9 @@ protected void doInBeforeTrace(SpanEventRecorder recorder, Object target, Object

@Override
protected void doInAfterTrace(SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) {
final RpcInvocation invocation = (RpcInvocation) args[0];
recorder.recordServiceType(ApacheDubboConstants.DUBBO_PROVIDER_SERVICE_NO_STATISTICS_TYPE);
recorder.recordApi(methodDescriptor);
recorder.recordAttribute(ApacheDubboConstants.DUBBO_ARGS_ANNOTATION_KEY, invocation.getArguments());
recorder.recordAttribute(ApacheDubboConstants.DUBBO_ARGS_ANNOTATION_KEY, ((RpcInvocation) args[0]).getArguments());

if (throwable == null) {
recorder.recordAttribute(ApacheDubboConstants.DUBBO_RESULT_ANNOTATION_KEY, result);
Expand Down