Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
test: Fix flaky errorsInSession replay test#7309
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import type { RecordingEvent, ReplayContainer } from '@sentry/replay/build/npm/types/types'; | ||
| import type { Breadcrumb, Event, ReplayEvent } from '@sentry/types'; | ||
| import pako from 'pako'; | ||
| import type { Page, Request } from 'playwright'; | ||
| import type { Page, Request, Response } from 'playwright'; | ||
| import { envelopeRequestParser } from './helpers'; | ||
| @@ -37,8 +37,10 @@ type SnapshotNode = { | ||
| * @param segmentId the segment_id of the replay event | ||
| * @returns | ||
| */ | ||
| export function waitForReplayRequest(page: Page, segmentId?: number): Promise<Request> { | ||
| return page.waitForRequest(req => { | ||
| export function waitForReplayRequest(page: Page, segmentId?: number): Promise<Response> { | ||
MemberAuthor 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. We actually wait on a response here now, as that may be a bit better/more expected timing. | ||
| return page.waitForResponse(res => { | ||
| const req = res.request(); | ||
| const postData = req.postData(); | ||
| if (!postData) { | ||
| return false; | ||
| @@ -78,7 +80,8 @@ export async function getReplaySnapshot(page: Page): Promise<ReplayContainer> { | ||
| export const REPLAY_DEFAULT_FLUSH_MAX_DELAY = 5_000; | ||
| export function getReplayEvent(replayRequest: Request): ReplayEvent { | ||
| export function getReplayEvent(resOrReq: Request | Response): ReplayEvent { | ||
| const replayRequest = getRequest(resOrReq); | ||
| const event = envelopeRequestParser(replayRequest); | ||
| if (!isReplayEvent(event)) { | ||
| throw new Error('Request is not a replay event'); | ||
| @@ -103,7 +106,8 @@ type RecordingContent = { | ||
| * @param replayRequest | ||
| * @returns an object containing the replay breadcrumbs and performance spans | ||
| */ | ||
| export function getCustomRecordingEvents(replayRequest: Request): CustomRecordingContent { | ||
| export function getCustomRecordingEvents(resOrReq: Request | Response): CustomRecordingContent { | ||
| const replayRequest = getRequest(resOrReq); | ||
| const recordingEvents = getDecompressedRecordingEvents(replayRequest); | ||
| const breadcrumbs = getReplayBreadcrumbs(recordingEvents); | ||
| @@ -128,21 +132,25 @@ function getReplayPerformanceSpans(recordingEvents: RecordingEvent[]): Performan | ||
| .map(data => data.payload) as PerformanceSpan[]; | ||
| } | ||
| export function getFullRecordingSnapshots(replayRequest: Request): RecordingSnapshot[] { | ||
| export function getFullRecordingSnapshots(resOrReq: Request | Response): RecordingSnapshot[] { | ||
| const replayRequest = getRequest(resOrReq); | ||
| const events = getDecompressedRecordingEvents(replayRequest) as RecordingEvent[]; | ||
| return events.filter(event => event.type === 2).map(event => event.data as RecordingSnapshot); | ||
| } | ||
| function getIncrementalRecordingSnapshots(replayRequest: Request): RecordingSnapshot[] { | ||
| function getIncrementalRecordingSnapshots(resOrReq: Request | Response): RecordingSnapshot[] { | ||
| const replayRequest = getRequest(resOrReq); | ||
| const events = getDecompressedRecordingEvents(replayRequest) as RecordingEvent[]; | ||
| return events.filter(event => event.type === 3).map(event => event.data as RecordingSnapshot); | ||
| } | ||
| function getDecompressedRecordingEvents(replayRequest: Request): RecordingEvent[] { | ||
| function getDecompressedRecordingEvents(resOrReq: Request | Response): RecordingEvent[] { | ||
| const replayRequest = getRequest(resOrReq); | ||
| return replayEnvelopeRequestParser(replayRequest, 5) as RecordingEvent[]; | ||
| } | ||
| export function getReplayRecordingContent(replayRequest: Request): RecordingContent { | ||
| export function getReplayRecordingContent(resOrReq: Request | Response): RecordingContent { | ||
| const replayRequest = getRequest(resOrReq); | ||
| const fullSnapshots = getFullRecordingSnapshots(replayRequest); | ||
| const incrementalSnapshots = getIncrementalRecordingSnapshots(replayRequest); | ||
| const customEvents = getCustomRecordingEvents(replayRequest); | ||
| @@ -255,3 +263,9 @@ function normalizeNumberAttribute(num: number): string { | ||
| return `[${stepCount * step}-${(stepCount + 1) * step}]`; | ||
| } | ||
| /** Get a request from either a request or a response */ | ||
| function getRequest(resOrReq: Request | Response): Request { | ||
| // @ts-ignore we check this | ||
| return typeof resOrReq.request === 'function' ? (resOrReq as Response).request() : (resOrReq as Request); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could probably sometimes lead to a second flush, which we didn't actually want/need. It will flush on page visit anyhow!