Skip to content

ref(server-utils): Ensure injected modules can reliably be picked up#22386

Draft
mydea wants to merge 2 commits into
developfrom
fn/injected-modules-pickup
Draft

ref(server-utils): Ensure injected modules can reliably be picked up#22386
mydea wants to merge 2 commits into
developfrom
fn/injected-modules-pickup

Conversation

@mydea

@mydea mydea commented Jul 20, 2026

Copy link
Copy Markdown
Member

Makes orchestrion-injected modules reliably discoverable at runtime, regardless of how (and when) they were injected.

This fixes two scenarios:

Turbopack

Here, only loaders are accepted, not plugins, so there is no build lifecucle hook to emit the aggregate list of instrumented modules at boot the way the webpack plugin does.

Other Bundlers

While here we can/do inject the aggregate list of modules at build time, depending on how the SDK is initialized this may or may not be defined before Sentry.init() is called - when init() is called ahead of the bundled server code with --import, the module list may not be available yet at this point.

The Fix

To fix this, injected modules now announce themselves through a shared set of runtime globals:

  • Build-time injection emits a dependency-free prologue (buildInjectPrologue) per instrumented module (Turbopack) or a boot-time snippet with the full module list (webpack/rollup/vite/esbuild). Both record the module in __SENTRY_ORCHESTRION__.bundler and call the SDK bridge (__SENTRY_ORCHESTRION_ON_INJECT__) so channel subscribers are wired up before the module publishes — this matters when Sentry.init() runs ahead of the bundled server (e.g. via --require).
  • A new invokeOrchestrionInstrumentation helper bridges these announcements to integration setup: it invokes the instrumentation callback immediately for already-injected (build-time) modules, or later when runtime injection happens, and guarantees the callback runs at most once. Bun/Deno register immediately since module tracking is unavailable and channel limits don't apply there.

This is the base of a stack; the follow-up migrates all channel integrations onto this helper.

@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 3 potential issues.

Fix All in Cursor

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

Reviewed by Cursor Bugbot for commit dcccddd. Configure here.


export function getModuleNames(config: InstrumentationConfig[]): string[] {
return uniq(config.map(config => config.module.name));
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unused dead helper added

Low Severity

New exported getModuleNames has no callers anywhere in the repo, and overlaps instrumentedModuleNames in config/index.ts, which already maps configs through uniq to module names. Dead helpers like this tend to drift from the real naming logic.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit dcccddd. Configure here.

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.

this is used in a follow up PR, wasn't 100% sure but I guess it's OK to keep this here...

Comment thread packages/nextjs/src/config/turbopack/generateValueInjectionRules.ts Outdated

const INSTRUMENTATION_FN_SYMBOL = Symbol.for('InstrumentationFn');
// oxlint-disable-next-line typescript/no-explicit-any
type InstrumentationFn = ((...args: any[]) => void) & { [INSTRUMENTATION_FN_SYMBOL]?: boolean };

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unguarded any in new helper

Low Severity

New InstrumentationFn uses any with only an oxlint disable and no comment explaining why a safer type is impossible. Project review rules require that explanation for new any in SDK source.

Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit dcccddd. Configure here.

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.

this is fine

@github-actions

github-actions Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.75 kB - -
@sentry/browser - with treeshaking flags 26.18 kB - -
@sentry/browser (incl. Tracing) 46.56 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 48.37 kB - -
@sentry/browser (incl. Tracing, Profiling) 51.36 kB - -
@sentry/browser (incl. Tracing, Replay) 85.83 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 75.46 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 90.55 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 103.2 kB - -
@sentry/browser (incl. Feedback) 44.93 kB - -
@sentry/browser (incl. sendFeedback) 32.55 kB - -
@sentry/browser (incl. FeedbackAsync) 37.69 kB - -
@sentry/browser (incl. Metrics) 28.83 kB - -
@sentry/browser (incl. Logs) 29.05 kB - -
@sentry/browser (incl. Metrics & Logs) 29.76 kB - -
@sentry/react 29.54 kB - -
@sentry/react (incl. Tracing) 48.84 kB - -
@sentry/vue 33.17 kB - -
@sentry/vue (incl. Tracing) 48.52 kB - -
@sentry/svelte 27.78 kB - -
CDN Bundle 30.14 kB - -
CDN Bundle (incl. Tracing) 48.53 kB - -
CDN Bundle (incl. Logs, Metrics) 31.73 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.83 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 70.98 kB - -
CDN Bundle (incl. Tracing, Replay) 86.04 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 87.34 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.84 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 93.11 kB - -
CDN Bundle - uncompressed 89.88 kB - -
CDN Bundle (incl. Tracing) - uncompressed 146.73 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 94.59 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 150.71 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 219.32 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 265.94 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 269.9 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 279.64 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 283.6 kB - -
@sentry/nextjs (client) 51.36 kB - -
@sentry/sveltekit (client) 46.99 kB - -
@sentry/core/server 80.13 kB - -
@sentry/core/browser 66.56 kB - -
@sentry/node-core 63.21 kB +0.01% +1 B 🔺
@sentry/node 125.66 kB - -
@sentry/node (incl. diagnostics channel injection) 149.46 kB +0.02% +22 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 70.03 kB -0.01% -2 B 🔽
@sentry/node/light 51.32 kB +0.01% +1 B 🔺
@sentry/node - without tracing 74.92 kB +0.01% +1 B 🔺
@sentry/aws-serverless 84.15 kB - -
@sentry/cloudflare (withSentry) - minified 197.51 kB - -
@sentry/cloudflare (withSentry) 485.87 kB - -

View base workflow run

The Turbopack value-injection seeded `__SENTRY_ORCHESTRION__` by assigning a
fresh `{ bundler: [] }` object, replacing any existing marker. Unlike the Bun
banner and `buildInjectPrologue`, this was not merge-safe, so a hybrid
runtime+bundler setup could wipe already-recorded runtime module names before
integrations read them.

The value-injection loader can only emit plain assignments, so it now accepts an
optional raw `prefixCode` and the marker is injected as a merge-safe snippet that
only creates the global/`bundler` array when absent.

Co-Authored-By: Claude Opus 4.8 (1M context) <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.

1 participant