|
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 |
|
@@ -1226,28 +1233,13 @@ export class ReplayContainer implements ReplayContainerInterface {
|
1226 | 1233 | return;
|
1227 | 1234 | }
|
1228 | 1235 |
|
1229 |
| - const start = this.session.started; |
1230 |
| - const now = Date.now(); |
1231 |
| - const duration = now - start; |
1232 |
| - |
1233 | 1236 | // A flush is about to happen, cancel any queued flushes
|
1234 | 1237 | this._debouncedFlush.cancel();
|
1235 | 1238 |
|
1236 |
| - // If session is too short, or too long (allow some wiggle room over maxReplayDuration), do not send it |
1237 |
| - // This _should_ not happen, but it may happen if flush is triggered due to a page activity change or similar |
1238 |
| - const tooShort = duration < this._options.minReplayDuration; |
1239 |
| - const tooLong = duration > this._options.maxReplayDuration + 5_000; |
1240 |
| - if (tooShort || tooLong) { |
1241 |
| - DEBUG_BUILD && |
1242 |
| - logger.info( |
1243 |
| - `Session duration (${Math.floor(duration / 1000)}s) is too ${ |
1244 |
| - tooShort ? 'short' : 'long' |
1245 |
| - }, not sending replay.`, |
1246 |
| - ); |
| 1239 | + const isValidDuration = this._checkReplayDurationDuringFlush(); |
1247 | 1240 |
|
1248 |
| - if (tooShort) { |
1249 |
| - this._debouncedFlush(); |
1250 |
| - } |
| 1241 | + // XXX: disregard durations for buffer mode for debug purposes |
| 1242 | + if (!isValidDuration && this.recordingMode !== 'buffer') { |
1251 | 1243 | return;
|
1252 | 1244 | }
|
1253 | 1245 |
|
@@ -1283,6 +1275,48 @@ export class ReplayContainer implements ReplayContainerInterface {
|
1283 | 1275 | }
|
1284 | 1276 | };
|
1285 | 1277 |
|
| 1278 | + /** |
| 1279 | + * Checks to see if replay duration is within bounds during a flush. If it is |
| 1280 | + * too short, will queue up a new flush to prevent short replays. |
| 1281 | + * |
| 1282 | + * Returns true if duration is ok, false otherwise |
| 1283 | + */ |
| 1284 | + private _checkReplayDurationDuringFlush(): boolean { |
| 1285 | + if (!this.session) { |
| 1286 | + return false; |
| 1287 | + } |
| 1288 | + |
| 1289 | + const start = this.session.started; |
| 1290 | + const now = Date.now(); |
| 1291 | + const duration = now - start; |
| 1292 | + |
| 1293 | + // If session is too short, or too long (allow some wiggle room over maxReplayDuration), do not send it |
| 1294 | + // This _should_ not happen, but it may happen if flush is triggered due to a page activity change or similar |
| 1295 | + const tooShort = duration < this._options.minReplayDuration; |
| 1296 | + const tooLong = duration > this._options.maxReplayDuration + 5_000; |
| 1297 | + if (tooShort || tooLong) { |
| 1298 | + DEBUG_BUILD && |
| 1299 | + logger.info( |
| 1300 | + `Session duration (${Math.floor(duration / 1000)}s) is too ${ |
| 1301 | + tooShort ? 'short' : 'long' |
| 1302 | + }, not sending replay.`, |
| 1303 | + ); |
| 1304 | + |
| 1305 | + if (tooShort) { |
| 1306 | + this._debouncedFlush(); |
| 1307 | + } |
| 1308 | + |
| 1309 | + // XXX: disregard durations for buffer mode for debug purposes |
| 1310 | + if (this.recordingMode === 'buffer') { |
| 1311 | + setTag(`replay.${tooShort ? 'tooShort' : 'tooLong'}`, true); |
| 1312 | + } |
| 1313 | + |
| 1314 | + return false; |
| 1315 | + } |
| 1316 | + |
| 1317 | + return true; |
| 1318 | + } |
| 1319 | + |
1286 | 1320 | /** Save the session, if it is sticky */
|
1287 | 1321 | private _maybeSaveSession(): void {
|
1288 | 1322 | if (this.session && this._options.stickySession) {
|
|
0 commit comments