Skip to content

feat(nuxt): Improve Nuxt server-side setup docs #12102

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

Merged
merged 4 commits into from
Dec 30, 2024
Merged

Conversation

s1gr1d
Copy link
Member

@s1gr1d s1gr1d commented Dec 12, 2024

DESCRIBE YOUR PR

Further improve the Nuxt server-side setup docs after feedback.

IS YOUR CHANGE URGENT?

Help us prioritize incoming PRs by letting us know when the change needs to go live.

  • Urgent deadline (GA date, etc.):
  • Other deadline:
  • None: Not urgent, can wait up to 1 week+

SLA

  • Teamwork makes the dream work, so please add a reviewer to your PRs.
  • Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it.
    Thanks in advance for your help!

PRE-MERGE CHECKLIST

Make sure you've checked the following before merging your changes:

  • Checked Vercel preview for correctness, including links
  • PR was reviewed and approved by any necessary SMEs (subject matter experts)
  • PR was reviewed and approved by a member of the Sentry docs team

Copy link

vercel bot commented Dec 12, 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 Dec 30, 2024 11:45am
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
changelog ⬜️ Ignored (Inspect) Visit Preview Dec 30, 2024 11:45am
develop-docs ⬜️ Ignored (Inspect) Visit Preview Dec 30, 2024 11:45am

Copy link

codecov bot commented Dec 12, 2024

Bundle Report

Changes will increase total bundle size by 143 bytes (0.0%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
sentry-docs-server-cjs 10.36MB 9 bytes (0.0%) ⬆️
sentry-docs-edge-server-array-push 366.68kB 140 bytes (0.04%) ⬆️
sentry-docs-client-array-push 9.28MB 6 bytes (-0.0%) ⬇️

@@ -7,17 +7,17 @@ description: "Learn how to use the node --import CLI flag."
## Understanding the `--import` CLI Flag

The [`--import` CLI flag](https://nodejs.org/api/cli.html#--importmodule) in Node is the default way in ESM to preload a module before the application starts.
If you cannot use the SDK's <PlatformLink to="/install/dynamic-import/">default dynamic import behaviour</PlatformLink>, setting
this flag is crucial for ensuring proper server-side initialization, as Sentry needs to be initialized before the rest of the application runs.
Setting this flag is crucial for ensuring proper server-side initialization, as Sentry needs to be initialized before the rest of the application runs.
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
Setting this flag is crucial for ensuring proper server-side initialization, as Sentry needs to be initialized before the rest of the application runs.
Setting this flag is crucial for ensuring proper server-side initialization, as Sentry needs to be initialized before the import graph of your application is resolved by Node. This is necessary for instrumentation of ESM modules to be possible.

This is not fully correct, or possibly misleading, because import at the top would also be "before the rest of the application runs". Actually, the problem is that Sentry needs to be initialized "before the import graph is resolved" 🤔 Which is why this has to happen in --import. Not sure how easy that is to understand though 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

True, I changed it a bit: "Setting this flag is crucial for ensuring proper server-side initialization, as Sentry needs to be initialized before Node.js resolves the entire import graph of your application. This is necessary for enabling proper instrumentation of ESM module"

Copy link
Member Author

@s1gr1d s1gr1d Dec 30, 2024

Choose a reason for hiding this comment

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

After Lizas review, I took a look at this again and I think this is true for the dynamic import (as it creates a new import graph). But for --import it's actually correct, that it loads before the application starts.
However, I will update it in the dynamic import page, as I wrote the same sentence there.

From the Node docs:

  • "The hooks can be registered before the application code is run by using the --import." here
  • "Preload the specified module at startup." here

I'll change it to this:

The --import CLI flag in Node is the default way in ESM to preload a specified module at startup.
Setting this CLI flag is crucial for ensuring proper server-side initialization, as Sentry needs to be initialized before the application runs.
This will register Sentry's loader hook and therefore enable proper instrumentation of ESM modules.

Comment on lines 16 to 17
- **Netlify** only allows scoped environment variables on its paid plans at this time
- **Vercel** doesn't currently provide an option for scoping environment variables
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
- **Netlify** only allows scoped environment variables on its paid plans at this time
- **Vercel** doesn't currently provide an option for scoping environment variables
- On **Netlify**, it is as of now not possible to configure `--import` properly.
- On **Vercel**, it is as of now not possible to configure `--import` properly.

should we just write it like this? 🤔 As the unknown path is also an issue there, in addition to the scopes variables stuff?

},
})
```
We recommend the guide for installing the SDK with the <PlatformLink to="/install/cli-import">CLI flag `--import`</PlatformLink> or a <PlatformLink to="/install/top-level-import/">top-level import</PlatformLink>
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
We recommend the guide for installing the SDK with the <PlatformLink to="/install/cli-import">CLI flag `--import`</PlatformLink> or a <PlatformLink to="/install/top-level-import/">top-level import</PlatformLink>
We recommend the guide for installing the SDK with the <PlatformLink to="/install/cli-import">CLI flag `--import`</PlatformLink> or a <PlatformLink to="/install/limited-server-tracing/">limited server tracing</PlatformLink>

@@ -1,20 +1,21 @@
---
title: Top-level import
title: Limited Server Tracing
Copy link
Member

Choose a reason for hiding this comment

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

Not sure, do we need to add a redirect for this renamed page? 🤔 Not sure how many links to the /top-level-import path are reasonably out there...?

Copy link
Member Author

Choose a reason for hiding this comment

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

It was online for quite some time so maybe not a bad idea

---

## Understanding Top-level `import`
## Understanding Limited Server Tracing

Sentry needs to be initialized before the application starts.
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 needs to be initialized before the application starts.
Sentry needs to be initialized before the import graph is resolved by Node.


```

<Alert level="warning">
Copy link
Member

Choose a reason for hiding this comment

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

Not 100% sure, but do we need to make this an alert? What about instead, just making this regular text? This is part of the server-side verify step basically, isn't 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 made part of it an alert. So the notice about dev mode and the troubleshooting link are in the alert.

Copy link
Contributor

@lizokm lizokm left a comment

Choose a reason for hiding this comment

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

Added a few comments!

If the default way of adding an <PlatformLink to="/install/cli-import">`--import` CLI flag</PlatformLink> flag does not work for you,
set up the SDK for adding a top-level `import`. This will import the Sentry server-side config at the top of the Nuxt server entry file.
set up the SDK for adding a top-level `import`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
set up the SDK for adding a top-level `import`.
enable the SDK to add a top-level `import`.

set up the SDK for adding a top-level `import`. This will import the Sentry server-side config at the top of the Nuxt server entry file.
set up the SDK for adding a top-level `import`.

The automatically added top-level `import` will import the Sentry server-side config at the top of the Nuxt server entry file.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
The automatically added top-level `import` will import the Sentry server-side config at the top of the Nuxt server entry file.
The automatically added top-level `import` will then import the Sentry server-side config to the top of the Nuxt server entry file.

import './sentry.server.config.mjs';
// Note: The file may have some imports and code, related to debug IDs
```
The SDK then automatically imports this file at the top of the Nitro server entry in the build output.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
The SDK then automatically imports this file at the top of the Nitro server entry in the build output.
The SDK will then automatically import this file to the top of the Nitro server entry in the build output.

@s1gr1d s1gr1d merged commit 3550cc4 into master Dec 30, 2024
13 checks passed
@s1gr1d s1gr1d deleted the sig/nuxt-setup-improve branch December 30, 2024 12:22
@github-actions github-actions bot locked and limited conversation to collaborators Jan 15, 2025
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.

3 participants