Skip to content

Commit f4e13d6

Browse files
committed
create quick start guide for Nuxt manual setup
1 parent cd10012 commit f4e13d6

File tree

1 file changed

+169
-93
lines changed

1 file changed

+169
-93
lines changed
Lines changed: 169 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
---
22
title: Manual Setup
33
sidebar_order: 1
4-
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."
55
---
66

7-
If you can't (or prefer not to) run the <PlatformLink to="/#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+
<Alert type="info">
8+
For the fastest setup, we recommend using the [wizard
9+
installer](/platforms/javascript/guides/nuxt).
10+
</Alert>
811

9-
## Compatibility
12+
<Alert level="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>
1018

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.
19+
<PlatformContent includePath="getting-started-prerequisites" />
1320

14-
In case you are using Nuxt before version `3.14.0`, add the following overrides:
21+
<Expandable title="Are you using Nuxt version < 3.14.0?">
22+
Add the following overrides:
1523

1624
```json {tabTitle:npm} {filename:package.json}
1725
"overrides": {
@@ -36,7 +44,21 @@ In case you are using Nuxt before version `3.14.0`, add the following overrides:
3644
}
3745
```
3846

39-
## Install
47+
</Expandable>
48+
49+
## Step 1: Install
50+
51+
Choose the features you want to configure, and this guide will show you how:
52+
53+
<OnboardingOptionButtons
54+
options={["error-monitoring", "performance", "session-replay"]}
55+
/>
56+
57+
<PlatformContent includePath="getting-started-features-expandable" />
58+
59+
### Install the Sentry SDK
60+
61+
Run the command for your preferred package manager to add the Sentry SDK to your application:
4062

4163
```bash {tabTitle:npm}
4264
npm install @sentry/nuxt --save
@@ -50,66 +72,90 @@ yarn add @sentry/nuxt
5072
pnpm add @sentry/nuxt
5173
```
5274

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
6176

62-
In these files, you can specify the full range of <PlatformLink to="/configuration/options">Sentry SDK options</PlatformLink>.
77+
### Apply Instrumentation to Your App
6378

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:
6880

6981
```javascript {filename:nuxt.config.ts}
7082
export default defineNuxtConfig({
71-
modules: ["@sentry/nuxt/module"]
83+
modules: ["@sentry/nuxt/module"],
7284
});
7385
```
7486

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
7888

7989
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:
8090

81-
```javascript {filename:sentry.client.config.ts}
82-
import * as Sentry from '@sentry/nuxt';
91+
```javascript {filename:sentry.client.config.ts} {"onboardingOptions": {"performance": "9-15", "session-replay": "7-8, 16-22"}}
92+
import * as Sentry from "@sentry/nuxt";
8393

8494
Sentry.init({
8595
// If set up, you can use the Nuxt runtime config here
8696
// dsn: useRuntimeConfig().public.sentry.dsn, // modify, depending on your custom runtime config
8797
dsn: "___PUBLIC_DSN___",
98+
// Replay may only be enabled for the client-side
99+
integrations: [Sentry.replayIntegration()],
100+
101+
// Set tracesSampleRate to 1.0 to capture 100%
102+
// of transactions for tracing.
103+
// We recommend adjusting this value in production
104+
// Learn more at
105+
// https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
106+
tracesSampleRate: 1.0,
107+
108+
// Capture Replay for 10% of all sessions,
109+
// plus for 100% of sessions with an error
110+
// Learn more at
111+
// https://docs.sentry.io/platforms/javascript/session-replay/configuration/#general-integration-configuration
112+
replaysSessionSampleRate: 0.1,
113+
replaysOnErrorSampleRate: 1.0,
114+
});
115+
```
88116

89-
// 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+
export default defineNuxtConfig({
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+
},
92129
});
93130
```
94131

95-
### Server-side Setup
132+
This allows you to access the DSN using `useRuntimeConfig().public.sentry.dsn`.
96133

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:
98137

