Skip to content

fix(nitro): Anchor both nitro integrations on h3 for Cloudflare auto-injection - #24897

Closed
mydea wants to merge 6 commits into
feat/nitro-move-to-server-utilsfrom
feat/nitro-anchor-both-on-h3
Closed

mydea wants to merge 6 commits into
feat/nitro-move-to-server-utilsfrom
feat/nitro-anchor-both-on-h3

Conversation

@mydea

@mydea mydea commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Stacked on #24861.

Addresses review feedback on the orchestrion registration: nitroServerTimingIntegration was anchored on unstorage (because the registration mapped one integration per module and h3 was taken by nitroIntegration). unstorage is practically always evaluated in a Nitro app, but it isn't the guaranteed HTTP module — so a Nitro app that didn't load it would silently fail to register the Server-Timing headers on a bundler-only SDK like @sentry/cloudflare, breaking pageload trace propagation with no error.

This lets a single module register multiple integrations and anchors both nitro integrations on h3 — the module every HTTP-serving Nitro app loads.

  • channel-integration-definitions.ts: both nitro entries → h3; subscriberExportForModule → subscriberExportsForModule (returns all exports for a module).
  • The injected snippet makes a single registration call per module, passing all of that module's factories. The helper treats each call as the module's complete list and replaces its entry, so a package split across several instrumented files (pg, amqplib, ...) doesn't accumulate duplicate factories.
  • The global orchestrion marker value is now always an array of factories, for every module. Version skew between the injected @sentry/server-utils and the reading SDK is unsupported (@sentry/cloudflare pins @sentry/server-utils exactly), so there is no older-reader shape to preserve.
  • config/nitro.ts drops the now-unnecessary unstorage anchor.

Only affects the Cloudflare (bundler-only) path — on node/deno/bun these integrations are registered statically.

🤖 Generated with Claude Code

@mydea
mydea added this pull request to stack #24871 September 30, 2026 13:45

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread packages/cloudflare/test/sdk.test.ts
@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 29.83 kB - -
@sentry/browser - with treeshaking flags 27.96 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 27.87 kB - -
@sentry/browser (incl. Tracing) 52.02 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 52.02 kB - -
@sentry/browser (incl. Tracing, Profiling) 54.96 kB - -
@sentry/browser (incl. Tracing, Replay) 91.75 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 80.62 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 96.47 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 109.43 kB - -
@sentry/browser (incl. Feedback) 47.35 kB - -
@sentry/browser (incl. sendFeedback) 34.89 kB - -
@sentry/browser (incl. FeedbackAsync) 40 kB - -
@sentry/browser (incl. Metrics) 30.85 kB - -
@sentry/browser (incl. Logs) 31.13 kB - -
@sentry/browser (incl. Metrics & Logs) 31.78 kB - -
@sentry/react 31.64 kB - -
@sentry/react (incl. Tracing) 54.34 kB - -
@sentry/vue 37.98 kB - -
@sentry/vue (incl. Tracing) 54.95 kB - -
@sentry/svelte 29.86 kB - -
@sentry/remix (Remix 3 client bundle) 57.02 kB - -
CDN Bundle 31.56 kB - -
CDN Bundle (incl. Tracing) 52.52 kB - -
CDN Bundle (incl. Logs, Metrics) 33.77 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 54.46 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 74.7 kB - -
CDN Bundle (incl. Tracing, Replay) 90.19 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 92.11 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 96.34 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 98.28 kB - -
CDN Bundle - uncompressed 92.98 kB - -
CDN Bundle (incl. Tracing) - uncompressed 155.83 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 99.52 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 161.79 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 229.56 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 276 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 281.94 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 289.7 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 295.63 kB - -
@sentry/nextjs (client) 56.75 kB - -
@sentry/sveltekit (client) 52.41 kB - -
@sentry/core/server 41.12 kB - -
@sentry/core/browser 13.81 kB - -
@sentry/node 153.65 kB +1.11% +1.68 kB 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 83.8 kB +0.03% +17 B 🔺
@sentry/node - without tracing 94.83 kB +0.32% +300 B 🔺
@sentry/node - without channel injection 131.84 kB +1.29% +1.67 kB 🔺
@sentry/aws-serverless 102.96 kB +0.27% +271 B 🔺
@sentry/cloudflare (withSentry) - minified 210.4 kB +0.01% +16 B 🔺
@sentry/cloudflare (withSentry) 521.63 kB +0.01% +20 B 🔺
@sentry/nextjs/cloudflare (withSentry) - minified 228.07 kB +0.01% +16 B 🔺

View base workflow run

@mydea
mydea force-pushed the feat/nuxt-strip-update-route-name branch from 2a97f05 to 01d3ad1 Compare September 30, 2026 14:13
@mydea
mydea force-pushed the feat/nitro-anchor-both-on-h3 branch from a38c9f8 to b12d5d7 Compare September 30, 2026 14:13
@mydea mydea closed this Sep 30, 2026
@mydea mydea reopened this Oct 1, 2026
@mydea
mydea removed this pull request from stack #24871 October 1, 2026 06:50
@mydea
mydea force-pushed the feat/nitro-anchor-both-on-h3 branch from b12d5d7 to 42650ee Compare October 1, 2026 06:51
@mydea
mydea changed the base branch from feat/nuxt-strip-update-route-name to feat/nitro-move-to-server-utils October 1, 2026 06:51

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread packages/server-utils/src/orchestrion/config/nitro.ts
@mydea
mydea added this pull request to stack #24913 October 1, 2026 07:14
@mydea
mydea force-pushed the feat/nitro-anchor-both-on-h3 branch 2 times, most recently from b7712e1 to 1a7314a Compare October 1, 2026 07:17

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread packages/server-utils/src/utils/moduleInjected.ts Outdated
@mydea
mydea force-pushed the feat/nitro-move-to-server-utils branch from d93c0f9 to a6ecc88 Compare October 1, 2026 10:59
@mydea
mydea force-pushed the feat/nitro-anchor-both-on-h3 branch from 1a7314a to 424ddfa Compare October 1, 2026 11:00

