use of org.apache.dubbo.rpc.RpcContext in project brave by openzipkin.
the class DubboParser method parseRemoteIpAndPort.
static boolean parseRemoteIpAndPort(Span span) {
RpcContext rpcContext = RpcContext.getContext();
InetSocketAddress remoteAddress = rpcContext.getRemoteAddress();
if (remoteAddress == null)
return false;
return span.remoteIpAndPort(Platform.get().getHostString(remoteAddress), remoteAddress.getPort());
}
use of org.apache.dubbo.rpc.RpcContext in project brave by openzipkin.
the class TracingFilter method invoke.
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
if (!isInit)
return invoker.invoke(invocation);
TraceContext invocationContext = currentTraceContext.get();
RpcContext rpcContext = RpcContext.getContext();
Kind kind = rpcContext.isProviderSide() ? Kind.SERVER : Kind.CLIENT;
Span span;
DubboRequest request;
if (kind.equals(Kind.CLIENT)) {
// When A service invoke B service, then B service then invoke C service, the parentId of the
// C service span is A when read from invocation.getAttachments(). This is because
// AbstractInvoker adds attachments via RpcContext.getContext(), not the invocation.
// See org.apache.dubbo.rpc.protocol.AbstractInvoker(line 141) from v2.7.3
Map<String, String> attachments = RpcContext.getContext().getAttachments();
DubboClientRequest clientRequest = new DubboClientRequest(invoker, invocation, attachments);
request = clientRequest;
span = clientHandler.handleSendWithParent(clientRequest, invocationContext);
} else {
DubboServerRequest serverRequest = new DubboServerRequest(invoker, invocation);
request = serverRequest;
span = serverHandler.handleReceive(serverRequest);
}
boolean isSynchronous = true;
Scope scope = currentTraceContext.newScope(span.context());
Result result = null;
Throwable error = null;
try {
result = invoker.invoke(invocation);
error = result.getException();
CompletableFuture<Object> future = rpcContext.getCompletableFuture();
if (future != null) {
isSynchronous = false;
// NOTE: We don't currently instrument CompletableFuture, so callbacks will not see the
// invocation context unless they use an executor instrumented by CurrentTraceContext
// If we later instrument this, take care to use the correct context depending on RPC kind!
future.whenComplete(FinishSpan.create(this, request, result, span));
}
return result;
} catch (Throwable e) {
propagateIfFatal(e);
error = e;
throw e;
} finally {
if (isSynchronous)
FinishSpan.finish(this, request, result, error, span);
scope.close();
}
}
use of org.apache.dubbo.rpc.RpcContext in project pinpoint by naver.
the class ApacheDubboProviderInterceptor method recordRequest.
private void recordRequest(SpanRecorder recorder, Object target, Object[] args) {
final RpcInvocation invocation = (RpcInvocation) args[0];
final RpcContext rpcContext = RpcContext.getContext();
// Record rpc name, client address, server address.
recorder.recordRpcName(invocation.getInvoker().getInterface().getSimpleName() + ":" + invocation.getMethodName());
recorder.recordEndPoint(rpcContext.getLocalAddressString());
if (rpcContext.getRemoteHost() != null) {
recorder.recordRemoteAddress(rpcContext.getRemoteAddressString());
} else {
recorder.recordRemoteAddress("Unknown");
}
// 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);
if (parentApplicationName != null) {
final short parentApplicationType = NumberUtils.parseShort(invocation.getAttachment(ApacheDubboConstants.META_PARENT_APPLICATION_TYPE), ServiceType.UNDEFINED.getCode());
recorder.recordParentApplication(parentApplicationName, parentApplicationType);
final String host = invocation.getAttachment(ApacheDubboConstants.META_HOST);
if (host != null) {
recorder.recordAcceptorHost(host);
} else {
// old version fallback
final String estimatedLocalHost = getLocalHost(rpcContext);
if (estimatedLocalHost != null) {
recorder.recordAcceptorHost(estimatedLocalHost);
}
}
}
}
// clear attachments
this.clearAttachments(rpcContext);
}
Aggregations