99138
```javascript {filename:sentry.server.config.ts}
100-
import * as Sentry from '@sentry/nuxt';
139+
import * as Sentry from "@sentry/nuxt";
101140

102141
Sentry.init({
103142
dsn: "___PUBLIC_DSN___",
104143

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
147+
// Learn more at
148+
// https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
149+
tracesSampleRate: 1.0,
108150
});
109151
```
110152

111-
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+
<Expandable title="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:
113159

114160
```bash {tabTitle: node}
115161
node --env-file=.env .output/server/index.mjs
@@ -118,29 +164,32 @@ node --env-file=.env .output/server/index.mjs
118164
or use the `dotenv` package:
119165

120166
```javascript {tabTitle: Server Config} {filename:sentry.server.config.ts} {1,3}
121-
import dotenv from 'dotenv';
167+
import dotenv from "dotenv";
122168

123169
dotenv.config();
124170

125171
// ... rest of the file
126172
```
127173

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:
129177

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`
180+
node --import ./.output/server/sentry.server.config.mjs .output/server/index.mjs
181+
```
131182

132183
Check out the <PlatformLink to="/install/cli-import">`--import` CLI flag</PlatformLink> docs for setup instructions.
133184

134185
<Alert level="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
188+
different Deployment
189+
Platforms](https://github.com/getsentry/sentry-javascript/issues/14029)
136190
</Alert>
137191

138-
#### Troubleshoot Errors during Server Startup
139-
140-
In case you are experiencing problems after adding `sentry.server.config.ts` and building the project, you can check out <PlatformLink to="/troubleshooting">Troubleshooting</PlatformLink>
141-
or read through the different <PlatformLink to="/install">installation methods</PlatformLink>.
142-
143-
## Source Maps Upload
192+
## Step 3: Add Readable Stack Traces With Source Maps (Optional)
144193

145194
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.
146195
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
149198
inside the `sentry` options of your `nuxt.config.ts`.
150199

151200
<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
202+
the SDK.
153203
</Alert>
154204

155205
<OrgAuthTokenNote />
@@ -161,9 +211,9 @@ export default defineNuxtConfig({
161211
sourceMapsUploadOptions: {
162212
org: "___ORG_SLUG___",
163213
project: "___PROJECT_SLUG___",
164-
authToken: "___ORG_AUTH_TOKEN___"
165-
}
166-
}
214+
authToken: "___ORG_AUTH_TOKEN___",
215+
},
216+
},
167217
});
168218
```
169219

@@ -172,7 +222,7 @@ but you'll need to enable it explicitly for the client-side. Add this code to yo
172222

173223
```javascript {filename:nuxt.config.ts} {2}
174224
export default defineNuxtConfig({
175-
sourcemap: { client: 'hidden' }
225+
sourcemap: { client: "hidden" },
176226
});
177227
```
178228

@@ -186,81 +236,107 @@ from trying to fetch missing files and avoiding unnecessary errors.
186236
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
187237
the Sentry Nuxt Module respects these when they are explicitly defined.
188238

189-
## Verify
239+
## Step 4: Verify Your Setup
190240

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.
192242

193-
### Server-side
243+
### Issues
194244

195-
Sentry can only be loaded on the server-side by being explicitly added via `--import`.
196-
Check out the <PlatformLink to="/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:
197246

