Skip to content
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

fix(node): Use normal require call to import Undici #10388

Merged
merged 8 commits into from
Feb 5, 2024

Conversation

lforst
Copy link
Member

@lforst lforst commented Jan 29, 2024

Dynamic require will work agains us in bundled server-side situations - e.g. Next.js. We are in Node.js world so require should be available in any case. We also use it in the normal http and https instrumentation.

@lforst lforst force-pushed the lforst-undici-normal-require branch from 87bece1 to 1aaeb2e Compare January 29, 2024 11:05
@lforst lforst marked this pull request as ready for review January 29, 2024 14:04
@@ -106,7 +105,7 @@ export class Undici implements Integration {
let ds: DiagnosticsChannel | undefined;
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
ds = dynamicRequire(module, 'diagnostics_channel') as DiagnosticsChannel;
ds = require('diagnostics_channel') as DiagnosticsChannel;
Copy link
Member

Choose a reason for hiding this comment

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

One reason this is there is because diagnostics_channel is only available for Node 16+, won't bundling break when bundling for older versions? (Like Node 14).

Copy link
Member Author

@lforst lforst Jan 30, 2024

Choose a reason for hiding this comment

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

I see it as follows: Every bundler has a built-in escape hatch because diagnostics_channel can always be manually externalized. The newer (sane) webpack versions automatically seem to externalize it out of the box, even on older Node.js versions.

Right now dynamicRequire seems to break fetch instrumentation on the Next.js canary: https://github.com/getsentry/sentry-javascript/actions/runs/7713179805/job/21023035517

With this change, it succeeds: https://github.com/getsentry/sentry-javascript/actions/runs/7712921252/job/21022104165

dynamicRequire effectively breaks bundled code. I see this more as a fix I think.

I have the soft opinion that this change is the lesser evil but I am not totally sure tbh. People affected would be people who are on old node versions && on old webpack versions. Wdyt?

@lforst
Copy link
Member Author

lforst commented Jan 29, 2024

I need to dwell on this for a bit. For some reason this doesn't even fix the issue I wanted to fix with this change: https://github.com/getsentry/sentry-javascript/actions/runs/7697605293/job/20975482956 🤔

Copy link
Contributor

github-actions bot commented Jan 30, 2024

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay, Feedback) - Webpack (gzipped) 78.2 KB (0%)
@sentry/browser (incl. Tracing, Replay) - Webpack (gzipped) 69.43 KB (0%)
@sentry/browser (incl. Tracing, Replay with Canvas) - Webpack (gzipped) 73.36 KB (0%)
@sentry/browser (incl. Tracing, Replay) - Webpack with treeshaking flags (gzipped) 63.04 KB (0%)
@sentry/browser (incl. Tracing) - Webpack (gzipped) 33.38 KB (0%)
@sentry/browser (incl. browserTracingIntegration) - Webpack (gzipped) 33.25 KB (0%)
@sentry/browser (incl. Feedback) - Webpack (gzipped) 31.33 KB (0%)
@sentry/browser (incl. sendFeedback) - Webpack (gzipped) 31.34 KB (0%)
@sentry/browser - Webpack (gzipped) 22.6 KB (0%)
@sentry/browser (incl. Tracing, Replay, Feedback) - ES6 CDN Bundle (gzipped) 76.17 KB (0%)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (gzipped) 67.72 KB (0%)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (gzipped) 33.5 KB (0%)
@sentry/browser - ES6 CDN Bundle (gzipped) 24.66 KB (0%)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (minified & uncompressed) 213.68 KB (0%)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (minified & uncompressed) 101.49 KB (0%)
@sentry/browser - ES6 CDN Bundle (minified & uncompressed) 74.01 KB (0%)
@sentry/browser (incl. Tracing) - ES5 CDN Bundle (gzipped) 36.63 KB (0%)
@sentry/react (incl. Tracing, Replay) - Webpack (gzipped) 69.8 KB (0%)
@sentry/react - Webpack (gzipped) 22.63 KB (0%)
@sentry/nextjs Client (incl. Tracing, Replay) - Webpack (gzipped) 87.42 KB (0%)
@sentry/nextjs Client - Webpack (gzipped) 51.57 KB (0%)
@sentry-internal/feedback - Webpack (gzipped) 17.21 KB (0%)

Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

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

I'm fine with making this change as long as we update troubleshooting docs accordingly.

@lforst
Copy link
Member Author

lforst commented Jan 31, 2024

I will merge this as soon as I have troubleshooting docs merged. Docs code freeze is in place right now tho.

@lforst lforst merged commit 028f4d5 into develop Feb 5, 2024
100 checks passed
@lforst lforst deleted the lforst-undici-normal-require branch February 5, 2024 12:28
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.

None yet

2 participants