@sentry/replay 0.4.8-3 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/README.md +15 -15
  2. package/dist/config/dist/src/api/captureReplay.d.ts +5 -3
  3. package/dist/config/dist/src/api/captureReplayUpdate.d.ts +5 -3
  4. package/dist/config/dist/src/coreHandlers/getBreadcrumbHandler.d.ts +3 -0
  5. package/dist/config/dist/src/coreHandlers/getSpanHandler.d.ts +5 -0
  6. package/dist/config/dist/src/coreHandlers/handleFetch.d.ts +19 -2
  7. package/dist/config/dist/src/coreHandlers/handleHistory.d.ts +7 -0
  8. package/dist/config/dist/src/coreHandlers/handleXhr.d.ts +21 -2
  9. package/dist/config/dist/src/eventBuffer.d.ts +11 -4
  10. package/dist/config/dist/src/index.d.ts +28 -13
  11. package/dist/config/dist/src/session/constants.d.ts +2 -2
  12. package/dist/config/dist/src/types.d.ts +22 -9
  13. package/dist/config/dist/src/util/createPayload.d.ts +5 -0
  14. package/dist/dist/api/captureReplay.d.ts +5 -3
  15. package/dist/dist/api/captureReplayUpdate.d.ts +5 -3
  16. package/dist/dist/coreHandlers/getBreadcrumbHandler.d.ts +3 -0
  17. package/dist/dist/coreHandlers/getSpanHandler.d.ts +5 -0
  18. package/dist/dist/coreHandlers/handleFetch.d.ts +19 -2
  19. package/dist/dist/coreHandlers/handleHistory.d.ts +7 -0
  20. package/dist/dist/coreHandlers/handleXhr.d.ts +21 -2
  21. package/dist/dist/eventBuffer.d.ts +11 -4
  22. package/dist/dist/index.d.ts +28 -13
  23. package/dist/dist/session/constants.d.ts +2 -2
  24. package/dist/dist/types.d.ts +22 -9
  25. package/dist/dist/util/createPayload.d.ts +5 -0
  26. package/dist/index.es.js +379 -222
  27. package/dist/index.js +377 -220
  28. package/dist/index.js.map +1 -1
  29. package/package.json +2 -2
  30. package/dist/dist/coreHandlers/index.d.ts +0 -4
package/README.md CHANGED
@@ -4,7 +4,7 @@ This integration is a WIP.
4
4
 
5
5
  ## Pre-Requisites
6
6
 
