From 621d49b8bffac60ba8cbf370b6cddb719d9d1d88 Mon Sep 17 00:00:00 2001 From: Gregory Wolf Date: Sun, 16 Sep 2018 14:56:54 +0200 Subject: [PATCH 1/2] Search for skipPattern in servletcontext if none is defined by Builder --- .../contrib/jaxrs2/server/ServerTracingFilter.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/server/ServerTracingFilter.java b/opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/server/ServerTracingFilter.java index 1cc1dea..981ae47 100644 --- a/opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/server/ServerTracingFilter.java +++ b/opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/server/ServerTracingFilter.java @@ -31,7 +31,12 @@ @Priority(Priorities.HEADER_DECORATOR) public class ServerTracingFilter implements ContainerRequestFilter, ContainerResponseFilter { private static final Logger log = Logger.getLogger(ServerTracingFilter.class.getName()); - + + /** + * Use as a key of {@link ServletContext#setAttribute(String, Object)} to skip pattern + */ + public static final String SKIP_PATTERN = ServerTracingFilter.class.getName() + ".skipPattern"; + private Tracer tracer; private List spanDecorators; private String operationName; @@ -128,6 +133,13 @@ public void filter(ContainerRequestContext requestContext, private boolean matchesSkipPattern(ContainerRequestContext requestContext) { // skip URLs matching skip pattern // e.g. pattern is defined as '/health|/status' then URL 'http://localhost:5000/context/health' won't be traced + if (skipPattern == null && httpServletRequest.getServletContext() != null) { + Object contextAttribute = httpServletRequest.getServletContext().getAttribute(SKIP_PATTERN); + if (contextAttribute instanceof Pattern) { + skipPattern = (Pattern) contextAttribute; + } + } + if (skipPattern != null) { String path = requestContext.getUriInfo().getPath(); if (path.charAt(0) != '/') { From d872ef0b7a1529a97391a54c8481010aecac30e9 Mon Sep 17 00:00:00 2001 From: Gregory Wolf Date: Sun, 16 Sep 2018 15:11:53 +0200 Subject: [PATCH 2/2] add check if httpServletRequest is not null --- .../opentracing/contrib/jaxrs2/server/ServerTracingFilter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/server/ServerTracingFilter.java b/opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/server/ServerTracingFilter.java index 981ae47..d1d4e65 100644 --- a/opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/server/ServerTracingFilter.java +++ b/opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/server/ServerTracingFilter.java @@ -133,7 +133,7 @@ public void filter(ContainerRequestContext requestContext, private boolean matchesSkipPattern(ContainerRequestContext requestContext) { // skip URLs matching skip pattern // e.g. pattern is defined as '/health|/status' then URL 'http://localhost:5000/context/health' won't be traced - if (skipPattern == null && httpServletRequest.getServletContext() != null) { + if (skipPattern == null && httpServletRequest != null && httpServletRequest.getServletContext() != null) { Object contextAttribute = httpServletRequest.getServletContext().getAttribute(SKIP_PATTERN); if (contextAttribute instanceof Pattern) { skipPattern = (Pattern) contextAttribute;