Search code examples
tracespring-cloud-sleuthzipkin

Sample rate issue


If the service has a lot of traffic, tracing each invocation and saving the corresponding link log costs a lot, but once the sample rate is set, some trace with errors may be missed. If I want to keep some rate collection, and the trace with errors must be traced, is this possible in spring-cloud-sleuth? If not, is there a solution?


Solution

  • Spring Cloud Sleuth pushes the sampling decision down to the tracer implementation, you need to create either a SamplerFunction or a Sampler to do this, please see the docs:

    Update: Sampling is an early decision because tracing has some overhead and early sampling can save your app from that. If you want to filter out your spans at the end, you can setup an always sampler and a SpanHandler where you can access the Span (error, tags, etc.) and you can also keep/drop them based on this (you can inject a sampler to your handler and apply its logic to the rest of your spans).