in geronimo-opentracing-extension/src/main/java/org/apache/geronimo/opentracing/extension/proxy/TracingProxyFactory.java [76:112]
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
final Tracer.SpanBuilder builder = tracer.buildSpan(method.getDeclaringClass().getName() + "." + method.getName());
builder.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER);
builder.withTag(Tags.COMPONENT.getKey(), "proxy");
tags.forEach(builder::withTag);
ofNullable(tracer.activeSpan()).ifPresent(builder::asChildOf);
final Scope scope = builder.startActive(false /*just handle span inheritance for async case*/);
boolean doFinish = true;
try {
final Object result = method.invoke(delegate, args);
if (CompletionStage.class.isInstance(result)) {
doFinish = false;
final CompletionStage<?> stage = CompletionStage.class.cast(result);
return stage.handle((r, e) -> {
try {
if (e != null) {
onError(scope, e);
return rethrow(e);
}
return r;
} finally {
scope.span().finish();
}
});
}
return result;
} catch (final InvocationTargetException ite) {
onError(scope, ite.getTargetException());
throw ite.getTargetException();
} finally {
if (doFinish) {
scope.span().finish();
}
scope.close();
}
}