Skip to content

fix(nestjs): Trace WebSocket interceptor contexts - #26768

Open
chargome wants to merge 23 commits into
fix/nestjs-duplicate-tracing-interceptorfrom
fix/nestjs-websocket-tracing-interceptor
Open

chargome wants to merge 23 commits into
fix/nestjs-duplicate-tracing-interceptorfrom
fix/nestjs-websocket-tracing-interceptor

Conversation

@chargome

@chargome chargome commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

What

On Nest 12+, the tracing interceptor creates a websocket span per WebSocket message, named WS <namespace> <pattern>, each in its own trace.

Why

Takes over #24862 from @faizansaiyed123 (commits kept). Nest only applies global interceptors to gateways from v12 on, so the e2e app moved to Nest 12. Stacked on #26775.

Closes: #13810

@chargome chargome self-assigned this Nov 23, 2026
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Compared: 04b8732 (PR test merge using fix/nestjs-duplicate-tracing-interceptor at c5c1dbe)

Against: 24e885e (fix/nestjs-duplicate-tracing-interceptor) · base run #67586

⚠️ Baseline mismatch: 1 fix/nestjs-duplicate-tracing-interceptor commit(s) in the PR build are missing from the baseline. Their size changes also affect this comparison. Compare commits. Re-run once fix/nestjs-duplicate-tracing-interceptor's baseline build for c5c1dbe finishes.

Path Size % Change Change
@sentry/browser 30.34 kB - -
@sentry/browser - with treeshaking flags 28.52 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 28.4 kB - -
@sentry/browser (incl. Tracing) 52.97 kB - -
@sentry/browser (incl. Tracing Core) 40.39 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 52.97 kB - -
@sentry/browser (incl. Tracing, Profiling) 55.83 kB - -
@sentry/browser (incl. Tracing, Replay) 93.02 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 81.86 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 97.36 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 110.96 kB - -
@sentry/browser (incl. Feedback) 48.31 kB - -
@sentry/browser (incl. sendFeedback) 30.91 kB - -
@sentry/browser (incl. FeedbackAsync) 35.96 kB - -
@sentry/browser (incl. Metrics) 31.66 kB - -
@sentry/browser (incl. Logs) 31.94 kB - -
@sentry/browser (incl. Metrics & Logs) 32.59 kB - -
@sentry/react 32.36 kB - -
@sentry/react (incl. Tracing) 55.57 kB - -
@sentry/vue 38.53 kB - -
@sentry/vue (incl. Tracing) 55.91 kB - -
@sentry/svelte 30.36 kB - -
@sentry/effect (client) 42.02 kB - -
@sentry/effect (client, incl. Tracing) 49.17 kB - -
@sentry/effect (client, incl. Tracing, Logs, Metrics) 59.08 kB - -
@sentry/remix (Remix 3 client bundle) 58.61 kB - -
CDN Bundle 32.25 kB - -
CDN Bundle (incl. Tracing) 53.37 kB - -
CDN Bundle (incl. Logs, Metrics) 35.04 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 55.91 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 76.11 kB - -
CDN Bundle (incl. Tracing, Replay) 91.26 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 93.88 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 96.69 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 99.24 kB - -
CDN Bundle - uncompressed 94.2 kB - -
CDN Bundle (incl. Tracing) - uncompressed 157.8 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 102.54 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 165.43 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 232.78 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 278.07 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 285.7 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 290 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 297.62 kB - -
@sentry/nextjs (client) 59.34 kB - -
@sentry/sveltekit (client) 54.25 kB - -
@sentry/core/server 45.81 kB - -
@sentry/core/browser 14.41 kB - -
@sentry/node 156.02 kB - -
@sentry/node/import (ESM hook with diagnostics-channel injection) 83.46 kB - -
@sentry/node - without tracing 89.05 kB -0.01% -5 B 🔽
@sentry/node - without channel injection 144.95 kB -0.01% -2 B 🔽
@sentry/aws-serverless 99.72 kB -0.01% -5 B 🔽
@sentry/cloudflare (withSentry) - minified 209.4 kB - -
@sentry/cloudflare (withSentry) 486.21 kB - -
@sentry/cloudflare (withSentry, instrumented CommonJS package) - minified 212.34 kB - -
@sentry/nextjs/cloudflare (withSentry) - minified 234.63 kB - -

View base workflow run

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Optional E2E tests

All optional checks were successful. 3 successful. See the run.

Successful checks
Check Status
✅ CI: Optional E2E Tests / E2E nestjs-12 (deno) Test (optional) Successful in 55s Details
✅ CI: Optional E2E Tests / E2E nestjs-12 (cloudflare) Test (optional) Successful in 38s Details
✅ CI: Optional E2E Tests / E2E nestjs-12 (bun) Test (optional) Successful in 1m Details

faizansaiyed123 and others added 22 commits November 23, 2026 15:35
Co-Authored-By: OpenAI/ChatGPT GPT-6 <codex@openai.com>
Co-Authored-By: OpenAI/ChatGPT GPT-6 <codex@openai.com>
Mark WebSocket spans as failed when an observer object has no error handler,
since RxJS ignores positional callbacks in that case. Skip expected errors
(WsException, HttpException) the same way SentryGlobalFilter does, and drop
the Socket.IO namespace from span names for regex or function namespaces,
which otherwise resolve to the concrete child namespace and blow up
cardinality.

Move instrumentObservable and its types into src/helpers.ts so the setup
types build no longer emits integrations/*.d.ts into the package root. The
e2e test asserts the op literal because the test app does not depend on
@sentry/conventions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
WebSocket message spans inherited the trace of their long-lived connection, so
unrelated messages landed in one trace. With Socket.IO's polling transport they
also became children of the HTTP request that delivered them instead of
segments. Start each message span in a new trace.

Fall back to the @SubscribeMessage metadata when getPattern() is missing
(Nest 8 and 9), and re-enter the interceptor's isolation scope on subscribe
instead of forking another one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Nest only applies global interceptors to WebSocket gateways from v12 on, so
SentryTracingInterceptor never sees gateway messages on Nest 8 to 11. Move the
nestjs-websockets app to Nest 12 (ESM, like nestjs-12) and drop the getPattern()
fallback, which only mattered for Nest 8 and 9.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chargome
chargome force-pushed the fix/nestjs-websocket-tracing-interceptor branch from 928368a to 8308354 Compare November 23, 2026 14:38
@chargome
chargome changed the base branch from develop to fix/nestjs-duplicate-tracing-interceptor November 23, 2026 14:38
Without a build tsconfig, nest build also compiled tests/ and emitted to dist/src, so the
ESM start script could not find dist/instrument.js.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chargome

Copy link
Copy Markdown
Member Author

bugbot run

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit d7d97c1. Configure here.

@chargome
chargome marked this pull request as ready for review November 24, 2026 05:51

This branch has not been deployed

No deployments
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