123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- import type {Crumb} from 'sentry/types/breadcrumbs';
- import {
- breadcrumbFactory,
- replayTimestamps,
- rrwebEventListFactory,
- spansFactory,
- } from 'sentry/utils/replays/replayDataUtils';
- import type {
- MemorySpanType,
- RecordingEvent,
- ReplayCrumb,
- ReplayError,
- ReplayRecord,
- ReplaySpan,
- } from 'sentry/views/replays/types';
- export interface ReplayReaderParams {
- breadcrumbs: ReplayCrumb[] | undefined;
- errors: ReplayError[] | undefined;
- /**
- * The root Replay event, created at the start of the browser session.
- */
- replayRecord: ReplayRecord | undefined;
- /**
- * The captured data from rrweb.
- * Saved as N attachments that belong to the root Replay event.
- */
- rrwebEvents: RecordingEvent[] | undefined;
- spans: ReplaySpan[] | undefined;
- }
- type RequiredNotNull<T> = {
- [P in keyof T]: NonNullable<T[P]>;
- };
- export default class ReplayReader {
- static factory({
- breadcrumbs,
- replayRecord,
- errors,
- rrwebEvents,
- spans,
- }: ReplayReaderParams) {
- if (!breadcrumbs || !replayRecord || !rrwebEvents || !spans || !errors) {
- return null;
- }
- return new ReplayReader({breadcrumbs, replayRecord, errors, rrwebEvents, spans});
- }
- private constructor({
- breadcrumbs,
- replayRecord,
- errors,
- rrwebEvents,
- spans,
- }: RequiredNotNull<ReplayReaderParams>) {
- // TODO(replays): We should get correct timestamps from the backend instead
- // of having to fix them up here.
- const {startTimestampMs, endTimestampMs} = replayTimestamps(
- replayRecord,
- rrwebEvents,
- breadcrumbs,
- spans
- );
- replayRecord.startedAt = new Date(startTimestampMs);
- replayRecord.finishedAt = new Date(endTimestampMs);
- this.spans = spansFactory(spans);
- this.breadcrumbs = breadcrumbFactory(replayRecord, errors, breadcrumbs, this.spans);
- this.rrwebEvents = rrwebEventListFactory(replayRecord, rrwebEvents);
- this.replayRecord = replayRecord;
- }
- private replayRecord: ReplayRecord;
- private rrwebEvents: RecordingEvent[];
- private breadcrumbs: Crumb[];
- private spans: ReplaySpan[];
- /**
- * @returns Duration of Replay (milliseonds)
- */
- getDurationMs = () => {
- return this.replayRecord.duration * 1000;
- };
- getReplay = () => {
- return this.replayRecord;
- };
- getRRWebEvents = () => {
- return this.rrwebEvents;
- };
- getRawCrumbs = () => {
- return this.breadcrumbs;
- };
- getRawSpans = () => {
- return this.spans;
- };
- isMemorySpan = (span: ReplaySpan): span is MemorySpanType => {
- return span.op === 'memory';
- };
- isNetworkSpan = (span: ReplaySpan) => {
- return !this.isMemorySpan(span) && !span.op.includes('paint');
- };
- }
|