Skip to content

Commit 80197f0

Browse files
committed
feat(js): Document onlyIncludeInstrumentedModules option
1 parent 1284d0b commit 80197f0

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

docs/platforms/javascript/common/install/esm.mdx

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,43 @@ NODE_OPTIONS="--import ./instrument.mjs" npm run start
4949

5050
We do not support ESM in Node versions before 18.19.0.
5151

52-
## Skipping instrumentation
52+
## Troubleshooting instrumentation
5353

54-
By default, all packages are wrapped under the hood by [import-in-the-middle](https://www.npmjs.com/package/import-in-the-middle). If you run into a problem with a package, you can skip instrumentation for it by configuring `registerEsmLoaderHooks` in your `Sentry.init()` config:
54+
By default, all packages are wrapped under the hood by
55+
[import-in-the-middle](https://www.npmjs.com/package/import-in-the-middle) to
56+
aid instrumenting them.
57+
58+
If `import-in-the-middle` encounters problems wrapping a package, you may see
59+
syntax errors at runtime or logged errors in your console:
60+
```
61+
SyntaxError: The requested module '...' does not provide an export named '...'
62+
(node:3368) Error: 'import-in-the-middle' failed to wrap 'file://../../path/to/file.js'
63+
```
64+
65+
You can confirm that these errors are caused by `import-in-the-middle` by
66+
disabling it by setting `registerEsmLoaderHooks` to false. Note, this will also
67+
disable tracing instrumentation:
68+
69+
```javascript {tabTitle:ESM} {filename: instrument.mjs}
70+
import * as Sentry from "@sentry/node";
71+
72+
Sentry.init({
73+
dsn: "___PUBLIC_DSN___",
74+
registerEsmLoaderHooks: false
75+
});
76+
```
77+
78+
If you are starting Sentry via `--import`, you can instruct `import-in-the-middle`
79+
to only wrap packages that Sentry specifically instruments. To do this, you can
80+
set the `onlyIncludeInstrumentedModules` to `true`:
5581

5682
```javascript {tabTitle:ESM} {filename: instrument.mjs}
5783
import * as Sentry from "@sentry/node";
5884

5985
Sentry.init({
6086
dsn: "___PUBLIC_DSN___",
6187
registerEsmLoaderHooks: {
62-
// Provide a list of package names to exclude from instrumentation
63-
exclude: ["package-name"],
88+
onlyIncludeInstrumentedModules: true
6489
},
6590
});
6691
```

docs/platforms/javascript/common/troubleshooting/index.mdx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ To fix this, change the `tracePropagationTargets` option during SDK initializati
8282
</Expandable>
8383
</PlatformCategorySection>
8484

85+
<Expandable permalink title="Error: 'import-in-the-middle' failed to wrap">
86+
When using ESM, by default all packages are wrapped under the hood by
87+
[import-in-the-middle](https://www.npmjs.com/package/import-in-the-middle).
88+
`import-in-the-middle` has compatibility issues with some packages and
89+
can throw errors in these situations.
90+
91+
Check out the [ESM troubleshooting section](/platforms/javascript/guides/node/install/esm/#troubleshooting-instrumentation) for more information.
92+
</Expandable>
93+
8594
<PlatformCategorySection supported={['browser']}>
8695
<Expandable permalink title="`instrument.js` Line Numbers for Console Log statements">
8796

0 commit comments

Comments
 (0)