Search in sources :

Example 1 with Traced

use of org.eclipse.microprofile.opentracing.Traced in project Payara by payara.

the class Ejb method shouldNotBeTraced.

/**
 * This method itself should not be traced.
 *
 * @return The current baggage items
 */
@Override
@Traced(false)
public String shouldNotBeTraced() {
    randomSleep();
    Span activeSpan = tracer.activeSpan();
    if (activeSpan != null) {
        return getBaggageItems(activeSpan);
    } else {
        return "Nothing found!";
    }
}
Also used : Span(io.opentracing.Span) Traced(org.eclipse.microprofile.opentracing.Traced)

Example 2 with Traced

use of org.eclipse.microprofile.opentracing.Traced in project Payara by payara.

the class Ejb method annotatedMethod.

/**
 * This method should be traced with a custom name
 *
 * @return The current baggage items
 */
@Override
@Traced(operationName = "customName")
public String annotatedMethod() {
    randomSleep();
    Span activeSpan = tracer.activeSpan();
    if (activeSpan != null) {
        return getBaggageItems(activeSpan);
    } else {
        return "Nothing found!";
    }
}
Also used : Span(io.opentracing.Span) Traced(org.eclipse.microprofile.opentracing.Traced)

Example 3 with Traced

use of org.eclipse.microprofile.opentracing.Traced in project Payara by payara.

the class JaxwsContainerRequestTracingFilter method filterResponse.

