Skip to content

Comments

feat(options): read sample rates from env vars#1540

Open
jpnurmi wants to merge 6 commits intomasterfrom
jpnurmi/feat/env-vars
Open

feat(options): read sample rates from env vars#1540
jpnurmi wants to merge 6 commits intomasterfrom
jpnurmi/feat/env-vars

Conversation

@jpnurmi
Copy link
Collaborator

@jpnurmi jpnurmi commented Feb 23, 2026

Read SENTRY_SAMPLE_RATE and SENTRY_TRACES_SAMPLE_RATE environment variables during sentry_options_new(), using locale-independent parsing with validation. Values are clamped to [0.0, 1.0] by the existing setter functions.

See also:
https://develop.sentry.dev/sdk/expected-features/environment-variables#supported-environment-variables

Closes: #1519

Support SENTRY_SAMPLE_RATE and SENTRY_TRACES_SAMPLE_RATE environment
variables during sentry_options_new(), using locale-independent parsing
with validation. Values are clamped to [0.0, 1.0] by existing setters.

https://develop.sentry.dev/sdk/expected-features/environment-variables#supported-environment-variables
Closes: #1519

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link

github-actions bot commented Feb 23, 2026

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against c082f3d

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
jpnurmi and others added 2 commits February 23, 2026 17:21
Reject NaN values parsed from SENTRY_SAMPLE_RATE and
SENTRY_TRACES_SAMPLE_RATE, as NaN bypasses the clamping logic
in the setter functions. Also restore env vars after tests and
add a NaN-specific test case.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Extract parse_double_env helper to deduplicate sample rate env parsing
and tolerate trailing whitespace. Replace SETENV/UNSETENV macros with
pushenv/popenv functions that clone the old value before overwriting,
preventing use of dangling getenv pointers.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

Replace isnan with !isfinite to also reject inf/-inf values, which
would otherwise get clamped and silently enable full sampling.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Supported environment variables

1 participant