tracing icon indicating copy to clipboard operation
tracing copied to clipboard

Cannot setup custom sampling with micrometer-tracing-bridge-brave

Open sandra-markerud opened this issue 1 month ago • 0 comments

Hello,

I am using micrometer tracing for enabling tracing in my spring boot (cloud) application. Tracing and sampling to zipkin works as expected. However, now I need to make some custom sampling decisions based on paths, header values or jwt claims from the bearer token within the 'Authorization' header.

Something like:

  • never sample requests to '/actuator' endpoints
  • never sample requests to some specific endpoints within the application like '/anonymous'
  • always sample requests with header 'foo' having value 'bar'
  • fallback to configured percentage sampling for everything else

After some research I found that brave seems to offer possibilities to do so: Brave: https://github.com/openzipkin/brave/blob/master/brave/README.md#custom-sampling

However, I don't seem to be able to wire it correctly within the micrometer setup.

I am aware of the possibility of using 'ObservationPredicate' e.g. for not observing specific paths, but that doesn't cover my needs. I don'T want/need to manipulate the observation as such but only customize the sampling decisions.

My micrometer-tracing-bridge-brave example: https://github.com/sandra-markerud/spring-demos/tree/feature/custom-sampling-brave

The SamplingConfiguration tries to setup a HttpTracing that respects the custom rules for sampling. However, the HttpTracing bean is not used, only the Tracing bean instead.

Any help is appreciated.

sandra-markerud avatar Jan 27 '25 20:01 sandra-markerud