/
types.ts
281 lines (235 loc) · 6.5 KB
/
types.ts
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
import type { ReplayRecordingData, ReplayRecordingMode } from '@sentry/types';
import type { eventWithTime, recordOptions } from './types/rrweb';
export type RecordingEvent = eventWithTime;
export type RecordingOptions = recordOptions;
export type AllPerformanceEntry = PerformancePaintTiming | PerformanceResourceTiming | PerformanceNavigationTiming;
export interface SendReplayData {
recordingData: ReplayRecordingData;
replayId: string;
segmentId: number;
includeReplayStartTimestamp: boolean;
eventContext: PopEventContext;
timestamp: number;
session: Session;
options: ReplayPluginOptions;
}
export type InstrumentationTypeBreadcrumb = 'dom' | 'scope';
/**
* The request payload to worker
*/
export interface WorkerRequest {
id: number;
method: string;
args: unknown[];
}
// PerformancePaintTiming and PerformanceNavigationTiming are only available with TS 4.4 and newer
// Therefore, we're exporting them here to make them available in older TS versions
export type PerformancePaintTiming = PerformanceEntry;
export type PerformanceNavigationTiming = PerformanceEntry & {
type: string;
transferSize: number;
domComplete: number;
};
/**
* The response from the worker
*/
export interface WorkerResponse {
id: number;
method: string;
success: boolean;
response: unknown;
}
export type AddEventResult = void;
export interface SampleRates {
/**
* The sample rate for session-long replays. 1.0 will record all sessions and
* 0 will record none.
*/
sessionSampleRate: number;
/**
* The sample rate for sessions that has had an error occur. This is
* independent of `sessionSampleRate`.
*/
errorSampleRate: number;
}
/**
* Session options that are configurable by the integration configuration
*/
export interface SessionOptions extends SampleRates {
/**
* If false, will create a new session per pageload. Otherwise, saves session
* to Session Storage.
*/
stickySession: boolean;
}
export interface ReplayPluginOptions extends SessionOptions {
/**
* The amount of time to wait before sending a replay
*/
flushMinDelay: number;
/**
* The max amount of time to wait before sending a replay
*/
flushMaxDelay: number;
/**
* Attempt to use compression when web workers are available
*
* (default is true)
*/
useCompression: boolean;
/**
* Mask all text in recordings. All text will be replaced with asterisks by default.
*/
maskAllText: boolean;
/**
* Block all media (e.g. images, svg, video) in recordings.
*/
blockAllMedia: boolean;
/**
* _experiments allows users to enable experimental or internal features.
* We don't consider such features as part of the public API and hence we don't guarantee semver for them.
* Experimental features can be added, changed or removed at any time.
*
* Default: undefined
*/
_experiments: Partial<{
captureExceptions: boolean;
traceInternals: boolean;
}>;
}
// These are optional for ReplayPluginOptions because the plugin sets default values
type OptionalReplayPluginOptions = Partial<ReplayPluginOptions>;
export interface ReplayConfiguration extends OptionalReplayPluginOptions, RecordingOptions {}
interface CommonEventContext {
/**
* The initial URL of the session
*/
initialUrl: string;
/**
* The initial starting timestamp of the session
*/
initialTimestamp: number;
/**
* Ordered list of URLs that have been visited during a replay segment
*/
urls: string[];
}
export interface PopEventContext extends CommonEventContext {
/**
* List of Sentry error ids that have occurred during a replay segment
*/
errorIds: Array<string>;
/**
* List of Sentry trace ids that have occurred during a replay segment
*/
traceIds: Array<string>;
}
/**
* Additional context that will be sent w/ `replay_event`
*/
export interface InternalEventContext extends CommonEventContext {
/**
* Set of Sentry error ids that have occurred during a replay segment
*/
errorIds: Set<string>;
/**
* Set of Sentry trace ids that have occurred during a replay segment
*/
traceIds: Set<string>;
/**
* The timestamp of the earliest event that has been added to event buffer. This can happen due to the Performance Observer which buffers events.
*/
earliestEvent: number | null;
}
export type Sampled = false | 'session' | 'error';
export interface Session {
id: string;
/**
* Start time of current session
*/
started: number;
/**
* Last known activity of the session
*/
lastActivity: number;
/**
* Segment ID for replay events
*/
segmentId: number;
/**
* The ID of the previous session.
* If this is empty, there was no previous session.
*/
previousSessionId?: string;
/**
* Is the session sampled? `false` if not sampled, otherwise, `session` or `error`
*/
sampled: Sampled;
}
export interface EventBuffer {
/**
* The number of raw events that are buffered
*/
readonly pendingLength: number;
/**
* The raw events that are buffered.
*/
readonly pendingEvents: RecordingEvent[];
/**
* Destroy the event buffer.
*/
destroy(): void;
/**
* Add an event to the event buffer.
*
* Returns a promise that resolves if the event was successfully added, else rejects.
*/
addEvent(event: RecordingEvent, isCheckout?: boolean): Promise<AddEventResult>;
/**
* Clears and returns the contents of the buffer.
*/
finish(): Promise<ReplayRecordingData>;
}
export type AddUpdateCallback = () => boolean | void;
export interface ReplayContainer {
eventBuffer: EventBuffer | null;
performanceEvents: AllPerformanceEntry[];
session: Session | undefined;
recordingMode: ReplayRecordingMode;
isEnabled(): boolean;
isPaused(): boolean;
getContext(): InternalEventContext;
start(): void;
stop(): void;
pause(): void;
resume(): void;
startRecording(): void;
stopRecording(): boolean;
flushImmediate(): void;
triggerUserActivity(): void;
addUpdate(cb: AddUpdateCallback): void;
getOptions(): ReplayPluginOptions;
getSessionId(): string | undefined;
}
export interface ReplayPerformanceEntry {
/**
* One of these types https://developer.mozilla.org/en-US/docs/Web/API/PerformanceEntry/entryType
*/
type: string;
/**
* A more specific description of the performance entry
*/
name: string;
/**
* The start timestamp in seconds
*/
start: number;
/**
* The end timestamp in seconds
*/
end: number;
/**
* Additional unstructured data to be included
*/
data?: Record<string, unknown>;
}