Commit a680e0c
authored
feat(browser): Add
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.onRequestSpanEnd hook to browser tracing integration (#17884)1 parent 6230aed commit a680e0c
File tree
13 files changed
+259
-57
lines changed- dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/on-request-span-end
- packages
- browser-utils/src
- browser/src/tracing
- core/src
- types-hoist
- replay-internal/src/coreHandlers/util
13 files changed
+259
-57
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
206 | 206 | | |
207 | 207 | | |
208 | 208 | | |
209 | | - | |
| 209 | + | |
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
| |||
Lines changed: 18 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
Lines changed: 61 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
Lines changed: 17 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
3 | 11 | | |
4 | 12 | | |
5 | 13 | | |
| |||
297 | 305 | | |
298 | 306 | | |
299 | 307 | | |
300 | | - | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
301 | 314 | | |
302 | 315 | | |
303 | 316 | | |
| |||
365 | 378 | | |
366 | 379 | | |
367 | 380 | | |
| 381 | + | |
368 | 382 | | |
369 | 383 | | |
370 | 384 | | |
| |||
692 | 706 | | |
693 | 707 | | |
694 | 708 | | |
| 709 | + | |
695 | 710 | | |
696 | 711 | | |
697 | 712 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
2 | 9 | | |
3 | 10 | | |
4 | 11 | | |
| |||
22 | 29 | | |
23 | 30 | | |
24 | 31 | | |
| 32 | + | |
25 | 33 | | |
26 | 34 | | |
27 | 35 | | |
28 | 36 | | |
29 | | - | |
| 37 | + | |
30 | 38 | | |
31 | 39 | | |
32 | 40 | | |
| |||
102 | 110 | | |
103 | 111 | | |
104 | 112 | | |
105 | | - | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
106 | 119 | | |
107 | 120 | | |
108 | 121 | | |
| |||
125 | 138 | | |
126 | 139 | | |
127 | 140 | | |
| 141 | + | |
128 | 142 | | |
129 | 143 | | |
130 | 144 | | |
| |||
171 | 185 | | |
172 | 186 | | |
173 | 187 | | |
| 188 | + | |
174 | 189 | | |
175 | 190 | | |
176 | 191 | | |
| |||
205 | 220 | | |
206 | 221 | | |
207 | 222 | | |
| 223 | + | |
208 | 224 | | |
209 | 225 | | |
210 | 226 | | |
211 | 227 | | |
212 | 228 | | |
213 | 229 | | |
214 | 230 | | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
222 | 234 | | |
223 | 235 | | |
224 | 236 | | |
225 | 237 | | |
226 | 238 | | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | 239 | | |
237 | 240 | | |
238 | 241 | | |
| |||
315 | 318 | | |
316 | 319 | | |
317 | 320 | | |
| 321 | + | |
318 | 322 | | |
319 | 323 | | |
320 | 324 | | |
| |||
337 | 341 | | |
338 | 342 | | |
339 | 343 | | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
340 | 349 | | |
341 | 350 | | |
342 | 351 | | |
| |||
438 | 447 | | |
439 | 448 | | |
440 | 449 | | |
441 | | - | |
442 | | - | |
443 | | - | |
444 | | - | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | | - | |
451 | | - | |
452 | | - | |
453 | | - | |
454 | | - | |
455 | | - | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
0 commit comments