diff --git a/docs/platforms/javascript/common/configuration/integrations/http.mdx b/docs/platforms/javascript/common/configuration/integrations/http.mdx index e4d564552673fe..471b9d39293c3d 100644 --- a/docs/platforms/javascript/common/configuration/integrations/http.mdx +++ b/docs/platforms/javascript/common/configuration/integrations/http.mdx @@ -87,6 +87,12 @@ The callback function receives two arguments: - `url`: The full URL of the incoming request, including the protocol, host, port, path and query string. For example: `https://example.com/users?name=John`. - `request`: An object of type `RequestOptions` containing the incoming request's options. You can use this to filter on properties like the request method or headers. +### `tracePropagation` + +_Type: `boolean`_ (Defaults to `true`) + +Whether to inject trace propagation headers (`sentry-trace`, `baggage`, `traceparent`) into outgoing HTTP requests. When set to `false`, Sentry will not inject any trace propagation headers but will still create breadcrumbs (if `breadcrumbs` is enabled). This is useful when `skipOpenTelemetrySetup: true` is configured and your external OpenTelemetry setup already handles trace propagation, to avoid duplicate headers. + ### `ignoreOutgoingRequests` _Type: `(url: string, request: RequestOptions) => boolean`_ diff --git a/docs/platforms/javascript/common/configuration/integrations/nodefetch.mdx b/docs/platforms/javascript/common/configuration/integrations/nodefetch.mdx index 1f8a0ab7789aa2..03917579c0affa 100644 --- a/docs/platforms/javascript/common/configuration/integrations/nodefetch.mdx +++ b/docs/platforms/javascript/common/configuration/integrations/nodefetch.mdx @@ -55,6 +55,12 @@ _Type: `boolean`_ If set to false, no breadcrumbs will be captured. +### `tracePropagation` + +_Type: `boolean`_ (Defaults to `true`) + +Whether to inject trace propagation headers (`sentry-trace`, `baggage`, `traceparent`) into outgoing fetch requests. When set to `false`, Sentry will not inject any trace propagation headers but will still create breadcrumbs (if `breadcrumbs` is enabled). This is useful when `skipOpenTelemetrySetup: true` is configured and your external OpenTelemetry setup already handles trace propagation, to avoid duplicate headers. + ### `ignoreOutgoingRequests` _Type: `(url: string) => boolean`_ diff --git a/docs/platforms/javascript/common/opentelemetry/custom-setup.mdx b/docs/platforms/javascript/common/opentelemetry/custom-setup.mdx index 1d3a8a7a279649..4a83cf21e8f7dd 100644 --- a/docs/platforms/javascript/common/opentelemetry/custom-setup.mdx +++ b/docs/platforms/javascript/common/opentelemetry/custom-setup.mdx @@ -104,14 +104,14 @@ If you want to add your own http/node-fetch instrumentation, you have to follow -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`: +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`. You can also set `tracePropagation: false` to prevent Sentry from injecting trace headers, letting your OpenTelemetry setup handle propagation instead: ```javascript const sentryClient = Sentry.init({ dsn: "___DSN___", skipOpenTelemetrySetup: true, - integrations: [Sentry.httpIntegration({ spans: false })], + integrations: [Sentry.httpIntegration({ spans: false, tracePropagation: false })], }); ``` @@ -134,6 +134,16 @@ It's important that `httpIntegration` is still registered this way to ensure tha If tracing is disabled, the Node Fetch instrumentation will not emit any spans. In this scenario, it will only inject sentry-specific trace propagation headers. You are free to add your own Node Fetch instrumentation on top of this which may emit spans as you like. +If your OpenTelemetry setup already handles trace propagation for fetch requests, you can set `tracePropagation: false` to prevent Sentry from injecting duplicate trace headers: + +```javascript +const sentryClient = Sentry.init({ + dsn: "___DSN___", + skipOpenTelemetrySetup: true, + integrations: [Sentry.nativeNodeFetchIntegration({ tracePropagation: false })], +}); +``` + ## Using a Custom Sampler While you can use your own sampler, we recommend that you use the `SentrySampler`. This will ensure that the correct subset of traces will be sent to Sentry, based on your `tracesSampleRate`. It will also ensure that all other Sentry features like trace propagation work as expected. If you do need to use your own sampler, make sure to wrap your `SamplingResult` with our `wrapSamplingDecision` method like in the example below: