Skip to content

Commit deabca3

Browse files
andreiborzalforst
andauthored
ref(docs): Update migration guide to use --require/--import flag (#11970)
Co-authored-by: Luca Forstner <[email protected]>
1 parent 4cf9742 commit deabca3

File tree

3 files changed

+73
-21
lines changed

3 files changed

+73
-21
lines changed

MIGRATION.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ stable release of `8.x` comes out).
2020

2121
## 1. Version Support changes:
2222

23-
**Node.js**: We now official support Node 14.18+ for our CJS package, and Node 18.8+ for our ESM package. This applies
24-
to `@sentry/node` and all of our node-based server-side sdks (`@sentry/nextjs`, `@sentry/serverless`, etc.). We no
25-
longer test against Node 8, 10, or 12 and cannot guarantee that the SDK will work as expected on these versions.
23+
**Node.js**: We now officially support Node 14.18+ for our CJS package, and Node 18.19.1+ for our ESM package. This
24+
applies to `@sentry/node` and all of our node-based server-side sdks (`@sentry/nextjs`, `@sentry/serverless`, etc.). We
25+
no longer test against Node 8, 10, or 12 and cannot guarantee that the SDK will work as expected on these versions.
2626

2727
**Browser**: Our browser SDKs (`@sentry/browser`, `@sentry/react`, `@sentry/vue`, etc.) now require ES2018+ compatible
2828
browsers. This means that we no longer support IE11 (end of an era). This also means that the Browser SDK requires the

docs/v8-initializing.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ In an environment with multiple execution contexts (e.g. Node), you can setup mu
2121
different contexts, like this:
2222

2323
```js
24-
import * as Sentry from '@sentry/browser';
24+
import * as Sentry from '@sentry/node';
2525

2626
// Sets up the _default_ client
2727
Sentry.init({

docs/v8-node.md

+69-17
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ We support the following Node Frameworks out of the box:
1616

1717
- [Express](#express)
1818
- [Fastify](#fastify)
19-
- Koa
19+
- [Connect](#connect)
20+
- [Koa](#koa)
2021
- Nest.js
2122
- Hapi
2223

@@ -52,13 +53,36 @@ Sentry.init({
5253
const app = express();
5354
```
5455

56+
We recommend creating a file named `instrument.js` that imports and initializes Sentry.
57+
5558
```js
56-
// In v8, in order to ensure express is instrumented,
57-
// you have to initialize before you import:
59+
// In v8, create a separate file that initializes sentry.
60+
// Then pass the file to Node via --require or --import.
5861
const Sentry = require('@sentry/node');
5962
Sentry.init({
6063
// ...
6164
});
65+
```
66+
67+
Adjust the Node.js call for your application to use the [--require](https://nodejs.org/api/cli.html#-r---require-module)
68+
or [--import](https://nodejs.org/api/cli.html#--importmodule) parameter and point it at `instrument.js`. Using
69+
`--require` or `--import` is the easiest way to guarantee that Sentry is imported and initialized before any other
70+
modules in your application
71+
72+
```bash
73+
# If you are using CommonJS (CJS)
74+
node --require ./instrument.js app.js
75+
76+
# If you are using ECMAScript Modules (ESM)
77+
# Note: This is only available for Node v18.19.0 onwards.
78+
node --import ./instrument.mjs app.mjs
79+
```
80+
81+
**Alternatively**, if you cannot run node with `--require` or `--import`, add a top level import of `instrument.js` in
82+
your application.
83+
84+
```js
85+
require('./instrument.js');
6286

6387
const express = require('express');
6488
const app = express();
@@ -75,8 +99,11 @@ See [New Performance APIs](./v8-new-performance-apis.md) for details.
7599

76100
### ESM Support
77101

78-
For now, ESM support is only experimental. For the time being we only fully support CJS-based Node application - we are
79-
working on this during the v8 alpha/beta cycle.
102+
Instrumentation works out of the box for CommonJS (CJS) applications based on require() calls. This means that as long
103+
as your application is either natively in CJS, or compiled at build time to CJS, everything will work without any
104+
further setup.
105+
106+
ECMAScript Modules (ESM) are only supported for Node v18.19.0 onwards.
80107

81108
### Using Custom OpenTelemetry Instrumentation
82109

@@ -153,12 +180,6 @@ your Express app.
153180

154181
```js
155182
const Sentry = require('@sentry/node');
156-
157-
Sentry.init({
158-
dsn: '__DSN__',
159-
tracesSampleRate: 1,
160-
});
161-
162183
const express = require('express');
163184
const app = express();
164185

@@ -177,12 +198,6 @@ your Fastify app.
177198

178199
```js
179200
const Sentry = require('@sentry/node');
180-
181-
Sentry.init({
182-
dsn: '__DSN__',
183-
tracesSampleRate: 1,
184-
});
185-
186201
const { fastify } = require('fastify');
187202
const app = fastify();
188203
Sentry.setupFastifyErrorHandler(app);
@@ -191,3 +206,40 @@ Sentry.setupFastifyErrorHandler(app);
191206

192207
app.listen();
193208
```
209+
210+
## Connect
211+
212+
The following shows how you can setup Connect instrumentation in v8. This will capture performance data & errors for
213+
your Fastify app.
214+
215+
```js
216+
const connect = require('connect');
217+
const Sentry = require('@sentry/node');
218+
const app = connect();
219+
220+
Sentry.setupConnectErrorHandler(app);
221+
222+
// Add your routes, etc.
223+
224+
app.listen(3030);
225+
```
226+
227+
## Koa
228+
229+
The following shows how you can setup Koa instrumentation in v8. This will capture performance data & errors for your
230+
Fastify app.
231+
232+
```js
233+
const Koa = require('koa');
234+
const Router = require('@koa/router');
235+
const Sentry = require('@sentry/node');
236+
237+
const router = new Router();
238+
const app = new Koa();
239+
240+
Sentry.setupKoaErrorHandler(app);
241+
242+
// Add your routes, etc.
243+
244+
app.listen(3030);
245+
```

0 commit comments

Comments
 (0)