Skip to content

Conversation

@JPeer264
Copy link
Member

It was not possible to use env variables for the Cloudflare SDK. This adds a subset of env variables to enable certain features just with env variables (not everything is yet supported - we should wait what gets supported once that PR lands).

This PR is important for #19215.

@JPeer264 JPeer264 self-assigned this Feb 10, 2026
CfHostMetadata
>,
>(optionsCallback: (env: Env) => CloudflareOptions, handler: T): T {
>(optionsCallback: (env: Env) => CloudflareOptions | undefined, handler: T): T {
Copy link
Member Author

Choose a reason for hiding this comment

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

note: I made this return undefined as it was also working before theoretically. I adapted the types to also allow undefined just to have this case also handled

: undefined;

return { release, ...userOptions };
const tracesSampleRate = userOptions.tracesSampleRate ?? parseFloat(getEnvVar(env, 'SENTRY_TRACE_SAMPLE_RATE') ?? '');
Copy link

Choose a reason for hiding this comment

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

Env variable name typo: missing 'S' in TRACES

High Severity

The code reads SENTRY_TRACE_SAMPLE_RATE (missing the 'S' in "TRACES"), but the standard Sentry env variable name is SENTRY_TRACES_SAMPLE_RATE. The tests also use SENTRY_TRACES_SAMPLE_RATE. This mismatch means the traces sample rate env variable will never be read, making the feature non-functional. This also means the related tests will fail.

Fix in Cursor Fix in Web

tracesSampleRate: isFinite(tracesSampleRate) ? tracesSampleRate : undefined,
release,
...userOptions,
};
Copy link

Choose a reason for hiding this comment

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

Spread operator overrides env-derived fallback values

Medium Severity

The ...userOptions spread at the end of the return object overrides the env-derived fallback values for dsn, environment, and tracesSampleRate whenever those keys exist in userOptions — even if their values are undefined. This means if a user passes { dsn: undefined }, the SENTRY_DSN env fallback is silently ignored. The ?? fallback logic and the isFinite guard are both bypassed by the spread.

Fix in Cursor Fix in Web

@github-actions
Copy link
Contributor

github-actions bot commented Feb 10, 2026

Codecov Results 📊


Generated by Codecov Action

const tracesSampleRate = userOptions.tracesSampleRate ?? parseFloat(getEnvVar(env, 'SENTRY_TRACE_SAMPLE_RATE') ?? '');

return {
dsn: userOptions.dsn ?? getEnvVar(env, 'SENTRY_DSN'),
Copy link
Member

Choose a reason for hiding this comment

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

l: can we also add SENTRY_DEBUG? You could use envToBool for that from node-core, maybe lift that up into @sentry/core?

Copy link
Member Author

Choose a reason for hiding this comment

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

Great idea. Added.

I also added tunnel to it

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.

dsn: userOptions.dsn ?? getEnvVar(env, 'SENTRY_DSN'),
environment: userOptions.environment ?? getEnvVar(env, 'SENTRY_ENVIRONMENT'),
tracesSampleRate: isFinite(tracesSampleRate) ? tracesSampleRate : undefined,
debug: userOptions.debug ?? envToBool(getEnvVar(env, 'SENTRY_DEBUG')),
Copy link

Choose a reason for hiding this comment

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

envToBool(undefined) forces debug: false when unset

Medium Severity

When SENTRY_DEBUG is absent from env, getEnvVar returns undefined, and envToBool(undefined) returns false (since Boolean(undefined) is false in loose mode). This means debug is always explicitly set to false in the returned options, even when neither the user nor the env specified it. This breaks multiple existing toEqual assertions (e.g., lines 29, 120, 132) that don't expect a debug property.

Fix in Cursor Fix in Web

@github-actions
Copy link
Contributor

github-actions bot commented Feb 10, 2026

size-limit report 📦

Path Size % Change Change
@sentry/browser 25.56 kB - -
@sentry/browser - with treeshaking flags 24.08 kB - -
@sentry/browser (incl. Tracing) 42.36 kB - -
@sentry/browser (incl. Tracing, Profiling) 47.03 kB - -
@sentry/browser (incl. Tracing, Replay) 81.18 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 70.8 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 85.87 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 98.03 kB - -
@sentry/browser (incl. Feedback) 42.29 kB - -
@sentry/browser (incl. sendFeedback) 30.23 kB - -
@sentry/browser (incl. FeedbackAsync) 35.22 kB - -
@sentry/browser (incl. Metrics) 26.74 kB - -
@sentry/browser (incl. Logs) 26.88 kB - -
@sentry/browser (incl. Metrics & Logs) 27.56 kB - -
@sentry/react 27.33 kB - -
@sentry/react (incl. Tracing) 44.7 kB - -
@sentry/vue 30.01 kB - -
@sentry/vue (incl. Tracing) 44.21 kB - -
@sentry/svelte 25.58 kB - -
CDN Bundle 28.11 kB - -
CDN Bundle (incl. Tracing) 43.2 kB - -
CDN Bundle (incl. Logs, Metrics) 28.95 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 44.03 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 68.02 kB - -
CDN Bundle (incl. Tracing, Replay) 80.07 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 80.94 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 85.5 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 86.4 kB - -
CDN Bundle - uncompressed 82.22 kB - -
CDN Bundle (incl. Tracing) - uncompressed 127.93 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 85.05 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 130.76 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 208.71 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 244.81 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 247.63 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 257.61 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 260.42 kB - -
@sentry/nextjs (client) 47.04 kB - -
@sentry/sveltekit (client) 42.81 kB - -
@sentry/node-core 52.17 kB -0.01% -5 B 🔽
@sentry/node 166.52 kB -0.01% -11 B 🔽
@sentry/node - without tracing 93.96 kB -0.01% -7 B 🔽
@sentry/aws-serverless 109.45 kB -0.02% -16 B 🔽

View base workflow run

@github-actions
Copy link
Contributor

github-actions bot commented Feb 10, 2026

node-overhead report 🧳

Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 9,302 - 9,067 +3%
GET With Sentry 1,770 19% 1,737 +2%
GET With Sentry (error only) 6,277 67% 6,080 +3%
POST Baseline 1,179 - 1,201 -2%
POST With Sentry 574 49% 587 -2%
POST With Sentry (error only) 1,049 89% 1,057 -1%
MYSQL Baseline 3,349 - 3,317 +1%
MYSQL With Sentry 533 16% 491 +9%
MYSQL With Sentry (error only) 2,768 83% 2,719 +2%

View base workflow run

@JPeer264 JPeer264 changed the title feat(cloudflare): Enable certain fields with env variables feat(core,cloudflare): Enable certain fields with env variables Feb 10, 2026
};

// Mock env without DSN for tests that should not initialize the SDK
const MOCK_ENV_WITHOUT_DSN = {
Copy link
Member Author

Choose a reason for hiding this comment

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

note: It seems that the SDK was not initialized for the tests where this is used. By now also allowing SENTRY_DSN from the variables these tests fail. I'll create a follow up PR and remove this, so the SDK is actually initialized (I don't want to blow up this PR with other code changes)

@JPeer264 JPeer264 requested a review from andreiborza February 10, 2026 16:51
@JPeer264 JPeer264 force-pushed the jp/env-variables-in-cf branch from b7264d0 to 6c2f692 Compare February 10, 2026 16:53
@JPeer264 JPeer264 merged commit 197369d into develop Feb 10, 2026
219 checks passed
@JPeer264 JPeer264 deleted the jp/env-variables-in-cf branch February 10, 2026 17:54
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.

2 participants