Skip to content

Conversation

@andreiborza
Copy link
Member

No description provided.

@vercel
Copy link

vercel bot commented May 7, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sentry-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 10, 2024 1:17pm

@codecov
Copy link

codecov bot commented May 7, 2024

Bundle Report

Changes will increase total bundle size by 3.01kB ⬆️

Bundle name Size Change
sentry-docs-server 7.43MB 3.01kB ⬆️
sentry-docs-edge-server 456.19kB 0 bytes
sentry-docs-client 6.16MB 2 bytes ⬆️


Once this is done, Sentry's Node SDK captures unhandled exceptions as well as tracing data for your application.

Therefore, we recommend to create a file named `instrumentation.js` that imports and initializes Sentry.
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick regarding line 36 and 46 in this file: Can you change the dash to an em dash?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

Comment on lines 3 to 5
```javascript {tabTitle:CommonJS}
require('./instrumentation.js')

Copy link
Contributor

Choose a reason for hiding this comment

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

I would argue that we should not honor this escape hatch an entire code block.

Considerations:

  • People might do both --require AND the import
  • It might be confusing
  • We really do not want people to do that unless absolutely necessary and a dedicated code block might be promoting it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree. I added these specifically to show that it really has to go to the top and any other imports come after but this is already explained in text as well. Probably better to drop it.

Copy link
Member

Choose a reason for hiding this comment

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

I have a different opinion: We definitely should to show this, because there will def. be people out there who do not have the (easy) capability to adjust the code their app is run in production. Lots of devs do not have direct access to their deployment infrastructure etc, making it much harder for them to get started with using sentry. We can call out why the other solution is preferable and lead with that, but should still show how you can get it to run otherwise. There is really nothing wrong with the instrument-on-top approach for require.js.

Copy link
Member

Choose a reason for hiding this comment

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

actually, we need to keep this anyhow and add a note that this is definitely needed for node <18 - no other way to run stuff there, I think?

Copy link
Member Author

Choose a reason for hiding this comment

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

actually, we need to keep this anyhow and add a note that this is definitely needed for node <18 - no other way to run stuff there, I think?

--require is supported since v1.6.0

Copy link
Member Author

Choose a reason for hiding this comment

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

I have a different opinion: We definitely should to show this, because there will def. be people out there who do not have the (easy) capability to adjust the code their app is run in production. Lots of devs do not have direct access to their deployment infrastructure etc, making it much harder for them to get started with using sentry. We can call out why the other solution is preferable and lead with that, but should still show how you can get it to run otherwise. There is really nothing wrong with the instrument-on-top approach for require.js.

We were just thinking that people will skip over reading the leading text and just copy paste code snippets around, ending up with both --require and a top level import.

Copy link
Member

Choose a reason for hiding this comment

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

--require is supported since v1.6.0

Ah, sweet! Good to know 🚀

We were just thinking that people will skip over reading the leading text and just copy paste code snippets around, ending up with both --require and a top level import.

You need to read this anyhow, as the text instructs you to create another file etc anyhow - this is not as easy as copy-pasting a snippet into your app.js anyhow, I'd argue. If you don't read this, it'll not work anyhow.

I'd just like to argue that while for us it is fine and easy to "just add a CLI flag when running the node app", there are loads of devs out there for whom this is not as trivial, and (as stated before) even more that simply can't do this themselves. Why should we not document how they can still use Sentry even if they can't easily adjust this themselves? I don't really see the upside of "hiding" this away? It's not even that problematic if this is double-initialized, it should work just fine even if somebody does that. And we could even guard against this, if we actually need it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea you're right. I can definitely see some orgs disallowing passing flags to node, or like you said, people not even having the ability to change how things are run.

Will keep it, but maybe give it its own heading — as is, it's easy to not see that this is an alternative way of running it, wdyt?

const http = require("http");
```

