Search in sources :

Example 1 with TracingFilter

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);
}
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 2 with TracingFilter

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;
}
Also used : TracingFilter(io.opentracing.contrib.web.servlet.filter.TracingFilter) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 3 with TracingFilter

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;
}
Also used : TracingFilter(io.opentracing.contrib.web.servlet.filter.TracingFilter) ServletFilterSpanDecorator(io.opentracing.contrib.web.servlet.filter.ServletFilterSpanDecorator) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

TracingFilter (io.opentracing.contrib.web.servlet.filter.TracingFilter)3 FilterRegistrationBean (org.springframework.boot.web.servlet.FilterRegistrationBean)2 Bean (org.springframework.context.annotation.Bean)2 Tracer (io.opentracing.Tracer)1 ServletFilterSpanDecorator (io.opentracing.contrib.web.servlet.filter.ServletFilterSpanDecorator)1 GlobalTracer (io.opentracing.util.GlobalTracer)1 Dynamic (javax.servlet.FilterRegistration.Dynamic)1 ServletContext (javax.servlet.ServletContext)1 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1