Skip to content
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

chore: Add missing fields into Replay NetworkRequestData type #8284

Merged
merged 8 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/replay/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ export { Replay } from './integration';
export type {
BreadcrumbFrame,
BreadcrumbFrameEvent,
OptionFrameEvent,
ReplayFrame,
ReplayFrameEvent,
SpanFrame,
SpanFrameEvent,
} from './types/replayFrame';
EventType,
} from './types';
1 change: 1 addition & 0 deletions packages/replay/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './performance';
export * from './replay';
export * from './replayFrame';
export * from './rrweb';
export type { EventType } from '@sentry-internal/rrweb';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm we have this duplicated here but I forgot why... might be because our fork of rrweb, it wasn't exported? cc @mydea

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took that duplicate definition out, as you saw below.

Now getsentry/sentry-javascript is importing from '@sentry-internal/rrweb' and getsentry/sentry will import from getsentry/sentry-javascript
hopefully i can skip @sentry-internal/rrweb altogether if i've cross referenced everything correctly.

4 changes: 4 additions & 0 deletions packages/replay/src/types/performance.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { ReplayNetworkRequestOrResponse } from './replay';

export type AllPerformanceEntry = PerformancePaintTiming | PerformanceResourceTiming | PerformanceNavigationTiming;

// PerformancePaintTiming and PerformanceNavigationTiming are only available with TS 4.4 and newer
Expand Down Expand Up @@ -124,6 +126,8 @@ export interface NetworkRequestData {
statusCode?: number;
requestBodySize?: number;
responseBodySize?: number;
request?: ReplayNetworkRequestOrResponse;
response?: ReplayNetworkRequestOrResponse;
ryan953 marked this conversation as resolved.
Show resolved Hide resolved
}

