@cloudcare/rum-uniapp 2.1.16 → 2.1.17
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/boot/buildEnv.js +1 -1
- package/cjs/boot/rum.entry.js +78 -56
- package/cjs/boot/rum.js +4 -3
- package/cjs/core/baseInfo.js +15 -1
- package/cjs/core/boundedBuffer.js +10 -6
- package/cjs/core/contextManager.js +84 -0
- package/cjs/core/dataMap.js +6 -1
- package/cjs/core/heavyCustomerDataWarning.js +31 -0
- package/cjs/core/transport.js +6 -28
- package/cjs/core/user.js +40 -0
- package/cjs/helper/byteUtils.js +39 -0
- package/cjs/helper/commonContext.js +14 -0
- package/cjs/helper/jsonStringify.js +57 -0
- package/cjs/helper/tracekit.js +23 -4
- package/cjs/helper/utils.js +160 -130
- package/cjs/rumEventsCollection/assembly.js +6 -1
- package/cjs/rumEventsCollection/error/errorCollection.js +20 -24
- package/cjs/rumEventsCollection/page/index.js +3 -2
- package/cjs/rumEventsCollection/resource/resourceCollection.js +3 -1
- package/esm/boot/buildEnv.js +1 -1
- package/esm/boot/rum.entry.js +73 -55
- package/esm/boot/rum.js +4 -2
- package/esm/core/baseInfo.js +13 -1
- package/esm/core/boundedBuffer.js +9 -6
- package/esm/core/contextManager.js +70 -0
- package/esm/core/dataMap.js +4 -0
- package/esm/core/heavyCustomerDataWarning.js +19 -0
- package/esm/core/transport.js +6 -29
- package/esm/core/user.js +31 -0
- package/esm/helper/byteUtils.js +29 -0
- package/esm/helper/commonContext.js +7 -0
- package/esm/helper/jsonStringify.js +46 -0
- package/esm/helper/tracekit.js +22 -4
- package/esm/helper/utils.js +144 -115
- package/esm/rumEventsCollection/assembly.js +6 -1
- package/esm/rumEventsCollection/error/errorCollection.js +20 -25
- package/esm/rumEventsCollection/page/index.js +4 -3
- package/esm/rumEventsCollection/resource/resourceCollection.js +2 -1
- package/package.json +43 -43
package/cjs/boot/buildEnv.js
CHANGED
package/cjs/boot/rum.entry.js
CHANGED
|
@@ -11,16 +11,48 @@ var _rum = require("./rum");
|
|
|
11
11
|
|
|
12
12
|
var _enums = require("../helper/enums");
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
var _commonContext = require("../helper/commonContext");
|
|
15
|
+
|
|
16
|
+
var _boundedBuffer = require("../core/boundedBuffer");
|
|
17
|
+
|
|
18
|
+
var _contextManager = require("../core/contextManager");
|
|
19
|
+
|
|
20
|
+
var _heavyCustomerDataWarning = require("../core/heavyCustomerDataWarning");
|
|
21
|
+
|
|
22
|
+
var _user = require("../core/user");
|
|
23
|
+
|
|
24
|
+
var _sdk = require("../core/sdk");
|
|
15
25
|
|
|
16
26
|
var makeRum = function makeRum(startRumImpl) {
|
|
17
27
|
var isAlreadyInitialized = false;
|
|
18
|
-
var globalContextManager = (0,
|
|
19
|
-
var user = {}
|
|
28
|
+
var globalContextManager = (0, _contextManager.createContextManager)(_heavyCustomerDataWarning.CustomerDataType.GlobalContext);
|
|
29
|
+
var userContextManager = (0, _contextManager.createContextManager)(_heavyCustomerDataWarning.CustomerDataType.User); // var user = {}
|
|
30
|
+
|
|
31
|
+
var getInternalContextStrategy = function getInternalContextStrategy() {
|
|
32
|
+
return undefined;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
var bufferApiCalls = new _boundedBuffer.BoundedBuffer();
|
|
36
|
+
|
|
37
|
+
var _addActionStrategy = function addActionStrategy(action, commonContext) {
|
|
38
|
+
if (typeof commonContext == 'undefined') {
|
|
39
|
+
commonContext = (0, _commonContext.buildCommonContext)(globalContextManager, userContextManager);
|
|
40
|
+
}
|
|
20
41
|
|
|
21
|
-
|
|
42
|
+
bufferApiCalls.add(function () {
|
|
43
|
+
return _addActionStrategy(action, commonContext);
|
|
44
|
+
});
|
|
45
|
+
};
|
|
22
46
|
|
|
23
|
-
var
|
|
47
|
+
var _addErrorStrategy = function addErrorStrategy(providedError, commonContext) {
|
|
48
|
+
if (typeof commonContext == 'undefined') {
|
|
49
|
+
commonContext = (0, _commonContext.buildCommonContext)(globalContextManager, userContextManager);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
bufferApiCalls.add(function () {
|
|
53
|
+
return _addErrorStrategy(providedError, commonContext);
|
|
54
|
+
});
|
|
55
|
+
};
|
|
24
56
|
|
|
25
57
|
var rumGlobal = {
|
|
26
58
|
init: function init(Vue, userConfiguration) {
|
|
@@ -35,54 +67,66 @@ var makeRum = function makeRum(startRumImpl) {
|
|
|
35
67
|
}
|
|
36
68
|
|
|
37
69
|
var _startRumImpl = startRumImpl(Vue, userConfiguration, function () {
|
|
38
|
-
return
|
|
39
|
-
user: user,
|
|
40
|
-
context: globalContextManager.get()
|
|
41
|
-
};
|
|
70
|
+
return (0, _commonContext.buildCommonContext)(globalContextManager, userContextManager);
|
|
42
71
|
});
|
|
43
72
|
|
|
44
|
-
|
|
45
|
-
|
|
73
|
+
getInternalContextStrategy = _startRumImpl.getInternalContext;
|
|
74
|
+
_addActionStrategy = _startRumImpl.addAction;
|
|
75
|
+
_addErrorStrategy = _startRumImpl.addError;
|
|
76
|
+
bufferApiCalls.drain();
|
|
46
77
|
isAlreadyInitialized = true;
|
|
47
78
|
},
|
|
48
79
|
initVue3: function initVue3(userConfiguration) {
|
|
49
|
-
this.init({},
|
|
80
|
+
this.init({}, extend({
|
|
50
81
|
isVue2: false
|
|
51
82
|
}, userConfiguration));
|
|
52
83
|
},
|
|
53
84
|
getInternalContext: function getInternalContext(startTime) {
|
|
54
|
-
return
|
|
85
|
+
return getInternalContextStrategy(startTime);
|
|
55
86
|
},
|
|
56
|
-
addRumGlobalContext: globalContextManager.
|
|
57
|
-
removeRumGlobalContext: globalContextManager.
|
|
58
|
-
getRumGlobalContext: globalContextManager.
|
|
59
|
-
setRumGlobalContext: globalContextManager.
|
|
87
|
+
addRumGlobalContext: globalContextManager.setContextProperty,
|
|
88
|
+
removeRumGlobalContext: globalContextManager.removeContextProperty,
|
|
89
|
+
getRumGlobalContext: globalContextManager.getContext,
|
|
90
|
+
setRumGlobalContext: globalContextManager.setContext,
|
|
91
|
+
clearRumGlobalContext: globalContextManager.clearContext,
|
|
60
92
|
addAction: function addAction(name, context) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
93
|
+
_addActionStrategy({
|
|
94
|
+
name: name,
|
|
95
|
+
context: (0, _utils.deepClone)(context),
|
|
96
|
+
startClocks: (0, _utils.now)(),
|
|
97
|
+
type: _enums.ActionType.custom
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
addError: function addError(error, context) {
|
|
101
|
+
_addErrorStrategy({
|
|
102
|
+
error: error,
|
|
103
|
+
context: (0, _utils.extend2Lev)({}, context),
|
|
104
|
+
startTime: (0, _utils.now)()
|
|
105
|
+
});
|
|
69
106
|
},
|
|
107
|
+
setUserProperty: function setUserProperty(key, property) {
|
|
108
|
+
var newUser = {};
|
|
109
|
+
newUser[key] = property;
|
|
110
|
+
var sanitizedProperty = (0, _user.sanitizeUser)(newUser)[key];
|
|
111
|
+
userContextManager.setContextProperty(key, sanitizedProperty);
|
|
112
|
+
},
|
|
113
|
+
removeUserProperty: userContextManager.removeContextProperty,
|
|
70
114
|
setUser: function setUser(newUser) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (sanitizedUser) {
|
|
74
|
-
user = sanitizedUser;
|
|
75
|
-
} else {
|
|
76
|
-
console.error('Unsupported user:', newUser);
|
|
115
|
+
if ((0, _user.checkUser)(newUser)) {
|
|
116
|
+
userContextManager.setContext((0, _user.sanitizeUser)(newUser));
|
|
77
117
|
}
|
|
78
118
|
},
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
119
|
+
getUser: userContextManager.getContext,
|
|
120
|
+
removeUser: userContextManager.clearContext
|
|
82
121
|
};
|
|
83
122
|
return rumGlobal;
|
|
84
123
|
|
|
85
124
|
function canInitRum(userConfiguration) {
|
|
125
|
+
if (!_sdk.sdk) {
|
|
126
|
+
console.error('DATAFLUX_RUM unsupport platform, Fail to start.');
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
|
|
86
130
|
if (isAlreadyInitialized) {
|
|
87
131
|
console.error('DATAFLUX_RUM is already initialized.');
|
|
88
132
|
return false;
|
|
@@ -105,28 +149,6 @@ var makeRum = function makeRum(startRumImpl) {
|
|
|
105
149
|
|
|
106
150
|
return true;
|
|
107
151
|
}
|
|
108
|
-
|
|
109
|
-
function sanitizeUser(newUser) {
|
|
110
|
-
if (_typeof(newUser) !== 'object' || !newUser) {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
var result = (0, _utils.extend2Lev)({}, newUser);
|
|
115
|
-
|
|
116
|
-
if ('id' in result) {
|
|
117
|
-
result.id = String(result.id);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if ('name' in result) {
|
|
121
|
-
result.name = String(result.name);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if ('email' in result) {
|
|
125
|
-
result.email = String(result.email);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return result;
|
|
129
|
-
}
|
|
130
152
|
};
|
|
131
153
|
|
|
132
154
|
exports.makeRum = makeRum;
|
package/cjs/boot/rum.js
CHANGED
|
@@ -37,8 +37,6 @@ var _sessionManagement = require("../core/sessionManagement");
|
|
|
37
37
|
|
|
38
38
|
var _internalContext = require("../rumEventsCollection/internalContext");
|
|
39
39
|
|
|
40
|
-
var _sdk = require("../core/sdk");
|
|
41
|
-
|
|
42
40
|
var startRum = function startRum(Vue, userConfiguration, getCommonContext) {
|
|
43
41
|
var configuration = (0, _configuration.commonInit)(userConfiguration, _buildEnv.buildEnv);
|
|
44
42
|
var lifeCycle = new _lifeCycle.LifeCycle();
|
|
@@ -49,7 +47,9 @@ var startRum = function startRum(Vue, userConfiguration, getCommonContext) {
|
|
|
49
47
|
(0, _appCollection.startAppCollection)(lifeCycle, configuration);
|
|
50
48
|
(0, _resourceCollection.startResourceCollection)(lifeCycle, configuration);
|
|
51
49
|
(0, _viewCollection.startViewCollection)(lifeCycle, configuration, Vue);
|
|
52
|
-
|
|
50
|
+
|
|
51
|
+
var _startErrorCollection = (0, _errorCollection.startErrorCollection)(lifeCycle, configuration);
|
|
52
|
+
|
|
53
53
|
(0, _requestCollection.startRequestCollection)(lifeCycle, configuration);
|
|
54
54
|
(0, _performanceCollection.startPagePerformanceObservable)(lifeCycle, configuration);
|
|
55
55
|
(0, _setDataCollection.startSetDataColloction)(lifeCycle, Vue);
|
|
@@ -59,6 +59,7 @@ var startRum = function startRum(Vue, userConfiguration, getCommonContext) {
|
|
|
59
59
|
var internalContext = (0, _internalContext.startInternalContext)(userConfiguration.applicationId, session, parentContexts);
|
|
60
60
|
return {
|
|
61
61
|
addAction: _startActionCollection.addAction,
|
|
62
|
+
addError: _startErrorCollection.addError,
|
|
62
63
|
getInternalContext: internalContext.get
|
|
63
64
|
};
|
|
64
65
|
};
|
package/cjs/core/baseInfo.js
CHANGED
|
@@ -40,7 +40,7 @@ var BaseInfo = /*#__PURE__*/function () {
|
|
|
40
40
|
osVersion = osInfo[0] || '';
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
var osVersionMajor = osVersion.split('.').length && osVersion.split('.')[0];
|
|
43
|
+
var osVersionMajor = osVersion && osVersion.split('.').length && osVersion.split('.')[0];
|
|
44
44
|
this.deviceInfo = {
|
|
45
45
|
screenSize: "".concat(deviceInfo.screenWidth, "*").concat(deviceInfo.screenHeight, " "),
|
|
46
46
|
platform: deviceInfo.platform,
|
|
@@ -87,6 +87,20 @@ var BaseInfo = /*#__PURE__*/function () {
|
|
|
87
87
|
_this.deviceInfo.network = e.networkType ? e.networkType : 'unknown';
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
|
+
}, {
|
|
91
|
+
key: "getLaunchOptions",
|
|
92
|
+
value: function getLaunchOptions() {
|
|
93
|
+
if (_sdk.sdk.getLaunchOptionsSync) {
|
|
94
|
+
var res = _sdk.sdk.getLaunchOptionsSync();
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
query: res && res.query || {},
|
|
98
|
+
referrerInfo: res && res.referrerInfo || {}
|
|
99
|
+
};
|
|
100
|
+
} else {
|
|
101
|
+
return {};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
90
104
|
}]);
|
|
91
105
|
|
|
92
106
|
return BaseInfo;
|
|
@@ -5,21 +5,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.BoundedBuffer = void 0;
|
|
7
7
|
|
|
8
|
+
var _utils = require("../helper/utils");
|
|
9
|
+
|
|
10
|
+
var BUFFER_LIMIT = 500;
|
|
11
|
+
|
|
8
12
|
var _BoundedBuffer = function _BoundedBuffer() {
|
|
9
13
|
this.buffer = [];
|
|
10
14
|
};
|
|
11
15
|
|
|
12
16
|
_BoundedBuffer.prototype = {
|
|
13
|
-
add: function add(
|
|
14
|
-
var length = this.buffer.push(
|
|
17
|
+
add: function add(callback) {
|
|
18
|
+
var length = this.buffer.push(callback);
|
|
15
19
|
|
|
16
|
-
if (length >
|
|
20
|
+
if (length > BUFFER_LIMIT) {
|
|
17
21
|
this.buffer.splice(0, 1);
|
|
18
22
|
}
|
|
19
23
|
},
|
|
20
|
-
drain: function drain(
|
|
21
|
-
this.buffer
|
|
22
|
-
|
|
24
|
+
drain: function drain() {
|
|
25
|
+
(0, _utils.each)(this.buffer, function (callback) {
|
|
26
|
+
callback();
|
|
23
27
|
});
|
|
24
28
|
this.buffer.length = 0;
|
|
25
29
|
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createContextManager = createContextManager;
|
|
7
|
+
exports.BYTES_COMPUTATION_THROTTLING_DELAY = void 0;
|
|
8
|
+
|
|
9
|
+
var _byteUtils = require("../helper/byteUtils");
|
|
10
|
+
|
|
11
|
+
var _utils = require("../helper/utils");
|
|
12
|
+
|
|
13
|
+
var _jsonStringify = require("../helper/jsonStringify");
|
|
14
|
+
|
|
15
|
+
var _heavyCustomerDataWarning = require("./heavyCustomerDataWarning");
|
|
16
|
+
|
|
17
|
+
var BYTES_COMPUTATION_THROTTLING_DELAY = 200;
|
|
18
|
+
exports.BYTES_COMPUTATION_THROTTLING_DELAY = BYTES_COMPUTATION_THROTTLING_DELAY;
|
|
19
|
+
|
|
20
|
+
function createContextManager(customerDataType, computeBytesCountImpl) {
|
|
21
|
+
if (typeof computeBytesCountImpl === 'undefined') {
|
|
22
|
+
computeBytesCountImpl = _byteUtils.computeBytesCount;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var context = {};
|
|
26
|
+
var bytesCountCache;
|
|
27
|
+
var alreadyWarned = false; // Throttle the bytes computation to minimize the impact on performance.
|
|
28
|
+
// Especially useful if the user call context APIs synchronously multiple times in a row
|
|
29
|
+
|
|
30
|
+
var computeBytesCountThrottled = (0, _utils.throttle)(function (context) {
|
|
31
|
+
bytesCountCache = computeBytesCountImpl((0, _jsonStringify.jsonStringify)(context));
|
|
32
|
+
|
|
33
|
+
if (!alreadyWarned) {
|
|
34
|
+
alreadyWarned = (0, _heavyCustomerDataWarning.warnIfCustomerDataLimitReached)(bytesCountCache, customerDataType);
|
|
35
|
+
}
|
|
36
|
+
}, BYTES_COMPUTATION_THROTTLING_DELAY).throttled;
|
|
37
|
+
return {
|
|
38
|
+
getBytesCount: function getBytesCount() {
|
|
39
|
+
return bytesCountCache;
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
/** @deprecated use getContext instead */
|
|
43
|
+
get: function get() {
|
|
44
|
+
return context;
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
/** @deprecated use setContextProperty instead */
|
|
48
|
+
add: function add(key, value) {
|
|
49
|
+
context[key] = value;
|
|
50
|
+
computeBytesCountThrottled(context);
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
/** @deprecated renamed to removeContextProperty */
|
|
54
|
+
remove: function remove(key) {
|
|
55
|
+
delete context[key];
|
|
56
|
+
computeBytesCountThrottled(context);
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
/** @deprecated use setContext instead */
|
|
60
|
+
set: function set(newContext) {
|
|
61
|
+
context = newContext;
|
|
62
|
+
computeBytesCountThrottled(context);
|
|
63
|
+
},
|
|
64
|
+
getContext: function getContext() {
|
|
65
|
+
return (0, _utils.deepClone)(context);
|
|
66
|
+
},
|
|
67
|
+
setContext: function setContext(newContext) {
|
|
68
|
+
context = (0, _utils.deepClone)(newContext);
|
|
69
|
+
computeBytesCountThrottled(context);
|
|
70
|
+
},
|
|
71
|
+
setContextProperty: function setContextProperty(key, property) {
|
|
72
|
+
context[key] = (0, _utils.deepClone)(property);
|
|
73
|
+
computeBytesCountThrottled(context);
|
|
74
|
+
},
|
|
75
|
+
removeContextProperty: function removeContextProperty(key) {
|
|
76
|
+
delete context[key];
|
|
77
|
+
computeBytesCountThrottled(context);
|
|
78
|
+
},
|
|
79
|
+
clearContext: function clearContext() {
|
|
80
|
+
context = {};
|
|
81
|
+
bytesCountCache = 0;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
package/cjs/core/dataMap.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.dataMap = exports.commonTags = void 0;
|
|
6
|
+
exports.dataMap = exports.commonFields = exports.commonTags = void 0;
|
|
7
7
|
|
|
8
8
|
var _enums = require("../helper/enums");
|
|
9
9
|
|
|
@@ -38,6 +38,11 @@ var commonTags = {
|
|
|
38
38
|
view_referer: 'page.referer'
|
|
39
39
|
};
|
|
40
40
|
exports.commonTags = commonTags;
|
|
41
|
+
var commonFields = {
|
|
42
|
+
app_launch_query: 'app.launch.query',
|
|
43
|
+
app_launch_referrer_info: 'app.launch.referrer_info'
|
|
44
|
+
};
|
|
45
|
+
exports.commonFields = commonFields;
|
|
41
46
|
var dataMap = {
|
|
42
47
|
view: {
|
|
43
48
|
type: _enums.RumEventType.VIEW,
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.warnIfCustomerDataLimitReached = warnIfCustomerDataLimitReached;
|
|
7
|
+
exports.CustomerDataType = exports.CUSTOMER_DATA_BYTES_LIMIT = void 0;
|
|
8
|
+
|
|
9
|
+
var _byteUtils = require("../helper/byteUtils");
|
|
10
|
+
|
|
11
|
+
// RUM and logs batch bytes limit is 16KB
|
|
12
|
+
// ensure that we leave room for other event attributes and maintain a decent amount of event per batch
|
|
13
|
+
// (3KB (customer data) + 1KB (other attributes)) * 4 (events per batch) = 16KB
|
|
14
|
+
var CUSTOMER_DATA_BYTES_LIMIT = 3 * _byteUtils.ONE_KIBI_BYTE;
|
|
15
|
+
exports.CUSTOMER_DATA_BYTES_LIMIT = CUSTOMER_DATA_BYTES_LIMIT;
|
|
16
|
+
var CustomerDataType = {
|
|
17
|
+
FeatureFlag: 'feature flag evaluation',
|
|
18
|
+
User: 'user',
|
|
19
|
+
GlobalContext: 'global context',
|
|
20
|
+
LoggerContext: 'logger context'
|
|
21
|
+
};
|
|
22
|
+
exports.CustomerDataType = CustomerDataType;
|
|
23
|
+
|
|
24
|
+
function warnIfCustomerDataLimitReached(bytesCount, customerDataType) {
|
|
25
|
+
if (bytesCount > CUSTOMER_DATA_BYTES_LIMIT) {
|
|
26
|
+
console.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.");
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return false;
|
|
31
|
+
}
|
package/cjs/core/transport.js
CHANGED
|
@@ -9,6 +9,8 @@ var _utils = require("../helper/utils");
|
|
|
9
9
|
|
|
10
10
|
var _sdk = require("../core/sdk");
|
|
11
11
|
|
|
12
|
+
var _byteUtils = require("../helper/byteUtils");
|
|
13
|
+
|
|
12
14
|
var _lifeCycle = require("../core/lifeCycle");
|
|
13
15
|
|
|
14
16
|
var _dataMap = require("./dataMap");
|
|
@@ -78,8 +80,9 @@ var processedMessageByDataMap = function processedMessageByDataMap(message) {
|
|
|
78
80
|
tagsStr.push((0, _utils.escapeRowData)(_key) + '=' + (0, _utils.escapeRowData)(_value));
|
|
79
81
|
}
|
|
80
82
|
});
|
|
83
|
+
var fields = (0, _utils.extend)({}, _dataMap.commonFields, value.fields);
|
|
81
84
|
var fieldsStr = [];
|
|
82
|
-
(0, _utils.each)(
|
|
85
|
+
(0, _utils.each)(fields, function (_value, _key) {
|
|
83
86
|
if ((0, _utils.isArray)(_value) && _value.length === 2) {
|
|
84
87
|
var type = _value[0],
|
|
85
88
|
value_path = _value[1];
|
|
@@ -186,31 +189,6 @@ batch.prototype = {
|
|
|
186
189
|
processSendData: function processSendData(message) {
|
|
187
190
|
return processedMessageByDataMap(message).rowStr;
|
|
188
191
|
},
|
|
189
|
-
sizeInBytes: function sizeInBytes(candidate) {
|
|
190
|
-
// Accurate byte size computations can degrade performances when there is a lot of events to process
|
|
191
|
-
if (!HAS_MULTI_BYTES_CHARACTERS.test(candidate)) {
|
|
192
|
-
return candidate.length;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
var total = 0,
|
|
196
|
-
charCode; // utf-8编码
|
|
197
|
-
|
|
198
|
-
for (var i = 0, len = candidate.length; i < len; i++) {
|
|
199
|
-
charCode = candidate.charCodeAt(i);
|
|
200
|
-
|
|
201
|
-
if (charCode <= 0x007f) {
|
|
202
|
-
total += 1;
|
|
203
|
-
} else if (charCode <= 0x07ff) {
|
|
204
|
-
total += 2;
|
|
205
|
-
} else if (charCode <= 0xffff) {
|
|
206
|
-
total += 3;
|
|
207
|
-
} else {
|
|
208
|
-
total += 4;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
return total;
|
|
213
|
-
},
|
|
214
192
|
addOrUpdate: function addOrUpdate(message, key) {
|
|
215
193
|
var process = this.process(message);
|
|
216
194
|
if (!process.processedMessage || process.processedMessage === '') return;
|
|
@@ -236,7 +214,7 @@ batch.prototype = {
|
|
|
236
214
|
},
|
|
237
215
|
process: function process(message) {
|
|
238
216
|
var processedMessage = this.processSendData(message);
|
|
239
|
-
var messageBytesSize =
|
|
217
|
+
var messageBytesSize = (0, _byteUtils.computeBytesCount)(processedMessage);
|
|
240
218
|
return {
|
|
241
219
|
processedMessage: processedMessage,
|
|
242
220
|
messageBytesSize: messageBytesSize
|
|
@@ -260,7 +238,7 @@ batch.prototype = {
|
|
|
260
238
|
remove: function remove(key) {
|
|
261
239
|
var removedMessage = this.upsertBuffer[key];
|
|
262
240
|
delete this.upsertBuffer[key];
|
|
263
|
-
var messageBytesSize =
|
|
241
|
+
var messageBytesSize = (0, _byteUtils.computeBytesCount)(removedMessage);
|
|
264
242
|
this.bufferBytesSize -= messageBytesSize;
|
|
265
243
|
this.bufferMessageCount -= 1;
|
|
266
244
|
|
package/cjs/core/user.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.sanitizeUser = sanitizeUser;
|
|
7
|
+
exports.checkUser = checkUser;
|
|
8
|
+
|
|
9
|
+
var _utils = require("../helper/utils");
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Clone input data and ensure known user properties (id, name, email)
|
|
13
|
+
* are strings, as defined here:
|
|
14
|
+
* https://docs.datadoghq.com/logs/log_configuration/attributes_naming_convention/#user-related-attributes
|
|
15
|
+
*/
|
|
16
|
+
function sanitizeUser(newUser) {
|
|
17
|
+
// We shallow clone only to prevent mutation of user data.
|
|
18
|
+
var user = (0, _utils.extend)({}, newUser);
|
|
19
|
+
var keys = ['id', 'name', 'email'];
|
|
20
|
+
(0, _utils.each)(keys, function (key) {
|
|
21
|
+
if (key in user) {
|
|
22
|
+
user[key] = String(user[key]);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return user;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Simple check to ensure user is valid
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
function checkUser(newUser) {
|
|
33
|
+
var isValid = (0, _utils.getType)(newUser) === 'object';
|
|
34
|
+
|
|
35
|
+
if (!isValid) {
|
|
36
|
+
console.error('Unsupported user:', newUser);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return isValid;
|
|
40
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.computeBytesCount = computeBytesCount;
|
|
7
|
+
exports.ONE_MEBI_BYTE = exports.ONE_KIBI_BYTE = void 0;
|
|
8
|
+
var ONE_KIBI_BYTE = 1024;
|
|
9
|
+
exports.ONE_KIBI_BYTE = ONE_KIBI_BYTE;
|
|
10
|
+
var ONE_MEBI_BYTE = 1024 * ONE_KIBI_BYTE; // eslint-disable-next-line no-control-regex
|
|
11
|
+
|
|
12
|
+
exports.ONE_MEBI_BYTE = ONE_MEBI_BYTE;
|
|
13
|
+
var HAS_MULTI_BYTES_CHARACTERS = /[^\u0000-\u007F]/;
|
|
14
|
+
|
|
15
|
+
function computeBytesCount(candidate) {
|
|
16
|
+
// Accurate byte size computations can degrade performances when there is a lot of events to process
|
|
17
|
+
if (!HAS_MULTI_BYTES_CHARACTERS.test(candidate)) {
|
|
18
|
+
return candidate.length;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
var total = 0,
|
|
22
|
+
charCode; // utf-8编码
|
|
23
|
+
|
|
24
|
+
for (var i = 0, len = candidate.length; i < len; i++) {
|
|
25
|
+
charCode = candidate.charCodeAt(i);
|
|
26
|
+
|
|
27
|
+
if (charCode <= 0x007f) {
|
|
28
|
+
total += 1;
|
|
29
|
+
} else if (charCode <= 0x07ff) {
|
|
30
|
+
total += 2;
|
|
31
|
+
} else if (charCode <= 0xffff) {
|
|
32
|
+
total += 3;
|
|
33
|
+
} else {
|
|
34
|
+
total += 4;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return total;
|
|
39
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.buildCommonContext = buildCommonContext;
|
|
7
|
+
|
|
8
|
+
function buildCommonContext(globalContextManager, userContextManager) {
|
|
9
|
+
return {
|
|
10
|
+
context: globalContextManager.getContext(),
|
|
11
|
+
user: userContextManager.getContext() // hasReplay: recorderApi.isRecording() ? true : undefined,
|
|
12
|
+
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.jsonStringify = jsonStringify;
|
|
7
|
+
exports.detachToJsonMethod = detachToJsonMethod;
|
|
8
|
+
|
|
9
|
+
var _utils = require("./utils");
|
|
10
|
+
|
|
11
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Custom implementation of JSON.stringify that ignores some toJSON methods. We need to do that
|
|
15
|
+
* because some sites badly override toJSON on certain objects. Removing all toJSON methods from
|
|
16
|
+
* nested values would be too costly, so we just detach them from the root value, and native classes
|
|
17
|
+
* used to build JSON values (Array and Object).
|
|
18
|
+
*
|
|
19
|
+
* Note: this still assumes that JSON.stringify is correct.
|
|
20
|
+
*/
|
|
21
|
+
function jsonStringify(value, replacer, space) {
|
|
22
|
+
if (_typeof(value) !== 'object' || value === null) {
|
|
23
|
+
return JSON.stringify(value);
|
|
24
|
+
} // Note: The order matter here. We need to detach toJSON methods on parent classes before their
|
|
25
|
+
// subclasses.
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
var restoreObjectPrototypeToJson = detachToJsonMethod(Object.prototype);
|
|
29
|
+
var restoreArrayPrototypeToJson = detachToJsonMethod(Array.prototype);
|
|
30
|
+
var restoreValuePrototypeToJson = detachToJsonMethod(Object.getPrototypeOf(value));
|
|
31
|
+
var restoreValueToJson = detachToJsonMethod(value);
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
return JSON.stringify(value, replacer, space);
|
|
35
|
+
} catch (error) {
|
|
36
|
+
return '<error: unable to serialize object>';
|
|
37
|
+
} finally {
|
|
38
|
+
restoreObjectPrototypeToJson();
|
|
39
|
+
restoreArrayPrototypeToJson();
|
|
40
|
+
restoreValuePrototypeToJson();
|
|
41
|
+
restoreValueToJson();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function detachToJsonMethod(value) {
|
|
46
|
+
var object = value;
|
|
47
|
+
var objectToJson = object.toJSON;
|
|
48
|
+
|
|
49
|
+
if (objectToJson) {
|
|
50
|
+
delete object.toJSON;
|
|
51
|
+
return function () {
|
|
52
|
+
object.toJSON = objectToJson;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return _utils.noop;
|
|
57
|
+
}
|