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