@sentry/replay 0.4.8-1 → 0.4.8

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 (128) hide show
  1. package/README.md +15 -15
  2. package/dist/{jest.config.d.ts → config/dist/jest.config.d.ts} +0 -0
  3. package/dist/{jest.setup.d.ts → config/dist/jest.setup.d.ts} +0 -0
  4. package/dist/config/dist/src/api/captureReplay.d.ts +10 -0
  5. package/dist/config/dist/src/api/captureReplayUpdate.d.ts +12 -0
  6. package/dist/config/dist/src/coreHandlers/getBreadcrumbHandler.d.ts +3 -0
  7. package/dist/config/dist/src/coreHandlers/getSpanHandler.d.ts +5 -0
  8. package/dist/{src → config/dist/src}/coreHandlers/handleDom.d.ts +0 -0
  9. package/dist/config/dist/src/coreHandlers/handleFetch.d.ts +19 -0
  10. package/dist/{src → config/dist/src}/coreHandlers/handleFetch.test.d.ts +0 -0
  11. package/dist/config/dist/src/coreHandlers/handleHistory.d.ts +7 -0
  12. package/dist/{src → config/dist/src}/coreHandlers/handleScope-unit.test.d.ts +0 -0
  13. package/dist/{src → config/dist/src}/coreHandlers/handleScope.d.ts +0 -0
  14. package/dist/{src → config/dist/src}/coreHandlers/handleScope.test.d.ts +0 -0
  15. package/dist/config/dist/src/coreHandlers/handleXhr.d.ts +21 -0
  16. package/dist/{dist → config/dist/src}/coreHandlers/index.d.ts +0 -0
  17. package/dist/{src → config/dist/src}/createPerformanceEntry.d.ts +0 -0
  18. package/dist/{src → config/dist/src}/createPerformanceEntry.test.d.ts +0 -0
  19. package/dist/{src → config/dist/src}/eventBuffer.d.ts +9 -2
  20. package/dist/config/dist/src/eventBuffer.test.d.ts +1 -0
  21. package/dist/{src → config/dist/src}/flags.d.ts +0 -0
  22. package/dist/{src → config/dist/src}/index-captureOnlyOnError.test.d.ts +0 -0
  23. package/dist/{src → config/dist/src}/index-noSticky.test.d.ts +0 -0
  24. package/dist/{src → config/dist/src}/index-sampling.test.d.ts +0 -0
  25. package/dist/{src → config/dist/src}/index.d.ts +18 -11
  26. package/dist/{src → config/dist/src}/index.test.d.ts +0 -0
  27. package/dist/{src → config/dist/src}/session/Session.d.ts +0 -0
  28. package/dist/{src → config/dist/src}/session/Session.test.d.ts +0 -0
  29. package/dist/{src → config/dist/src}/session/constants.d.ts +0 -0
  30. package/dist/{src → config/dist/src}/session/createSession.d.ts +0 -0
  31. package/dist/{src → config/dist/src}/session/createSession.test.d.ts +0 -0
  32. package/dist/{src → config/dist/src}/session/fetchSession.d.ts +0 -0
  33. package/dist/{src → config/dist/src}/session/fetchSession.test.d.ts +0 -0
  34. package/dist/{src → config/dist/src}/session/getSession.d.ts +0 -0
  35. package/dist/{src → config/dist/src}/session/getSession.test.d.ts +0 -0
  36. package/dist/{src → config/dist/src}/session/index.d.ts +0 -0
  37. package/dist/{src → config/dist/src}/session/saveSession.d.ts +0 -0
  38. package/dist/{src → config/dist/src}/session/saveSession.test.d.ts +0 -0
  39. package/dist/{src → config/dist/src}/types.d.ts +22 -8
  40. package/dist/{src → config/dist/src}/util/createBreadcrumb.d.ts +0 -0
  41. package/dist/config/dist/src/util/createPayload.d.ts +5 -0
  42. package/dist/{src → config/dist/src}/util/isExpired.d.ts +0 -0
  43. package/dist/{src → config/dist/src}/util/isExpired.test.d.ts +0 -0
  44. package/dist/{src → config/dist/src}/util/isIngestHost.d.ts +0 -0
  45. package/dist/{src → config/dist/src}/util/isSampled.d.ts +0 -0
  46. package/dist/{src → config/dist/src}/util/isSampled.test.d.ts +0 -0
  47. package/dist/{src → config/dist/src}/util/isSessionExpired.d.ts +0 -0
  48. package/dist/{src → config/dist/src}/util/isSessionExpired.test.d.ts +0 -0
  49. package/dist/{src → config/dist/src}/util/logger.d.ts +0 -0
  50. package/dist/{src → config/dist/src}/util/supportsSendBeacon.d.ts +0 -0
  51. package/dist/{test → config/dist/test}/index.d.ts +0 -0
  52. package/dist/{test → config/dist/test}/mocks/mockRrweb.d.ts +0 -0
  53. package/dist/{test → config/dist/test}/mocks/mockSdk.d.ts +0 -0
  54. package/dist/dist/api/captureReplay.d.ts +5 -3
  55. package/dist/dist/api/captureReplayUpdate.d.ts +5 -3
  56. package/dist/dist/coreHandlers/getBreadcrumbHandler.d.ts +3 -0
  57. package/dist/dist/coreHandlers/getSpanHandler.d.ts +5 -0
  58. package/dist/dist/coreHandlers/handleFetch.d.ts +19 -2
  59. package/dist/dist/coreHandlers/handleHistory.d.ts +7 -0
  60. package/dist/dist/coreHandlers/handleXhr.d.ts +21 -2
  61. package/dist/dist/index.d.ts +18 -7
  62. package/dist/dist/types.d.ts +20 -8
  63. package/dist/index.es.js +223 -126
  64. package/dist/index.js +222 -125
  65. package/dist/index.js.map +1 -1
  66. package/package.json +1 -1
  67. package/dist/esm/index.js +0 -1454
  68. package/dist/esm/worker-aa3eb59a.js +0 -4
  69. package/dist/src/api/captureReplay.d.ts +0 -3
  70. package/dist/src/api/captureReplayUpdate.d.ts +0 -2
  71. package/dist/src/coreHandlers/handleFetch.d.ts +0 -2
  72. package/dist/src/coreHandlers/handleXhr.d.ts +0 -2
  73. package/dist/src/coreHandlers/index.d.ts +0 -4
  74. package/dist/src/eventBuffer.test.d.ts +0 -1
  75. package/dist/types/jest.config.d.ts +0 -3
  76. package/dist/types/jest.setup.d.ts +0 -10
  77. package/dist/types/src/api/captureReplay.d.ts +0 -3
  78. package/dist/types/src/api/captureReplayUpdate.d.ts +0 -2
  79. package/dist/types/src/coreHandlers/handleDom.d.ts +0 -1
  80. package/dist/types/src/coreHandlers/handleFetch.d.ts +0 -2
  81. package/dist/types/src/coreHandlers/handleFetch.test.d.ts +0 -1
  82. package/dist/types/src/coreHandlers/handleScope-unit.test.d.ts +0 -1
  83. package/dist/types/src/coreHandlers/handleScope.d.ts +0 -2
  84. package/dist/types/src/coreHandlers/handleScope.test.d.ts +0 -1
  85. package/dist/types/src/coreHandlers/handleXhr.d.ts +0 -2
  86. package/dist/types/src/coreHandlers/index.d.ts +0 -4
  87. package/dist/types/src/createPerformanceEntry.d.ts +0 -42
  88. package/dist/types/src/createPerformanceEntry.test.d.ts +0 -1
  89. package/dist/types/src/eventBuffer.d.ts +0 -31
  90. package/dist/types/src/eventBuffer.test.d.ts +0 -1
  91. package/dist/types/src/flags.d.ts +0 -2
  92. package/dist/types/src/index-captureOnlyOnError.test.d.ts +0 -1
  93. package/dist/types/src/index-noSticky.test.d.ts +0 -1
  94. package/dist/types/src/index-sampling.test.d.ts +0 -1
  95. package/dist/types/src/index.d.ts +0 -209
  96. package/dist/types/src/index.test.d.ts +0 -1
  97. package/dist/types/src/session/Session.d.ts +0 -63
  98. package/dist/types/src/session/Session.test.d.ts +0 -1
  99. package/dist/types/src/session/constants.d.ts +0 -5
  100. package/dist/types/src/session/createSession.d.ts +0 -19
  101. package/dist/types/src/session/createSession.test.d.ts +0 -1
  102. package/dist/types/src/session/fetchSession.d.ts +0 -5
  103. package/dist/types/src/session/fetchSession.test.d.ts +0 -1
  104. package/dist/types/src/session/getSession.d.ts +0 -28
  105. package/dist/types/src/session/getSession.test.d.ts +0 -1
  106. package/dist/types/src/session/index.d.ts +0 -1
  107. package/dist/types/src/session/saveSession.d.ts +0 -2
  108. package/dist/types/src/session/saveSession.test.d.ts +0 -1
  109. package/dist/types/src/session/types.d.ts +0 -0
  110. package/dist/types/src/types.d.ts +0 -76
  111. package/dist/types/src/util/createBreadcrumb.d.ts +0 -4
  112. package/dist/types/src/util/isExpired.d.ts +0 -5
  113. package/dist/types/src/util/isExpired.test.d.ts +0 -1
  114. package/dist/types/src/util/isIngestHost.d.ts +0 -4
  115. package/dist/types/src/util/isSampled.d.ts +0 -7
  116. package/dist/types/src/util/isSampled.test.d.ts +0 -1
  117. package/dist/types/src/util/isSessionExpired.d.ts +0 -5
  118. package/dist/types/src/util/isSessionExpired.test.d.ts +0 -1
  119. package/dist/types/src/util/logger.d.ts +0 -12
  120. package/dist/types/src/util/supportsSendBeacon.d.ts +0 -4
  121. package/dist/types/test/index.d.ts +0 -3
  122. package/dist/types/test/mocks/mockRrweb.d.ts +0 -15
  123. package/dist/types/test/mocks/mockSdk.d.ts +0 -11
  124. package/dist/types/worker/src/Compressor.d.ts +0 -15
  125. package/dist/types/worker/src/handleMessage.d.ts +0 -2
  126. package/dist/worker-aa3eb59a.js +0 -4
  127. package/dist/worker-f4750cfb.js +0 -7
  128. package/dist/worker-f4750cfb.js.map +0 -1
package/dist/index.es.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { captureEvent, getCurrentHub, captureException, addGlobalEventProcessor } from '@sentry/core';
2
- import { uuid4, logger as logger$1, htmlTreeAsString, addInstrumentationHandler } from '@sentry/utils';
2
+ import { uuid4, htmlTreeAsString, logger as logger$1, addInstrumentationHandler } from '@sentry/utils';
3
3
  import { record, EventType } from 'rrweb';
4
4
 
5
5
  /******************************************************************************
@@ -97,19 +97,27 @@ var SESSION_IDLE_DURATION = 900000; // 15 minutes
97
97
  var VISIBILITY_CHANGE_TIMEOUT = SESSION_IDLE_DURATION;
98
98
 
99
99
  function captureReplay(_a) {
100
- var session = _a.session, initialState = _a.initialState;
100
+ var session = _a.session, initialState = _a.initialState, errorIds = _a.errorIds, traceIds = _a.traceIds, urls = _a.urls;
101
101
  captureEvent({
102
102
  message: ROOT_REPLAY_NAME,
103
103
  tags: { segmentId: session.segmentId, url: initialState.url },
104
104
  timestamp: initialState.timestamp / 1000,
105
+ // @ts-expect-error replay event type accepts this
106
+ error_ids: errorIds,
107
+ trace_ids: traceIds,
108
+ urls: urls,
105
109
  }, { event_id: session.id });
106
110
  }
107
111
 
108
112
  function captureReplayUpdate(_a) {
109
- var session = _a.session, timestamp = _a.timestamp;
113
+ var session = _a.session, timestamp = _a.timestamp, errorIds = _a.errorIds, traceIds = _a.traceIds, urls = _a.urls;
110
114
  captureEvent({
111
115
  timestamp: timestamp / 1000,
112
116
  message: "".concat(REPLAY_EVENT_NAME, "-").concat(uuid4().substring(16)),
117
+ // @ts-expect-error replay event type accepts this
118
+ error_ids: errorIds,
119
+ trace_ids: traceIds,
120
+ urls: urls,
113
121
  tags: {
114
122
  replayId: session.id,
115
123
  segmentId: session.segmentId++,
@@ -117,6 +125,143 @@ function captureReplayUpdate(_a) {
117
125
  });
118
126
  }
119
127
 
128
+ function createBreadcrumb(breadcrumb) {
129
+ return __assign({ timestamp: new Date().getTime() / 1000, type: 'default' }, breadcrumb);
130
+ }
131
+
132
+ function handleDom(handlerData) {
133
+ // Taken from https://github.com/getsentry/sentry-javascript/blob/master/packages/browser/src/integrations/breadcrumbs.ts#L112
134
+ var target;
135
+ var targetNode;
136
+ // Accessing event.target can throw (see getsentry/raven-js#838, #768)
137
+ try {
138
+ targetNode =
139
+ handlerData.event.target ||
140
+ handlerData.event;
141
+ target = htmlTreeAsString(targetNode);
142
+ }
143
+ catch (e) {
144
+ target = '<unknown>';
145
+ }
146
+ if (target.length === 0) {
147
+ return null;
148
+ }
149
+ return createBreadcrumb({
150
+ category: "ui.".concat(handlerData.name),
151
+ message: target,
152
+ data: __assign({}, (targetNode ? { nodeId: record.mirror.getId(targetNode) } : {})),
153
+ });
154
+ }
155
+
156
+ var _LAST_BREADCRUMB = null;
157
+ function handleScope(scope) {
158
+ var _a;
159
+ //@ts-expect-error using private val
160
+ var newBreadcrumb = scope._breadcrumbs[scope._breadcrumbs.length - 1];
161
+ // Listener can be called when breadcrumbs have not changed, so we store the
162
+ // reference to the last crumb and only return a crumb if it has changed
163
+ if (_LAST_BREADCRUMB === newBreadcrumb || !newBreadcrumb) {
164
+ return null;
165
+ }
166
+ _LAST_BREADCRUMB = newBreadcrumb;
167
+ if (['fetch', 'xhr', 'sentry.event', 'sentry.transaction'].includes(newBreadcrumb.category) ||
168
+ ((_a = newBreadcrumb.category) === null || _a === void 0 ? void 0 : _a.startsWith('ui.'))) {
169
+ return null;
170
+ }
171
+ return createBreadcrumb(newBreadcrumb);
172
+ }
173
+
174
+ function getBreadcrumbHandler(type) {
175
+ if (type === 'scope') {
176
+ return handleScope;
177
+ }
178
+ return handleDom;
179
+ }
180
+
181
+ /**
182
+ * Checks is `targetHost` is a Sentry ingestion host
183
+ */
184
+ function isIngestHost(targetHost) {
185
+ var _a = getCurrentHub().getClient().getDsn(), protocol = _a.protocol, host = _a.host;
186
+ return targetHost.startsWith("".concat(protocol, "://").concat(host));
187
+ }
188
+
189
+ function handleFetch(handlerData) {
190
+ if (!handlerData.endTimestamp) {
191
+ return null;
192
+ }
193
+ var startTimestamp = handlerData.startTimestamp, endTimestamp = handlerData.endTimestamp, fetchData = handlerData.fetchData, response = handlerData.response;
194
+ // Do not capture fetches to Sentry ingestion endpoint
195
+ if (isIngestHost(fetchData.url)) {
196
+ return null;
197
+ }
198
+ return {
199
+ type: 'resource.fetch',
200
+ start: startTimestamp / 1000,
201
+ end: endTimestamp / 1000,
202
+ name: fetchData.url,
203
+ data: {
204
+ method: fetchData.method,
205
+ statusCode: response.status,
206
+ },
207
+ };
208
+ }
209
+
210
+ function handleHistory(handlerData) {
211
+ var from = handlerData.from, to = handlerData.to;
212
+ var now = new Date().getTime() / 1000;
213
+ return {
214
+ type: 'navigation.push',
215
+ start: now,
216
+ end: now,
217
+ name: to,
218
+ data: {
219
+ previous: from,
220
+ },
221
+ };
222
+ }
223
+
224
+ function handleXhr(handlerData) {
225
+ if (handlerData.xhr.__sentry_own_request__) {
226
+ // Taken from sentry-javascript
227
+ // Only capture non-sentry requests
228
+ return null;
229
+ }
230
+ if (handlerData.startTimestamp) {
231
+ // TODO: See if this is still needed
232
+ handlerData.xhr.__sentry_xhr__.startTimestamp = handlerData.startTimestamp;
233
+ }
234
+ if (!handlerData.endTimestamp) {
235
+ return null;
236
+ }
237
+ var _a = handlerData.xhr.__sentry_xhr__ || {}, method = _a.method, url = _a.url, statusCode = _a.status_code;
238
+ // Do not capture fetches to Sentry ingestion endpoint
239
+ if (isIngestHost(url)) {
240
+ return null;
241
+ }
242
+ return {
243
+ type: 'resource.xhr',
244
+ name: url,
245
+ start: handlerData.xhr.__sentry_xhr__.startTimestamp / 1000 ||
246
+ handlerData.endTimestamp / 1000.0,
247
+ end: handlerData.endTimestamp / 1000.0,
248
+ data: {
249
+ method: method,
250
+ statusCode: statusCode,
251
+ },
252
+ };
253
+ }
254
+
255
+ function getSpanHandler(type) {
256
+ if (type === 'fetch') {
257
+ return handleFetch;
258
+ }
259
+ if (type === 'xhr') {
260
+ return handleXhr;
261
+ }
262
+ return handleHistory;
263
+ }
264
+
120
265
  /**
121
266
  * Given an initial timestamp and an expiry duration, checks to see if current
122
267
  * time should be considered as expired.
@@ -144,9 +289,11 @@ function isSessionExpired(session, expiry, targetTime) {
144
289
 
145
290
  function wrapLogger(logFn) {
146
291
  return function wrappedLog() {
147
- {
148
- return;
292
+ var args = [];
293
+ for (var _i = 0; _i < arguments.length; _i++) {
294
+ args[_i] = arguments[_i];
149
295
  }
296
+ return logFn.call.apply(logFn, __spreadArray([logger$1, '[Replay]'], args, false));
150
297
  };
151
298
  }
152
299
  var logger = __assign(__assign({}, logger$1), { error: wrapLogger(logger$1.error), warn: wrapLogger(logger$1.warn), log: wrapLogger(logger$1.log) });
@@ -307,7 +454,6 @@ function getSession(_a) {
307
454
  // TODO: We should probably set a max age on this as well
308
455
  var isExpired = isSessionExpired(session, expiry);
309
456
  if (!isExpired) {
310
- logger.log("Using existing session: ".concat(session.id));
311
457
  return { type: 'saved', session: session };
312
458
  }
313
459
  else {
@@ -319,10 +465,6 @@ function getSession(_a) {
319
465
  return { type: 'new', session: newSession };
320
466
  }
321
467
 
322
- function createBreadcrumb(breadcrumb) {
323
- return __assign({ timestamp: new Date().getTime() / 1000, type: 'default' }, breadcrumb);
324
- }
325
-
326
468
  /**
327
469
  * Determine if there is browser support for `navigator.sendBeacon`
328
470
  */
