Patches XMLHttpRequest.prototype so the request method, URL, headers and
body are stashed on each instance (_method, _url, _requestHeaders,
_body). The XMLHttpRequestInstrumentation applyCustomAttributesOnSpan
hook only receives the finished XHR object, so this is the only way for it
to attach http.request.body and http.request.header.* to the span.
The session replay XHRListener populates the same fields, but it is only
installed when the SessionReplay plugin has recordHeadersAndBody enabled.
Tracing must not depend on that, so this is installed whenever the
Observability plugin asks for headers and bodies. Values the XHRListener
already stashed are left untouched.
Returns a function that restores the original prototype methods.
Patches
XMLHttpRequest.prototypeso the request method, URL, headers and body are stashed on each instance (_method,_url,_requestHeaders,_body). The XMLHttpRequestInstrumentationapplyCustomAttributesOnSpanhook only receives the finished XHR object, so this is the only way for it to attachhttp.request.bodyandhttp.request.header.*to the span.The session replay
XHRListenerpopulates the same fields, but it is only installed when the SessionReplay plugin hasrecordHeadersAndBodyenabled. Tracing must not depend on that, so this is installed whenever the Observability plugin asks for headers and bodies. Values the XHRListener already stashed are left untouched.Returns a function that restores the original prototype methods.