@sentry/replay 7.24.2 → 7.25.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 (179) hide show
  1. package/README.md +1 -2
  2. package/cjs/_virtual/_commonjsHelpers.js +42 -0
  3. package/cjs/_virtual/_commonjsHelpers.js.map +1 -0
  4. package/cjs/constants.js +8 -0
  5. package/cjs/constants.js.map +1 -1
  6. package/cjs/coreHandlers/breadcrumbHandler.js.map +1 -1
  7. package/cjs/coreHandlers/handleFetch.js +33 -6
  8. package/cjs/coreHandlers/handleFetch.js.map +1 -1
  9. package/cjs/coreHandlers/handleGlobalEvent.js +91 -0
  10. package/cjs/coreHandlers/handleGlobalEvent.js.map +1 -0
  11. package/cjs/coreHandlers/handleHistory.js +30 -1
  12. package/cjs/coreHandlers/handleHistory.js.map +1 -1
  13. package/cjs/coreHandlers/handleScope.js +4 -12
  14. package/cjs/coreHandlers/handleScope.js.map +1 -1
  15. package/cjs/coreHandlers/handleXhr.js +33 -4
  16. package/cjs/coreHandlers/handleXhr.js.map +1 -1
  17. package/cjs/coreHandlers/performanceObserver.js +47 -0
  18. package/cjs/coreHandlers/performanceObserver.js.map +1 -0
  19. package/cjs/createPerformanceEntry.js +0 -6
  20. package/cjs/createPerformanceEntry.js.map +1 -1
  21. package/cjs/eventBuffer.js.map +1 -1
  22. package/cjs/integration.js +13 -10
  23. package/cjs/integration.js.map +1 -1
  24. package/cjs/node_modules/lodash.debounce/index.js +384 -0
  25. package/cjs/node_modules/lodash.debounce/index.js.map +1 -0
  26. package/cjs/replay.js +198 -412
  27. package/cjs/replay.js.map +1 -1
  28. package/cjs/session/Session.js.map +1 -1
  29. package/cjs/session/createSession.js.map +1 -1
  30. package/cjs/session/fetchSession.js.map +1 -1
  31. package/cjs/session/getSession.js.map +1 -1
  32. package/cjs/session/saveSession.js.map +1 -1
  33. package/cjs/util/addEvent.js +47 -0
  34. package/cjs/util/addEvent.js.map +1 -0
  35. package/cjs/util/addMemoryEntry.js +23 -0
  36. package/cjs/util/addMemoryEntry.js.map +1 -0
  37. package/cjs/util/createPayload.js.map +1 -1
  38. package/cjs/util/createPerformanceSpans.js +30 -0
  39. package/cjs/util/createPerformanceSpans.js.map +1 -0
  40. package/cjs/util/createReplayEnvelope.js +34 -0
  41. package/cjs/util/createReplayEnvelope.js.map +1 -0
  42. package/cjs/util/getReplayEvent.js +32 -0
  43. package/cjs/util/getReplayEvent.js.map +1 -0
  44. package/cjs/util/isSessionExpired.js.map +1 -1
  45. package/cjs/util/monkeyPatchRecordDroppedEvent.js +44 -0
  46. package/cjs/util/monkeyPatchRecordDroppedEvent.js.map +1 -0
  47. package/cjs/util/shouldFilterRequest.js +30 -0
  48. package/cjs/util/shouldFilterRequest.js.map +1 -0
  49. package/esm/_virtual/_commonjsHelpers.js +35 -0
  50. package/esm/_virtual/_commonjsHelpers.js.map +1 -0
  51. package/esm/constants.js +7 -1
  52. package/esm/constants.js.map +1 -1
  53. package/esm/coreHandlers/breadcrumbHandler.js.map +1 -1
  54. package/esm/coreHandlers/handleFetch.js +33 -7
  55. package/esm/coreHandlers/handleFetch.js.map +1 -1
  56. package/esm/coreHandlers/handleGlobalEvent.js +86 -0
  57. package/esm/coreHandlers/handleGlobalEvent.js.map +1 -0
  58. package/esm/coreHandlers/handleHistory.js +30 -1
  59. package/esm/coreHandlers/handleHistory.js.map +1 -1
  60. package/esm/coreHandlers/handleScope.js +4 -9
  61. package/esm/coreHandlers/handleScope.js.map +1 -1
  62. package/esm/coreHandlers/handleXhr.js +33 -4
  63. package/esm/coreHandlers/handleXhr.js.map +1 -1
  64. package/esm/coreHandlers/performanceObserver.js +45 -0
  65. package/esm/coreHandlers/performanceObserver.js.map +1 -0
  66. package/esm/createPerformanceEntry.js +0 -6
  67. package/esm/createPerformanceEntry.js.map +1 -1
  68. package/esm/eventBuffer.js.map +1 -1
  69. package/esm/integration.js +13 -10
  70. package/esm/integration.js.map +1 -1
  71. package/esm/node_modules/lodash.debounce/index.js +382 -0
  72. package/esm/node_modules/lodash.debounce/index.js.map +1 -0
  73. package/esm/replay.js +197 -411
  74. package/esm/replay.js.map +1 -1
  75. package/esm/session/Session.js.map +1 -1
  76. package/esm/session/createSession.js.map +1 -1
  77. package/esm/session/fetchSession.js.map +1 -1
  78. package/esm/session/getSession.js.map +1 -1
  79. package/esm/session/saveSession.js.map +1 -1
  80. package/esm/util/addEvent.js +42 -0
  81. package/esm/util/addEvent.js.map +1 -0
  82. package/esm/util/addMemoryEntry.js +21 -0
  83. package/esm/util/addMemoryEntry.js.map +1 -0
  84. package/esm/util/createPayload.js.map +1 -1
  85. package/esm/util/createPerformanceSpans.js +28 -0
  86. package/esm/util/createPerformanceSpans.js.map +1 -0
  87. package/esm/util/createReplayEnvelope.js +32 -0
  88. package/esm/util/createReplayEnvelope.js.map +1 -0
  89. package/esm/util/getReplayEvent.js +30 -0
  90. package/esm/util/getReplayEvent.js.map +1 -0
  91. package/esm/util/isSessionExpired.js.map +1 -1
  92. package/esm/util/monkeyPatchRecordDroppedEvent.js +41 -0
  93. package/esm/util/monkeyPatchRecordDroppedEvent.js.map +1 -0
  94. package/esm/util/shouldFilterRequest.js +25 -0
  95. package/esm/util/shouldFilterRequest.js.map +1 -0
  96. package/package.json +7 -8
  97. package/types/constants.d.ts +5 -0
  98. package/types/constants.d.ts.map +1 -1
  99. package/types/coreHandlers/breadcrumbHandler.d.ts +1 -1
  100. package/types/coreHandlers/breadcrumbHandler.d.ts.map +1 -1
  101. package/types/coreHandlers/handleFetch.d.ts +9 -2
  102. package/types/coreHandlers/handleFetch.d.ts.map +1 -1
  103. package/types/coreHandlers/handleGlobalEvent.d.ts +7 -0
  104. package/types/coreHandlers/handleGlobalEvent.d.ts.map +1 -0
  105. package/types/coreHandlers/handleHistory.d.ts +7 -3
  106. package/types/coreHandlers/handleHistory.d.ts.map +1 -1
  107. package/types/coreHandlers/handleScope.d.ts.map +1 -1
  108. package/types/coreHandlers/handleXhr.d.ts +6 -3
  109. package/types/coreHandlers/handleXhr.d.ts.map +1 -1
  110. package/types/coreHandlers/performanceObserver.d.ts +6 -0
  111. package/types/coreHandlers/performanceObserver.d.ts.map +1 -0
  112. package/types/createPerformanceEntry.d.ts +1 -1
  113. package/types/createPerformanceEntry.d.ts.map +1 -1
  114. package/types/eventBuffer.d.ts +1 -7
  115. package/types/eventBuffer.d.ts.map +1 -1
  116. package/types/integration.d.ts +3 -3
  117. package/types/integration.d.ts.map +1 -1
  118. package/types/replay.d.ts +30 -59
  119. package/types/replay.d.ts.map +1 -1
  120. package/types/session/Session.d.ts +1 -26
  121. package/types/session/Session.d.ts.map +1 -1
  122. package/types/session/createSession.d.ts +1 -2
  123. package/types/session/createSession.d.ts.map +1 -1
  124. package/types/session/fetchSession.d.ts +1 -1
  125. package/types/session/fetchSession.d.ts.map +1 -1
  126. package/types/session/getSession.d.ts +1 -2
  127. package/types/session/getSession.d.ts.map +1 -1
  128. package/types/session/saveSession.d.ts +1 -1
  129. package/types/session/saveSession.d.ts.map +1 -1
  130. package/types/types.d.ts +63 -2
  131. package/types/types.d.ts.map +1 -1
  132. package/types/util/addEvent.d.ts +6 -0
  133. package/types/util/addEvent.d.ts.map +1 -0
  134. package/types/util/addMemoryEntry.d.ts +7 -0
  135. package/types/util/addMemoryEntry.d.ts.map +1 -0
  136. package/types/util/createPayload.d.ts +1 -1
  137. package/types/util/createPayload.d.ts.map +1 -1
  138. package/types/util/createPerformanceSpans.d.ts +7 -0
  139. package/types/util/createPerformanceSpans.d.ts.map +1 -0
  140. package/types/util/createReplayEnvelope.d.ts +3 -0
  141. package/types/util/createReplayEnvelope.d.ts.map +1 -0
  142. package/types/util/getReplayEvent.d.ts +9 -0
  143. package/types/util/getReplayEvent.d.ts.map +1 -0
  144. package/types/util/isSessionExpired.d.ts +1 -1
  145. package/types/util/isSessionExpired.d.ts.map +1 -1
  146. package/types/util/monkeyPatchRecordDroppedEvent.d.ts +3 -0
  147. package/types/util/monkeyPatchRecordDroppedEvent.d.ts.map +1 -0
  148. package/types/util/shouldFilterRequest.d.ts +6 -0
  149. package/types/util/shouldFilterRequest.d.ts.map +1 -0
  150. package/cjs/coreHandlers/spanHandler.js +0 -20
  151. package/cjs/coreHandlers/spanHandler.js.map +0 -1
  152. package/cjs/util/addInternalBreadcrumb.js +0 -25
  153. package/cjs/util/addInternalBreadcrumb.js.map +0 -1
  154. package/cjs/util/captureInternalException.js +0 -18
  155. package/cjs/util/captureInternalException.js.map +0 -1
  156. package/cjs/util/isIngestHost.js +0 -26
  157. package/cjs/util/isIngestHost.js.map +0 -1
  158. package/cjs/util/isInternal.js +0 -15
  159. package/cjs/util/isInternal.js.map +0 -1
  160. package/esm/coreHandlers/spanHandler.js +0 -18
  161. package/esm/coreHandlers/spanHandler.js.map +0 -1
  162. package/esm/util/addInternalBreadcrumb.js +0 -23
  163. package/esm/util/addInternalBreadcrumb.js.map +0 -1
  164. package/esm/util/captureInternalException.js +0 -16
  165. package/esm/util/captureInternalException.js.map +0 -1
  166. package/esm/util/isIngestHost.js +0 -21
  167. package/esm/util/isIngestHost.js.map +0 -1
  168. package/esm/util/isInternal.js +0 -13
  169. package/esm/util/isInternal.js.map +0 -1
  170. package/types/coreHandlers/spanHandler.d.ts +0 -4
  171. package/types/coreHandlers/spanHandler.d.ts.map +0 -1
  172. package/types/util/addInternalBreadcrumb.d.ts +0 -6
  173. package/types/util/addInternalBreadcrumb.d.ts.map +0 -1
  174. package/types/util/captureInternalException.d.ts +0 -5
  175. package/types/util/captureInternalException.d.ts.map +0 -1
  176. package/types/util/isIngestHost.d.ts +0 -5
  177. package/types/util/isIngestHost.d.ts.map +0 -1
  178. package/types/util/isInternal.d.ts +0 -6
  179. package/types/util/isInternal.d.ts.map +0 -1
