opentracing-contrib / java-spring-web

OpenTracing Spring Web instrumentation
Apache License 2.0
107 stars 59 forks source link

increase the visibility of shouldFilter. #126

Closed sijuv closed 4 years ago

sijuv commented 4 years ago

There could be need to further customize the default shouldFilter implementation, ex you want to exclude traffic based on user agent as in case of bots.

geoand commented 4 years ago

Thanks for the contribution.

Can you show a concrete example where you would need this?

Thanks

sijuv commented 4 years ago

we have a use case where certain bots hit our production services. These are identified by their user-agent header. We dont want such calls to be traced. A sample code would look like this:

if (Option.ofNullable(request.getHeaders().getFirst(HttpHeaders.USER_AGENT))
    .map(s -> userAgentSkipPattern.matcher(s.toLowerCase()).matches()).orElse(false)) {
  if (LOG.isTraceEnabled()) {
    LOG.trace(
        "Not tracing request " + request + " because it matches user agen skip pattern: " + userAgentSkipPattern);
  }
  return false;
}

To implement this I would extend the open tracing provided TracingWebFIlter and override the shouldBeTracedMethod.

geoand commented 4 years ago

That makes sense, thanks

geoand commented 4 years ago

I merged and launched a release of 3.0.1 which should contain the fix if the release goes well