Skip to content

Commit 2b76c04

Browse files
committed
add instruction on node --require
1 parent a0ec24b commit 2b76c04

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

docs/platforms/javascript/guides/node/index.mdx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,28 @@ Sentry should be initialized as early in your app as possible. It is essential t
3737

3838
Once this is done, Sentry's Node SDK captures unhandled exceptions as well as tracing data for your application.
3939

40+
Therefore, we recommend to create a file named `instrumentation.js` that imports and initializes Sentry.
41+
4042
<PlatformContent includePath="getting-started-config" />
4143

4244
If you set a `tracesSampleRate`, performance instrumentation will automatically be enabled for you. See <PlatformLink to="/performance/instrumentation/automatic-instrumentation">Automatic Instrumentation</PlatformLink> to learn about all the things that the SDK automatically instruments for you.
4345

4446
You can also manually capture performance data - see <PlatformLink to="/performance/instrumentation/custom-instrumentation">Custom Instrumentation</PlatformLink> for details.
4547

46-
<Include name="node-esm-compatibility" />
48+
## Run
49+
50+
Adjust the Node.js call for your application to use the [--require](https://nodejs.org/api/cli.html#-r---require-module) parameter and point it at `instrumentation.js`
51+
52+
<PlatformContent includePath="getting-started-run" />
53+
54+
Alternatively, if you cannot use [--require](https://nodejs.org/api/cli.html#-r---require-module), import `instrumentation.js` at the top of your application.
55+
56+
<PlatformContent includePath="getting-started-run-alternative" />
4757

4858
<PlatformContent includePath="getting-started-sourcemaps" />
4959

60+
<Include name="node-esm-compatibility" />
61+
5062
## Verify
5163

5264
This snippet includes an intentional error, so you can test that everything is working as soon as you set it up.

platform-includes/getting-started-config/javascript.node.mdx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ Sentry.init({
1111
// We recommend adjusting this value in production
1212
tracesSampleRate: 1.0,
1313
});
14-
15-
// http and other libraries are only instrumented
16-
// if required _after_ Sentry has been initialized
17-
const http = require("http");
1814
```
1915

2016
```javascript {tabTitle:ESM}
@@ -28,8 +24,4 @@ Sentry.init({
2824
// We recommend adjusting this value in production
2925
tracesSampleRate: 1.0,
3026
});
31-
32-
// http and other libraries are only instrumented
33-
// if imported _after_ Sentry has been initialized
34-
import http from "http";
3527
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<SignInNote />
2+
3+
```javascript {tabTitle:CommonJS}
4+
require('./instrumentation.js')
5+
6+
// http and other libraries are only instrumented
7+
// if required _after_ Sentry has been initialized
8+
const http = require("http");
9+
```
10+
11+
```javascript {tabTitle:ESM}
12+
import './instrumentation.js'
13+
14+
// http and other libraries are only instrumented
15+
// if imported _after_ Sentry has been initialized
16+
import http from "http";
17+
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```bash
2+
node --require ./instrumentation.js ./your/app.js
3+
```

0 commit comments

Comments
 (0)