Skip to content

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

Open
mydea wants to merge 1 commit into
fn/injected-modules-pickupfrom
fn/lazy-register-orchestrion
Open

fix(server-utils): Ensure all orchestrion instrumentation lazy registers#22387
mydea wants to merge 1 commit into
fn/injected-modules-pickupfrom
fn/lazy-register-orchestrion

Conversation

@mydea

@mydea mydea commented Jul 20, 2026

Copy link
Copy Markdown
Member

Migrates all orchestrion tracing-channel integrations to the invokeOrchestrionInstrumentation helper so that every integration lazily registers its channel subscribers only once the corresponding module is actually injected, rather than registering eagerly at Sentry.init().

Previously each integration wired up its own diagnostics-channel subscription directly, which meant subscribers could be registered before (or without) the target module ever being loaded, and the timing was inconsistent across integrations. Routing everything through the shared helper makes the behavior uniform: subscribers are set up for build-time-injected modules immediately and for runtime-injected modules when injection happens, always before the module publishes, and never more than once.

Alongside the migration, several integrations (hapi, graphql, kafkajs) are restructured into a <name>/index.ts + <name>/instrumentation.ts layout to match the existing convention and keep the instrumentation wiring separate from the integration definition.

Stacked on top of #22386 (ensure injected modules can reliably be picked up).

@github-actions

github-actions Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

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.84 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.21 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.99 kB - -
CDN Bundle (incl. Tracing, Replay) 86.05 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 87.35 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.85 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 93.12 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.35 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 265.96 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 269.93 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 279.67 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 283.62 kB - -
@sentry/nextjs (client) 51.36 kB - -
@sentry/sveltekit (client) 46.99 kB - -
@sentry/core/server 80.26 kB - -
@sentry/core/browser 66.69 kB - -
@sentry/node-core 63.21 kB -0.01% -1 B 🔽
@sentry/node 125.73 kB - -
@sentry/node (incl. diagnostics channel injection) 149.78 kB +0.18% +263 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 - -
@sentry/aws-serverless 84.15 kB - -
@sentry/cloudflare (withSentry) - minified 197.51 kB - -
@sentry/cloudflare (withSentry) 485.87 kB - -

View base workflow run

Comment thread packages/server-utils/src/orchestrion/config/nestjs.ts Outdated

@timfish timfish left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I can't find where invokeOrchestrionInstrumentation is defined 🤔

@mydea

mydea commented Jul 21, 2026

Copy link
Copy Markdown
Member Author

I can't find where invokeOrchestrionInstrumentation is defined 🤔

This is in the other PR in this stack: #22386

@mydea
mydea force-pushed the fn/lazy-register-orchestrion branch from 8e918d3 to 03b2355 Compare July 21, 2026 07:55
@mydea
mydea marked this pull request as ready for review July 21, 2026 07:55
@mydea
mydea requested a review from a team as a code owner July 21, 2026 07:55
@mydea
mydea requested review from msonnb and stephanie-anderson and removed request for a team July 21, 2026 07:55

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

There are 2 total unresolved issues (including 1 from previous review).

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 03b2355. Configure here.

Comment thread packages/server-utils/src/integrations/tracing-channel/redis.ts
@mydea
mydea force-pushed the fn/injected-modules-pickup branch from 1ba8963 to 3e8c1ea Compare July 21, 2026 08:34
@mydea
mydea force-pushed the fn/lazy-register-orchestrion branch from 03b2355 to 93dba1a Compare July 21, 2026 08:34
Comment on lines +87 to 89
setup(client) {
invokeOrchestrionInstrumentation(client, langchainModuleNames, instrumentLangChain, [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: Calling Sentry.init() multiple times causes subsequent clients to skip instrumentation because invokeOrchestrionInstrumentation deduplicates based on a shared, module-level function reference.
Severity: MEDIUM

Suggested Fix

The deduplication logic in invokeOrchestrionInstrumentation should be client-aware. Instead of marking the function object globally, the check should be scoped per client. For example, maintain a set of instrumented functions on the client object itself, or use a WeakMap with the client as the key to track which instrumentations have been applied for that specific client. This ensures that each client can be instrumented independently, respecting the setup(client) contract.

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#L87-L89

Potential issue: The `invokeOrchestrionInstrumentation` function uses `hasBeenInjected`
to prevent re-instrumentation. However, the deduplication key is the callback function
object itself (e.g., `instrumentLangChain`), which is a module-level singleton. When
`Sentry.init()` is called multiple times, it creates new clients. The first client's
`setup(client)` call successfully instruments and marks the callback function.
Subsequent calls for new clients will see the function is already marked and will skip
instrumentation entirely for that client. This leads to a silent loss of tracing for any
client initialized after the first one.

Also affects:

  • packages/server-utils/src/integrations/tracing-channel/koa.ts:95~97

Did we get this right? 👍 / 👎 to inform future reviews.

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