use of org.apache.dubbo.rpc.RpcInvocation in project pinpoint by naver.
the class ApacheDubboProviderInterceptor method readRequestTrace.
private Trace readRequestTrace(Object target, Object[] args) {
final Invoker invoker = (Invoker) target;
// Ignore monitor service.
if (ApacheDubboConstants.MONITOR_SERVICE_FQCN.equals(invoker.getInterface().getName())) {
return traceContext.disableSampling();
}
final RpcInvocation invocation = (RpcInvocation) args[0];
// If this transaction is not traceable, mark as disabled.
if (invocation.getAttachment(ApacheDubboConstants.META_DO_NOT_TRACE) != null) {
return traceContext.disableSampling();
}
final String transactionId = invocation.getAttachment(ApacheDubboConstants.META_TRANSACTION_ID);
// We'll have to check if a trace object already exists and create a span event instead of a span in that case.
if (transactionId == null) {
return traceContext.newTraceObject();
}
// 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 TraceId traceId = traceContext.createTraceId(transactionId, parentSpanID, spanID, flags);
return traceContext.continueTraceObject(traceId);
}
use of org.apache.dubbo.rpc.RpcInvocation in project pinpoint by naver.
the class ApacheDubboProviderInterceptorTest method createTrace.
@Test
public void createTrace() {
doReturn(true).when(trace).canSampled();
doReturn(spanRecorder).when(trace).getSpanRecorder();
doReturn(trace).when(traceContext).newTraceObject();
Invoker invoker = new DubboInvoker(Object.class, new URL("http", "127.0.0.1", 8080), null);
ApacheDubboProviderInterceptor interceptor = new ApacheDubboProviderInterceptor(traceContext, descriptor);
RpcInvocation rpcInvocation = new RpcInvocation();
rpcInvocation.setInvoker(invoker);
rpcInvocation.setMethodName("test");
rpcInvocation.setAttachment(ApacheDubboConstants.META_PARENT_APPLICATION_NAME, UUID.randomUUID().toString());
Object[] args = new Object[] { rpcInvocation };
interceptor.createTrace(invoker, args);
}
use of org.apache.dubbo.rpc.RpcInvocation in project pinpoint by naver.
the class ApacheDubboConsumerInterceptor method after.
@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
if (isDebug) {
logger.afterInterceptor(target, args);
}
// Ignore monitor service
if (isMonitorService(target)) {
return;
}
final Trace trace = traceContext.currentTraceObject();
if (trace == null) {
return;
}
try {
final RpcInvocation invocation = (RpcInvocation) args[0];
final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
recorder.recordApi(descriptor);
if (throwable == null) {
String endPoint = RpcContext.getContext().getRemoteAddressString();
// RPC client have to record end point (server address)
recorder.recordEndPoint(endPoint);
// 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_RESULT_ANNOTATION_KEY, result);
} else {
recorder.recordException(throwable);
}
} finally {
trace.traceBlockEnd();
}
}
use of org.apache.dubbo.rpc.RpcInvocation in project pinpoint by naver.
the class ApacheDubboConsumerInterceptorTest method before.
@Test
public void before() {
doReturn(trace).when(traceContext).currentRawTraceObject();
doReturn(true).when(trace).canSampled();
doReturn(traceId).when(trace).getTraceId();
doReturn(nextId).when(traceId).getNextTraceId();
doReturn(spanRecorder).when(trace).traceBlockBegin();
ApacheDubboConsumerInterceptor interceptor = new ApacheDubboConsumerInterceptor(traceContext, descriptor);
RpcInvocation rpcInvocation = new RpcInvocation();
rpcInvocation.setInvoker(new DubboInvoker(Object.class, new URL("http", "127.0.0.1", 8080), null));
rpcInvocation.setMethodName("test");
Object[] args = new Object[] { rpcInvocation };
interceptor.before(obj, args);
}
use of org.apache.dubbo.rpc.RpcInvocation in project pinpoint by naver.
the class ApacheDubboConsumerInterceptorTest method after.
@Test
public void after() {
doReturn(trace).when(traceContext).currentTraceObject();
doReturn(spanRecorder).when(trace).currentSpanEventRecorder();
RpcInvocation rpcInvocation = new RpcInvocation();
Object[] args = new Object[] { rpcInvocation };
ApacheDubboConsumerInterceptor interceptor = new ApacheDubboConsumerInterceptor(traceContext, descriptor);
interceptor.after(obj, args, null, null);
}
Aggregations