Search in sources :

Example 11 with Tracer

use of io.opentracing.Tracer in project wildfly-swarm by wildfly-swarm.

the class OpenTracingInitializer method contextInitialized.

@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
    ServletContext servletContext = servletContextEvent.getServletContext();
    String skipPatternAttribute = servletContext.getInitParameter(TracingFilter.SKIP_PATTERN);
    if (null != skipPatternAttribute && !skipPatternAttribute.isEmpty()) {
        servletContext.setAttribute(TracingFilter.SKIP_PATTERN, Pattern.compile(skipPatternAttribute));
    }
    logger.info("Registering Tracing Filter");
    Dynamic filterRegistration = servletContext.addFilter("tracingFilter", new TracingFilter());
    filterRegistration.setAsyncSupported(true);
    filterRegistration.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "*");
    String skipParameter = servletContext.getInitParameter("skipOpenTracingResolver");
    if (skipParameter != null && Boolean.parseBoolean(skipParameter)) {
        logger.info("OpenTracing automatic resolution is being explicitly skipped.");
        return;
    }
    if (GlobalTracer.isRegistered()) {
        logger.info("A Tracer is already registered at the GlobalTracer. Skipping resolution via TraceResolver.");
        return;
    }
    Tracer tracer = TracerResolver.resolveTracer();
    if (null == tracer) {
        logger.info("Could not get a valid OpenTracing Tracer from the classpath. Skipping.");
        return;
    }
    logger.info(String.format("Registering %s as the OpenTracing Tracer", tracer.getClass().getName()));
    GlobalTracer.register(tracer);
}
Also used : TracingFilter(io.opentracing.contrib.web.servlet.filter.TracingFilter) Dynamic(javax.servlet.FilterRegistration.Dynamic) Tracer(io.opentracing.Tracer) GlobalTracer(io.opentracing.util.GlobalTracer) ServletContext(javax.servlet.ServletContext)

Example 12 with Tracer

use of io.opentracing.Tracer in project wildfly by wildfly.

the class ResteasyClientTracingRegistrarProvider method configure.

@Override
public ClientBuilder configure(ClientBuilder clientBuilder, ExecutorService executorService) {
    ResteasyClientBuilder resteasyClientBuilder = (ResteasyClientBuilder) clientBuilder;
    Tracer tracer = CDI.current().select(Tracer.class).get();
    return resteasyClientBuilder.executorService(new TracedExecutorService(executorService, tracer)).register(new SmallRyeClientTracingFeature(tracer));
}
Also used : ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Tracer(io.opentracing.Tracer) TracedExecutorService(io.opentracing.contrib.concurrent.TracedExecutorService)

Example 13 with Tracer

use of io.opentracing.Tracer in project Payara by payara.

the class RemoteEjbClientIT method executeRemoteEjbMethodIT.

@Test
public void executeRemoteEjbMethodIT() throws NamingException {
    Properties contextProperties = new Properties();
    contextProperties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.enterprise.naming.SerialInitContextFactory");
    contextProperties.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
    contextProperties.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
    Context context = new InitialContext(contextProperties);
    EjbRemote ejb = (EjbRemote) context.lookup(String.format("java:global%sEjb", uri.getPath()));
    Tracer tracer = GlobalTracer.get();
    Span span = null;
    try {
        span = tracer.buildSpan("ExecuteEjb").start();
        tracer.activateSpan(span);
        span.setBaggageItem("Wibbles", "Wobbles");
        String baggageItems = ejb.annotatedMethod();
        Assert.assertTrue("Baggage items didn't match, received: " + baggageItems, baggageItems.contains("\nWibbles : Wobbles\n"));
        span.setBaggageItem("Nibbles", "Nobbles");
        baggageItems = ejb.nonAnnotatedMethod();
        Assert.assertTrue("Baggage items didn't match, received: " + baggageItems, baggageItems.contains("Wibbles : Wobbles") && baggageItems.contains("Nibbles : Nobbles"));
        span.setBaggageItem("Bibbles", "Bobbles");
        baggageItems = ejb.shouldNotBeTraced();
        Assert.assertTrue("Baggage items didn't match, received: " + baggageItems, baggageItems.contains("Wibbles : Wobbles") && baggageItems.contains("Nibbles : Nobbles") && baggageItems.contains("Bibbles : Bobbles"));
        baggageItems = ejb.editBaggageItems();
        Assert.assertTrue("Baggage items didn't match, received: " + baggageItems, baggageItems.contains("Wibbles : Wabbles") && baggageItems.contains("Nibbles : Nabbles") && baggageItems.contains("Bibbles : Babbles"));
    } finally {
        if (span != null) {
            span.finish();
        }
    }
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) Tracer(io.opentracing.Tracer) GlobalTracer(io.opentracing.util.GlobalTracer) Properties(java.util.Properties) Span(io.opentracing.Span) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 14 with Tracer