```javascript {tabTitle:ESM}
Copy link
Contributor

Choose a reason for hiding this comment

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

Adding a filename here now would be nice!

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

@andreiborza andreiborza force-pushed the ab/node-require-instrumentationjs branch from a2b5709 to 6e20f0f Compare May 7, 2024 13:08
Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

Can we also update the SDK initialization section in the migration guide? https://docs.sentry.io/platforms/javascript/guides/node/migration/v7-to-v8/#updated-sdk-initialization

(feel free to do this in a follow-up PR, don't want to block this any longer than necessary)

@andreiborza
Copy link
Member Author

Can we also update the SDK initialization section in the migration guide? https://docs.sentry.io/platforms/javascript/guides/node/migration/v7-to-v8/#updated-sdk-initialization

(feel free to do this in a follow-up PR, don't want to block this any longer than necessary)

Yep can do.

Copy link
Member

@s1gr1d s1gr1d left a comment

Choose a reason for hiding this comment

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

Thanks for adding this 🙌🏻
Do not forget to also add this to koa, aws-lambda, azure-functions, connect, express and fastify.

## Configure

Sentry should be initialized as early in your app as possible. It is essential that you call `Sentry.init` before you require any other modules in your application - otherwise, auto-instrumentation of these modules will _not_ work.
Sentry should be initialized as early in your app as possible. It is essential that you call `Sentry.init` before you require any other modules in your application otherwise, auto-instrumentation of these modules will _not_ work.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Sentry should be initialized as early in your app as possible. It is essential that you call `Sentry.init` before you require any other modules in your applicationotherwise, auto-instrumentation of these modules will _not_ work.
Sentry should be initialized as early in your app as possible. It is essential that you call `Sentry.init` before you require any other modules in your applicationotherwise, auto-instrumentation of these modules will _not_ work.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, fixed

If you set a `tracesSampleRate`, performance instrumentation will automatically be enabled for you. See <PlatformLink to="/performance/instrumentation/automatic-instrumentation">Automatic Instrumentation</PlatformLink> to learn about all the things that the SDK automatically instruments for you.

You can also manually capture performance data - see <PlatformLink to="/performance/instrumentation/custom-instrumentation">Custom Instrumentation</PlatformLink> for details.
You can also manually capture performance data see <PlatformLink to="/performance/instrumentation/custom-instrumentation">Custom Instrumentation</PlatformLink> for details.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
You can also manually capture performance datasee <PlatformLink to="/performance/instrumentation/custom-instrumentation">Custom Instrumentation</PlatformLink> for details.
You can also manually capture performance datasee <PlatformLink to="/performance/instrumentation/custom-instrumentation">Custom Instrumentation</PlatformLink> for details.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

@@ -0,0 +1,28 @@
---
title: Run Methods
Copy link
Member

Choose a reason for hiding this comment

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

We talked about that already in person: Maybe call this page "Initialization Variants" 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, renamed it.

@@ -0,0 +1,8 @@
---
title: Run as toplevel import
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
title: Run as toplevel import
title: Add as top-level import

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you :) fixed

@andreiborza
Copy link
Member Author

Thanks for adding this 🙌🏻 Do not forget to also add this to koa, aws-lambda, azure-functions, connect, express and fastify.

Added the others except aws-lambda and azure-functions because I'm unsure if we should advocate an extra file there as we discussed in the office the other day.

If you could have another look please :)

@andreiborza andreiborza marked this pull request as ready for review May 10, 2024 08:45
@lforst lforst merged commit b5b1e2c into v8-docs May 10, 2024
@lforst lforst deleted the ab/node-require-instrumentationjs branch May 10, 2024 14:07
mydea pushed a commit that referenced this pull request May 13, 2024
Co-authored-by: vivianyentran <[email protected]>
Co-authored-by: Luca Forstner <[email protected]>
Co-authored-by: Stephanie Anderson <[email protected]>
@github-actions github-actions bot locked and limited conversation to collaborators May 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants