Search in sources :

Example 1 with RpcInvocation

use of com.alibaba.dubbo.rpc.RpcInvocation in project pinpoint by naver.

the class DubboProviderInterceptor method doInAfterTrace.

@Override
protected void doInAfterTrace(SpanRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) {
    RpcInvocation invocation = (RpcInvocation) args[0];
    recorder.recordApi(methodDescriptor);
    recorder.recordAttribute(DubboConstants.DUBBO_ARGS_ANNOTATION_KEY, invocation.getArguments());
    if (throwable == null) {
        recorder.recordAttribute(DubboConstants.DUBBO_RESULT_ANNOTATION_KEY, result);
    } else {
        recorder.recordException(throwable);
    }
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation)

Example 2 with RpcInvocation

use of com.alibaba.dubbo.rpc.RpcInvocation in project pinpoint by naver.

the class DubboProviderInterceptor method createTrace.

@Override
protected Trace createTrace(Object target, Object[] args) {
    Invoker invoker = (Invoker) target;
    // Ignore monitor service.
    if (DubboConstants.MONITOR_SERVICE_FQCN.equals(invoker.getInterface().getName())) {
        return traceContext.disableSampling();
    }
    RpcInvocation invocation = (RpcInvocation) args[0];
    // If this transaction is not traceable, mark as disabled.
    if (invocation.getAttachment(DubboConstants.META_DO_NOT_TRACE) != null) {
        return traceContext.disableSampling();
    }
    String transactionId = invocation.getAttachment(DubboConstants.META_TRANSACTION_ID);
    // If there's no trasanction id, a new trasaction begins here.
    if (transactionId == null) {
        return traceContext.newTraceObject();
    }
    // otherwise, continue tracing with given data.
    long parentSpanID = NumberUtils.parseLong(invocation.getAttachment(DubboConstants.META_PARENT_SPAN_ID), SpanId.NULL);
    long spanID = NumberUtils.parseLong(invocation.getAttachment(DubboConstants.META_SPAN_ID), SpanId.NULL);
    short flags = NumberUtils.parseShort(invocation.getAttachment(DubboConstants.META_FLAGS), (short) 0);
    TraceId traceId = traceContext.createTraceId(transactionId, parentSpanID, spanID, flags);
    return traceContext.continueTraceObject(traceId);
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) Invoker(com.alibaba.dubbo.rpc.Invoker)

Example 3 with RpcInvocation

use of com.alibaba.dubbo.rpc.RpcInvocation in project pinpoint by naver.

the class DubboProviderInterceptor method doInBeforeTrace.

@Override
protected void doInBeforeTrace(SpanRecorder recorder, Object target, Object[] args) {
    RpcInvocation invocation = (RpcInvocation) args[0];
    RpcContext rpcContext = RpcContext.getContext();
    // You have to record a service type within Server range.
    recorder.recordServiceType(DubboConstants.DUBBO_PROVIDER_SERVICE_TYPE);
    // Record rpc name, client address, server address.
    recorder.recordRpcName(invocation.getInvoker().getInterface().getSimpleName() + ":" + invocation.getMethodName());
    recorder.recordEndPoint(rpcContext.getLocalAddressString());
    recorder.recordRemoteAddress(rpcContext.getRemoteAddressString());
    // If this transaction did not begin here, record parent(client who sent this request) information
    if (!recorder.isRoot()) {
        String parentApplicationName = invocation.getAttachment(DubboConstants.META_PARENT_APPLICATION_NAME);
        if (parentApplicationName != null) {
            short parentApplicationType = NumberUtils.parseShort(invocation.getAttachment(DubboConstants.META_PARENT_APPLICATION_TYPE), ServiceType.UNDEFINED.getCode());
            recorder.recordParentApplication(parentApplicationName, parentApplicationType);
            // Pinpoint finds caller - callee relation by matching caller's end point and callee's acceptor host.
            // https://github.com/naver/pinpoint/issues/1395
            recorder.recordAcceptorHost(rpcContext.getLocalAddressString());
        }
    }
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) RpcContext(com.alibaba.dubbo.rpc.RpcContext)

