in geronimo-opentracing/src/main/java/org/apache/geronimo/microprofile/opentracing/microprofile/cdi/TracedInterceptor.java [65:109]
public Object trace(final InvocationContext context) throws Exception {
final Method method = context.getMethod();
Meta meta = metas.get(method);
if (meta == null) {
final AnnotatedType<?> annotatedType = beanManager.createAnnotatedType(bean.getBeanClass());
final Traced traced = requireNonNull(annotatedType.getMethods().stream()
.filter(m -> m.getJavaMember().equals(method))
.findFirst().map(m -> m.getAnnotation(Traced.class))
.orElseGet(() -> annotatedType.getAnnotation(Traced.class)), "no @Traced found on " + method);
meta = new Meta(
traced.value(),
Optional.of(traced.operationName())
.filter(v -> !v.isEmpty())
.orElseGet(() -> method.getDeclaringClass().getName() + "." + method.getName()));
metas.putIfAbsent(method, meta); // no big deal to not use the same meta instance
}
if (!meta.traced) {
return context.proceed();
}
final Tracer.SpanBuilder spanBuilder = tracer.buildSpan(meta.operationName);
final Scope parent = tracer.scopeManager().active();
if (parent != null) {
spanBuilder.asChildOf(parent.span());
}
Scope scope = null;
try {
scope = spanBuilder.startActive(true);
return context.proceed();
} catch (final RuntimeException re) {
if (scope != null) {
final Span span = scope.span();
Tags.ERROR.set(span, true);
final Map<String, Object> logs = new LinkedHashMap<>();
logs.put("event", Tags.ERROR.getKey());
logs.put("error.object", re);
span.log(logs);
}
throw re;
} finally {
if (scope != null) {
scope.close();
}
}
}