feat(options): read sample rates from env vars by jpnurmi · Pull Request #1540 · getsentry/sentry-native

@jpnurmi @claude

cursor[bot]

bot reviewed Feb 23, 2026

@jpnurmi @claude

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

sentry[bot]

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>

cursor[bot]

@jpnurmi @claude

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>

cursor[bot]

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

mujacica

@jpnurmi jpnurmi deleted the jpnurmi/feat/env-vars branch

February 25, 2026 14:26