use of fish.payara.requesttracing.jaxrs.client.PayaraTracingServices in project Payara by payara.
the class OpenTracingApplicationEventListener method postConstruct.
/**
* Initialization of internal services.
*/
@PostConstruct
public void postConstruct() {
LOG.finest("postConstruct()");
final PayaraTracingServices payaraTracingServices = new PayaraTracingServices();
this.requestTracing = payaraTracingServices.getRequestTracingService();
this.openTracing = payaraTracingServices.getOpenTracingService();
this.applicationName = payaraTracingServices.getApplicationName();
}
use of fish.payara.requesttracing.jaxrs.client.PayaraTracingServices in project Payara by payara.
the class TracedInterceptor method traceCdiCall.
/**
* If the tracing is enabled and possible for the invoked method, traces it's execution.
* If not, only executes the invocation context.
*
* @param invocationContext the context to be executed
* @return result of the invocation context execution.
* @throws Exception any execution thrown from the invocation context execution.
*/
@AroundInvoke
public Object traceCdiCall(final InvocationContext invocationContext) throws Exception {
LOG.fine(() -> "traceCdiCall(" + invocationContext + ")");
// Get the required HK2 services
final PayaraTracingServices payaraTracingServices = new PayaraTracingServices();
final OpenTracingService openTracing = payaraTracingServices.getOpenTracingService();
final InvocationManager invocationManager = payaraTracingServices.getInvocationManager();
// If Request Tracing is enabled, and this isn't a JaxRs method
if (//
openTracing == null || !openTracing.isEnabled() || isJaxRsMethod(invocationContext) || isWebServiceMethod(invocationContext, invocationManager)) {
// If request tracing was turned off, or this is a JaxRs method, just carry on
LOG.finest("The call is already monitored by some different component, proceeding the invocation.");
return invocationContext.proceed();
}
// Get the Traced annotation present on the method or class
final Traced traced = getAnnotation(beanManager, Traced.class, invocationContext);
// Get the enabled (value) variable from a config override, or from the annotation if there is no override
final boolean tracingEnabled = OpenTracingCdiUtils.getConfigOverrideValue(Traced.class, "value", invocationContext, boolean.class).orElse(traced.value());
// If we've explicitly been told not to trace the method: don't!
if (!tracingEnabled) {
LOG.finest("Tracing is not enabled, nothing to do.");
return invocationContext.proceed();
}
// If we *have* been told to, get the application's Tracer instance and start an active span.
final String applicationName = openTracing.getApplicationName(invocationManager, invocationContext);
final Tracer tracer = openTracing.getTracer(applicationName);
final String operationName = getOperationName(invocationContext, traced);
Span parentSpan = tracer.activeSpan();
final Span span = tracer.buildSpan(operationName).start();
try (Scope scope = tracer.scopeManager().activate(span)) {
try {
return invocationContext.proceed();
} catch (final Exception ex) {
LOG.log(Level.FINEST, "Setting the error to the active span ...", ex);
span.setTag(Tags.ERROR.getKey(), true);
final Map<String, Object> errorInfoMap = new HashMap<>();
errorInfoMap.put(Fields.EVENT, "error");
errorInfoMap.put(Fields.ERROR_OBJECT, ex.getClass().getName());
span.log(errorInfoMap);
throw ex;
}
} finally {
span.finish();
}
}
Aggregations