@cloudcare/browser-core 3.2.13 → 3.2.15
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/cjs/dataMap.js +1 -1
- package/cjs/dataMap.js.map +1 -1
- package/cjs/helper/lifeCycle.js +1 -0
- package/cjs/helper/lifeCycle.js.map +1 -1
- package/cjs/helper/limitModification.js +39 -38
- package/cjs/helper/limitModification.js.map +1 -1
- package/cjs/helper/serialisation/const.js +18 -0
- package/cjs/helper/serialisation/const.js.map +1 -0
- package/cjs/helper/serialisation/contextManager.js +45 -50
- package/cjs/helper/serialisation/contextManager.js.map +1 -1
- package/cjs/helper/serialisation/customerDataTracker.js +127 -0
- package/cjs/helper/serialisation/customerDataTracker.js.map +1 -0
- package/cjs/index.js +16 -4
- package/cjs/index.js.map +1 -1
- package/esm/dataMap.js +1 -1
- package/esm/dataMap.js.map +1 -1
- package/esm/helper/lifeCycle.js +1 -0
- package/esm/helper/lifeCycle.js.map +1 -1
- package/esm/helper/limitModification.js +40 -40
- package/esm/helper/limitModification.js.map +1 -1
- package/esm/helper/serialisation/const.js +11 -0
- package/esm/helper/serialisation/const.js.map +1 -0
- package/esm/helper/serialisation/contextManager.js +46 -49
- package/esm/helper/serialisation/contextManager.js.map +1 -1
- package/esm/helper/serialisation/customerDataTracker.js +116 -0
- package/esm/helper/serialisation/customerDataTracker.js.map +1 -0
- package/esm/index.js +2 -1
- package/esm/index.js.map +1 -1
- package/package.json +2 -2
- package/src/dataMap.js +1 -1
- package/src/helper/lifeCycle.js +1 -0
- package/src/helper/limitModification.js +43 -48
- package/src/helper/serialisation/const.js +10 -0
- package/src/helper/serialisation/contextManager.js +41 -64
- package/src/helper/serialisation/customerDataTracker.js +139 -0
- package/src/index.js +2 -1
- package/cjs/helper/serialisation/heavyCustomerDataWarning.js +0 -29
- package/cjs/helper/serialisation/heavyCustomerDataWarning.js.map +0 -1
- package/esm/helper/serialisation/heavyCustomerDataWarning.js +0 -21
- package/esm/helper/serialisation/heavyCustomerDataWarning.js.map +0 -1
- package/src/helper/serialisation/heavyCustomerDataWarning.js +0 -28
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { ONE_KIBI_BYTE, computeBytesCount } from '../byteUtils'
|
|
2
|
+
import { throttle, isEmptyObject } from '../tools'
|
|
3
|
+
import { jsonStringify } from './jsonStringify'
|
|
4
|
+
import { display } from '../display'
|
|
5
|
+
|
|
6
|
+
// RUM and logs batch bytes limit is 16KB
|
|
7
|
+
// ensure that we leave room for other event attributes and maintain a decent amount of event per batch
|
|
8
|
+
// (3KB (customer data) + 1KB (other attributes)) * 4 (events per batch) = 16KB
|
|
9
|
+
export const CUSTOMER_DATA_BYTES_LIMIT = 3 * ONE_KIBI_BYTE
|
|
10
|
+
|
|
11
|
+
// We observed that the compression ratio is around 8 in general, but we also want to keep a margin
|
|
12
|
+
// because some data might not be compressed (ex: last view update on page exit). We chose 16KiB
|
|
13
|
+
// because it is also the limit of the 'batchBytesCount' that we use for RUM and Logs data, but this
|
|
14
|
+
// is a bit arbitrary.
|
|
15
|
+
export const CUSTOMER_COMPRESSED_DATA_BYTES_LIMIT = 16 * ONE_KIBI_BYTE
|
|
16
|
+
|
|
17
|
+
export const BYTES_COMPUTATION_THROTTLING_DELAY = 200
|
|
18
|
+
|
|
19
|
+
export const CustomerDataCompressionStatus = {
|
|
20
|
+
Unknown: 0,
|
|
21
|
+
Enabled: 1,
|
|
22
|
+
Disabled: 2
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function createCustomerDataTrackerManager(
|
|
26
|
+
compressionStatus = CustomerDataCompressionStatus.Disabled
|
|
27
|
+
) {
|
|
28
|
+
const customerDataTrackers = new Map()
|
|
29
|
+
|
|
30
|
+
let alreadyWarned = false
|
|
31
|
+
function checkCustomerDataLimit(initialBytesCount = 0) {
|
|
32
|
+
if (
|
|
33
|
+
alreadyWarned ||
|
|
34
|
+
compressionStatus === CustomerDataCompressionStatus.Unknown
|
|
35
|
+
) {
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const bytesCountLimit =
|
|
40
|
+
compressionStatus === CustomerDataCompressionStatus.Disabled
|
|
41
|
+
? CUSTOMER_DATA_BYTES_LIMIT
|
|
42
|
+
: CUSTOMER_COMPRESSED_DATA_BYTES_LIMIT
|
|
43
|
+
|
|
44
|
+
let bytesCount = initialBytesCount
|
|
45
|
+
customerDataTrackers.forEach((tracker) => {
|
|
46
|
+
bytesCount += tracker.getBytesCount()
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
if (bytesCount > bytesCountLimit) {
|
|
50
|
+
displayCustomerDataLimitReachedWarning(bytesCountLimit)
|
|
51
|
+
alreadyWarned = true
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
/**
|
|
57
|
+
* Creates a detached tracker. The manager will not store a reference to that tracker, and the
|
|
58
|
+
* bytes count will be counted independently from other detached trackers.
|
|
59
|
+
*
|
|
60
|
+
* This is particularly useful when we don't know when the tracker will be unused, so we don't
|
|
61
|
+
* leak memory (ex: when used in Logger instances).
|
|
62
|
+
*/
|
|
63
|
+
createDetachedTracker: () => {
|
|
64
|
+
const tracker = createCustomerDataTracker(() =>
|
|
65
|
+
checkCustomerDataLimit(tracker.getBytesCount())
|
|
66
|
+
)
|
|
67
|
+
return tracker
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Creates a tracker if it doesn't exist, and returns it.
|
|
72
|
+
*/
|
|
73
|
+
getOrCreateTracker: (type) => {
|
|
74
|
+
if (!customerDataTrackers.has(type)) {
|
|
75
|
+
customerDataTrackers.set(
|
|
76
|
+
type,
|
|
77
|
+
createCustomerDataTracker(checkCustomerDataLimit)
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
return customerDataTrackers.get(type)
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
setCompressionStatus: (newCompressionStatus) => {
|
|
84
|
+
if (compressionStatus === CustomerDataCompressionStatus.Unknown) {
|
|
85
|
+
compressionStatus = newCompressionStatus
|
|
86
|
+
checkCustomerDataLimit()
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
getCompressionStatus: () => compressionStatus,
|
|
91
|
+
|
|
92
|
+
stop: () => {
|
|
93
|
+
customerDataTrackers.forEach((tracker) => tracker.stop())
|
|
94
|
+
customerDataTrackers.clear()
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function createCustomerDataTracker(checkCustomerDataLimit) {
|
|
100
|
+
let bytesCountCache = 0
|
|
101
|
+
|
|
102
|
+
// Throttle the bytes computation to minimize the impact on performance.
|
|
103
|
+
// Especially useful if the user call context APIs synchronously multiple times in a row
|
|
104
|
+
const {
|
|
105
|
+
throttled: computeBytesCountThrottled,
|
|
106
|
+
cancel: cancelComputeBytesCount
|
|
107
|
+
} = throttle((context) => {
|
|
108
|
+
bytesCountCache = computeBytesCount(jsonStringify(context))
|
|
109
|
+
checkCustomerDataLimit()
|
|
110
|
+
}, BYTES_COMPUTATION_THROTTLING_DELAY)
|
|
111
|
+
|
|
112
|
+
const resetBytesCount = () => {
|
|
113
|
+
cancelComputeBytesCount()
|
|
114
|
+
bytesCountCache = 0
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
updateCustomerData: (context) => {
|
|
119
|
+
if (isEmptyObject(context)) {
|
|
120
|
+
resetBytesCount()
|
|
121
|
+
} else {
|
|
122
|
+
computeBytesCountThrottled(context)
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
resetCustomerData: resetBytesCount,
|
|
126
|
+
getBytesCount: () => bytesCountCache,
|
|
127
|
+
stop: () => {
|
|
128
|
+
cancelComputeBytesCount()
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function displayCustomerDataLimitReachedWarning(bytesCountLimit) {
|
|
134
|
+
display.warn(
|
|
135
|
+
`Customer data exceeds the recommended ${
|
|
136
|
+
bytesCountLimit / ONE_KIBI_BYTE
|
|
137
|
+
}KiB threshold.`
|
|
138
|
+
)
|
|
139
|
+
}
|
package/src/index.js
CHANGED
|
@@ -51,10 +51,11 @@ export * from './transport'
|
|
|
51
51
|
export * from './synthetics/syntheticsWorkerValues'
|
|
52
52
|
|
|
53
53
|
export * from './helper/serialisation/contextManager'
|
|
54
|
-
export * from './helper/serialisation/
|
|
54
|
+
export * from './helper/serialisation/const'
|
|
55
55
|
export * from './helper/serialisation/jsonStringify'
|
|
56
56
|
export * from './helper/serialisation/rowData'
|
|
57
57
|
export * from './helper/serialisation/storedContextManager'
|
|
58
|
+
export * from './helper/serialisation/customerDataTracker'
|
|
58
59
|
export * from './helper/encoder'
|
|
59
60
|
export * from './user'
|
|
60
61
|
export * from './helper/polyfills'
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.CustomerDataType = exports.CUSTOMER_DATA_BYTES_LIMIT = void 0;
|
|
7
|
-
exports.warnIfCustomerDataLimitReached = warnIfCustomerDataLimitReached;
|
|
8
|
-
var _byteUtils = require("../byteUtils");
|
|
9
|
-
var _display = require("../display");
|
|
10
|
-
// RUM and logs batch bytes limit is 16KB
|
|
11
|
-
// ensure that we leave room for other event attributes and maintain a decent amount of event per batch
|
|
12
|
-
// (3KB (customer data) + 1KB (other attributes)) * 4 (events per batch) = 16KB
|
|
13
|
-
var CUSTOMER_DATA_BYTES_LIMIT = 3 * _byteUtils.ONE_KIBI_BYTE;
|
|
14
|
-
exports.CUSTOMER_DATA_BYTES_LIMIT = CUSTOMER_DATA_BYTES_LIMIT;
|
|
15
|
-
var CustomerDataType = {
|
|
16
|
-
FeatureFlag: 'feature flag evaluation',
|
|
17
|
-
User: 'user',
|
|
18
|
-
GlobalContext: 'global context',
|
|
19
|
-
LoggerContext: 'logger context'
|
|
20
|
-
};
|
|
21
|
-
exports.CustomerDataType = CustomerDataType;
|
|
22
|
-
function warnIfCustomerDataLimitReached(bytesCount, customerDataType) {
|
|
23
|
-
if (bytesCount > CUSTOMER_DATA_BYTES_LIMIT) {
|
|
24
|
-
_display.display.warn('The ' + customerDataType + 'data is over ' + CUSTOMER_DATA_BYTES_LIMIT / _byteUtils.ONE_KIBI_BYTE + " KiB. On low connectivity, the SDK has the potential to exhaust the user's upload bandwidth.");
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
//# sourceMappingURL=heavyCustomerDataWarning.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"heavyCustomerDataWarning.js","names":["_byteUtils","require","_display","CUSTOMER_DATA_BYTES_LIMIT","ONE_KIBI_BYTE","exports","CustomerDataType","FeatureFlag","User","GlobalContext","LoggerContext","warnIfCustomerDataLimitReached","bytesCount","customerDataType","display","warn"],"sources":["../../../src/helper/serialisation/heavyCustomerDataWarning.js"],"sourcesContent":["import { ONE_KIBI_BYTE } from '../byteUtils'\nimport { display } from '../display'\n\n// RUM and logs batch bytes limit is 16KB\n// ensure that we leave room for other event attributes and maintain a decent amount of event per batch\n// (3KB (customer data) + 1KB (other attributes)) * 4 (events per batch) = 16KB\nexport var CUSTOMER_DATA_BYTES_LIMIT = 3 * ONE_KIBI_BYTE\n\nexport var CustomerDataType = {\n FeatureFlag: 'feature flag evaluation',\n User: 'user',\n GlobalContext: 'global context',\n LoggerContext: 'logger context'\n}\n\nexport function warnIfCustomerDataLimitReached(bytesCount, customerDataType) {\n if (bytesCount > CUSTOMER_DATA_BYTES_LIMIT) {\n display.warn(\n 'The ' +\n customerDataType +\n 'data is over ' +\n CUSTOMER_DATA_BYTES_LIMIT / ONE_KIBI_BYTE +\n \" KiB. On low connectivity, the SDK has the potential to exhaust the user's upload bandwidth.\"\n )\n return true\n }\n return false\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAEA;AACA;AACA;AACO,IAAIE,yBAAyB,GAAG,CAAC,GAAGC,wBAAa;AAAAC,OAAA,CAAAF,yBAAA,GAAAA,yBAAA;AAEjD,IAAIG,gBAAgB,GAAG;EAC5BC,WAAW,EAAE,yBAAyB;EACtCC,IAAI,EAAE,MAAM;EACZC,aAAa,EAAE,gBAAgB;EAC/BC,aAAa,EAAE;AACjB,CAAC;AAAAL,OAAA,CAAAC,gBAAA,GAAAA,gBAAA;AAEM,SAASK,8BAA8BA,CAACC,UAAU,EAAEC,gBAAgB,EAAE;EAC3E,IAAID,UAAU,GAAGT,yBAAyB,EAAE;IAC1CW,gBAAO,CAACC,IAAI,CACV,MAAM,GACJF,gBAAgB,GAChB,eAAe,GACfV,yBAAyB,GAAGC,wBAAa,GACzC,8FACJ,CAAC;IACD,OAAO,IAAI;EACb;EACA,OAAO,KAAK;AACd","ignoreList":[]}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ONE_KIBI_BYTE } from '../byteUtils';
|
|
2
|
-
import { display } from '../display';
|
|
3
|
-
|
|
4
|
-
// RUM and logs batch bytes limit is 16KB
|
|
5
|
-
// ensure that we leave room for other event attributes and maintain a decent amount of event per batch
|
|
6
|
-
// (3KB (customer data) + 1KB (other attributes)) * 4 (events per batch) = 16KB
|
|
7
|
-
export var CUSTOMER_DATA_BYTES_LIMIT = 3 * ONE_KIBI_BYTE;
|
|
8
|
-
export var CustomerDataType = {
|
|
9
|
-
FeatureFlag: 'feature flag evaluation',
|
|
10
|
-
User: 'user',
|
|
11
|
-
GlobalContext: 'global context',
|
|
12
|
-
LoggerContext: 'logger context'
|
|
13
|
-
};
|
|
14
|
-
export function warnIfCustomerDataLimitReached(bytesCount, customerDataType) {
|
|
15
|
-
if (bytesCount > CUSTOMER_DATA_BYTES_LIMIT) {
|
|
16
|
-
display.warn('The ' + customerDataType + 'data is over ' + CUSTOMER_DATA_BYTES_LIMIT / ONE_KIBI_BYTE + " KiB. On low connectivity, the SDK has the potential to exhaust the user's upload bandwidth.");
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=heavyCustomerDataWarning.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"heavyCustomerDataWarning.js","names":["ONE_KIBI_BYTE","display","CUSTOMER_DATA_BYTES_LIMIT","CustomerDataType","FeatureFlag","User","GlobalContext","LoggerContext","warnIfCustomerDataLimitReached","bytesCount","customerDataType","warn"],"sources":["../../../src/helper/serialisation/heavyCustomerDataWarning.js"],"sourcesContent":["import { ONE_KIBI_BYTE } from '../byteUtils'\nimport { display } from '../display'\n\n// RUM and logs batch bytes limit is 16KB\n// ensure that we leave room for other event attributes and maintain a decent amount of event per batch\n// (3KB (customer data) + 1KB (other attributes)) * 4 (events per batch) = 16KB\nexport var CUSTOMER_DATA_BYTES_LIMIT = 3 * ONE_KIBI_BYTE\n\nexport var CustomerDataType = {\n FeatureFlag: 'feature flag evaluation',\n User: 'user',\n GlobalContext: 'global context',\n LoggerContext: 'logger context'\n}\n\nexport function warnIfCustomerDataLimitReached(bytesCount, customerDataType) {\n if (bytesCount > CUSTOMER_DATA_BYTES_LIMIT) {\n display.warn(\n 'The ' +\n customerDataType +\n 'data is over ' +\n CUSTOMER_DATA_BYTES_LIMIT / ONE_KIBI_BYTE +\n \" KiB. On low connectivity, the SDK has the potential to exhaust the user's upload bandwidth.\"\n )\n return true\n }\n return false\n}\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,cAAc;AAC5C,SAASC,OAAO,QAAQ,YAAY;;AAEpC;AACA;AACA;AACA,OAAO,IAAIC,yBAAyB,GAAG,CAAC,GAAGF,aAAa;AAExD,OAAO,IAAIG,gBAAgB,GAAG;EAC5BC,WAAW,EAAE,yBAAyB;EACtCC,IAAI,EAAE,MAAM;EACZC,aAAa,EAAE,gBAAgB;EAC/BC,aAAa,EAAE;AACjB,CAAC;AAED,OAAO,SAASC,8BAA8BA,CAACC,UAAU,EAAEC,gBAAgB,EAAE;EAC3E,IAAID,UAAU,GAAGP,yBAAyB,EAAE;IAC1CD,OAAO,CAACU,IAAI,CACV,MAAM,GACJD,gBAAgB,GAChB,eAAe,GACfR,yBAAyB,GAAGF,aAAa,GACzC,8FACJ,CAAC;IACD,OAAO,IAAI;EACb;EACA,OAAO,KAAK;AACd","ignoreList":[]}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { ONE_KIBI_BYTE } from '../byteUtils'
|
|
2
|
-
import { display } from '../display'
|
|
3
|
-
|
|
4
|
-
// RUM and logs batch bytes limit is 16KB
|
|
5
|
-
// ensure that we leave room for other event attributes and maintain a decent amount of event per batch
|
|
6
|
-
// (3KB (customer data) + 1KB (other attributes)) * 4 (events per batch) = 16KB
|
|
7
|
-
export var CUSTOMER_DATA_BYTES_LIMIT = 3 * ONE_KIBI_BYTE
|
|
8
|
-
|
|
9
|
-
export var CustomerDataType = {
|
|
10
|
-
FeatureFlag: 'feature flag evaluation',
|
|
11
|
-
User: 'user',
|
|
12
|
-
GlobalContext: 'global context',
|
|
13
|
-
LoggerContext: 'logger context'
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function warnIfCustomerDataLimitReached(bytesCount, customerDataType) {
|
|
17
|
-
if (bytesCount > CUSTOMER_DATA_BYTES_LIMIT) {
|
|
18
|
-
display.warn(
|
|
19
|
-
'The ' +
|
|
20
|
-
customerDataType +
|
|
21
|
-
'data is over ' +
|
|
22
|
-
CUSTOMER_DATA_BYTES_LIMIT / ONE_KIBI_BYTE +
|
|
23
|
-
" KiB. On low connectivity, the SDK has the potential to exhaust the user's upload bandwidth."
|
|
24
|
-
)
|
|
25
|
-
return true
|
|
26
|
-
}
|
|
27
|
-
return false
|
|
28
|
-
}
|