use of io.opentracing.Tracer in project Payara by payara.

the class SafeProperties method addEjbMethodTraceLog.

private void addEjbMethodTraceLog(CallFlowInfo info, boolean callEnter) {
    if (openTracingService.isEnabled()) {
        Tracer tracer = openTracingService.getTracer(openTracingService.getApplicationName(invocationManager));
        RequestTraceSpanLog spanLog = constructEjbMethodSpanLog(info, callEnter);
        if (tracer != null) {
            Span span = tracer.activeSpan();
            if (span != null) {
                span.log(spanLog.getTimeMillis(), spanLog.getLogEntries());
            } else {
                // Traces started in the pre-OpenTracing style won't have an active span, so just attempt to add as
                // is to thread local trace if there is one
                requestTracingService.addSpanLog(spanLog);
            }
        } else {
            // If we couldn't get a tracer here, it's because we couldn't get a name from the invocation manager.
            // In such a case, just try to add the span log to the currently active thread local request trace
            requestTracingService.addSpanLog(spanLog);
        }
    }
}
Also used : Tracer(io.opentracing.Tracer) RequestTraceSpanLog(fish.payara.notification.requesttracing.RequestTraceSpanLog) Span(io.opentracing.Span)

Example 15 with Tracer

use of io.opentracing.Tracer in project Payara by payara.

the class OpenTracingService method createTracer.

private synchronized Tracer createTracer(String applicationName) {
    // Does this NEED to be synchronised? Tracers don't store state, and Scopes are ThreadLocal
    // Double-checked locking - potentially naughty
    Tracer tracer = tracers.computeIfAbsent(applicationName, (appName) -> {
        Tracer newTracer = null;
        // Check which type of Tracer to create
        try {
            // See if an alternate implementation of Tracer is available in a library.
            ServiceLoader<Tracer> tracerLoader = ServiceLoader.load(Tracer.class);
            Iterator<Tracer> loadedTracer = tracerLoader.iterator();
            if (loadedTracer.hasNext()) {
                newTracer = loadedTracer.next();
            }
        } catch (NoClassDefFoundError ex) {
            logger.log(Level.SEVERE, "Unable to find Tracer implementation", ex);
        }
        if (newTracer == null) {
            newTracer = new fish.payara.opentracing.tracer.Tracer(appName, getRequestTracingService());
        }
        return newTracer;
    });
    return tracer;
}
Also used : Tracer(io.opentracing.Tracer)

Aggregations

Tracer (io.opentracing.Tracer)104 Span (io.opentracing.Span)49 SpanContext (io.opentracing.SpanContext)30 Map (java.util.Map)21 Vertx (io.vertx.core.Vertx)19 HashMap (java.util.HashMap)19 Test (org.junit.Test)19 BeforeEach (org.junit.jupiter.api.BeforeEach)19 Test (org.junit.jupiter.api.Test)19 Future (io.vertx.core.Future)18 Buffer (io.vertx.core.buffer.Buffer)16 HttpURLConnection (java.net.HttpURLConnection)14 EventBus (io.vertx.core.eventbus.EventBus)13 JsonObject (io.vertx.core.json.JsonObject)12 Objects (java.util.Objects)12 Logger (org.slf4j.Logger)11 LoggerFactory (org.slf4j.LoggerFactory)11 Tags (io.opentracing.tag.Tags)9 Scope (io.opentracing.Scope)8 GlobalTracer (io.opentracing.util.GlobalTracer)8