use of org.apache.dubbo.rpc.Result 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.Result in project brave by openzipkin.
the class ITTracingFilter_Provider method customParser.
@Test
public void customParser() {
Tag<DubboResponse> javaValue = new Tag<DubboResponse>("dubbo.result_value") {
@Override
protected String parseValue(DubboResponse input, TraceContext context) {
Result result = input.result();
if (result == null)
return null;
return String.valueOf(result.getValue());
}
};
RpcTracing rpcTracing = RpcTracing.newBuilder(tracing).serverResponseParser((res, context, span) -> {
RpcResponseParser.DEFAULT.parse(res, context, span);
if (res instanceof DubboResponse) {
javaValue.tag((DubboResponse) res, span);
}
}).build();
init().setRpcTracing(rpcTracing);
String javaResult = client.get().sayHello("jorge");
assertThat(testSpanHandler.takeRemoteSpan(SERVER).tags()).containsEntry("dubbo.result_value", javaResult);
}
Aggregations