Skip to content

Commit b607226

Browse files
Lms24mydea
andauthored
ref(js): Update custom Node Otel setup docs (#11697)
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]>
1 parent 9ea051f commit b607226

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

docs/platforms/javascript/common/opentelemetry/custom-setup.mdx

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,25 @@ If tracing is not enabled (no `tracesSampleRate` is defined in the SDK configura
105105
</Note>
106106
</PlatformSection>
107107

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.
109109

110110
If you want to add your own http/node-fetch instrumentation, you have to follow the following steps:
111111

112112
### Custom HTTP Instrumentation
113113

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 <PlatformLink to="/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`:
117+
118+
```javascript
119+
const sentryClient = Sentry.init({
120+
dsn: "___DSN___",
121+
skipOpenTelemetrySetup: true,
122+
integrations: [Sentry.httpIntegration({ spans: false })],
123+
});
124+
```
125+
126+
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.
115127

116128
### Custom Node Fetch Instrumentation
117129

@@ -168,3 +180,28 @@ const provider = new NodeTracerProvider({
168180
// Validate that the setup is correct
169181
Sentry.validateOpenTelemetrySetup();
170182
```
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.
199+
[More details.](https://github.com/getsentry/sentry-javascript/issues/14065#issuecomment-2435546961)
200+
201+
</Note>
202+
203+
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+
<PlatformSection supported={['javascript.node']}>
206+
<PlatformLink to="/install">Learn more about ESM installation methods.</PlatformLink>
207+
</PlatformSection>

0 commit comments

Comments
 (0)