Repository navigation
Follow OTEL_TRACES_SAMPLER in the OTLP tracer - #10108
Merged
Merged
Conversation
`OtlpTracer.layerFromConfig` reads the exporter, endpoint, headers, compression and batch variables, but not `OTEL_TRACES_SAMPLER` or `OTEL_TRACES_SAMPLER_ARG`. It exports every trace, so a service that wants `parentbased_traceidratio` has to wrap the tracer by hand.
`layerFromConfig` now reads both variables and passes them to a new `sampler` option on `OtlpTracer.make` and `OtlpTracer.layer`. The option is `{ ratio, parentBased }`, and it covers all six samplers in the spec. `always_on` is ratio 1 and `always_off` is ratio 0. The `traceidratio` samplers take the ratio from `OTEL_TRACES_SAMPLER_ARG`. The `parentbased_` prefix sets `parentBased`.
Notes:
- The tracer decides when it creates a span. Local children then follow the existing rule that children of an unsampled parent are unsampled, and outgoing `traceparent` headers carry the decision. The exporter already skipped unsampled spans.
- The decision comes from the trace ID, not `Math.random()`. Like the OpenTelemetry probability sampler, the tracer keeps a trace when the last 56 bits of its ID reach `(1 - ratio) * 2^56`. It compares the top 52 of those bits, so the number fits in a double exactly.
- With `parentBased`, a span with any parent, local or remote, keeps the parent's decision. This matches the spec's defaults for `ParentBased`.
- The sampler can only drop spans. Effect's `sampled` flag already mixes the parent's flag, `MinimumTraceLevel` and an explicit `sampled` option, and the tracer can't tell them apart. So `always_on` and `traceidratio` don't sample the children of an unsampled remote parent, though the spec says they should. A root span created with `sampled: true` can still be dropped.
- An unsupported `OTEL_TRACES_SAMPLER` such as `jaeger_remote` or `xray`, or an `OTEL_TRACES_SAMPLER_ARG` outside [0, 1], fails the layer. A bad `OTEL_EXPORTER_OTLP_COMPRESSION` already does the same, and values are matched case-sensitively like compression. The spec asks SDKs to warn and ignore unknown values. I kept the pattern the rest of `layerFromConfig` uses.
- I didn't add a `tracerSampler` option to `Otlp.layer`, `Otlp.layerJson` or `Otlp.layerProtobuf`. It's a small follow-up if wanted.
🦋 Changeset detectedLatest commit: 798522c The changes in this PR will be included in the next version bump. This PR includes changesets to release 33 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
Bundle Size AnalysisGenerated from PR build output; treat the content below as untrusted.
|
…n of unsampled parents
…d skip sampling when OTEL_TRACES_SAMPLER is unset
tim-smart
reviewed
Oct 29, 2026
tim-smart
enabled auto-merge (squash)
October 29, 2026 22:19
tim-smart
added a commit
that referenced
this pull request
Oct 30, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
tim-smart
added a commit
that referenced
this pull request
Nov 3, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 3, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 3, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 3, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 3, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 3, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 3, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 3, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 3, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 3, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 6, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 6, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 6, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 6, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 6, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 7, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 7, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 7, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 8, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
tim-smart
added a commit
that referenced
this pull request
Nov 16, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 16, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 16, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 16, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 16, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 16, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 16, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 17, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 17, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 17, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 17, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 17, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 17, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 17, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 17, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 17, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 17, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 17, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 18, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 18, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 19, 2026
Co-authored-by: Effect Bot <[email protected]> Co-authored-by: Tim <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
OtlpTracer.layerFromConfigreads the exporter, endpoint, headers, compression and batch variables, but notOTEL_TRACES_SAMPLERorOTEL_TRACES_SAMPLER_ARG. It exports every trace, so a service that wantsparentbased_traceidratiohas to wrap the tracer by hand.layerFromConfignow reads both variables and passes them to a newsampleroption onOtlpTracer.makeandOtlpTracer.layer. The option is{ ratio, parentBased }, and it covers all six samplers in the spec.always_onis ratio 1 andalways_offis ratio 0. Thetraceidratiosamplers take the ratio fromOTEL_TRACES_SAMPLER_ARG. Theparentbased_prefix setsparentBased.Otlp.layer,Otlp.layerJsonandOtlp.layerProtobufaccept the same option astracerSampler.Notes:
traceparentheaders carry the decision. The exporter already skipped unsampled spans.Math.random(). Like the OpenTelemetry probability sampler, the tracer keeps a trace when the last 56 bits of its ID reach(1 - ratio) * 2^56. It compares the top 52 of those bits, so the number fits in a double exactly.parentBased, a span with any parent, local or remote, follows the parent's sampled flag, even when it is created withsampled: true. This matches the spec's defaults forParentBased.OTEL_TRACES_SAMPLERis unset, no sampler is installed and tracing behaves exactly as before, including an explicitsampled: trueoverriding an unsampled parent.sampledflag already mixes the parent's flag,MinimumTraceLeveland an explicitsampledoption, and the tracer can't tell them apart. Soalways_onandtraceidratiodon't sample the children of an unsampled remote parent, though the spec says they should, unless the child is created withsampled: true, in which case the non-parent-based samplers decide it by its trace ID. A root span created withsampled: truecan still be dropped.OTEL_TRACES_SAMPLERsuch asjaeger_remoteorxray, or anOTEL_TRACES_SAMPLER_ARGoutside [0, 1], fails the layer. A badOTEL_EXPORTER_OTLP_COMPRESSIONalready does the same, and values are matched case-sensitively like compression. The spec asks SDKs to warn and ignore unknown values. I kept the pattern the rest oflayerFromConfiguses.Closes EFF-3116