-
Notifications
You must be signed in to change notification settings - Fork 758
Overriding sampling rate in certain cases #1654
-
Is it possible to override the sampling rate, not decision, when you create a span without using the SDK part of opentelemetry-python?
When we create the tracer provider we create a ParentBasedTraceIdRatio that we use as the sampler which samples a globally defined rate of traces. In some high priority or low traffic but fragile endpoints/consumers we would like to sample 50% - 100% of the traffic instead of the default 0.1% - 1%. I generally don't want to override the sampling decision, I just want to control the sampling rate.
Right now the SDK part of the opentelemetry-python is safely tucked away in a single file in our application and the rest of the code always uses the API abstraction layers. When I call trace.get_tracer( I will get a tracer that have the applications default sampler, is there anyway to override the sampling rate for the new tracer without having to use the SDK files? I could always do
consumer_tracer: opentelemetry.sdk.trace.Tracer = get_tracer(options.app_name, options.app_version) consumer_tracer.sampler = ParentBasedTraceIdRatio(0.5)
but then the application might crash if we use a DefaultTracerProvider tracer provider and is fragile in other ways.
Beta Was this translation helpful? Give feedback.
All reactions
@Gyllsdorff
I'm not sure how you would be able to do this since Sampler is an SDK concept. Perhaps you could make your own "overridable" custom Sampler that inherits from Sampler and has some APIs that could change the sampling percentage during runtime?
Replies: 1 comment 1 reply
-
@Gyllsdorff
I'm not sure how you would be able to do this since Sampler is an SDK concept. Perhaps you could make your own "overridable" custom Sampler that inherits from Sampler and has some APIs that could change the sampling percentage during runtime?
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
I think we will solve it by creating a custom sample that checks a ContextVar if it should override the sample. Thanks for the quick help.
Beta Was this translation helpful? Give feedback.