You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/platforms/javascript/common/opentelemetry/custom-setup.mdx
+34-1Lines changed: 34 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -111,7 +111,17 @@ If you want to add your own http/node-fetch instrumentation, you have to follow
111
111
112
112
### Custom HTTP Instrumentation
113
113
114
-
You won't be able to add `@opentelemetry/instrumentation-http` yourself and will need to use `httpIntegration` in order for Sentry to work as expected. If you want to use custom configuration for your HTTP instrumentation, you can use the <PlatformLinkto="/configuration/integrations/http/">httpIntegration configuration</PlatformLink>.
114
+
You can add your own `@opentelemetry/instrumentation-http` instance in your setup. However, in this case, you need to disable span creation in Sentry's `httpIntegration`:
It's important that `httpIntegration` is still registered this way to ensure that the Sentry SDK can correctly isolate requests, for example when capturing errors.
115
125
116
126
### Custom Node Fetch Instrumentation
117
127
@@ -168,3 +178,26 @@ const provider = new NodeTracerProvider({
168
178
// Validate that the setup is correct
169
179
Sentry.validateOpenTelemetrySetup();
170
180
```
181
+
## ESM loaders
182
+
183
+
If your application is running in ESM (`import`/`export` syntax), OpenTelemetry requires a [special setup](https://github.com/open-telemetry/opentelemetry-js/blob/main/doc/esm-support.md) to work correctly.
184
+
The Sentry SDK will automatically detect if your application is running in ESM mode and by default [register a loader hook](https://github.com/open-telemetry/opentelemetry-js/blob/main/doc/esm-support.md#instrumentation-hook-required-for-esm) itself.
185
+
If you are also registering a loader hook, you need to disable Sentry's loader hook:
186
+
187
+
```javascript
188
+
Sentry.init({
189
+
skipOpenTelemetrySetup:true,
190
+
registerEsmLoaderHooks:false,
191
+
});
192
+
```
193
+
194
+
<Note>
195
+
196
+
Registering loader hooks multiple times might result in duplicated spans being created.
Alternatively, you can also use Sentry's loader hook and remove your own loader hook registration code.
202
+
In this case, ensure that you initialize the Sentry SDK in its own file and you load this file prior to your application via `node --import instrument.mjs your-app.mjs`.
203
+
<PlatformLinkto="/install">Learn more about ESM installation methods.</PlatformLink>
0 commit comments