Skip to content

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

Merged
jpnurmi merged 8 commits intomasterfrom
jpnurmi/feat/env-vars
Feb 25, 2026
Merged

feat(options): read sample rates from env vars#1540
jpnurmi merged 8 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 a341315

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.

jpnurmi and others added 3 commits February 23, 2026 17:48
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>
Move env var double parsing from sentry_options.c into a reusable
sentry__getenv_double(name, fallback) helper in sentry_utils. This
simplifies option initialization to inline calls and moves parsing
tests to test_utils.c where they test the utility directly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jpnurmi jpnurmi merged commit 63765bd into master Feb 25, 2026
47 checks passed
@jpnurmi jpnurmi deleted the jpnurmi/feat/env-vars branch February 25, 2026 14:26
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

2 participants