Skip to content

fix(server-utils): Ensure all orchestrion instrumentation lazy registers#22518

Open
isaacs wants to merge 1 commit into
developfrom
isaacs/lazy-register-orchestrion
Open

fix(server-utils): Ensure all orchestrion instrumentation lazy registers#22518
isaacs wants to merge 1 commit into
developfrom
isaacs/lazy-register-orchestrion

Conversation

@isaacs

@isaacs isaacs commented Jul 23, 2026

Copy link
Copy Markdown
Member

This ports and refactors the intent of #22387, using the mechanisms landed on develop in #22094, rather than the mechanisms in #22386 which are similar in intent, but substantially different in implementation.

The difference from #22387 is entirely in the plumbing underneath the helper. The way that "is my module injected?" and "tell me when it gets injected" are answered, both now use the machinery that already landed.

Beyond that, the actual registration, event emitting, double-wrap guard, and integration refactoring, should all look very familiar.

@isaacs
isaacs requested review from JPeer264 and mydea July 23, 2026 03:32
@isaacs
isaacs requested review from a team as code owners July 23, 2026 03:32
Comment thread packages/server-utils/src/integrations/tracing-channel/mongoose.ts Outdated
Comment thread packages/server-utils/src/orchestrion/instrumentation.ts
@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.95 kB - -
@sentry/browser - with treeshaking flags 26.39 kB - -
@sentry/browser (incl. Tracing) 46.41 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 48.18 kB - -
@sentry/browser (incl. Tracing, Profiling) 51.21 kB - -
@sentry/browser (incl. Tracing, Replay) 85.69 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 75.33 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 90.4 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 103.06 kB - -
@sentry/browser (incl. Feedback) 45.13 kB - -
@sentry/browser (incl. sendFeedback) 32.74 kB - -
@sentry/browser (incl. FeedbackAsync) 37.8 kB - -
@sentry/browser (incl. Metrics) 29.04 kB - -
@sentry/browser (incl. Logs) 29.26 kB - -
@sentry/browser (incl. Metrics & Logs) 29.97 kB - -
@sentry/react 29.75 kB - -
@sentry/react (incl. Tracing) 48.71 kB - -
@sentry/vue 33.38 kB - -
@sentry/vue (incl. Tracing) 48.4 kB - -
@sentry/svelte 27.97 kB - -
CDN Bundle 30.28 kB - -
CDN Bundle (incl. Tracing) 48.26 kB - -
CDN Bundle (incl. Logs, Metrics) 31.85 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.58 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 71.13 kB - -
CDN Bundle (incl. Tracing, Replay) 85.83 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 87.14 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.6 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.89 kB - -
CDN Bundle - uncompressed 90.15 kB - -
CDN Bundle (incl. Tracing) - uncompressed 145.22 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 94.86 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 149.2 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 219.62 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 264.46 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 268.42 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 278.16 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 282.11 kB - -
@sentry/nextjs (client) 51.24 kB - -
@sentry/sveltekit (client) 46.84 kB - -
@sentry/core/server 80.05 kB - -
@sentry/core/browser 52.01 kB - -
@sentry/node 123.14 kB -0.01% -1 B 🔽
@sentry/node (incl. diagnostics channel injection) 167.33 kB +0.12% +190 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 166 B - -
@sentry/node - without tracing 73.31 kB -0.01% -1 B 🔽
@sentry/aws-serverless 82.82 kB - -
@sentry/cloudflare (withSentry) - minified 197.05 kB - -
@sentry/cloudflare (withSentry) 484.73 kB - -

View base workflow run

@isaacs
isaacs force-pushed the isaacs/lazy-register-orchestrion branch 2 times, most recently from 73c683a to d752238 Compare July 23, 2026 15:13
Comment thread packages/server-utils/src/integrations/tracing-channel/knex.ts Outdated
@isaacs

isaacs commented Jul 23, 2026

Copy link
Copy Markdown
Member Author

Going to port this atop #22443 once that lands, since there are some conflicts.


UPDATE: this is now done. Single commit can base cleanly on develop if CI goes green and reviewers approve.

@isaacs
isaacs force-pushed the isaacs/lazy-register-orchestrion branch from 6d6a126 to 464dc8f Compare July 23, 2026 22:41
isaacs added a commit that referenced this pull request Jul 23, 2026
…on Node (#22518)

Co-Authored-By: isaacs <i@izs.me>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@isaacs
isaacs force-pushed the isaacs/lazy-register-orchestrion branch from 464dc8f to ae93c4e Compare July 23, 2026 22:43
@isaacs
isaacs enabled auto-merge (rebase) July 23, 2026 22:43
Comment thread packages/server-utils/src/orchestrion/instrumentation.ts Outdated
isaacs added a commit that referenced this pull request Jul 24, 2026
Comment thread packages/server-utils/src/orchestrion/instrumentation.ts
isaacs added a commit that referenced this pull request Jul 24, 2026
…on Node (#22518)

Co-Authored-By: isaacs <i@izs.me>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@isaacs
isaacs force-pushed the isaacs/lazy-register-orchestrion branch from 38d60ec to 7edaad4 Compare July 24, 2026 14:28

@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.

Reviewed by Cursor Bugbot for commit 7edaad4. Configure here.

const marker = (GLOBAL_OBJ.__SENTRY_ORCHESTRION__ ??= {});
marker.onInject ??= (moduleName: string): void => {
getClient()?.emit('orchestrion.module-runtime-injected', moduleName);
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Premature orchestrion marker breaks fallbacks

High Severity

registerDiagnosticsChannelInjection now creates globalThis.__SENTRY_ORCHESTRION__ (to install onInject) before hook registration succeeds. On the skip/failure returns, that marker is left behind, so isOrchestrionInjected() becomes true even though nothing will inject channels. Opt-in paths that choose channel vs OTel from that check (knex, dataloader, Nest) then take the channel path and lose spans with no OTel fallback.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 7edaad4. Configure here.

Comment on lines +85 to +94
const cleanup = client.on('orchestrion.module-runtime-injected', (moduleName: string) => {
if (hasBeenInstrumented(callback)) {
cleanup();
return;
}
if (moduleNames.includes(moduleName)) {
run();
cleanup();
}
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: In deferred instrumentation, the event listener is removed via cleanup() before the async waitForTracingChannelBinding retry completes, potentially causing permanent loss of instrumentation if the binding is unavailable.
Severity: MEDIUM

Suggested Fix

The cleanup() function should only be called after the instrumentation callback has successfully executed and been marked as instrumented. This can be achieved by moving the cleanup() call inside the callback that is passed to waitForTracingChannelBinding.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: packages/server-utils/src/orchestrion/instrumentation.ts#L85-L94

Potential issue: When instrumentation is deferred for a module that is not yet loaded,
an event listener is registered. If the async-context binding is not available when the
module injection event fires, `waitForTracingChannelBinding` schedules an asynchronous
retry. However, the event listener is immediately and synchronously removed via
`cleanup()`. If this retry also fails to find the binding, the instrumentation callback
is never executed, and the callback is not marked as instrumented. Because the listener
has been removed, the instrumentation for that module is permanently and silently lost.

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