Search in sources :

Example 1 with RpcInvocation

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);
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) Invoker(org.apache.dubbo.rpc.Invoker) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId)

Example 2 with RpcInvocation

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);
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) Invoker(org.apache.dubbo.rpc.Invoker) DubboInvoker(org.apache.dubbo.rpc.protocol.dubbo.DubboInvoker) DubboInvoker(org.apache.dubbo.rpc.protocol.dubbo.DubboInvoker) URL(org.apache.dubbo.common.URL) Test(org.junit.Test)

Example 3 with RpcInvocation

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();
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)

Example 4 with RpcInvocation

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);
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) DubboInvoker(org.apache.dubbo.rpc.protocol.dubbo.DubboInvoker) URL(org.apache.dubbo.common.URL) Test(org.junit.Test)

Example 5 with RpcInvocation

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);
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) Test(org.junit.Test)

Aggregations

RpcInvocation (org.apache.dubbo.rpc.RpcInvocation)172 Test (org.junit.jupiter.api.Test)122 URL (org.apache.dubbo.common.URL)101 Invoker (org.apache.dubbo.rpc.Invoker)65 ArrayList (java.util.ArrayList)51 Result (org.apache.dubbo.rpc.Result)38 Invocation (org.apache.dubbo.rpc.Invocation)36 RpcException (org.apache.dubbo.rpc.RpcException)26 RegistryDirectory (org.apache.dubbo.registry.integration.RegistryDirectory)23 AppResponse (org.apache.dubbo.rpc.AppResponse)20 MockClusterInvoker (org.apache.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker)20 Router (org.apache.dubbo.rpc.cluster.Router)19 MockInvoker (org.apache.dubbo.rpc.cluster.router.MockInvoker)18 HashMap (java.util.HashMap)16 AsyncRpcResult (org.apache.dubbo.rpc.AsyncRpcResult)16 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)14 Method (java.lang.reflect.Method)9 List (java.util.List)8 Person (org.apache.dubbo.rpc.support.Person)7 Protocol (org.apache.dubbo.rpc.Protocol)6