@@ -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({
5253const 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.
5861const Sentry = require (' @sentry/node' );
5962Sentry .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
6387const express = require (' express' );
6488const 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
155182const Sentry = require (' @sentry/node' );
156-
157- Sentry .init ({
158- dsn: ' __DSN__' ,
159- tracesSampleRate: 1 ,
160- });
161-
162183const express = require (' express' );
163184const app = express ();
164185
@@ -177,12 +198,6 @@ your Fastify app.
177198
178199``` js
179200const Sentry = require (' @sentry/node' );
180-
181- Sentry .init ({
182- dsn: ' __DSN__' ,
183- tracesSampleRate: 1 ,
184- });
185-
186201const { fastify } = require (' fastify' );
187202const app = fastify ();
188203Sentry .setupFastifyErrorHandler (app);
@@ -191,3 +206,40 @@ Sentry.setupFastifyErrorHandler(app);
191206
192207app .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