Skip to content

Commit 8a40bb9

Browse files
CopilotHazAT
andcommitted
fix(node-sdk): document headersToSpanAttributes option on nativeNodeFetchIntegration
Addresses skill drift from getsentry/sentry-javascript#19770. The nativeNodeFetchIntegration() now accepts headersToSpanAttributes to capture specific HTTP headers as span attributes, which became opt-in after @opentelemetry/instrumentation-undici@0.22.0. Co-Authored-By: Claude (Anthropic) Co-authored-by: HazAT <363802+HazAT@users.noreply.github.com>
1 parent edfc7d0 commit 8a40bb9

2 files changed

Lines changed: 62 additions & 1 deletion

File tree

skills/sentry-node-sdk/SKILL.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,29 @@ Then check your [Sentry Issues dashboard](https://sentry.io/issues/) — the err
599599
| `sampleRate` | `number` | `1.0` | Fraction of error events to send (0–1) |
600600
| `shutdownTimeout` | `number` | `2000` | Milliseconds to flush events before process exit |
601601

602+
### `nativeNodeFetchIntegration()` Options
603+
604+
Configures outgoing `fetch`/`undici` span capture. Since `@opentelemetry/instrumentation-undici@0.22.0`, response headers like `content-length` are no longer captured automatically — use `headersToSpanAttributes` to opt in:
605+
606+
```javascript
607+
Sentry.init({
608+
integrations: [
609+
Sentry.nativeNodeFetchIntegration({
610+
headersToSpanAttributes: {
611+
requestHeaders: ["x-request-id"],
612+
responseHeaders: ["content-length", "content-type"],
613+
},
614+
}),
615+
],
616+
});
617+
```
618+
619+
| Option | Type | Default | Notes |
620+
|--------|------|---------|-------|
621+
| `breadcrumbs` | `boolean` | `true` | Record breadcrumbs for outgoing fetch requests |
622+
| `headersToSpanAttributes.requestHeaders` | `string[]` || Request header names to capture as span attributes |
623+
| `headersToSpanAttributes.responseHeaders` | `string[]` || Response header names to capture as span attributes |
624+
602625
### Graceful Shutdown
603626

604627
Flush buffered events before process exit — important for short-lived scripts and serverless:

skills/sentry-node-sdk/references/tracing.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,37 @@ tracesSampler: ({ inheritOrSampleWith }) => inheritOrSampleWith(0.1),
122122
|---------|------|-----------------|
123123
| `node:http` / `node:https` (incoming) | `http.server` | Method, URL, status code, duration |
124124
| `node:http` / `node:https` (outgoing) | `http.client` | Method, URL, status code, duration |
125-
| `fetch` / `undici` | `http.client` | Method, URL, status code |
125+
| `fetch` / `undici` | `http.client` | Method, URL, status code (headers opt-in via `headersToSpanAttributes`) |
126126
| `axios` | `http.client` | Method, URL, status code |
127127

128+
#### Capturing HTTP Headers on Fetch Spans
129+
130+
Since `@opentelemetry/instrumentation-undici@0.22.0`, response headers like `content-length` are **no longer captured automatically** on outgoing `fetch`/`undici` spans. To restore header capture or add custom headers, use `headersToSpanAttributes` on `nativeNodeFetchIntegration()`:
131+
132+
```typescript
133+
import * as Sentry from "@sentry/node";
134+
135+
Sentry.init({
136+
dsn: process.env.SENTRY_DSN,
137+
tracesSampleRate: 1.0,
138+
integrations: [
139+
Sentry.nativeNodeFetchIntegration({
140+
headersToSpanAttributes: {
141+
requestHeaders: ["x-request-id", "x-custom-header"],
142+
responseHeaders: ["content-length", "content-type"],
143+
},
144+
}),
145+
],
146+
});
147+
```
148+
149+
Matched headers appear as span attributes: `http.request.header.<name>` and `http.response.header.<name>`.
150+
151+
| Option | Type | Default | Description |
152+
|--------|------|---------|-------------|
153+
| `headersToSpanAttributes.requestHeaders` | `string[]` | `undefined` | Request header names to capture as span attributes |
154+
| `headersToSpanAttributes.responseHeaders` | `string[]` | `undefined` | Response header names to capture as span attributes |
155+
128156
### Databases
129157

130158
| Library | `op` | What's captured |
@@ -638,6 +666,16 @@ Sentry.init({
638666
}
639667
return span;
640668
},
669+
670+
// Capture HTTP headers on outgoing fetch/undici spans
671+
integrations: [
672+
Sentry.nativeNodeFetchIntegration({
673+
headersToSpanAttributes: {
674+
requestHeaders: ["x-request-id"],
675+
responseHeaders: ["content-length", "content-type"],
676+
},
677+
}),
678+
],
641679
});
642680
```
643681

0 commit comments

Comments
 (0)