Skip to content

ref(node): Avoid double wrapping http module for vercel on Node #16178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

mydea
Copy link
Member

@mydea mydea commented Apr 30, 2025

This PR is a follow up to #16177

There, we found out that double-wrapping (with stealthWrap) the http module seems to break in ESM mode, for whatever reason - us double-wrapping this leads to the OTEL-instrumentation creating spans twice, for whatever reason.

We removed this for the core sentry-http instrumentation, but we still do it for vercel-edge here. For consistency, this cleans this up so we should be safe.

As an added benefit, it again leads to all the sentry-specific instrumentation code to be in one place, and to us not having to care about instrumentation order, hopefully, if this actually works.

@mydea mydea requested a review from lforst April 30, 2025 14:25
@mydea mydea self-assigned this Apr 30, 2025
@mydea mydea force-pushed the fn/patch-response-channel branch from 67ee12d to 512e319 Compare April 30, 2025 14:25
Copy link
Contributor

github-actions bot commented Apr 30, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 23.34 KB - -
@sentry/browser - with treeshaking flags 23.16 KB - -
@sentry/browser (incl. Tracing) 37.22 KB - -
@sentry/browser (incl. Tracing, Replay) 74.45 KB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 68.32 KB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 79.11 KB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 90.93 KB - -
@sentry/browser (incl. Feedback) 39.72 KB - -
@sentry/browser (incl. sendFeedback) 27.96 KB - -
@sentry/browser (incl. FeedbackAsync) 32.72 KB - -
@sentry/react 25.14 KB - -
@sentry/react (incl. Tracing) 39.22 KB - -
@sentry/vue 27.6 KB - -
@sentry/vue (incl. Tracing) 38.99 KB - -
@sentry/svelte 23.36 KB - -
CDN Bundle 24.55 KB - -
CDN Bundle (incl. Tracing) 37.3 KB - -
CDN Bundle (incl. Tracing, Replay) 72.34 KB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 77.62 KB - -
CDN Bundle - uncompressed 71.62 KB - -
CDN Bundle (incl. Tracing) - uncompressed 110.34 KB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 221.63 KB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 234.15 KB - -
@sentry/nextjs (client) 40.83 KB - -
@sentry/sveltekit (client) 37.72 KB - -
@sentry/node 144.26 KB -0.11% -153 B 🔽
@sentry/node - without tracing 96.14 KB -0.16% -150 B 🔽
@sentry/aws-serverless 120.49 KB -0.14% -167 B 🔽

View base workflow run

@mydea mydea force-pushed the fn/http-instrumentation-diagnostics-channel branch from 72ddee3 to 596dcee Compare May 2, 2025 11:14
@lforst
Copy link
Member

lforst commented May 5, 2025

Would you mind explaining in the PR description why we do this and what this PR does? I can see us going back to this in 3 months and asking ourselves wtf

@mydea mydea force-pushed the fn/http-instrumentation-diagnostics-channel branch from aff551f to 0cd1834 Compare May 5, 2025 08:27
Base automatically changed from fn/http-instrumentation-diagnostics-channel to develop May 5, 2025 12:24
@mydea mydea force-pushed the fn/patch-response-channel branch from 512e319 to 96423b2 Compare May 5, 2025 12:32
@mydea mydea changed the title ref(node): Avoid double wrapping http module for vercel-edge ref(node): Avoid double wrapping http module for vercel on Node May 5, 2025
@lforst
Copy link
Member

lforst commented May 6, 2025

To recapitulate, what needs to happen for the logic to still work is to register the res.on('close') listener after OTEL registers its own res.on('close') listener for ending a span. Reminder that res.on('close') is only fired after res.end() has been called.

Findings so far, because the current approach doesn't work:

  • Putting the patching logic into http.server.response.created does not work because it will run before OTEL applies its .on('close') handler.
  • Putting the patching logic into http.server.response.finish for some reason does not work because the diagnostic handler weirdly runs after res.on('close') is fired (even though the code in Node.js would indicate otherwise???).

tldr we have no good place to register the res.on('close') handler...

mydea added a commit that referenced this pull request May 6, 2025
As pre-work for
#16178, actually add
a test for this (kind of). This showed that there was actually a
fundamental flaw here, as we looked as the `req` not the `res`, oops.
@mydea mydea force-pushed the fn/patch-response-channel branch from 96423b2 to 8e6d77e Compare May 7, 2025 08:43
@mydea mydea marked this pull request as ready for review May 7, 2025 09:17
@mydea
Copy link
Member Author

mydea commented May 7, 2025

OK we can't get this to work on Vercel on prod, so we'll just remove this for now until we get a better handle on this 😬 cc @lforst

@lforst
Copy link
Member

lforst commented May 7, 2025

I am in support of removing

@mydea
Copy link
Member Author

mydea commented May 7, 2025

Replaced by #16217

@mydea mydea closed this May 7, 2025
@mydea mydea deleted the fn/patch-response-channel branch May 7, 2025 13:35
mydea added a commit that referenced this pull request May 7, 2025
We could never get this to apply properly on vercel in production, so
we're removing this for now and may revisit this later.

Replaces #16178
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