@@ -330,92 +472,6 @@ function supportsSendBeacon() {
330
472
  return 'navigator' in window && 'sendBeacon' in window.navigator;
331
473
  }
332
474
 
333
- function handleDom(handlerData) {
334
- // Taken from https://github.com/getsentry/sentry-javascript/blob/master/packages/browser/src/integrations/breadcrumbs.ts#L112
335
- var target;
336
- var targetNode;
337
- // Accessing event.target can throw (see getsentry/raven-js#838, #768)
338
- try {
339
- targetNode =
340
- handlerData.event.target ||
341
- handlerData.event;
342
- target = htmlTreeAsString(targetNode);
343
- }
344
- catch (e) {
345
- target = '<unknown>';
346
- }
347
- if (target.length === 0) {
348
- return null;
349
- }
350
- return createBreadcrumb({
351
- category: "ui.".concat(handlerData.name),
352
- message: target,
353
- data: __assign({}, (targetNode ? { nodeId: record.mirror.getId(targetNode) } : {})),
354
- });
355
- }
356
-
357
- function handleFetch(handlerData) {
358
- if (!handlerData.endTimestamp) {
359
- return null;
360
- }
361
- var _a = handlerData.args, op = _a[0], description = _a[1];
362
- return {
363
- description: description,
364
- op: op,
365
- startTimestamp: handlerData.startTimestamp / 1000,
366
- endTimestamp: handlerData.endTimestamp / 1000,
367
- data: {
368
- statusCode: handlerData.response.status,
369
- },
370
- };
371
- }
372
-
373
- var _LAST_BREADCRUMB = null;
374
- function handleScope(scope) {
375
- var _a;
376
- //@ts-expect-error using private val
377
- var newBreadcrumb = scope._breadcrumbs[scope._breadcrumbs.length - 1];
378
- // Listener can be called when breadcrumbs have not changed, so we store the
379
- // reference to the last crumb and only return a crumb if it has changed
380
- if (_LAST_BREADCRUMB === newBreadcrumb || !newBreadcrumb) {
381
- return null;
382
- }
383
- _LAST_BREADCRUMB = newBreadcrumb;
384
- if (['fetch', 'xhr', 'sentry.event', 'sentry.transaction'].includes(newBreadcrumb.category) ||
385
- ((_a = newBreadcrumb.category) === null || _a === void 0 ? void 0 : _a.startsWith('ui.'))) {
386
- return null;
387
- }
388
- return createBreadcrumb(newBreadcrumb);
389
- }
390
-
391
- function handleXhr(handlerData) {
392
- if (handlerData.startTimestamp) {
393
- handlerData.xhr.__sentry_xhr__.startTimestamp = handlerData.startTimestamp;
394
- }
395
- if (!handlerData.endTimestamp) {
396
- return null;
397
- }
398
- var _a = handlerData.args, op = _a[0], description = _a[1];
399
- return {
400
- description: description,
401
- op: op,
402
- startTimestamp: handlerData.xhr.__sentry_xhr__.startTimestamp / 1000 ||
403
- handlerData.endTimestamp / 1000.0,
404
- endTimestamp: handlerData.endTimestamp / 1000.0,
405
- data: {
406
- statusCode: handlerData.response.status,
407
- },
408
- };
409
- }
410
-
411
- /**
412
- * Checks is `targetHost` is a Sentry ingestion host
413
- */
414
- function isIngestHost(targetHost) {
415
- var _a = getCurrentHub().getClient().getDsn(), protocol = _a.protocol, host = _a.host;
416
- return targetHost.startsWith("".concat(protocol, "://").concat(host));
417
- }
418
-
419
475
  var _a;
