Search in sources :

Example 6 with RequestTracingService

use of fish.payara.nucleus.requesttracing.RequestTracingService in project Payara by payara.

the class JaxrsClientRequestTracingFilter method filter.

// After method invocation
@Override
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
    final PayaraTracingServices payaraTracingServices = new PayaraTracingServices();
    final RequestTracingService requestTracing = payaraTracingServices.getRequestTracingService();
    // If request tracing is enabled, and there's a trace actually in progress, add info about method
    if (requestTracing != null && requestTracing.isRequestTracingEnabled() && shouldTrace(requestContext)) {
        // Get the active span from the application's tracer instance
        Span activeSpan = payaraTracingServices.getActiveTracer().scopeManager().activeSpan();
        if (activeSpan == null) {
            // This should really only occur when enabling request tracing due to the nature of the
            // service not being enabled when making the request to enable it, and then
            // obviously being enabled on the return. Any other entrance into here is likely a bug
            // caused by a tracing context not being propagated.
            Logger.getLogger(JaxrsClientRequestTracingFilter.class.getName()).log(Level.FINE, "activeScope in opentracing request tracing filter was null for {0}", responseContext);
            return;
        }
        try {
            // Get the response status and add it to the active span
            StatusType statusInfo = responseContext.getStatusInfo();
            activeSpan.setTag(Tags.HTTP_STATUS.getKey(), statusInfo.getStatusCode());
            // If the response status is an error, add error info to the active span
            if (statusInfo.getFamily() == Family.CLIENT_ERROR || statusInfo.getFamily() == Family.SERVER_ERROR) {
                activeSpan.setTag(Tags.ERROR.getKey(), true);
                activeSpan.log(Collections.singletonMap("event", "error"));
                activeSpan.log(Collections.singletonMap("error.object", statusInfo.getFamily()));
            }
        } finally {
            activeSpan.finish();
            Object scopeObj = requestContext.getProperty(Scope.class.getName());
            if (scopeObj != null && scopeObj instanceof Scope) {
                try (Scope scope = (Scope) scopeObj) {
                    requestContext.removeProperty(Scope.class.getName());
                }
            }
        }
    }
}
Also used : Scope(io.opentracing.Scope) StatusType(javax.ws.rs.core.Response.StatusType) RequestTraceSpan(fish.payara.notification.requesttracing.RequestTraceSpan) Span(io.opentracing.Span) RequestTracingService(fish.payara.nucleus.requesttracing.RequestTracingService)

Example 7 with RequestTracingService

use of fish.payara.nucleus.requesttracing.RequestTracingService in project Payara by payara.

the class FaultToleranceServiceImpl method postConstruct.

@PostConstruct
public void postConstruct() {
    try {
        events.register(this);
        invocationManager = serviceLocator.getService(InvocationManager.class);
        requestTracingService = serviceLocator.getService(RequestTracingService.class);
        config = serviceLocator.getService(FaultToleranceServiceConfiguration.class);
        InitialContext context = new InitialContext();
        asyncExecutorService = (ManagedExecutorService) context.lookup(config.getManagedExecutorService());
        delayExecutorService = (ManagedScheduledExecutorService) context.lookup(config.getManagedScheduledExecutorService());
    } catch (NamingException namingException) {
        throw new RuntimeException("Error initialising Fault Tolerance Service: could not perform lookup for configured managed-executor-service or managed-scheduled-executor-service.", namingException);
    }
}
Also used : InvocationManager(org.glassfish.api.invocation.InvocationManager) NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext) RequestTracingService(fish.payara.nucleus.requesttracing.RequestTracingService) PostConstruct(javax.annotation.PostConstruct)

Aggregations

RequestTracingService (fish.payara.nucleus.requesttracing.RequestTracingService)7 RequestTraceSpan (fish.payara.notification.requesttracing.RequestTraceSpan)4 Span (io.opentracing.Span)3 Scope (io.opentracing.Scope)2 SpanContext (io.opentracing.SpanContext)2 Tracer (io.opentracing.Tracer)2 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)2 RequestTraceSpanContext (fish.payara.notification.requesttracing.RequestTraceSpanContext)1 OpenTracingService (fish.payara.opentracing.OpenTracingService)1 MapToTextMap (fish.payara.opentracing.propagation.MapToTextMap)1 SpanBuilder (io.opentracing.Tracer.SpanBuilder)1 HashMap (java.util.HashMap)1 PostConstruct (javax.annotation.PostConstruct)1 AroundInvoke (javax.interceptor.AroundInvoke)1 InitialContext (javax.naming.InitialContext)1 NamingException (javax.naming.NamingException)1 StatusType (javax.ws.rs.core.Response.StatusType)1 InvocationManager (org.glassfish.api.invocation.InvocationManager)1