diff --git a/plugins/apache-dubbo/src/main/java/com/navercorp/pinpoint/plugin/apache/dubbo/interceptor/ApacheDubboConsumerInterceptor.java b/plugins/apache-dubbo/src/main/java/com/navercorp/pinpoint/plugin/apache/dubbo/interceptor/ApacheDubboConsumerInterceptor.java index 0762efd0306e..aad530b297ce 100644 --- a/plugins/apache-dubbo/src/main/java/com/navercorp/pinpoint/plugin/apache/dubbo/interceptor/ApacheDubboConsumerInterceptor.java +++ b/plugins/apache-dubbo/src/main/java/com/navercorp/pinpoint/plugin/apache/dubbo/interceptor/ApacheDubboConsumerInterceptor.java @@ -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(); @@ -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"); } } @@ -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); } @@ -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) { @@ -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); diff --git a/plugins/apache-dubbo/src/main/java/com/navercorp/pinpoint/plugin/apache/dubbo/interceptor/ApacheDubboProviderInterceptor.java b/plugins/apache-dubbo/src/main/java/com/navercorp/pinpoint/plugin/apache/dubbo/interceptor/ApacheDubboProviderInterceptor.java index bb78814fa54e..a2a81fdcc8f1 100644 --- a/plugins/apache-dubbo/src/main/java/com/navercorp/pinpoint/plugin/apache/dubbo/interceptor/ApacheDubboProviderInterceptor.java +++ b/plugins/apache-dubbo/src/main/java/com/navercorp/pinpoint/plugin/apache/dubbo/interceptor/ApacheDubboProviderInterceptor.java @@ -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. @@ -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); @@ -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 { @@ -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);