You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: "Learn how to set up the SDK manually."
4
+
description: "Learn how to manually set up Sentry in your Nuxt app and capture your first errors."
5
5
---
6
6
7
-
If you can't (or prefer not to) run the <PlatformLinkto="/#install">automatic setup</PlatformLink>, you can follow the instructions below to configure the Sentry Nuxt SDK in your application. This guide is also useful to adjust the pre-set configuration if you used the installation wizard for automatic setup.
7
+
<Alerttype="info">
8
+
For the fastest setup, we recommend using the [wizard
9
+
installer](/platforms/javascript/guides/nuxt).
10
+
</Alert>
8
11
9
-
## Compatibility
12
+
<Alertlevel="warning">
13
+
This SDK is currently in **beta**. Beta features are still in progress and may
14
+
have bugs. Please reach out on
15
+
[GitHub](https://github.com/getsentry/sentry-javascript/issues/new/choose) if
16
+
you have any feedback or concerns.
17
+
</Alert>
10
18
11
-
The Sentry Nuxt SDK supports Nuxt version `3.7.0` and above. For best results, we recommend
12
-
using Nuxt `3.14.0` or later, which includes updated dependencies critical to the SDK's functionality.
Run the command for your preferred package manager to add the Sentry SDK to your application:
40
62
41
63
```bash {tabTitle:npm}
42
64
npm install @sentry/nuxt --save
@@ -50,66 +72,90 @@ yarn add @sentry/nuxt
50
72
pnpm add @sentry/nuxt
51
73
```
52
74
53
-
## Configure
54
-
55
-
Configuration should happen as early as possible in your application's lifecycle.
56
-
57
-
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:
58
-
59
-
- Client-Side: `sentry.client.config.ts` in the root containing `Sentry.init`
60
-
- Server-Side: `sentry.server.config.ts` in the root containing `Sentry.init`
75
+
## Step 2: Configure
61
76
62
-
In these files, you can specify the full range of <PlatformLinkto="/configuration/options">Sentry SDK options</PlatformLink>.
77
+
### Apply Instrumentation to Your App
63
78
64
-
65
-
### Nuxt Module Setup
66
-
67
-
Add the Sentry Nuxt Module to your `nuxt.config.ts` file:
79
+
Add the Sentry Nuxt module to your `nuxt.config.ts` file:
68
80
69
81
```javascript {filename:nuxt.config.ts}
70
82
exportdefaultdefineNuxtConfig({
71
-
modules: ["@sentry/nuxt/module"]
83
+
modules: ["@sentry/nuxt/module"],
72
84
});
73
85
```
74
86
75
-
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.
76
-
77
-
### Client-side Setup
87
+
### Configure Client-side Sentry
78
88
79
89
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:
// We recommend adjusting this value in production, or using tracesSampler
90
-
// for finer control
91
-
tracesSampleRate:1.0
117
+
We recommend you store your Sentry [Data Source Name](/concepts/key-terms/dsn-explainer/) (DSN) in an environment variable and configure it via the Nuxt runtime config like so:
118
+
119
+
```javascript {filename:nuxt.config.ts}
120
+
exportdefaultdefineNuxtConfig({
121
+
modules: ["@sentry/nuxt"],
122
+
runtimeConfig: {
123
+
public: {
124
+
sentry: {
125
+
dsn:process.env.SENTRY_DSN_PUBLIC, // Use a public environment variable for the DSN
126
+
},
127
+
},
128
+
},
92
129
});
93
130
```
94
131
95
-
### Server-side Setup
132
+
This allows you to access the DSN using `useRuntimeConfig().public.sentry.dsn`.
96
133
97
-
Add a `sentry.server.config.ts` file to the root of your project:
134
+
### Configure Server-side Sentry
135
+
136
+
Add a `sentry.server.config.ts` file to the root of your project and add the following initialization code to it:
98
137
99
138
```javascript {filename:sentry.server.config.ts}
100
-
import*asSentryfrom'@sentry/nuxt';
139
+
import*asSentryfrom"@sentry/nuxt";
101
140
102
141
Sentry.init({
103
142
dsn:"___PUBLIC_DSN___",
104
143
105
-
// We recommend adjusting this value in production, or using tracesSampler
106
-
// for finer control
107
-
tracesSampleRate:1.0
144
+
// Set tracesSampleRate to 1.0 to capture 100%
145
+
// of transactions for tracing.
146
+
// We recommend adjusting this value in production
The Nuxt `useRuntimeConfig()` does not work in the Sentry server config due to technical reasons (the config file has to
112
-
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
153
+
We recommend you store your Sentry [Data Source Name](/concepts/key-terms/dsn-explainer/) (DSN) in an environment variable.
154
+
155
+
<Expandabletitle="How to access environment variables in sentry.server.config.ts">
156
+
Since Sentry on the server side needs to be loaded before `useRuntimeConfig()` is fully available, environment variables are not directly accessible via `process.env`. To make sure your environment variables are available, use one of these methods:
157
+
158
+
Load environment variables from your `.env` file when starting the server:
```javascript {tabTitle: Server Config} {filename:sentry.server.config.ts} {1,3}
121
-
importdotenvfrom'dotenv';
167
+
importdotenvfrom"dotenv";
122
168
123
169
dotenv.config();
124
170
125
171
// ... rest of the file
126
172
```
127
173
128
-
#### Load Sentry config
174
+
</Expandable>
175
+
176
+
**Sentry's server-side monitoring doesn't work in development mode**. To enable it, you first need to build your application and then load the Sentry server-side config using the `--import` flag when running your application:
129
177
130
-
Sentry can only be loaded on the server-side by being explicitly added via `--import`.
178
+
```
179
+
# Start your app after building your project with `nuxi build`
Check out the <PlatformLinkto="/install/cli-import">`--import` CLI flag</PlatformLink> docs for setup instructions.
133
184
134
185
<Alertlevel="warning">
135
-
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)
186
+
In the beta state of the Nuxt SDK, some features may not work with certain
187
+
deployment providers. Check the progress on GitHub: [Compatibility with
In case you are experiencing problems after adding `sentry.server.config.ts` and building the project, you can check out <PlatformLinkto="/troubleshooting">Troubleshooting</PlatformLink>
141
-
or read through the different <PlatformLinkto="/install">installation methods</PlatformLink>.
The Sentry Nuxt Module uses the [Sentry Vite Plugin](https://www.npmjs.com/package/@sentry/vite-plugin) to upload source maps for both server and client builds.
146
195
This means that when you run a production build (`nuxt build`), source maps will be generated and uploaded to Sentry, so that you get readable stack traces in your Sentry issues.
@@ -149,7 +198,8 @@ To upload source maps, specify your Sentry auth token as well as your org and pr
149
198
inside the `sentry` options of your `nuxt.config.ts`.
150
199
151
200
<Alert>
152
-
The module options inside `sentry` are only affecting the **build-time** of the SDK.
201
+
The module options inside `sentry` are only affecting the **build-time** of
@@ -172,7 +222,7 @@ but you'll need to enable it explicitly for the client-side. Add this code to yo
172
222
173
223
```javascript {filename:nuxt.config.ts} {2}
174
224
exportdefaultdefineNuxtConfig({
175
-
sourcemap: { client:'hidden' }
225
+
sourcemap: { client:"hidden" },
176
226
});
177
227
```
178
228
@@ -186,81 +236,107 @@ from trying to fetch missing files and avoiding unnecessary errors.
186
236
You need to explicitly enable client-side source maps because Nuxt applies default [source map settings](https://nuxt.com/docs/api/nuxt-config#sourcemap), and
187
237
the Sentry Nuxt Module respects these when they are explicitly defined.
188
238
189
-
## Verify
239
+
## Step 4: Verify Your Setup
190
240
191
-
This snippet includes an intentional error, so you can test that everything is working as soon as you set it up.
241
+
Let's test your setup and confirm that Sentry is working correctly and sending data to your Sentry project.
192
242
193
-
### Server-side
243
+
### Issues
194
244
195
-
Sentry can only be loaded on the server-side by being explicitly added via `--import`.
196
-
Check out the <PlatformLinkto="/install/cli-import">`--import` CLI flag</PlatformLink> docs for setup instructions.
245
+
To verify that Sentry captures errors and creates issues in your Sentry project, create a test page with a button:
197
246
198
-
To verify that Sentry works on the server-side, add the following snippet on the server-side:
<buttontype="button"@click="getSentryData">Throw Server Error</button>
251
305
</template>
252
306
```
253
307
254
-
<Alert>
308
+
Once you have your test code in place, you need to build your project since Sentry's server-side monitoring doesn't work in development mode.
309
+
Then start your app and make sure to load Sentry on the server side by explicitly adding it via `--import`.
255
310
256
-
Learn more about manually capturing an error or message in our <PlatformLinkto="/usage/">Usage documentation</PlatformLink>.
311
+
After running your project:
257
312
258
-
</Alert>
313
+
1. Open your test page in a browser (for most Nuxt applications, this will be at localhost)
314
+
2. Click the "Throw Client Error" button to trigger an error in the frontend
315
+
3. Click the "Throw Server Error" button to trigger an error within the API route and start a performance trace to measure the time it takes for the API request to complete.
316
+
317
+
</OnboardingOption>
259
318
260
-
To view and resolve the recorded error, log into [sentry.io](https://sentry.io) and select your project. Clicking on the error's title will open a page where you can see detailed information and mark it as resolved.
319
+
### View Captured Data in Sentry
320
+
321
+
Now, head over to your project on [Sentry.io](https://sentry.io) to view the collected data (it takes a couple of moments for the data to appear).
0 commit comments