package/esm/replay.js CHANGED
@@ -1,23 +1,30 @@
1
1
  import { _optionalChain } from '@sentry/utils/esm/buildPolyfills';
2
- import { getCurrentHub, addGlobalEventProcessor, setContext } from '@sentry/core';
3
- import { logger, addInstrumentationHandler, createEnvelope } from '@sentry/utils';
4
- import debounce from 'lodash.debounce';
2
+ import { captureException, getCurrentHub, addGlobalEventProcessor, setContext } from '@sentry/core';
3
+ import { logger, addInstrumentationHandler } from '@sentry/utils';
4
+ import lodash_debounce from './node_modules/lodash.debounce/index.js';
5
5
  import './node_modules/rrweb/es/rrweb/packages/rrweb/src/entries/all.js';
6
- import { SESSION_IDLE_DURATION, WINDOW, REPLAY_EVENT_NAME, VISIBILITY_CHANGE_TIMEOUT, MAX_SESSION_LIFE } from './constants.js';
6
+ import { SESSION_IDLE_DURATION, WINDOW, VISIBILITY_CHANGE_TIMEOUT, MAX_SESSION_LIFE, REPLAY_EVENT_NAME, UNABLE_TO_SEND_REPLAY } from './constants.js';
7
7
  import { breadcrumbHandler } from './coreHandlers/breadcrumbHandler.js';
8
- import { spanHandler } from './coreHandlers/spanHandler.js';
9
- import { createPerformanceEntries, createMemoryEntry } from './createPerformanceEntry.js';
8
+ import { handleFetchSpanListener } from './coreHandlers/handleFetch.js';
9
+ import { handleGlobalEventListener } from './coreHandlers/handleGlobalEvent.js';
10
+ import { handleHistorySpanListener } from './coreHandlers/handleHistory.js';
11
+ import { handleXhrSpanListener } from './coreHandlers/handleXhr.js';
12
+ import { setupPerformanceObserver } from './coreHandlers/performanceObserver.js';
13
+ import { createPerformanceEntries } from './createPerformanceEntry.js';
10
14
  import { createEventBuffer } from './eventBuffer.js';
11
15
  import { deleteSession } from './session/deleteSession.js';
12
16
  import { getSession } from './session/getSession.js';
13
17
  import { saveSession } from './session/saveSession.js';
14
- import { addInternalBreadcrumb } from './util/addInternalBreadcrumb.js';
15
- import { captureInternalException } from './util/captureInternalException.js';
18
+ import { addEvent } from './util/addEvent.js';
19
+ import { addMemoryEntry } from './util/addMemoryEntry.js';
16
20
  import { createBreadcrumb } from './util/createBreadcrumb.js';
