-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(nuxt): Add Nuxt wizard instructions
- Loading branch information
Showing
6 changed files
with
107 additions
and
168 deletions.
There are no files selected for viewing
120 changes: 2 additions & 118 deletions
120
platform-includes/getting-started-config/javascript.nuxt.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,118 +1,2 @@ | ||
To set up the Sentry SDK, register the Sentry Nuxt module and initialize the SDK for client and server. At build time, the Sentry Nuxt Module looks for the following two files: | ||
|
||
- Client-Side: `sentry.client.config.ts` in the root containing `Sentry.init` | ||
- Server-Side: `sentry.server.config.ts` in the root containing `Sentry.init` | ||
|
||
In these files, you can specify the full range of <PlatformLink to="/configuration/options">Sentry SDK options</PlatformLink>. | ||
|
||
|
||
### Nuxt Module Setup | ||
|
||
Add the Sentry Nuxt Module to your `nuxt.config.ts` file: | ||
|
||
```javascript {filename:nuxt.config.ts} | ||
export default defineNuxtConfig({ | ||
modules: ["@sentry/nuxt/module"] | ||
}); | ||
``` | ||
|
||
Adding this module enables the Sentry SDK in your Nuxt application. The Sentry Nuxt Module will then automatically look for the Sentry configuration files and initialize the SDK accordingly. | ||
|
||
### Client-side Setup | ||
|
||
Add a `sentry.client.config.ts` file to the root of your project (this is probably the same level as the `package.json`). In this file, import and initialize Sentry, specifying any SDK options for the client: | ||
|
||
```javascript {filename:sentry.client.config.ts} | ||
import * as Sentry from '@sentry/nuxt'; | ||
|
||
Sentry.init({ | ||
// If set up, you can use your runtime config here | ||
// dsn: useRuntimeConfig().public.sentry.dsn, | ||
dsn: "___PUBLIC_DSN___", | ||
|
||
// We recommend adjusting this value in production, or using tracesSampler | ||
// for finer control | ||
tracesSampleRate: 1.0 | ||
}); | ||
``` | ||
|
||
### Server-side Setup | ||
|
||
1. Add a `sentry.server.config.ts` file to the root of your project: | ||
|
||
```javascript {filename:sentry.server.config.ts} | ||
import * as Sentry from '@sentry/nuxt'; | ||
|
||
Sentry.init({ | ||
dsn: "___PUBLIC_DSN___", | ||
|
||
// We recommend adjusting this value in production, or using tracesSampler | ||
// for finer control | ||
tracesSampleRate: 1.0 | ||
}); | ||
``` | ||
|
||
The Nuxt `useRuntimeConfig()` does not work in the Sentry server config due to technical reasons (the config file has to | ||
be loaded before Nuxt is loaded). To be able to use `process.env` you either have to add `--env-file=.env` to your node command | ||
|
||
```bash {tabTitle: node} | ||
node --env-file=.env .output/server/index.mjs | ||
``` | ||
|
||
or use the `dotenv` package: | ||
|
||
```javascript {tabTitle: Server Config} {filename:sentry.server.config.ts} {1,3} | ||
import dotenv from 'dotenv'; | ||
|
||
dotenv.config(); | ||
|
||
// ... rest of the file | ||
``` | ||
|
||
<Alert level="warning"> | ||
In the beta state of the Nuxt SDK, some features may not work with certain deployment providers. Check the progress on GitHub: [Compatibility with different Deployment Platforms](https://github.com/getsentry/sentry-javascript/issues/14029) | ||
</Alert> | ||
|
||
#### Troubleshoot Errors during Server Startup | ||
|
||
After adding `sentry.server.config.ts` and building the project, you might get an error like this: | ||
`Failed to register ESM hook import-in-the-middle/hook.mjs`. You can add an override (npm/pnpm) or a resolution (yarn) | ||
for `@vercel/nft` to fix this. This will add the `hook.mjs` file to your build output. See the [underlying issue in the UnJS Nitro project](https://github.com/unjs/nitro/issues/2703). | ||
|
||
|
||
Nitro updated `@vercel/nft` in Nitro version `2.10.0`, so you might not get this error anymore, and you don't need to | ||
add this override/resolution. | ||
|
||
```json {tabTitle:npm} {filename:package.json} | ||
"overrides": { | ||
"@vercel/nft": "^0.27.4" | ||
} | ||
``` | ||
|
||
```json {tabTitle:yarn} {filename:package.json} | ||
"resolutions": { | ||
"@vercel/nft": "^0.27.4" | ||
} | ||
``` | ||
|
||
```json {tabTitle:pnpm} {filename:package.json} | ||
"pnpm": { | ||
"overrides": { | ||
"@vercel/nft": "^0.27.4" | ||
} | ||
} | ||
``` | ||
|
||
**Pnpm and Import-In-The-Middle** | ||
|
||
Sentry injects `import "import-in-the-middle/hook.mjs"` in your server entry. This import acts as a hint for node bundlers to really include this file. | ||
As pnpm implements a strict dependency isolation, this import might cause problems. | ||
Per default, `shamefully-hoist` is `false` ([pnpm docs here](https://pnpm.io/next/npmrc#shamefully-hoist)) and this prevents accessing non-declared dependencies. | ||
You probably don't want to change this setting, so you have to explicitly add the dependency `import-in-the-middle`: | ||
|
||
```json {tabTitle:pnpm} {filename:package.json} | ||
// only when using pnpm | ||
"dependencies": { | ||
"import-in-the-middle": "^1.11.2" | ||
} | ||
``` | ||
To complete your configuration, add <PlatformLink to="/configuration/options/">options</PlatformLink> to your `Sentry.init()` calls. | ||
Here, you'll also be able to set context data, which includes data about the <PlatformLink to="/enriching-events/identify-user/">user</PlatformLink>, <PlatformLink to="/enriching-events/tags/">tags</PlatformLink>, or even <PlatformLink to="/enriching-events/context/">arbitrary data</PlatformLink>, all of which will be added to every event sent to Sentry. |
26 changes: 18 additions & 8 deletions
26
platform-includes/getting-started-install/javascript.nuxt.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
```bash {tabTitle:npm} | ||
npm install @sentry/nuxt --save | ||
``` | ||
We recommend installing the SDK by running our installation wizard in the root directory of your project: | ||
|
||
```bash {tabTitle:yarn} | ||
yarn add @sentry/nuxt | ||
```bash | ||
npx @sentry/wizard@latest -i nuxt | ||
``` | ||
|
||
```bash {tabTitle:pnpm} | ||
pnpm add @sentry/nuxt | ||
``` | ||
The wizard will prompt you to log in to Sentry. It will then automatically do the following steps for you: | ||
|
||
- create or update Nuxt files with the default Sentry configuration: | ||
- `sentry.(client|server).config.ts` to initialize the SDK | ||
- `nuxt.config.ts` to add build options to add source maps upload and auto-instrumentation via Vite plugins. | ||
- create a `.env.sentry-build-plugin` file with an auth token to upload source maps (this file is automatically added to `.gitignore`) | ||
- add an example page to your frontend app and your server to verify your Sentry setup | ||
|
||
After the wizard setup is completed, the SDK will automatically capture unhandled errors, and monitor performance. | ||
|
||
You can also <PlatformLink to="/usage/">manually capture errors</PlatformLink>. | ||
|
||
<Note> | ||
If the setup through the wizard doesn't work for you, you can also <PlatformLink to="/manual-setup/">set up the SDK manually</PlatformLink>. | ||
</Note> |
4 changes: 4 additions & 0 deletions
4
platform-includes/getting-started-next-steps/javascript.nuxt.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## Next Steps | ||
|
||
- Track your Vue Components or your Pinia store by [adding support for client features](/platforms/javascript/guides/nuxt/features/) | ||
- In case you experience any issues during setup or startup, check out <PlatformLink to="/troubleshooting">Troubleshooting</PlatformLink> | ||
|
||
|
||
or read through the different <PlatformLink to="/install">installation methods</PlatformLink>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 0 additions & 37 deletions
37
platform-includes/getting-started-sourcemaps/javascript.nuxt.mdx
This file was deleted.
Oops, something went wrong.
50 changes: 45 additions & 5 deletions
50
platform-includes/getting-started-verify/javascript.nuxt.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,54 @@ | ||
```html {tabTitle:Vue} {filename:ErrorButton.vue} | ||
On the client-side: | ||
|
||
```html {tabTitle:Vue} {filename:pages/example-error.vue} | ||
<script setup> | ||
const triggerError = () => { | ||
throw new Error("Nuxt Button Error"); | ||
}; | ||
import * as Sentry from '@sentry/nuxt'; | ||
import { useFetch} from '#imports' | ||
function triggerClientError() { | ||
throw new Error("Nuxt Button Error"); | ||
}; | ||
function getSentryData() { | ||
Sentry.startSpan( | ||
{ | ||
name: 'Example Frontend Span', | ||
op: 'test' | ||
}, | ||
async () => { | ||
await useFetch('/sentry-example-api'); | ||
} | ||
) | ||
} | ||
</script> | ||
|
||
<template> | ||
<button id="errorBtn" @click="triggerError">Trigger Error</button> | ||
<button id="errorBtn" @click="triggerClientError"> | ||
Throw Client Error | ||
</button> | ||
<button type="button" @click="getSentryData"> | ||
Throw Server Error | ||
</button> | ||
</template> | ||
``` | ||
|
||
On the server-side: | ||
|
||
```js {tabTitle:Nitro} {filename:server/sentry-example-api.ts} | ||
import { defineEventHandler } from '#imports'; | ||
|
||
export default defineEventHandler(event => { | ||
throw new Error("Sentry Example API Route Error"); | ||
}); | ||
|
||
``` | ||
|
||
<Alert level="warning"> | ||
Keep in mind, that the server-side monitoring **does not work in development mode!** | ||
|
||
If you want to test server-side monitoring locally, build your project and run: | ||
``` | ||
# Start your app after building your project with `nuxi build` | ||
node .output/server/index.mjs | ||
``` | ||
</Alert> |