javascriptnode.jsopen-telemetryobservability

OpenTelemetry adjust sampling ratio programmatically


In the OpenTelemetry SDK for JS, is there a way to modify the TraceIdRatioBasedSampler sampling ratio at run time? Alternatively, I was considering creating a new sampler and updating the trace provider, but from what I can see in the NodeTracerProvider and BasicTracerProvider docs, there isn't any method to modify the sampler.


Solution

  • There is currently no existing component which allows for runtime changing of sampling rates. You could implement and use your own sampler which implements the interface and allows for mutable sampling rates. You cannot modify the sampler from the Tracer directly, but you can configure your tracer provider with a different sampler when it is constructed.