17
21
  import { createPayload } from './util/createPayload.js';
18
- import { dedupePerformanceEntries } from './util/dedupePerformanceEntries.js';
22
+ import { createPerformanceSpans } from './util/createPerformanceSpans.js';
23
+ import { createReplayEnvelope } from './util/createReplayEnvelope.js';
24
+ import { getReplayEvent } from './util/getReplayEvent.js';
19
25
  import { isExpired } from './util/isExpired.js';
20
26
  import { isSessionExpired } from './util/isSessionExpired.js';
27
+ import { overwriteRecordDroppedEvent, restoreRecordDroppedEvent } from './util/monkeyPatchRecordDroppedEvent.js';
21
28
  import record from './node_modules/rrweb/es/rrweb/packages/rrweb/src/record/index.js';
22
29
  import { EventType } from './node_modules/rrweb/es/rrweb/packages/rrweb/src/types.js';
23
30
 
@@ -29,9 +36,8 @@ import { EventType } from './node_modules/rrweb/es/rrweb/packages/rrweb/src/type
29
36
 
30
37
  const BASE_RETRY_INTERVAL = 5000;
31
38
  const MAX_RETRY_COUNT = 3;
32
- const UNABLE_TO_SEND_REPLAY = 'Unable to send Replay';
33
39
 
