Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Overriding sampling rate in certain cases #1654

Answered by lzchen
Gyllsdorff asked this question in Q&A
Discussion options

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.

You must be logged in to vote

@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

Comment options

@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?

You must be logged in to vote
1 reply
Comment options

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.

Answer selected by Gyllsdorff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /