@sentry/replay 0.4.8-2 → 0.4.9

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 (67) hide show
  1. package/README.md +15 -15
  2. package/dist/config/dist/jest.config.d.ts +3 -0
  3. package/dist/config/dist/jest.setup.d.ts +10 -0
  4. package/dist/config/dist/src/api/captureReplay.d.ts +10 -0
  5. package/dist/config/dist/src/api/captureReplayUpdate.d.ts +12 -0
  6. package/dist/config/dist/src/coreHandlers/getBreadcrumbHandler.d.ts +3 -0
  7. package/dist/config/dist/src/coreHandlers/getSpanHandler.d.ts +5 -0
  8. package/dist/config/dist/src/coreHandlers/handleDom.d.ts +1 -0
  9. package/dist/config/dist/src/coreHandlers/handleFetch.d.ts +19 -0
  10. package/dist/config/dist/src/coreHandlers/handleFetch.test.d.ts +1 -0
  11. package/dist/config/dist/src/coreHandlers/handleHistory.d.ts +7 -0
  12. package/dist/config/dist/src/coreHandlers/handleScope-unit.test.d.ts +1 -0
  13. package/dist/config/dist/src/coreHandlers/handleScope.d.ts +2 -0
  14. package/dist/config/dist/src/coreHandlers/handleScope.test.d.ts +1 -0
  15. package/dist/config/dist/src/coreHandlers/handleXhr.d.ts +21 -0
  16. package/dist/{dist → config/dist/src}/coreHandlers/index.d.ts +0 -0
  17. package/dist/config/dist/src/createPerformanceEntry.d.ts +42 -0
  18. package/dist/config/dist/src/createPerformanceEntry.test.d.ts +1 -0
  19. package/dist/config/dist/src/eventBuffer.d.ts +45 -0
  20. package/dist/config/dist/src/eventBuffer.test.d.ts +1 -0
  21. package/dist/config/dist/src/flags.d.ts +2 -0
  22. package/dist/config/dist/src/index-captureOnlyOnError.test.d.ts +1 -0
  23. package/dist/config/dist/src/index-noSticky.test.d.ts +1 -0
  24. package/dist/config/dist/src/index-sampling.test.d.ts +1 -0
  25. package/dist/config/dist/src/index.d.ts +225 -0
  26. package/dist/config/dist/src/index.test.d.ts +1 -0
  27. package/dist/config/dist/src/session/Session.d.ts +63 -0
  28. package/dist/config/dist/src/session/Session.test.d.ts +1 -0
  29. package/dist/config/dist/src/session/constants.d.ts +5 -0
  30. package/dist/config/dist/src/session/createSession.d.ts +19 -0
  31. package/dist/config/dist/src/session/createSession.test.d.ts +1 -0
  32. package/dist/config/dist/src/session/fetchSession.d.ts +5 -0
  33. package/dist/config/dist/src/session/fetchSession.test.d.ts +1 -0
  34. package/dist/config/dist/src/session/getSession.d.ts +28 -0
  35. package/dist/config/dist/src/session/getSession.test.d.ts +1 -0
  36. package/dist/config/dist/src/session/index.d.ts +1 -0
  37. package/dist/config/dist/src/session/saveSession.d.ts +2 -0
  38. package/dist/config/dist/src/session/saveSession.test.d.ts +1 -0
  39. package/dist/config/dist/src/types.d.ts +90 -0
  40. package/dist/config/dist/src/util/createBreadcrumb.d.ts +4 -0
  41. package/dist/config/dist/src/util/createPayload.d.ts +5 -0
  42. package/dist/config/dist/src/util/isExpired.d.ts +5 -0
  43. package/dist/config/dist/src/util/isExpired.test.d.ts +1 -0
  44. package/dist/config/dist/src/util/isIngestHost.d.ts +4 -0
  45. package/dist/config/dist/src/util/isSampled.d.ts +7 -0
  46. package/dist/config/dist/src/util/isSampled.test.d.ts +1 -0
  47. package/dist/config/dist/src/util/isSessionExpired.d.ts +5 -0
  48. package/dist/config/dist/src/util/isSessionExpired.test.d.ts +1 -0
  49. package/dist/config/dist/src/util/logger.d.ts +12 -0
  50. package/dist/config/dist/src/util/supportsSendBeacon.d.ts +4 -0
  51. package/dist/config/dist/test/index.d.ts +3 -0
  52. package/dist/config/dist/test/mocks/mockRrweb.d.ts +15 -0
  53. package/dist/config/dist/test/mocks/mockSdk.d.ts +11 -0
  54. package/dist/dist/api/captureReplay.d.ts +5 -3
  55. package/dist/dist/api/captureReplayUpdate.d.ts +5 -3
  56. package/dist/dist/coreHandlers/getBreadcrumbHandler.d.ts +3 -0
  57. package/dist/dist/coreHandlers/getSpanHandler.d.ts +5 -0
  58. package/dist/dist/coreHandlers/handleFetch.d.ts +19 -2
  59. package/dist/dist/coreHandlers/handleHistory.d.ts +7 -0
  60. package/dist/dist/coreHandlers/handleXhr.d.ts +21 -2
  61. package/dist/dist/eventBuffer.d.ts +11 -4
  62. package/dist/dist/index.d.ts +26 -10
  63. package/dist/dist/types.d.ts +20 -8
  64. package/dist/index.es.js +329 -199
  65. package/dist/index.js +328 -198
  66. package/dist/index.js.map +1 -1
  67. package/package.json +1 -1
