@sentry/replay 0.5.17 → 0.5.19

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 (60) hide show
  1. package/README.md +12 -10
  2. package/dist/config/types/jest.config.d.ts +3 -0
  3. package/dist/config/types/jest.setup.d.ts +10 -0
  4. package/dist/config/types/src/api/captureReplayEvent.d.ts +37 -0
  5. package/dist/config/types/src/coreHandlers/getBreadcrumbHandler.d.ts +3 -0
  6. package/dist/config/types/src/coreHandlers/getSpanHandler.d.ts +5 -0
  7. package/dist/config/types/src/coreHandlers/handleDom.d.ts +1 -0
  8. package/dist/config/types/src/coreHandlers/handleFetch.d.ts +19 -0
  9. package/dist/config/types/src/coreHandlers/handleFetch.test.d.ts +1 -0
  10. package/dist/config/types/src/coreHandlers/handleHistory.d.ts +7 -0
  11. package/dist/config/types/src/coreHandlers/handleScope-unit.test.d.ts +1 -0
  12. package/dist/config/types/src/coreHandlers/handleScope.d.ts +2 -0
  13. package/dist/config/types/src/coreHandlers/handleScope.test.d.ts +1 -0
  14. package/dist/config/types/src/coreHandlers/handleXhr.d.ts +21 -0
  15. package/dist/config/types/src/createPerformanceEntry.d.ts +43 -0
  16. package/dist/config/types/src/createPerformanceEntry.test.d.ts +1 -0
  17. package/dist/config/types/src/eventBuffer.d.ts +45 -0
  18. package/dist/config/types/src/eventBuffer.test.d.ts +1 -0
  19. package/dist/config/types/src/flags.d.ts +2 -0
  20. package/dist/config/types/src/flush.test.d.ts +1 -0
  21. package/dist/config/types/src/index-captureOnlyOnError.test.d.ts +1 -0
  22. package/dist/config/types/src/index-noSticky.test.d.ts +1 -0
  23. package/dist/config/types/src/index-sampling.test.d.ts +1 -0
  24. package/dist/config/types/src/index.d.ts +253 -0
  25. package/dist/config/types/src/index.test.d.ts +1 -0
  26. package/dist/config/types/src/session/Session.d.ts +63 -0
  27. package/dist/config/types/src/session/Session.test.d.ts +1 -0
  28. package/dist/config/types/src/session/constants.d.ts +5 -0
  29. package/dist/config/types/src/session/createSession.d.ts +19 -0
  30. package/dist/config/types/src/session/createSession.test.d.ts +1 -0
  31. package/dist/config/types/src/session/deleteSession.d.ts +4 -0
  32. package/dist/config/types/src/session/deleteSession.test.d.ts +1 -0
  33. package/dist/config/types/src/session/fetchSession.d.ts +5 -0
  34. package/dist/config/types/src/session/fetchSession.test.d.ts +1 -0
  35. package/dist/config/types/src/session/getSession.d.ts +28 -0
  36. package/dist/config/types/src/session/getSession.test.d.ts +1 -0
  37. package/dist/config/types/src/session/index.d.ts +1 -0
  38. package/dist/config/types/src/session/saveSession.d.ts +2 -0
  39. package/dist/config/types/src/session/saveSession.test.d.ts +1 -0
  40. package/dist/config/types/src/stop.test.d.ts +1 -0
  41. package/dist/config/types/src/types.d.ts +102 -0
  42. package/dist/config/types/src/util/createBreadcrumb.d.ts +4 -0
  43. package/dist/config/types/src/util/createPayload.d.ts +5 -0
  44. package/dist/config/types/src/util/isExpired.d.ts +5 -0
  45. package/dist/config/types/src/util/isExpired.test.d.ts +1 -0
  46. package/dist/config/types/src/util/isIngestHost.d.ts +4 -0
  47. package/dist/config/types/src/util/isSampled.d.ts +7 -0
  48. package/dist/config/types/src/util/isSampled.test.d.ts +1 -0
  49. package/dist/config/types/src/util/isSessionExpired.d.ts +5 -0
  50. package/dist/config/types/src/util/isSessionExpired.test.d.ts +1 -0
  51. package/dist/config/types/src/util/logger.d.ts +12 -0
  52. package/dist/config/types/test/index.d.ts +3 -0
  53. package/dist/config/types/test/mocks/mockRrweb.d.ts +15 -0
  54. package/dist/config/types/test/mocks/mockSdk.d.ts +11 -0
  55. package/dist/index.es.js +11 -4
  56. package/dist/index.js +11 -4
  57. package/dist/index.js.map +1 -1
  58. package/dist/types/src/index.d.ts +3 -3
  59. package/dist/types/src/types.d.ts +4 -0
  60. package/package.json +1 -1
