@cloudcare/browser-rum 3.1.0 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle/dataflux-rum.js +1 -1
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/boot/recorderApi.js +25 -21
- package/cjs/boot/recorderApi.js.map +1 -1
- package/cjs/boot/startRecording.js +5 -2
- package/cjs/boot/startRecording.js.map +1 -1
- package/cjs/domain/contexts/pageStateHistory.js +0 -1
- package/cjs/domain/contexts/pageStateHistory.js.map +1 -1
- package/cjs/domain/replay/deflate/deflateEncoder.js +82 -0
- package/cjs/domain/replay/deflate/deflateEncoder.js.map +1 -0
- package/cjs/domain/replay/deflate/deflateWorker.js +142 -0
- package/cjs/domain/replay/deflate/deflateWorker.js.map +1 -0
- package/cjs/domain/replay/deflate/index.js +44 -0
- package/cjs/domain/replay/deflate/index.js.map +1 -0
- package/cjs/domain/replay/segmentCollection/buildReplayPayload.js +1 -1
- package/cjs/domain/replay/segmentCollection/buildReplayPayload.js.map +1 -1
- package/cjs/domain/replay/segmentCollection/index.js +0 -7
- package/cjs/domain/replay/segmentCollection/index.js.map +1 -1
- package/cjs/domain/replay/segmentCollection/segment.js +19 -67
- package/cjs/domain/replay/segmentCollection/segment.js.map +1 -1
- package/cjs/domain/replay/segmentCollection/segmentCollection.js +36 -40
- package/cjs/domain/replay/segmentCollection/segmentCollection.js.map +1 -1
- package/esm/boot/buildEnv.js +1 -1
- package/esm/boot/recorderApi.js +27 -23
- package/esm/boot/recorderApi.js.map +1 -1
- package/esm/boot/startRecording.js +6 -3
- package/esm/boot/startRecording.js.map +1 -1
- package/esm/domain/contexts/pageStateHistory.js +0 -1
- package/esm/domain/contexts/pageStateHistory.js.map +1 -1
- package/esm/domain/replay/deflate/deflateEncoder.js +74 -0
- package/esm/domain/replay/deflate/deflateEncoder.js.map +1 -0
- package/esm/domain/replay/deflate/deflateWorker.js +129 -0
- package/esm/domain/replay/deflate/deflateWorker.js.map +1 -0
- package/esm/domain/replay/deflate/index.js +3 -0
- package/esm/domain/replay/deflate/index.js.map +1 -0
- package/esm/domain/replay/segmentCollection/buildReplayPayload.js +1 -1
- package/esm/domain/replay/segmentCollection/buildReplayPayload.js.map +1 -1
- package/esm/domain/replay/segmentCollection/index.js +0 -1
- package/esm/domain/replay/segmentCollection/index.js.map +1 -1
- package/esm/domain/replay/segmentCollection/segment.js +20 -68
- package/esm/domain/replay/segmentCollection/segment.js.map +1 -1
- package/esm/domain/replay/segmentCollection/segmentCollection.js +36 -40
- package/esm/domain/replay/segmentCollection/segmentCollection.js.map +1 -1
- package/package.json +4 -4
- package/src/boot/recorderApi.js +43 -32
- package/src/boot/startRecording.js +7 -3
- package/src/domain/contexts/pageStateHistory.js +0 -1
- package/src/domain/replay/deflate/deflateEncoder.js +88 -0
- package/src/domain/replay/{segmentCollection/startDeflateWorker.js → deflate/deflateWorker.js} +55 -32
- package/src/domain/replay/deflate/index.js +7 -0
- package/src/domain/replay/segmentCollection/buildReplayPayload.js +1 -1
- package/src/domain/replay/segmentCollection/index.js +0 -1
- package/src/domain/replay/segmentCollection/segment.js +28 -83
- package/src/domain/replay/segmentCollection/segmentCollection.js +49 -55
- package/cjs/domain/replay/segmentCollection/startDeflateWorker.js +0 -126
- package/cjs/domain/replay/segmentCollection/startDeflateWorker.js.map +0 -1
- package/esm/domain/replay/segmentCollection/startDeflateWorker.js +0 -117
- package/esm/domain/replay/segmentCollection/startDeflateWorker.js.map +0 -1
|
@@ -33,17 +33,17 @@ export var SEGMENT_BYTES_LIMIT = 60000;
|
|
|
33
33
|
// To help investigate session replays issues, each segment is created with a "creation reason",
|
|
34
34
|
// indicating why the session has been created.
|
|
35
35
|
|
|
36
|
-
export function startSegmentCollection(lifeCycle, configuration, sessionManager, viewContexts, httpRequest,
|
|
36
|
+
export function startSegmentCollection(lifeCycle, configuration, sessionManager, viewContexts, httpRequest, encoder) {
|
|
37
37
|
return doStartSegmentCollection(lifeCycle, function () {
|
|
38
38
|
return computeSegmentContext(configuration, sessionManager, viewContexts);
|
|
39
|
-
}, httpRequest,
|
|
39
|
+
}, httpRequest, encoder);
|
|
40
40
|
}
|
|
41
41
|
var SegmentCollectionStatus = {
|
|
42
42
|
WaitingForInitialRecord: 0,
|
|
43
43
|
SegmentPending: 1,
|
|
44
44
|
Stopped: 2
|
|
45
45
|
};
|
|
46
|
-
export function doStartSegmentCollection(lifeCycle, getSegmentContext, httpRequest,
|
|
46
|
+
export function doStartSegmentCollection(lifeCycle, getSegmentContext, httpRequest, encoder) {
|
|
47
47
|
var state = {
|
|
48
48
|
status: SegmentCollectionStatus.WaitingForInitialRecord,
|
|
49
49
|
nextSegmentCreationReason: 'init'
|
|
@@ -58,7 +58,14 @@ export function doStartSegmentCollection(lifeCycle, getSegmentContext, httpReque
|
|
|
58
58
|
var unsubscribePageExited = subscribePageExited.unsubscribe;
|
|
59
59
|
function flushSegment(flushReason) {
|
|
60
60
|
if (state.status === SegmentCollectionStatus.SegmentPending) {
|
|
61
|
-
state.segment.flush(
|
|
61
|
+
state.segment.flush(function (metadata) {
|
|
62
|
+
var payload = buildReplayPayload(encoder.getEncodedBytes(), metadata, encoder.getRawBytesCount());
|
|
63
|
+
if (isPageExitReason(flushReason)) {
|
|
64
|
+
httpRequest.sendOnExit(payload);
|
|
65
|
+
} else {
|
|
66
|
+
httpRequest.send(payload);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
62
69
|
clearTimeout(state.expirationTimeoutId);
|
|
63
70
|
}
|
|
64
71
|
if (flushReason !== 'stop') {
|
|
@@ -72,41 +79,32 @@ export function doStartSegmentCollection(lifeCycle, getSegmentContext, httpReque
|
|
|
72
79
|
};
|
|
73
80
|
}
|
|
74
81
|
}
|
|
75
|
-
function createNewSegment(creationReason, initialRecord) {
|
|
76
|
-
var context = getSegmentContext();
|
|
77
|
-
if (!context) {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
var segment = new Segment(worker, context, creationReason, initialRecord, function (compressedSegmentBytesCount) {
|
|
81
|
-
if (!segment.flushReason && compressedSegmentBytesCount > SEGMENT_BYTES_LIMIT) {
|
|
82
|
-
flushSegment('segment_bytes_limit');
|
|
83
|
-
}
|
|
84
|
-
}, function (data, rawSegmentBytesCount) {
|
|
85
|
-
var payload = buildReplayPayload(data, segment.metadata, rawSegmentBytesCount);
|
|
86
|
-
if (isPageExitReason(segment.flushReason)) {
|
|
87
|
-
httpRequest.sendOnExit(payload);
|
|
88
|
-
} else {
|
|
89
|
-
httpRequest.send(payload);
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
state = {
|
|
93
|
-
status: SegmentCollectionStatus.SegmentPending,
|
|
94
|
-
segment: segment,
|
|
95
|
-
expirationTimeoutId: setTimeout(function () {
|
|
96
|
-
flushSegment('segment_duration_limit');
|
|
97
|
-
}, SEGMENT_DURATION_LIMIT)
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
82
|
return {
|
|
101
83
|
addRecord: function addRecord(record) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
84
|
+
if (state.status === SegmentCollectionStatus.Stopped) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (state.status === SegmentCollectionStatus.WaitingForInitialRecord) {
|
|
88
|
+
var context = getSegmentContext();
|
|
89
|
+
if (!context) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
state = {
|
|
93
|
+
status: SegmentCollectionStatus.SegmentPending,
|
|
94
|
+
segment: new Segment(encoder, context, state.nextSegmentCreationReason),
|
|
95
|
+
expirationTimeoutId: setTimeout(function () {
|
|
96
|
+
flushSegment('segment_duration_limit');
|
|
97
|
+
}, SEGMENT_DURATION_LIMIT)
|
|
98
|
+
};
|
|
109
99
|
}
|
|
100
|
+
var segment = state.segment;
|
|
101
|
+
segment.addRecord(record, function () {
|
|
102
|
+
if (
|
|
103
|
+
// the written segment is still pending
|
|
104
|
+
state.status === SegmentCollectionStatus.SegmentPending && state.segment === segment && encoder.getEncodedBytesCount() > SEGMENT_BYTES_LIMIT) {
|
|
105
|
+
flushSegment('segment_bytes_limit');
|
|
106
|
+
}
|
|
107
|
+
});
|
|
110
108
|
},
|
|
111
109
|
stop: function stop() {
|
|
112
110
|
flushSegment('stop');
|
|
@@ -140,10 +138,8 @@ export function computeSegmentContext(configuration, sessionManager, viewContext
|
|
|
140
138
|
}
|
|
141
139
|
};
|
|
142
140
|
}
|
|
143
|
-
export function setSegmentBytesLimit(
|
|
144
|
-
|
|
145
|
-
newSegmentBytesLimit = 60000;
|
|
146
|
-
}
|
|
141
|
+
export function setSegmentBytesLimit() {
|
|
142
|
+
var newSegmentBytesLimit = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 60000;
|
|
147
143
|
SEGMENT_BYTES_LIMIT = newSegmentBytesLimit;
|
|
148
144
|
}
|
|
149
145
|
//# sourceMappingURL=segmentCollection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"segmentCollection.js","names":["ONE_SECOND","LifeCycleEventType","isPageExitReason","setTimeout","clearTimeout","buildReplayPayload","Segment","SEGMENT_DURATION_LIMIT","SEGMENT_BYTES_LIMIT","startSegmentCollection","lifeCycle","configuration","sessionManager","viewContexts","httpRequest","worker","doStartSegmentCollection","computeSegmentContext","SegmentCollectionStatus","WaitingForInitialRecord","SegmentPending","Stopped","getSegmentContext","state","status","nextSegmentCreationReason","subscribeViewCreated","subscribe","VIEW_CREATED","flushSegment","unsubscribeViewCreated","unsubscribe","subscribePageExited","PAGE_EXITED","pageExitEvent","reason","unsubscribePageExited","flushReason","segment","flush","expirationTimeoutId","createNewSegment","creationReason","initialRecord","context","compressedSegmentBytesCount","data","rawSegmentBytesCount","payload","metadata","sendOnExit","send","addRecord","record","stop","session","findTrackedSession","viewContext","findView","undefined","sdk","name","sdkName","version","sdkVersion","env","service","app","id","applicationId","view","setSegmentBytesLimit","newSegmentBytesLimit"],"sources":["../../../../src/domain/replay/segmentCollection/segmentCollection.js"],"sourcesContent":["import {\n ONE_SECOND,\n LifeCycleEventType,\n isPageExitReason,\n setTimeout,\n clearTimeout\n} from '@cloudcare/browser-core'\nimport { buildReplayPayload } from './buildReplayPayload'\nimport { Segment } from './segment'\n\nexport var SEGMENT_DURATION_LIMIT = 30 * ONE_SECOND\n/**\n * beacon payload max queue size implementation is 64kb\n * ensure that we leave room for logs, rum and potential other users\n */\nexport var SEGMENT_BYTES_LIMIT = 60000\n\n// Segments are the main data structure for session replays. They contain context information used\n// for indexing or UI needs, and a list of records (RRWeb 'events', renamed to avoid confusing\n// namings). They are stored without any processing from the intake, and fetched one after the\n// other while a session is being replayed. Their encoding (deflate) are carefully crafted to allow\n// concatenating multiple segments together. Segments have a size overhead (metadata), so our goal is to\n// build segments containing as many records as possible while complying with the various flush\n// strategies to guarantee a good replay quality.\n//\n// When the recording starts, a segment is initially created. The segment is flushed (finalized and\n// sent) based on various events (non-exhaustive list):\n//\n// * the page visibility change or becomes to unload\n// * the segment duration reaches a limit\n// * the encoded segment bytes count reaches a limit\n// * ...\n//\n// A segment cannot be created without its context. If the RUM session ends and no session id is\n// available when creating a new segment, records will be ignored, until the session is renewed and\n// a new session id is available.\n//\n// Empty segments (segments with no record) aren't useful and should be ignored.\n//\n// To help investigate session replays issues, each segment is created with a \"creation reason\",\n// indicating why the session has been created.\n\nexport function startSegmentCollection(\n lifeCycle,\n configuration,\n sessionManager,\n viewContexts,\n httpRequest,\n worker\n) {\n return doStartSegmentCollection(\n lifeCycle,\n function () {\n return computeSegmentContext(configuration, sessionManager, viewContexts)\n },\n httpRequest,\n worker\n )\n}\n\nvar SegmentCollectionStatus = {\n WaitingForInitialRecord: 0,\n SegmentPending: 1,\n Stopped: 2\n}\n\nexport function doStartSegmentCollection(\n lifeCycle,\n getSegmentContext,\n httpRequest,\n worker\n) {\n var state = {\n status: SegmentCollectionStatus.WaitingForInitialRecord,\n nextSegmentCreationReason: 'init'\n }\n var subscribeViewCreated = lifeCycle.subscribe(\n LifeCycleEventType.VIEW_CREATED,\n function () {\n flushSegment('view_change')\n }\n )\n var unsubscribeViewCreated = subscribeViewCreated.unsubscribe\n var subscribePageExited = lifeCycle.subscribe(\n LifeCycleEventType.PAGE_EXITED,\n function (pageExitEvent) {\n flushSegment(pageExitEvent.reason)\n }\n )\n var unsubscribePageExited = subscribePageExited.unsubscribe\n\n function flushSegment(flushReason) {\n if (state.status === SegmentCollectionStatus.SegmentPending) {\n state.segment.flush(flushReason)\n clearTimeout(state.expirationTimeoutId)\n }\n\n if (flushReason !== 'stop') {\n state = {\n status: SegmentCollectionStatus.WaitingForInitialRecord,\n nextSegmentCreationReason: flushReason\n }\n } else {\n state = {\n status: SegmentCollectionStatus.Stopped\n }\n }\n }\n\n function createNewSegment(creationReason, initialRecord) {\n var context = getSegmentContext()\n if (!context) {\n return\n }\n\n var segment = new Segment(\n worker,\n context,\n creationReason,\n initialRecord,\n function (compressedSegmentBytesCount) {\n if (\n !segment.flushReason &&\n compressedSegmentBytesCount > SEGMENT_BYTES_LIMIT\n ) {\n flushSegment('segment_bytes_limit')\n }\n },\n function (data, rawSegmentBytesCount) {\n var payload = buildReplayPayload(\n data,\n segment.metadata,\n rawSegmentBytesCount\n )\n if (isPageExitReason(segment.flushReason)) {\n httpRequest.sendOnExit(payload)\n } else {\n httpRequest.send(payload)\n }\n }\n )\n state = {\n status: SegmentCollectionStatus.SegmentPending,\n segment: segment,\n expirationTimeoutId: setTimeout(function () {\n flushSegment('segment_duration_limit')\n }, SEGMENT_DURATION_LIMIT)\n }\n }\n\n return {\n addRecord: function (record) {\n switch (state.status) {\n case SegmentCollectionStatus.WaitingForInitialRecord:\n createNewSegment(state.nextSegmentCreationReason, record)\n break\n\n case SegmentCollectionStatus.SegmentPending:\n state.segment.addRecord(record)\n break\n }\n },\n\n stop: function () {\n flushSegment('stop')\n unsubscribeViewCreated()\n unsubscribePageExited()\n }\n }\n}\n\nexport function computeSegmentContext(\n configuration,\n sessionManager,\n viewContexts\n) {\n var session = sessionManager.findTrackedSession()\n var viewContext = viewContexts.findView()\n if (!session || !viewContext) {\n return undefined\n }\n return {\n sdk: {\n name: configuration.sdkName,\n version: configuration.sdkVersion\n },\n env: configuration.env || '',\n service: viewContext.service || configuration.service || 'browser',\n version: viewContext.version || configuration.version || '',\n app: {\n id: configuration.applicationId\n },\n session: {\n id: session.id\n },\n view: {\n id: viewContext.id\n }\n }\n}\n\nexport function setSegmentBytesLimit(newSegmentBytesLimit) {\n if (newSegmentBytesLimit === undefined) {\n newSegmentBytesLimit = 60000\n }\n SEGMENT_BYTES_LIMIT = newSegmentBytesLimit\n}\n"],"mappings":"AAAA,SACEA,UAAU,EACVC,kBAAkB,EAClBC,gBAAgB,EAChBC,UAAU,EACVC,YAAY,QACP,yBAAyB;AAChC,SAASC,kBAAkB,QAAQ,sBAAsB;AACzD,SAASC,OAAO,QAAQ,WAAW;AAEnC,OAAO,IAAIC,sBAAsB,GAAG,EAAE,GAAGP,UAAU;AACnD;AACA;AACA;AACA;AACA,OAAO,IAAIQ,mBAAmB,GAAG,KAAK;;AAEtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,SAASC,sBAAsBA,CACpCC,SAAS,EACTC,aAAa,EACbC,cAAc,EACdC,YAAY,EACZC,WAAW,EACXC,MAAM,EACN;EACA,OAAOC,wBAAwB,CAC7BN,SAAS,EACT,YAAY;IACV,OAAOO,qBAAqB,CAACN,aAAa,EAAEC,cAAc,EAAEC,YAAY,CAAC;EAC3E,CAAC,EACDC,WAAW,EACXC,MACF,CAAC;AACH;AAEA,IAAIG,uBAAuB,GAAG;EAC5BC,uBAAuB,EAAE,CAAC;EAC1BC,cAAc,EAAE,CAAC;EACjBC,OAAO,EAAE;AACX,CAAC;AAED,OAAO,SAASL,wBAAwBA,CAC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ACZ;EACA,IAAI0C,OAAO,GAAG3C,cAAc,CAAC4C,kBAAkB,CAAC,CAAC;EACjD,IAAIC,WAAW,GAAG5C,YAAY,CAAC6C,QAAQ,CAAC,CAAC;EACzC,IAAI,CAACH,OAAO,IAAI,CAACE,WAAW,EAAE;IAC5B,OAAOE,SAAS;EAClB;EACA,OAAO;IACLC,GAAG,EAAE;MACHC,IAAI,EAAElD,aAAa,CAACmD,OAAO;MAC3BC,OAAO,EAAEpD,aAAa,CAACqD;IACzB,CAAC;IACDC,GAAG,EAAEtD,aAAa,CAACsD,GAAG,IAAI,EAAE;IAC5BC,OAAO,EAAET,WAAW,CAACS,OAAO,IAAIvD,aAAa,CAACuD,OAAO,IAAI,SAAS;IAClEH,OAAO,EAAEN,WAAW,CAACM,OAAO,IAAIpD,aAAa,CAACoD,OAAO,IAAI,EAAE;IAC3DI,GAAG,EAAE;MACHC,EAAE,EAAEzD,aAAa,CAAC0D;IACpB,CAAC;IACDd,OAAO,EAAE;MACPa,EAAE,EAAEb,OAAO,CAACa;IACd,CAAC;IACDE,IAAI,EAAE;MACJF,EAAE,EAAEX,WAAW,CAACW;IAClB;EACF,CAAC;AACH;AAEA,OAAO,SAASG,oBAAoBA,CAACC,oBAAoB,EAAE;EACzD,IAAIA,oBAAoB,KAAKb,SAAS,EAAE;IACtCa,oBAAoB,GAAG,KAAK;EAC9B;EACAhE,mBAAmB,GAAGgE,oBAAoB;AAC5C"}
|
|
1
|
+
{"version":3,"file":"segmentCollection.js","names":["ONE_SECOND","LifeCycleEventType","isPageExitReason","setTimeout","clearTimeout","buildReplayPayload","Segment","SEGMENT_DURATION_LIMIT","SEGMENT_BYTES_LIMIT","startSegmentCollection","lifeCycle","configuration","sessionManager","viewContexts","httpRequest","encoder","doStartSegmentCollection","computeSegmentContext","SegmentCollectionStatus","WaitingForInitialRecord","SegmentPending","Stopped","getSegmentContext","state","status","nextSegmentCreationReason","subscribeViewCreated","subscribe","VIEW_CREATED","flushSegment","unsubscribeViewCreated","unsubscribe","subscribePageExited","PAGE_EXITED","pageExitEvent","reason","unsubscribePageExited","flushReason","segment","flush","metadata","payload","getEncodedBytes","getRawBytesCount","sendOnExit","send","expirationTimeoutId","addRecord","record","context","getEncodedBytesCount","stop","session","findTrackedSession","viewContext","findView","undefined","sdk","name","sdkName","version","sdkVersion","env","service","app","id","applicationId","view","setSegmentBytesLimit","newSegmentBytesLimit","arguments","length"],"sources":["../../../../src/domain/replay/segmentCollection/segmentCollection.js"],"sourcesContent":["import {\n ONE_SECOND,\n LifeCycleEventType,\n isPageExitReason,\n setTimeout,\n clearTimeout\n} from '@cloudcare/browser-core'\nimport { buildReplayPayload } from './buildReplayPayload'\nimport { Segment } from './segment'\n\nexport var SEGMENT_DURATION_LIMIT = 30 * ONE_SECOND\n/**\n * beacon payload max queue size implementation is 64kb\n * ensure that we leave room for logs, rum and potential other users\n */\nexport var SEGMENT_BYTES_LIMIT = 60000\n\n// Segments are the main data structure for session replays. They contain context information used\n// for indexing or UI needs, and a list of records (RRWeb 'events', renamed to avoid confusing\n// namings). They are stored without any processing from the intake, and fetched one after the\n// other while a session is being replayed. Their encoding (deflate) are carefully crafted to allow\n// concatenating multiple segments together. Segments have a size overhead (metadata), so our goal is to\n// build segments containing as many records as possible while complying with the various flush\n// strategies to guarantee a good replay quality.\n//\n// When the recording starts, a segment is initially created. The segment is flushed (finalized and\n// sent) based on various events (non-exhaustive list):\n//\n// * the page visibility change or becomes to unload\n// * the segment duration reaches a limit\n// * the encoded segment bytes count reaches a limit\n// * ...\n//\n// A segment cannot be created without its context. If the RUM session ends and no session id is\n// available when creating a new segment, records will be ignored, until the session is renewed and\n// a new session id is available.\n//\n// Empty segments (segments with no record) aren't useful and should be ignored.\n//\n// To help investigate session replays issues, each segment is created with a \"creation reason\",\n// indicating why the session has been created.\n\nexport function startSegmentCollection(\n lifeCycle,\n configuration,\n sessionManager,\n viewContexts,\n httpRequest,\n encoder\n) {\n return doStartSegmentCollection(\n lifeCycle,\n function () {\n return computeSegmentContext(configuration, sessionManager, viewContexts)\n },\n httpRequest,\n encoder\n )\n}\n\nvar SegmentCollectionStatus = {\n WaitingForInitialRecord: 0,\n SegmentPending: 1,\n Stopped: 2\n}\n\nexport function doStartSegmentCollection(\n lifeCycle,\n getSegmentContext,\n httpRequest,\n encoder\n) {\n var state = {\n status: SegmentCollectionStatus.WaitingForInitialRecord,\n nextSegmentCreationReason: 'init'\n }\n var subscribeViewCreated = lifeCycle.subscribe(\n LifeCycleEventType.VIEW_CREATED,\n function () {\n flushSegment('view_change')\n }\n )\n var unsubscribeViewCreated = subscribeViewCreated.unsubscribe\n var subscribePageExited = lifeCycle.subscribe(\n LifeCycleEventType.PAGE_EXITED,\n function (pageExitEvent) {\n flushSegment(pageExitEvent.reason)\n }\n )\n var unsubscribePageExited = subscribePageExited.unsubscribe\n\n function flushSegment(flushReason) {\n if (state.status === SegmentCollectionStatus.SegmentPending) {\n state.segment.flush(function (metadata) {\n var payload = buildReplayPayload(\n encoder.getEncodedBytes(),\n metadata,\n encoder.getRawBytesCount()\n )\n\n if (isPageExitReason(flushReason)) {\n httpRequest.sendOnExit(payload)\n } else {\n httpRequest.send(payload)\n }\n })\n clearTimeout(state.expirationTimeoutId)\n }\n\n if (flushReason !== 'stop') {\n state = {\n status: SegmentCollectionStatus.WaitingForInitialRecord,\n nextSegmentCreationReason: flushReason\n }\n } else {\n state = {\n status: SegmentCollectionStatus.Stopped\n }\n }\n }\n\n return {\n addRecord: function (record) {\n if (state.status === SegmentCollectionStatus.Stopped) {\n return\n }\n\n if (state.status === SegmentCollectionStatus.WaitingForInitialRecord) {\n var context = getSegmentContext()\n if (!context) {\n return\n }\n\n state = {\n status: SegmentCollectionStatus.SegmentPending,\n segment: new Segment(\n encoder,\n context,\n state.nextSegmentCreationReason\n ),\n expirationTimeoutId: setTimeout(function () {\n flushSegment('segment_duration_limit')\n }, SEGMENT_DURATION_LIMIT)\n }\n }\n\n var segment = state.segment\n\n segment.addRecord(record, function () {\n if (\n // the written segment is still pending\n state.status === SegmentCollectionStatus.SegmentPending &&\n state.segment === segment &&\n encoder.getEncodedBytesCount() > SEGMENT_BYTES_LIMIT\n ) {\n flushSegment('segment_bytes_limit')\n }\n })\n },\n\n stop: function () {\n flushSegment('stop')\n unsubscribeViewCreated()\n unsubscribePageExited()\n }\n }\n}\n\nexport function computeSegmentContext(\n configuration,\n sessionManager,\n viewContexts\n) {\n var session = sessionManager.findTrackedSession()\n var viewContext = viewContexts.findView()\n if (!session || !viewContext) {\n return undefined\n }\n return {\n sdk: {\n name: configuration.sdkName,\n version: configuration.sdkVersion\n },\n env: configuration.env || '',\n service: viewContext.service || configuration.service || 'browser',\n version: viewContext.version || configuration.version || '',\n app: {\n id: configuration.applicationId\n },\n session: {\n id: session.id\n },\n view: {\n id: viewContext.id\n }\n }\n}\n\nexport function setSegmentBytesLimit(newSegmentBytesLimit = 60_000) {\n SEGMENT_BYTES_LIMIT = newSegmentBytesLimit\n}\n"],"mappings":"AAAA,SACEA,UAAU,EACVC,kBAAkB,EAClBC,gBAAgB,EAChBC,UAAU,EACVC,YAAY,QACP,yBAAyB;AAChC,SAASC,kBAAkB,QAAQ,sBAAsB;AACzD,SAASC,OAAO,QAAQ,WAAW;AAEnC,OAAO,IAAIC,sBAAsB,GAAG,EAAE,GAAGP,UAAU;AACnD;AACA;AACA;AACA;AACA,OAAO,IAAIQ,mBAAmB,GAAG,KAAK;;AAEtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,SAASC,sBAAsBA,CACpCC,SAAS,EACTC,aAAa,EACbC,cAAc,EACdC,YAAY,EACZC,WAAW,EACXC,OAAO,EACP;EACA,OAAOC,wBAAwB,CAC7BN,SAAS,EACT,YAAY;IACV,OAAOO,qBAAqB,CAACN,aAAa,EAAEC,cAAc,EAAEC,YAAY,CAAC;EAC3E,CAAC,EACDC,W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cjs/index.js",
|
|
5
5
|
"module": "esm/index.js",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@cloudcare/browser-core": "3.1.
|
|
8
|
-
"@cloudcare/browser-worker": "3.1.
|
|
7
|
+
"@cloudcare/browser-core": "3.1.1",
|
|
8
|
+
"@cloudcare/browser-worker": "3.1.1"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
11
|
"dev": "webpack serve --open --mode=development",
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"homepage": "https://github.com/CloudCare/dataflux-rum-sdk-javascript/blob/master/packages/rum/README.md",
|
|
33
33
|
"description": "DataFlux RUM Web 端数据指标监控",
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "7216e7579806f7c9992938c41c7e383aebc9e045"
|
|
35
35
|
}
|
package/src/boot/recorderApi.js
CHANGED
|
@@ -2,12 +2,19 @@ import {
|
|
|
2
2
|
noop,
|
|
3
3
|
runOnReadyState,
|
|
4
4
|
LifeCycleEventType,
|
|
5
|
-
canUseEventBridge
|
|
5
|
+
canUseEventBridge,
|
|
6
|
+
Observable,
|
|
7
|
+
relativeNow
|
|
6
8
|
} from '@cloudcare/browser-core'
|
|
7
9
|
|
|
8
|
-
import { getReplayStats } from '../domain/replay/replayStats'
|
|
9
|
-
import {
|
|
10
|
-
|
|
10
|
+
import { getReplayStats as getReplayStatsImpl } from '../domain/replay/replayStats'
|
|
11
|
+
import {
|
|
12
|
+
DeflateEncoderStreamId,
|
|
13
|
+
createDeflateEncoder,
|
|
14
|
+
startDeflateWorker,
|
|
15
|
+
DeflateWorkerStatus,
|
|
16
|
+
getDeflateWorkerStatus
|
|
17
|
+
} from '../domain/replay/deflate'
|
|
11
18
|
var RecorderStatus = {
|
|
12
19
|
// The recorder is stopped.
|
|
13
20
|
Stopped: 0,
|
|
@@ -20,10 +27,8 @@ var RecorderStatus = {
|
|
|
20
27
|
Started: 3
|
|
21
28
|
}
|
|
22
29
|
|
|
23
|
-
export function makeRecorderApi(startRecordingImpl,
|
|
24
|
-
|
|
25
|
-
startDeflateWorkerImpl = startDeflateWorker
|
|
26
|
-
}
|
|
30
|
+
export function makeRecorderApi(startRecordingImpl, createDeflateWorkerImpl) {
|
|
31
|
+
var recorderStartObservable = new Observable()
|
|
27
32
|
if (canUseEventBridge() || !isBrowserSupported()) {
|
|
28
33
|
return {
|
|
29
34
|
start: noop,
|
|
@@ -34,7 +39,8 @@ export function makeRecorderApi(startRecordingImpl, startDeflateWorkerImpl) {
|
|
|
34
39
|
onRumStart: noop,
|
|
35
40
|
isRecording: function () {
|
|
36
41
|
return false
|
|
37
|
-
}
|
|
42
|
+
},
|
|
43
|
+
recorderStartObservable: recorderStartObservable
|
|
38
44
|
}
|
|
39
45
|
}
|
|
40
46
|
|
|
@@ -55,7 +61,12 @@ export function makeRecorderApi(startRecordingImpl, startDeflateWorkerImpl) {
|
|
|
55
61
|
stop: function () {
|
|
56
62
|
stopStrategy()
|
|
57
63
|
},
|
|
58
|
-
|
|
64
|
+
recorderStartObservable: recorderStartObservable,
|
|
65
|
+
getReplayStats: function (viewId) {
|
|
66
|
+
return getDeflateWorkerStatus() === DeflateWorkerStatus.Initialized
|
|
67
|
+
? getReplayStatsImpl(viewId)
|
|
68
|
+
: undefined
|
|
69
|
+
},
|
|
59
70
|
|
|
60
71
|
onRumStart: function (
|
|
61
72
|
lifeCycle,
|
|
@@ -99,30 +110,30 @@ export function makeRecorderApi(startRecordingImpl, startDeflateWorkerImpl) {
|
|
|
99
110
|
if (state.status !== RecorderStatus.Starting) {
|
|
100
111
|
return
|
|
101
112
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
state = {
|
|
110
|
-
status: RecorderStatus.Stopped
|
|
111
|
-
}
|
|
112
|
-
return
|
|
113
|
-
}
|
|
114
|
-
var recordingImpl = startRecordingImpl(
|
|
115
|
-
lifeCycle,
|
|
116
|
-
configuration,
|
|
117
|
-
sessionManager,
|
|
118
|
-
viewContexts,
|
|
119
|
-
worker
|
|
120
|
-
)
|
|
113
|
+
if (state.status !== RecorderStatus.Starting) {
|
|
114
|
+
return
|
|
115
|
+
}
|
|
116
|
+
var worker = startDeflateWorker(function () {
|
|
117
|
+
stopStrategy()
|
|
118
|
+
}, createDeflateWorkerImpl)
|
|
119
|
+
if (!worker) {
|
|
121
120
|
state = {
|
|
122
|
-
status: RecorderStatus.
|
|
123
|
-
stopRecording: recordingImpl.stop
|
|
121
|
+
status: RecorderStatus.Stopped
|
|
124
122
|
}
|
|
125
|
-
|
|
123
|
+
return
|
|
124
|
+
}
|
|
125
|
+
var recordingImpl = startRecordingImpl(
|
|
126
|
+
lifeCycle,
|
|
127
|
+
configuration,
|
|
128
|
+
sessionManager,
|
|
129
|
+
viewContexts,
|
|
130
|
+
createDeflateEncoder(worker, DeflateEncoderStreamId.REPLAY)
|
|
131
|
+
)
|
|
132
|
+
recorderStartObservable.notify(relativeNow())
|
|
133
|
+
state = {
|
|
134
|
+
status: RecorderStatus.Started,
|
|
135
|
+
stopRecording: recordingImpl.stop
|
|
136
|
+
}
|
|
126
137
|
})
|
|
127
138
|
}
|
|
128
139
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
timeStampNow,
|
|
3
3
|
createHttpRequest,
|
|
4
|
-
LifeCycleEventType
|
|
4
|
+
LifeCycleEventType,
|
|
5
|
+
addTelemetryDebug
|
|
5
6
|
} from '@cloudcare/browser-core'
|
|
6
7
|
import { record } from '../domain/replay/record'
|
|
7
8
|
import {
|
|
@@ -15,11 +16,14 @@ export function startRecording(
|
|
|
15
16
|
configuration,
|
|
16
17
|
sessionManager,
|
|
17
18
|
viewContexts,
|
|
18
|
-
|
|
19
|
+
encoder,
|
|
19
20
|
httpRequest
|
|
20
21
|
) {
|
|
21
22
|
var reportError = function (error) {
|
|
22
23
|
lifeCycle.notify(LifeCycleEventType.RAW_ERROR_COLLECTED, { error: error })
|
|
24
|
+
addTelemetryDebug('Error reported to customer', {
|
|
25
|
+
'error.message': error.message
|
|
26
|
+
})
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
var replayRequest =
|
|
@@ -36,7 +40,7 @@ export function startRecording(
|
|
|
36
40
|
sessionManager,
|
|
37
41
|
viewContexts,
|
|
38
42
|
replayRequest,
|
|
39
|
-
|
|
43
|
+
encoder
|
|
40
44
|
)
|
|
41
45
|
var addRecord = segmentCollection.addRecord
|
|
42
46
|
var stopSegmentCollection = segmentCollection.stop
|
|
@@ -48,7 +48,6 @@ export function startPageStateHistory(maxPageStateEntriesSelectable) {
|
|
|
48
48
|
],
|
|
49
49
|
function (event) {
|
|
50
50
|
// Only get events fired by the browser to avoid false currentPageState changes done with custom events
|
|
51
|
-
// cf: developer extension auto flush: https://github.com/DataDog/browser-sdk/blob/2f72bf05a672794c9e33965351964382a94c72ba/developer-extension/src/panel/flushEvents.ts#L11-L12
|
|
52
51
|
if (event.isTrusted) {
|
|
53
52
|
addPageState(computePageState(event), event.timeStamp)
|
|
54
53
|
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import {
|
|
2
|
+
addEventListener,
|
|
3
|
+
concatBuffers,
|
|
4
|
+
addTelemetryDebug
|
|
5
|
+
} from '@cloudcare/browser-core'
|
|
6
|
+
export var DeflateEncoderStreamId = {
|
|
7
|
+
REPLAY: 1
|
|
8
|
+
}
|
|
9
|
+
export function createDeflateEncoder(worker, streamId) {
|
|
10
|
+
var rawBytesCount = 0
|
|
11
|
+
var compressedData = []
|
|
12
|
+
var compressedDataTrailer
|
|
13
|
+
|
|
14
|
+
var nextWriteActionId = 0
|
|
15
|
+
var pendingWriteActions = []
|
|
16
|
+
|
|
17
|
+
var wokerListener = addEventListener(worker, 'message', function (params) {
|
|
18
|
+
var data = params.data
|
|
19
|
+
if (data.type !== 'wrote' || data.streamId !== streamId) {
|
|
20
|
+
return
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var nextPendingAction = pendingWriteActions.shift()
|
|
24
|
+
if (nextPendingAction && nextPendingAction.id === data.id) {
|
|
25
|
+
if (data.id === 0) {
|
|
26
|
+
// Initial state
|
|
27
|
+
rawBytesCount = data.additionalBytesCount
|
|
28
|
+
compressedData = [data.result]
|
|
29
|
+
} else {
|
|
30
|
+
rawBytesCount += data.additionalBytesCount
|
|
31
|
+
compressedData.push(data.result)
|
|
32
|
+
}
|
|
33
|
+
compressedDataTrailer = data.trailer
|
|
34
|
+
nextPendingAction.callback()
|
|
35
|
+
} else {
|
|
36
|
+
removeMessageListener()
|
|
37
|
+
addTelemetryDebug('Worker responses received out of order.')
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
var removeMessageListener = wokerListener.stop
|
|
41
|
+
return {
|
|
42
|
+
getEncodedBytes: function () {
|
|
43
|
+
if (!compressedData.length) {
|
|
44
|
+
return new Uint8Array(0)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return concatBuffers(compressedData.concat(compressedDataTrailer))
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
getEncodedBytesCount: function () {
|
|
51
|
+
if (!compressedData.length) {
|
|
52
|
+
return 0
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
compressedData.reduce(function (total, buffer) {
|
|
57
|
+
return total + buffer.length
|
|
58
|
+
}, 0) + compressedDataTrailer.length
|
|
59
|
+
)
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
getRawBytesCount: function () {
|
|
63
|
+
return rawBytesCount
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
write: function (data, callback) {
|
|
67
|
+
worker.postMessage({
|
|
68
|
+
action: 'write',
|
|
69
|
+
id: nextWriteActionId,
|
|
70
|
+
data: data,
|
|
71
|
+
streamId: streamId
|
|
72
|
+
})
|
|
73
|
+
pendingWriteActions.push({
|
|
74
|
+
id: nextWriteActionId,
|
|
75
|
+
callback: callback
|
|
76
|
+
})
|
|
77
|
+
nextWriteActionId += 1
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
reset: function () {
|
|
81
|
+
worker.postMessage({
|
|
82
|
+
action: 'reset',
|
|
83
|
+
streamId: streamId
|
|
84
|
+
})
|
|
85
|
+
nextWriteActionId = 0
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
package/src/domain/replay/{segmentCollection/startDeflateWorker.js → deflate/deflateWorker.js}
RENAMED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import {
|
|
2
2
|
display,
|
|
3
3
|
includes,
|
|
4
|
-
|
|
5
|
-
addEventListener
|
|
4
|
+
setTimeout,
|
|
5
|
+
addEventListener,
|
|
6
|
+
addTelemetryError,
|
|
7
|
+
ONE_SECOND
|
|
6
8
|
} from '@cloudcare/browser-core'
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
+
|
|
10
|
+
export var INITIALIZATION_TIME_OUT_DELAY = 10 * ONE_SECOND
|
|
9
11
|
|
|
10
12
|
export function createDeflateWorker() {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
return new Worker(workerURL)
|
|
13
|
+
return new Worker(
|
|
14
|
+
URL.createObjectURL(new Blob([__BUILD_ENV__WORKER_STRING__]))
|
|
15
|
+
)
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* In order to be sure that the worker is correctly working, we need a round trip of
|
|
19
19
|
* initialization messages, making the creation asynchronous.
|
|
20
20
|
* These worker lifecycle states handle this case.
|
|
21
21
|
*/
|
|
22
|
-
var DeflateWorkerStatus = {
|
|
22
|
+
export var DeflateWorkerStatus = {
|
|
23
23
|
Nil: 0,
|
|
24
24
|
Loading: 1,
|
|
25
25
|
Error: 2,
|
|
@@ -28,30 +28,31 @@ var DeflateWorkerStatus = {
|
|
|
28
28
|
|
|
29
29
|
var state = { status: DeflateWorkerStatus.Nil }
|
|
30
30
|
|
|
31
|
-
export function startDeflateWorker(
|
|
31
|
+
export function startDeflateWorker(
|
|
32
|
+
onInitializationFailure,
|
|
33
|
+
createDeflateWorkerImpl
|
|
34
|
+
) {
|
|
32
35
|
if (createDeflateWorkerImpl === undefined) {
|
|
33
36
|
createDeflateWorkerImpl = createDeflateWorker
|
|
34
37
|
}
|
|
38
|
+
if (state.status === DeflateWorkerStatus.Nil) {
|
|
39
|
+
doStartDeflateWorker(createDeflateWorkerImpl)
|
|
40
|
+
}
|
|
35
41
|
switch (state.status) {
|
|
36
|
-
case DeflateWorkerStatus.Nil:
|
|
37
|
-
state = { status: DeflateWorkerStatus.Loading, callbacks: [callback] }
|
|
38
|
-
doStartDeflateWorker(createDeflateWorkerImpl)
|
|
39
|
-
break
|
|
40
42
|
case DeflateWorkerStatus.Loading:
|
|
41
|
-
state.
|
|
42
|
-
|
|
43
|
-
case DeflateWorkerStatus.Error:
|
|
44
|
-
callback()
|
|
45
|
-
break
|
|
43
|
+
state.initializationFailureCallbacks.push(onInitializationFailure)
|
|
44
|
+
return state.worker
|
|
46
45
|
case DeflateWorkerStatus.Initialized:
|
|
47
|
-
|
|
48
|
-
break
|
|
46
|
+
return state.worker
|
|
49
47
|
}
|
|
50
48
|
}
|
|
51
49
|
|
|
52
50
|
export function resetDeflateWorkerState() {
|
|
53
51
|
state = { status: DeflateWorkerStatus.Nil }
|
|
54
52
|
}
|
|
53
|
+
export function getDeflateWorkerStatus() {
|
|
54
|
+
return state.status
|
|
55
|
+
}
|
|
55
56
|
|
|
56
57
|
/**
|
|
57
58
|
* Starts the deflate worker and handle messages and errors
|
|
@@ -74,24 +75,36 @@ export function doStartDeflateWorker(createDeflateWorkerImpl) {
|
|
|
74
75
|
if (data.type === 'errored') {
|
|
75
76
|
onError(data.error, data.streamId)
|
|
76
77
|
} else if (data.type === 'initialized') {
|
|
77
|
-
onInitialized(
|
|
78
|
+
onInitialized(data.version)
|
|
78
79
|
}
|
|
79
80
|
})
|
|
80
81
|
worker.postMessage({ action: 'init' })
|
|
81
|
-
|
|
82
|
+
setTimeout(onTimeout, INITIALIZATION_TIME_OUT_DELAY)
|
|
83
|
+
state = {
|
|
84
|
+
status: DeflateWorkerStatus.Loading,
|
|
85
|
+
worker: worker,
|
|
86
|
+
initializationFailureCallbacks: []
|
|
87
|
+
}
|
|
82
88
|
} catch (error) {
|
|
83
89
|
onError(error)
|
|
84
90
|
}
|
|
85
91
|
}
|
|
86
|
-
|
|
87
|
-
function onInitialized(worker, version) {
|
|
92
|
+
function onTimeout() {
|
|
88
93
|
if (state.status === DeflateWorkerStatus.Loading) {
|
|
89
|
-
|
|
90
|
-
|
|
94
|
+
display.error(
|
|
95
|
+
'Session Replay recording failed to start: a timeout occurred while initializing the Worker'
|
|
96
|
+
)
|
|
97
|
+
state.initializationFailureCallbacks.forEach(function (callback) {
|
|
98
|
+
callback()
|
|
91
99
|
})
|
|
100
|
+
state = { status: DeflateWorkerStatus.Error }
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function onInitialized(version) {
|
|
104
|
+
if (state.status === DeflateWorkerStatus.Loading) {
|
|
92
105
|
state = {
|
|
93
106
|
status: DeflateWorkerStatus.Initialized,
|
|
94
|
-
worker: worker,
|
|
107
|
+
worker: state.worker,
|
|
95
108
|
version: version
|
|
96
109
|
}
|
|
97
110
|
}
|
|
@@ -108,11 +121,21 @@ function onError(error, streamId) {
|
|
|
108
121
|
(error instanceof Error && isMessageCspRelated(error.message))
|
|
109
122
|
) {
|
|
110
123
|
display.error('Please make sure CSP is correctly configured !!!')
|
|
124
|
+
} else {
|
|
125
|
+
addTelemetryError(error)
|
|
126
|
+
}
|
|
127
|
+
if (state.status === DeflateWorkerStatus.Loading) {
|
|
128
|
+
state.initializationFailureCallbacks.forEach(function (callback) {
|
|
129
|
+
callback()
|
|
130
|
+
})
|
|
111
131
|
}
|
|
112
|
-
each(state.callbacks, function (callback) {
|
|
113
|
-
callback()
|
|
114
|
-
})
|
|
115
132
|
state = { status: DeflateWorkerStatus.Error }
|
|
133
|
+
} else {
|
|
134
|
+
addTelemetryError(error, {
|
|
135
|
+
worker_version:
|
|
136
|
+
state.status === DeflateWorkerStatus.Initialized && state.version,
|
|
137
|
+
stream_id: streamId
|
|
138
|
+
})
|
|
116
139
|
}
|
|
117
140
|
}
|
|
118
141
|
function isMessageCspRelated(message) {
|
|
@@ -13,7 +13,7 @@ export function buildReplayPayload(data, metadata, rawSegmentBytesCount) {
|
|
|
13
13
|
toFormEntries(metadata, function (key, value) {
|
|
14
14
|
formData.append(key, value)
|
|
15
15
|
})
|
|
16
|
-
formData.append('raw_segment_size', rawSegmentBytesCount
|
|
16
|
+
formData.append('raw_segment_size', rawSegmentBytesCount)
|
|
17
17
|
|
|
18
18
|
return { data: formData, bytesCount: data.byteLength }
|
|
19
19
|
}
|