use of io.opentracing.contrib.web.servlet.filter.TracingFilter 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.contrib.web.servlet.filter.TracingFilter in project java-spring-web by opentracing-contrib.
the class SpringBootConfiguration method tracingFilter.
@Bean
public FilterRegistrationBean tracingFilter() {
TracingFilter tracingFilter = new TracingFilter(tracer, Collections.singletonList(ServletFilterSpanDecorator.STANDARD_TAGS), Pattern.compile("/health"));
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(tracingFilter);
filterRegistrationBean.addUrlPatterns("/*");
filterRegistrationBean.setOrder(Integer.MIN_VALUE);
filterRegistrationBean.setAsyncSupported(true);
return filterRegistrationBean;
}
use of io.opentracing.contrib.web.servlet.filter.TracingFilter in project java-spring-web by opentracing-contrib.
the class ServerTracingAutoConfiguration method tracingFilter.
@Bean
@ConditionalOnMissingBean(TracingFilter.class)
public FilterRegistrationBean tracingFilter(Tracer tracer, WebTracingProperties tracingConfiguration) {
log.info(format("Creating %s bean with %s mapped to %s, skip pattern is \"%s\"", FilterRegistrationBean.class.getSimpleName(), TracingFilter.class.getSimpleName(), tracingConfiguration.getUrlPatterns().toString(), tracingConfiguration.getSkipPattern()));
List<ServletFilterSpanDecorator> decorators = servletFilterSpanDecorator.getIfAvailable();
if (CollectionUtils.isEmpty(decorators)) {
decorators = Collections.singletonList(ServletFilterSpanDecorator.STANDARD_TAGS);
}
TracingFilter tracingFilter = new TracingFilter(tracer, decorators, tracingConfiguration.getSkipPattern());
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(tracingFilter);
filterRegistrationBean.setUrlPatterns(tracingConfiguration.getUrlPatterns());
filterRegistrationBean.setOrder(tracingConfiguration.getOrder());
filterRegistrationBean.setAsyncSupported(true);
return filterRegistrationBean;
}
Aggregations