-
-
Notifications
You must be signed in to change notification settings - Fork 361
feat(replay): capture fetch (Blob/ArrayBuffer) response bodies in Session Replay network details #6473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(replay): capture fetch (Blob/ArrayBuffer) response bodies in Session Replay network details #6473
Changes from all commits
66f029a
5aee932
7c638d3
e479547
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,16 @@ | ||
| import type { Client, DynamicSamplingContext, ErrorEvent, Event, EventHint, Integration, Metric } from '@sentry/core'; | ||
|
|
||
| import { debug } from '@sentry/core'; | ||
| import type { | ||
| Breadcrumb, | ||
| BreadcrumbHint, | ||
| Client, | ||
| DynamicSamplingContext, | ||
| ErrorEvent, | ||
| Event, | ||
| EventHint, | ||
| Integration, | ||
| Metric, | ||
| } from '@sentry/core'; | ||
|
|
||
| import { addBreadcrumb, debug } from '@sentry/core'; | ||
|
|
||
| import type { ResolvedNetworkOptions } from './networkUtils'; | ||
|
|
||
|
|
@@ -9,7 +19,12 @@ import { hasHooks } from '../utils/clientutils'; | |
| import { isExpoGo, notMobileOs } from '../utils/environment'; | ||
| import { registerFeatureMarker } from '../utils/featureMarkers'; | ||
| import { NATIVE } from '../wrapper'; | ||
| import { makeEnrichXhrBreadcrumbsForMobileReplay } from './xhrUtils'; | ||
| import { | ||
| makeEnrichXhrBreadcrumbsForMobileReplay, | ||
| REPLAY_RESOLVED_RESPONSE_BODY_HINT_KEY, | ||
| resolveXhrResponseBody, | ||
| shouldCaptureResponseBodyAsync, | ||
| } from './xhrUtils'; | ||
|
|
||
| const MOBILE_REPLAY_NETWORK_DETAILS_INTEGRATION_NAME = 'MobileReplayNetworkDetails'; | ||
| const MOBILE_REPLAY_NETWORK_BODIES_INTEGRATION_NAME = 'MobileReplayNetworkBodies'; | ||
|
|
@@ -433,6 +448,36 @@ export const mobileReplayIntegration = (initOptions: MobileReplayOptions = defau | |
|
|
||
| // Wrap beforeSend to run processEvent after user's beforeSend | ||
| const clientOptions = client.getOptions(); | ||
|
|
||
| // Binary (Blob/ArrayBuffer) response bodies — which is every `fetch` | ||
| // response, since RN's fetch polyfill uses XHR with responseType 'blob' — | ||
| // can only be read asynchronously, but the breadcrumb is forwarded to the | ||
| // native SDKs synchronously. Hold such breadcrumbs here (return null), | ||
| // read the body, then re-add the same breadcrumb (timestamp is already | ||
| // set, so it keeps its original time) with the resolved body and a | ||
| // metadata snapshot on the hint — the xhr itself may be reused by then. | ||
| if (networkOptions.captureBodies && networkOptions.allowUrls.length > 0) { | ||
| const originalBeforeBreadcrumb = clientOptions.beforeBreadcrumb; | ||
| clientOptions.beforeBreadcrumb = (breadcrumb: Breadcrumb, hint?: BreadcrumbHint): Breadcrumb | null => { | ||
| if (hint && REPLAY_RESOLVED_RESPONSE_BODY_HINT_KEY in hint) { | ||
| // second pass with the resolved body — the user's beforeBreadcrumb already ran | ||
| return breadcrumb; | ||
| } | ||
| const result = originalBeforeBreadcrumb ? originalBeforeBreadcrumb(breadcrumb, hint) : breadcrumb; | ||
| if (result === null || !shouldCaptureResponseBodyAsync(result, hint, networkOptions)) { | ||
| return result; | ||
| } | ||
| const xhr = hint.xhr; | ||
| resolveXhrResponseBody(xhr) | ||
| .then(resolved => { | ||
| addBreadcrumb(result, { ...hint, [REPLAY_RESOLVED_RESPONSE_BODY_HINT_KEY]: resolved }); | ||
| }) | ||
| .then(undefined, (error: unknown) => { | ||
| debug.error(`[Sentry] ${MOBILE_REPLAY_INTEGRATION_NAME} Failed to re-add network breadcrumb`, error); | ||
| }); | ||
| return null; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Held fetch breadcrumbs miss error eventsHigh Severity Returning Additional Locations (2)Triggered by project rule: PR Review Guidelines for Cursor Bot Reviewed by Cursor Bugbot for commit e479547. Configure here. |
||
| }; | ||
| } | ||
| const originalBeforeSend = clientOptions.beforeSend; | ||
| clientOptions.beforeSend = async (event: ErrorEvent, hint: EventHint): Promise<ErrorEvent | null> => { | ||
| let result: ErrorEvent | null = event; | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.