7
- For the sentry-replay integration to work, you must have the [Sentry browser SDK package](https://www.npmjs.com/package/@sentry/browser) and the [rrweb package](https://www.npmjs.com/package/rrweb) installed.
7
+ For the sentry-replay integration to work, you must have the [Sentry browser SDK package](https://www.npmjs.com/package/@sentry/browser) installed.
8
8
 
9
9
  ## Installation
10
10
 
@@ -19,13 +19,13 @@ npm install --save @sentry/browser @sentry/replay
19
19
  with yarn:
20
20
 
21
21
  ```shell
22
- yarn add @sentry/replay @sentry/browser @sentry/replay
22
+ yarn add @sentry/browser @sentry/replay
23
23
  ```
24
24
 
25
25
  ## Setup
26
26
 
27
- To set up the integration add the following to your Sentry initialization. Several options are supported and passable via the integration constructor.
28
- See the rrweb documentation for advice on configuring these values.
27
+ To set up the integration add the following to your Sentry initialization. Several options are supported and passable via the integration constructor.
28
+ See the rrweb documentation for advice on configuring these values.
29
29
 
30
30
 
31
31
  ```javascript
@@ -51,14 +51,14 @@ Sentry.init({
51
51
 
52
52
  | key | type | default | description |
53
53
  | --- | ---- | ------- | ----------- |
54
- | flushMinDelay | number | 5000 | The minimum time to wait (in ms) before sending the recording payload. The payload is sent if `flushMinDelay` ms have elapsed between two events. |
55
- | flushMaxDelay | number | 15000 | The maximum time to wait (in ms) when sending the recording payload. The payload is sent if events occur at an interval less than `flushMinDelay` and `flushMaxDelay` ms have elapsed since the last time a payload was sent. |
56
- | initialFlushDelay | number | 5000 | The amount of time to wait (in ms) before sending the initial recording payload. This helps drop recordings where users visit and close the page quickly. |
57
- | stickySession | boolean | false | Keep track of the user across page loads. Note a single user using multiple tabs will result in multiple sessions. Closing a tab will result in the session being closed as well. |
58
- | useCompression | boolean | true | Uses `WebWorkers` (if available) to compress the recording payload before uploading to Sentry. |
59
- | captureOnlyOnError | boolean | false | Only capture the recording when an error happens. |
60
- | replaysSamplingRate | number | 1.0 | The rate at which to sample replays. (1.0 will collect all replays, 0 will collect no replays). |
61
- | maskAllInputs | boolean | true | Mask all `<input>` elements |
62
- | blockClass | string | `'sr-block'` | Redact all elements with the class name `sr-block` |
63
- | ignoreClass | string | `'sr-ignore'` | Ignores all elements with the class name `sr-ignore` |
64
- | maskTextClass | string | `'sr-mask'` | Mask all elements with the class name `sr-ignore` |
54
+ | `flushMinDelay` | `number` | `5000` | The minimum time to wait (in ms) before sending the recording payload. The payload is sent if `flushMinDelay` ms have elapsed between two events. |
55
+ | `flushMaxDelay` | `number` | `15000` | The maximum time to wait (in ms) when sending the recording payload. The payload is sent if events occur at an interval less than `flushMinDelay` and `flushMaxDelay` ms have elapsed since the last time a payload was sent. |
56
+ | `initialFlushDelay` | `number` | `5000` | The amount of time to wait (in ms) before sending the initial recording payload. This helps drop recordings where users visit and close the page quickly. |
57
+ | `stickySession` | `boolean` | `false` | Keep track of the user across page loads. Note a single user using multiple tabs will result in multiple sessions. Closing a tab will result in the session being closed as well. |
58
+ | `useCompression` | `boolean` | `true` | Uses `WebWorkers` (if available) to compress the recording payload before uploading to Sentry. |
59
+ | `captureOnlyOnError` | `boolean` | `false` | Only capture the recording when an error happens. |
60
+ | `replaysSamplingRate` | `number` | `1.0` | The rate at which to sample replays. (1.0 will collect all replays, 0 will collect no replays). |
61
+ | `recordingConfig.maskAllInputs` | `boolean` | `true` | Mask all `<input>` elements |
62
+ | `recordingConfig.blockClass` | `string` | `'sr-block'` | Redact all elements with the class name `sr-block` |
63
+ | `recordingConfig.ignoreClass` | `string` | `'sr-ignore'` | Ignores all elements with the class name `sr-ignore` |
64
+ | `recordingConfig.maskTextClass` | `string` | `'sr-mask'` | Mask all elements with the class name `sr-ignore` |
@@ -1,8 +1,10 @@
1
1
  import type { Session } from '@/session/Session';
2
2
  import { InitialState } from '@/types';
3
- interface CaptureReplayParams {
3
+ export interface CaptureReplayParams {
4
4
  session: Session;
5
5
  initialState: InitialState;
6
+ errorIds: string[];
7
+ traceIds: string[];
8
+ urls: string[];
6
9
  }
7
- export declare function captureReplay({ session, initialState }: CaptureReplayParams): void;
8
- export {};
10
+ export declare function captureReplay({ session, initialState, errorIds, traceIds, urls, }: CaptureReplayParams): void;
@@ -1,10 +1,12 @@
1
1
  import type { Session } from '@/session/Session';
2
- interface CaptureReplayUpdateParams {
2
+ export interface CaptureReplayUpdateParams {
3
3
  session: Session;
4
4
  /**
5
5
  * Timestamp of the event in milliseconds
6
6
  */
7
7
  timestamp: number;
8
+ errorIds: string[];
9
+ traceIds: string[];
10
+ urls: string[];
8
11
  }
9
- export declare function captureReplayUpdate({ session, timestamp, }: CaptureReplayUpdateParams): void;
10
- export {};
12
+ export declare function captureReplayUpdate({ session, timestamp, errorIds, traceIds, urls, }: CaptureReplayUpdateParams): void;
@@ -0,0 +1,3 @@
1
+ import { InstrumentationTypeBreadcrumb } from '@/types';
2
+ import { handleScope } from './handleScope';
3
+ export declare function getBreadcrumbHandler(type: InstrumentationTypeBreadcrumb): typeof handleScope;
@@ -0,0 +1,5 @@
1
+ import { InstrumentationTypeSpan } from '@/types';
2
+ import { handleFetch } from './handleFetch';
3
+ import { handleHistory } from './handleHistory';
4
+ import { handleXhr } from './handleXhr';
5
+ export declare function getSpanHandler(type: InstrumentationTypeSpan): typeof handleFetch | typeof handleXhr | typeof handleHistory;
@@ -1,2 +1,19 @@
1
- import { ReplaySpan } from '@/types';
2
- export declare function handleFetch(handlerData: any): ReplaySpan;
1
+ import { ReplayPerformanceEntry } from '@/createPerformanceEntry';
2
+ interface FetchHandlerData {
3
+ args: Parameters<typeof fetch>;
4
+ fetchData: {
5
+ method: string;
6
+ url: string;
7
+ };
8
+ response: {
9
+ type: string;
10
+ url: string;
11
+ redirected: boolean;
12
+ status: number;
13
+ ok: boolean;
14
+ };
15
+ startTimestamp: number;
16
+ endTimestamp?: number;
17
+ }
18
+ export declare function handleFetch(handlerData: FetchHandlerData): ReplayPerformanceEntry;
19
+ export {};
@@ -0,0 +1,7 @@
1
+ import { ReplayPerformanceEntry } from '@/createPerformanceEntry';
2
+ interface HistoryHandlerData {
3
+ from: string;
4
+ to: string;
5
+ }
6
+ export declare function handleHistory(handlerData: HistoryHandlerData): ReplayPerformanceEntry;
7
+ export {};
@@ -1,2 +1,21 @@
1
- import { ReplaySpan } from '@/types';
2
- export declare function handleXhr(handlerData: any): ReplaySpan;
1
+ import { ReplayPerformanceEntry } from '@/createPerformanceEntry';
2
+ declare type XHRSendInput = null | Blob | BufferSource | FormData | URLSearchParams | string;
3
+ interface SentryWrappedXMLHttpRequest extends XMLHttpRequest {
4
+ [key: string]: any;
5
+ __sentry_xhr__?: {
6
+ method?: string;
7
+ url?: string;
8
+ status_code?: number;
9
+ body?: XHRSendInput;
10
+ startTimestamp?: number;
11
+ };
12
+ __sentry_own_request__?: boolean;
13
+ }
14
+ interface XhrHandlerData {
15
+ args: [method: string, url: string];
16
+ xhr: SentryWrappedXMLHttpRequest;
17
+ startTimestamp: number;
18
+ endTimestamp?: number;
19
+ }
20
+ export declare function handleXhr(handlerData: XhrHandlerData): ReplayPerformanceEntry;
21
+ export {};
@@ -1,4 +1,4 @@
1
- import { RecordingEvent, WorkerRequest } from './types';
1
+ import { RecordingEvent, WorkerRequest, WorkerResponse } from './types';
2
2
  interface CreateEventBufferParams {
3
3
  useCompression: boolean;
4
4
  }
@@ -26,12 +26,19 @@ export declare class EventBufferCompressionWorker implements IEventBuffer {
26
26
  * Read-only incrementing counter
27
27
  */
28
28
  get id(): number;
29
- postMessage(args: WorkerRequest): void;
29
+ /**
30
+ * Post message to worker and wait for response before resolving promise.
31
+ */
32
+ postMessage({ id, method, args, }: WorkerRequest): Promise<WorkerResponse['response']>;
30
33
  init(): void;
31
34
  destroy(): void;
35
+ /**
36
+ * Note that this may not reflect what is actually in the event buffer. This
37
+ * is only a local count of the buffer size since `addEvent` is async.
38
+ */
32
39
  get length(): number;
33
- addEvent(event: RecordingEvent, isCheckout?: boolean): void;
34
- sendEventToWorker: (event: RecordingEvent) => void;
40
+ addEvent(event: RecordingEvent, isCheckout?: boolean): Promise<string | Uint8Array>;
41
+ sendEventToWorker: (event: RecordingEvent) => Promise<string | Uint8Array>;
35
42
  finishRequest: (id: number) => Promise<Uint8Array>;
36
43
  finish(): Promise<Uint8Array>;
37
44
  }
@@ -1,8 +1,10 @@
1
- import { Breadcrumb, DsnComponents, Event, Integration } from '@sentry/types';
1
+ import { Breadcrumb, Event, Integration } from '@sentry/types';
2
+ import { CaptureReplayParams } from './api/captureReplay';
3
+ import { CaptureReplayUpdateParams } from './api/captureReplayUpdate';
2
4
  import { Session } from './session/Session';
3
5
  import { ReplayPerformanceEntry } from './createPerformanceEntry';
4
6
  import { IEventBuffer } from './eventBuffer';
5
- import type { InstrumentationType, RecordingConfig, RecordingEvent, ReplayRequest, ReplaySpan, SentryReplayConfiguration, SentryReplayPluginOptions } from './types';
7
+ import type { InstrumentationTypeBreadcrumb, InstrumentationTypeSpan, RecordedEvents, RecordingConfig, RecordingEvent, ReplayRequest, SentryReplayConfiguration, SentryReplayPluginOptions } from './types';
6
8
  /**
7
9
  * Returns true to return control to calling function, otherwise continue with normal batching
8
10
  */
@@ -21,10 +23,6 @@ export declare class SentryReplay implements Integration {
21
23
  * Buffer of breadcrumbs to be uploaded
22
24
  */
23
25
  breadcrumbs: Breadcrumb[];
24
- /**
25
- * Buffer of replay spans to be uploaded
26
- */
27
- replaySpans: ReplaySpan[];
28
26
  /**
29
27
  * List of PerformanceEntry from PerformanceObserver
30
28
  */
@@ -58,8 +56,8 @@ export declare class SentryReplay implements Integration {
58
56
  * Captured state when integration is first initialized
59
57
  */
60
58
  private initialState;
59
+ private context;
61
60
  session: Session | undefined;
62
- static attachmentUrlFromDsn(dsn: DsnComponents, eventId: string): string;
63
61
  constructor({ flushMinDelay, flushMaxDelay, initialFlushDelay, stickySession, // TBD: Making this opt-in for now
64
62
  useCompression, captureOnlyOnError, replaysSamplingRate, recordingConfig: { maskAllInputs, blockClass, ignoreClass, maskTextClass, ...recordingOptions }, }?: SentryReplayConfiguration);
65
63
  /**
@@ -141,10 +139,16 @@ export declare class SentryReplay implements Integration {
141
139
  /**
142
140
  * Handler for Sentry Core SDK events.
143
141
  *
144
- * Transforms core SDK events into replay events.
142
+ * These specific events will create span-like objects in the recording.
143
+ *
144
+ */
145
+ handleCoreSpanListener: (type: InstrumentationTypeSpan) => (handlerData: any) => void;
146
+ /**
147
+ * Handler for Sentry Core SDK events.
145
148
  *
149
+ * These events will create breadcrumb-like objects in the recording.
146
150
  */
147
- handleCoreListener: (type: InstrumentationType) => (handlerData: any) => void;
151
+ handleCoreBreadcrumbListener: (type: InstrumentationTypeBreadcrumb) => (handlerData: any) => void;
148
152
  /**
149
153
  * Keep a list of performance entries that will be sent with a replay
150
154
  */
@@ -171,14 +175,19 @@ export declare class SentryReplay implements Integration {
171
175
  */
172
176
  createCustomBreadcrumb(breadcrumb: Breadcrumb): void;
173
177
  /**
174
- * Create a span for each performance entry. The parent transaction is `this.replayEvent`.
178
+ * Create a "span" for each performance entry. The parent transaction is `this.replayEvent`.
175
179
  */
176
- createPerformanceSpans(entries: ReplayPerformanceEntry[]): void;
180
+ createPerformanceSpans(entries: ReplayPerformanceEntry[]): Promise<void[]>;
177
181
  /**
178
182
  * Observed performance events are added to `this.performanceEvents`. These
179
183
  * are included in the replay event before it is finished and sent to Sentry.
180
184
  */
181
- addPerformanceEntries(): void;
185
+ addPerformanceEntries(): Promise<void[]>;
186
+ /**
187
+ * Create a "span" for the total amount of memory being used by JS objects
188
+ * (including v8 internal objects).
189
+ */
190
+ addMemoryEntry(): Promise<void[]>;
182
191
  /**
183
192
  *
184
193
  *
@@ -189,6 +198,12 @@ export declare class SentryReplay implements Integration {
189
198
  * Only flush if `captureOnlyOnError` is false.
190
199
  */
191
200
  conditionalFlush(lastActivity?: number): Promise<void>;
201
+ /**
202
+ * Return and clear context
203
+ */
204
+ popEventContext({ timestamp, }: {
205
+ timestamp: number;
206
+ }): CaptureReplayParams & CaptureReplayUpdateParams;
192
207
  /**
193
208
  * Flushes replay event buffer to Sentry.
194
209
  *
@@ -204,6 +219,6 @@ export declare class SentryReplay implements Integration {
204
219
  /**
205
220
  * Finalize and send the current replay event to Sentry
206
221
  */
207
- sendReplay(eventId: string, events: Uint8Array | string): Promise<boolean>;
222
+ sendReplay(eventId: string, events: RecordedEvents): Promise<boolean>;
208
223
  }
209
224
  export {};
@@ -1,5 +1,5 @@
1
1
  export declare const REPLAY_SESSION_KEY = "sentryReplaySession";
2
- export declare const ROOT_REPLAY_NAME = "sentry-replay";
3
- export declare const REPLAY_EVENT_NAME = "sentry-replay-event";
2
+ export declare const REPLAY_EVENT_NAME = "replay_event";
3
+ export declare const RECORDING_EVENT_NAME = "replay_recording";
4
4
  export declare const SESSION_IDLE_DURATION = 900000;
5
5
  export declare const VISIBILITY_CHANGE_TIMEOUT = 900000;
@@ -2,18 +2,14 @@ import { record } from 'rrweb';
2
2
  import type { eventWithTime } from 'rrweb/typings/types';
3
3
  export declare type RecordingEvent = eventWithTime;
4
4
  export declare type RecordingConfig = Parameters<typeof record>[0];
5
- export interface ReplaySpan {
6
- description: string;
7
- op: string;
8
- startTimestamp: number;
9
- endTimestamp: number;
10
- data?: Record<string, unknown>;
11
- }
5
+ export declare type RecordedEvents = Uint8Array | string;
12
6
  export interface ReplayRequest {
13
7
  endpoint: string;
14
- events: Uint8Array | string;
8
+ events: RecordedEvents;
15
9
  }
16
- export declare type InstrumentationType = 'scope' | 'dom' | 'fetch' | 'xhr';
10
+ export declare type InstrumentationTypeBreadcrumb = 'dom' | 'scope';
11
+ export declare type InstrumentationTypeSpan = 'fetch' | 'xhr' | 'history';
12
+ export declare type InstrumentationType = InstrumentationTypeBreadcrumb | InstrumentationTypeSpan | 'console' | 'error' | 'unhandledrejection';
17
13
  /**
18
14
  * The request payload to worker
19
15
  */
@@ -76,3 +72,20 @@ export interface InitialState {
76
72
  timestamp: number;
77
73
  url: string;
78
74
  }
75
+ /**
76
+ * Additional context that will be sent w/ `replay_event`
77
+ */
78
+ export interface ReplayEventContext {
79
+ /**
80
+ * Set of Sentry error ids that have occurred during a replay segment
81
+ */
82
+ errorIds: Set<string>;
83
+ /**
84
+ * Set of Sentry trace ids that have occurred during a replay segment
85
+ */
86
+ traceIds: Set<string>;
87
+ /**
88
+ * Ordered list of URLs that have been visited during a replay segment
89
+ */
90
+ urls: string[];
91
+ }
@@ -0,0 +1,5 @@
1
+ import { RecordedEvents } from '@/types';
2
+ export declare function createPayload({ events, headers, }: {
3
+ events: RecordedEvents;
4
+ headers: Record<string, any>;
5
+ }): string | Uint8Array;
@@ -1,8 +1,10 @@
1
1
  import type { Session } from '@/session/Session';
2
2
  import { InitialState } from '@/types';
3
- interface CaptureReplayParams {
3
+ export interface CaptureReplayParams {
4
4
  session: Session;
5
5
  initialState: InitialState;
6
+ errorIds: string[];
7
+ traceIds: string[];
8
+ urls: string[];
6
9
  }
7
- export declare function captureReplay({ session, initialState }: CaptureReplayParams): void;
8
- export {};
10
+ export declare function captureReplay({ session, initialState, errorIds, traceIds, urls, }: CaptureReplayParams): void;
@@ -1,10 +1,12 @@
1
1
  import type { Session } from '@/session/Session';
2
- interface CaptureReplayUpdateParams {
2
+ export interface CaptureReplayUpdateParams {
3
3
  session: Session;
4
4
  /**
5
5
  * Timestamp of the event in milliseconds
6
6
  */
7
7
  timestamp: number;
8
+ errorIds: string[];
9
+ traceIds: string[];
10
+ urls: string[];
8
11
  }
9
- export declare function captureReplayUpdate({ session, timestamp, }: CaptureReplayUpdateParams): void;
10
- export {};
12
+ export declare function captureReplayUpdate({ session, timestamp, errorIds, traceIds, urls, }: CaptureReplayUpdateParams): void;
@@ -0,0 +1,3 @@
1
+ import { InstrumentationTypeBreadcrumb } from '@/types';
2
+ import { handleScope } from './handleScope';
3
+ export declare function getBreadcrumbHandler(type: InstrumentationTypeBreadcrumb): typeof handleScope;
@@ -0,0 +1,5 @@
1
+ import { InstrumentationTypeSpan } from '@/types';
2
+ import { handleFetch } from './handleFetch';
3
+ import { handleHistory } from './handleHistory';
4
+ import { handleXhr } from './handleXhr';
5
+ export declare function getSpanHandler(type: InstrumentationTypeSpan): typeof handleFetch | typeof handleXhr | typeof handleHistory;
@@ -1,2 +1,19 @@
1
- import { ReplaySpan } from '@/types';
2
- export declare function handleFetch(handlerData: any): ReplaySpan;
1
+ import { ReplayPerformanceEntry } from '@/createPerformanceEntry';
2
+ interface FetchHandlerData {
3
+ args: Parameters<typeof fetch>;
4
+ fetchData: {
5
+ method: string;
6
+ url: string;
7
+ };
8
+ response: {
9
+ type: string;
10
+ url: string;
11
+ redirected: boolean;
12
+ status: number;
13
+ ok: boolean;
14
+ };
15
+ startTimestamp: number;
16
+ endTimestamp?: number;
17
+ }
18
+ export declare function handleFetch(handlerData: FetchHandlerData): ReplayPerformanceEntry;
19
+ export {};
@@ -0,0 +1,7 @@
1
+ import { ReplayPerformanceEntry } from '@/createPerformanceEntry';
2
+ interface HistoryHandlerData {
3
+ from: string;
4
+ to: string;
5
+ }
6
+ export declare function handleHistory(handlerData: HistoryHandlerData): ReplayPerformanceEntry;
7
+ export {};
@@ -1,2 +1,21 @@
1
- import { ReplaySpan } from '@/types';
2
- export declare function handleXhr(handlerData: any): ReplaySpan;
1
+ import { ReplayPerformanceEntry } from '@/createPerformanceEntry';
2
+ declare type XHRSendInput = null | Blob | BufferSource | FormData | URLSearchParams | string;
3
+ interface SentryWrappedXMLHttpRequest extends XMLHttpRequest {
4
+ [key: string]: any;
5
+ __sentry_xhr__?: {
6
+ method?: string;
7
+ url?: string;
8
+ status_code?: number;
9
+ body?: XHRSendInput;
10
+ startTimestamp?: number;
11
+ };
12
+ __sentry_own_request__?: boolean;
13
+ }
14
+ interface XhrHandlerData {
15
+ args: [method: string, url: string];
16
+ xhr: SentryWrappedXMLHttpRequest;
17
+ startTimestamp: number;
18
+ endTimestamp?: number;
19
+ }
20
+ export declare function handleXhr(handlerData: XhrHandlerData): ReplayPerformanceEntry;
21
+ export {};
@@ -1,4 +1,4 @@
1
- import { RecordingEvent, WorkerRequest } from './types';
1
+ import { RecordingEvent, WorkerRequest, WorkerResponse } from './types';
2
2
  interface CreateEventBufferParams {
3
3
  useCompression: boolean;
4
4
  }
@@ -26,12 +26,19 @@ export declare class EventBufferCompressionWorker implements IEventBuffer {
26
26
  * Read-only incrementing counter
27
27
  */
28
28
  get id(): number;
29
- postMessage(args: WorkerRequest): void;
29
+ /**
30
+ * Post message to worker and wait for response before resolving promise.
31
+ */
32
+ postMessage({ id, method, args, }: WorkerRequest): Promise<WorkerResponse['response']>;
30
33
  init(): void;
31
34
  destroy(): void;
35
+ /**
36
+ * Note that this may not reflect what is actually in the event buffer. This
37
+ * is only a local count of the buffer size since `addEvent` is async.
38
+ */
32
39
  get length(): number;
33
- addEvent(event: RecordingEvent, isCheckout?: boolean): void;
34
- sendEventToWorker: (event: RecordingEvent) => void;
40
+ addEvent(event: RecordingEvent, isCheckout?: boolean): Promise<string | Uint8Array>;
41
+ sendEventToWorker: (event: RecordingEvent) => Promise<string | Uint8Array>;
35
42
  finishRequest: (id: number) => Promise<Uint8Array>;
36
43
  finish(): Promise<Uint8Array>;
37
44
  }
@@ -1,8 +1,10 @@
1
- import { Breadcrumb, DsnComponents, Event, Integration } from '@sentry/types';
1
+ import { Breadcrumb, Event, Integration } from '@sentry/types';
2
+ import { CaptureReplayParams } from './api/captureReplay';
3
+ import { CaptureReplayUpdateParams } from './api/captureReplayUpdate';
2
4
  import { Session } from './session/Session';
3
5
  import { ReplayPerformanceEntry } from './createPerformanceEntry';
4
6
  import { IEventBuffer } from './eventBuffer';
5
- import type { InstrumentationType, RecordingConfig, RecordingEvent, ReplayRequest, ReplaySpan, SentryReplayConfiguration, SentryReplayPluginOptions } from './types';
7
+ import type { InstrumentationTypeBreadcrumb, InstrumentationTypeSpan, RecordedEvents, RecordingConfig, RecordingEvent, ReplayRequest, SentryReplayConfiguration, SentryReplayPluginOptions } from './types';
6
8
  /**
7
9
  * Returns true to return control to calling function, otherwise continue with normal batching
8
10
  */
@@ -21,10 +23,6 @@ export declare class SentryReplay implements Integration {
21
23
  * Buffer of breadcrumbs to be uploaded
22
24
  */
23
25
  breadcrumbs: Breadcrumb[];
24
- /**
25
- * Buffer of replay spans to be uploaded
26
- */
27
- replaySpans: ReplaySpan[];
28
26
  /**
29
27
  * List of PerformanceEntry from PerformanceObserver
30
28
  */
@@ -58,8 +56,8 @@ export declare class SentryReplay implements Integration {
58
56
  * Captured state when integration is first initialized
59
57
  */
60
58
  private initialState;
59
+ private context;
61
60
  session: Session | undefined;
62
- static attachmentUrlFromDsn(dsn: DsnComponents, eventId: string): string;
63
61
  constructor({ flushMinDelay, flushMaxDelay, initialFlushDelay, stickySession, // TBD: Making this opt-in for now
64
62
  useCompression, captureOnlyOnError, replaysSamplingRate, recordingConfig: { maskAllInputs, blockClass, ignoreClass, maskTextClass, ...recordingOptions }, }?: SentryReplayConfiguration);
65
63
  /**
@@ -141,10 +139,16 @@ export declare class SentryReplay implements Integration {
141
139
  /**
142
140
  * Handler for Sentry Core SDK events.
143
141
  *
144
- * Transforms core SDK events into replay events.
142
+ * These specific events will create span-like objects in the recording.
143
+ *
144
+ */
145
+ handleCoreSpanListener: (type: InstrumentationTypeSpan) => (handlerData: any) => void;
146
+ /**
147
+ * Handler for Sentry Core SDK events.
145
148
  *
149
+ * These events will create breadcrumb-like objects in the recording.
146
150
  */
147
- handleCoreListener: (type: InstrumentationType) => (handlerData: any) => void;
151
+ handleCoreBreadcrumbListener: (type: InstrumentationTypeBreadcrumb) => (handlerData: any) => void;
148
152
  /**
149
153
  * Keep a list of performance entries that will be sent with a replay
150
154
  */
@@ -171,14 +175,19 @@ export declare class SentryReplay implements Integration {
171
175
  */
172
176
  createCustomBreadcrumb(breadcrumb: Breadcrumb): void;
173
177
  /**
174
- * Create a span for each performance entry. The parent transaction is `this.replayEvent`.
178
+ * Create a "span" for each performance entry. The parent transaction is `this.replayEvent`.
175
179
  */
176
- createPerformanceSpans(entries: ReplayPerformanceEntry[]): void;
180
+ createPerformanceSpans(entries: ReplayPerformanceEntry[]): Promise<void[]>;
177
181
  /**
178
182
  * Observed performance events are added to `this.performanceEvents`. These
179
183
  * are included in the replay event before it is finished and sent to Sentry.
180
184
  */
181
- addPerformanceEntries(): void;
185
+ addPerformanceEntries(): Promise<void[]>;
186
+ /**
187
+ * Create a "span" for the total amount of memory being used by JS objects
188
+ * (including v8 internal objects).
189
+ */
190
+ addMemoryEntry(): Promise<void[]>;
182
191
  /**
183
192
  *
184
193
  *
@@ -189,6 +198,12 @@ export declare class SentryReplay implements Integration {
189
198
  * Only flush if `captureOnlyOnError` is false.
190
199
  */
191
200
  conditionalFlush(lastActivity?: number): Promise<void>;
201
+ /**
202
+ * Return and clear context
203
+ */
204
+ popEventContext({ timestamp, }: {
205
+ timestamp: number;
206
+ }): CaptureReplayParams & CaptureReplayUpdateParams;
192
207
  /**
193
208
  * Flushes replay event buffer to Sentry.
194
209
  *
@@ -204,6 +219,6 @@ export declare class SentryReplay implements Integration {
204
219
  /**
205
220
  * Finalize and send the current replay event to Sentry
206
221
  */
207
- sendReplay(eventId: string, events: Uint8Array | string): Promise<boolean>;
222
+ sendReplay(eventId: string, events: RecordedEvents): Promise<boolean>;
208
223
  }
209
224
  export {};
@@ -1,5 +1,5 @@
1
1
  export declare const REPLAY_SESSION_KEY = "sentryReplaySession";
2
- export declare const ROOT_REPLAY_NAME = "sentry-replay";
3
- export declare const REPLAY_EVENT_NAME = "sentry-replay-event";
2
+ export declare const REPLAY_EVENT_NAME = "replay_event";
3
+ export declare const RECORDING_EVENT_NAME = "replay_recording";
4
4
  export declare const SESSION_IDLE_DURATION = 900000;
5
5
  export declare const VISIBILITY_CHANGE_TIMEOUT = 900000;
@@ -2,18 +2,14 @@ import { record } from 'rrweb';
2
2
  import type { eventWithTime } from 'rrweb/typings/types';
3
3
  export declare type RecordingEvent = eventWithTime;
4
4
  export declare type RecordingConfig = Parameters<typeof record>[0];
5
- export interface ReplaySpan {
6
- description: string;
7
- op: string;
8
- startTimestamp: number;
9
- endTimestamp: number;
10
- data?: Record<string, unknown>;
11
- }
5
+ export declare type RecordedEvents = Uint8Array | string;
12
6
  export interface ReplayRequest {
13
7
  endpoint: string;
14
- events: Uint8Array | string;
8
+ events: RecordedEvents;
15
9
  }
16
- export declare type InstrumentationType = 'scope' | 'dom' | 'fetch' | 'xhr';
10
+ export declare type InstrumentationTypeBreadcrumb = 'dom' | 'scope';
11
+ export declare type InstrumentationTypeSpan = 'fetch' | 'xhr' | 'history';
12
+ export declare type InstrumentationType = InstrumentationTypeBreadcrumb | InstrumentationTypeSpan | 'console' | 'error' | 'unhandledrejection';
17
13
  /**
18
14
  * The request payload to worker
19
15
  */
@@ -76,3 +72,20 @@ export interface InitialState {
76
72
  timestamp: number;
77
73
  url: string;
78
74
  }
75
+ /**
76
+ * Additional context that will be sent w/ `replay_event`
77
+ */
78
+ export interface ReplayEventContext {
79
+ /**
80
+ * Set of Sentry error ids that have occurred during a replay segment
81
+ */
82
+ errorIds: Set<string>;
83
+ /**
84
+ * Set of Sentry trace ids that have occurred during a replay segment
85
+ */
86
+ traceIds: Set<string>;
87
+ /**
88
+ * Ordered list of URLs that have been visited during a replay segment
89
+ */
90
+ urls: string[];
91
+ }
@@ -0,0 +1,5 @@
1
+ import { RecordedEvents } from '@/types';
2
+ export declare function createPayload({ events, headers, }: {
3
+ events: RecordedEvents;
4
+ headers: Record<string, any>;
5
+ }): string | Uint8Array;