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