34
- class ReplayContainer {
40
+ class ReplayContainer {
35
41
  __init() {this.eventBuffer = null;}
36
42
 
37
43
  /**
@@ -39,39 +45,40 @@ class ReplayContainer {
39
45
  */
40
46
  __init2() {this.performanceEvents = [];}
41
47
 
48
+ /**
49
+ * Recording can happen in one of two modes:
50
+ * * session: Record the whole session, sending it continuously
51
+ * * error: Always keep the last 60s of recording, and when an error occurs, send it immediately
52
+ */
53
+ __init3() {this.recordingMode = 'session';}
54
+
42
55
  /**
43
56
  * Options to pass to `rrweb.record()`
44
57
  */
45
58
 
46
- __init3() {this._performanceObserver = null;}
59
+ __init4() {this._performanceObserver = null;}
47
60
 
48
- __init4() {this._retryCount = 0;}
49
- __init5() {this._retryInterval = BASE_RETRY_INTERVAL;}
61
+ __init5() {this._retryCount = 0;}
62
+ __init6() {this._retryInterval = BASE_RETRY_INTERVAL;}
50
63
 
51
- __init6() {this._flushLock = null;}
64
+ __init7() {this._flushLock = null;}
52
65
 
53
66
  /**
54
67
  * Timestamp of the last user activity. This lives across sessions.
55
68
  */
56
- __init7() {this._lastActivity = new Date().getTime();}
69
+ __init8() {this._lastActivity = new Date().getTime();}
57
70
 
58
71
  /**
59
72
  * Is the integration currently active?
60
73
  */
61
- __init8() {this._isEnabled = false;}
74
+ __init9() {this._isEnabled = false;}
62
75
 
63
76
  /**
64
77
  * Paused is a state where:
65
78
  * - DOM Recording is not listening at all
66
79
  * - Nothing will be added to event buffer (e.g. core SDK events)
67
80
  */
68
- __init9() {this._isPaused = false;}
69
-
70
- /**
71
- * Integration will wait until an error occurs before creating and sending a
72
- * replay.
73
- */
74
- __init10() {this._waitForError = false;}
81
+ __init10() {this._isPaused = false;}
75
82
 
76
83
  /**
77
84
  * Have we attached listeners to the core SDK?
@@ -84,10 +91,6 @@ class ReplayContainer {
84
91
  */
85
92
  __init12() {this._stopRecording = null;}
86
93
 
87
- /**
88
- * We overwrite `client.recordDroppedEvent`, but store the original method here so we can restore it.
89
- */
90
-
91
94
  __init13() {this._context = {
92
95
  errorIds: new Set(),
93
96
  traceIds: new Set(),
@@ -97,15 +100,35 @@ class ReplayContainer {
97
100
  initialUrl: '',
98
101
  };}
99
102
 
100
- constructor({ options, recordingOptions }) {;ReplayContainer.prototype.__init.call(this);ReplayContainer.prototype.__init2.call(this);ReplayContainer.prototype.__init3.call(this);ReplayContainer.prototype.__init4.call(this);ReplayContainer.prototype.__init5.call(this);ReplayContainer.prototype.__init6.call(this);ReplayContainer.prototype.__init7.call(this);ReplayContainer.prototype.__init8.call(this);ReplayContainer.prototype.__init9.call(this);ReplayContainer.prototype.__init10.call(this);ReplayContainer.prototype.__init11.call(this);ReplayContainer.prototype.__init12.call(this);ReplayContainer.prototype.__init13.call(this);ReplayContainer.prototype.__init14.call(this);ReplayContainer.prototype.__init15.call(this);ReplayContainer.prototype.__init16.call(this);ReplayContainer.prototype.__init17.call(this);ReplayContainer.prototype.__init18.call(this);ReplayContainer.prototype.__init19.call(this);ReplayContainer.prototype.__init20.call(this);ReplayContainer.prototype.__init21.call(this);ReplayContainer.prototype.__init22.call(this);
101
- this.recordingOptions = recordingOptions;
102
- this.options = options;
103
+ constructor({ options, recordingOptions }) {;ReplayContainer.prototype.__init.call(this);ReplayContainer.prototype.__init2.call(this);ReplayContainer.prototype.__init3.call(this);ReplayContainer.prototype.__init4.call(this);ReplayContainer.prototype.__init5.call(this);ReplayContainer.prototype.__init6.call(this);ReplayContainer.prototype.__init7.call(this);ReplayContainer.prototype.__init8.call(this);ReplayContainer.prototype.__init9.call(this);ReplayContainer.prototype.__init10.call(this);ReplayContainer.prototype.__init11.call(this);ReplayContainer.prototype.__init12.call(this);ReplayContainer.prototype.__init13.call(this);ReplayContainer.prototype.__init14.call(this);ReplayContainer.prototype.__init15.call(this);ReplayContainer.prototype.__init16.call(this);ReplayContainer.prototype.__init17.call(this);ReplayContainer.prototype.__init18.call(this);ReplayContainer.prototype.__init19.call(this);
104
+ this._recordingOptions = recordingOptions;
105
+ this._options = options;
103
106
 
104
- this._debouncedFlush = debounce(() => this.flush(), this.options.flushMinDelay, {
105
- maxWait: this.options.flushMaxDelay,
107
+ this._debouncedFlush = lodash_debounce(() => this.flush(), this._options.flushMinDelay, {
108
+ maxWait: this._options.flushMaxDelay,
106
109
  });
107
110
  }
108
111
 
112
+ /** Get the event context. */
113
+ getContext() {
114
+ return this._context;
115
+ }
116
+
117
+ /** If recording is currently enabled. */
118
+ isEnabled() {
119
+ return this._isEnabled;
120
+ }
121
+
122
+ /** If recording is currently paused. */
123
+ isPaused() {
124
+ return this._isPaused;
125
+ }
126
+
127
+ /** Get the replay integration options. */
128
+ getOptions() {
129
+ return this._options;
130
+ }
131
+
109
132
  /**
110
133
  * Initializes the plugin.
111
134
  *
@@ -119,7 +142,7 @@ class ReplayContainer {
119
142
 
120
143
  // If there is no session, then something bad has happened - can't continue
121
144
  if (!this.session) {
122
- captureInternalException(new Error('Invalid session'));
145
+ this.handleException(new Error('No session found'));
123
146
  return;
124
147
  }
125
148
 
@@ -133,7 +156,7 @@ class ReplayContainer {
133
156
  // when an error will occur, so we need to keep a buffer of
134
157
  // replay events.
135
158
  if (this.session.sampled === 'error') {
136
- this._waitForError = true;
159
+ this.recordingMode = 'error';
137
160
  }
138
161
 
139
162
  // setup() is generally called on page load or manually - in both cases we
@@ -141,7 +164,7 @@ class ReplayContainer {
141
164
  this.updateSessionActivity();
142
165
 
143
166
  this.eventBuffer = createEventBuffer({
144
- useCompression: Boolean(this.options.useCompression),
167
+ useCompression: Boolean(this._options.useCompression),
145
168
  });
146
169
 
147
170
  this.addListeners();
@@ -159,19 +182,31 @@ class ReplayContainer {
159
182
  startRecording() {
160
183
  try {
161
184
  this._stopRecording = record({
162
- ...this.recordingOptions,
185
+ ...this._recordingOptions,
163
186
  // When running in error sampling mode, we need to overwrite `checkoutEveryNth`
164
187
  // Without this, it would record forever, until an error happens, which we don't want
165
188
  // instead, we'll always keep the last 60 seconds of replay before an error happened
166
- ...(this._waitForError && { checkoutEveryNth: 60000 }),
189
+ ...(this.recordingMode === 'error' && { checkoutEveryNth: 60000 }),
167
190
  emit: this.handleRecordingEmit,
168
191
  });
169
192
  } catch (err) {
170
- (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error('[Replay]', err);
171
- captureInternalException(err);
193
+ this.handleException(err);
172
194
  }
173
195
  }
174
196
 
197
+ /**
198
+ * Stops the recording, if it was running.
199
+ * Returns true if it was stopped, else false.
200
+ */
201
+ stopRecording() {
202
+ if (this._stopRecording) {
203
+ this._stopRecording();
204
+ return true;
205
+ }
206
+
207
+ return false;
208
+ }
209
+
175
210
  /**
176
211
  * Currently, this needs to be manually called (e.g. for tests). Sentry SDK
177
212
  * does not support a teardown
@@ -181,12 +216,11 @@ class ReplayContainer {
181
216
  (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.log('[Replay] Stopping Replays');
182
217
  this._isEnabled = false;
183
218
  this.removeListeners();
184
- _optionalChain([this, 'access', _21 => _21._stopRecording, 'optionalCall', _22 => _22()]);
185
- _optionalChain([this, 'access', _23 => _23.eventBuffer, 'optionalAccess', _24 => _24.destroy, 'call', _25 => _25()]);
219
+ _optionalChain([this, 'access', _11 => _11._stopRecording, 'optionalCall', _12 => _12()]);
220
+ _optionalChain([this, 'access', _13 => _13.eventBuffer, 'optionalAccess', _14 => _14.destroy, 'call', _15 => _15()]);
186
221
  this.eventBuffer = null;
187
222
  } catch (err) {
188
- (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error('[Replay]', err);
189
- captureInternalException(err);
223
+ this.handleException(err);
190
224
  }
191
225
  }
192
226
 
@@ -203,8 +237,7 @@ class ReplayContainer {
203
237
  this._stopRecording = undefined;
204
238
  }
205
239
  } catch (err) {
206
- (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error('[Replay]', err);
207
- captureInternalException(err);
240
+ this.handleException(err);
208
241
  }
209
242
  }
210
243
 
@@ -219,14 +252,22 @@ class ReplayContainer {
219
252
  this.startRecording();
220
253
  }
221
254
 
255
+ /** A wrapper to conditionally capture exceptions. */
256
+ handleException(error) {
257
+ (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error('[Replay]', error);
258
+
259
+ if ((typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && this._options._experiments && this._options._experiments.captureExceptions) {
260
+ captureException(error);
261
+ }
262
+ }
263
+
222
264
  /** for tests only */
223
265
  clearSession() {
224
266
  try {
225
267
  deleteSession();
226
268
  this.session = undefined;
227
269
  } catch (err) {
228
- (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error('[Replay]', err);
229
- captureInternalException(err);
270
+ this.handleException(err);
230
271
  }
231
272
  }
232
273
 
@@ -237,10 +278,10 @@ class ReplayContainer {
237
278
  loadSession({ expiry }) {
238
279
  const { type, session } = getSession({
239
280
  expiry,
240
- stickySession: Boolean(this.options.stickySession),
281
+ stickySession: Boolean(this._options.stickySession),
241
282
  currentSession: this.session,
242
- sessionSampleRate: this.options.sessionSampleRate,
243
- errorSampleRate: this.options.errorSampleRate,
283
+ sessionSampleRate: this._options.sessionSampleRate,
284
+ errorSampleRate: this._options.errorSampleRate,
244
285
  });
245
286
 
246
287
  // If session was newly created (i.e. was not loaded from storage), then
@@ -249,8 +290,8 @@ class ReplayContainer {
249
290
  this.setInitialState();
250
291
  }
251
292
 
252
- if (session.id !== _optionalChain([this, 'access', _26 => _26.session, 'optionalAccess', _27 => _27.id])) {
253
- session.previousSessionId = _optionalChain([this, 'access', _28 => _28.session, 'optionalAccess', _29 => _29.id]);
293
+ if (session.id !== _optionalChain([this, 'access', _16 => _16.session, 'optionalAccess', _17 => _17.id])) {
294
+ session.previousSessionId = _optionalChain([this, 'access', _18 => _18.session, 'optionalAccess', _19 => _19.id]);
254
295
  }
255
296
 
256
297
  this.session = session;
@@ -285,27 +326,26 @@ class ReplayContainer {
285
326
  WINDOW.addEventListener('focus', this.handleWindowFocus);
286
327
 
287
328
  // We need to filter out dropped events captured by `addGlobalEventProcessor(this.handleGlobalEvent)` below
288
- this._overwriteRecordDroppedEvent();
329
+ overwriteRecordDroppedEvent(this._context.errorIds);
289
330
 
290
331
  // There is no way to remove these listeners, so ensure they are only added once
291
332
  if (!this._hasInitializedCoreListeners) {
292
333
  // Listeners from core SDK //
293
334
  const scope = getCurrentHub().getScope();
294
- _optionalChain([scope, 'optionalAccess', _30 => _30.addScopeListener, 'call', _31 => _31(this.handleCoreBreadcrumbListener('scope'))]);
335
+ _optionalChain([scope, 'optionalAccess', _20 => _20.addScopeListener, 'call', _21 => _21(this.handleCoreBreadcrumbListener('scope'))]);
295
336
  addInstrumentationHandler('dom', this.handleCoreBreadcrumbListener('dom'));
296
- addInstrumentationHandler('fetch', this.handleCoreSpanListener('fetch'));
297
- addInstrumentationHandler('xhr', this.handleCoreSpanListener('xhr'));
298
- addInstrumentationHandler('history', this.handleCoreSpanListener('history'));
337
+ addInstrumentationHandler('fetch', handleFetchSpanListener(this));
338
+ addInstrumentationHandler('xhr', handleXhrSpanListener(this));
339
+ addInstrumentationHandler('history', handleHistorySpanListener(this));
299
340
 
300
341
  // Tag all (non replay) events that get sent to Sentry with the current
301
342
  // replay ID so that we can reference them later in the UI
302
- addGlobalEventProcessor(this.handleGlobalEvent);
343
+ addGlobalEventProcessor(handleGlobalEventListener(this));
303
344
 
304
345
  this._hasInitializedCoreListeners = true;
305
346
  }
306
347
  } catch (err) {
307
- (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error('[Replay]', err);
308
- captureInternalException(err);
348
+ this.handleException(err);
309
349
  }
310
350
 
311
351
  // _performanceObserver //
@@ -313,30 +353,7 @@ class ReplayContainer {
313
353
  return;
314
354
  }
315
355
 
316
- this._performanceObserver = new PerformanceObserver(this.handle_performanceObserver);
317
-
318
- // Observe almost everything for now (no mark/measure)
319
- [
320
- 'element',
321
- 'event',
322
- 'first-input',
323
- 'largest-contentful-paint',
324
- 'layout-shift',
325
- 'longtask',
326
- 'navigation',
327
- 'paint',
328
- 'resource',
329
- ].forEach(type => {
330
- try {
331
- _optionalChain([this, 'access', _32 => _32._performanceObserver, 'optionalAccess', _33 => _33.observe, 'call', _34 => _34({
332
- type,
333
- buffered: true,
334
- })]);
335
- } catch (e) {
336
- // This can throw if an entry type is not supported in the browser.
337
- // Ignore these errors.
338
- }
339
- });
356
+ this._performanceObserver = setupPerformanceObserver(this);
340
357
  }
341
358
 
342
359
  /**
@@ -349,15 +366,14 @@ class ReplayContainer {
349
366
  WINDOW.removeEventListener('blur', this.handleWindowBlur);
350
367
  WINDOW.removeEventListener('focus', this.handleWindowFocus);
351
368
 
352
- this._restoreRecordDroppedEvent();
369
+ restoreRecordDroppedEvent();
353
370
 
354
371
  if (this._performanceObserver) {
355
372
  this._performanceObserver.disconnect();
356
373
  this._performanceObserver = null;
357
374
  }
358
375
  } catch (err) {
359
- (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error('[Replay]', err);
360
- captureInternalException(err);
376
+ this.handleException(err);
361
377
  }
362
378
  }
363
379
 
@@ -370,12 +386,12 @@ class ReplayContainer {
370
386
  * processing and hand back control to caller.
371
387
  */
372
388
  addUpdate(cb) {
373
- // We need to always run `cb` (e.g. in the case of `this._waitForError == true`)
374
- const cbResult = _optionalChain([cb, 'optionalCall', _35 => _35()]);
389
+ // We need to always run `cb` (e.g. in the case of `this.recordingMode == 'error'`)
390
+ const cbResult = _optionalChain([cb, 'optionalCall', _22 => _22()]);
375
391
 
376
392
  // If this option is turned on then we will only want to call `flush`
377
393
  // explicitly
378
- if (this._waitForError) {
394
+ if (this.recordingMode === 'error') {
379
395
  return;
380
396
  }
381
397
 
@@ -390,78 +406,12 @@ class ReplayContainer {
390
406
  this._debouncedFlush();
391
407
  }
392
408
 
393
- /**
394
- * Core Sentry SDK global event handler. Attaches `replayId` to all [non-replay]
395
- * events as a tag. Also handles the case where we only want to capture a reply
396
- * when an error occurs.
397
- **/
398
- __init14() {this.handleGlobalEvent = (event) => {
399
- // Do not apply replayId to the root event
400
- if (
401
- // @ts-ignore new event type
402
- event.type === REPLAY_EVENT_NAME
403
- ) {
404
- // Replays have separate set of breadcrumbs, do not include breadcrumbs
405
- // from core SDK
406
- delete event.breadcrumbs;
407
- return event;
408
- }
409
-
410
- // Only tag transactions with replayId if not waiting for an error
411
- if (event.type !== 'transaction' || !this._waitForError) {
412
- event.tags = { ...event.tags, replayId: _optionalChain([this, 'access', _36 => _36.session, 'optionalAccess', _37 => _37.id]) };
413
- }
414
-
415
- // Collect traceIds in _context regardless of `_waitForError` - if it's true,
416
- // _context gets cleared on every checkout
417
- if (event.type === 'transaction') {
418
- this._context.traceIds.add(String(_optionalChain([event, 'access', _38 => _38.contexts, 'optionalAccess', _39 => _39.trace, 'optionalAccess', _40 => _40.trace_id]) || ''));
419
- return event;
420
- }
421
-
422
- // XXX: Is it safe to assume that all other events are error events?
423
- // @ts-ignore: Type 'undefined' is not assignable to type 'string'.ts(2345)
424
- this._context.errorIds.add(event.event_id);
425
-
426
- const exc = _optionalChain([event, 'access', _41 => _41.exception, 'optionalAccess', _42 => _42.values, 'optionalAccess', _43 => _43[0]]);
427
- addInternalBreadcrumb({
428
- message: `Tagging event (${event.event_id}) - ${event.message} - ${_optionalChain([exc, 'optionalAccess', _44 => _44.type]) || 'Unknown'}: ${
429
- _optionalChain([exc, 'optionalAccess', _45 => _45.value]) || 'n/a'
430
- }`,
431
- });
432
-
433
- // Need to be very careful that this does not cause an infinite loop
434
- if (
435
- this._waitForError &&
436
- event.exception &&
437
- event.message !== UNABLE_TO_SEND_REPLAY // ignore this error because otherwise we could loop indefinitely with trying to capture replay and failing
438
- ) {
439
- setTimeout(async () => {
440
- // Allow flush to complete before resuming as a session recording, otherwise
441
- // the checkout from `startRecording` may be included in the payload.
442
- // Prefer to keep the error replay as a separate (and smaller) segment
443
- // than the session replay.
444
- await this.flushImmediate();
445
-
446
- if (this._stopRecording) {
447
- this._stopRecording();
448
- // Reset all "capture on error" configuration before
449
- // starting a new recording
450
- this._waitForError = false;
451
- this.startRecording();
452
- }
453
- });
454
- }
455
-
456
- return event;
457
- };}
458
-
459
409
  /**
460
410
  * Handler for recording events.
461
411
  *
462
412
  * Adds to event buffer, and has varying flushing behaviors if the event was a checkout.
463
413
  */
464
- __init15() {this.handleRecordingEmit = (
414
+ __init14() {this.handleRecordingEmit = (
465
415
  event,
466
416
  isCheckout,
467
417
  ) => {
@@ -478,13 +428,13 @@ class ReplayContainer {
478
428
  // when an error occurs. Clear any state that happens before this current
479
429
  // checkout. This needs to happen before `addEvent()` which updates state
480
430
  // dependent on this reset.
481
- if (this._waitForError && event.type === 2) {
431
+ if (this.recordingMode === 'error' && event.type === 2) {
482
432
  this.setInitialState();
483
433
  }
484
434
 
485
435
  // We need to clear existing events on a checkout, otherwise they are
486
436
  // incremental event updates and should be appended
487
- this.addEvent(event, isCheckout);
437
+ addEvent(this, event, isCheckout);
488
438
 
489
439
  // Different behavior for full snapshots (type=2), ignore other event types
490
440
  // See https://github.com/rrweb-io/rrweb/blob/d8f9290ca496712aa1e7d472549480c4e7876594/packages/rrweb/src/types.ts#L16
@@ -498,13 +448,13 @@ class ReplayContainer {
498
448
  // of the previous session. Do not immediately flush in this case
499
449
  // to avoid capturing only the checkout and instead the replay will
500
450
  // be captured if they perform any follow-up actions.
501
- if (_optionalChain([this, 'access', _46 => _46.session, 'optionalAccess', _47 => _47.previousSessionId])) {
451
+ if (_optionalChain([this, 'access', _23 => _23.session, 'optionalAccess', _24 => _24.previousSessionId])) {
502
452
  return true;
503
453
  }
504
454
 
505
455
  // See note above re: session start needs to reflect the most recent
506
456
  // checkout.
507
- if (this._waitForError && this.session && this._context.earliestEvent) {
457
+ if (this.recordingMode === 'error' && this.session && this._context.earliestEvent) {
508
458
  this.session.started = this._context.earliestEvent;
509
459
  this._maybeSaveSession();
510
460
  }
@@ -513,7 +463,7 @@ class ReplayContainer {
513
463
  // a previous session ID. In this case, we want to buffer events
514
464
  // for a set amount of time before flushing. This can help avoid
515
465
  // capturing replays of users that immediately close the window.
516
- setTimeout(() => this.conditionalFlush(), this.options.initialFlushDelay);
466
+ setTimeout(() => this.conditionalFlush(), this._options.initialFlushDelay);
517
467
 
518
468
  // Cancel any previously debounced flushes to ensure there are no [near]
519
469
  // simultaneous flushes happening. The latter request should be
@@ -523,7 +473,7 @@ class ReplayContainer {
523
473
  // This can happen because there's no guarantee that a recording event
524
474
  // happens first. e.g. a mouse click can happen and trigger a debounced
525
475
  // flush before the checkout.
526
- _optionalChain([this, 'access', _48 => _48._debouncedFlush, 'optionalAccess', _49 => _49.cancel, 'call', _50 => _50()]);
476
+ _optionalChain([this, 'access', _25 => _25._debouncedFlush, 'optionalAccess', _26 => _26.cancel, 'call', _27 => _27()]);
527
477
 
528
478
  return true;
529
479
  });
@@ -535,7 +485,7 @@ class ReplayContainer {
535
485
  * be hidden. Likewise, moving a different window to cover the contents of the
536
486
  * page will also trigger a change to a hidden state.
537
487
  */
538
- __init16() {this.handleVisibilityChange = () => {
488
+ __init15() {this.handleVisibilityChange = () => {
539
489
  if (WINDOW.document.visibilityState === 'visible') {
540
490
  this.doChangeToForegroundTasks();
541
491
  } else {
@@ -546,7 +496,7 @@ class ReplayContainer {
546
496
  /**
547
497
  * Handle when page is blurred
548
498
  */
549
- __init17() {this.handleWindowBlur = () => {
499
+ __init16() {this.handleWindowBlur = () => {
550
500
  const breadcrumb = createBreadcrumb({
551
501
  category: 'ui.blur',
552
502
  });
@@ -559,7 +509,7 @@ class ReplayContainer {
559
509
  /**
560
510
  * Handle when page is focused
561
511
  */
562
- __init18() {this.handleWindowFocus = () => {
512
+ __init17() {this.handleWindowFocus = () => {
563
513
  const breadcrumb = createBreadcrumb({
564
514
  category: 'ui.focus',
565
515
  });
@@ -569,45 +519,12 @@ class ReplayContainer {
569
519
  this.doChangeToForegroundTasks(breadcrumb);
570
520
  };}
571
521
 
572
- /**
573
- * Handler for Sentry Core SDK events.
574
- *
575
- * These specific events will create span-like objects in the recording.
576
- */
577
- __init19() {this.handleCoreSpanListener =
578
- (type) =>
579
- (handlerData) => {
580
- if (!this._isEnabled) {
581
- return;
582
- }
583
-
584
- const result = spanHandler(type, handlerData);
585
-
586
- if (result === null) {
587
- return;
588
- }
589
-
590
- if (type === 'history') {
591
- // Need to collect visited URLs
592
- this._context.urls.push(result.name);
593
- this.triggerUserActivity();
594
- }
595
-
596
- this.addUpdate(() => {
597
- void this.createPerformanceSpans([result ]);
598
- // Returning true will cause `addUpdate` to not flush
599
- // We do not want network requests to cause a flush. This will prevent
600
- // recurring/polling requests from keeping the replay session alive.
601
- return ['xhr', 'fetch'].includes(type);
602
- });
603
- };}
604
-
605
522
  /**
606
523
  * Handler for Sentry Core SDK events.
607
524
  *
608
525
  * These events will create breadcrumb-like objects in the recording.
609
526
  */
610
- __init20() {this.handleCoreBreadcrumbListener =
527
+ __init18() {this.handleCoreBreadcrumbListener =
611
528
  (type) =>
612
529
  (handlerData) => {
613
530
  if (!this._isEnabled) {
@@ -631,7 +548,7 @@ class ReplayContainer {
631
548
  }
632
549
 
633
550
  this.addUpdate(() => {
634
- this.addEvent({
551
+ addEvent(this, {
635
552
  type: EventType.Custom,
636
553
  // TODO: We were converting from ms to seconds for breadcrumbs, spans,
637
554
  // but maybe we should just keep them as milliseconds
@@ -647,19 +564,6 @@ class ReplayContainer {
647
564
  });
648
565
  };}
649
566
 
650
- /**
651
- * Keep a list of performance entries that will be sent with a replay
652
- */
653
- __init21() {this.handle_performanceObserver = (list) => {
654
- // For whatever reason the observer was returning duplicate navigation
655
- // entries (the other entry types were not duplicated).
656
- const newPerformanceEntries = dedupePerformanceEntries(
657
- this.performanceEvents,
658
- list.getEntries() ,
659
- );
660
- this.performanceEvents = newPerformanceEntries;
661
- };}
662
-
663
567
  /**
664
568
  * Tasks to run when we consider a page to be hidden (via blurring and/or visibility)
665
569
  */
@@ -714,45 +618,6 @@ class ReplayContainer {
714
618
  record.takeFullSnapshot(true);
715
619
  }
716
620
 
717
- /**
718
- * Add an event to the event buffer
719
- */
720
- addEvent(event, isCheckout) {
721
- if (!this.eventBuffer) {
722
- // This implies that `_isEnabled` is false
723
- return;
724
- }
725
-
726
- if (this._isPaused) {
727
- // Do not add to event buffer when recording is paused
728
- return;
729
- }
730
-
731
- // TODO: sadness -- we will want to normalize timestamps to be in ms -
732
- // requires coordination with frontend
733
- const isMs = event.timestamp > 9999999999;
734
- const timestampInMs = isMs ? event.timestamp : event.timestamp * 1000;
735
-
736
- // Throw out events that happen more than 5 minutes ago. This can happen if
737
- // page has been left open and idle for a long period of time and user
738
- // comes back to trigger a new session. The performance entries rely on
739
- // `performance.timeOrigin`, which is when the page first opened.
740
- if (timestampInMs + SESSION_IDLE_DURATION < new Date().getTime()) {
741
- return;
742
- }
743
-
744
- // Only record earliest event if a new session was created, otherwise it
745
- // shouldn't be relevant
746
- if (
747
- _optionalChain([this, 'access', _51 => _51.session, 'optionalAccess', _52 => _52.segmentId]) === 0 &&
748
- (!this._context.earliestEvent || timestampInMs < this._context.earliestEvent)
749
- ) {
750
- this._context.earliestEvent = timestampInMs;
751
- }
752
-
753
- this.eventBuffer.addEvent(event, isCheckout);
754
- }
755
-
756
621
  /**
757
622
  * Update user activity (across session lifespans)
758
623
  */
@@ -801,7 +666,7 @@ class ReplayContainer {
801
666
  */
802
667
  createCustomBreadcrumb(breadcrumb) {
803
668
  this.addUpdate(() => {
804
- this.addEvent({
669
+ addEvent(this, {
805
670
  type: EventType.Custom,
806
671
  timestamp: breadcrumb.timestamp || 0,
807
672
  data: {
@@ -812,30 +677,6 @@ class ReplayContainer {
812
677
  });
813
678
  }
814
679
 
815
- /**
816
- * Create a "span" for each performance entry. The parent transaction is `this.replayEvent`.
817
- */
818
- createPerformanceSpans(entries) {
819
- return Promise.all(
820
- entries.map(({ type, start, end, name, data }) =>
821
- this.addEvent({
822
- type: EventType.Custom,
823
- timestamp: start,
824
- data: {
825
- tag: 'performanceSpan',
826
- payload: {
827
- op: type,
828
- description: name,
829
- startTimestamp: start,
830
- endTimestamp: end,
831
- data,
832
- },
833
- },
834
- }),
835
- ),
836
- );
837
- }
838
-
839
680
  /**
840
681
  * Observed performance events are added to `this.performanceEvents`. These
841
682
  * are included in the replay event before it is finished and sent to Sentry.
@@ -845,24 +686,7 @@ class ReplayContainer {
845
686
  const entries = [...this.performanceEvents];
846
687
  this.performanceEvents = [];
847
688
 
848
- return this.createPerformanceSpans(createPerformanceEntries(entries));
849
- }
850
-
851
- /**
852
- * Create a "span" for the total amount of memory being used by JS objects
853
- * (including v8 internal objects).
854
- */
855
- addMemoryEntry() {
856
- // window.performance.memory is a non-standard API and doesn't work on all browsers
857
- // so we check before creating the event.
858
- if (!('memory' in WINDOW.performance)) {
859
- return;
860
- }
861
-
862
- return this.createPerformanceSpans([
863
- // @ts-ignore memory doesn't exist on type Performance as the API is non-standard (we check that it exists above)
864
- createMemoryEntry(WINDOW.performance.memory),
865
- ]);
689
+ createPerformanceSpans(this, createPerformanceEntries(entries));
866
690
  }
867
691
 
868
692
  /**
@@ -873,7 +697,7 @@ class ReplayContainer {
873
697
  * Returns true if session is not expired, false otherwise.
874
698
  */
875
699
  checkAndHandleExpiredSession({ expiry = SESSION_IDLE_DURATION } = {}) {
876
- const oldSessionId = _optionalChain([this, 'access', _53 => _53.session, 'optionalAccess', _54 => _54.id]);
700
+ const oldSessionId = _optionalChain([this, 'access', _28 => _28.session, 'optionalAccess', _29 => _29.id]);
877
701
 
878
702
  // Prevent starting a new session if the last user activity is older than
879
703
  // MAX_SESSION_LIFE. Otherwise non-user activity can trigger a new
@@ -890,7 +714,7 @@ class ReplayContainer {
890
714
  this.loadSession({ expiry });
891
715
 
892
716
  // Session was expired if session ids do not match
893
- const expired = oldSessionId !== _optionalChain([this, 'access', _55 => _55.session, 'optionalAccess', _56 => _56.id]);
717
+ const expired = oldSessionId !== _optionalChain([this, 'access', _30 => _30.session, 'optionalAccess', _31 => _31.id]);
894
718
 
895
719
  if (!expired) {
896
720
  return true;
@@ -903,10 +727,10 @@ class ReplayContainer {
903
727
  }
904
728
 
905
729
  /**
906
- * Only flush if `this._waitForError` is false.
730
+ * Only flush if `this.recordingMode === 'session'`
907
731
  */
908
732
  conditionalFlush() {
909
- if (this._waitForError) {
733
+ if (this.recordingMode === 'error') {
910
734
  return;
911
735
  }
912
736
 
@@ -961,12 +785,12 @@ class ReplayContainer {
961
785
 
962
786
  await this.addPerformanceEntries();
963
787
 
964
- if (!_optionalChain([this, 'access', _57 => _57.eventBuffer, 'optionalAccess', _58 => _58.length])) {
788
+ if (!_optionalChain([this, 'access', _32 => _32.eventBuffer, 'optionalAccess', _33 => _33.length])) {
965
789
  return;
966
790
  }
967
791
 
968
792
  // Only attach memory event if eventBuffer is not empty
969
- await this.addMemoryEntry();
793
+ await addMemoryEntry(this);
970
794
 
971
795
  try {
972
796
  // Note this empties the event buffer regardless of outcome of sending replay
@@ -988,8 +812,7 @@ class ReplayContainer {
988
812
  eventContext,
989
813
  });
990
814
  } catch (err) {
991
- (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error(err);
992
- captureInternalException(err);
815
+ this.handleException(err);
993
816
  }
994
817
  }
995
818
 
@@ -997,7 +820,7 @@ class ReplayContainer {
997
820
  * Flush recording data to Sentry. Creates a lock so that only a single flush
998
821
  * can be active at a time. Do not call this directly.
999
822
  */
1000
- __init22() {this.flush = async () => {
823
+ __init19() {this.flush = async () => {
1001
824
  if (!this._isEnabled) {
1002
825
  // This is just a precaution, there should be no listeners that would
1003
826
  // cause a flush.
@@ -1009,13 +832,13 @@ class ReplayContainer {
1009
832
  return;
1010
833
  }
1011
834
 
1012
- if (!_optionalChain([this, 'access', _59 => _59.session, 'optionalAccess', _60 => _60.id])) {
835
+ if (!_optionalChain([this, 'access', _34 => _34.session, 'optionalAccess', _35 => _35.id])) {
1013
836
  (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error('[Replay] No session found to flush.');
1014
837
  return;
1015
838
  }
1016
839
 
1017
840
  // A flush is about to happen, cancel any queued flushes
1018
- _optionalChain([this, 'access', _61 => _61._debouncedFlush, 'optionalAccess', _62 => _62.cancel, 'call', _63 => _63()]);
841
+ _optionalChain([this, 'access', _36 => _36._debouncedFlush, 'optionalAccess', _37 => _37.cancel, 'call', _38 => _38()]);
1019
842
 
1020
843
  // No existing flush in progress, proceed with flushing.
1021
844
  // this._flushLock acts as a lock so that future calls to `flush()`
@@ -1059,7 +882,7 @@ class ReplayContainer {
1059
882
  */
1060
883
  async sendReplayRequest({
1061
884
  events,
1062
- replayId: event_id,
885
+ replayId,
1063
886
  segmentId: segment_id,
1064
887
  includeReplayStartTimestamp,
1065
888
  eventContext,
@@ -1075,78 +898,77 @@ class ReplayContainer {
1075
898
 
1076
899
  const currentTimestamp = new Date().getTime();
1077
900
 
1078
- const sdkInfo = {
1079
- name: 'sentry.javascript.integration.replay',
1080
- version: "7.24.2",
1081
- };
901
+ const hub = getCurrentHub();
902
+ const client = hub.getClient();
903
+ const scope = hub.getScope();
904
+ const transport = client && client.getTransport();
1082
905
 
1083
- const replayEvent = await new Promise(resolve => {
1084
- _optionalChain([getCurrentHub, 'call', _64 => _64()
1085
-
1086
- , 'optionalAccess', _65 => _65._withClient, 'call', _66 => _66(async (client, scope) => {
1087
- // XXX: This event does not trigger `beforeSend` in SDK
1088
- // @ts-ignore private api
1089
- const preparedEvent = await client._prepareEvent(
1090
- {
1091
- type: REPLAY_EVENT_NAME,
1092
- ...(includeReplayStartTimestamp ? { replay_start_timestamp: initialTimestamp / 1000 } : {}),
1093
- timestamp: currentTimestamp / 1000,
1094
- error_ids: errorIds,
1095
- trace_ids: traceIds,
1096
- urls,
1097
- replay_id: event_id,
1098
- segment_id,
1099
- },
1100
- { event_id },
1101
- scope,
1102
- );
1103
- const session = scope && scope.getSession();
1104
- if (session) {
1105
- // @ts-ignore private api
1106
- client._updateSessionFromEvent(session, preparedEvent);
1107
- }
906
+ if (!client || !scope || !transport) {
907
+ return;
908
+ }
1108
909
 
1109
- preparedEvent.sdk = {
1110
- ...preparedEvent.sdk,
1111
- ...sdkInfo,
1112
- };
910
+ const baseEvent = {
911
+ // @ts-ignore private api
912
+ type: REPLAY_EVENT_NAME,
913
+ ...(includeReplayStartTimestamp ? { replay_start_timestamp: initialTimestamp / 1000 } : {}),
914
+ timestamp: currentTimestamp / 1000,
915
+ error_ids: errorIds,
916
+ trace_ids: traceIds,
917
+ urls,
918
+ replay_id: replayId,
919
+ segment_id,
920
+ };
1113
921
 
1114
- preparedEvent.tags = {
1115
- ...preparedEvent.tags,
1116
- sessionSampleRate: this.options.sessionSampleRate,
1117
- errorSampleRate: this.options.errorSampleRate,
1118
- replayType: _optionalChain([this, 'access', _67 => _67.session, 'optionalAccess', _68 => _68.sampled]),
1119
- };
922
+ const replayEvent = await getReplayEvent({ scope, client, replayId, event: baseEvent });
1120
923
 
1121
- resolve(preparedEvent);
1122
- })]);
1123
- });
924
+ replayEvent.tags = {
925
+ ...replayEvent.tags,
926
+ sessionSampleRate: this._options.sessionSampleRate,
927
+ errorSampleRate: this._options.errorSampleRate,
928
+ replayType: _optionalChain([this, 'access', _39 => _39.session, 'optionalAccess', _40 => _40.sampled]),
929
+ };
1124
930
 
1125
- const envelope = createEnvelope(
1126
- {
1127
- event_id,
1128
- sent_at: new Date().toISOString(),
1129
- sdk: sdkInfo,
1130
- },
1131
- [
1132
- // @ts-ignore New types
1133
- [{ type: 'replay_event' }, replayEvent],
1134
- [
1135
- {
1136
- // @ts-ignore setting envelope
1137
- type: 'replay_recording',
1138
- length: payloadWithSequence.length,
1139
- },
1140
- // @ts-ignore: Type 'string' is not assignable to type 'ClientReport'.ts(2322)
1141
- payloadWithSequence,
931
+ /*
932
+ For reference, the fully built event looks something like this:
933
+ {
934
+ "type": "replay_event",
935
+ "timestamp": 1670837008.634,
936
+ "error_ids": [
937
+ "errorId"
938
+ ],
939
+ "trace_ids": [
940
+ "traceId"
1142
941
  ],
1143
- ],
1144
- );
942
+ "urls": [
943
+ "https://example.com"
944
+ ],
945
+ "replay_id": "eventId",
946
+ "segment_id": 3,
947
+ "platform": "javascript",
948
+ "event_id": "eventId",
949
+ "environment": "production",
950
+ "sdk": {
951
+ "integrations": [
952
+ "BrowserTracing",
953
+ "Replay"
954
+ ],
955
+ "name": "sentry.javascript.integration.replay",
956
+ "version": "7.24.2"
957
+ },
958
+ "sdkProcessingMetadata": {},
959
+ "tags": {
960
+ "sessionSampleRate": 1,
961
+ "errorSampleRate": 0,
962
+ "replayType": "error"
963
+ }
964
+ }
965
+ */
966
+
967
+ const envelope = createReplayEnvelope(replayId, replayEvent, payloadWithSequence);
1145
968
 
1146
- const client = getCurrentHub().getClient();
1147
969
  try {
1148
- return _optionalChain([client, 'optionalAccess', _69 => _69.getTransport, 'call', _70 => _70(), 'optionalAccess', _71 => _71.send, 'call', _72 => _72(envelope)]);
1149
- } catch (e2) {
970
+ return transport.send(envelope);
971
+ } catch (e) {
1150
972
  throw new Error(UNABLE_TO_SEND_REPLAY);
1151
973
  }
1152
974
  }
@@ -1182,12 +1004,11 @@ class ReplayContainer {
1182
1004
  this.resetRetries();
1183
1005
  return true;
1184
1006
  } catch (err) {
1185
- (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error(err);
1186
1007
  // Capture error for every failed replay
1187
1008
  setContext('Replays', {
1188
1009
  _retryCount: this._retryCount,
1189
1010
  });
1190
- captureInternalException(err);
1011
+ this.handleException(err);
1191
1012
 
1192
1013
  // If an error happened here, it's likely that uploading the attachment
1193
1014
  // failed, we'll can retry with the same events payload
@@ -1220,45 +1041,10 @@ class ReplayContainer {
1220
1041
 
1221
1042
  /** Save the session, if it is sticky */
1222
1043
  _maybeSaveSession() {
1223
- if (this.session && this.options.stickySession) {
1044
+ if (this.session && this._options.stickySession) {
1224
1045
  saveSession(this.session);
1225
1046
  }
1226
1047
  }
1227
-
1228
- _overwriteRecordDroppedEvent() {
1229
- const client = getCurrentHub().getClient();
1230
-
1231
- if (!client) {
1232
- return;
1233
- }
1234
-
1235
- const _originalCallback = client.recordDroppedEvent.bind(client);
1236
-
1237
- const recordDroppedEvent = (
1238
- reason,
1239
- category,
1240
- event,
1241
- ) => {
1242
- if (event && event.event_id) {
1243
- this._context.errorIds.delete(event.event_id);
1244
- }
1245
-
1246
- return _originalCallback(reason, category, event);
1247
- };
1248
-
1249
- client.recordDroppedEvent = recordDroppedEvent;
1250
- this._originalRecordDroppedEvent = _originalCallback;
1251
- }
1252
-
1253
- _restoreRecordDroppedEvent() {
1254
- const client = getCurrentHub().getClient();
1255
-
1256
- if (!client || !this._originalRecordDroppedEvent) {
1257
- return;
1258
- }
1259
-
1260
- client.recordDroppedEvent = this._originalRecordDroppedEvent;
1261
- }
1262
1048
  }
1263
1049
 
1264
1050
  export { ReplayContainer };