// After method invocation
@Override
public void filterResponse(Packet pipeRequest, Packet pipeResponse, MonitorContext monitorContext) {
    // Try block so that we can always attach error info if there is any
    try {
        // If request tracing is enabled, and there is a trace in progress (which there should be!)
        if (isTraceInProgress()) {
            // Get the Traced annotation from the target method if CDI is initialised
            Traced tracedAnnotation = getTraceAnnotation(monitorContext);
            // pattern and a traced annotation set to true (via annotation or config override)
            if (shouldTrace(pipeRequest) && shouldTrace(monitorContext, tracedAnnotation)) {
                Span activeSpan = getTracer().scopeManager().activeSpan();
                if (activeSpan == null) {
                    return;
                }
                HttpServletRequest httpRequest = (HttpServletRequest) pipeRequest.get(SERVLET_REQUEST);
                try {
                    // Get and add the response status to the active span
                    Response.StatusType statusInfo = getResponseStatus(pipeRequest, pipeRequest);
                    activeSpan.setTag(HTTP_STATUS.getKey(), statusInfo.getStatusCode());
                    // If the response status is an error, add error information to the span
                    if (statusInfo.getFamily() == CLIENT_ERROR || statusInfo.getFamily() == SERVER_ERROR) {
                        activeSpan.setTag(ERROR.getKey(), true);
                        activeSpan.log(singletonMap("event", "error"));
                        // If there's an attached exception, add it to the span
                        Message message = pipeResponse.getMessage();
                        if (message != null && message.isFault()) {
                            activeSpan.log(singletonMap("error.object", getErrorObject(message)));
                        }
                    }
                } finally {
                    activeSpan.finish();
                    Object scopeObj = httpRequest.getAttribute(Scope.class.getName());
                    if (scopeObj != null && scopeObj instanceof Scope) {
                        try (Scope scope = (Scope) scopeObj) {
                            httpRequest.removeAttribute(Scope.class.getName());
                        }
                    }
                }
            }
        }
    } finally {
        // If there's an attached error on the response, log the exception
        Message message = pipeResponse.getMessage();
        if (message != null && message.isFault()) {
            Object errorObject = getErrorObject(message);
            if (errorObject != null) {
                // TODO: have an actual detail formatter for fault
                logger.log(SEVERE, getErrorObject(message).toString());
            }
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Response(javax.ws.rs.core.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) Traced(org.eclipse.microprofile.opentracing.Traced) Message(com.sun.xml.ws.api.message.Message) Scope(io.opentracing.Scope) Span(io.opentracing.Span)

Example 4 with Traced

use of org.eclipse.microprofile.opentracing.Traced in project Payara by payara.

the class OpenTracingRequestEventListener method determineOperationName.

/**
 * Helper method that determines what the operation name of the span.
 * Depends on completely initialized resourceInfo.
 *
 * @return The name to use as the Span's operation name
 */
private String determineOperationName(final ContainerRequestContext request, final Traced tracedAnnotation) {
    if (tracedAnnotation != null) {
        String operationName = OpenTracingCdiUtils.getConfigOverrideValue(Traced.class, "operationName", resourceInfo, String.class).orElse(tracedAnnotation.operationName());
        // followed by the method signature
        if (operationName.equals("")) {
            operationName = request.getMethod() + ":" + resourceInfo.getResourceClass().getCanonicalName() + "." + resourceInfo.getResourceMethod().getName();
        }
        return operationName;
    }
    // If there is no @Traced annotation
    final Config config = getConfig();
    // Determine if an operation name provider has been given
    final Optional<String> operationNameProviderOptional = config == null ? Optional.empty() : config.getOptionalValue("mp.opentracing.server.operation-name-provider", String.class);
    if (operationNameProviderOptional.isPresent()) {
        final String operationNameProvider = operationNameProviderOptional.get();
        final Path classLevelAnnotation = resourceInfo.getResourceClass().getAnnotation(Path.class);
        final Path methodLevelAnnotation = resourceInfo.getResourceMethod().getAnnotation(Path.class);
        // If the provider is set to "http-path" and the class-level @Path annotation is actually present
        if (operationNameProvider.equals("http-path") && classLevelAnnotation != null) {
            String operationName = request.getMethod() + ":";
            if (classLevelAnnotation.value().startsWith("/")) {
                operationName += classLevelAnnotation.value();
            } else {
                operationName += "/" + classLevelAnnotation.value();
            }
            // If the method-level @Path annotation is present, use its value
            if (methodLevelAnnotation != null) {
                if (methodLevelAnnotation.value().startsWith("/")) {
                    operationName += methodLevelAnnotation.value();
                } else {
                    operationName += "/" + methodLevelAnnotation.value();
                }
            }
            return operationName;
        }
    }
    // If we haven't returned by now, just go with the default ("class-method")
    return request.getMethod() + ":" + resourceInfo.getResourceClass().getCanonicalName() + "." + resourceInfo.getResourceMethod().getName();
}
Also used : Path(javax.ws.rs.Path) Traced(org.eclipse.microprofile.opentracing.Traced) Config(org.eclipse.microprofile.config.Config)

Example 5 with Traced

use of org.eclipse.microprofile.opentracing.Traced in project quickstart by wildfly.

the class ExplicitlyTracedBean method getHello.

@Traced
public String getHello() {
    Span prepareHelloSpan = tracer.buildSpan("prepare-hello").start();
    String hello = "hello";
    Span processHelloSpan = tracer.buildSpan("process-hello").start();
    hello = hello.toUpperCase();
    processHelloSpan.finish();
    prepareHelloSpan.finish();
    return hello;
}
Also used : Span(io.opentracing.Span) Traced(org.eclipse.microprofile.opentracing.Traced)

Aggregations

Traced (org.eclipse.microprofile.opentracing.Traced)9 Span (io.opentracing.Span)6 Scope (io.opentracing.Scope)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 Tracer (io.opentracing.Tracer)2 Config (org.eclipse.microprofile.config.Config)2 Message (com.sun.xml.ws.api.message.Message)1 OpenTracingService (fish.payara.opentracing.OpenTracingService)1 PayaraTracingServices (fish.payara.requesttracing.jaxrs.client.PayaraTracingServices)1 SpanContext (io.opentracing.SpanContext)1 SpanBuilder (io.opentracing.Tracer.SpanBuilder)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AroundInvoke (javax.interceptor.AroundInvoke)1 WebMethod (javax.jws.WebMethod)1 WebService (javax.jws.WebService)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Path (javax.ws.rs.Path)1 Response (javax.ws.rs.core.Response)1 InvocationManager (org.glassfish.api.invocation.InvocationManager)1