@sentry/replay 0.6.13 → 0.6.14-1

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.
package/README.md CHANGED
@@ -79,6 +79,26 @@ replay.start(); // Start recording
79
79
  replay.stop(); // Stop recording
80
80
  ```
81
81
 
82
+ ## Sessions
83
+
84
+ A session starts when the Session Replay SDK is first loaded and initialized. The session will continue until 5 minutes passes without any user interactions[^1] with the application *OR* until a maximum of 30 minutes have elapsed. Closing the browser tab will end the session immediately according to the rules for [SessionStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage).
85
+
86
+ [^1]: An 'interaction' refers to either a mouse click or a browser navigation event.
87
+
88
+ ### Replay Captures Only on Errors
89
+
90
+ Alternatively, rather than recording an entire session, you can capture a replay only when an error occurs. In this case, the integration will buffer up to one minute worth of events prior to the error being thrown. It will continue to record the session following the rules above regarding session life and activity. Read the [sampling](#Sampling) section for configuration options.
91
+
92
+ ## Sampling
93
+
94
+ Sampling allows you to control how much of your website's traffic will result in a Session Replay. There are two sample rates you can adjust to get the replays more relevant to your interests:
95
+
96
+ - `sessionSampleRate` - The sample rate for replays that begin recording immediately and last the entirety of the user's session.
97
+ - `errorSampleRate` - The sample rate for replays that are recorded when an error happens. This type of replay will record up to a minute of events prior to the error and continue recording until the session ends.
98
+
99
+ Sampling occurs when the session is first started. `sessionSampleRate` is evaluated first. If it is sampled, then the replay recording begins. Otherwise, `errorSampleRate` is evaluated and if it is sampled, the integration will begin buffering the replay and will only upload a replay to Sentry when an error occurs. The remainder of the replay will behave similarly to a whole-session replay.
100
+
101
+
82
102
  ## Configuration
83
103
 
84
104
  ### General Configuration
@@ -2,7 +2,7 @@ import { Breadcrumb, Event, Integration } from '@sentry/types';
2
2
  import { Session } from './session/Session';
3
3
  import { ReplayPerformanceEntry } from './createPerformanceEntry';
4
4
  import { IEventBuffer } from './eventBuffer';
5
- import type { AllPerformanceEntry, InitialState, InstrumentationTypeBreadcrumb, InstrumentationTypeSpan, RecordedEvents, RecordingEvent, RecordingOptions, ReplayConfiguration, ReplayPluginOptions, SendReplayRequest } from './types';
5
+ import type { AllPerformanceEntry, InitialState, InstrumentationTypeBreadcrumb, InstrumentationTypeSpan, RecordingEvent, RecordingOptions, ReplayConfiguration, ReplayPluginOptions, SendReplay } from './types';
6
6
  /**
7
7
  * Returns true to return control to calling function, otherwise continue with normal batching
8
8
  */
@@ -278,16 +278,11 @@ export declare class Replay implements Integration {
278
278
  /**
279
279
  * Send replay attachment using `fetch()`
280
280
  */
281
- sendReplayRequest({ endpoint, events, replayId: event_id, segmentId: segment_id, includeReplayStartTimestamp, }: SendReplayRequest): Promise<void>;
281
+ sendReplayRequest({ events, replayId: event_id, segmentId: segment_id, includeReplayStartTimestamp, }: SendReplay): Promise<void | undefined>;
282
282
  resetRetries(): void;
283
283
  /**
284
284
  * Finalize and send the current replay event to Sentry
285
285
  */
286
- sendReplay({ replayId, events, segmentId, includeReplayStartTimestamp, }: {
287
- replayId: string;
288
- events: RecordedEvents;
289
- segmentId: number;
290
- includeReplayStartTimestamp: boolean;
291
- }): Promise<unknown>;
286
+ sendReplay({ replayId, events, segmentId, includeReplayStartTimestamp, }: SendReplay): Promise<unknown>;
292
287
  }
293
288
  export {};
@@ -49,6 +49,7 @@ export declare class Session {
49
49
  constructor(session: Partial<SessionObject> | undefined, { stickySession, sessionSampleRate, errorSampleRate, }: StickyOption & SampleRates);
50
50
  get id(): string;
51
51
  get started(): number;
52
+ set started(newDate: number);
52
53
  get lastActivity(): number;
53
54
  set lastActivity(newDate: number);
54
55
  get segmentId(): number;
@@ -3,8 +3,7 @@ export declare type RecordingEvent = eventWithTime;
3
3
  export declare type RecordingOptions = recordOptions<eventWithTime>;
4
4
  export declare type RecordedEvents = Uint8Array | string;
5
5
  export declare type AllPerformanceEntry = PerformancePaintTiming | PerformanceResourceTiming | PerformanceNavigationTiming;
6
- export interface SendReplayRequest {
7
- endpoint: string;
6
+ export interface SendReplay {
8
7
  events: RecordedEvents;
9
8
  replayId: string;
10
9
  segmentId: number;
package/dist/index.es.js CHANGED
@@ -1,5 +1,5 @@
1
- import { getCurrentHub, addBreadcrumb, captureException, addGlobalEventProcessor, setContext, getEnvelopeEndpointWithUrlEncodedAuth } from '@sentry/core';
2
- import { htmlTreeAsString, logger as logger$1, uuid4, browserPerformanceTimeOrigin, addInstrumentationHandler, createEnvelope, serializeEnvelope } from '@sentry/utils';
1
+ import { getCurrentHub, addBreadcrumb, captureException, addGlobalEventProcessor, setContext } from '@sentry/core';
2
+ import { htmlTreeAsString, logger as logger$1, uuid4, browserPerformanceTimeOrigin, addInstrumentationHandler, createEnvelope } from '@sentry/utils';
3
3
  import debounce from 'lodash.debounce';
4
4
  import { record, EventType } from 'rrweb';
5
5
 
@@ -373,6 +373,12 @@ var Session = /** @class */ (function () {
373
373
  get: function () {
374
374
  return this._started;
375
375
  },
376
+ set: function (newDate) {
377
+ this._started = newDate;
378
+ if (this.options.stickySession) {
379
+ saveSession(this);
380
+ }
381
+ },
376
382
  enumerable: false,
377
383
  configurable: true
378
384
  });
@@ -981,7 +987,7 @@ var Replay = /** @class */ (function () {
981
987
  * when an error occurs.
982
988
  **/
983
989
  this.handleGlobalEvent = function (event) {
984
- var _a, _b, _c, _d;
990
+ var _a, _b, _c, _d, _e;
985
991
  // Do not apply replayId to the root event
986
992
  if (
987
993
  // @ts-expect-error new event type
@@ -991,15 +997,20 @@ var Replay = /** @class */ (function () {
991
997
  delete event.breadcrumbs;
992
998
  return event;
993
999
  }
994
- event.tags = __assign(__assign({}, event.tags), { replayId: (_a = _this.session) === null || _a === void 0 ? void 0 : _a.id });
1000
+ // Only tag transactions with replayId if not waiting for an error
1001
+ if (event.type !== 'transaction' || !_this.waitForError) {
1002
+ event.tags = __assign(__assign({}, event.tags), { replayId: (_a = _this.session) === null || _a === void 0 ? void 0 : _a.id });
1003
+ }
1004
+ // Collect traceIds in context regardless of `waitForError` - if it's true,
1005
+ // context gets cleared on every checkout
995
1006
  if (event.type === 'transaction') {
996
- _this.context.traceIds.add(String(((_b = event.contexts) === null || _b === void 0 ? void 0 : _b.trace.trace_id) || ''));
1007
+ _this.context.traceIds.add(String(((_c = (_b = event.contexts) === null || _b === void 0 ? void 0 : _b.trace) === null || _c === void 0 ? void 0 : _c.trace_id) || ''));
997
1008
  return event;
998
1009
  }
999
1010
  // XXX: Is it safe to assume that all other events are error events?
1000
1011
  // @ts-expect-error: Type 'undefined' is not assignable to type 'string'.ts(2345)
1001
1012
  _this.context.errorIds.add(event.event_id);
1002
- var exc = (_d = (_c = event.exception) === null || _c === void 0 ? void 0 : _c.values) === null || _d === void 0 ? void 0 : _d[0];
1013
+ var exc = (_e = (_d = event.exception) === null || _d === void 0 ? void 0 : _d.values) === null || _e === void 0 ? void 0 : _e[0];
1003
1014
  addInternalBreadcrumb({
1004
1015
  message: "Tagging event (".concat(event.event_id, ") - ").concat(event.message, " - ").concat((exc === null || exc === void 0 ? void 0 : exc.type) || 'Unknown', ": ").concat((exc === null || exc === void 0 ? void 0 : exc.value) || 'n/a'),
1005
1016
  });
@@ -1011,8 +1022,17 @@ var Replay = /** @class */ (function () {
1011
1022
  setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
1012
1023
  return __generator(this, function (_a) {
1013
1024
  switch (_a.label) {
1014
- case 0: return [4 /*yield*/, this.flushImmediate()];
1025
+ case 0:
1026
+ // Allow flush to complete before resuming as a session recording, otherwise
1027
+ // the checkout from `startRecording` may be included in the payload.
1028
+ // Prefer to keep the error replay as a separate (and smaller) segment
1029
+ // than the session replay.
1030
+ return [4 /*yield*/, this.flushImmediate()];
1015
1031
  case 1:
1032
+ // Allow flush to complete before resuming as a session recording, otherwise
1033
+ // the checkout from `startRecording` may be included in the payload.
1034
+ // Prefer to keep the error replay as a separate (and smaller) segment
1035
+ // than the session replay.
1016
1036
  _a.sent();
1017
1037
  if (this.stopRecording) {
1018
1038
  this.stopRecording();
@@ -1042,6 +1062,14 @@ var Replay = /** @class */ (function () {
1042
1062
  }
1043
1063
  _this.addUpdate(function () {
1044
1064
  var _a, _b;
1065
+ // The session is always started immediately on pageload/init, but for
1066
+ // error-only replays, it should reflect the most recent checkout
1067
+ // when an error occurs. Clear any state that happens before this current
1068
+ // checkout. This needs to happen before `addEvent()` which updates state
1069
+ // dependent on this reset.
1070
+ if (_this.waitForError && event.type === 2) {
1071
+ _this.setInitialState();
1072
+ }
1045
1073
  // We need to clear existing events on a checkout, otherwise they are
1046
1074
  // incremental event updates and should be appended
1047
1075
  _this.addEvent(event, isCheckout);
@@ -1059,6 +1087,11 @@ var Replay = /** @class */ (function () {
1059
1087
  if ((_a = _this.session) === null || _a === void 0 ? void 0 : _a.previousSessionId) {
1060
1088
  return true;
1061
1089
  }
1090
+ // See note above re: session start needs to reflect the most recent
1091
+ // checkout.
1092
+ if (_this.waitForError && _this.session && _this.context.earliestEvent) {
1093
+ _this.session.started = _this.context.earliestEvent;
1094
+ }
1062
1095
  // If the full snapshot is due to an initial load, we will not have
1063
1096
  // a previous session ID. In this case, we want to buffer events
1064
1097
  // for a set amount of time before flushing. This can help avoid
@@ -1846,13 +1879,13 @@ var Replay = /** @class */ (function () {
1846
1879
  * Send replay attachment using `fetch()`
1847
1880
  */
1848
1881
  Replay.prototype.sendReplayRequest = function (_a) {
1849
- var endpoint = _a.endpoint, events = _a.events, event_id = _a.replayId, segment_id = _a.segmentId, includeReplayStartTimestamp = _a.includeReplayStartTimestamp;
1882
+ var _b;
1883
+ var events = _a.events, event_id = _a.replayId, segment_id = _a.segmentId, includeReplayStartTimestamp = _a.includeReplayStartTimestamp;
1850
1884
  return __awaiter(this, void 0, void 0, function () {
1851
- var payloadWithSequence, _b, urls, errorIds, traceIds, initialState, timestamp, sdkInfo, replayEvent, envelope, response, _c, _d;
1852
- var _e;
1885
+ var payloadWithSequence, _c, urls, errorIds, traceIds, initialState, timestamp, sdkInfo, replayEvent, envelope, client;
1853
1886
  var _this = this;
1854
- return __generator(this, function (_f) {
1855
- switch (_f.label) {
1887
+ return __generator(this, function (_d) {
1888
+ switch (_d.label) {
1856
1889
  case 0:
1857
1890
  payloadWithSequence = createPayload({
1858
1891
  events: events,
@@ -1860,11 +1893,11 @@ var Replay = /** @class */ (function () {
1860
1893
  segment_id: segment_id,
1861
1894
  },
1862
1895
  });
1863
- _b = this.popEventContext(), urls = _b.urls, errorIds = _b.errorIds, traceIds = _b.traceIds, initialState = _b.initialState;
1896
+ _c = this.popEventContext(), urls = _c.urls, errorIds = _c.errorIds, traceIds = _c.traceIds, initialState = _c.initialState;
1864
1897
  timestamp = new Date().getTime();
1865
1898
  sdkInfo = {
1866
1899
  name: 'sentry.javascript.integration.replay',
1867
- version: "0.6.13",
1900
+ version: "0.6.14-1",
1868
1901
  };
1869
1902
  return [4 /*yield*/, new Promise(function (resolve) {
1870
1903
  var _a;
@@ -1889,7 +1922,7 @@ var Replay = /** @class */ (function () {
1889
1922
  }); });
1890
1923
  })];
1891
1924
  case 1:
1892
- replayEvent = _f.sent();
1925
+ replayEvent = _d.sent();
1893
1926
  envelope = createEnvelope({
1894
1927
  event_id: event_id,
1895
1928
  sent_at: new Date().toISOString(),
@@ -1907,26 +1940,14 @@ var Replay = /** @class */ (function () {
1907
1940
  payloadWithSequence,
1908
1941
  ],
1909
1942
  ]);
1910
- // Otherwise use `fetch`, which *WILL* get cancelled on page reloads/unloads
1911
- logger.log("uploading attachment via fetch()");
1912
- return [4 /*yield*/, fetch(endpoint, {
1913
- method: 'POST',
1914
- body: serializeEnvelope(envelope),
1915
- })];
1916
- case 2:
1917
- response = _f.sent();
1918
- if (!(response.status !== 200)) return [3 /*break*/, 4];
1919
- _c = setContext;
1920
- _d = ['Send Replay Response'];
1921
- _e = {
1922
- status: response.status
1923
- };
1924
- return [4 /*yield*/, response.text()];
1925
- case 3:
1926
- _c.apply(void 0, _d.concat([(_e.body = _f.sent(),
1927
- _e)]));
1928
- throw new Error(UNABLE_TO_SEND_REPLAY);
1929
- case 4: return [2 /*return*/];
1943
+ client = getCurrentHub().getClient();
1944
+ try {
1945
+ return [2 /*return*/, (_b = client === null || client === void 0 ? void 0 : client.getTransport()) === null || _b === void 0 ? void 0 : _b.send(envelope)];
1946
+ }
1947
+ catch (_e) {
1948
+ throw new Error(UNABLE_TO_SEND_REPLAY);
1949
+ }
1950
+ return [2 /*return*/];
1930
1951
  }
1931
1952
  });
1932
1953
  });
@@ -1941,7 +1962,7 @@ var Replay = /** @class */ (function () {
1941
1962
  Replay.prototype.sendReplay = function (_a) {
1942
1963
  var replayId = _a.replayId, events = _a.events, segmentId = _a.segmentId, includeReplayStartTimestamp = _a.includeReplayStartTimestamp;
1943
1964
  return __awaiter(this, void 0, void 0, function () {
1944
- var client, endpoint, ex_1;
1965
+ var ex_1;
1945
1966
  var _this = this;
1946
1967
  return __generator(this, function (_b) {
1947
1968
  switch (_b.label) {
@@ -1950,13 +1971,10 @@ var Replay = /** @class */ (function () {
1950
1971
  if (!events.length) {
1951
1972
  return [2 /*return*/];
1952
1973
  }
1953
- client = getCurrentHub().getClient();
1954
- endpoint = getEnvelopeEndpointWithUrlEncodedAuth(client.getDsn());
1955
1974
  _b.label = 1;
1956
1975
  case 1:
1957
1976
  _b.trys.push([1, 3, , 5]);
1958
1977
  return [4 /*yield*/, this.sendReplayRequest({
1959
- endpoint: endpoint,
1960
1978
  events: events,
1961
1979
  replayId: replayId,
1962
1980
  segmentId: segmentId,
package/dist/index.js CHANGED
@@ -381,6 +381,12 @@ var Session = /** @class */ (function () {
381
381
  get: function () {
382
382
  return this._started;
383
383
  },
384
+ set: function (newDate) {
385
+ this._started = newDate;
386
+ if (this.options.stickySession) {
387
+ saveSession(this);
388
+ }
389
+ },
384
390
  enumerable: false,
385
391
  configurable: true
386
392
  });
@@ -989,7 +995,7 @@ var Replay = /** @class */ (function () {
989
995
  * when an error occurs.
990
996
  **/
991
997
  this.handleGlobalEvent = function (event) {
992
- var _a, _b, _c, _d;
998
+ var _a, _b, _c, _d, _e;
993
999
  // Do not apply replayId to the root event
994
1000
  if (
995
1001
  // @ts-expect-error new event type
@@ -999,15 +1005,20 @@ var Replay = /** @class */ (function () {
999
1005
  delete event.breadcrumbs;
1000
1006
  return event;
1001
1007
  }
1002
- event.tags = __assign(__assign({}, event.tags), { replayId: (_a = _this.session) === null || _a === void 0 ? void 0 : _a.id });
1008
+ // Only tag transactions with replayId if not waiting for an error
1009
+ if (event.type !== 'transaction' || !_this.waitForError) {
1010
+ event.tags = __assign(__assign({}, event.tags), { replayId: (_a = _this.session) === null || _a === void 0 ? void 0 : _a.id });
1011
+ }
1012
+ // Collect traceIds in context regardless of `waitForError` - if it's true,
1013
+ // context gets cleared on every checkout
1003
1014
  if (event.type === 'transaction') {
1004
- _this.context.traceIds.add(String(((_b = event.contexts) === null || _b === void 0 ? void 0 : _b.trace.trace_id) || ''));
1015
+ _this.context.traceIds.add(String(((_c = (_b = event.contexts) === null || _b === void 0 ? void 0 : _b.trace) === null || _c === void 0 ? void 0 : _c.trace_id) || ''));
1005
1016
  return event;
1006
1017
  }
1007
1018
  // XXX: Is it safe to assume that all other events are error events?
1008
1019
  // @ts-expect-error: Type 'undefined' is not assignable to type 'string'.ts(2345)
1009
1020
  _this.context.errorIds.add(event.event_id);
1010
- var exc = (_d = (_c = event.exception) === null || _c === void 0 ? void 0 : _c.values) === null || _d === void 0 ? void 0 : _d[0];
1021
+ var exc = (_e = (_d = event.exception) === null || _d === void 0 ? void 0 : _d.values) === null || _e === void 0 ? void 0 : _e[0];
1011
1022
  addInternalBreadcrumb({
1012
1023
  message: "Tagging event (".concat(event.event_id, ") - ").concat(event.message, " - ").concat((exc === null || exc === void 0 ? void 0 : exc.type) || 'Unknown', ": ").concat((exc === null || exc === void 0 ? void 0 : exc.value) || 'n/a'),
1013
1024
  });
@@ -1019,8 +1030,17 @@ var Replay = /** @class */ (function () {
1019
1030
  setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
1020
1031
  return __generator(this, function (_a) {
1021
1032
  switch (_a.label) {
1022
- case 0: return [4 /*yield*/, this.flushImmediate()];
1033
+ case 0:
1034
+ // Allow flush to complete before resuming as a session recording, otherwise
1035
+ // the checkout from `startRecording` may be included in the payload.
1036
+ // Prefer to keep the error replay as a separate (and smaller) segment
1037
+ // than the session replay.
1038
+ return [4 /*yield*/, this.flushImmediate()];
1023
1039
  case 1:
1040
+ // Allow flush to complete before resuming as a session recording, otherwise
1041
+ // the checkout from `startRecording` may be included in the payload.
1042
+ // Prefer to keep the error replay as a separate (and smaller) segment
1043
+ // than the session replay.
1024
1044
  _a.sent();
1025
1045
  if (this.stopRecording) {
1026
1046
  this.stopRecording();
@@ -1050,6 +1070,14 @@ var Replay = /** @class */ (function () {
1050
1070
  }
1051
1071
  _this.addUpdate(function () {
1052
1072
  var _a, _b;
1073
+ // The session is always started immediately on pageload/init, but for
1074
+ // error-only replays, it should reflect the most recent checkout
1075
+ // when an error occurs. Clear any state that happens before this current
1076
+ // checkout. This needs to happen before `addEvent()` which updates state
1077
+ // dependent on this reset.
1078
+ if (_this.waitForError && event.type === 2) {
1079
+ _this.setInitialState();
1080
+ }
1053
1081
  // We need to clear existing events on a checkout, otherwise they are
1054
1082
  // incremental event updates and should be appended
1055
1083
  _this.addEvent(event, isCheckout);
@@ -1067,6 +1095,11 @@ var Replay = /** @class */ (function () {
1067
1095
  if ((_a = _this.session) === null || _a === void 0 ? void 0 : _a.previousSessionId) {
1068
1096
  return true;
1069
1097
  }
1098
+ // See note above re: session start needs to reflect the most recent
1099
+ // checkout.
1100
+ if (_this.waitForError && _this.session && _this.context.earliestEvent) {
1101
+ _this.session.started = _this.context.earliestEvent;
1102
+ }
1070
1103
  // If the full snapshot is due to an initial load, we will not have
1071
1104
  // a previous session ID. In this case, we want to buffer events
1072
1105
  // for a set amount of time before flushing. This can help avoid
@@ -1854,13 +1887,13 @@ var Replay = /** @class */ (function () {
1854
1887
  * Send replay attachment using `fetch()`
1855
1888
  */
1856
1889
  Replay.prototype.sendReplayRequest = function (_a) {
1857
- var endpoint = _a.endpoint, events = _a.events, event_id = _a.replayId, segment_id = _a.segmentId, includeReplayStartTimestamp = _a.includeReplayStartTimestamp;
1890
+ var _b;
1891
+ var events = _a.events, event_id = _a.replayId, segment_id = _a.segmentId, includeReplayStartTimestamp = _a.includeReplayStartTimestamp;
1858
1892
  return __awaiter(this, void 0, void 0, function () {
1859
- var payloadWithSequence, _b, urls, errorIds, traceIds, initialState, timestamp, sdkInfo, replayEvent, envelope, response, _c, _d;
1860
- var _e;
1893
+ var payloadWithSequence, _c, urls, errorIds, traceIds, initialState, timestamp, sdkInfo, replayEvent, envelope, client;
1861
1894
  var _this = this;
1862
- return __generator(this, function (_f) {
1863
- switch (_f.label) {
1895
+ return __generator(this, function (_d) {
1896
+ switch (_d.label) {
1864
1897
  case 0:
1865
1898
  payloadWithSequence = createPayload({
1866
1899
  events: events,
@@ -1868,11 +1901,11 @@ var Replay = /** @class */ (function () {
1868
1901
  segment_id: segment_id,
1869
1902
  },
1870
1903
  });
1871
- _b = this.popEventContext(), urls = _b.urls, errorIds = _b.errorIds, traceIds = _b.traceIds, initialState = _b.initialState;
1904
+ _c = this.popEventContext(), urls = _c.urls, errorIds = _c.errorIds, traceIds = _c.traceIds, initialState = _c.initialState;
1872
1905
  timestamp = new Date().getTime();
1873
1906
  sdkInfo = {
1874
1907
  name: 'sentry.javascript.integration.replay',
1875
- version: "0.6.13",
1908
+ version: "0.6.14-1",
1876
1909
  };
1877
1910
  return [4 /*yield*/, new Promise(function (resolve) {
1878
1911
  var _a;
@@ -1897,7 +1930,7 @@ var Replay = /** @class */ (function () {
1897
1930
  }); });
1898
1931
  })];
1899
1932
  case 1:
1900
- replayEvent = _f.sent();
1933
+ replayEvent = _d.sent();
1901
1934
  envelope = utils.createEnvelope({
1902
1935
  event_id: event_id,
1903
1936
  sent_at: new Date().toISOString(),
@@ -1915,26 +1948,14 @@ var Replay = /** @class */ (function () {
1915
1948
  payloadWithSequence,
1916
1949
  ],
1917
1950
  ]);
1918
- // Otherwise use `fetch`, which *WILL* get cancelled on page reloads/unloads
1919
- logger.log("uploading attachment via fetch()");
1920
- return [4 /*yield*/, fetch(endpoint, {
1921
- method: 'POST',
1922
- body: utils.serializeEnvelope(envelope),
1923
- })];
1924
- case 2:
1925
- response = _f.sent();
1926
- if (!(response.status !== 200)) return [3 /*break*/, 4];
1927
- _c = core.setContext;
1928
- _d = ['Send Replay Response'];
1929
- _e = {
1930
- status: response.status
1931
- };
1932
- return [4 /*yield*/, response.text()];
1933
- case 3:
1934
- _c.apply(void 0, _d.concat([(_e.body = _f.sent(),
1935
- _e)]));
1936
- throw new Error(UNABLE_TO_SEND_REPLAY);
1937
- case 4: return [2 /*return*/];
1951
+ client = core.getCurrentHub().getClient();
1952
+ try {
1953
+ return [2 /*return*/, (_b = client === null || client === void 0 ? void 0 : client.getTransport()) === null || _b === void 0 ? void 0 : _b.send(envelope)];
1954
+ }
1955
+ catch (_e) {
1956
+ throw new Error(UNABLE_TO_SEND_REPLAY);
1957
+ }
1958
+ return [2 /*return*/];
1938
1959
  }
1939
1960
  });
1940
1961
  });
@@ -1949,7 +1970,7 @@ var Replay = /** @class */ (function () {
1949
1970
  Replay.prototype.sendReplay = function (_a) {
1950
1971
  var replayId = _a.replayId, events = _a.events, segmentId = _a.segmentId, includeReplayStartTimestamp = _a.includeReplayStartTimestamp;
1951
1972
  return __awaiter(this, void 0, void 0, function () {
1952
- var client, endpoint, ex_1;
1973
+ var ex_1;
1953
1974
  var _this = this;
1954
1975
  return __generator(this, function (_b) {
1955
1976
  switch (_b.label) {
@@ -1958,13 +1979,10 @@ var Replay = /** @class */ (function () {
1958
1979
  if (!events.length) {
1959
1980
  return [2 /*return*/];
1960
1981
  }
1961
- client = core.getCurrentHub().getClient();
1962
- endpoint = core.getEnvelopeEndpointWithUrlEncodedAuth(client.getDsn());
1963
1982
  _b.label = 1;
1964
1983
  case 1:
1965
1984
  _b.trys.push([1, 3, , 5]);
1966
1985
  return [4 /*yield*/, this.sendReplayRequest({
1967
- endpoint: endpoint,
1968
1986
  events: events,
1969
1987
  replayId: replayId,
1970
1988
  segmentId: segmentId,