198-
To verify that Sentry works on the server-side, add the following snippet on the server-side:
247+
```html {tabTitle:Vue} {filename:pages/example-error.vue}
248+
<script setup>
249+
import * as Sentry from "@sentry/nuxt";
199250
200-
```js {tabTitle:Nitro} {filename:server/api/sentry-example.get.ts}
201-
export default defineEventHandler(event => {
202-
throw new Error("Sentry Example API Route Error");
203-
});
251+
function triggerClientError() {
252+
throw new Error("Nuxt Button Error");
253+
}
254+
</script>
255+
256+
<template>
257+
<button id="errorBtn" @click="triggerClientError">Throw Client Error</button>
258+
</template>
204259
```
205260

206-
If you want to test server-side monitoring locally, build your project and run:
207-
```
208-
# Start your app after building your project with `nuxi build`
209-
node --import ./.output/server/sentry.server.config.mjs .output/server/index.mjs
210-
```
261+
<OnboardingOption optionId="performance" hideForThisOption>
262+
Open the page in a browser (for most Nuxt applications, this will be at
263+
localhost) and click the button to trigger a frontend error.
264+
</OnboardingOption>
211265

212-
<Alert level="warning">
213-
Sentry server-side monitoring **doesn't work in development mode!**
266+
<PlatformContent includePath="getting-started-browser-sandbox-warning" />
214267

215-
If you experience any issues with the server-side setup, check out <PlatformLink to="/troubleshooting">Troubleshooting</PlatformLink>
216-
or read through the different <PlatformLink to="/install">installation methods</PlatformLink>.
217-
</Alert>
268+
<OnboardingOption optionId="performance">
269+
### Tracing
218270

219-
### Client-side
271+
To test tracing, create a test API route `server/api/sentry-example.get.ts`:
220272

221-
Add the following snippet on the client-side:
273+
```js {tabTitle:Nitro} {filename:server/api/sentry-example.get.ts}
274+
export default defineEventHandler((event) => {
275+
throw new Error("Sentry Example API Route Error");
276+
});
277+
```
278+
279+
Then update the test page by including a new button that executes a function to fetch your API route:
222280

223281
```html {tabTitle:Vue} {filename:pages/example-error.vue}
224282
<script setup>
225-
import * as Sentry from '@sentry/nuxt';
283+
import * as Sentry from "@sentry/nuxt";
226284
227285
function triggerClientError() {
228286
throw new Error("Nuxt Button Error");
229-
};
287+
}
230288
231289
function getSentryData() {
232290
Sentry.startSpan(
233291
{
234-
name: 'Example Frontend Span',
235-
op: 'test'
292+
name: "Example Frontend Span",
293+
op: "test",
236294
},
237295
async () => {
238-
await $fetch('/api/sentry-example');
296+
await $fetch("/api/sentry-example");
239297
}
240-
)
298+
);
241299
}
242300
</script>
243301

244302
<template>
245-
<button id="errorBtn" @click="triggerClientError">
246-
Throw Client Error
247-
</button>
248-
<button type="button" @click="getSentryData">
249-
Throw Server Error
250-
</button>
303+
<button id="errorBtn" @click="triggerClientError">Throw Client Error</button>
304+
<button type="button" @click="getSentryData">Throw Server Error</button>
251305
</template>
252306
```
253307

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`.
255310

256-
Learn more about manually capturing an error or message in our <PlatformLink to="/usage/">Usage documentation</PlatformLink>.
311+
After running your project:
257312

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>
259318

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).
322+
323+
<PlatformContent includePath="getting-started-verify-locate-data" />
261324

262325
## Next Steps
263326

264-
- Track your Vue Components or your Pinia store by [adding support for client features](/platforms/javascript/guides/nuxt/features/)
265-
- In case you experience any issues during setup or startup, check out <PlatformLink to="/troubleshooting">Troubleshooting</PlatformLink>
266-
or read through the different <PlatformLink to="/install">installation methods</PlatformLink>.
327+
At this point, you should have integrated Sentry into your Next.js application and should already be sending data to your Sentry project.
328+
329+
Now's a good time to customize your setup and look into more advanced topics. Our next recommended steps for you are:
330+
331+
- Learn how to [manually capture errors](/platforms/javascript/guides/nuxt/usage/)
332+
- Continue to [customize your configuration](/platforms/javascript/guides/nuxt/configuration/)
333+
- Get familiar with [Sentry's product features](/product) like tracing, insights, and alerts
334+
- Learn how to [track your Vue components or your Pinia store](/platforms/javascript/guides/nuxt/features/)
335+
336+
<Expandable permalink={false} title="Are you having problems setting up the SDK?">
337+
338+
- If you encountered issues with setting up Sentry manually, [try our installation wizard](/platforms/javascript/guides/nuxt/)
339+
- Find various support topics in <PlatformLink to="/troubleshooting">troubleshooting</PlatformLink>
340+
- [Get support](https://sentry.zendesk.com/hc/en-us/)
341+
342+
</Expandable>

0 commit comments

Comments
 (0)