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
updates the Custom Node Otel setup page by:
- showing how users can now add their own HttpInstrumentation (possible since we added `httpIntegration({spans: false})` in 8.35.0
- adding a section discussing ESM loaders and that only one loader hook (either their own or Sentry's) should be registered (we learned about this in getsentry/sentry-javascript#14065)
---------
Co-authored-by: Francesco Novy <[email protected]>
Copy file name to clipboardExpand all lines: docs/platforms/javascript/common/opentelemetry/custom-setup.mdx
+39-2Lines changed: 39 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -105,13 +105,25 @@ If tracing is not enabled (no `tracesSampleRate` is defined in the SDK configura
105
105
</Note>
106
106
</PlatformSection>
107
107
108
-
These are needed to make sure that trace propagation works correctly. Additionally, the HTTP instrumentation is configured to ensure that request isolation is automatically applied for Sentry.
108
+
These are needed to make sure that trace propagation works correctly.
109
109
110
110
If you want to add your own http/node-fetch instrumentation, you have to follow the following steps:
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
+
_Available since SDK version 8.35.0_
115
+
116
+
You can add your own `@opentelemetry/instrumentation-http` instance in your OpenTelemetry 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
127
116
128
### Custom Node Fetch Instrumentation
117
129
@@ -168,3 +180,28 @@ const provider = new NodeTracerProvider({
168
180
// Validate that the setup is correct
169
181
Sentry.validateOpenTelemetrySetup();
170
182
```
183
+
## ESM Loaders
184
+
185
+
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.
186
+
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.
187
+
If you are also registering a loader hook, you need to disable Sentry's loader hook:
188
+
189
+
```javascript
190
+
Sentry.init({
191
+
skipOpenTelemetrySetup:true,
192
+
registerEsmLoaderHooks:false,
193
+
});
194
+
```
195
+
196
+
<Note>
197
+
198
+
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.
204
+
In this case, ensure that you initialize the Sentry SDK in its own file and load this file prior to your application via `node --import instrument.mjs your-app.mjs`.
205
+
<PlatformSectionsupported={['javascript.node']}>
206
+
<PlatformLinkto="/install">Learn more about ESM installation methods.</PlatformLink>
0 commit comments