@@ -0,0 +1,2 @@
1
+ import { Session } from './Session';
2
+ export declare function saveSession(session: Session): void;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,90 @@
1
+ import { record } from 'rrweb';
2
+ import type { eventWithTime } from 'rrweb/typings/types';
3
+ export declare type RecordingEvent = eventWithTime;
4
+ export declare type RecordingConfig = Parameters<typeof record>[0];
5
+ export interface ReplayRequest {
6
+ endpoint: string;
7
+ events: Uint8Array | string;
8
+ }
9
+ export declare type InstrumentationTypeBreadcrumb = 'dom' | 'scope';
10
+ export declare type InstrumentationTypeSpan = 'fetch' | 'xhr' | 'history';
11
+ export declare type InstrumentationType = InstrumentationTypeBreadcrumb | InstrumentationTypeSpan | 'console' | 'error' | 'unhandledrejection';
12
+ /**
13
+ * The request payload to worker
14
+ */
15
+ export interface WorkerRequest {
16
+ id: number;
17
+ method: string;
18
+ args: any[];
19
+ }
20
+ /**
21
+ * The response from the worker
22
+ */
23
+ export interface WorkerResponse {
24
+ id: number;
25
+ method: string;
26
+ success: boolean;
27
+ response: string | Uint8Array;
28
+ }
29
+ export interface SentryReplayPluginOptions {
30
+ /**
31
+ * The amount of time to wait before sending a replay
32
+ */
33
+ flushMinDelay?: number;
34
+ /**
35
+ * The max amount of time to wait before sending a replay
36
+ */
37
+ flushMaxDelay?: number;
38
+ /**
39
+ * The amount of time to buffer the initial snapshot
40
+ */
41
+ initialFlushDelay?: number;
42
+ /**
43
+ * If false, will create a new session per pageload
44
+ */
45
+ stickySession?: boolean;
46
+ /**
47
+ * Attempt to use compression when web workers are available
48
+ *
49
+ * (default is true)
50
+ */
51
+ useCompression?: boolean;
52
+ /**
53
+ * Only capture replays when an error happens
54
+ */
55
+ captureOnlyOnError?: boolean;
56
+ /**
57
+ * The sampling rate for replays. 1.0 will record all replays, 0 will record none.
58
+ */
59
+ replaysSamplingRate?: number;
60
+ }
61
+ export interface SentryReplayConfiguration extends SentryReplayPluginOptions {
62
+ /**
63
+ * Options for `rrweb.record()`
64
+ */
65
+ recordingConfig?: RecordingConfig;
66
+ }
67
+ /**
68
+ * Some initial state captured before creating a root replay event
69
+ */
70
+ export interface InitialState {
71
+ timestamp: number;
72
+ url: string;
73
+ }
74
+ /**
75
+ * Additional context that will be sent w/ `replay_event`
76
+ */
77
+ export interface ReplayEventContext {
78
+ /**
79
+ * Set of Sentry error ids that have occurred during a replay segment
80
+ */
81
+ errorIds: Set<string>;
82
+ /**
83
+ * Set of Sentry trace ids that have occurred during a replay segment
84
+ */
85
+ traceIds: Set<string>;
86
+ /**
87
+ * Ordered list of URLs that have been visited during a replay segment
88
+ */
89
+ urls: string[];
90
+ }
@@ -0,0 +1,4 @@
1
+ import type { Breadcrumb } from '@sentry/types';
2
+ declare type RequiredProperties = 'category' | 'message';
3
+ export default function createBreadcrumb(breadcrumb: Pick<Breadcrumb, RequiredProperties> & Partial<Omit<Breadcrumb, RequiredProperties>>): Breadcrumb;
4
+ export {};
@@ -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;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Given an initial timestamp and an expiry duration, checks to see if current
3
+ * time should be considered as expired.
4
+ */
5
+ export declare function isExpired(initialTime: number, expiry: number, targetTime?: number): boolean;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Checks is `targetHost` is a Sentry ingestion host
3
+ */
4
+ export declare function isIngestHost(targetHost: string): boolean;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Given a sample rate, returns true if replay should be sampled.
3
+ *
4
+ * 1.0 = 100% sampling
5
+ * 0.0 = 0% sampling
6
+ */
7
+ export declare function isSampled(sampleRate: number): boolean;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import { Session } from '@/session/Session';
2
+ /**
3
+ * Checks to see if session is expired
4
+ */
5
+ export declare function isSessionExpired(session: Session, expiry: number, targetTime?: number): boolean;
@@ -0,0 +1,12 @@
1
+ declare const logger: {
2
+ error: (...args: any[]) => any;
3
+ warn: (...args: any[]) => any;
4
+ log: (...args: any[]) => any;
5
+ disable(): void;
6
+ enable(): void;
7
+ debug: (...args: unknown[]) => void;
8
+ info: (...args: unknown[]) => void;
9
+ assert: (...args: unknown[]) => void;
10
+ trace: (...args: unknown[]) => void;
11
+ };
12
+ export { logger };
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Determine if there is browser support for `navigator.sendBeacon`
3
+ */
4
+ export declare function supportsSendBeacon(): boolean;
@@ -0,0 +1,3 @@
1
+ export * from './mocks/mockRrweb';
2
+ export * from './mocks/mockSdk';
3
+ export declare const BASE_TIMESTAMP: number;
@@ -0,0 +1,15 @@
1
+ /// <reference types="jest" />
2
+ import { RecordingEvent } from '@/types';
3
+ declare type RecordAdditionalProperties = {
4
+ takeFullSnapshot: jest.Mock;
5
+ addCustomEvent: () => void;
6
+ freezePage: () => void;
7
+ mirror: unknown;
8
+ _emitter: (event: RecordingEvent, ...args: any[]) => void;
9
+ };
10
+ export declare type RecordMock = jest.MockedFunction<typeof rrweb.record> & RecordAdditionalProperties;
11
+ import * as rrweb from 'rrweb';
12
+ export declare function mockRrweb(): {
13
+ record: RecordMock;
14
+ };
15
+ export {};
@@ -0,0 +1,11 @@
1
+ import { BrowserOptions } from '@sentry/browser';
2
+ import { SentryReplay } from '@';
3
+ import { SentryReplayConfiguration } from '@/types';
4
+ interface MockSdkParams {
5
+ replayOptions?: SentryReplayConfiguration;
6
+ sentryOptions?: BrowserOptions;
7
+ }
8
+ export declare function mockSdk({ replayOptions, sentryOptions, }?: MockSdkParams): {
9
+ replay: SentryReplay;
10
+ };
11
+ export {};
@@ -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
1
  import { Breadcrumb, DsnComponents, 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, 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,6 +56,7 @@ 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
61
  static attachmentUrlFromDsn(dsn: DsnComponents, eventId: string): string;
63
62
  constructor({ flushMinDelay, flushMaxDelay, initialFlushDelay, stickySession, // TBD: Making this opt-in for now
@@ -141,10 +140,16 @@ export declare class SentryReplay implements Integration {
141
140
  /**
142
141
  * Handler for Sentry Core SDK events.
143
142
  *
144
- * Transforms core SDK events into replay events.
143
+ * These specific events will create span-like objects in the recording.
144
+ *
145
+ */
146
+ handleCoreSpanListener: (type: InstrumentationTypeSpan) => (handlerData: any) => void;
147
+ /**
148
+ * Handler for Sentry Core SDK events.
145
149
  *
150
+ * These events will create breadcrumb-like objects in the recording.
146
151
  */
147
- handleCoreListener: (type: InstrumentationType) => (handlerData: any) => void;
152
+ handleCoreBreadcrumbListener: (type: InstrumentationTypeBreadcrumb) => (handlerData: any) => void;
148
153
  /**
149
154
  * Keep a list of performance entries that will be sent with a replay
150
155
  */
@@ -171,14 +176,19 @@ export declare class SentryReplay implements Integration {
171
176
  */
172
177
  createCustomBreadcrumb(breadcrumb: Breadcrumb): void;
173
178
  /**
174
- * Create a span for each performance entry. The parent transaction is `this.replayEvent`.
179
+ * Create a "span" for each performance entry. The parent transaction is `this.replayEvent`.
175
180
  */
176
- createPerformanceSpans(entries: ReplayPerformanceEntry[]): void;
181
+ createPerformanceSpans(entries: ReplayPerformanceEntry[]): Promise<void[]>;
177
182
  /**
178
183
  * Observed performance events are added to `this.performanceEvents`. These
179
184
  * are included in the replay event before it is finished and sent to Sentry.
180
185
  */
181
- addPerformanceEntries(): void;
186
+ addPerformanceEntries(): Promise<void[]>;
187
+ /**
188
+ * Create a "span" for the total amount of memory being used by JS objects
189
+ * (including v8 internal objects).
190
+ */
191
+ addMemoryEntry(): Promise<void[]>;
182
192
  /**
183
193
  *
184
194
  *
@@ -189,6 +199,12 @@ export declare class SentryReplay implements Integration {
189
199
  * Only flush if `captureOnlyOnError` is false.
190
200
  */
191
201
  conditionalFlush(lastActivity?: number): Promise<void>;
202
+ /**
203
+ * Return and clear context
204
+ */
205
+ popEventContext({ timestamp, }: {
206
+ timestamp: number;
207
+ }): CaptureReplayParams & CaptureReplayUpdateParams;
192
208
  /**
193
209
  * Flushes replay event buffer to Sentry.
194
210
  *
@@ -2,18 +2,13 @@ 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
- }
12
5
  export interface ReplayRequest {
13
6
  endpoint: string;
14
7
  events: Uint8Array | string;
15
8
  }
16
- export declare type InstrumentationType = 'scope' | 'dom' | 'fetch' | 'xhr';
9
+ export declare type InstrumentationTypeBreadcrumb = 'dom' | 'scope';
10
+ export declare type InstrumentationTypeSpan = 'fetch' | 'xhr' | 'history';
11
+ export declare type InstrumentationType = InstrumentationTypeBreadcrumb | InstrumentationTypeSpan | 'console' | 'error' | 'unhandledrejection';
17
12
  /**
18
13
  * The request payload to worker
19
14
  */
@@ -76,3 +71,20 @@ export interface InitialState {
76
71
  timestamp: number;
77
72
  url: string;
78
73
  }
74
+ /**
75
+ * Additional context that will be sent w/ `replay_event`
76
+ */
77
+ export interface ReplayEventContext {
78
+ /**
79
+ * Set of Sentry error ids that have occurred during a replay segment
80
+ */
81
+ errorIds: Set<string>;
82
+ /**
83
+ * Set of Sentry trace ids that have occurred during a replay segment
84
+ */
85
+ traceIds: Set<string>;
86
+ /**
87
+ * Ordered list of URLs that have been visited during a replay segment
88
+ */
89
+ urls: string[];
90
+ }