Conversation
Bundles Sizes Evolution
🚀 CPU PerformancePending... 🧠 Memory PerformancePending... |
|
✅ Tests 🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: 8c0365f | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback! |
Instrument `XMLHttpRequest.prototype.setRequestHeader` to collect request headers for XHR resources, closing the last gap in network header capture (Fetch request/response and XHR response headers were already supported). Headers are stored lazily on the existing `XhrOpenContext` via a `Headers` object in the `xhrContexts` WeakMap and passed through `RequestCompleteEvent` to `resourceCollection`, where the existing `filterHeaders` security layer (forbidden header pattern, 100-header cap, 128-char value truncation) applies unchanged. Gated by `ExperimentalFeature.TRACK_RESOURCE_HEADERS` and `trackResourceHeaders` config — no new flags needed. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
2b9abcb to
8c0365f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The browser SDK already captures network headers for three out of four request/direction combinations:
XHR requests account for a significant portion of the network requests we collect. This PR closes the gap.
The root challenge:
XMLHttpRequesthas no native getter for request headers — oncesetRequestHeader()is called, headers cannot be read back. This PR solves it by interceptingsetRequestHeaderat instrumentation time.Changes
Instrument
XMLHttpRequest.prototype.setRequestHeaderinxhrObservable.ts, alongside the existingopen/send/abortinterception. Headers are stored lazily as aHeadersobject onXhrOpenContextin the existingxhrContextsWeakMap, then passed throughRequestCompleteEventtoresourceCollection.tswhere the existingfilterHeaderssecurity layer applies unchanged (forbidden header pattern, 100-header cap, 128-char value truncation).Files changed:
packages/core/src/browser/xhrObservable.ts— instrumentsetRequestHeader, extendXhrOpenContextwithrequestHeaders?: Headerspackages/core/test/emulate/mockXhr.ts— addsetRequestHeadersupport to the mock XHRpackages/rum-core/src/domain/requestCollection.ts— extendRequestCompleteEventwithrequestHeaders?: Headerspackages/rum-core/src/domain/resource/resourceCollection.ts— readrequest.requestHeadersfor XHR ingetRequestHeaders()No new feature flags or configuration options. Gated by the existing
ExperimentalFeature.TRACK_RESOURCE_HEADERSandtrackResourceHeadersconfig.Design notes:
onPostCall(not pre-call), so phantom headers are never captured whensetRequestHeaderthrows (e.g. called beforeopen(), invalid header name)Headers.append()preserves the spec behavior for duplicate header names (X-Foo: a, b)x-datadog-trace-idetc.) are captured alongside app headers — intentional, filtered by user'strackResourceHeadersconfigBundle size impact (~80 bytes gzipped on rum/rum-slim):
Test instructions
Expected output:
[ { "url": "https://tools-httpstatus.pickup-services.com/200", "headers": { "x-custom-header": "my-value", "x-request-id": "req-123" } }, { "url": "https://tools-httpstatus.pickup-services.com/200", "headers": null }, { "url": "https://tools-httpstatus.pickup-services.com/200", "headers": { "x-custom-header": "should-appear" } } ]x-custom-headerandx-request-idare capturedrequest.headersis absent (null)authorizationis stripped byFORBIDDEN_HEADER_PATTERN;x-custom-headerstill appearsChecklist