420
476
  // Map entryType -> function to normalize data for event
421
477
  var ENTRY_TYPES = (_a = {
@@ -466,6 +522,10 @@ function createResourceEntry(entry) {
466
522
  if (isIngestHost(name)) {
467
523
  return null;
468
524
  }
525
+ // Core SDK handles these
526
+ if (['fetch', 'xmlhttprequest'].includes(initiatorType)) {
527
+ return null;
528
+ }
469
529
  return {
470
530
  type: "".concat(entryType, ".").concat(initiatorType),
471
531
  start: getAbsoluteTime(startTime),
@@ -526,7 +586,6 @@ function createEventBuffer(_a) {
526
586
  return new EventBufferCompressionWorker(worker);
527
587
  }
528
588
  else {
529
- // TODO: Debugging
530
589
  captureException(new Error('Unable to create compression worker'));
531
590
  }
532
591
  }
@@ -584,7 +643,6 @@ var EventBufferCompressionWorker = /** @class */ (function () {
584
643
  method: 'addEvent',
585
644
  args: [event],
586
645
  });
587
- logger.log('Message posted to compression worker');
588
646
  _this.eventBufferItemLength++;
589
647
  };
590
648
  this.finishRequest = function (id) {
@@ -697,10 +755,6 @@ var SentryReplay = /** @class */ (function () {
697
755
  * Buffer of breadcrumbs to be uploaded
698
756
  */
699
757
  this.breadcrumbs = [];
700
- /**
701
- * Buffer of replay spans to be uploaded
702
- */
703
- this.replaySpans = [];
704
758
  /**
705
759
  * List of PerformanceEntry from PerformanceObserver
706
760
  */
@@ -721,19 +775,30 @@ var SentryReplay = /** @class */ (function () {
721
775
  * immediately before sending recording)
722
776
  */
723
777
  this.needsCaptureReplay = false;
778
+ this.context = {
779
+ errorIds: new Set(),
780
+ traceIds: new Set(),
781
+ urls: [],
782
+ };
724
783
  /**
725
784
  * Core Sentry SDK global event handler. Attaches `replayId` to all [non-replay]
726
785
  * events as a tag. Also handles the case where we only want to capture a reply
727
786
  * when an error occurs.
728
787
  **/
729
788
  this.handleGlobalEvent = function (event) {
730
- var _a;
789
+ var _a, _b;
731
790
  // Do not apply replayId to the root event
732
791
  if (event.message === ROOT_REPLAY_NAME ||
733
792
  ((_a = event.message) === null || _a === void 0 ? void 0 : _a.startsWith(REPLAY_EVENT_NAME))) {
734
793
  return event;
735
794
  }
736
795
  event.tags = __assign(__assign({}, event.tags), { replayId: _this.session.id });
796
+ if (event.type === 'transaction') {
797
+ _this.context.traceIds.add(String(((_b = event.contexts) === null || _b === void 0 ? void 0 : _b.trace.trace_id) || ''));
798
+ return event;
799
+ }
800
+ // XXX: Is it safe to assume that all other events are error events?
801
+ _this.context.errorIds.add(event.event_id);
737
802
  // Need to be very careful that this does not cause an infinite loop
738
803
  if (_this.options.captureOnlyOnError && event.exception) {
739
804
  // TODO: Do we continue to record after?
@@ -824,25 +889,35 @@ var SentryReplay = /** @class */ (function () {
824
889
  /**
825
890
  * Handler for Sentry Core SDK events.
826
891
  *
827
- * Transforms core SDK events into replay events.
892
+ * These specific events will create span-like objects in the recording.
828
893
  *
829
894
  */
830
- this.handleCoreListener = function (type) { return function (handlerData) {
831
- var handlerMap = {
832
- scope: [handleScope, 'breadcrumb'],
833
- dom: [handleDom, 'breadcrumb'],
834
- fetch: [handleFetch, 'span'],
835
- xhr: [handleXhr, 'span'],
836
- };
837
- if (!(type in handlerMap)) {
838
- throw new Error("No handler defined for type: ".concat(type));
895
+ this.handleCoreSpanListener = function (type) { return function (handlerData) {
896
+ var handler = getSpanHandler(type);
897
+ var result = handler(handlerData);
898
+ if (result === null) {
899
+ return;
900
+ }
901
+ if (type === 'history') {
902
+ // Need to collect visited URLs
903
+ _this.context.urls.push(result.name);
839
904
  }
840
- var _a = handlerMap[type], handlerFn = _a[0], eventType = _a[1];
841
- var result = handlerFn(handlerData);
905
+ _this.addUpdate(function () {
906
+ _this.createPerformanceSpans([result]);
907
+ });
908
+ }; };
909
+ /**
910
+ * Handler for Sentry Core SDK events.
911
+ *
912
+ * These events will create breadcrumb-like objects in the recording.
913
+ */
914
+ this.handleCoreBreadcrumbListener = function (type) { return function (handlerData) {
915
+ var handler = getBreadcrumbHandler(type);
916
+ var result = handler(handlerData);
842
917
  if (result === null) {
843
918
  return;
844
919
  }
845
- if (['sentry.transaction'].includes(result.category)) {
920
+ if (result.category === 'sentry.transaction') {
846
921
  return;
847
922
  }
848
923
  _this.addUpdate(function () {
@@ -850,10 +925,9 @@ var SentryReplay = /** @class */ (function () {
850
925
  type: EventType.Custom,
851
926
  // TODO: We were converting from ms to seconds for breadcrumbs, spans,
852
927
  // but maybe we should just keep them as milliseconds
853
- timestamp: result.timestamp * 1000 ||
854
- result.startTimestamp * 1000,
928
+ timestamp: result.timestamp * 1000,
855
929
  data: {
856
- tag: eventType,
930
+ tag: 'breadcrumb',
857
931
  payload: result,
858
932
  },
859
933
  });
@@ -927,12 +1001,15 @@ var SentryReplay = /** @class */ (function () {
927
1001
  // replay ID so that we can reference them later in the UI
928
1002
  addGlobalEventProcessor(this.handleGlobalEvent);
929
1003
  record(__assign(__assign({}, this.recordingOptions), { emit: this.handleRecordingEmit }));
1004
+ var urlPath = "".concat(window.location.pathname).concat(window.location.hash).concat(window.location.search);
1005
+ var url = "".concat(window.location.origin).concat(urlPath);
930
1006
  // Otherwise, these will be captured after the first flush, which means the
931
1007
  // URL and timestamps could be incorrect
932
1008
  this.initialState = {
933
1009
  timestamp: new Date().getTime(),
934
- url: "".concat(window.location.origin).concat(window.location.pathname),
1010
+ url: url,
935
1011
  };
1012
+ this.context.urls.push(url);
936
1013
  };
937
1014
  /**
938
1015
  * We want to batch uploads of replay events. Save events only if
@@ -989,7 +1066,6 @@ var SentryReplay = /** @class */ (function () {
989
1066
  SentryReplay.prototype.destroy = function () {
990
1067
  logger.log('Destroying instance');
991
1068
  this.removeListeners();
992
- // this.eventBuffer.clear();
993
1069
  };
994
1070
  SentryReplay.prototype.clearSession = function () {
995
1071
  this.session = null;
@@ -1028,8 +1104,11 @@ var SentryReplay = /** @class */ (function () {
1028
1104
  window.addEventListener('beforeunload', this.handleWindowUnload);
1029
1105
  // Listeners from core SDK //
1030
1106
  var scope = getCurrentHub().getScope();
1031
- scope.addScopeListener(this.handleCoreListener('scope'));
1032
- addInstrumentationHandler('dom', this.handleCoreListener('dom'));
1107
+ scope.addScopeListener(this.handleCoreBreadcrumbListener('scope'));
1108
+ addInstrumentationHandler('dom', this.handleCoreBreadcrumbListener('dom'));
1109
+ addInstrumentationHandler('fetch', this.handleCoreSpanListener('fetch'));
1110
+ addInstrumentationHandler('xhr', this.handleCoreSpanListener('xhr'));
1111
+ addInstrumentationHandler('history', this.handleCoreSpanListener('history'));
1033
1112
  // PerformanceObserver //
1034
1113
  if (!('PerformanceObserver' in window)) {
1035
1114
  return;
@@ -1212,6 +1291,24 @@ var SentryReplay = /** @class */ (function () {
1212
1291
  }
1213
1292
  return this.flushUpdate(lastActivity);
1214
1293
  };
1294
+ /**
1295
+ * Return and clear context
1296
+ */
1297
+ SentryReplay.prototype.popEventContext = function (_a) {
1298
+ var timestamp = _a.timestamp;
1299
+ var context = {
1300
+ session: this.session,
1301
+ initialState: this.initialState,
1302
+ timestamp: timestamp,
1303
+ errorIds: Array.from(this.context.errorIds).filter(Boolean),
1304
+ traceIds: Array.from(this.context.traceIds).filter(Boolean),
1305
+ urls: this.context.urls,
1306
+ };
1307
+ this.context.errorIds.clear();
1308
+ this.context.traceIds.clear();
1309
+ this.context.urls = [];
1310
+ return context;
1311
+ };
1215
1312
  /**
1216
1313
  * Flushes replay event buffer to Sentry.
1217
1314
  *
@@ -1236,10 +1333,11 @@ var SentryReplay = /** @class */ (function () {
1236
1333
  if (!this.eventBuffer.length) {
1237
1334
  return [2 /*return*/];
1238
1335
  }
1336
+ timestamp = lastActivity !== null && lastActivity !== void 0 ? lastActivity : new Date().getTime();
1239
1337
  // Only want to create replay event if session is new
1240
1338
  if (this.needsCaptureReplay) {
1241
1339
  // This event needs to exist before calling `sendReplay`
1242
- captureReplay({ session: this.session, initialState: this.initialState });
1340
+ captureReplay(this.popEventContext({ timestamp: timestamp }));
1243
1341
  this.needsCaptureReplay = false;
1244
1342
  }
1245
1343
  // Reset this to null regardless of `sendReplay` result so that future
@@ -1248,7 +1346,6 @@ var SentryReplay = /** @class */ (function () {
1248
1346
  _a.label = 1;
1249
1347
  case 1:
1250
1348
  _a.trys.push([1, 4, , 5]);
1251
- timestamp = lastActivity !== null && lastActivity !== void 0 ? lastActivity : new Date().getTime();
1252
1349
  return [4 /*yield*/, this.eventBuffer.finish()];
1253
1350
  case 2:
1254
1351
  recordingData = _a.sent();
@@ -1261,7 +1358,7 @@ var SentryReplay = /** @class */ (function () {
1261
1358
  // of the event is passed as an argument in the case where a timeout
1262
1359
  // occurs.
1263
1360
  this.updateLastActivity(timestamp);
1264
- captureReplayUpdate({ session: this.session, timestamp: timestamp });
1361
+ captureReplayUpdate(this.popEventContext({ timestamp: timestamp }));
1265
1362
  return [3 /*break*/, 5];
1266
1363
  case 4:
1267
1364
  err_1 = _a.sent();