@cursor cursor Bot left a comment

Copy link
Copy Markdown

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.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 424ddfa. Configure here.

Comment thread dev-packages/e2e-tests/test-applications/nuxt-5/tests/cache.test.ts Outdated
@mydea
mydea force-pushed the feat/nitro-anchor-both-on-h3 branch from 4cf95b6 to a01699a Compare October 1, 2026 12:41
@mydea
mydea marked this pull request as ready for review October 12, 2026 13:13
@mydea
mydea requested review from a team as code owners October 12, 2026 13:13
@mydea
mydea requested review from JPeer264, isaacs, nicohrubec and s1gr1d and removed request for a team October 12, 2026 13:13
@mydea
mydea force-pushed the feat/nitro-move-to-server-utils branch from 73ba6de to eb9579a Compare October 12, 2026 13:18
@mydea
mydea force-pushed the feat/nitro-anchor-both-on-h3 branch from a01699a to 4316c1b Compare October 12, 2026 13:18
mydea and others added 3 commits October 12, 2026 15:55
…injection

The orchestrion registration previously mapped one integration per module, so
`nitroServerTimingIntegration` was anchored on `unstorage` while
`nitroIntegration` took `h3`. `unstorage` is practically always evaluated in a
Nitro app, but it is not the guaranteed HTTP module, so a Nitro app that did not
load it would silently fail to register Server-Timing (breaking pageload trace
propagation) on a bundler-only SDK like `@sentry/cloudflare`.

Let a module register several integrations, and anchor both nitro integrations
on `h3` — the module every HTTP-serving Nitro app loads. The global orchestrion
marker now stores a Set of factories per module; the injected snippet emits one
registration call per export; and cloudflare instantiates all of them.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ctories

The prior test only exercised the init-time path with a Set of factories. Add a
test that emits `orchestrion.module-injected` for a module holding a Set, so the
late-registration listener's Set-unwrapping is covered with more than one
factory too.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Emitting one `orchestrionModuleInjected` call per export made the helper merge
factories across calls, but every instrumented file of a package injects its
own fresh thunk for the same integration. Packages split across files (pg,
amqplib, ...) therefore accumulated duplicate factories and were upgraded to a
Set despite having a single integration, breaking the plain-factory shape kept
for older readers.

The snippet now passes all of a module's factories in a single call, and the
helper treats each call as the module's complete list and replaces the entry:
one factory stays a plain factory, several become a Set. This also announces
`h3` once per file instead of once per integration. Adds a transform test for
the multi-export `h3` injection.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mydea
mydea force-pushed the feat/nitro-anchor-both-on-h3 branch from 4316c1b to 800b14e Compare October 12, 2026 13:55

@isaacs isaacs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we can remove a layer of complexity by settling on a single shape here, since we pin versions and don't normally support skew anyway, but this is also fine as-is.

Comment thread packages/core/src/utils/worldwide.ts Outdated
* instantiates them.
*/
integrations?: Map<string, () => Integration>;
integrations?: Map<string, (() => Integration) | Set<() => Integration>>;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This dual factory | Set shape does not give the compatibility it claims, for the only module that uses it. I think we should pick one and simplify it.

The marker field has shipped since #22094 as Map<string, () => Integration>. This PR keeps a plain factory for single-integration modules "so an older reader stays compatible".

But h3 is now always a Set. A released @sentry/cloudflare reader does [...registered.values()].map(factory => factory()), which throws TypeError: factory is not a function on the Set. That throw happens inside getDefaultIntegrations during init(), so a Nitro app with version skew between the injected @sentry/server-utils and @sentry/cloudflare would fail at init, not just miss an integration.

@sentry/cloudflare pins @sentry/server-utils to an exact version, so skew needs two installed copies (for example an app-level @sentry/server-utils dependency at another version), which would be very surprising, and we could easily say is unsupported. But then the compat argument is weak for every module, and the dual shape is complexity for nothing. If skew is a real concern (which I'm not convinced it is), the current design would still break for exactly the Nitro case this PR targets.

Suggestion: Treat writer/reader skew as unsupported, as the exact pin already implies. Store one shape always (Set or array) for every module. Drop the [first, ...rest] branching in moduleInjected.ts, the instanceof Set checks in both baseSdk.ts readers, and the compat wording in this comment.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yeah good point, I rewrote it to expect an array only!

Comment thread packages/server-utils/src/orchestrion/bundler/moduleInjectedTransform.ts Outdated
mydea and others added 3 commits October 14, 2026 08:45
Writer/reader version skew is already unsupported (`@sentry/cloudflare` pins
`@sentry/server-utils` exactly), and the dual factory | Set shape did not
keep older readers working for `h3` anyway. Always store the module's factory
list as an array so the readers no longer need to branch on the shape.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…le-injected snippet

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: isaacs <i@izs.me>
@mydea

mydea commented Oct 14, 2026

Copy link
Copy Markdown
Member Author

Superseded by #25349, which merges the two nitro integrations into a single nitroIntegration with serverTiming / storage options instead of letting one module register several integrations.

@mydea mydea closed this Oct 14, 2026

@JPeer264 JPeer264 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. The point Isaac brought up seems to be in already and is indeed cleaner now.

edit: That aged like milk

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.

3 participants