You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(browser): Add onRequestSpanEnd hook to browser tracing integration (#17884)
This PR aims to address #9643 partially by introducing a
`onRequestSpanEnd` hook to the browser integration. These changes make
it easier for users to enrich tracing spans with response header data.
#### Example
```ts
import * as Sentry from '@sentry/browser';
Sentry.init({
// ...
integrations: [
Sentry.browserTracingIntegration({
onRequestSpanEnd(span, responseInformation) {
span.setAttributes({
response_type: 'JSON',
});
},
}),
],
});
```
#### Tracing Integration and API Improvements
* Added `onRequestSpanEnd` callback to `BrowserTracingOptions` and
`RequestInstrumentationOptions`, allowing users to access response
headers when a request span ends. This enables custom span annotation
based on response data.
* Updated internal request instrumentation logic to call
`onRequestSpanEnd` for both Fetch and XHR requests, passing parsed
response headers to the callback.
#### Utility and Refactoring
* Centralized header parsing and filtering utilities
(`parseXhrResponseHeaders`, `getFetchResponseHeaders`,
`filterAllowedHeaders`) in `networkUtils.ts`, and exported them for
reuse across packages.
* Moved helper functions for baggage header checking, URL resolution,
performance timing checks, and safe header creation to a new `utils.ts`
file to avoid failing the file size limit lint rule.
I was hesitant to hoist up those replay utils initially but a few of
them were needed to expose them on the hook callback.
#### Type and API Consistency
* Introduced new types `RequestHookInfo` and `ResponseHookInfo` to
standardize the information passed to request span hooks, and exported
them from the core package for use in integrations.
I also added the necessary tests to test out the new hook.
0 commit comments