export interface HistoryData {
Expand Down
125 changes: 88 additions & 37 deletions packages/replay/src/types/replayFrame.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import type { Breadcrumb, FetchBreadcrumbData, XhrBreadcrumbData } from '@sentry/types';

import type { AllEntryData } from './performance';
import type { EventType } from './rrweb';

interface BaseReplayFrame {
import type { EventType } from '@sentry-internal/rrweb';
import type { Breadcrumb } from '@sentry/types';

import type {
HistoryData,
LargestContentfulPaintData,
MemoryData,
NavigationData,
NetworkRequestData,
PaintData,
ResourceData,
} from './performance';

interface BaseBreadcrumbFrame {
timestamp: number;
/**
* For compatibility reasons
Expand All @@ -29,43 +37,31 @@ interface ConsoleFrameData {
logger: string;
arguments?: unknown[];
}
interface ConsoleFrame extends BaseReplayFrame {
interface ConsoleFrame extends BaseBreadcrumbFrame {
category: 'console';
level: Breadcrumb['level'];
message: string;
data: ConsoleFrameData;
}

type ClickFrameData = BaseDomFrameData;
interface ClickFrame extends BaseReplayFrame {
interface ClickFrame extends BaseBreadcrumbFrame {
category: 'ui.click';
message: string;
data: ClickFrameData;
}

interface FetchFrame extends BaseReplayFrame {
category: 'fetch';
type: 'http';
data: FetchBreadcrumbData;
}

interface InputFrame extends BaseReplayFrame {
interface InputFrame extends BaseBreadcrumbFrame {
category: 'ui.input';
message: string;
}

interface XhrFrame extends BaseReplayFrame {
category: 'xhr';
type: 'http';
data: XhrBreadcrumbData;
}

/* Breadcrumbs from Replay */
interface MutationFrameData {
count: number;
limit: boolean;
}
interface MutationFrame extends BaseReplayFrame {
interface MutationFrame extends BaseBreadcrumbFrame {
category: 'replay.mutations';
data: MutationFrameData;
}
Expand All @@ -77,16 +73,16 @@ interface KeyboardEventFrameData extends BaseDomFrameData {
altKey: boolean;
key: string;
}
interface KeyboardEventFrame extends BaseReplayFrame {
interface KeyboardEventFrame extends BaseBreadcrumbFrame {
category: 'ui.keyDown';
data: KeyboardEventFrameData;
}

interface BlurFrame extends BaseReplayFrame {
interface BlurFrame extends BaseBreadcrumbFrame {
category: 'ui.blur';
}

interface FocusFrame extends BaseReplayFrame {
interface FocusFrame extends BaseBreadcrumbFrame {
category: 'ui.focus';
}

Expand All @@ -95,46 +91,101 @@ interface SlowClickFrameData extends ClickFrameData {
timeAfterClickFs: number;
endReason: string;
}
interface SlowClickFrame extends BaseReplayFrame {
interface SlowClickFrame extends BaseBreadcrumbFrame {
category: 'ui.slowClickDetected';
data: SlowClickFrameData;
}

interface OptionFrame {
sessionSampleRate: number;
errorSampleRate: number;
useCompressionOption: boolean;
blockAllMedia: boolean;
maskAllText: boolean;
errorSampleRate: number;
maskAllInputs: boolean;
useCompression: boolean;
networkDetailHasUrls: boolean;
maskAllText: boolean;
networkCaptureBodies: boolean;
networkDetailHasUrls: boolean;
networkRequestHasHeaders: boolean;
networkResponseHasHeaders: boolean;
sessionSampleRate: number;
useCompression: boolean;
useCompressionOption: boolean;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorted these fields, no changes.

this object is duplicated in sentry, so i'm happy for the re-use here.

export type BreadcrumbFrame =
| ConsoleFrame
| ClickFrame
| FetchFrame
| InputFrame
| XhrFrame
| KeyboardEventFrame
| BlurFrame
| FocusFrame
| SlowClickFrame
| MutationFrame
| BaseReplayFrame;
| BaseBreadcrumbFrame;

export interface SpanFrame {
interface BaseSpanFrame {
op: string;
description: string;
startTimestamp: number;
endTimestamp: number;
data: AllEntryData;
data?: undefined | Record<string, any>;
}

interface FetchFrame extends BaseSpanFrame {
data: NetworkRequestData;
op: 'resource.fetch'
}

interface HistoryFrame extends BaseSpanFrame {
data: HistoryData;
op: 'navigation.push';
}

interface LargestContentfulPaintFrame extends BaseSpanFrame {
data: LargestContentfulPaintData;
op: 'largest-contentful-paint';
}

interface MemoryFrame extends BaseSpanFrame {
data: MemoryData,
op: 'memory',
}

interface NavigationFrame extends BaseSpanFrame {
data: NavigationData
op: 'navigation.navigate' | 'navigation.reload' | 'navigation.back_forward';
}

interface PaintFrame extends BaseSpanFrame {
data: PaintData;
op: 'paint';
}

interface ResourceFrame extends BaseSpanFrame {
data: ResourceData;
op:
| 'resource.css'
| 'resource.iframe'
| 'resource.img'
| 'resource.link'
| 'resource.other'
| 'resource.script';
}

interface XHRFrame extends BaseSpanFrame {
data: NetworkRequestData;
op: 'resource.xhr'
}

export type SpanFrame =
| BaseSpanFrame
| FetchFrame
| HistoryFrame
| LargestContentfulPaintFrame
| MemoryFrame
| NavigationFrame
| PaintFrame
| ResourceFrame
| XHRFrame;

export type ReplayFrame = BreadcrumbFrame | SpanFrame;

interface RecordingCustomEvent {
Expand Down
12 changes: 2 additions & 10 deletions packages/replay/src/types/rrweb.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
/* eslint-disable @typescript-eslint/naming-convention */

import type { EventType } from '@sentry-internal/rrweb';

type blockClass = string | RegExp;
type maskTextClass = string | RegExp;

export enum EventType {
DomContentLoaded = 0,
Load = 1,
FullSnapshot = 2,
IncrementalSnapshot = 3,
Meta = 4,
Custom = 5,
Plugin = 6,
}

ryan953 marked this conversation as resolved.
Show resolved Hide resolved
/**
* This is a partial copy of rrweb's eventWithTime type which only contains the properties
* we specifcally need in the SDK.
Expand Down
2 changes: 1 addition & 1 deletion packages/replay/src/util/addEvent.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { EventType } from '@sentry-internal/rrweb';
import { getCurrentHub } from '@sentry/core';
import { logger } from '@sentry/utils';

import type { AddEventResult, RecordingEvent, ReplayContainer, ReplayFrameEvent } from '../types';
import { EventType } from '../types/rrweb';
import { timestampToMs } from './timestampToMs';

function isCustomEvent(event: RecordingEvent): event is ReplayFrameEvent {
Expand Down
2 changes: 1 addition & 1 deletion packages/replay/src/util/handleRecordingEmit.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { EventType } from '@sentry-internal/rrweb';
import { logger } from '@sentry/utils';

import { saveSession } from '../session/saveSession';
import type { AddEventResult, OptionFrameEvent, RecordingEvent, ReplayContainer } from '../types';
import { EventType } from '../types/rrweb';
import { addEvent } from './addEvent';

type RecordingEmitCallback = (event: RecordingEvent, isCheckout?: boolean) => void;
Expand Down
Loading