ref(server-utils): Ensure injected modules can reliably be picked up#22386
ref(server-utils): Ensure injected modules can reliably be picked up#22386mydea wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 3 potential issues.
❌ 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)); | ||
| } |
There was a problem hiding this comment.
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.
Reviewed by Cursor Bugbot for commit dcccddd. Configure here.
There was a problem hiding this comment.
this is used in a follow up PR, wasn't 100% sure but I guess it's OK to keep this here...
|
|
||
| const INSTRUMENTATION_FN_SYMBOL = Symbol.for('InstrumentationFn'); | ||
| // oxlint-disable-next-line typescript/no-explicit-any | ||
| type InstrumentationFn = ((...args: any[]) => void) & { [INSTRUMENTATION_FN_SYMBOL]?: boolean }; |
There was a problem hiding this comment.
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.
Triggered by project rule: PR Review Guidelines for Cursor Bot
Reviewed by Cursor Bugbot for commit dcccddd. Configure here.
size-limit report 📦
|
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>


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 - wheninit()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:
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__.bundlerand call the SDK bridge (__SENTRY_ORCHESTRION_ON_INJECT__) so channel subscribers are wired up before the module publishes — this matters whenSentry.init()runs ahead of the bundled server (e.g. via--require).invokeOrchestrionInstrumentationhelper 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.