-
Notifications
You must be signed in to change notification settings - Fork 795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add OTEL_SAMPLING_PROBABILITY env var #1069
feat: add OTEL_SAMPLING_PROBABILITY env var #1069
Conversation
Looks like somehow CI might have been disabled? |
Anyone know why CI is not being triggered? |
Yes I've noticed this for all my open PRs. 🤔 It's a conspiracy I tell you! 😛 |
CI ran in #1063 less than an hour ago |
I think it's for my PRs in particular. Did I consume too much build time with my obnoxious amount of pushes? 😆 |
I don't think it works per-user like that. |
It is a punishment from github for too many force push :D |
@naseemkullah can you confirm if that is actually your issue? |
Thanks @dyladan, so I had revoked the github app as I did not think I needed it (i.e. it is not used in my personal projects currently and it said last used within last 7 months or something.) I re-granted access and things are now in order! |
Yay the build failed! |
You don't hear that everyday! |
Codecov Report
@@ Coverage Diff @@
## master #1069 +/- ##
=======================================
Coverage 92.69% 92.70%
=======================================
Files 193 193
Lines 4807 4812 +5
Branches 983 986 +3
=======================================
+ Hits 4456 4461 +5
Misses 351 351
|
packages/opentelemetry-core/src/platform/browser/sampling-probability.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-core/src/platform/node/sampling-probability.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @dyladan, similarly to OTEL_LOG_LEVEL
can we get this in with OTEL_SAMPLING_PROBABILITY
as a working name until spec confirms the name?
packages/opentelemetry-core/src/platform/node/sampling-probability.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-core/test/platform/sampling-probability.test.ts
Outdated
Show resolved
Hide resolved
@@ -32,7 +32,6 @@ export const DEFAULT_MAX_LINKS_PER_SPAN = 32; | |||
export const DEFAULT_CONFIG = { | |||
defaultAttributes: {}, | |||
logLevel: LogLevel.INFO, | |||
sampler: ALWAYS_SAMPLER, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should keep always sampler as default and if OTEL_SAMPLING_PROBABILITY
env is set, use ProbabilitySampler
. WDYT?
Also, please take a look #1279.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure sgtm. I'll adjust accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parentOrElse
is pretty cool, today we are putting a low probability across the board, but perhaps we want to pass that low probability to a parentOrElse 🤔 🤔
Should OTEL_SAMPLING_PROBABILITY now adjust probability in the delagatedSampler of a parentOrElse sampler?? is parentOrElse always better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OTEL_SAMPLING_PROBABILITY should probably be read by the probability sampler and the parent or else sampler. The parent or else sampler will use the always on sampler by default, but if the OTEL_SAMPLING_PROBABILITY env var exists and is the right format, it could use the probability sampler as a delegate. No need for it to play with probabilities because the probability sampler will just reread the env var.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alright, so my pending question is:
if you set OTEL_SAMPLING_PROBABILITY, (without any further config) which sampler does the tracer user? a parentOrElse or a probabilitySampler (directly)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh you are saying if you have coded in the use of a parentOrElse sampler, and left the delegation empty, OTEL_SAMPLING_PROBABILITY
will place a probability sampler in it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no such thing as a parent or else sampler with an empty delegate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you set OTEL_SAMPLING_PROBABILITY, (without any further config) which sampler does the tracer user? a parentOrElse or a probabilitySampler (directly)?
it should use a parent or else sampler with a probability delegate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, just to confirm: parentOrElse with a prob delegate is always/generally favoured over a direct prob sampler?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless specifically configured otherwise by the user, yes.
3f3b9a8
to
e0dd42c
Compare
Does the spec hint at any implementation of metrics sampling? if so we might want to rename this to |
Metrics aggregation takes the place of trace sampling. The point of sampling is to not overload the server. Since we don't send every metric event to the server, this is not a problem for metrics. |
@mayurkale22 are you satisfied with the updates? @naseemkullah can you fix the conflicts? I think this can be merged soon |
e0dd42c
to
a8b7898
Compare
@dyladan, @mayurkale22 I've added use of |
a8b7898
to
08eef7a
Compare
Please let me know before merging as I'd like to clean up the history. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Please fix the build, this is good to go. |
const otelSamplingProbability = getEnv().OTEL_SAMPLING_PROBABILITY; | ||
const validOtelSamplingProbability = | ||
otelSamplingProbability && | ||
otelSamplingProbability >= 0 && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are doing number comparisons on a string here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shoot, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but the logic pasted is slightly flawed, looking into it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the first condition is not needed as second otelSamplingProbability >=0
is already enough
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
besides that this is already checked in env so in fact OTEL_SAMPLING_PROBABILITY will always be a number between 0 and 1 (default is set to 1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @obecny that's a good point! I will only check if it is less than one, and if not, will use the AlwaysOnSampler() as per spec's recommendation
otelSamplingProbability !== undefined && otelSamplingProbability < 1
is the check since according to ts it could be undefined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after this PR -> #1328 ts will not complain about undefined
48f95ca
to
f40d8ad
Compare
? { | ||
sampler: new ParentOrElseSampler(delegateSampler), | ||
} | ||
: { sampler: DEFAULT_CONFIG.sampler }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to repeat the fallback/default sampler here, but not sure why (thought that {}
would be good enough but no strangely).
f40d8ad
to
6137226
Compare
@naseemkullah please fix the build |
2c484bd
to
7c50b3e
Compare
Allows user to configure tracer's sampling probability via an env var. Uses parentOrElse sampler with a probability sampler delegate when setting OTEL_SAMPLING_PROBABILITY Defaults to AlwaysOnSampler when unset or set to 1. Signed-off-by: Naseem <[email protected]>
7c50b3e
to
6454443
Compare
Allows user to configure tracer's sampling probability via env var
Which problem is this PR solving?
Short description of the changes
Tracer.ts
looks to see ifprocess.env.OTEL_SAMPLING_PROBABILITY
is set and if so determines the sampling probability by converting its contents to a number and passing it to theProbabilitySampler
constructor. If unset it defaults to passing in a probability of 1.