use of io.opentracing.util.GlobalTracer 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);
}
use of io.opentracing.util.GlobalTracer in project java-spring-web by opentracing-contrib.
the class TracerAutoConfiguration method getTracer.
/**
* This method provides tracer if user did not specify any tracer bean.
* <p>
* The order of getting the tracer is:
* <ol>
* <li>Tracer registered in {@link GlobalTracer#register(Tracer)}</li>
* <li>Tracer resolved from {@link TracerResolver#resolve()}</li>
* <li>Default tracer, which is {@link io.opentracing.NoopTracer}</li>
* </ol>
* @return tracer
*/
@Bean
@ConditionalOnMissingBean(Tracer.class)
public Tracer getTracer() {
Tracer tracer;
if (GlobalTracer.isRegistered()) {
log.warn("GlobalTracer is already registered. For consistency it is best practice to provide " + "a Tracer bean instead of manually registering it with the GlobalTracer");
tracer = GlobalTracer.get();
} else {
tracer = TracerResolver.resolveTracer();
if (tracer == null) {
// WARNING: Don't return GlobalTracer.get() as this will result in a
// stack overflow if the returned tracer is subsequently wrapped by a
// BeanPostProcessor. The post processed tracer would then be registered
// with the {@link GlobalTracer) (via the {@link TracerRegisterAutoConfiguration})
// resulting in the wrapper both wrapping the GlobalTracer, as well as being
// the tracer used by the GlobalTracer.
tracer = NoopTracerFactory.create();
}
}
log.warn("Tracer bean is not configured! Switching to " + tracer);
return tracer;
}
Aggregations