@cloudcare/browser-rum 3.3.22 → 3.3.24
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/bundle/dataflux-rum.js +1 -1
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/boot/rum.js +7 -6
- package/cjs/boot/rum.js.map +1 -1
- package/cjs/domain/deflate/deflateWorker.js +1 -1
- package/cjs/domain/performanceUtils.js +6 -1
- package/cjs/domain/performanceUtils.js.map +1 -1
- package/cjs/domain/replay/record/canvasEncodeWorker.js +1 -1
- package/cjs/domain/replay/segmentCollection/segmentCollection.js +3 -1
- package/cjs/domain/replay/segmentCollection/segmentCollection.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackNavigationTimings.js +25 -3
- package/cjs/domain/rumEventsCollection/view/trackNavigationTimings.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackViews.js +56 -32
- package/cjs/domain/rumEventsCollection/view/trackViews.js.map +1 -1
- package/cjs/transport/startRumBatch.js +4 -0
- package/cjs/transport/startRumBatch.js.map +1 -1
- package/esm/boot/buildEnv.js +2 -5
- package/esm/boot/buildEnv.js.map +1 -1
- package/esm/boot/disabledRumPublicApi.js +2 -35
- package/esm/boot/disabledRumPublicApi.js.map +1 -1
- package/esm/boot/perStartRum.js +2 -260
- package/esm/boot/perStartRum.js.map +1 -1
- package/esm/boot/recorderApi.js +2 -338
- package/esm/boot/recorderApi.js.map +1 -1
- package/esm/boot/recorderApiStub.js +2 -21
- package/esm/boot/recorderApiStub.js.map +1 -1
- package/esm/boot/rum.entry.js +2 -13
- package/esm/boot/rum.entry.js.map +1 -1
- package/esm/boot/rum.js +2 -183
- package/esm/boot/rum.js.map +1 -1
- package/esm/boot/rum.slim.entry.js +2 -7
- package/esm/boot/rum.slim.entry.js.map +1 -1
- package/esm/boot/rumEntryFactory.js +2 -18
- package/esm/boot/rumEntryFactory.js.map +1 -1
- package/esm/boot/rumPublicApi.js +2 -344
- package/esm/boot/rumPublicApi.js.map +1 -1
- package/esm/boot/rumRecorderApiStub.js +2 -13
- package/esm/boot/rumRecorderApiStub.js.map +1 -1
- package/esm/boot/rumSlimConfiguration.js +2 -10
- package/esm/boot/rumSlimConfiguration.js.map +1 -1
- package/esm/boot/sessionReplayPublicApi.js +2 -43
- package/esm/boot/sessionReplayPublicApi.js.map +1 -1
- package/esm/boot/startRecording.js +2 -444
- package/esm/boot/startRecording.js.map +1 -1
- package/esm/constants.js +2 -28
- package/esm/constants.js.map +1 -1
- package/esm/domain/assembly.js +2 -213
- package/esm/domain/assembly.js.map +1 -1
- package/esm/domain/configuration.js +2 -323
- package/esm/domain/configuration.js.map +1 -1
- package/esm/domain/contexts/commonContext.js +2 -8
- package/esm/domain/contexts/commonContext.js.map +1 -1
- package/esm/domain/contexts/displayContext.js +2 -16
- package/esm/domain/contexts/displayContext.js.map +1 -1
- package/esm/domain/contexts/foregroundContexts.js +2 -103
- package/esm/domain/contexts/foregroundContexts.js.map +1 -1
- package/esm/domain/contexts/internalContext.js +2 -41
- package/esm/domain/contexts/internalContext.js.map +1 -1
- package/esm/domain/contexts/pageStateHistory.js +2 -104
- package/esm/domain/contexts/pageStateHistory.js.map +1 -1
- package/esm/domain/contexts/urlContexts.js +2 -85
- package/esm/domain/contexts/urlContexts.js.map +1 -1
- package/esm/domain/contexts/viewContexts.js +2 -45
- package/esm/domain/contexts/viewContexts.js.map +1 -1
- package/esm/domain/deflate/deflateEncoder.js +2 -592
- package/esm/domain/deflate/deflateEncoder.js.map +1 -1
- package/esm/domain/deflate/deflateWorker.js +2 -225
- package/esm/domain/deflate/deflateWorker.js.map +1 -1
- package/esm/domain/deflate/index.js +2 -3
- package/esm/domain/deflate/index.js.map +1 -1
- package/esm/domain/domMutationObservable.js +2 -62
- package/esm/domain/domMutationObservable.js.map +1 -1
- package/esm/domain/encoderStreamId.js +2 -6
- package/esm/domain/encoderStreamId.js.map +1 -1
- package/esm/domain/firstInputPolyfill.js +2 -77
- package/esm/domain/firstInputPolyfill.js.map +1 -1
- package/esm/domain/initViewportObservable.js +2 -36
- package/esm/domain/initViewportObservable.js.map +1 -1
- package/esm/domain/locationChangeObservable.js +2 -65
- package/esm/domain/locationChangeObservable.js.map +1 -1
- package/esm/domain/performanceObservable.js +2 -116
- package/esm/domain/performanceObservable.js.map +1 -1
- package/esm/domain/performanceUtils.js +2 -40
- package/esm/domain/performanceUtils.js.map +1 -1
- package/esm/domain/plugins.js +2 -59
- package/esm/domain/plugins.js.map +1 -1
- package/esm/domain/privacy.js +2 -266
- package/esm/domain/privacy.js.map +1 -1
- package/esm/domain/replay/record/canvasAutoSnapshot.js +2 -9
- package/esm/domain/replay/record/canvasAutoSnapshot.js.map +1 -1
- package/esm/domain/replay/record/canvasCommandCapture.js +2 -1275
- package/esm/domain/replay/record/canvasCommandCapture.js.map +1 -1
- package/esm/domain/replay/record/canvasCommandObserver.js +2 -1207
- package/esm/domain/replay/record/canvasCommandObserver.js.map +1 -1
- package/esm/domain/replay/record/canvasCommandSerializeArgs.js +2 -111
- package/esm/domain/replay/record/canvasCommandSerializeArgs.js.map +1 -1
- package/esm/domain/replay/record/canvasContext.js +2 -50
- package/esm/domain/replay/record/canvasContext.js.map +1 -1
- package/esm/domain/replay/record/canvasContinuousScheduler.js +2 -378
- package/esm/domain/replay/record/canvasContinuousScheduler.js.map +1 -1
- package/esm/domain/replay/record/canvasEncodeBridge.js +2 -692
- package/esm/domain/replay/record/canvasEncodeBridge.js.map +1 -1
- package/esm/domain/replay/record/canvasEncodeWorker.js +2 -164
- package/esm/domain/replay/record/canvasEncodeWorker.js.map +1 -1
- package/esm/domain/replay/record/canvasFrameSignature.js +2 -75
- package/esm/domain/replay/record/canvasFrameSignature.js.map +1 -1
- package/esm/domain/replay/record/canvasMutationRecord.js +2 -26
- package/esm/domain/replay/record/canvasMutationRecord.js.map +1 -1
- package/esm/domain/replay/record/canvasObserver.js +2 -420
- package/esm/domain/replay/record/canvasObserver.js.map +1 -1
- package/esm/domain/replay/record/canvasSerializeArgs.js +2 -101
- package/esm/domain/replay/record/canvasSerializeArgs.js.map +1 -1
- package/esm/domain/replay/record/canvasWebGLPluginHost.js +2 -26
- package/esm/domain/replay/record/canvasWebGLPluginHost.js.map +1 -1
- package/esm/domain/replay/record/elementsScrollPositions.js +2 -23
- package/esm/domain/replay/record/elementsScrollPositions.js.map +1 -1
- package/esm/domain/replay/record/index.js +2 -4
- package/esm/domain/replay/record/index.js.map +1 -1
- package/esm/domain/replay/record/mutationBatch.js +2 -562
- package/esm/domain/replay/record/mutationBatch.js.map +1 -1
- package/esm/domain/replay/record/mutationObserver.js +2 -2332
- package/esm/domain/replay/record/mutationObserver.js.map +1 -1
- package/esm/domain/replay/record/mutationResourceBudget.js +2 -137
- package/esm/domain/replay/record/mutationResourceBudget.js.map +1 -1
- package/esm/domain/replay/record/observers.js +2 -624
- package/esm/domain/replay/record/observers.js.map +1 -1
- package/esm/domain/replay/record/privacy.js +2 -1
- package/esm/domain/replay/record/privacy.js.map +1 -1
- package/esm/domain/replay/record/record.js +2 -3511
- package/esm/domain/replay/record/record.js.map +1 -1
- package/esm/domain/replay/record/serializationUtils.js +2 -677
- package/esm/domain/replay/record/serializationUtils.js.map +1 -1
- package/esm/domain/replay/record/serialize.js +2 -735
- package/esm/domain/replay/record/serialize.js.map +1 -1
- package/esm/domain/replay/record/shadowRootsController.js +2 -902
- package/esm/domain/replay/record/shadowRootsController.js.map +1 -1
- package/esm/domain/replay/record/utils.js +2 -36
- package/esm/domain/replay/record/utils.js.map +1 -1
- package/esm/domain/replay/record/viewports.js +2 -58
- package/esm/domain/replay/record/viewports.js.map +1 -1
- package/esm/domain/replay/replayStats.js +2 -59
- package/esm/domain/replay/replayStats.js.map +1 -1
- package/esm/domain/replay/segmentCollection/buildReplayPayload.js +2 -31
- package/esm/domain/replay/segmentCollection/buildReplayPayload.js.map +1 -1
- package/esm/domain/replay/segmentCollection/index.js +2 -3
- package/esm/domain/replay/segmentCollection/index.js.map +1 -1
- package/esm/domain/replay/segmentCollection/segment.js +2 -415
- package/esm/domain/replay/segmentCollection/segment.js.map +1 -1
- package/esm/domain/replay/segmentCollection/segmentCollection.js +2 -1112
- package/esm/domain/replay/segmentCollection/segmentCollection.js.map +1 -1
- package/esm/domain/replay/startRecordBridge.js +2 -13
- package/esm/domain/replay/startRecordBridge.js.map +1 -1
- package/esm/domain/replay/timeAnchor.js +2 -20
- package/esm/domain/replay/timeAnchor.js.map +1 -1
- package/esm/domain/requestCollection.js +2 -121
- package/esm/domain/requestCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/actionCollection.js +2 -83
- package/esm/domain/rumEventsCollection/actions/actionCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/clickChain.js +2 -62
- package/esm/domain/rumEventsCollection/actions/clickChain.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/computeFrustration.js +2 -67
- package/esm/domain/rumEventsCollection/actions/computeFrustration.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/getActionNameFromElement.js +2 -279
- package/esm/domain/rumEventsCollection/actions/getActionNameFromElement.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/getSelectorsFromElement.js +2 -233
- package/esm/domain/rumEventsCollection/actions/getSelectorsFromElement.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/interactionSelectorCache.js +2 -21
- package/esm/domain/rumEventsCollection/actions/interactionSelectorCache.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/listenActionEvents.js +2 -67
- package/esm/domain/rumEventsCollection/actions/listenActionEvents.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/trackClickActions.js +2 -263
- package/esm/domain/rumEventsCollection/actions/trackClickActions.js.map +1 -1
- package/esm/domain/rumEventsCollection/error/errorCollection.js +2 -93
- package/esm/domain/rumEventsCollection/error/errorCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/error/trackConsoleError.js +2 -12
- package/esm/domain/rumEventsCollection/error/trackConsoleError.js.map +1 -1
- package/esm/domain/rumEventsCollection/error/trackReportError.js +2 -19
- package/esm/domain/rumEventsCollection/error/trackReportError.js.map +1 -1
- package/esm/domain/rumEventsCollection/longTask/longAnimationFrameCollection.js +2 -55
- package/esm/domain/rumEventsCollection/longTask/longAnimationFrameCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/longTask/longTaskCollection.js +2 -38
- package/esm/domain/rumEventsCollection/longTask/longTaskCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/matchRequestResourceEntry.js +2 -69
- package/esm/domain/rumEventsCollection/resource/matchRequestResourceEntry.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/resourceCollection.js +2 -294
- package/esm/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/resourceTrackerManager.js +2 -232
- package/esm/domain/rumEventsCollection/resource/resourceTrackerManager.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/resourceUtils.js +2 -218
- package/esm/domain/rumEventsCollection/resource/resourceUtils.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js +2 -19
- package/esm/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/webSocketCollection.js +2 -191
- package/esm/domain/rumEventsCollection/resource/webSocketCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/interactionCountPolyfill.js +2 -47
- package/esm/domain/rumEventsCollection/view/interactionCountPolyfill.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackCommonViewMetrics.js +2 -42
- package/esm/domain/rumEventsCollection/view/trackCommonViewMetrics.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +2 -117
- package/esm/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackFirstContentfulPaint.js +2 -20
- package/esm/domain/rumEventsCollection/view/trackFirstContentfulPaint.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackFirstHidden.js +2 -49
- package/esm/domain/rumEventsCollection/view/trackFirstHidden.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackFirstInput.js +2 -41
- package/esm/domain/rumEventsCollection/view/trackFirstInput.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackInitialViewTimings.js +2 -44
- package/esm/domain/rumEventsCollection/view/trackInitialViewTimings.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackInteractionToNextPaint.js +2 -153
- package/esm/domain/rumEventsCollection/view/trackInteractionToNextPaint.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackLargestContentfulPaint.js +2 -54
- package/esm/domain/rumEventsCollection/view/trackLargestContentfulPaint.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackLoadingTime.js +2 -50
- package/esm/domain/rumEventsCollection/view/trackLoadingTime.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackNavigationTimings.js +2 -51
- package/esm/domain/rumEventsCollection/view/trackNavigationTimings.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackScrollMetrics.js +2 -84
- package/esm/domain/rumEventsCollection/view/trackScrollMetrics.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackSoftNavigationMetrics.js +2 -38
- package/esm/domain/rumEventsCollection/view/trackSoftNavigationMetrics.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackViewEventCounts.js +2 -15
- package/esm/domain/rumEventsCollection/view/trackViewEventCounts.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackViews.js +2 -394
- package/esm/domain/rumEventsCollection/view/trackViews.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/viewCollection.js +2 -127
- package/esm/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
- package/esm/domain/rumSessionManager.js +2 -208
- package/esm/domain/rumSessionManager.js.map +1 -1
- package/esm/domain/tracing/ddtraceTracer.js +2 -40
- package/esm/domain/tracing/ddtraceTracer.js.map +1 -1
- package/esm/domain/tracing/getDocumentTraceId.js +2 -69
- package/esm/domain/tracing/getDocumentTraceId.js.map +1 -1
- package/esm/domain/tracing/jaegerTracer.js +2 -42
- package/esm/domain/tracing/jaegerTracer.js.map +1 -1
- package/esm/domain/tracing/sampler.js +2 -61
- package/esm/domain/tracing/sampler.js.map +1 -1
- package/esm/domain/tracing/skywalkingTracer.js +2 -90
- package/esm/domain/tracing/skywalkingTracer.js.map +1 -1
- package/esm/domain/tracing/traceIdentifier.js +2 -57
- package/esm/domain/tracing/traceIdentifier.js.map +1 -1
- package/esm/domain/tracing/tracer.js +2 -128
- package/esm/domain/tracing/tracer.js.map +1 -1
- package/esm/domain/tracing/w3cTraceParentTracer.js +2 -69
- package/esm/domain/tracing/w3cTraceParentTracer.js.map +1 -1
- package/esm/domain/tracing/zipkinMultiTracer.js +2 -42
- package/esm/domain/tracing/zipkinMultiTracer.js.map +1 -1
- package/esm/domain/tracing/zipkinSingleTracer.js +2 -41
- package/esm/domain/tracing/zipkinSingleTracer.js.map +1 -1
- package/esm/domain/trackEventCounts.js +2 -49
- package/esm/domain/trackEventCounts.js.map +1 -1
- package/esm/domain/usr/index.js +2 -38
- package/esm/domain/usr/index.js.map +1 -1
- package/esm/domain/visitorId/index.js +2 -406
- package/esm/domain/visitorId/index.js.map +1 -1
- package/esm/domain/waitPageActivityEnd.js +2 -142
- package/esm/domain/waitPageActivityEnd.js.map +1 -1
- package/esm/index.js +2 -4
- package/esm/index.js.map +1 -1
- package/esm/transport/startRumBatch.js +2 -70
- package/esm/transport/startRumBatch.js.map +1 -1
- package/esm/transport/startRumEventBridge.js +2 -9
- package/esm/transport/startRumEventBridge.js.map +1 -1
- package/esm/types/index.js +2 -1
- package/esm/types/index.js.map +1 -1
- package/esm/types/sessionReplayConstants.js +2 -46
- package/esm/types/sessionReplayConstants.js.map +1 -1
- package/package.json +5 -5
- package/src/boot/rum.js +7 -6
- package/src/domain/performanceUtils.js +17 -1
- package/src/domain/replay/segmentCollection/segmentCollection.js +6 -1
- package/src/domain/rumEventsCollection/view/trackNavigationTimings.js +37 -3
- package/src/domain/rumEventsCollection/view/trackViews.js +66 -38
- package/src/transport/startRumBatch.js +4 -0
|
@@ -1,1112 +1,2 @@
|
|
|
1
|
-
import { ONE_SECOND, LifeCycleEventType, isPageExitReason, PageExitReason, assign, addTelemetryDebug, dateNow, setTimeout, clearTimeout } from '@cloudcare/browser-core';
|
|
2
|
-
|
|
3
|
-
import { buildReplayPayload } from './buildReplayPayload';
|
|
4
|
-
import { createSegment } from './segment';
|
|
5
|
-
import { isSessionReplayTimeAnchor, SESSION_REPLAY_TIME_ANCHOR_BACKPRESSURE_RESERVE } from '../timeAnchor';
|
|
6
|
-
export var SEGMENT_DURATION_LIMIT = 5 * ONE_SECOND;
|
|
7
|
-
/**
|
|
8
|
-
* beacon payload max queue size implementation is 64kb
|
|
9
|
-
* ensure that we leave room for logs, rum and potential other users
|
|
10
|
-
*/
|
|
11
|
-
export var SEGMENT_BYTES_LIMIT = 60000;
|
|
12
|
-
// buildReplayPayload() exposes the compressed segment size, but sendBeacon
|
|
13
|
-
// accounts for the multipart boundaries, headers, and metadata fields too.
|
|
14
|
-
// Reserve a conservative envelope per segment so several small unload
|
|
15
|
-
// segments cannot collectively overrun the browser's exit delivery queue.
|
|
16
|
-
var SEGMENT_FORM_DATA_ESTIMATED_OVERHEAD = 2 * 1024;
|
|
17
|
-
var SEGMENT_PENDING_RAW_BYTES_LIMIT = 4 * 1024 * 1024;
|
|
18
|
-
var LOCKED_SEGMENTS_LIMIT = 12;
|
|
19
|
-
var REPLAY_MEMORY_BUDGET_BYTES = 48 * 1024 * 1024;
|
|
20
|
-
var CANVAS_FLUSH_MIN_INTERVAL = 250;
|
|
21
|
-
var MAX_CONSECUTIVE_FULL_SNAPSHOT_FAILURES = 3;
|
|
22
|
-
|
|
23
|
-
// Segments are the main data structure for session replays. They contain context information used
|
|
24
|
-
// for indexing or UI needs, and a list of records (RRWeb 'events', renamed to avoid confusing
|
|
25
|
-
// namings). They are stored without any processing from the intake, and fetched one after the
|
|
26
|
-
// other while a session is being replayed. Their encoding (deflate) are carefully crafted to allow
|
|
27
|
-
// concatenating multiple segments together. Segments have a size overhead (metadata), so our goal is to
|
|
28
|
-
// build segments containing as many records as possible while complying with the various flush
|
|
29
|
-
// strategies to guarantee a good replay quality.
|
|
30
|
-
//
|
|
31
|
-
// When the recording starts, a segment is initially created. The segment is flushed (finalized and
|
|
32
|
-
// sent) based on various events (non-exhaustive list):
|
|
33
|
-
//
|
|
34
|
-
// * the page visibility change or becomes to unload
|
|
35
|
-
// * the segment duration reaches a limit
|
|
36
|
-
// * the encoded segment bytes count reaches a limit
|
|
37
|
-
// * ...
|
|
38
|
-
//
|
|
39
|
-
// A segment cannot be created without its context. If the RUM session ends and no session id is
|
|
40
|
-
// available when creating a new segment, records will be ignored, until the session is renewed and
|
|
41
|
-
// a new session id is available.
|
|
42
|
-
//
|
|
43
|
-
// Empty segments (segments with no record) aren't useful and should be ignored.
|
|
44
|
-
//
|
|
45
|
-
// To help investigate session replays issues, each segment is created with a "creation reason",
|
|
46
|
-
// indicating why the session has been created.
|
|
47
|
-
|
|
48
|
-
export function startSegmentCollection(lifeCycle, configuration, sessionManager, viewContexts, httpRequest, encoder) {
|
|
49
|
-
var isLocked = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
|
|
50
|
-
var additionalOptions = arguments.length > 7 ? arguments[7] : undefined;
|
|
51
|
-
return doStartSegmentCollection(lifeCycle, function () {
|
|
52
|
-
return computeSegmentContext(configuration, sessionManager, viewContexts);
|
|
53
|
-
}, httpRequest, encoder, isLocked, assign({
|
|
54
|
-
flushCanvasImmediately: configuration.replayCanvasFlushImmediately,
|
|
55
|
-
pendingRawBytesLimit: SEGMENT_PENDING_RAW_BYTES_LIMIT,
|
|
56
|
-
beforePageExitFlush: undefined,
|
|
57
|
-
onReplayResetNeeded: undefined,
|
|
58
|
-
onReplayResetExhausted: undefined,
|
|
59
|
-
onSegmentFlushed: undefined
|
|
60
|
-
}, additionalOptions));
|
|
61
|
-
}
|
|
62
|
-
var SegmentCollectionStatus = {
|
|
63
|
-
WaitingForInitialRecord: 0,
|
|
64
|
-
SegmentPending: 1,
|
|
65
|
-
Stopped: 2
|
|
66
|
-
};
|
|
67
|
-
export function doStartSegmentCollection(lifeCycle, getSegmentContext, httpRequest, encoder, isLocked, options) {
|
|
68
|
-
if (options === undefined) {
|
|
69
|
-
options = {};
|
|
70
|
-
}
|
|
71
|
-
var pendingRawBytesLimit = typeof options.pendingRawBytesLimit === 'number' ? options.pendingRawBytesLimit : SEGMENT_PENDING_RAW_BYTES_LIMIT;
|
|
72
|
-
var lockedSegments = [];
|
|
73
|
-
var memoryBudget = options.memoryBudget;
|
|
74
|
-
var lockedBufferGeneration = 0;
|
|
75
|
-
var reportedDropReasons = {};
|
|
76
|
-
var lastCanvasFlushAt = -Infinity;
|
|
77
|
-
var canvasFlushTimeoutId;
|
|
78
|
-
var replayResetNeeded = false;
|
|
79
|
-
var replayResetReason;
|
|
80
|
-
var replayResetNotificationSent = false;
|
|
81
|
-
var replayResetNotificationTimeoutId;
|
|
82
|
-
var activeBaselineGeneration = 0;
|
|
83
|
-
var nextBaselineGeneration = 0;
|
|
84
|
-
var baselineGenerationStates = {};
|
|
85
|
-
var transportGenerationStates = {};
|
|
86
|
-
var baselineGenerationInFlightCounts = {};
|
|
87
|
-
var pendingSegmentResultsByGeneration = {};
|
|
88
|
-
var consecutiveFullSnapshotFailures = 0;
|
|
89
|
-
var replayRecoveryExhausted = false;
|
|
90
|
-
var lifecycleSubscriptionsStopped = false;
|
|
91
|
-
var nextSegmentFlushSequence = 0;
|
|
92
|
-
var inFlightSegmentFlushes = new Set();
|
|
93
|
-
var lastAddRecordWasBackpressured = false;
|
|
94
|
-
var backpressuredSerializedRecordData = new WeakMap();
|
|
95
|
-
var unloadingTransportLatched = false;
|
|
96
|
-
var unloadingDeliveryBytesRemaining;
|
|
97
|
-
var unloadingDeliveryBudgetExhausted = false;
|
|
98
|
-
var unloadingRetryPayloadsDrained = false;
|
|
99
|
-
var mandatoryRecoveryPending = false;
|
|
100
|
-
var bufferCheckoutPending = false;
|
|
101
|
-
var activeBaselineTransaction;
|
|
102
|
-
var state = {
|
|
103
|
-
$rStatus: SegmentCollectionStatus.WaitingForInitialRecord,
|
|
104
|
-
$rNextReason: 'init',
|
|
105
|
-
$rLocked: isLocked,
|
|
106
|
-
$rGeneration: activeBaselineGeneration
|
|
107
|
-
};
|
|
108
|
-
if (memoryBudget) {
|
|
109
|
-
memoryBudget.$rSegment = getSegmentMemoryUsage;
|
|
110
|
-
}
|
|
111
|
-
function prepareRecordsBeforePageExit(pageExitEvent) {
|
|
112
|
-
if (!options.beforePageExitFlush) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
try {
|
|
116
|
-
return options.beforePageExitFlush(pageExitEvent);
|
|
117
|
-
} catch (error) {
|
|
118
|
-
addTelemetryDebug('Session Replay failed to prepare records before page exit.', {
|
|
119
|
-
reason: pageExitEvent && pageExitEvent.reason,
|
|
120
|
-
error: String(error)
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
var subscribeViewCreated = lifeCycle.subscribe(LifeCycleEventType.VIEW_CREATED, function () {
|
|
125
|
-
flushSegment('view_change');
|
|
126
|
-
});
|
|
127
|
-
var unsubscribeViewCreated = subscribeViewCreated.unsubscribe;
|
|
128
|
-
var subscribePageExited = lifeCycle.subscribe(LifeCycleEventType.PAGE_EXITED, function (pageExitEvent) {
|
|
129
|
-
if (state.$rStatus === SegmentCollectionStatus.Stopped) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
prepareRecordsBeforePageExit(pageExitEvent);
|
|
133
|
-
upgradeSegmentTransportsForPageExit(pageExitEvent.reason);
|
|
134
|
-
if (state.$rLocked && pageExitEvent.reason === PageExitReason.UNLOADING) {
|
|
135
|
-
lockedBufferGeneration += 1;
|
|
136
|
-
lockedSegments = [];
|
|
137
|
-
}
|
|
138
|
-
flushSegment(pageExitEvent.reason);
|
|
139
|
-
if (flushPendingSegmentEncodingsForUnload(pageExitEvent.reason)) {
|
|
140
|
-
// The synchronous drain releases encoder backpressure. Give staged DOM
|
|
141
|
-
// mutations one final admission pass, then flush that second segment
|
|
142
|
-
// through the same unload-safe transport.
|
|
143
|
-
prepareRecordsBeforePageExit(pageExitEvent);
|
|
144
|
-
flushSegment(pageExitEvent.reason);
|
|
145
|
-
flushPendingSegmentEncodingsForUnload(pageExitEvent.reason);
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
var unsubscribePageExited = subscribePageExited.unsubscribe;
|
|
149
|
-
function reportDroppedRecord(reason, estimatedBytesCount) {
|
|
150
|
-
if (reportedDropReasons[reason]) {
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
reportedDropReasons[reason] = true;
|
|
154
|
-
addTelemetryDebug('Session Replay record discarded.', {
|
|
155
|
-
reason: reason,
|
|
156
|
-
estimated_bytes_count: estimatedBytesCount
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
function clearReplayResetNotificationTimeout() {
|
|
160
|
-
if (replayResetNotificationTimeoutId !== undefined) {
|
|
161
|
-
clearTimeout(replayResetNotificationTimeoutId);
|
|
162
|
-
replayResetNotificationTimeoutId = undefined;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
function getPendingRawBytesCount() {
|
|
166
|
-
return encoder.getPendingRawBytesCount ? encoder.getPendingRawBytesCount() : 0;
|
|
167
|
-
}
|
|
168
|
-
function scheduleReplayResetNotification() {
|
|
169
|
-
if (!replayResetNeeded || replayResetNotificationSent || replayResetNotificationTimeoutId !== undefined || !options.onReplayResetNeeded || state.$rStatus === SegmentCollectionStatus.Stopped || getPendingRawBytesCount() > 0) {
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
replayResetNotificationTimeoutId = setTimeout(function () {
|
|
173
|
-
replayResetNotificationTimeoutId = undefined;
|
|
174
|
-
if (!replayResetNeeded || replayResetNotificationSent || state.$rStatus === SegmentCollectionStatus.Stopped || getPendingRawBytesCount() > 0) {
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
replayResetNotificationSent = true;
|
|
178
|
-
options.onReplayResetNeeded(replayResetReason);
|
|
179
|
-
}, 0);
|
|
180
|
-
}
|
|
181
|
-
function markReplayResetNeeded(reason, shouldNotifyAgain) {
|
|
182
|
-
if (!replayResetNeeded || shouldNotifyAgain) {
|
|
183
|
-
replayResetReason = reason;
|
|
184
|
-
replayResetNotificationSent = false;
|
|
185
|
-
if (shouldNotifyAgain) {
|
|
186
|
-
clearReplayResetNotificationTimeout();
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
replayResetNeeded = true;
|
|
190
|
-
scheduleReplayResetNotification();
|
|
191
|
-
}
|
|
192
|
-
function clearReplayResetNeeded() {
|
|
193
|
-
replayResetNeeded = false;
|
|
194
|
-
replayResetReason = undefined;
|
|
195
|
-
replayResetNotificationSent = false;
|
|
196
|
-
clearReplayResetNotificationTimeout();
|
|
197
|
-
}
|
|
198
|
-
function unsubscribeLifecycle() {
|
|
199
|
-
if (lifecycleSubscriptionsStopped) {
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
lifecycleSubscriptionsStopped = true;
|
|
203
|
-
unsubscribeViewCreated();
|
|
204
|
-
unsubscribePageExited();
|
|
205
|
-
}
|
|
206
|
-
function exhaustReplayRecovery(reason) {
|
|
207
|
-
if (replayRecoveryExhausted) {
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
replayRecoveryExhausted = true;
|
|
211
|
-
clearReplayResetNeeded();
|
|
212
|
-
clearCanvasFlushTimeout();
|
|
213
|
-
lockedBufferGeneration += 1;
|
|
214
|
-
lockedSegments = [];
|
|
215
|
-
baselineGenerationStates = {};
|
|
216
|
-
transportGenerationStates = {};
|
|
217
|
-
baselineGenerationInFlightCounts = {};
|
|
218
|
-
pendingSegmentResultsByGeneration = {};
|
|
219
|
-
if (state.$rStatus === SegmentCollectionStatus.SegmentPending) {
|
|
220
|
-
// A dependent segment can already exist when the asynchronous failure
|
|
221
|
-
// of the third replacement baseline arrives. Finalize-discard its
|
|
222
|
-
// shared deflate stream before stopping, otherwise a later explicit
|
|
223
|
-
// recorder restart can prepend these abandoned bytes to the new
|
|
224
|
-
// baseline.
|
|
225
|
-
discardCurrentSegment('recovery_exhausted');
|
|
226
|
-
}
|
|
227
|
-
state = {
|
|
228
|
-
$rStatus: SegmentCollectionStatus.Stopped,
|
|
229
|
-
$rLocked: false
|
|
230
|
-
};
|
|
231
|
-
unsubscribeLifecycle();
|
|
232
|
-
if (options.onReplayResetExhausted) {
|
|
233
|
-
options.onReplayResetExhausted(reason);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
function failBaselineGeneration(baselineGeneration, reason, isFullSnapshotFailure) {
|
|
237
|
-
if (baselineGeneration > 0) {
|
|
238
|
-
baselineGenerationStates[baselineGeneration] = 'invalid';
|
|
239
|
-
delete pendingSegmentResultsByGeneration[baselineGeneration];
|
|
240
|
-
}
|
|
241
|
-
if (baselineGeneration !== activeBaselineGeneration) {
|
|
242
|
-
tryCleanupBaselineGeneration(baselineGeneration);
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
if (isFullSnapshotFailure) {
|
|
246
|
-
consecutiveFullSnapshotFailures += 1;
|
|
247
|
-
if (consecutiveFullSnapshotFailures >= MAX_CONSECUTIVE_FULL_SNAPSHOT_FAILURES) {
|
|
248
|
-
exhaustReplayRecovery(reason);
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
markReplayResetNeeded(reason, true);
|
|
253
|
-
}
|
|
254
|
-
function retainBaselineGeneration(baselineGeneration) {
|
|
255
|
-
if (baselineGeneration <= 0) {
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
baselineGenerationInFlightCounts[baselineGeneration] = (baselineGenerationInFlightCounts[baselineGeneration] || 0) + 1;
|
|
259
|
-
}
|
|
260
|
-
function releaseBaselineGeneration(baselineGeneration) {
|
|
261
|
-
if (baselineGeneration <= 0 || !baselineGenerationInFlightCounts[baselineGeneration]) {
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
baselineGenerationInFlightCounts[baselineGeneration] -= 1;
|
|
265
|
-
if (!baselineGenerationInFlightCounts[baselineGeneration]) {
|
|
266
|
-
delete baselineGenerationInFlightCounts[baselineGeneration];
|
|
267
|
-
}
|
|
268
|
-
tryCleanupBaselineGeneration(baselineGeneration);
|
|
269
|
-
}
|
|
270
|
-
function tryCleanupBaselineGeneration(baselineGeneration) {
|
|
271
|
-
if (baselineGeneration <= 0 || baselineGeneration === activeBaselineGeneration || baselineGenerationInFlightCounts[baselineGeneration] || pendingSegmentResultsByGeneration[baselineGeneration]) {
|
|
272
|
-
return;
|
|
273
|
-
}
|
|
274
|
-
delete baselineGenerationStates[baselineGeneration];
|
|
275
|
-
delete transportGenerationStates[baselineGeneration];
|
|
276
|
-
}
|
|
277
|
-
function getTransportGenerationState(baselineGeneration) {
|
|
278
|
-
if (!transportGenerationStates[baselineGeneration]) {
|
|
279
|
-
transportGenerationStates[baselineGeneration] = {
|
|
280
|
-
$rValid: true
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
return transportGenerationStates[baselineGeneration];
|
|
284
|
-
}
|
|
285
|
-
function clearCanvasFlushTimeout() {
|
|
286
|
-
if (canvasFlushTimeoutId !== undefined) {
|
|
287
|
-
clearTimeout(canvasFlushTimeoutId);
|
|
288
|
-
canvasFlushTimeoutId = undefined;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
function upgradeSegmentTransportsForPageExit(flushReason) {
|
|
292
|
-
if (!isPageExitReason(flushReason)) {
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
|
-
var exitState = flushReason === PageExitReason.HIDDEN ? PageExitReason.HIDDEN : true;
|
|
296
|
-
if (flushReason === PageExitReason.UNLOADING) {
|
|
297
|
-
unloadingTransportLatched = true;
|
|
298
|
-
if (unloadingDeliveryBytesRemaining === undefined) {
|
|
299
|
-
unloadingDeliveryBytesRemaining = SEGMENT_BYTES_LIMIT;
|
|
300
|
-
}
|
|
301
|
-
drainRetryPayloadsForUnload();
|
|
302
|
-
}
|
|
303
|
-
inFlightSegmentFlushes.forEach(function (transport) {
|
|
304
|
-
transport.$rExit = exitState;
|
|
305
|
-
});
|
|
306
|
-
// A dependent segment can finish encoding before its Full Snapshot and is
|
|
307
|
-
// then removed from inFlightSegmentFlushes while waiting for the baseline
|
|
308
|
-
// generation to be confirmed. Preserve the page-exit transport intent on
|
|
309
|
-
// those completed results as well. UNLOADING still uses the shared latch
|
|
310
|
-
// and aggregate delivery budget in sendSegment().
|
|
311
|
-
Object.keys(pendingSegmentResultsByGeneration).forEach(function (baselineGeneration) {
|
|
312
|
-
pendingSegmentResultsByGeneration[baselineGeneration].forEach(function (segmentResult) {
|
|
313
|
-
segmentResult.$rExit = exitState;
|
|
314
|
-
});
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
function flushPendingSegmentEncodingsSync() {
|
|
318
|
-
if (encoder.flushPendingActionsSync) {
|
|
319
|
-
encoder.flushPendingActionsSync(SEGMENT_BYTES_LIMIT);
|
|
320
|
-
return true;
|
|
321
|
-
}
|
|
322
|
-
return false;
|
|
323
|
-
}
|
|
324
|
-
function drainRetryPayloadsForUnload() {
|
|
325
|
-
if (unloadingRetryPayloadsDrained) {
|
|
326
|
-
return;
|
|
327
|
-
}
|
|
328
|
-
unloadingRetryPayloadsDrained = true;
|
|
329
|
-
if (typeof httpRequest.$rDrainOnExit !== 'function') {
|
|
330
|
-
return;
|
|
331
|
-
}
|
|
332
|
-
var deliveryResult = httpRequest.$rDrainOnExit(unloadingDeliveryBytesRemaining);
|
|
333
|
-
if (deliveryResult && typeof deliveryResult.$rBytesCount === 'number' && isFinite(deliveryResult.$rBytesCount) && deliveryResult.$rBytesCount >= 0) {
|
|
334
|
-
unloadingDeliveryBytesRemaining = Math.max(unloadingDeliveryBytesRemaining - deliveryResult.$rBytesCount, 0);
|
|
335
|
-
if (deliveryResult.$rAllPayloadsSent === false && !deliveryResult.$rPending) {
|
|
336
|
-
// Replay segments are ordered. If an older queued payload does not fit,
|
|
337
|
-
// no current tail may overtake it.
|
|
338
|
-
unloadingDeliveryBudgetExhausted = true;
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
function flushPendingSegmentEncodingsForUnload(flushReason) {
|
|
343
|
-
return flushReason === PageExitReason.UNLOADING && flushPendingSegmentEncodingsSync();
|
|
344
|
-
}
|
|
345
|
-
function removeInFlightSegmentFlush(transport) {
|
|
346
|
-
inFlightSegmentFlushes["delete"](transport);
|
|
347
|
-
}
|
|
348
|
-
function handlePermanentTransportDrop(segmentResult, reason) {
|
|
349
|
-
// Invalidate the transport chain even after the recorder itself stopped;
|
|
350
|
-
// older queued dependents must never be promoted past the missing segment.
|
|
351
|
-
segmentResult.$rTransportGeneration.$rValid = false;
|
|
352
|
-
if (state.$rStatus === SegmentCollectionStatus.Stopped || replayRecoveryExhausted) {
|
|
353
|
-
return;
|
|
354
|
-
}
|
|
355
|
-
var dropReason = 'transport_' + reason;
|
|
356
|
-
reportDroppedRecord(dropReason, 0);
|
|
357
|
-
// Once a segment is permanently rejected, every later incremental in its
|
|
358
|
-
// generation may depend on replay state the player will never receive.
|
|
359
|
-
// Retire the generation and gate admission until a replacement Full
|
|
360
|
-
// Snapshot establishes a new chain. A transport failure is not evidence
|
|
361
|
-
// that Full Snapshot serialization itself is permanently broken.
|
|
362
|
-
failBaselineGeneration(segmentResult.$rGeneration, dropReason, false);
|
|
363
|
-
scheduleReplayResetNotification();
|
|
364
|
-
}
|
|
365
|
-
function sendSegment(segmentResult) {
|
|
366
|
-
var metadata = segmentResult.$rMetadata;
|
|
367
|
-
var encoderResult = segmentResult.$rEncoder;
|
|
368
|
-
if (false && options.onSegmentFlushed) {
|
|
369
|
-
options.onSegmentFlushed({
|
|
370
|
-
creationReason: metadata.creation_reason,
|
|
371
|
-
flushReason: segmentResult.$rReason,
|
|
372
|
-
recordsCount: metadata.records_count,
|
|
373
|
-
recordCountsByType: segmentResult.$rCounts,
|
|
374
|
-
start: metadata.start,
|
|
375
|
-
end: metadata.end,
|
|
376
|
-
indexInView: metadata.index_in_view,
|
|
377
|
-
rawBytesCount: encoderResult.rawBytesCount
|
|
378
|
-
});
|
|
379
|
-
}
|
|
380
|
-
var shouldUseExitTransport = !segmentResult.$rRegular && (segmentResult.$rExit === true || unloadingTransportLatched);
|
|
381
|
-
var estimatedDeliveryBytesCount = encoderResult.outputBytesCount + SEGMENT_FORM_DATA_ESTIMATED_OVERHEAD;
|
|
382
|
-
if (shouldUseExitTransport && unloadingTransportLatched) {
|
|
383
|
-
if (unloadingDeliveryBudgetExhausted) {
|
|
384
|
-
unloadingDeliveryBudgetExhausted = true;
|
|
385
|
-
reportDroppedRecord('page_exit_delivery_budget', estimatedDeliveryBytesCount);
|
|
386
|
-
return;
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
var payload = buildReplayPayload(encoderResult.output, metadata, encoderResult.rawBytesCount);
|
|
390
|
-
payload.$rExitBytesCount = estimatedDeliveryBytesCount;
|
|
391
|
-
payload.$rEnforceOrder = true;
|
|
392
|
-
payload.$rKeepalive = Boolean(!shouldUseExitTransport && segmentResult.$rExit === PageExitReason.HIDDEN && estimatedDeliveryBytesCount <= SEGMENT_BYTES_LIMIT);
|
|
393
|
-
payload.$rIsValid = function () {
|
|
394
|
-
return segmentResult.$rTransportGeneration.$rValid;
|
|
395
|
-
};
|
|
396
|
-
payload.$rOnPermanentDrop = function (reason) {
|
|
397
|
-
handlePermanentTransportDrop(segmentResult, reason);
|
|
398
|
-
};
|
|
399
|
-
// Blob owns the encoded bytes after buildReplayPayload(). Release the
|
|
400
|
-
// original Uint8Array reference while transport callbacks keep only the
|
|
401
|
-
// generation metadata.
|
|
402
|
-
segmentResult.$rEncoder = undefined;
|
|
403
|
-
if (shouldUseExitTransport) {
|
|
404
|
-
var exitDeliveryResult = httpRequest.sendOnExit(payload, unloadingTransportLatched ? unloadingDeliveryBytesRemaining : undefined);
|
|
405
|
-
if (unloadingTransportLatched) {
|
|
406
|
-
if (exitDeliveryResult && typeof exitDeliveryResult.$rBytesCount === 'number' && isFinite(exitDeliveryResult.$rBytesCount) && exitDeliveryResult.$rBytesCount >= 0) {
|
|
407
|
-
unloadingDeliveryBytesRemaining = Math.max(unloadingDeliveryBytesRemaining - exitDeliveryResult.$rBytesCount, 0);
|
|
408
|
-
if (!exitDeliveryResult.$rCurrentPayloadSent && !exitDeliveryResult.$rPending) {
|
|
409
|
-
unloadingDeliveryBudgetExhausted = true;
|
|
410
|
-
reportDroppedRecord('page_exit_delivery_budget', estimatedDeliveryBytesCount);
|
|
411
|
-
}
|
|
412
|
-
} else {
|
|
413
|
-
// Preserve compatibility with injected transports that predate the
|
|
414
|
-
// aggregate-budget result contract.
|
|
415
|
-
unloadingDeliveryBytesRemaining = Math.max(unloadingDeliveryBytesRemaining - estimatedDeliveryBytesCount, 0);
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
} else {
|
|
419
|
-
httpRequest.send(payload);
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
function retainLockedSegment(segmentResult) {
|
|
423
|
-
// Locked error-session buffers are only delivered after checkout. Clear
|
|
424
|
-
// any historical page-exit hint so a later unlock uses regular transport.
|
|
425
|
-
segmentResult.$rExit = false;
|
|
426
|
-
segmentResult.$rRegular = true;
|
|
427
|
-
if (replayResetNeeded) {
|
|
428
|
-
// A valid replacement snapshot clears the reset before delivery.
|
|
429
|
-
return;
|
|
430
|
-
}
|
|
431
|
-
lockedSegments.push(segmentResult);
|
|
432
|
-
var latestFullSnapshotIndex = -1;
|
|
433
|
-
for (var index = lockedSegments.length - 1; index >= 0; index -= 1) {
|
|
434
|
-
if (lockedSegments[index].$rMetadata.has_full_snapshot) {
|
|
435
|
-
latestFullSnapshotIndex = index;
|
|
436
|
-
break;
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
if (latestFullSnapshotIndex > 0) {
|
|
440
|
-
lockedSegments.splice(0, latestFullSnapshotIndex);
|
|
441
|
-
}
|
|
442
|
-
if (lockedSegments.length > LOCKED_SEGMENTS_LIMIT || memoryBudget && getSegmentMemoryUsage() + memoryBudget.$rRecord() > REPLAY_MEMORY_BUDGET_BYTES) {
|
|
443
|
-
// Incremental segments form a dependency chain. Keeping the anchor while
|
|
444
|
-
// deleting a middle segment can leave later records referencing nodes the
|
|
445
|
-
// player never received. Retire the whole lock generation and admit no
|
|
446
|
-
// more incrementals until a replacement full snapshot starts a new chain.
|
|
447
|
-
lockedBufferGeneration += 1;
|
|
448
|
-
lockedSegments = [];
|
|
449
|
-
markReplayResetNeeded('locked_buffer_capacity');
|
|
450
|
-
// Records already admitted to the current segment still belong to the
|
|
451
|
-
// overflowing lock epoch. Finalize that segment now so its immutable
|
|
452
|
-
// epoch can reject the result, and force the replacement Full Snapshot
|
|
453
|
-
// to start a clean segment.
|
|
454
|
-
flushSegment('locked_buffer_capacity');
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
function getLockedSegmentsBytesCount() {
|
|
458
|
-
return lockedSegments.reduce(function (bytesCount, segmentResult) {
|
|
459
|
-
var encoderResult = segmentResult.$rEncoder;
|
|
460
|
-
return bytesCount + (encoderResult && typeof encoderResult.outputBytesCount === 'number' ? encoderResult.outputBytesCount : 0);
|
|
461
|
-
}, 0);
|
|
462
|
-
}
|
|
463
|
-
function getSegmentMemoryUsage() {
|
|
464
|
-
return getPendingRawBytesCount() + getLockedSegmentsBytesCount() + (typeof httpRequest.$rPendingBytes === 'function' ? httpRequest.$rPendingBytes() : 0);
|
|
465
|
-
}
|
|
466
|
-
function drainLockedSegments() {
|
|
467
|
-
var segmentsToSend = lockedSegments;
|
|
468
|
-
lockedSegments = [];
|
|
469
|
-
if (segmentsToSend.length > 0 && !segmentsToSend.some(function (segmentResult) {
|
|
470
|
-
return segmentResult.$rMetadata.has_full_snapshot;
|
|
471
|
-
})) {
|
|
472
|
-
markReplayResetNeeded('locked_buffer_missing_full_snapshot');
|
|
473
|
-
return;
|
|
474
|
-
}
|
|
475
|
-
segmentsToSend.forEach(function (segmentResult) {
|
|
476
|
-
segmentResult.$rExit = false;
|
|
477
|
-
segmentResult.$rRegular = true;
|
|
478
|
-
sendSegment(segmentResult);
|
|
479
|
-
});
|
|
480
|
-
}
|
|
481
|
-
function deliverSegmentResult(segmentResult) {
|
|
482
|
-
if (!segmentResult.$rLocked) {
|
|
483
|
-
sendSegment(segmentResult);
|
|
484
|
-
return;
|
|
485
|
-
}
|
|
486
|
-
if (segmentResult.$rLockGeneration !== lockedBufferGeneration || segmentResult.$rReason === 'buffer_checkout' || segmentResult.$rReason === 'stop' || segmentResult.$rReason === PageExitReason.UNLOADING) {
|
|
487
|
-
return;
|
|
488
|
-
}
|
|
489
|
-
if (state.$rLocked) {
|
|
490
|
-
retainLockedSegment(segmentResult);
|
|
491
|
-
} else {
|
|
492
|
-
segmentResult.$rExit = false;
|
|
493
|
-
segmentResult.$rRegular = true;
|
|
494
|
-
sendSegment(segmentResult);
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
function retainPendingSegmentResult(baselineGeneration, segmentResult) {
|
|
498
|
-
if (!pendingSegmentResultsByGeneration[baselineGeneration]) {
|
|
499
|
-
pendingSegmentResultsByGeneration[baselineGeneration] = [];
|
|
500
|
-
}
|
|
501
|
-
pendingSegmentResultsByGeneration[baselineGeneration].push(segmentResult);
|
|
502
|
-
}
|
|
503
|
-
function confirmBaselineGeneration(baselineGeneration, segmentResult) {
|
|
504
|
-
if (replayRecoveryExhausted || baselineGenerationStates[baselineGeneration] === 'invalid') {
|
|
505
|
-
return;
|
|
506
|
-
}
|
|
507
|
-
baselineGenerationStates[baselineGeneration] = 'confirmed';
|
|
508
|
-
if (baselineGeneration === activeBaselineGeneration && (!replayResetNeeded || !segmentResult.$rLocked || segmentResult.$rLockGeneration === lockedBufferGeneration)) {
|
|
509
|
-
consecutiveFullSnapshotFailures = 0;
|
|
510
|
-
clearReplayResetNeeded();
|
|
511
|
-
}
|
|
512
|
-
deliverSegmentResult(segmentResult);
|
|
513
|
-
var pendingSegmentResults = pendingSegmentResultsByGeneration[baselineGeneration] || [];
|
|
514
|
-
delete pendingSegmentResultsByGeneration[baselineGeneration];
|
|
515
|
-
pendingSegmentResults.sort(function (first, second) {
|
|
516
|
-
return first.$rSequence - second.$rSequence;
|
|
517
|
-
});
|
|
518
|
-
pendingSegmentResults.forEach(deliverSegmentResult);
|
|
519
|
-
tryCleanupBaselineGeneration(baselineGeneration);
|
|
520
|
-
}
|
|
521
|
-
function handleSuccessfulSegment(baselineGeneration, segmentResult) {
|
|
522
|
-
if (segmentResult.$rMetadata.has_full_snapshot) {
|
|
523
|
-
confirmBaselineGeneration(baselineGeneration, segmentResult);
|
|
524
|
-
return;
|
|
525
|
-
}
|
|
526
|
-
if (baselineGeneration === 0) {
|
|
527
|
-
deliverSegmentResult(segmentResult);
|
|
528
|
-
return;
|
|
529
|
-
}
|
|
530
|
-
var baselineState = baselineGenerationStates[baselineGeneration];
|
|
531
|
-
if (baselineState === 'confirmed') {
|
|
532
|
-
deliverSegmentResult(segmentResult);
|
|
533
|
-
} else if (baselineState === 'pending') {
|
|
534
|
-
retainPendingSegmentResult(baselineGeneration, segmentResult);
|
|
535
|
-
} else if (baselineGeneration === activeBaselineGeneration && !replayRecoveryExhausted) {
|
|
536
|
-
failBaselineGeneration(baselineGeneration, 'missing_full_snapshot', false);
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
function resetState(flushReason) {
|
|
540
|
-
if (flushReason !== 'stop') {
|
|
541
|
-
state = {
|
|
542
|
-
$rStatus: SegmentCollectionStatus.WaitingForInitialRecord,
|
|
543
|
-
$rNextReason: flushReason,
|
|
544
|
-
$rLocked: state.$rLocked,
|
|
545
|
-
$rGeneration: activeBaselineGeneration
|
|
546
|
-
};
|
|
547
|
-
} else {
|
|
548
|
-
state = {
|
|
549
|
-
$rStatus: SegmentCollectionStatus.Stopped,
|
|
550
|
-
$rLocked: false
|
|
551
|
-
};
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
function handleFlushedSegment(flushReason, wasLocked, lockedGeneration, baselineGeneration, metadata, encoderResult, recordCountsByType, transport) {
|
|
555
|
-
if (replayRecoveryExhausted) {
|
|
556
|
-
return;
|
|
557
|
-
}
|
|
558
|
-
if (encoderResult.error) {
|
|
559
|
-
reportDroppedRecord('encoder_error', 0);
|
|
560
|
-
failBaselineGeneration(baselineGeneration, 'encoder_error', metadata.has_full_snapshot);
|
|
561
|
-
scheduleReplayResetNotification();
|
|
562
|
-
return;
|
|
563
|
-
}
|
|
564
|
-
// SEGMENT_BYTES_LIMIT is a rolling target and a beacon budget, not a hard
|
|
565
|
-
// limit for regular fetch requests. The asynchronous deflate result can
|
|
566
|
-
// legitimately overshoot its estimate. Discarding that finalized segment
|
|
567
|
-
// would invalidate the replay chain and can force an impossible
|
|
568
|
-
// replacement snapshot on large pages. sendSegment() applies the bounded
|
|
569
|
-
// page-exit delivery budget separately.
|
|
570
|
-
var segmentResult = {
|
|
571
|
-
$rMetadata: metadata,
|
|
572
|
-
$rEncoder: encoderResult,
|
|
573
|
-
$rReason: flushReason,
|
|
574
|
-
$rExit: transport.$rExit,
|
|
575
|
-
$rLocked: wasLocked,
|
|
576
|
-
$rLockGeneration: lockedGeneration,
|
|
577
|
-
$rGeneration: baselineGeneration,
|
|
578
|
-
$rTransportGeneration: getTransportGenerationState(baselineGeneration),
|
|
579
|
-
$rSequence: transport.$rSequence
|
|
580
|
-
};
|
|
581
|
-
if (false) {
|
|
582
|
-
segmentResult.$rCounts = recordCountsByType;
|
|
583
|
-
}
|
|
584
|
-
handleSuccessfulSegment(baselineGeneration, segmentResult);
|
|
585
|
-
scheduleReplayResetNotification();
|
|
586
|
-
}
|
|
587
|
-
function flushSegment(flushReason, callback, isStopping) {
|
|
588
|
-
if (state.$rStatus === SegmentCollectionStatus.Stopped) {
|
|
589
|
-
if (callback) {
|
|
590
|
-
callback();
|
|
591
|
-
}
|
|
592
|
-
return;
|
|
593
|
-
}
|
|
594
|
-
if (state.$rStatus === SegmentCollectionStatus.SegmentPending && state.$rMandatoryRecoveryHold) {
|
|
595
|
-
if (isStopping) {
|
|
596
|
-
mandatoryRecoveryPending = false;
|
|
597
|
-
discardCurrentSegment('mandatory_recovery_incomplete');
|
|
598
|
-
// discardCurrentSegment() normally returns to Waiting so a recovery
|
|
599
|
-
// baseline can create the next stream. A terminal stop must override
|
|
600
|
-
// that reusable state even though the discard finish is asynchronous.
|
|
601
|
-
resetState('stop');
|
|
602
|
-
}
|
|
603
|
-
if (callback) {
|
|
604
|
-
callback();
|
|
605
|
-
}
|
|
606
|
-
return;
|
|
607
|
-
}
|
|
608
|
-
if (flushReason !== 'canvas_snapshot') {
|
|
609
|
-
clearCanvasFlushTimeout();
|
|
610
|
-
}
|
|
611
|
-
if (state.$rStatus === SegmentCollectionStatus.SegmentPending) {
|
|
612
|
-
var segmentState = state;
|
|
613
|
-
var wasLocked = segmentState.$rLocked;
|
|
614
|
-
var lockedGeneration = segmentState.$rLockGeneration;
|
|
615
|
-
var baselineGeneration = state.$rGeneration;
|
|
616
|
-
var transport = {
|
|
617
|
-
$rExit: flushReason === PageExitReason.HIDDEN ? PageExitReason.HIDDEN : isPageExitReason(flushReason),
|
|
618
|
-
$rSequence: ++nextSegmentFlushSequence
|
|
619
|
-
};
|
|
620
|
-
clearTimeout(state.$rExpiration);
|
|
621
|
-
resetState(isStopping ? 'stop' : flushReason);
|
|
622
|
-
if (!segmentState.$rSegment.isEmpty()) {
|
|
623
|
-
inFlightSegmentFlushes.add(transport);
|
|
624
|
-
retainBaselineGeneration(baselineGeneration);
|
|
625
|
-
segmentState.$rSegment.flush(function (metadata, encoderResult, recordCountsByType) {
|
|
626
|
-
removeInFlightSegmentFlush(transport);
|
|
627
|
-
try {
|
|
628
|
-
handleFlushedSegment(flushReason, wasLocked, lockedGeneration, baselineGeneration, metadata, encoderResult, recordCountsByType, transport);
|
|
629
|
-
} finally {
|
|
630
|
-
releaseBaselineGeneration(baselineGeneration);
|
|
631
|
-
}
|
|
632
|
-
if (callback) {
|
|
633
|
-
callback();
|
|
634
|
-
}
|
|
635
|
-
});
|
|
636
|
-
return;
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
resetState(isStopping ? 'stop' : flushReason);
|
|
640
|
-
if (callback) {
|
|
641
|
-
callback();
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
function ensureSegment() {
|
|
645
|
-
if (state.$rStatus !== SegmentCollectionStatus.WaitingForInitialRecord) {
|
|
646
|
-
return state.$rStatus === SegmentCollectionStatus.SegmentPending;
|
|
647
|
-
}
|
|
648
|
-
var context = getSegmentContext();
|
|
649
|
-
if (!context) {
|
|
650
|
-
return false;
|
|
651
|
-
}
|
|
652
|
-
state = {
|
|
653
|
-
$rStatus: SegmentCollectionStatus.SegmentPending,
|
|
654
|
-
$rSegment: createSegment({
|
|
655
|
-
encoder: encoder,
|
|
656
|
-
context: context,
|
|
657
|
-
creationReason: state.$rNextReason
|
|
658
|
-
}),
|
|
659
|
-
$rLocked: state.$rLocked,
|
|
660
|
-
$rLockGeneration: lockedBufferGeneration,
|
|
661
|
-
$rGeneration: activeBaselineGeneration,
|
|
662
|
-
$rHasSnapshot: false,
|
|
663
|
-
$rMandatoryRecoveryHold: mandatoryRecoveryPending,
|
|
664
|
-
$rExpiration: setTimeout(function () {
|
|
665
|
-
flushSegment('segment_duration_limit');
|
|
666
|
-
}, SEGMENT_DURATION_LIMIT)
|
|
667
|
-
};
|
|
668
|
-
return true;
|
|
669
|
-
}
|
|
670
|
-
function discardEmptyCurrentSegment(reason) {
|
|
671
|
-
if (state.$rStatus === SegmentCollectionStatus.SegmentPending && state.$rSegment.isEmpty()) {
|
|
672
|
-
clearTimeout(state.$rExpiration);
|
|
673
|
-
resetState(reason);
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
function discardCurrentSegment(reason) {
|
|
677
|
-
if (state.$rStatus !== SegmentCollectionStatus.SegmentPending) {
|
|
678
|
-
return;
|
|
679
|
-
}
|
|
680
|
-
var discardedSegment = state.$rSegment;
|
|
681
|
-
var isEmpty = discardedSegment.isEmpty();
|
|
682
|
-
clearTimeout(state.$rExpiration);
|
|
683
|
-
resetState(reason);
|
|
684
|
-
if (!isEmpty) {
|
|
685
|
-
// The deflate encoder is shared by consecutive segments. Merely
|
|
686
|
-
// forgetting this Segment would leave its already-written bytes in the
|
|
687
|
-
// active stream and prepend them to the replacement baseline. Finalize
|
|
688
|
-
// the stream to reset the encoder, but deliberately ignore its result.
|
|
689
|
-
discardedSegment.$rDiscard(function () {
|
|
690
|
-
// A rejected mandatory Full Snapshot may have marked recovery while
|
|
691
|
-
// encoder writes were still pending. Wake the deferred notification
|
|
692
|
-
// after finish drains that backlog, even though this segment result is
|
|
693
|
-
// intentionally not delivered.
|
|
694
|
-
scheduleReplayResetNotification();
|
|
695
|
-
});
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
function addRecordToCurrentSegment(record, serializedRecordData, ignoreSegmentBytesLimit) {
|
|
699
|
-
var segmentState = state;
|
|
700
|
-
var segment = segmentState.$rSegment;
|
|
701
|
-
var synchronousEncoderError;
|
|
702
|
-
var isTimeAnchor = isSessionReplayTimeAnchor(record);
|
|
703
|
-
var recordPendingRawBytesLimit = pendingRawBytesLimit;
|
|
704
|
-
if (isTimeAnchor && recordPendingRawBytesLimit !== undefined) {
|
|
705
|
-
recordPendingRawBytesLimit += SESSION_REPLAY_TIME_ANCHOR_BACKPRESSURE_RESERVE;
|
|
706
|
-
}
|
|
707
|
-
var addResult = segment.addRecord(record, function (encodedBytesCount, error) {
|
|
708
|
-
if (state.$rStatus !== SegmentCollectionStatus.SegmentPending || state.$rSegment !== segment) {
|
|
709
|
-
scheduleReplayResetNotification();
|
|
710
|
-
return;
|
|
711
|
-
}
|
|
712
|
-
if (error) {
|
|
713
|
-
synchronousEncoderError = error;
|
|
714
|
-
var isBaselineTransactionFailure = activeBaselineTransaction && activeBaselineTransaction.$rSegment === segment;
|
|
715
|
-
clearTimeout(state.$rExpiration);
|
|
716
|
-
reportDroppedRecord('encoder_error', 0);
|
|
717
|
-
resetState('encoder_error');
|
|
718
|
-
failBaselineGeneration(segmentState.$rGeneration, 'encoder_error', segmentState.$rHasSnapshot || Boolean(isBaselineTransactionFailure));
|
|
719
|
-
} else if (encodedBytesCount > SEGMENT_BYTES_LIMIT && !segmentState.$rMandatoryRecoveryHold) {
|
|
720
|
-
if (activeBaselineTransaction && activeBaselineTransaction.$rSegment === segment) {
|
|
721
|
-
// Meta + Focus + FullSnapshot is one replay baseline. An encoder
|
|
722
|
-
// callback may run synchronously while those records are being
|
|
723
|
-
// added; flushing after Meta would expose an incomplete baseline
|
|
724
|
-
// and leave the following records without a current segment.
|
|
725
|
-
activeBaselineTransaction.$rExceededSegmentBytesLimit = true;
|
|
726
|
-
} else {
|
|
727
|
-
flushSegment('segment_bytes_limit');
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
scheduleReplayResetNotification();
|
|
731
|
-
}, ignoreSegmentBytesLimit ? undefined : SEGMENT_BYTES_LIMIT,
|
|
732
|
-
// The SDK time anchor is a fixed, tiny, state-free boundary. Give it a
|
|
733
|
-
// small bounded reserve behind the regular worker backlog without
|
|
734
|
-
// synchronously draining that backlog; segment size and async action
|
|
735
|
-
// ordering remain unchanged.
|
|
736
|
-
recordPendingRawBytesLimit, serializedRecordData);
|
|
737
|
-
if (synchronousEncoderError) {
|
|
738
|
-
return {
|
|
739
|
-
status: 'encoder_error',
|
|
740
|
-
error: synchronousEncoderError
|
|
741
|
-
};
|
|
742
|
-
}
|
|
743
|
-
return addResult;
|
|
744
|
-
}
|
|
745
|
-
function flushCanvasWithRateLimit() {
|
|
746
|
-
var now = dateNow();
|
|
747
|
-
var timeUntilNextFlush = CANVAS_FLUSH_MIN_INTERVAL - (now - lastCanvasFlushAt);
|
|
748
|
-
if (timeUntilNextFlush <= 0) {
|
|
749
|
-
lastCanvasFlushAt = now;
|
|
750
|
-
flushSegment('canvas_snapshot');
|
|
751
|
-
return;
|
|
752
|
-
}
|
|
753
|
-
if (canvasFlushTimeoutId === undefined) {
|
|
754
|
-
canvasFlushTimeoutId = setTimeout(function () {
|
|
755
|
-
canvasFlushTimeoutId = undefined;
|
|
756
|
-
lastCanvasFlushAt = dateNow();
|
|
757
|
-
flushSegment('canvas_snapshot');
|
|
758
|
-
}, timeUntilNextFlush);
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
|
-
function addRecordWithBaselineGeneration(record, serializedRecordData, ignoreSegmentBytesLimit) {
|
|
762
|
-
var segmentState = state;
|
|
763
|
-
var previousBaselineGeneration = activeBaselineGeneration;
|
|
764
|
-
var previousSegmentBaselineGeneration = segmentState.$rGeneration;
|
|
765
|
-
var previousHasFullSnapshot = segmentState.$rHasSnapshot;
|
|
766
|
-
var fullSnapshotGeneration;
|
|
767
|
-
if (record.type === RecordType.FullSnapshot) {
|
|
768
|
-
var previousActiveBaselineGeneration = activeBaselineGeneration;
|
|
769
|
-
fullSnapshotGeneration = ++nextBaselineGeneration;
|
|
770
|
-
activeBaselineGeneration = fullSnapshotGeneration;
|
|
771
|
-
baselineGenerationStates[fullSnapshotGeneration] = 'pending';
|
|
772
|
-
segmentState.$rGeneration = fullSnapshotGeneration;
|
|
773
|
-
segmentState.$rHasSnapshot = true;
|
|
774
|
-
}
|
|
775
|
-
var result = addRecordToCurrentSegment(record, serializedRecordData, ignoreSegmentBytesLimit);
|
|
776
|
-
if (result.status === 'segment_full' && fullSnapshotGeneration !== undefined) {
|
|
777
|
-
delete baselineGenerationStates[fullSnapshotGeneration];
|
|
778
|
-
activeBaselineGeneration = previousBaselineGeneration;
|
|
779
|
-
segmentState.$rGeneration = previousSegmentBaselineGeneration;
|
|
780
|
-
segmentState.$rHasSnapshot = previousHasFullSnapshot;
|
|
781
|
-
fullSnapshotGeneration = undefined;
|
|
782
|
-
} else if (fullSnapshotGeneration !== undefined) {
|
|
783
|
-
tryCleanupBaselineGeneration(previousActiveBaselineGeneration);
|
|
784
|
-
}
|
|
785
|
-
return {
|
|
786
|
-
$rResult: result,
|
|
787
|
-
$rGeneration: segmentState.$rGeneration
|
|
788
|
-
};
|
|
789
|
-
}
|
|
790
|
-
function rejectRecordAdmission(wasBackpressured) {
|
|
791
|
-
lastAddRecordWasBackpressured = Boolean(wasBackpressured);
|
|
792
|
-
return false;
|
|
793
|
-
}
|
|
794
|
-
function startFreshBaselineTransactionSegment() {
|
|
795
|
-
if (state.$rStatus === SegmentCollectionStatus.SegmentPending && !state.$rSegment.isEmpty()) {
|
|
796
|
-
if (state.$rMandatoryRecoveryHold) {
|
|
797
|
-
discardCurrentSegment('mandatory_recovery_replaced');
|
|
798
|
-
} else {
|
|
799
|
-
flushSegment('full_snapshot');
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
return ensureSegment();
|
|
803
|
-
}
|
|
804
|
-
function tryAddBaselineTransaction(records, ignoreSegmentBytesLimit) {
|
|
805
|
-
var transaction = {
|
|
806
|
-
$rSegment: state.$rSegment,
|
|
807
|
-
$rExceededSegmentBytesLimit: false
|
|
808
|
-
};
|
|
809
|
-
activeBaselineTransaction = transaction;
|
|
810
|
-
var attempt;
|
|
811
|
-
try {
|
|
812
|
-
for (var index = 0; index < records.length; index += 1) {
|
|
813
|
-
var record = records[index];
|
|
814
|
-
var addResult = addRecordWithBaselineGeneration(record, backpressuredSerializedRecordData.get(record), ignoreSegmentBytesLimit);
|
|
815
|
-
if (addResult.$rResult.status !== 'added') {
|
|
816
|
-
attempt = {
|
|
817
|
-
$rAddResult: addResult,
|
|
818
|
-
$rRecord: record
|
|
819
|
-
};
|
|
820
|
-
break;
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
if (!attempt) {
|
|
824
|
-
attempt = {
|
|
825
|
-
$rAddResult: addResult,
|
|
826
|
-
$rRecord: records[records.length - 1]
|
|
827
|
-
};
|
|
828
|
-
}
|
|
829
|
-
} finally {
|
|
830
|
-
activeBaselineTransaction = undefined;
|
|
831
|
-
}
|
|
832
|
-
attempt.$rExceededSegmentBytesLimit = transaction.$rExceededSegmentBytesLimit;
|
|
833
|
-
return attempt;
|
|
834
|
-
}
|
|
835
|
-
function rejectBaselineTransaction(records, attempt) {
|
|
836
|
-
var result = attempt.$rAddResult.$rResult;
|
|
837
|
-
var record = attempt.$rRecord;
|
|
838
|
-
records.forEach(function (baselineRecord) {
|
|
839
|
-
backpressuredSerializedRecordData["delete"](baselineRecord);
|
|
840
|
-
});
|
|
841
|
-
if (result.status === 'encoder_error') {
|
|
842
|
-
mandatoryRecoveryPending = false;
|
|
843
|
-
bufferCheckoutPending = false;
|
|
844
|
-
discardCurrentSegment('baseline_transaction_encoder_error');
|
|
845
|
-
return rejectRecordAdmission();
|
|
846
|
-
}
|
|
847
|
-
if (result.status === 'record_too_large') {
|
|
848
|
-
reportDroppedRecord(record.type === RecordType.FullSnapshot ? 'full_snapshot_too_large' : 'record_too_large', result.estimatedBytesCount);
|
|
849
|
-
} else {
|
|
850
|
-
reportDroppedRecord(record.type === RecordType.FullSnapshot ? 'full_snapshot_encoder_backpressure' : 'encoder_backpressure', result.estimatedBytesCount);
|
|
851
|
-
}
|
|
852
|
-
if (record.type === RecordType.FullSnapshot) {
|
|
853
|
-
failBaselineGeneration(attempt.$rAddResult.$rGeneration, result.status === 'record_too_large' ? 'full_snapshot_too_large' : 'full_snapshot_encoder_backpressure', result.status === 'record_too_large');
|
|
854
|
-
}
|
|
855
|
-
mandatoryRecoveryPending = false;
|
|
856
|
-
bufferCheckoutPending = false;
|
|
857
|
-
discardCurrentSegment('baseline_transaction_rejected');
|
|
858
|
-
return rejectRecordAdmission(result.status === 'encoder_backpressure');
|
|
859
|
-
}
|
|
860
|
-
function addBaselineRecords(records) {
|
|
861
|
-
lastAddRecordWasBackpressured = false;
|
|
862
|
-
if (state.$rStatus === SegmentCollectionStatus.Stopped || !records || records.length !== 3 || records[0].type !== RecordType.Meta || records[1].type !== RecordType.Focus || records[2].type !== RecordType.FullSnapshot || !startFreshBaselineTransactionSegment()) {
|
|
863
|
-
return rejectRecordAdmission();
|
|
864
|
-
}
|
|
865
|
-
var attempt = tryAddBaselineTransaction(records, false);
|
|
866
|
-
if (attempt.$rAddResult.$rResult.status === 'segment_full') {
|
|
867
|
-
if (typeof attempt.$rAddResult.$rResult.serializedRecordData === 'string') {
|
|
868
|
-
backpressuredSerializedRecordData.set(attempt.$rRecord, attempt.$rAddResult.$rResult.serializedRecordData);
|
|
869
|
-
}
|
|
870
|
-
// Meta and Focus are the prelude of the Full Snapshot, not independent
|
|
871
|
-
// replay state. Retire this unsent attempt and replay the complete
|
|
872
|
-
// transaction in a fresh segment. Like a Full Snapshot as the first
|
|
873
|
-
// physical record, the retry may exceed the estimated segment target by
|
|
874
|
-
// the small prelude; the finalized payload still goes through the hard
|
|
875
|
-
// SEGMENT_BYTES_LIMIT delivery check.
|
|
876
|
-
discardCurrentSegment('baseline_transaction_retry');
|
|
877
|
-
if (!ensureSegment()) {
|
|
878
|
-
return rejectRecordAdmission();
|
|
879
|
-
}
|
|
880
|
-
attempt = tryAddBaselineTransaction(records, true);
|
|
881
|
-
}
|
|
882
|
-
if (attempt.$rAddResult.$rResult.status !== 'added') {
|
|
883
|
-
return rejectBaselineTransaction(records, attempt);
|
|
884
|
-
}
|
|
885
|
-
records.forEach(function (record) {
|
|
886
|
-
backpressuredSerializedRecordData["delete"](record);
|
|
887
|
-
});
|
|
888
|
-
if (mandatoryRecoveryPending) {
|
|
889
|
-
mandatoryRecoveryPending = false;
|
|
890
|
-
bufferCheckoutPending = false;
|
|
891
|
-
state.$rMandatoryRecoveryHold = false;
|
|
892
|
-
flushSegment('mandatory_full_snapshot');
|
|
893
|
-
} else if (attempt.$rExceededSegmentBytesLimit) {
|
|
894
|
-
flushSegment('segment_bytes_limit');
|
|
895
|
-
}
|
|
896
|
-
return true;
|
|
897
|
-
}
|
|
898
|
-
var segmentCollection = {
|
|
899
|
-
$rAddBaselineRecords: addBaselineRecords,
|
|
900
|
-
addRecord: function addRecord(record) {
|
|
901
|
-
lastAddRecordWasBackpressured = false;
|
|
902
|
-
var isTimeAnchor = isSessionReplayTimeAnchor(record);
|
|
903
|
-
if (state.$rStatus === SegmentCollectionStatus.Stopped) {
|
|
904
|
-
return rejectRecordAdmission();
|
|
905
|
-
}
|
|
906
|
-
if (bufferCheckoutPending && record.type !== RecordType.FullSnapshot && record.type !== RecordType.Meta && record.type !== RecordType.Focus) {
|
|
907
|
-
return rejectRecordAdmission();
|
|
908
|
-
}
|
|
909
|
-
if (replayResetNeeded && record.type !== RecordType.FullSnapshot && record.type !== RecordType.Meta && record.type !== RecordType.Focus && baselineGenerationStates[activeBaselineGeneration] !== 'pending') {
|
|
910
|
-
return rejectRecordAdmission();
|
|
911
|
-
}
|
|
912
|
-
if (!ensureSegment()) {
|
|
913
|
-
return rejectRecordAdmission();
|
|
914
|
-
}
|
|
915
|
-
var addResult = addRecordWithBaselineGeneration(record, backpressuredSerializedRecordData.get(record));
|
|
916
|
-
var result = addResult.$rResult;
|
|
917
|
-
if (result.status === 'segment_full') {
|
|
918
|
-
var serializedRecordData = result.serializedRecordData;
|
|
919
|
-
if (state.$rMandatoryRecoveryHold) {
|
|
920
|
-
discardCurrentSegment('mandatory_recovery_replaced');
|
|
921
|
-
} else {
|
|
922
|
-
flushSegment('segment_bytes_limit');
|
|
923
|
-
}
|
|
924
|
-
if (!ensureSegment()) {
|
|
925
|
-
return rejectRecordAdmission();
|
|
926
|
-
}
|
|
927
|
-
addResult = addRecordWithBaselineGeneration(record, serializedRecordData);
|
|
928
|
-
result = addResult.$rResult;
|
|
929
|
-
}
|
|
930
|
-
if (result.status === 'record_too_large') {
|
|
931
|
-
backpressuredSerializedRecordData["delete"](record);
|
|
932
|
-
reportDroppedRecord('record_too_large', result.estimatedBytesCount);
|
|
933
|
-
discardEmptyCurrentSegment('record_too_large');
|
|
934
|
-
// Incremental admission fails synchronously, before the recorder
|
|
935
|
-
// publishes any DOM membership carried by the record. Returning false
|
|
936
|
-
// lets it cancel that staged membership, so the existing baseline
|
|
937
|
-
// remains valid and does not need a global reset.
|
|
938
|
-
if (record.type !== RecordType.IncrementalSnapshot && !isTimeAnchor) {
|
|
939
|
-
failBaselineGeneration(addResult.$rGeneration, record.type === RecordType.FullSnapshot ? 'full_snapshot_too_large' : 'record_too_large', record.type === RecordType.FullSnapshot);
|
|
940
|
-
}
|
|
941
|
-
if (record.type === RecordType.FullSnapshot && mandatoryRecoveryPending) {
|
|
942
|
-
mandatoryRecoveryPending = false;
|
|
943
|
-
bufferCheckoutPending = false;
|
|
944
|
-
discardCurrentSegment('mandatory_recovery_failed');
|
|
945
|
-
}
|
|
946
|
-
return rejectRecordAdmission();
|
|
947
|
-
}
|
|
948
|
-
if (result.status === 'encoder_backpressure') {
|
|
949
|
-
if (typeof result.serializedRecordData === 'string') {
|
|
950
|
-
backpressuredSerializedRecordData.set(record, result.serializedRecordData);
|
|
951
|
-
}
|
|
952
|
-
reportDroppedRecord('encoder_backpressure', result.estimatedBytesCount);
|
|
953
|
-
if (state.$rSegment.isEmpty()) {
|
|
954
|
-
discardEmptyCurrentSegment('encoder_backpressure');
|
|
955
|
-
} else {
|
|
956
|
-
flushSegment('encoder_backpressure');
|
|
957
|
-
}
|
|
958
|
-
// Later records may be waiting behind a large FullSnapshot write.
|
|
959
|
-
// Their temporary rejection must not invalidate that already-admitted
|
|
960
|
-
// baseline. The recorder retries them after the encoder drains;
|
|
961
|
-
// Meta/Focus within an atomic baseline use rejectBaselineTransaction.
|
|
962
|
-
if (record.type === RecordType.FullSnapshot) {
|
|
963
|
-
failBaselineGeneration(addResult.$rGeneration, record.type === RecordType.FullSnapshot ? 'full_snapshot_encoder_backpressure' : 'encoder_backpressure', false);
|
|
964
|
-
}
|
|
965
|
-
if (record.type === RecordType.FullSnapshot && mandatoryRecoveryPending) {
|
|
966
|
-
mandatoryRecoveryPending = false;
|
|
967
|
-
bufferCheckoutPending = false;
|
|
968
|
-
discardCurrentSegment('mandatory_recovery_failed');
|
|
969
|
-
}
|
|
970
|
-
return rejectRecordAdmission(true);
|
|
971
|
-
}
|
|
972
|
-
backpressuredSerializedRecordData["delete"](record);
|
|
973
|
-
if (result.status === 'encoder_error') {
|
|
974
|
-
if (record.type === RecordType.FullSnapshot && mandatoryRecoveryPending) {
|
|
975
|
-
mandatoryRecoveryPending = false;
|
|
976
|
-
bufferCheckoutPending = false;
|
|
977
|
-
discardCurrentSegment('mandatory_recovery_failed');
|
|
978
|
-
}
|
|
979
|
-
return rejectRecordAdmission();
|
|
980
|
-
}
|
|
981
|
-
if (record.type === RecordType.FullSnapshot && mandatoryRecoveryPending) {
|
|
982
|
-
mandatoryRecoveryPending = false;
|
|
983
|
-
bufferCheckoutPending = false;
|
|
984
|
-
state.$rMandatoryRecoveryHold = false;
|
|
985
|
-
flushSegment('mandatory_full_snapshot');
|
|
986
|
-
}
|
|
987
|
-
if (options.flushCanvasImmediately && isCanvasMutationRecord(record) && state.$rStatus === SegmentCollectionStatus.SegmentPending) {
|
|
988
|
-
flushCanvasWithRateLimit();
|
|
989
|
-
}
|
|
990
|
-
return true;
|
|
991
|
-
},
|
|
992
|
-
$rWasLastAddRecordBackpressured: function $rWasLastAddRecordBackpressured() {
|
|
993
|
-
return lastAddRecordWasBackpressured;
|
|
994
|
-
},
|
|
995
|
-
unlockSegment: function unlockSegment() {
|
|
996
|
-
state.$rLocked = false;
|
|
997
|
-
drainLockedSegments();
|
|
998
|
-
},
|
|
999
|
-
flushBufferSegment: function flushBufferSegment(callback) {
|
|
1000
|
-
if (bufferCheckoutPending) {
|
|
1001
|
-
return false;
|
|
1002
|
-
}
|
|
1003
|
-
bufferCheckoutPending = true;
|
|
1004
|
-
lockedBufferGeneration += 1;
|
|
1005
|
-
lockedSegments = [];
|
|
1006
|
-
var callbackWasInvoked = false;
|
|
1007
|
-
flushSegment('buffer_checkout', function () {
|
|
1008
|
-
callbackWasInvoked = true;
|
|
1009
|
-
beginMandatoryRecovery();
|
|
1010
|
-
if (callback) {
|
|
1011
|
-
callback();
|
|
1012
|
-
}
|
|
1013
|
-
});
|
|
1014
|
-
// A non-empty segment finishes asynchronously. Enter the hold before
|
|
1015
|
-
// application code can enqueue another record or unlock the error
|
|
1016
|
-
// session, so no post-checkout incrementals can be sent without the
|
|
1017
|
-
// replacement baseline.
|
|
1018
|
-
if (!callbackWasInvoked) {
|
|
1019
|
-
beginMandatoryRecovery();
|
|
1020
|
-
}
|
|
1021
|
-
return true;
|
|
1022
|
-
},
|
|
1023
|
-
isLocked: function isLocked() {
|
|
1024
|
-
return state.$rLocked;
|
|
1025
|
-
},
|
|
1026
|
-
$rBeginMandatoryRecovery: function $rBeginMandatoryRecovery() {
|
|
1027
|
-
beginMandatoryRecovery();
|
|
1028
|
-
},
|
|
1029
|
-
$rDiscardMandatoryRecovery: function $rDiscardMandatoryRecovery() {
|
|
1030
|
-
if (!mandatoryRecoveryPending) {
|
|
1031
|
-
return;
|
|
1032
|
-
}
|
|
1033
|
-
mandatoryRecoveryPending = false;
|
|
1034
|
-
bufferCheckoutPending = false;
|
|
1035
|
-
if (state.$rStatus === SegmentCollectionStatus.SegmentPending && state.$rMandatoryRecoveryHold) {
|
|
1036
|
-
discardCurrentSegment('mandatory_recovery_incomplete');
|
|
1037
|
-
}
|
|
1038
|
-
},
|
|
1039
|
-
stop: function stop(flushReason) {
|
|
1040
|
-
lockedBufferGeneration += 1;
|
|
1041
|
-
lockedSegments = [];
|
|
1042
|
-
bufferCheckoutPending = false;
|
|
1043
|
-
clearCanvasFlushTimeout();
|
|
1044
|
-
clearReplayResetNotificationTimeout();
|
|
1045
|
-
upgradeSegmentTransportsForPageExit(flushReason);
|
|
1046
|
-
var stopEvent = isPageExitReason(flushReason) ? {
|
|
1047
|
-
reason: flushReason
|
|
1048
|
-
} : undefined;
|
|
1049
|
-
prepareRecordsBeforePageExit(stopEvent);
|
|
1050
|
-
if (flushReason === PageExitReason.UNLOADING) {
|
|
1051
|
-
flushSegment(flushReason || 'stop');
|
|
1052
|
-
if (flushPendingSegmentEncodingsForUnload(flushReason)) {
|
|
1053
|
-
// A synchronous encoder drain can release admission backpressure.
|
|
1054
|
-
// Ask the still-active recorder for one final mutation pass before
|
|
1055
|
-
// terminally closing the second unload-safe segment.
|
|
1056
|
-
prepareRecordsBeforePageExit(stopEvent);
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
flushSegment(flushReason || 'stop', undefined, true);
|
|
1060
|
-
// Normal stop/session renewal leaves shared encoder groups to complete
|
|
1061
|
-
// asynchronously. Only a real unload uses the bounded synchronous drain.
|
|
1062
|
-
flushPendingSegmentEncodingsForUnload(flushReason);
|
|
1063
|
-
unsubscribeLifecycle();
|
|
1064
|
-
}
|
|
1065
|
-
};
|
|
1066
|
-
if (false) {
|
|
1067
|
-
segmentCollection.getBaselineGenerationStateCountForDebug = function () {
|
|
1068
|
-
return Object.keys(baselineGenerationStates).length;
|
|
1069
|
-
};
|
|
1070
|
-
}
|
|
1071
|
-
return segmentCollection;
|
|
1072
|
-
function beginMandatoryRecovery() {
|
|
1073
|
-
mandatoryRecoveryPending = true;
|
|
1074
|
-
if (state.$rStatus === SegmentCollectionStatus.SegmentPending) {
|
|
1075
|
-
state.$rMandatoryRecoveryHold = true;
|
|
1076
|
-
clearTimeout(state.$rExpiration);
|
|
1077
|
-
}
|
|
1078
|
-
}
|
|
1079
|
-
}
|
|
1080
|
-
function isCanvasMutationRecord(record) {
|
|
1081
|
-
return record && record.type === RecordType.IncrementalSnapshot && record.data && record.data.source === IncrementalSource.CanvasMutation;
|
|
1082
|
-
}
|
|
1083
|
-
export function computeSegmentContext(configuration, sessionManager, viewContexts) {
|
|
1084
|
-
var session = sessionManager.findTrackedSession();
|
|
1085
|
-
var viewContext = viewContexts.findView();
|
|
1086
|
-
if (!session || !viewContext) {
|
|
1087
|
-
return undefined;
|
|
1088
|
-
}
|
|
1089
|
-
return {
|
|
1090
|
-
sdk: {
|
|
1091
|
-
name: configuration.sdkName,
|
|
1092
|
-
version: configuration.sdkVersion
|
|
1093
|
-
},
|
|
1094
|
-
env: configuration.env || '',
|
|
1095
|
-
service: viewContext.service || configuration.service || 'browser',
|
|
1096
|
-
version: viewContext.version || configuration.version || '',
|
|
1097
|
-
app: {
|
|
1098
|
-
id: configuration.applicationId
|
|
1099
|
-
},
|
|
1100
|
-
session: {
|
|
1101
|
-
id: session.id
|
|
1102
|
-
},
|
|
1103
|
-
view: {
|
|
1104
|
-
id: viewContext.id
|
|
1105
|
-
}
|
|
1106
|
-
};
|
|
1107
|
-
}
|
|
1108
|
-
export function setSegmentBytesLimit() {
|
|
1109
|
-
var newSegmentBytesLimit = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 60000;
|
|
1110
|
-
SEGMENT_BYTES_LIMIT = newSegmentBytesLimit;
|
|
1111
|
-
}
|
|
1112
|
-
//# sourceMappingURL=segmentCollection.js.map
|
|
1
|
+
import{ONE_SECOND,LifeCycleEventType,isPageExitReason,PageExitReason,assign,addTelemetryDebug,dateNow,setTimeout,clearTimeout}from"@cloudcare/browser-core";import{IncrementalSource,RecordType}from"../../../types";import{buildReplayPayload}from"./buildReplayPayload";import{createSegment}from"./segment";import{isSessionReplayTimeAnchor,SESSION_REPLAY_TIME_ANCHOR_BACKPRESSURE_RESERVE}from"../timeAnchor";export var SEGMENT_DURATION_LIMIT=5*ONE_SECOND;export var SEGMENT_BYTES_LIMIT=6e4;export function startSegmentCollection(lifeCycle,configuration,sessionManager,viewContexts,httpRequest,encoder){var isLocked=arguments.length>6&&void 0!==arguments[6]&&arguments[6],additionalOptions=arguments.length>7?arguments[7]:void 0;return doStartSegmentCollection(lifeCycle,(function(){return computeSegmentContext(configuration,sessionManager,viewContexts)}),httpRequest,encoder,isLocked,assign({flushCanvasImmediately:configuration.replayCanvasFlushImmediately,pendingRawBytesLimit:4194304,beforePageExitFlush:void 0,onReplayResetNeeded:void 0,onReplayResetExhausted:void 0,onSegmentFlushed:void 0},additionalOptions))}var SegmentCollectionStatus={WaitingForInitialRecord:0,SegmentPending:1,Stopped:2};export function doStartSegmentCollection(lifeCycle,getSegmentContext,httpRequest,encoder,isLocked,options){void 0===options&&(options={});var canvasFlushTimeoutId,replayResetReason,replayResetNotificationTimeoutId,unloadingDeliveryBytesRemaining,activeBaselineTransaction,pendingRawBytesLimit="number"==typeof options.pendingRawBytesLimit?options.pendingRawBytesLimit:4194304,lockedSegments=[],memoryBudget=options.memoryBudget,lockedBufferGeneration=0,reportedDropReasons={},lastCanvasFlushAt=-1/0,replayResetNeeded=!1,replayResetNotificationSent=!1,activeBaselineGeneration=0,nextBaselineGeneration=0,baselineGenerationStates={},transportGenerationStates={},baselineGenerationInFlightCounts={},pendingSegmentResultsByGeneration={},consecutiveFullSnapshotFailures=0,replayRecoveryExhausted=!1,lifecycleSubscriptionsStopped=!1,nextSegmentFlushSequence=0,inFlightSegmentFlushes=new Set,lastAddRecordWasBackpressured=!1,backpressuredSerializedRecordData=new WeakMap,unloadingTransportLatched=!1,unloadingDeliveryBudgetExhausted=!1,unloadingRetryPayloadsDrained=!1,mandatoryRecoveryPending=!1,bufferCheckoutPending=!1,state={$rStatus:SegmentCollectionStatus.WaitingForInitialRecord,$rNextReason:"init",$rLocked:isLocked,$rGeneration:activeBaselineGeneration};function prepareRecordsBeforePageExit(pageExitEvent){if(options.beforePageExitFlush)try{return options.beforePageExitFlush(pageExitEvent)}catch(error){addTelemetryDebug("Session Replay failed to prepare records before page exit.",{reason:pageExitEvent&&pageExitEvent.reason,error:String(error)})}}memoryBudget&&(memoryBudget.$rSegment=getSegmentMemoryUsage);var unsubscribeViewCreated=lifeCycle.subscribe(LifeCycleEventType.VIEW_CREATED,(function(){flushSegment("view_change")})).unsubscribe,unsubscribePageExited=lifeCycle.subscribe(LifeCycleEventType.PAGE_EXITED,(function(pageExitEvent){state.$rStatus!==SegmentCollectionStatus.Stopped&&pageExitEvent.reason!==PageExitReason.PAGE_TERMINATED&&(prepareRecordsBeforePageExit(pageExitEvent),upgradeSegmentTransportsForPageExit(pageExitEvent.reason),state.$rLocked&&pageExitEvent.reason===PageExitReason.UNLOADING&&(lockedBufferGeneration+=1,lockedSegments=[]),flushSegment(pageExitEvent.reason),flushPendingSegmentEncodingsForUnload(pageExitEvent.reason)&&(prepareRecordsBeforePageExit(pageExitEvent),flushSegment(pageExitEvent.reason),flushPendingSegmentEncodingsForUnload(pageExitEvent.reason)))})).unsubscribe;function reportDroppedRecord(reason,estimatedBytesCount){reportedDropReasons[reason]||(reportedDropReasons[reason]=!0,addTelemetryDebug("Session Replay record discarded.",{reason:reason,estimated_bytes_count:estimatedBytesCount}))}function clearReplayResetNotificationTimeout(){void 0!==replayResetNotificationTimeoutId&&(clearTimeout(replayResetNotificationTimeoutId),replayResetNotificationTimeoutId=void 0)}function getPendingRawBytesCount(){return encoder.getPendingRawBytesCount?encoder.getPendingRawBytesCount():0}function scheduleReplayResetNotification(){!replayResetNeeded||replayResetNotificationSent||void 0!==replayResetNotificationTimeoutId||!options.onReplayResetNeeded||state.$rStatus===SegmentCollectionStatus.Stopped||getPendingRawBytesCount()>0||(replayResetNotificationTimeoutId=setTimeout((function(){replayResetNotificationTimeoutId=void 0,!replayResetNeeded||replayResetNotificationSent||state.$rStatus===SegmentCollectionStatus.Stopped||getPendingRawBytesCount()>0||(replayResetNotificationSent=!0,options.onReplayResetNeeded(replayResetReason))}),0))}function markReplayResetNeeded(reason,shouldNotifyAgain){replayResetNeeded&&!shouldNotifyAgain||(replayResetReason=reason,replayResetNotificationSent=!1,shouldNotifyAgain&&clearReplayResetNotificationTimeout()),replayResetNeeded=!0,scheduleReplayResetNotification()}function clearReplayResetNeeded(){replayResetNeeded=!1,replayResetReason=void 0,replayResetNotificationSent=!1,clearReplayResetNotificationTimeout()}function unsubscribeLifecycle(){lifecycleSubscriptionsStopped||(lifecycleSubscriptionsStopped=!0,unsubscribeViewCreated(),unsubscribePageExited())}function failBaselineGeneration(baselineGeneration,reason,isFullSnapshotFailure){baselineGeneration>0&&(baselineGenerationStates[baselineGeneration]="invalid",delete pendingSegmentResultsByGeneration[baselineGeneration]),baselineGeneration===activeBaselineGeneration?isFullSnapshotFailure&&(consecutiveFullSnapshotFailures+=1)>=3?function exhaustReplayRecovery(reason){replayRecoveryExhausted||(replayRecoveryExhausted=!0,clearReplayResetNeeded(),clearCanvasFlushTimeout(),lockedBufferGeneration+=1,lockedSegments=[],baselineGenerationStates={},transportGenerationStates={},baselineGenerationInFlightCounts={},pendingSegmentResultsByGeneration={},state.$rStatus===SegmentCollectionStatus.SegmentPending&&discardCurrentSegment("recovery_exhausted"),state={$rStatus:SegmentCollectionStatus.Stopped,$rLocked:!1},unsubscribeLifecycle(),options.onReplayResetExhausted&&options.onReplayResetExhausted(reason))}(reason):markReplayResetNeeded(reason,!0):tryCleanupBaselineGeneration(baselineGeneration)}function tryCleanupBaselineGeneration(baselineGeneration){baselineGeneration<=0||baselineGeneration===activeBaselineGeneration||baselineGenerationInFlightCounts[baselineGeneration]||pendingSegmentResultsByGeneration[baselineGeneration]||(delete baselineGenerationStates[baselineGeneration],delete transportGenerationStates[baselineGeneration])}function getTransportGenerationState(baselineGeneration){return transportGenerationStates[baselineGeneration]||(transportGenerationStates[baselineGeneration]={$rValid:!0}),transportGenerationStates[baselineGeneration]}function clearCanvasFlushTimeout(){void 0!==canvasFlushTimeoutId&&(clearTimeout(canvasFlushTimeoutId),canvasFlushTimeoutId=void 0)}function upgradeSegmentTransportsForPageExit(flushReason){if(isPageExitReason(flushReason)){var exitState=flushReason!==PageExitReason.HIDDEN||PageExitReason.HIDDEN;flushReason===PageExitReason.UNLOADING&&(unloadingTransportLatched=!0,void 0===unloadingDeliveryBytesRemaining&&(unloadingDeliveryBytesRemaining=SEGMENT_BYTES_LIMIT),function drainRetryPayloadsForUnload(){if(unloadingRetryPayloadsDrained)return;if(unloadingRetryPayloadsDrained=!0,"function"!=typeof httpRequest.$rDrainOnExit)return;var deliveryResult=httpRequest.$rDrainOnExit(unloadingDeliveryBytesRemaining);deliveryResult&&"number"==typeof deliveryResult.$rBytesCount&&isFinite(deliveryResult.$rBytesCount)&&deliveryResult.$rBytesCount>=0&&(unloadingDeliveryBytesRemaining=Math.max(unloadingDeliveryBytesRemaining-deliveryResult.$rBytesCount,0),!1!==deliveryResult.$rAllPayloadsSent||deliveryResult.$rPending||(unloadingDeliveryBudgetExhausted=!0))}()),inFlightSegmentFlushes.forEach((function(transport){transport.$rExit=exitState})),Object.keys(pendingSegmentResultsByGeneration).forEach((function(baselineGeneration){pendingSegmentResultsByGeneration[baselineGeneration].forEach((function(segmentResult){segmentResult.$rExit=exitState}))}))}}function flushPendingSegmentEncodingsForUnload(flushReason){return flushReason===PageExitReason.UNLOADING&&function flushPendingSegmentEncodingsSync(){return!!encoder.flushPendingActionsSync&&(encoder.flushPendingActionsSync(SEGMENT_BYTES_LIMIT),!0)}()}function sendSegment(segmentResult){var metadata=segmentResult.$rMetadata,encoderResult=segmentResult.$rEncoder;var shouldUseExitTransport=!segmentResult.$rRegular&&(!0===segmentResult.$rExit||unloadingTransportLatched),estimatedDeliveryBytesCount=encoderResult.outputBytesCount+2048;if(shouldUseExitTransport&&unloadingTransportLatched&&unloadingDeliveryBudgetExhausted)return unloadingDeliveryBudgetExhausted=!0,void reportDroppedRecord("page_exit_delivery_budget",estimatedDeliveryBytesCount);var payload=buildReplayPayload(encoderResult.output,metadata,encoderResult.rawBytesCount);if(payload.$rExitBytesCount=estimatedDeliveryBytesCount,payload.$rEnforceOrder=!0,payload.$rKeepalive=Boolean(!shouldUseExitTransport&&segmentResult.$rExit===PageExitReason.HIDDEN&&estimatedDeliveryBytesCount<=SEGMENT_BYTES_LIMIT),payload.$rIsValid=function(){return segmentResult.$rTransportGeneration.$rValid},payload.$rOnPermanentDrop=function(reason){!function handlePermanentTransportDrop(segmentResult,reason){if(segmentResult.$rTransportGeneration.$rValid=!1,state.$rStatus!==SegmentCollectionStatus.Stopped&&!replayRecoveryExhausted){var dropReason="transport_"+reason;reportDroppedRecord(dropReason,0),failBaselineGeneration(segmentResult.$rGeneration,dropReason,!1),scheduleReplayResetNotification()}}(segmentResult,reason)},segmentResult.$rEncoder=void 0,shouldUseExitTransport){var exitDeliveryResult=httpRequest.sendOnExit(payload,unloadingTransportLatched?unloadingDeliveryBytesRemaining:void 0);unloadingTransportLatched&&(exitDeliveryResult&&"number"==typeof exitDeliveryResult.$rBytesCount&&isFinite(exitDeliveryResult.$rBytesCount)&&exitDeliveryResult.$rBytesCount>=0?(unloadingDeliveryBytesRemaining=Math.max(unloadingDeliveryBytesRemaining-exitDeliveryResult.$rBytesCount,0),exitDeliveryResult.$rCurrentPayloadSent||exitDeliveryResult.$rPending||(unloadingDeliveryBudgetExhausted=!0,reportDroppedRecord("page_exit_delivery_budget",estimatedDeliveryBytesCount))):unloadingDeliveryBytesRemaining=Math.max(unloadingDeliveryBytesRemaining-estimatedDeliveryBytesCount,0))}else httpRequest.send(payload)}function getSegmentMemoryUsage(){return getPendingRawBytesCount()+function getLockedSegmentsBytesCount(){return lockedSegments.reduce((function(bytesCount,segmentResult){var encoderResult=segmentResult.$rEncoder;return bytesCount+(encoderResult&&"number"==typeof encoderResult.outputBytesCount?encoderResult.outputBytesCount:0)}),0)}()+("function"==typeof httpRequest.$rPendingBytes?httpRequest.$rPendingBytes():0)}function deliverSegmentResult(segmentResult){segmentResult.$rLocked?segmentResult.$rLockGeneration===lockedBufferGeneration&&"buffer_checkout"!==segmentResult.$rReason&&"stop"!==segmentResult.$rReason&&segmentResult.$rReason!==PageExitReason.UNLOADING&&(state.$rLocked?function retainLockedSegment(segmentResult){if(segmentResult.$rExit=!1,segmentResult.$rRegular=!0,!replayResetNeeded){lockedSegments.push(segmentResult);for(var latestFullSnapshotIndex=-1,index=lockedSegments.length-1;index>=0;index-=1)if(lockedSegments[index].$rMetadata.has_full_snapshot){latestFullSnapshotIndex=index;break}latestFullSnapshotIndex>0&&lockedSegments.splice(0,latestFullSnapshotIndex),(lockedSegments.length>12||memoryBudget&&getSegmentMemoryUsage()+memoryBudget.$rRecord()>50331648)&&(lockedBufferGeneration+=1,lockedSegments=[],markReplayResetNeeded("locked_buffer_capacity"),flushSegment("locked_buffer_capacity"))}}(segmentResult):(segmentResult.$rExit=!1,segmentResult.$rRegular=!0,sendSegment(segmentResult))):sendSegment(segmentResult)}function handleSuccessfulSegment(baselineGeneration,segmentResult){if(segmentResult.$rMetadata.has_full_snapshot)(function confirmBaselineGeneration(baselineGeneration,segmentResult){if(!replayRecoveryExhausted&&"invalid"!==baselineGenerationStates[baselineGeneration]){baselineGenerationStates[baselineGeneration]="confirmed",baselineGeneration!==activeBaselineGeneration||replayResetNeeded&&segmentResult.$rLocked&&segmentResult.$rLockGeneration!==lockedBufferGeneration||(consecutiveFullSnapshotFailures=0,clearReplayResetNeeded()),deliverSegmentResult(segmentResult);var pendingSegmentResults=pendingSegmentResultsByGeneration[baselineGeneration]||[];delete pendingSegmentResultsByGeneration[baselineGeneration],pendingSegmentResults.sort((function(first,second){return first.$rSequence-second.$rSequence})),pendingSegmentResults.forEach(deliverSegmentResult),tryCleanupBaselineGeneration(baselineGeneration)}})(baselineGeneration,segmentResult);else if(0!==baselineGeneration){var baselineState=baselineGenerationStates[baselineGeneration];"confirmed"===baselineState?deliverSegmentResult(segmentResult):"pending"===baselineState?function retainPendingSegmentResult(baselineGeneration,segmentResult){pendingSegmentResultsByGeneration[baselineGeneration]||(pendingSegmentResultsByGeneration[baselineGeneration]=[]),pendingSegmentResultsByGeneration[baselineGeneration].push(segmentResult)}(baselineGeneration,segmentResult):baselineGeneration!==activeBaselineGeneration||replayRecoveryExhausted||failBaselineGeneration(baselineGeneration,"missing_full_snapshot",!1)}else deliverSegmentResult(segmentResult)}function resetState(flushReason){state="stop"!==flushReason?{$rStatus:SegmentCollectionStatus.WaitingForInitialRecord,$rNextReason:flushReason,$rLocked:state.$rLocked,$rGeneration:activeBaselineGeneration}:{$rStatus:SegmentCollectionStatus.Stopped,$rLocked:!1}}function flushSegment(flushReason,callback,isStopping){if(state.$rStatus!==SegmentCollectionStatus.Stopped){if(state.$rStatus===SegmentCollectionStatus.SegmentPending&&state.$rMandatoryRecoveryHold)return isStopping&&(mandatoryRecoveryPending=!1,discardCurrentSegment("mandatory_recovery_incomplete"),resetState("stop")),void(callback&&callback());if("canvas_snapshot"!==flushReason&&clearCanvasFlushTimeout(),state.$rStatus===SegmentCollectionStatus.SegmentPending){var segmentState=state,wasLocked=segmentState.$rLocked,lockedGeneration=segmentState.$rLockGeneration,baselineGeneration=state.$rGeneration,transport={$rExit:flushReason===PageExitReason.HIDDEN?PageExitReason.HIDDEN:isPageExitReason(flushReason),$rSequence:++nextSegmentFlushSequence};if(clearTimeout(state.$rExpiration),resetState(isStopping?"stop":flushReason),!segmentState.$rSegment.isEmpty())return inFlightSegmentFlushes.add(transport),function retainBaselineGeneration(baselineGeneration){baselineGeneration<=0||(baselineGenerationInFlightCounts[baselineGeneration]=(baselineGenerationInFlightCounts[baselineGeneration]||0)+1)}(baselineGeneration),void segmentState.$rSegment.flush((function(metadata,encoderResult,recordCountsByType){!function removeInFlightSegmentFlush(transport){inFlightSegmentFlushes.delete(transport)}(transport);try{!function handleFlushedSegment(flushReason,wasLocked,lockedGeneration,baselineGeneration,metadata,encoderResult,recordCountsByType,transport){if(!replayRecoveryExhausted){if(encoderResult.error)return reportDroppedRecord("encoder_error",0),failBaselineGeneration(baselineGeneration,"encoder_error",metadata.has_full_snapshot),void scheduleReplayResetNotification();handleSuccessfulSegment(baselineGeneration,{$rMetadata:metadata,$rEncoder:encoderResult,$rReason:flushReason,$rExit:transport.$rExit,$rLocked:wasLocked,$rLockGeneration:lockedGeneration,$rGeneration:baselineGeneration,$rTransportGeneration:getTransportGenerationState(baselineGeneration),$rSequence:transport.$rSequence}),scheduleReplayResetNotification()}}(flushReason,wasLocked,lockedGeneration,baselineGeneration,metadata,encoderResult,0,transport)}finally{!function releaseBaselineGeneration(baselineGeneration){baselineGeneration<=0||!baselineGenerationInFlightCounts[baselineGeneration]||(baselineGenerationInFlightCounts[baselineGeneration]-=1,baselineGenerationInFlightCounts[baselineGeneration]||delete baselineGenerationInFlightCounts[baselineGeneration],tryCleanupBaselineGeneration(baselineGeneration))}(baselineGeneration)}callback&&callback()}))}resetState(isStopping?"stop":flushReason),callback&&callback()}else callback&&callback()}function ensureSegment(){if(state.$rStatus!==SegmentCollectionStatus.WaitingForInitialRecord)return state.$rStatus===SegmentCollectionStatus.SegmentPending;var context=getSegmentContext();return!!context&&(state={$rStatus:SegmentCollectionStatus.SegmentPending,$rSegment:createSegment({encoder:encoder,context:context,creationReason:state.$rNextReason}),$rLocked:state.$rLocked,$rLockGeneration:lockedBufferGeneration,$rGeneration:activeBaselineGeneration,$rHasSnapshot:!1,$rMandatoryRecoveryHold:mandatoryRecoveryPending,$rExpiration:setTimeout((function(){flushSegment("segment_duration_limit")}),SEGMENT_DURATION_LIMIT)},!0)}function discardEmptyCurrentSegment(reason){state.$rStatus===SegmentCollectionStatus.SegmentPending&&state.$rSegment.isEmpty()&&(clearTimeout(state.$rExpiration),resetState(reason))}function discardCurrentSegment(reason){if(state.$rStatus===SegmentCollectionStatus.SegmentPending){var discardedSegment=state.$rSegment,isEmpty=discardedSegment.isEmpty();clearTimeout(state.$rExpiration),resetState(reason),isEmpty||discardedSegment.$rDiscard((function(){scheduleReplayResetNotification()}))}}function addRecordWithBaselineGeneration(record,serializedRecordData,ignoreSegmentBytesLimit){var fullSnapshotGeneration,segmentState=state,previousBaselineGeneration=activeBaselineGeneration,previousSegmentBaselineGeneration=segmentState.$rGeneration,previousHasFullSnapshot=segmentState.$rHasSnapshot;if(record.type===RecordType.FullSnapshot){var previousActiveBaselineGeneration=activeBaselineGeneration;fullSnapshotGeneration=++nextBaselineGeneration,activeBaselineGeneration=fullSnapshotGeneration,baselineGenerationStates[fullSnapshotGeneration]="pending",segmentState.$rGeneration=fullSnapshotGeneration,segmentState.$rHasSnapshot=!0}var result=function addRecordToCurrentSegment(record,serializedRecordData,ignoreSegmentBytesLimit){var synchronousEncoderError,segmentState=state,segment=segmentState.$rSegment,isTimeAnchor=isSessionReplayTimeAnchor(record),recordPendingRawBytesLimit=pendingRawBytesLimit;isTimeAnchor&&void 0!==recordPendingRawBytesLimit&&(recordPendingRawBytesLimit+=SESSION_REPLAY_TIME_ANCHOR_BACKPRESSURE_RESERVE);var addResult=segment.addRecord(record,(function(encodedBytesCount,error){if(state.$rStatus===SegmentCollectionStatus.SegmentPending&&state.$rSegment===segment){if(error){synchronousEncoderError=error;var isBaselineTransactionFailure=activeBaselineTransaction&&activeBaselineTransaction.$rSegment===segment;clearTimeout(state.$rExpiration),reportDroppedRecord("encoder_error",0),resetState("encoder_error"),failBaselineGeneration(segmentState.$rGeneration,"encoder_error",segmentState.$rHasSnapshot||Boolean(isBaselineTransactionFailure))}else encodedBytesCount>SEGMENT_BYTES_LIMIT&&!segmentState.$rMandatoryRecoveryHold&&(activeBaselineTransaction&&activeBaselineTransaction.$rSegment===segment?activeBaselineTransaction.$rExceededSegmentBytesLimit=!0:flushSegment("segment_bytes_limit"));scheduleReplayResetNotification()}else scheduleReplayResetNotification()}),ignoreSegmentBytesLimit?void 0:SEGMENT_BYTES_LIMIT,recordPendingRawBytesLimit,serializedRecordData);return synchronousEncoderError?{status:"encoder_error",error:synchronousEncoderError}:addResult}(record,serializedRecordData,ignoreSegmentBytesLimit);return"segment_full"===result.status&&void 0!==fullSnapshotGeneration?(delete baselineGenerationStates[fullSnapshotGeneration],activeBaselineGeneration=previousBaselineGeneration,segmentState.$rGeneration=previousSegmentBaselineGeneration,segmentState.$rHasSnapshot=previousHasFullSnapshot,fullSnapshotGeneration=void 0):void 0!==fullSnapshotGeneration&&tryCleanupBaselineGeneration(previousActiveBaselineGeneration),{$rResult:result,$rGeneration:segmentState.$rGeneration}}function rejectRecordAdmission(wasBackpressured){return lastAddRecordWasBackpressured=Boolean(wasBackpressured),!1}function tryAddBaselineTransaction(records,ignoreSegmentBytesLimit){var attempt,transaction={$rSegment:state.$rSegment,$rExceededSegmentBytesLimit:!1};activeBaselineTransaction=transaction;try{for(var index=0;index<records.length;index+=1){var record=records[index],addResult=addRecordWithBaselineGeneration(record,backpressuredSerializedRecordData.get(record),ignoreSegmentBytesLimit);if("added"!==addResult.$rResult.status){attempt={$rAddResult:addResult,$rRecord:record};break}}attempt||(attempt={$rAddResult:addResult,$rRecord:records[records.length-1]})}finally{activeBaselineTransaction=void 0}return attempt.$rExceededSegmentBytesLimit=transaction.$rExceededSegmentBytesLimit,attempt}var segmentCollection={$rAddBaselineRecords:function addBaselineRecords(records){if(lastAddRecordWasBackpressured=!1,state.$rStatus===SegmentCollectionStatus.Stopped||!records||3!==records.length||records[0].type!==RecordType.Meta||records[1].type!==RecordType.Focus||records[2].type!==RecordType.FullSnapshot||!function startFreshBaselineTransactionSegment(){return state.$rStatus!==SegmentCollectionStatus.SegmentPending||state.$rSegment.isEmpty()||(state.$rMandatoryRecoveryHold?discardCurrentSegment("mandatory_recovery_replaced"):flushSegment("full_snapshot")),ensureSegment()}())return rejectRecordAdmission();var attempt=tryAddBaselineTransaction(records,!1);if("segment_full"===attempt.$rAddResult.$rResult.status){if("string"==typeof attempt.$rAddResult.$rResult.serializedRecordData&&backpressuredSerializedRecordData.set(attempt.$rRecord,attempt.$rAddResult.$rResult.serializedRecordData),discardCurrentSegment("baseline_transaction_retry"),!ensureSegment())return rejectRecordAdmission();attempt=tryAddBaselineTransaction(records,!0)}return"added"!==attempt.$rAddResult.$rResult.status?function rejectBaselineTransaction(records,attempt){var result=attempt.$rAddResult.$rResult,record=attempt.$rRecord;return records.forEach((function(baselineRecord){backpressuredSerializedRecordData.delete(baselineRecord)})),"encoder_error"===result.status?(mandatoryRecoveryPending=!1,bufferCheckoutPending=!1,discardCurrentSegment("baseline_transaction_encoder_error"),rejectRecordAdmission()):("record_too_large"===result.status?reportDroppedRecord(record.type===RecordType.FullSnapshot?"full_snapshot_too_large":"record_too_large",result.estimatedBytesCount):reportDroppedRecord(record.type===RecordType.FullSnapshot?"full_snapshot_encoder_backpressure":"encoder_backpressure",result.estimatedBytesCount),record.type===RecordType.FullSnapshot&&failBaselineGeneration(attempt.$rAddResult.$rGeneration,"record_too_large"===result.status?"full_snapshot_too_large":"full_snapshot_encoder_backpressure","record_too_large"===result.status),mandatoryRecoveryPending=!1,bufferCheckoutPending=!1,discardCurrentSegment("baseline_transaction_rejected"),rejectRecordAdmission("encoder_backpressure"===result.status))}(records,attempt):(records.forEach((function(record){backpressuredSerializedRecordData.delete(record)})),mandatoryRecoveryPending?(mandatoryRecoveryPending=!1,bufferCheckoutPending=!1,state.$rMandatoryRecoveryHold=!1,flushSegment("mandatory_full_snapshot")):attempt.$rExceededSegmentBytesLimit&&flushSegment("segment_bytes_limit"),!0)},addRecord:function addRecord(record){lastAddRecordWasBackpressured=!1;var isTimeAnchor=isSessionReplayTimeAnchor(record);if(state.$rStatus===SegmentCollectionStatus.Stopped)return rejectRecordAdmission();if(bufferCheckoutPending&&record.type!==RecordType.FullSnapshot&&record.type!==RecordType.Meta&&record.type!==RecordType.Focus)return rejectRecordAdmission();if(replayResetNeeded&&record.type!==RecordType.FullSnapshot&&record.type!==RecordType.Meta&&record.type!==RecordType.Focus&&"pending"!==baselineGenerationStates[activeBaselineGeneration])return rejectRecordAdmission();if(!ensureSegment())return rejectRecordAdmission();var addResult=addRecordWithBaselineGeneration(record,backpressuredSerializedRecordData.get(record)),result=addResult.$rResult;if("segment_full"===result.status){var serializedRecordData=result.serializedRecordData;if(state.$rMandatoryRecoveryHold?discardCurrentSegment("mandatory_recovery_replaced"):flushSegment("segment_bytes_limit"),!ensureSegment())return rejectRecordAdmission();result=(addResult=addRecordWithBaselineGeneration(record,serializedRecordData)).$rResult}return"record_too_large"===result.status?(backpressuredSerializedRecordData.delete(record),reportDroppedRecord("record_too_large",result.estimatedBytesCount),discardEmptyCurrentSegment("record_too_large"),record.type===RecordType.IncrementalSnapshot||isTimeAnchor||failBaselineGeneration(addResult.$rGeneration,record.type===RecordType.FullSnapshot?"full_snapshot_too_large":"record_too_large",record.type===RecordType.FullSnapshot),record.type===RecordType.FullSnapshot&&mandatoryRecoveryPending&&(mandatoryRecoveryPending=!1,bufferCheckoutPending=!1,discardCurrentSegment("mandatory_recovery_failed")),rejectRecordAdmission()):"encoder_backpressure"===result.status?("string"==typeof result.serializedRecordData&&backpressuredSerializedRecordData.set(record,result.serializedRecordData),reportDroppedRecord("encoder_backpressure",result.estimatedBytesCount),state.$rSegment.isEmpty()?discardEmptyCurrentSegment("encoder_backpressure"):flushSegment("encoder_backpressure"),record.type===RecordType.FullSnapshot&&failBaselineGeneration(addResult.$rGeneration,record.type===RecordType.FullSnapshot?"full_snapshot_encoder_backpressure":"encoder_backpressure",!1),record.type===RecordType.FullSnapshot&&mandatoryRecoveryPending&&(mandatoryRecoveryPending=!1,bufferCheckoutPending=!1,discardCurrentSegment("mandatory_recovery_failed")),rejectRecordAdmission(!0)):(backpressuredSerializedRecordData.delete(record),"encoder_error"===result.status?(record.type===RecordType.FullSnapshot&&mandatoryRecoveryPending&&(mandatoryRecoveryPending=!1,bufferCheckoutPending=!1,discardCurrentSegment("mandatory_recovery_failed")),rejectRecordAdmission()):(record.type===RecordType.FullSnapshot&&mandatoryRecoveryPending&&(mandatoryRecoveryPending=!1,bufferCheckoutPending=!1,state.$rMandatoryRecoveryHold=!1,flushSegment("mandatory_full_snapshot")),options.flushCanvasImmediately&&function isCanvasMutationRecord(record){return record&&record.type===RecordType.IncrementalSnapshot&&record.data&&record.data.source===IncrementalSource.CanvasMutation}(record)&&state.$rStatus===SegmentCollectionStatus.SegmentPending&&function flushCanvasWithRateLimit(){var now=dateNow(),timeUntilNextFlush=250-(now-lastCanvasFlushAt);if(timeUntilNextFlush<=0)return lastCanvasFlushAt=now,void flushSegment("canvas_snapshot");void 0===canvasFlushTimeoutId&&(canvasFlushTimeoutId=setTimeout((function(){canvasFlushTimeoutId=void 0,lastCanvasFlushAt=dateNow(),flushSegment("canvas_snapshot")}),timeUntilNextFlush))}(),!0))},$rWasLastAddRecordBackpressured:function $rWasLastAddRecordBackpressured(){return lastAddRecordWasBackpressured},unlockSegment:function unlockSegment(){state.$rLocked=!1,function drainLockedSegments(){var segmentsToSend=lockedSegments;lockedSegments=[],segmentsToSend.length>0&&!segmentsToSend.some((function(segmentResult){return segmentResult.$rMetadata.has_full_snapshot}))?markReplayResetNeeded("locked_buffer_missing_full_snapshot"):segmentsToSend.forEach((function(segmentResult){segmentResult.$rExit=!1,segmentResult.$rRegular=!0,sendSegment(segmentResult)}))}()},flushBufferSegment:function flushBufferSegment(callback){if(bufferCheckoutPending)return!1;bufferCheckoutPending=!0,lockedBufferGeneration+=1,lockedSegments=[];var callbackWasInvoked=!1;return flushSegment("buffer_checkout",(function(){callbackWasInvoked=!0,beginMandatoryRecovery(),callback&&callback()})),callbackWasInvoked||beginMandatoryRecovery(),!0},isLocked:function isLocked(){return state.$rLocked},$rBeginMandatoryRecovery:function $rBeginMandatoryRecovery(){beginMandatoryRecovery()},$rDiscardMandatoryRecovery:function $rDiscardMandatoryRecovery(){mandatoryRecoveryPending&&(mandatoryRecoveryPending=!1,bufferCheckoutPending=!1,state.$rStatus===SegmentCollectionStatus.SegmentPending&&state.$rMandatoryRecoveryHold&&discardCurrentSegment("mandatory_recovery_incomplete"))},stop:function stop(flushReason){lockedBufferGeneration+=1,lockedSegments=[],bufferCheckoutPending=!1,clearCanvasFlushTimeout(),clearReplayResetNotificationTimeout(),upgradeSegmentTransportsForPageExit(flushReason);var stopEvent=isPageExitReason(flushReason)?{reason:flushReason}:void 0;prepareRecordsBeforePageExit(stopEvent),flushReason===PageExitReason.UNLOADING&&(flushSegment(flushReason||"stop"),flushPendingSegmentEncodingsForUnload(flushReason)&&prepareRecordsBeforePageExit(stopEvent)),flushSegment(flushReason||"stop",void 0,!0),flushPendingSegmentEncodingsForUnload(flushReason),unsubscribeLifecycle()}};return segmentCollection;function beginMandatoryRecovery(){mandatoryRecoveryPending=!0,state.$rStatus===SegmentCollectionStatus.SegmentPending&&(state.$rMandatoryRecoveryHold=!0,clearTimeout(state.$rExpiration))}}export function computeSegmentContext(configuration,sessionManager,viewContexts){var session=sessionManager.findTrackedSession(),viewContext=viewContexts.findView();if(session&&viewContext)return{sdk:{name:configuration.sdkName,version:configuration.sdkVersion},env:configuration.env||"",service:viewContext.service||configuration.service||"browser",version:viewContext.version||configuration.version||"",app:{id:configuration.applicationId},session:{id:session.id},view:{id:viewContext.id}}}export function setSegmentBytesLimit(){var newSegmentBytesLimit=arguments.length>0&&void 0!==arguments[0]?arguments[0]:6e4;SEGMENT_BYTES_LIMIT=newSegmentBytesLimit}
|
|
2
|
+
//# sourceMappingURL=segmentCollection.js.map
|