Skip to content

Conversation

@lforst
Copy link
Contributor

@lforst lforst commented Jan 14, 2025

Adjusts the dev docs on sample_rand to require 30 less IQ points when reading. I used myself (borderline dyslexic) as a benchmark.

@vercel
Copy link

vercel bot commented Jan 14, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
develop-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 14, 2025 10:54pm
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
changelog ⬜️ Ignored (Inspect) Visit Preview Jan 14, 2025 10:54pm
sentry-docs ⬜️ Ignored (Inspect) Visit Preview Jan 14, 2025 10:54pm

The random value is set according to the following rules:
1. When tracing is enabled and a new trace is started, the SDK generates a `sample_rand` value for the current execution context. A `sample_rand` is a float (`0.1234` notation) in the range of `[0, 1)` (including 0.0, excluding 1.0).
1. It is _recommended_ to generate the random number deterministically using the trace ID as seed or source of randomness. The exact method by which the random number is created is implementation defined and may vary between SDK implementations.
1. The `sample_rand` is part of the DSC (Dynamic Sampling Context) and as with other values on the `baggage` header, the `sentry-sample_rand` value from the current execution context should be propagated to downstream SDKs.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
1. The `sample_rand` is part of the DSC (Dynamic Sampling Context) and as with other values on the `baggage` header, the `sentry-sample_rand` value from the current execution context should be propagated to downstream SDKs.
1. The `sample_rand` is part of the DSC (Dynamic Sampling Context) and as with other values on the `baggage` header, the `sample_rand` value from the current execution context should be propagated to downstream SDKs.

The SDK should always use the stored random number (`sentry-sample_rand`) for sampling decisions and should no longer rely on `math.random()` or similar functions in tracing code:
1. When the `tracesSampler` is invoked, the return value should be compared with `sample_rand`: `trace["sentry-sample_rand"] < tracesSampler(context)`
1. When the SDK is the head of a trace (and `tracesSampleRate` is defined), the sampling is done comparing the `tracesSampleRate` with the `sample_rand`: `trace["sentry-sample_rand"] < config.tracesSampleRate`
1. If no `tracesSampler` callback is configured, the SDK fully inherits incoming sampling decisions from the `sentry-trace` header for propagated traces.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
1. If no `tracesSampler` callback is configured, the SDK fully inherits incoming sampling decisions from the `sentry-trace` header for propagated traces.
1. Otherwise, there is an incoming trace and the SDK fully inherits incoming sampling decisions from the `sentry-trace` header for propagated traces.

You might also turn 2 and 3 around for clarity to say:

  • if tracesSampler, ...
  • if there's an incoming trace, ...
  • otherwise, the SDK is the head of the trace, ...

@lforst lforst enabled auto-merge (squash) January 14, 2025 22:50
@lforst lforst merged commit a205292 into master Jan 14, 2025
10 checks passed
@lforst lforst deleted the lforst-simplify-and-specify-sample-rand-docs branch January 14, 2025 22:54
@github-actions github-actions bot locked and limited conversation to collaborators Jan 30, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants