|
1 | 1 | /* eslint-disable max-lines */ // TODO: We might want to split this file up
|
2 | 2 | import { EventType, record } from '@sentry-internal/rrweb';
|
3 |
| -import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, getActiveSpan, getClient, getRootSpan, spanToJSON } from '@sentry/core'; |
| 3 | +import { |
| 4 | + SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, |
| 5 | + getActiveSpan, |
| 6 | + getClient, |
| 7 | + getRootSpan, |
| 8 | + setTag, |
| 9 | + spanToJSON, |
| 10 | +} from '@sentry/core'; |
4 | 11 | import type { ReplayRecordingMode, Span } from '@sentry/types';
|
5 | 12 | import { logger } from './util/logger';
|
6 | 13 |
|
@@ -1215,28 +1222,13 @@ export class ReplayContainer implements ReplayContainerInterface {
|
1215 | 1222 | return;
|
1216 | 1223 | }
|
1217 | 1224 |
|
1218 |
| - const start = this.session.started; |
1219 |
| - const now = Date.now(); |
1220 |
| - const duration = now - start; |
1221 |
| - |
1222 | 1225 | // A flush is about to happen, cancel any queued flushes
|
1223 | 1226 | this._debouncedFlush.cancel();
|
1224 | 1227 |
|
1225 |
| - // If session is too short, or too long (allow some wiggle room over maxReplayDuration), do not send it |
1226 |
| - // This _should_ not happen, but it may happen if flush is triggered due to a page activity change or similar |
1227 |
| - const tooShort = duration < this._options.minReplayDuration; |
1228 |
| - const tooLong = duration > this._options.maxReplayDuration + 5_000; |
1229 |
| - if (tooShort || tooLong) { |
1230 |
| - DEBUG_BUILD && |
1231 |
| - logger.info( |
1232 |
| - `Session duration (${Math.floor(duration / 1000)}s) is too ${ |
1233 |
| - tooShort ? 'short' : 'long' |
1234 |
| - }, not sending replay.`, |
1235 |
| - ); |
| 1228 | + const isValidDuration = this._checkReplayDurationDuringFlush(); |
1236 | 1229 |
|
1237 |
| - if (tooShort) { |
1238 |
| - this._debouncedFlush(); |
1239 |
| - } |
| 1230 | + // XXX: disregard durations for buffer mode for debug purposes |
| 1231 | + if (!isValidDuration && this.recordingMode !== 'buffer') { |
1240 | 1232 | return;
|
1241 | 1233 | }
|
1242 | 1234 |
|
@@ -1272,6 +1264,48 @@ export class ReplayContainer implements ReplayContainerInterface {
|
1272 | 1264 | }
|
1273 | 1265 | };
|
1274 | 1266 |
|
| 1267 | + /** |
| 1268 | + * Checks to see if replay duration is within bounds during a flush. If it is |
| 1269 | + * too short, will queue up a new flush to prevent short replays. |
| 1270 | + * |
| 1271 | + * Returns true if duration is ok, false otherwise |
| 1272 | + */ |
| 1273 | + private _checkReplayDurationDuringFlush(): boolean { |
| 1274 | + if (!this.session) { |
| 1275 | + return false; |
| 1276 | + } |
| 1277 | + |
| 1278 | + const start = this.session.started; |
| 1279 | + const now = Date.now(); |
| 1280 | + const duration = now - start; |
| 1281 | + |
| 1282 | + // If session is too short, or too long (allow some wiggle room over maxReplayDuration), do not send it |
| 1283 | + // This _should_ not happen, but it may happen if flush is triggered due to a page activity change or similar |
| 1284 | + const tooShort = duration < this._options.minReplayDuration; |
| 1285 | + const tooLong = duration > this._options.maxReplayDuration + 5_000; |
| 1286 | + if (tooShort || tooLong) { |
| 1287 | + DEBUG_BUILD && |
| 1288 | + logger.info( |
| 1289 | + `Session duration (${Math.floor(duration / 1000)}s) is too ${ |
| 1290 | + tooShort ? 'short' : 'long' |
| 1291 | + }, not sending replay.`, |
| 1292 | + ); |
| 1293 | + |
| 1294 | + if (tooShort) { |
| 1295 | + this._debouncedFlush(); |
| 1296 | + } |
| 1297 | + |
| 1298 | + // XXX: disregard durations for buffer mode for debug purposes |
| 1299 | + if (this.recordingMode === 'buffer') { |
| 1300 | + setTag(`replay.${tooShort ? 'tooShort' : 'tooLong'}`, true); |
| 1301 | + } |
| 1302 | + |
| 1303 | + return false; |
| 1304 | + } |
| 1305 | + |
| 1306 | + return true; |
| 1307 | + } |
| 1308 | + |
1275 | 1309 | /** Save the session, if it is sticky */
|
1276 | 1310 | private _maybeSaveSession(): void {
|
1277 | 1311 | if (this.session && this._options.stickySession) {
|
|
0 commit comments