-
Notifications
You must be signed in to change notification settings - Fork 828
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 #975
feat: add OTEL_SAMPLING_PROBABILITY env var #975
Conversation
a6f6769
to
918c4db
Compare
Hello, I cannot seem to get |
readonly resource: Resource; | ||
|
||
constructor(private _config: TracerConfig = DEFAULT_CONFIG) { | ||
this.logger = _config.logger || new ConsoleLogger(_config.logLevel); | ||
this.sampler = | ||
_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.
by default _config
is the DEFAULT_CONFIG
so your fallback is never called 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.
Thanks @vmarchaud I did this because of ts error:
Type 'Sampler | undefined' is not assignable to type 'Sampler'.
Type 'undefined' is not assignable to type 'Sampler'.
But have worked around this with:
readonly sampler: api.Sampler | 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.
We should always have a sampler though so you approach was fine, however i would use ??
instead of ||
EDIt: The current approach is the correct way, but you shouldn't need to add | undefined
to the _sampler
@@ -32,7 +32,7 @@ export const DEFAULT_MAX_LINKS_PER_SPAN = 32; | |||
export const DEFAULT_CONFIG = { | |||
defaultAttributes: {}, | |||
logLevel: LogLevel.INFO, | |||
sampler: ALWAYS_SAMPLER, | |||
sampler: new ProbabilitySampler(Number(process.env.OTEL_SAMPLING_RATE || 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.
This config is created when this file is required so well before your test tries to set it into the environment.
I don't think you should change the default config. I would have checked the existence of the env variable inside the BasicTracer and override the sampler there. Also you'll like the other PR to have a different implementation for the browser since process
will not be available
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.
This config is created when this file is required so well before your test tries to set it into the environment.
I don't think you should change the default config. I would have checked the existence of the env variable inside the BasicTracer and override the sampler there.
Also tried this approach but the env var is not working as expected 🤔
1) BasicTracerProvider
.startSpan()
should not sample a trace when OTEL_SAMPLING_RATE is 0:
AssertionError [ERR_ASSERTION]: Input A expected to strictly equal input B:
+ expected - actual
- 1
+ 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.
I don't know then, maybe try to use the ConsoleLogger
and increase the verbosity to debug ?
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.
Hmmm in the end I only had to make changes to Tracer.ts
but not BasicTracerProvider,ts
🤷♂️
11eef5a
to
72e9da1
Compare
72e9da1
to
4b303a5
Compare
f5c1ca1
to
8a24a66
Compare
User can now control the trace sampling probability by means of env var. Signed-off-by: Naseem <[email protected]>
8a24a66
to
d07b41d
Compare
packages/opentelemetry-tracing/test/BasicTracerProvider.test.ts
Outdated
Show resolved
Hide resolved
User can now control the trace sampling probability by means of env var. Signed-off-by: Naseem <[email protected]>
…metry-js into otel-sampling-rate
Signed-off-by: Naseem <[email protected]>
User can now control the trace sampling probability by means of env var. Signed-off-by: Naseem <[email protected]>
Signed-off-by: Naseem <[email protected]>
…metry-js into otel-sampling-rate
Not sure how 637f982 wound up in this branch. I tried rebasing from master. |
Anyone know why isn't CI being triggered? |
User can now control the trace sampling probability by means of env var. Signed-off-by: Naseem <[email protected]>
Signed-off-by: Naseem <[email protected]>
…metry-js into otel-sampling-rate
Signed-off-by: Naseem <[email protected]>
Signed-off-by: Naseem <[email protected]>
Signed-off-by: Naseem <[email protected]>
Closing and opening a new PR due to git complications. |
User can now control the trace sampling rate by means of env var.
JS implementation of open-telemetry/opentelemetry-specification#567