Skip to content
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

Merged

Conversation

naseemkullah
Copy link
Member

@naseemkullah naseemkullah commented May 18, 2020

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 if process.env.OTEL_SAMPLING_PROBABILITY is set and if so determines the sampling probability by converting its contents to a number and passing it to the ProbabilitySampler constructor. If unset it defaults to passing in a probability of 1.

@dyladan
Copy link
Member

dyladan commented May 18, 2020

Looks like somehow CI might have been disabled?

@naseemkullah
Copy link
Member Author

Anyone know why CI is not being triggered?

@naseemkullah
Copy link
Member Author

naseemkullah commented May 18, 2020

Looks like somehow CI might have been disabled?

Yes I've noticed this for all my open PRs. 🤔 It's a conspiracy I tell you! 😛

@dyladan
Copy link
Member

dyladan commented May 18, 2020

CI ran in #1063 less than an hour ago

@naseemkullah
Copy link
Member Author

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

@dyladan
Copy link
Member

dyladan commented May 18, 2020

I don't think it works per-user like that.

@obecny
Copy link
Member

obecny commented May 18, 2020

It is a punishment from github for too many force push :D

@dyladan
Copy link
Member

dyladan commented May 18, 2020

@naseemkullah can you confirm if that is actually your issue?

@naseemkullah
Copy link
Member Author

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

@dyladan
Copy link
Member

dyladan commented May 18, 2020

Yay the build failed!

@naseemkullah
Copy link
Member Author

Yay the build failed!

You don't hear that everyday!

@mayurkale22 mayurkale22 added the enhancement New feature or request label May 18, 2020
@naseemkullah naseemkullah requested a review from mwear as a code owner May 21, 2020 03:30
@codecov
Copy link

codecov bot commented May 21, 2020

Codecov Report

Merging #1069 into master will increase coverage by 0.00%.
The diff coverage is n/a.

@@           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           
Impacted Files Coverage Δ
...ject/packages/opentelemetry-tracing/src/utility.ts 100.00% <0.00%> (ø)

Copy link
Member Author

@naseemkullah naseemkullah left a 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?

@@ -32,7 +32,6 @@ export const DEFAULT_MAX_LINKS_PER_SPAN = 32;
export const DEFAULT_CONFIG = {
defaultAttributes: {},
logLevel: LogLevel.INFO,
sampler: ALWAYS_SAMPLER,
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

@naseemkullah naseemkullah Jul 9, 2020

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

Copy link
Member Author

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?

Copy link
Member

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

Copy link
Member

@dyladan dyladan Jul 9, 2020

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

Copy link
Member Author

@naseemkullah naseemkullah Jul 9, 2020

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?

Copy link
Member

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.

@naseemkullah
Copy link
Member Author

naseemkullah commented Jul 9, 2020

Does the spec hint at any implementation of metrics sampling? if so we might want to rename this to OTEL_TRACE(R)_SAMPLING_PROBABILITY

@dyladan
Copy link
Member

dyladan commented Jul 9, 2020

Does the spec hint at any implementation of metrics sampling? if so we might want to rename this to OTEL_TRACE(R)_SAMPLING_PROBABILITY

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.

@dyladan
Copy link
Member

dyladan commented Jul 15, 2020

@mayurkale22 are you satisfied with the updates?

@naseemkullah can you fix the conflicts? I think this can be merged soon

@naseemkullah
Copy link
Member Author

@mayurkale22 are you satisfied with the updates?

@naseemkullah can you fix the conflicts? I think this can be merged soon

@dyladan, @mayurkale22 I've added use of ParentOrElse and I've ensured AlwaysOnSampler is used by default if sampling probability is unset or set to 1.

@naseemkullah
Copy link
Member Author

Please let me know before merging as I'd like to clean up the history.

Copy link
Member

@mayurkale22 mayurkale22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mayurkale22
Copy link
Member

Please fix the build, this is good to go.

const otelSamplingProbability = getEnv().OTEL_SAMPLING_PROBABILITY;
const validOtelSamplingProbability =
otelSamplingProbability &&
otelSamplingProbability >= 0 &&
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shoot, thanks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually no, its a number
image

Copy link
Member Author

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

Copy link
Member

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

Copy link
Member

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)

Copy link
Member Author

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.

Copy link
Member

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

@naseemkullah naseemkullah force-pushed the otel-sampling-probability branch 3 times, most recently from 48f95ca to f40d8ad Compare July 18, 2020 02:41
? {
sampler: new ParentOrElseSampler(delegateSampler),
}
: { sampler: DEFAULT_CONFIG.sampler },
Copy link
Member Author

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).

@dyladan
Copy link
Member

dyladan commented Jul 22, 2020

@naseemkullah please fix the build

@naseemkullah naseemkullah force-pushed the otel-sampling-probability branch 2 times, most recently from 2c484bd to 7c50b3e Compare July 23, 2020 18:45
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]>
@mayurkale22 mayurkale22 merged commit 0f0c08a into open-telemetry:master Jul 24, 2020
@naseemkullah naseemkullah deleted the otel-sampling-probability branch July 24, 2020 04:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants