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);
}
}
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);
}
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());
}
}
}
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();
}
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));
}
Aggregations