@@ -0,0 +1,5 @@
1
+ import { Session } from './Session';
2
+ /**
3
+ * Fetches a session from storage
4
+ */
5
+ export declare function fetchSession(): Session | null;
@@ -0,0 +1,28 @@
1
+ import { Session } from './Session';
2
+ interface GetSessionParams {
3
+ /**
4
+ * The length of time (in ms) which we will consider the session to be expired.
5
+ */
6
+ expiry: number;
7
+ /**
8
+ * Should save session to sessionStorage?
9
+ */
10
+ stickySession: boolean;
11
+ /**
12
+ * The current session (e.g. if stickySession is off)
13
+ */
14
+ currentSession?: Session;
15
+ /**
16
+ * The sampling rate of the Session. See integration configuration comments
17
+ * for `replaysSamplingRate`.
18
+ */
19
+ samplingRate?: number;
20
+ }
21
+ /**
22
+ * Get or create a session
23
+ */
24
+ export declare function getSession({ expiry, currentSession, stickySession, samplingRate, }: GetSessionParams): {
25
+ type: string;
26
+ session: Session;
27
+ };
28
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export * from './createSession';
@@ -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,102 @@
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 declare type RecordedEvents = Uint8Array | string;
6
+ export declare type AllPerformanceEntry = PerformancePaintTiming | PerformanceResourceTiming | PerformanceNavigationTiming;
7
+ export interface ReplayRequest {
8
+ endpoint: string;
9
+ events: RecordedEvents;
10
+ replayId: string;
11
+ segmentId: number;
12
+ }
13
+ export declare type InstrumentationTypeBreadcrumb = 'dom' | 'scope';
14
+ export declare type InstrumentationTypeSpan = 'fetch' | 'xhr' | 'history';
15
+ export declare type InstrumentationType = InstrumentationTypeBreadcrumb | InstrumentationTypeSpan | 'console' | 'error' | 'unhandledrejection';
16
+ /**
17
+ * The request payload to worker
18
+ */
19
+ export interface WorkerRequest {
20
+ id: number;
21
+ method: string;
22
+ args: any[];
23
+ }
24
+ /**
25
+ * The response from the worker
26
+ */
27
+ export interface WorkerResponse {
28
+ id: number;
29
+ method: string;
30
+ success: boolean;
31
+ response: string | Uint8Array;
32
+ }
33
+ export interface SentryReplayPluginOptions {
34
+ /**
35
+ * The amount of time to wait before sending a replay
36
+ */
37
+ flushMinDelay?: number;
38
+ /**
39
+ * The max amount of time to wait before sending a replay
40
+ */
41
+ flushMaxDelay?: number;
42
+ /**
43
+ * The amount of time to buffer the initial snapshot
44
+ */
45
+ initialFlushDelay?: number;
46
+ /**
47
+ * If false, will create a new session per pageload
48
+ */
49
+ stickySession?: boolean;
50
+ /**
51
+ * Attempt to use compression when web workers are available
52
+ *
53
+ * (default is true)
54
+ */
55
+ useCompression?: boolean;
56
+ /**
57
+ * Only capture replays when an error happens
58
+ */
59
+ captureOnlyOnError?: boolean;
60
+ /**
61
+ * The sampling rate for replays. 1.0 will record all replays, 0 will record none.
62
+ */
63
+ replaysSamplingRate?: number;
64
+ /**
65
+ * Mask all text in recordings. All text will be replaced with asterisks by default.
66
+ */
67
+ maskAllText?: boolean;
68
+ }
69
+ export interface SentryReplayConfiguration extends SentryReplayPluginOptions {
70
+ /**
71
+ * Options for `rrweb.record()`
72
+ */
73
+ recordingConfig?: RecordingConfig;
74
+ }
75
+ /**
76
+ * Some initial state captured before creating a root replay event
77
+ */
78
+ export interface InitialState {
79
+ timestamp: number;
80
+ url: string;
81
+ }
82
+ /**
83
+ * Additional context that will be sent w/ `replay_event`
84
+ */
85
+ export interface ReplayEventContext {
86
+ /**
87
+ * Set of Sentry error ids that have occurred during a replay segment
88
+ */
89
+ errorIds: Set<string>;
90
+ /**
91
+ * Set of Sentry trace ids that have occurred during a replay segment
92
+ */
93
+ traceIds: Set<string>;
94
+ /**
95
+ * Ordered list of URLs that have been visited during a replay segment
96
+ */
97
+ urls: string[];
98
+ /**
99
+ * The timestamp of the earliest event that has been added to event buffer. This can happen due to the Performance Observer which buffers events.
100
+ */
101
+ earliestEvent: number | null;
102
+ }
@@ -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: null | number, expiry: undefined | 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,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 {};
package/dist/index.es.js CHANGED
@@ -797,7 +797,7 @@ var SentryReplay = /** @class */ (function () {
797
797
  function SentryReplay(_a) {
798
798
  if (_a === void 0) { _a = {}; }
799
799
  var _this = this;
800
- var _b = _a.flushMinDelay, flushMinDelay = _b === void 0 ? 5000 : _b, _c = _a.flushMaxDelay, flushMaxDelay = _c === void 0 ? 15000 : _c, _d = _a.initialFlushDelay, initialFlushDelay = _d === void 0 ? 5000 : _d, _e = _a.stickySession, stickySession = _e === void 0 ? true : _e, _f = _a.useCompression, useCompression = _f === void 0 ? true : _f, _g = _a.captureOnlyOnError, captureOnlyOnError = _g === void 0 ? false : _g, _h = _a.replaysSamplingRate, replaysSamplingRate = _h === void 0 ? 1.0 : _h, _j = _a.recordingConfig, _k = _j === void 0 ? {} : _j, _l = _k.maskAllInputs, maskAllInputs = _l === void 0 ? true : _l, _m = _k.blockClass, blockClass = _m === void 0 ? 'sr-block' : _m, _o = _k.ignoreClass, ignoreClass = _o === void 0 ? 'sr-ignore' : _o, _p = _k.maskTextClass, maskTextClass = _p === void 0 ? 'sr-mask' : _p, recordingOptions = __rest(_k, ["maskAllInputs", "blockClass", "ignoreClass", "maskTextClass"]);
800
+ var _b = _a.flushMinDelay, flushMinDelay = _b === void 0 ? 5000 : _b, _c = _a.flushMaxDelay, flushMaxDelay = _c === void 0 ? 15000 : _c, _d = _a.initialFlushDelay, initialFlushDelay = _d === void 0 ? 5000 : _d, _e = _a.stickySession, stickySession = _e === void 0 ? true : _e, _f = _a.useCompression, useCompression = _f === void 0 ? true : _f, _g = _a.captureOnlyOnError, captureOnlyOnError = _g === void 0 ? false : _g, _h = _a.replaysSamplingRate, replaysSamplingRate = _h === void 0 ? 1.0 : _h, _j = _a.maskAllText, maskAllText = _j === void 0 ? false : _j, _k = _a.recordingConfig, _l = _k === void 0 ? {} : _k, _m = _l.maskAllInputs, maskAllInputs = _m === void 0 ? true : _m, _o = _l.blockClass, blockClass = _o === void 0 ? 'sentry-block' : _o, _p = _l.ignoreClass, ignoreClass = _p === void 0 ? 'sentry-ignore' : _p, _q = _l.maskTextClass, maskTextClass = _q === void 0 ? 'sentry-mask' : _q, recordingOptions = __rest(_l, ["maskAllInputs", "blockClass", "ignoreClass", "maskTextClass"]);
801
801
  /**
802
802
  * @inheritDoc
803
803
  */
@@ -1089,12 +1089,19 @@ var SentryReplay = /** @class */ (function () {
1089
1089
  captureOnlyOnError: captureOnlyOnError,
1090
1090
  replaysSamplingRate: replaysSamplingRate,
1091
1091
  useCompression: useCompression,
1092
+ maskAllText: maskAllText,
1092
1093
  };
1093
1094
  // Modify rrweb options to checkoutEveryNthSecond if this is defined, as we don't know when an error occurs, so we want to try to minimize the number of events captured.
1094
1095
  if (this.options.captureOnlyOnError) {
1095
1096
  // Checkout every minute, meaning we only get up-to one minute of events before the error happens
1096
1097
  this.recordingOptions.checkoutEveryNms = 60000;
1097
1098
  }
1099
+ if (this.options.maskAllText) {
1100
+ // `maskAllText` is a more user friendly option to configure
1101
+ // `maskTextSelector`. This means that all nodes will have their text
1102
+ // content masked.
1103
+ this.recordingOptions.maskTextSelector = '*';
1104
+ }
1098
1105
  }
1099
1106
  /**
1100
1107
  * Because we create a transaction in `setupOnce`, we can potentially create a
@@ -1108,14 +1115,14 @@ var SentryReplay = /** @class */ (function () {
1108
1115
  SentryReplay.prototype.setupOnce = function () {
1109
1116
  var _this = this;
1110
1117
  // XXX: See method comments above
1111
- window.setTimeout(function () { return _this.setup(); });
1118
+ window.setTimeout(function () { return _this.start(); });
1112
1119
  };
1113
1120
  /**
1114
1121
  * Initializes the plugin.
1115
1122
  *
1116
1123
  * Creates or loads a session, attaches listeners to varying events (DOM, PerformanceObserver, Recording, Sentry SDK, etc)
1117
1124
  */
1118
- SentryReplay.prototype.setup = function () {
1125
+ SentryReplay.prototype.start = function () {
1119
1126
  this.loadSession({ expiry: SESSION_IDLE_DURATION });
1120
1127
  // If there is no session, then something bad has happened - can't continue
1121
1128
  if (!this.session) {
@@ -1190,7 +1197,7 @@ var SentryReplay = /** @class */ (function () {
1190
1197
  /**
1191
1198
  * Currently, this needs to be manually called (e.g. for tests). Sentry SDK does not support a teardown
1192
1199
  */
1193
- SentryReplay.prototype.destroy = function () {
1200
+ SentryReplay.prototype.stop = function () {
1194
1201
  var _a, _b;
1195
1202
  logger.log('Stopping Replays');
1196
1203
  this.isEnabled = false;
package/dist/index.js CHANGED
@@ -805,7 +805,7 @@ var SentryReplay = /** @class */ (function () {
805
805
  function SentryReplay(_a) {
806
806
  if (_a === void 0) { _a = {}; }
807
807
  var _this = this;
808
- var _b = _a.flushMinDelay, flushMinDelay = _b === void 0 ? 5000 : _b, _c = _a.flushMaxDelay, flushMaxDelay = _c === void 0 ? 15000 : _c, _d = _a.initialFlushDelay, initialFlushDelay = _d === void 0 ? 5000 : _d, _e = _a.stickySession, stickySession = _e === void 0 ? true : _e, _f = _a.useCompression, useCompression = _f === void 0 ? true : _f, _g = _a.captureOnlyOnError, captureOnlyOnError = _g === void 0 ? false : _g, _h = _a.replaysSamplingRate, replaysSamplingRate = _h === void 0 ? 1.0 : _h, _j = _a.recordingConfig, _k = _j === void 0 ? {} : _j, _l = _k.maskAllInputs, maskAllInputs = _l === void 0 ? true : _l, _m = _k.blockClass, blockClass = _m === void 0 ? 'sr-block' : _m, _o = _k.ignoreClass, ignoreClass = _o === void 0 ? 'sr-ignore' : _o, _p = _k.maskTextClass, maskTextClass = _p === void 0 ? 'sr-mask' : _p, recordingOptions = __rest(_k, ["maskAllInputs", "blockClass", "ignoreClass", "maskTextClass"]);
808
+ var _b = _a.flushMinDelay, flushMinDelay = _b === void 0 ? 5000 : _b, _c = _a.flushMaxDelay, flushMaxDelay = _c === void 0 ? 15000 : _c, _d = _a.initialFlushDelay, initialFlushDelay = _d === void 0 ? 5000 : _d, _e = _a.stickySession, stickySession = _e === void 0 ? true : _e, _f = _a.useCompression, useCompression = _f === void 0 ? true : _f, _g = _a.captureOnlyOnError, captureOnlyOnError = _g === void 0 ? false : _g, _h = _a.replaysSamplingRate, replaysSamplingRate = _h === void 0 ? 1.0 : _h, _j = _a.maskAllText, maskAllText = _j === void 0 ? false : _j, _k = _a.recordingConfig, _l = _k === void 0 ? {} : _k, _m = _l.maskAllInputs, maskAllInputs = _m === void 0 ? true : _m, _o = _l.blockClass, blockClass = _o === void 0 ? 'sentry-block' : _o, _p = _l.ignoreClass, ignoreClass = _p === void 0 ? 'sentry-ignore' : _p, _q = _l.maskTextClass, maskTextClass = _q === void 0 ? 'sentry-mask' : _q, recordingOptions = __rest(_l, ["maskAllInputs", "blockClass", "ignoreClass", "maskTextClass"]);
809
809
  /**
810
810
  * @inheritDoc
811
811
  */
@@ -1097,12 +1097,19 @@ var SentryReplay = /** @class */ (function () {
1097
1097
  captureOnlyOnError: captureOnlyOnError,
1098
1098
  replaysSamplingRate: replaysSamplingRate,
1099
1099
  useCompression: useCompression,
1100
+ maskAllText: maskAllText,
1100
1101
  };
1101
1102
  // Modify rrweb options to checkoutEveryNthSecond if this is defined, as we don't know when an error occurs, so we want to try to minimize the number of events captured.
1102
1103
  if (this.options.captureOnlyOnError) {
1103
1104
  // Checkout every minute, meaning we only get up-to one minute of events before the error happens
1104
1105
  this.recordingOptions.checkoutEveryNms = 60000;
1105
1106
  }
1107
+ if (this.options.maskAllText) {
1108
+ // `maskAllText` is a more user friendly option to configure
1109
+ // `maskTextSelector`. This means that all nodes will have their text
1110
+ // content masked.
1111
+ this.recordingOptions.maskTextSelector = '*';
1112
+ }
1106
1113
  }
1107
1114
  /**
1108
1115
  * Because we create a transaction in `setupOnce`, we can potentially create a
@@ -1116,14 +1123,14 @@ var SentryReplay = /** @class */ (function () {
1116
1123
  SentryReplay.prototype.setupOnce = function () {
1117
1124
  var _this = this;
1118
1125
  // XXX: See method comments above
1119
- window.setTimeout(function () { return _this.setup(); });
1126
+ window.setTimeout(function () { return _this.start(); });
1120
1127
  };
1121
1128
  /**
1122
1129
  * Initializes the plugin.
1123
1130
  *
1124
1131
  * Creates or loads a session, attaches listeners to varying events (DOM, PerformanceObserver, Recording, Sentry SDK, etc)
1125
1132
  */
1126
- SentryReplay.prototype.setup = function () {
1133
+ SentryReplay.prototype.start = function () {
1127
1134
  this.loadSession({ expiry: SESSION_IDLE_DURATION });
1128
1135
  // If there is no session, then something bad has happened - can't continue
1129
1136
  if (!this.session) {
@@ -1198,7 +1205,7 @@ var SentryReplay = /** @class */ (function () {
1198
1205
  /**
1199
1206
  * Currently, this needs to be manually called (e.g. for tests). Sentry SDK does not support a teardown
1200
1207
  */
1201
- SentryReplay.prototype.destroy = function () {
1208
+ SentryReplay.prototype.stop = function () {
1202
1209
  var _a, _b;
1203
1210
  logger.log('Stopping Replays');
1204
1211
  this.isEnabled = false;