Example 4 with RpcInvocation

use of com.alibaba.dubbo.rpc.RpcInvocation in project dubbo by alibaba.

the class ExceptionFilterTest method testRpcException.

@SuppressWarnings("unchecked")
@Test
public void testRpcException() {
    Logger logger = EasyMock.createMock(Logger.class);
    RpcContext.getContext().setRemoteAddress("127.0.0.1", 1234);
    RpcException exception = new RpcException("TestRpcException");
    logger.error(EasyMock.eq("Got unchecked and undeclared exception which called by 127.0.0.1. service: " + DemoService.class.getName() + ", method: sayHello, exception: " + RpcException.class.getName() + ": TestRpcException"), EasyMock.eq(exception));
    ExceptionFilter exceptionFilter = new ExceptionFilter(logger);
    RpcInvocation invocation = new RpcInvocation("sayHello", new Class<?>[] { String.class }, new Object[] { "world" });
    Invoker<DemoService> invoker = EasyMock.createMock(Invoker.class);
    EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class);
    EasyMock.expect(invoker.invoke(EasyMock.eq(invocation))).andThrow(exception);
    EasyMock.replay(logger, invoker);
    try {
        exceptionFilter.invoke(invoker, invocation);
    } catch (RpcException e) {
        assertEquals("TestRpcException", e.getMessage());
    }
    EasyMock.verify(logger, invoker);
    RpcContext.removeContext();
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) RpcException(com.alibaba.dubbo.rpc.RpcException) DemoService(com.alibaba.dubbo.rpc.support.DemoService) Logger(com.alibaba.dubbo.common.logger.Logger) Test(org.junit.Test)

Example 5 with RpcInvocation

use of com.alibaba.dubbo.rpc.RpcInvocation in project dubbo by alibaba.

the class RpcUtilsTest method testAttachInvocationIdIfAsync_forceAttache.

/**
 * scenario: explicitly configure to add attachment
 * verify: id attribute added in attachment
 */
@Test
public void testAttachInvocationIdIfAsync_forceAttache() {
    URL url = URL.valueOf("dubbo://localhost/?" + Constants.AUTO_ATTACH_INVOCATIONID_KEY + "=true");
    Invocation inv = new RpcInvocation("test", new Class[] {}, new String[] {});
    RpcUtils.attachInvocationIdIfAsync(url, inv);
    Assert.assertNotNull(RpcUtils.getInvocationId(inv));
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) Invocation(com.alibaba.dubbo.rpc.Invocation) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Aggregations

RpcInvocation (com.alibaba.dubbo.rpc.RpcInvocation)110 Test (org.junit.Test)77 URL (com.alibaba.dubbo.common.URL)62 ArrayList (java.util.ArrayList)45 Invoker (com.alibaba.dubbo.rpc.Invoker)40 Result (com.alibaba.dubbo.rpc.Result)29 RegistryDirectory (com.alibaba.dubbo.registry.integration.RegistryDirectory)22 RpcException (com.alibaba.dubbo.rpc.RpcException)22 Router (com.alibaba.dubbo.rpc.cluster.Router)15 MockInvoker (com.alibaba.dubbo.rpc.cluster.router.MockInvoker)13 Invocation (com.alibaba.dubbo.rpc.Invocation)12 List (java.util.List)10 RpcResult (com.alibaba.dubbo.rpc.RpcResult)9 Method (java.lang.reflect.Method)6 Protocol (com.alibaba.dubbo.rpc.Protocol)4 MockProtocol (com.alibaba.dubbo.rpc.support.MockProtocol)4 RemotingException (com.alibaba.dubbo.remoting.RemotingException)3 TimeoutException (com.alibaba.dubbo.remoting.TimeoutException)3 Request (com.alibaba.dubbo.remoting.exchange.Request)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3