Skip to content

feat(nuxt): Add "Deployment Provider Setup" #11486

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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/platforms/javascript/common/best-practices/index.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Special Use Cases
description: "Learn how to set up Sentry for several specific use cases with these best practice guides."
sidebar_order: 6
sidebar_order: 7
notSupported:
- javascript.node
- javascript.aws-lambda
Expand Down
2 changes: 1 addition & 1 deletion docs/platforms/javascript/common/data-management/index.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Data Management
description: Learn about different ways to scrub data within your SDK before it gets sent to Sentry.
sidebar_order: 7
sidebar_order: 8
---

<PageGrid />
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
---
title: General
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
title: General
title: General Deployment Setup

sidebar_order: 1
description: "Learn about the general deployment setup when using Sentry."
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
description: "Learn about the general deployment setup when using Sentry."
description: "Learn how to use a general deployment setup when adding Sentry to a Nuxt project in ESM syntax."

supported:
- javascript.nuxt
---

<PlatformSection supported={['javascript.nuxt']}>
Nuxt compiles all your code for the client and server side to ECMAScript modules (ESM) syntax ([learn more about ESM and Nuxt](https://nuxt.com/docs/guide/concepts/esm)).
</PlatformSection>

Comment on lines +8 to +12
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
<PlatformSection supported={['javascript.nuxt']}>
Nuxt compiles all your code for the client and server side to ECMAScript modules (ESM) syntax ([learn more about ESM and Nuxt](https://nuxt.com/docs/guide/concepts/esm)).
</PlatformSection>
<PlatformSection supported={['javascript.nuxt']}>
Nuxt compiles all your code for the client and server side to ECMAScript modules (ESM) syntax ([learn more about ESM and Nuxt](https://nuxt.com/docs/guide/concepts/esm)).
</PlatformSection>

It would be great if you could add a little more context here. Like a sentence or two explaining why a user would want to use this type of setup. Maybe something as simple as: Use this setup if you want to add Sentry to a Nuxt project in ESM syntax. (As the first line on the page.)

Adding Sentry on the server-side for a project in ESM syntax is different from adding Sentry to a project in CommonJS (CJS) syntax.
The Sentry initialization code needs to be loaded first when the application starts.
Comment on lines +13 to +14
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
Adding Sentry on the server-side for a project in ESM syntax is different from adding Sentry to a project in CommonJS (CJS) syntax.
The Sentry initialization code needs to be loaded first when the application starts.
Because adding Sentry on the server-side for a project in ESM syntax is different than adding Sentry to a project in CommonJS (CJS) syntax, you'll want to load the Sentry initialization code first when the application starts.

Preloading the Sentry server config file can be done with the Node [`--import`](https://nodejs.org/api/cli.html#--importmodule) CLI flag when starting the application.
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
Preloading the Sentry server config file can be done with the Node [`--import`](https://nodejs.org/api/cli.html#--importmodule) CLI flag when starting the application.
You can preload the Sentry server config file with the Node [`--import`](https://nodejs.org/api/cli.html#--importmodule) CLI flag when starting the application.


Internally, Sentry uses a specific ESM loader hook "[import-in-the-middle/hook.mjs](https://www.npmjs.com/package/import-in-the-middle)" which is
automatically added when you add the Sentry server-side config file with `--import`. This will automatically instrument all modules in your application.
Comment on lines +17 to +18
Copy link
Member

Choose a reason for hiding this comment

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

l: I am not sure if we need to/should include this - this is very much internal stuff that users don't really need to know/understand, and also could possibly change. IMHO it is enough to have the paragraph above, which states that sentry has to be initialized via --import ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I tend to agree. I think wherever possible, we should only give the users the information they need most and avoid going too deep :)


## Setup Sentry Server Config

As described above, there are some prerequisites for adding Sentry to a Nuxt project in ESM syntax:

1. The possibility to add the node `--import` CLI flag.
2. Knowing the correct path to your Sentry server config file within your deployment environment (to add the path to the `--import` CLI flag).
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
2. Knowing the correct path to your Sentry server config file within your deployment environment (to add the path to the `--import` CLI flag).
2. Knowing the correct path to your Sentry server config file within your deployment environment (as you need to pass it to the `--import` CLI flag).

Comment on lines +20 to +25
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
## Setup Sentry Server Config
As described above, there are some prerequisites for adding Sentry to a Nuxt project in ESM syntax:
1. The possibility to add the node `--import` CLI flag.
2. Knowing the correct path to your Sentry server config file within your deployment environment (to add the path to the `--import` CLI flag).
## Setup Sentry Server Config
### Prerequisites
There are a few prerequisites for adding Sentry to a Nuxt project in ESM syntax:
1. You should be able to add the node `--import` CLI flag.
2. You should know the correct path to your Sentry server config file within your deployment environment (you'll need to pass it to the `--import` CLI flag).

3. The `hook.mjs` file is available under `node_modules/import-in-the-middle/hook.mjs` wherever your server-side code is executed.
4. Running Node.js version 18.19.0 or higher (support for `--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
4. Running Node.js version 18.19.0 or higher (support for `--import`).
4. Running Node.js version 18.19.0 or higher

Comment on lines +26 to +27
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
3. The `hook.mjs` file is available under `node_modules/import-in-the-middle/hook.mjs` wherever your server-side code is executed.
4. Running Node.js version 18.19.0 or higher (support for `--import`).
3. The `hook.mjs` file should be available under `node_modules/import-in-the-middle/hook.mjs`, wherever your server-side code is executed.
4. Node.js version 18.19.0 or higher.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd make the version requirement (#4) the first requirement.


### Adding the `--import` CLI flag
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
### Adding the `--import` CLI flag
### Adding the `--import` CLI Flag


You can either add the flag directly to the `node` command when starting the application:

```bash
node --import ./path/to/sentry-server-config.mjs ./path/to/index.mjs
```

or use the `NODE_OPTIONS` environment variable:

```bash
NODE_OPTIONS="--import ./path/to/sentry-server-config.mjs" node ./path/to/index.mjs
```

If modifying the `node` command is not possible, you can also add the `NODE_OPTIONS` environment variable wherever you can set environment variables within your deployment environment.
Make sure that this variable is only available during server runtime (not during build time).
Comment on lines +43 to +44
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
If modifying the `node` command is not possible, you can also add the `NODE_OPTIONS` environment variable wherever you can set environment variables within your deployment environment.
Make sure that this variable is only available during server runtime (not during build time).
If you can't modify the `node` command, you can add the `NODE_OPTIONS` environment variable wherever you can set environment variables within your deployment environment instead.
Make sure that this variable is only available during server runtime (not during build time).


### `import-in-the-middle/hook.mjs` is available
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
### `import-in-the-middle/hook.mjs` is available
### `import-in-the-middle/hook.mjs` Is Available


Usually, the file `node_modules/import-in-the-middle/hook.mjs` is automatically available when installing dependencies.
However, some deployment providers use custom node bundlers that might not include all `node_modules` in order to save storage.
This is often done by tracing the node files and only including the necessary dependencies. Since Sentry has to include the `hook.mjs` file internally with `module.register()` it might not be discovered by some bundlers and therefore not included.
If you get a warning that the `hook.mjs` file is not found, please report this in [the Sentry JS GitHub repo](https://github.com/getsentry/sentry-javascript/issues) or file an issue at your deployment provider.

Nitro (which is used by Nuxt and SolidStart on the server side) uses [`@vercel/nft`](https://github.com/vercel/nft) during the build. `@vercel/nft` includes files that are added with `module.register()` from version 0.27.4 onwards.
Comment on lines +48 to +53
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
Usually, the file `node_modules/import-in-the-middle/hook.mjs` is automatically available when installing dependencies.
However, some deployment providers use custom node bundlers that might not include all `node_modules` in order to save storage.
This is often done by tracing the node files and only including the necessary dependencies. Since Sentry has to include the `hook.mjs` file internally with `module.register()` it might not be discovered by some bundlers and therefore not included.
If you get a warning that the `hook.mjs` file is not found, please report this in [the Sentry JS GitHub repo](https://github.com/getsentry/sentry-javascript/issues) or file an issue at your deployment provider.
Nitro (which is used by Nuxt and SolidStart on the server side) uses [`@vercel/nft`](https://github.com/vercel/nft) during the build. `@vercel/nft` includes files that are added with `module.register()` from version 0.27.4 onwards.
In most cases the file `node_modules/import-in-the-middle/hook.mjs` is automatically available when installing dependencies.
However, some deployment providers use custom node bundlers that may not include all `node_modules` in order to save storage.
This is often done by tracing the node files and only including the necessary dependencies. Since Sentry has to include the `hook.mjs` file internally with `module.register()` it may not be discovered by some bundlers and won't be included.
If you get a warning that the `hook.mjs` file isn't found, please report this in [the Sentry JS GitHub repo](https://github.com/getsentry/sentry-javascript/issues) or file an issue with your deployment provider.
Nitro (which is used by Nuxt and SolidStart on the server side) uses [`@vercel/nft`](https://github.com/vercel/nft) during the build. `@vercel/nft` includes files that are added with `module.register()` from version 0.27.4 onwards.

In case you get a runtime error along the lines `Cannot find module '/node_modules/import-in-the-middle/hook.mjs'`, make sure to add a resolution (yarn) or an override (npm/pnpm) for `@vercel/nft`:
Copy link
Member

@mydea mydea Oct 7, 2024

Choose a reason for hiding this comment

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

Suggested change
In case you get a runtime error along the lines `Cannot find module '/node_modules/import-in-the-middle/hook.mjs'`, make sure to add a resolution (yarn) or an override (npm/pnpm) for `@vercel/nft`:
If you get a runtime error along the lines of `Cannot find module '/node_modules/import-in-the-middle/hook.mjs'`, be sure to add an override (npm/pnpm) or a resolution (yarn) for `@vercel/nft`:

we should probably mention npm first (generally)


```json {tabTitle:yarn} {filename: package.json}
Copy link
Member

Choose a reason for hiding this comment

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

should we flip these around, npm first, then yarn?

{
"resolutions": {
"@vercel/nft": "^0.27.4"
}
}
```

```json {tabTitle:npm/pnpm} {filename: package.json}
{
"overrides": {
"@vercel/nft": "^0.27.4"
}
}
```

## Setup other environment variables
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
## Setup other environment variables
## Set Up Other Environment Variables


In case you are using environment variables in your project to set up Sentry don't forget to also add them inside your deployment environment:

```bash
SENTRY_DSN="___PUBLIC_DSN___"
SENTRY_AUTH_TOKEN="___ORG_AUTH_TOKEN___"
```


Comment on lines +80 to +81
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

extra new lines here


## Exclude modules from import-in-the-middle
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
## Exclude modules from import-in-the-middle
## Exclude Modules From Import-in-the-middle


As all packages are wrapped under the hood by [import-in-the-middle](https://www.npmjs.com/package/import-in-the-middle), you might run into issues with certain packages. If you run into a problem with a package, you can skip instrumentation for it by configuring `registerEsmLoaderHooks` in your `Sentry.init()` config.

Comment on lines +85 to +86
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
As all packages are wrapped under the hood by [import-in-the-middle](https://www.npmjs.com/package/import-in-the-middle), you might run into issues with certain packages. If you run into a problem with a package, you can skip instrumentation for it by configuring `registerEsmLoaderHooks` in your `Sentry.init()` config.
All packages are wrapped under the hood by [import-in-the-middle](https://www.npmjs.com/package/import-in-the-middle) and you may run into issues with certain packages. If this happens, skip the package instrumentation by configuring `registerEsmLoaderHooks` in your `Sentry.init()` config.

```javascript {tabTitle:ESM} {filename: instrument.mjs}
import * as Sentry from "@sentry/node";

Sentry.init({
dsn: "___PUBLIC_DSN___",
registerEsmLoaderHooks: {
// Provide a list of package names to exclude from instrumentation
exclude: ["package-name"],
},
});
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: Deployment Provider Setup
Copy link
Member

Choose a reason for hiding this comment

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

L: This is very much bike shedding, but what about just calling this Deploying Nuxt with Sentry or something like this?

Copy link
Member

Choose a reason for hiding this comment

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

Or, if we want to keep it generic, e.g. "Deploying your application" or something like this?

Copy link
Contributor

Choose a reason for hiding this comment

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

@s1gr1d @mydea could we just call this "Alternate Installation Methods"? or "Alternate Ways to Set Up"?

sidebar_order: 4
description: "Review our alternate installation methods."
Copy link
Member

Choose a reason for hiding this comment

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

this is probably left over from copying this 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
description: "Review our alternate installation methods."
description: "Here are a few other ways to set up Sentry in your application."

supported:
- javascript.nuxt
---

<PageGrid />
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
title: Netlify
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
title: Netlify
title: Netlify Deployment Setup

sidebar_order: 10
description: "Learn about running Sentry when deploying to Netlify."
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
description: "Learn about running Sentry when deploying to Netlify."
description: "Learn how to deploy to Netlify when adding Sentry to a Nuxt project."

supported:
- javascript.nuxt
---

<Alert level="warning">
Deploying on Netlify is still experimental. Currently, not all Sentry features are supported on the server-side. Only your frontend will be monitored.
</Alert>
Comment on lines +9 to +11
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
<Alert level="warning">
Deploying on Netlify is still experimental. Currently, not all Sentry features are supported on the server-side. Only your frontend will be monitored.
</Alert>
<Alert level="warning">
Deploying on Netlify is currently experimental and not all Sentry features are supported on the server-side. Only your frontend will be monitored.
</Alert>


<Alert level="info">
Before approaching the steps below, read the general documentation around <PlatformLink to="/deployment-provider-setup/general/">setting up Sentry on a deployment provider</PlatformLink> to get quick general overview of the process.
This page only shows Netlify-specific steps.
</Alert>
Comment on lines +12 to +16
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
<Alert level="info">
Before approaching the steps below, read the general documentation around <PlatformLink to="/deployment-provider-setup/general/">setting up Sentry on a deployment provider</PlatformLink> to get quick general overview of the process.
This page only shows Netlify-specific steps.
</Alert>
This page only shows Netlify-specific steps. We recommend that you read the general documentation for <PlatformLink to="/deployment-provider-setup/general/">setting up Sentry on a deployment provider</PlatformLink> to get quick general overview of the process before getting started with the steps below.

It's a bit jarring to have 2 different-colored alerts at the very beginning of the page. I think this sentence works better as a regular sentence rather than as an alert.


## Approach 1: Adding the `--import` flag
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
## Approach 1: Adding the `--import` flag
## Approach 1: Adding the `--import` Flag


<PlatformSection supported={['javascript.nuxt']}>
The server-side of Nuxt is deployed as a Netlify Function. So make sure to scope the environment variable `NODE_OPTIONS` to "Functions".
The path to the function is depending on your setup. When building the preset locally, the file is available at: `.netlify/functions-internal/server/sentry.server.config.mjs`.

Comment on lines +19 to +23
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
<PlatformSection supported={['javascript.nuxt']}>
The server-side of Nuxt is deployed as a Netlify Function. So make sure to scope the environment variable `NODE_OPTIONS` to "Functions".
The path to the function is depending on your setup. When building the preset locally, the file is available at: `.netlify/functions-internal/server/sentry.server.config.mjs`.
<PlatformSection supported={['javascript.nuxt']}>
The server-side of Nuxt is deployed as a Netlify Function, so make sure to scope the environment variable `NODE_OPTIONS` to "Functions".
The path to the function depends on your setup. If you're building the preset locally, you'll find the file at: `.netlify/functions-internal/server/sentry.server.config.mjs`.

<Alert level="warning">
The docs for this are still vague and we will update them as soon as we know more about which exact path to use for the `--import` flag.
Copy link
Member

@mydea mydea Oct 7, 2024

Choose a reason for hiding this comment

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

I guess what you want to say here is that the docs are not really ready/done here yet? "vague" implies for me that everything works but is not documented well 🤔 Maybe rather:

Suggested change
The docs for this are still vague and we will update them as soon as we know more about which exact path to use for the `--import` flag.
The docs for this are still a work in progress. We'll update them as soon as we know more about which exact path to use for the `--import` flag.

Copy link
Member

Choose a reason for hiding this comment

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

Also, does this work as of today? If it does not actually work we should not document it, and/or call out very specifically that it does not work!

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to @mydea. I think it's best not to document it if we know it doesn't work.

</Alert>

<Include name="common-imgs/netlify-env-variable" />
</PlatformSection>


## Approach 2: Enable `experimental_basicServerTracing`


Enabling `experimental_basicServerTracing` can be used when adding the node option `--import` does not work. This however only comes with limited tracing functionality because Sentry server config is not **pre**loaded with `--import`.

<PlatformSection supported={['javascript.nuxt']}>
Enabling this option will automatically import the Sentry server config at the top of the server entry file (server entry: `.netlify/functions-internal/server/server.mjs`).

Comment on lines +34 to +39
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
Enabling `experimental_basicServerTracing` can be used when adding the node option `--import` does not work. This however only comes with limited tracing functionality because Sentry server config is not **pre**loaded with `--import`.
<PlatformSection supported={['javascript.nuxt']}>
Enabling this option will automatically import the Sentry server config at the top of the server entry file (server entry: `.netlify/functions-internal/server/server.mjs`).
If adding the node option `--import` doesn't work, you can enable `experimental_basicServerTracing` instead. Note, that `experimental_basicServerTracing` only comes with limited tracing functionality because Sentry server config is not **pre**loaded with `--import`.
<PlatformSection supported={['javascript.nuxt']}>
Enabling this option will automatically import the Sentry server config at the top of the server entry file (server entry: `.netlify/functions-internal/server/server.mjs`).

```javascript {tabTitle: Nuxt Config} {filename: nuxt.config.ts}
export default defineNuxtConfig({
sentry: {
// ... other options
experimental_basicServerTracing: true
},
})
```
</PlatformSection>


Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Enriching Events
description: Add additional context to your events to make them easier to debug.
sidebar_order: 5
sidebar_order: 6
---

<PageGrid />
2 changes: 1 addition & 1 deletion docs/platforms/javascript/common/usage/index.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Capturing Errors and Events
description: "Learn how to use the SDK to manually capture errors and other events."
sidebar_order: 4
sidebar_order: 5
---

Sentry's SDK hooks into your runtime environment and automatically reports errors, uncaught exceptions, and unhandled rejections as well as other types of errors depending on the platform.
Expand Down
2 changes: 1 addition & 1 deletion docs/platforms/javascript/guides/nuxt/features/index.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Vue Features
description: "Learn how to exposes features for first class integration with Vue with Sentry's Nuxt SDK."
sidebar_order: 4
sidebar_order: 5
---

The Sentry Nuxt SDK offers Vue-specific features for first class integration with the framework.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions includes/common-imgs/netlify-env-variable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
![Setting up scoped environment variables in Netlify](./img/netlify-env-variable.png)
Loading