Skip to content

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

Open
isaacs wants to merge 2 commits into
developfrom
isaacs/lazy-register-orchestrion
Open

fix(server-utils): Ensure all orchestrion instrumentation lazy registers#22518
isaacs wants to merge 2 commits 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 - -
@sentry/node (incl. diagnostics channel injection) 167.41 kB +0.16% +267 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 166 B - -
@sentry/node - without tracing 73.3 kB -0.01% -2 B 🔽
@sentry/aws-serverless 82.81 kB -0.01% -1 B 🔽
@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
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
Comment thread packages/server-utils/src/orchestrion/runtime/register.ts
Comment thread packages/server-utils/src/orchestrion/instrumentation.ts
isaacs added a commit that referenced this pull request Jul 24, 2026
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 added a commit that referenced this pull request Jul 24, 2026
isaacs added a commit that referenced this pull request Jul 24, 2026
@isaacs
isaacs force-pushed the isaacs/lazy-register-orchestrion branch from 549f754 to 3f5b4ba Compare July 24, 2026 16:38
Comment thread packages/server-utils/src/orchestrion/bundler/webpack-loader.ts
Comment thread packages/server-utils/src/orchestrion/bundler/webpack-loader.ts Outdated
isaacs added a commit that referenced this pull request Jul 24, 2026
…n 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 62e4483 to 96d3ac4 Compare July 24, 2026 19:44
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 96d3ac4 to bf10337 Compare July 24, 2026 19:45
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 bf10337 to 0f52d62 Compare July 24, 2026 22:37
Comment thread packages/server-utils/src/integrations/tracing-channel/redis.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 0f52d62 to d48f476 Compare July 24, 2026 23:18

@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 d48f476. Configure here.

Comment thread packages/server-utils/src/integrations/tracing-channel/langchain.ts Outdated
…on Node (#22518)

fix: JS-3059
fix: #22302

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 d48f476 to f3d53d0 Compare July 25, 2026 15:49
Comment on lines +56 to +61
invokeOrchestrionInstrumentation(client, langchainModuleNames, instrumentChatModels, [options], {
requiresTracingChannelBinding: false,
});
// Embeddings open their own spans via `bindTracingChannelToSpan`, which
// needs the binding.
invokeOrchestrionInstrumentation(client, langchainModuleNames, instrumentEmbeddings, [options]);

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: When using multiple Sentry clients, the langChainChannelIntegration only applies options from the first client. Subsequent client configurations are ignored due to a global instrumentation guard.
Severity: MEDIUM

Suggested Fix

The instrumentation guard should be scoped per-client or per-integration instance rather than globally on the callback function reference. This would allow instrumentChatModels and instrumentEmbeddings to be re-invoked with different options for each distinct Sentry client, respecting their individual configurations.

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/integrations/tracing-channel/langchain.ts#L56-L61

Potential issue: When multiple Sentry clients are initialized with different
`LangChainOptions`, only the options from the first client are actually used. This
occurs because the instrumentation functions, `instrumentChatModels` and
`instrumentEmbeddings`, are marked with a global `INSTRUMENTED` guard after being called
for the first client. When a second client is initialized, the
`invokeOrchestrionInstrumentation` function sees this global guard and exits early,
preventing the new options from being applied. As a result, all subsequent LangChain
instrumentation incorrectly uses the configuration from the first client, breaking the
expected per-client setup behavior.

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