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 http monkeypatching for Node 18.15 introduced in v7.42.0 #7425

Closed
3 tasks done
dotansimha opened this issue Mar 12, 2023 · 4 comments · Fixed by #7430
Closed
3 tasks done

Fix http monkeypatching for Node 18.15 introduced in v7.42.0 #7425

dotansimha opened this issue Mar 12, 2023 · 4 comments · Fixed by #7430
Assignees
Labels
Package: node Issues related to the Sentry Node SDK Type: Bug

Comments

@dotansimha
Copy link

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using? If you use the CDN bundles, please specify the exact bundle (e.g. bundle.tracing.min.js) in your SDK setup.

@sentry/node

SDK Version

7.42.0

Framework Version

Node 18.15

Link to Sentry event

No response

SDK Setup

Nothing too fancy. Just a regular setup with defaults:

    Sentry.init({
      serverName: 'webhooks',
      enabled: !!env.sentry,
      environment: env.environment,
      dsn: env.sentry.dsn,
      release: env.release,
    });

Steps to Reproduce

Since upgraded to v7.42.0 along with Node 18.15, I get this error when my server starts:

TypeError: Cannot assign to read only property 'get' of object '[object Module]'
    at fill (file:///usr/src/app/index.js:169657:16)
    at Http2.setupOnce (file:///usr/src/app/index.js:174266:5)
    at setupIntegration (file:///usr/src/app/index.js:172908:17)
    at file:///usr/src/app/index.js:172899:7
    at Array.forEach (<anonymous>)
    at setupIntegrations (file:///usr/src/app/index.js:172897:16)
    at NodeClient2.setupIntegrations (file:///usr/src/app/index.js:173180:28)
    at Hub2.bindClient (file:///usr/src/app/index.js:171810:14)
    at initAndBind (file:///usr/src/app/index.js:173445:7)
    at init (file:///usr/src/app/index.js:175864:3)
    at main (file:///usr/src/app/index.js:210652:5)
    at file:///usr/src/app/index.js:210766:1
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

And this line is found in:
https://github.com/getsentry/sentry-javascript/blob/develop/packages/node/src/integrations/http.ts#L105

It seems like a recent PR was touching these code areas? #7377

Reverting back to 7.41.0 seems to work perfectly fine.

Expected Result

Actual Result

@timfish timfish added Status: Confirmed Package: node Issues related to the Sentry Node SDK labels Mar 12, 2023
@timfish
Copy link
Collaborator

timfish commented Mar 12, 2023

This has also been reproduced in one of the Electron SDK e2e tests that uses Rollup for the node process code:
https://github.com/getsentry/sentry-electron/actions/runs/4393299439/jobs/7693621262#step:5:489

Looks like this is caused by #7377 + strict mode + bundled into a single file.

@mydea mydea changed the title Cannot assign to read only property 'get' of object '[object Module]' on Node 18.15 and SDK v7.42.0 Fix http monkeypatching for Node 18.15 introduced in v7.42.0 Mar 13, 2023
@Lms24 Lms24 self-assigned this Mar 13, 2023
@Lms24
Copy link
Member

Lms24 commented Mar 13, 2023

Hi @dotansimha thanks for reporting! I'll take a look at this. Ideally we can find a solution that doesn't require (pun intended) us to switch back to require.

@Lms24
Copy link
Member

Lms24 commented Mar 13, 2023

@dotansimha: We've opened a PR (#7430) to partially revert #7377. In my reproduction (which I initially got to fail with the same error you reported), everything seems to work now again.

Would you nevertheless mind sharing a little bit about your project setup? I'm assuming you're using a bundler, right? If yes, please share your config and how you're setting your bundler up. Are you transpiling to CJS?
Background: We want to continue investigating this a bit to see if we can come up with some kind of alternative in the long run. Having more data and more repros helps us a great deal here.

Lms24 added a commit that referenced this issue Mar 13, 2023
…7430)

Partially revert #7377 which caused monkey patching errors when patching the native `http` and `https` modules in the Node SDK (#7425). Similarly, also our Serverless SDK was subjected to the same problem (#7421). 

The problem is that `import` doesn't permit monkey patching of the imported (`http(s)`) module, producing this error:

```bash
TypeError: Cannot assign to read only property 'get' of object '[object Module]'
```

I tried using a dynamic import instead but got the same result. So it seems like we can only use `require` here :(
@dotansimha
Copy link
Author

dotansimha commented Mar 13, 2023

@dotansimha: We've opened a PR (#7430) to partially revert #7377. In my reproduction (which I initially got to fail with the same error you reported), everything seems to work now again.

That's great, thank you for the quick response on this one! Can't wait for the release to test it :)

Would you nevertheless mind sharing a little bit about your project setup? I'm assuming you're using a bundler, right? If yes, please share your config and how you're setting your bundler up. Are you transpiling to CJS? Background: We want to continue investigating this a bit to see if we can come up with some kind of alternative in the long run. Having more data and more repros helps us a great deal here.

Sure. We are using a custom tool (https://github.com/kamilkisiela/bob) that wraps tsup (basically, esbuild). You can find a snippet here:
https://github.com/kamilkisiela/bob/blob/master/src/commands/runify.ts#L241-L273 . For that specific package built and failed with the Sentry package, we had useEsm = true.

I'll ask our team to share a bit more information here soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: node Issues related to the Sentry Node SDK Type: Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants