Skip to content

fix(nestjs): trace WebSocket interceptor contexts - #24862

Closed
faizansaiyed123 wants to merge 20 commits into
getsentry:developfrom
faizansaiyed123:fix/nestjs-websocket-tracing-interceptor
Closed

faizansaiyed123 wants to merge 20 commits into
getsentry:developfrom
faizansaiyed123:fix/nestjs-websocket-tracing-interceptor

Conversation

@faizansaiyed123

Copy link
Copy Markdown
Contributor

Extends the existing NestJS tracing interceptor to name WebSocket transactions from the WebSocket pattern, including the Socket.IO namespace when available. Non-Socket.IO adapters fall back to the pattern alone, and contexts without a pattern keep the existing pass-through behavior.

Regression tests cover Socket.IO namespaces, namespace-less adapters, and missing patterns.

Fixes #13810

@faizansaiyed123
faizansaiyed123 requested a review from a team as a code owner September 30, 2026 07:21
@faizansaiyed123
faizansaiyed123 requested review from nicohrubec and s1gr1d and removed request for a team September 30, 2026 07:21
@github-actions github-actions Bot added the external PR from an external contributor label Sep 30, 2026
Comment thread packages/nestjs/src/setup.ts Resolved

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

Stale Bugbot comment from a previous run.

Comment thread packages/nestjs/src/setup.ts Resolved
@faizansaiyed123
faizansaiyed123 force-pushed the fix/nestjs-websocket-tracing-interceptor branch from d2bd884 to 4bca084 Compare September 30, 2026 07:30

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

Stale Bugbot comment from a previous run.

Comment thread packages/nestjs/src/setup.ts Resolved
@faizansaiyed123
faizansaiyed123 force-pushed the fix/nestjs-websocket-tracing-interceptor branch from 4bca084 to 89f0658 Compare September 30, 2026 07:41

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

Stale Bugbot comment from a previous run.

Comment thread packages/nestjs/src/setup.ts Resolved
@faizansaiyed123
faizansaiyed123 force-pushed the fix/nestjs-websocket-tracing-interceptor branch 2 times, most recently from b5cdddd to ef6a094 Compare September 30, 2026 07:57
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

👋 @nicohrubec, @s1gr1d — Please review this PR when you get a chance!

@faizansaiyed123
faizansaiyed123 requested review from a team as code owners October 6, 2026 06:34
@faizansaiyed123
faizansaiyed123 requested review from Lms24, andreiborza and mydea and removed request for a team October 6, 2026 06:34
Comment thread packages/nestjs/src/setup.ts Resolved

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

Stale Bugbot comment from a previous run.

Comment thread packages/nestjs/src/setup.ts Resolved

@Lms24 Lms24 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hey @faizansaiyed123 thanks for opening a PR!
This PR currently has a massive amount of changes. I think it may need a rebase so that we can see what the intended changes are here.

@faizansaiyed123

Copy link
Copy Markdown
Contributor Author

@Lms24 Thanks for the review! Agreed — the branch history has accumulated a large number of upstream commits, which makes the PR difficult to review.

I’ll rebase the branch onto the latest develop and keep only the intended NestJS WebSocket tracing changes.

@faizansaiyed123
faizansaiyed123 force-pushed the fix/nestjs-websocket-tracing-interceptor branch from 629eec6 to d073e4e Compare October 6, 2026 11:29
@faizansaiyed123
faizansaiyed123 force-pushed the fix/nestjs-websocket-tracing-interceptor branch from 6a59f5c to 5353fe6 Compare October 6, 2026 11:31
@faizansaiyed123
faizansaiyed123 requested a review from Lms24 October 6, 2026 13:46
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

👋 @nicohrubec, @s1gr1d — Please review this PR when you get a chance!

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

Stale Bugbot comment from a previous 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.

Stale Bugbot comment from a previous run.

Comment thread packages/nestjs/src/setup.ts Resolved
Comment thread packages/nestjs/src/setup.ts Resolved
Comment thread packages/nestjs/src/setup.ts Resolved
Comment thread packages/nestjs/src/setup.ts Resolved
@faizansaiyed123

Copy link
Copy Markdown
Contributor Author

Hi @nicohrubec, thanks for the feedback. I've pushed the follow-up changes addressing your comments, including instrumentation of the existing Observable and WebSocket E2E coverage.

I've also updated the WebSocket span operation and origin attributes and handled span cleanup if the handler throws.

Could you please take another look at the latest changes and let me know if anything else needs to be addressed? Thanks for your time!

@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 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 664c18b. Configure here.

Comment thread packages/nestjs/src/setup.ts Resolved
Comment thread packages/nestjs/src/setup.ts Resolved
@faizansaiyed123

Copy link
Copy Markdown
Contributor Author

Hi @nicohrubec,

I've pushed the latest fixes addressing the remaining review and Bugbot findings.

I've also added regression tests covering asynchronous WebSocket handler failures and verified that failed handlers correctly produce error-status spans.

All CI checks are now passing.

Could you please take another look at the updated PR when you get a chance? Thanks for your time and feedback!

@nicohrubec

nicohrubec commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

@faizansaiyed123 Thanks for the updates. I'll take another look eventually but this feature is not a high priority for us at the moment and I am tied up with other projects, so might take a while. Sorry about the delay.

@nicohrubec
nicohrubec requested a review from chargome November 20, 2026 13:52
@chargome chargome self-assigned this Nov 23, 2026
@chargome

Copy link
Copy Markdown
Member

Hey @faizansaiyed123, thanks a lot for this PR and for sticking with it through the review rounds!

We're going to take it over from here so we can get it over the line. While testing it we found two things that needed bigger changes:

  • SentryModule.forRoot() registered the tracing interceptor twice. That affects all apps, not just WebSockets, so we're fixing it on its own in fix(nestjs): Register SentryTracingInterceptor only once #26775.
  • Nest only runs global interceptors on WebSocket gateways from v12 on, so this tracing only works on Nest 12+. We moved the e2e app to Nest 12 and added a few fixes on top.

Your commits are kept as they are in #26768, which is stacked on #26775, so you'll be credited when it's released. I'll close this one in favor of those. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external PR from an external contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expand SentryTracingInterceptor to ws context

4 participants