@cloudcare/browser-core 1.0.24 → 1.0.29
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/configuration.js +11 -0
- package/cjs/dataMap.js +2 -0
- package/cjs/errorCollection.js +3 -1
- package/cjs/helper/mobileUtil.js +4 -3
- package/cjs/helper/tools.js +9 -0
- package/cjs/transport.js +60 -30
- package/esm/configuration.js +11 -0
- package/esm/dataMap.js +2 -0
- package/esm/errorCollection.js +3 -1
- package/esm/helper/mobileUtil.js +1 -1
- package/esm/helper/tools.js +7 -0
- package/esm/transport.js +61 -31
- package/package.json +2 -2
- package/src/configuration.js +8 -0
- package/src/dataMap.js +3 -1
- package/src/errorCollection.js +3 -1
- package/src/helper/mobileUtil.js +1 -1
- package/src/helper/tools.js +8 -0
- package/src/transport.js +61 -24
package/cjs/configuration.js
CHANGED
|
@@ -51,6 +51,9 @@ var DEFAULT_CONFIGURATION = {
|
|
|
51
51
|
// 新增
|
|
52
52
|
isServiceSampling: false,
|
|
53
53
|
// 是否不抛弃采样是数据, 采用在服务端菜样的方式
|
|
54
|
+
isJsBirdge: false,
|
|
55
|
+
// 是否需要对webview 发送数据,需要装我们对应ios sdk
|
|
56
|
+
isLineProtocolToJson: false,
|
|
54
57
|
beforeSend: function beforeSend(event) {},
|
|
55
58
|
isServerError: function isServerError(request) {
|
|
56
59
|
return false;
|
|
@@ -102,6 +105,14 @@ function commonInit(userConfiguration, buildEnv) {
|
|
|
102
105
|
cookieOptions: buildCookieOptions(userConfiguration)
|
|
103
106
|
};
|
|
104
107
|
|
|
108
|
+
if ('isJsBirdge' in userConfiguration) {
|
|
109
|
+
transportConfiguration.isJsBirdge = userConfiguration.isJsBirdge;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if ('isLineProtocolToJson' in userConfiguration) {
|
|
113
|
+
transportConfiguration.isLineProtocolToJson = userConfiguration.isLineProtocolToJson;
|
|
114
|
+
}
|
|
115
|
+
|
|
105
116
|
if ('allowedDDTracingOrigins' in userConfiguration) {
|
|
106
117
|
transportConfiguration.allowedTracingOrigins = userConfiguration.allowedDDTracingOrigins;
|
|
107
118
|
}
|
package/cjs/dataMap.js
CHANGED
package/cjs/errorCollection.js
CHANGED
|
@@ -123,7 +123,9 @@ function trackNetworkError(configuration, errorObservable) {
|
|
|
123
123
|
resource: {
|
|
124
124
|
method: request.method,
|
|
125
125
|
statusCode: request.status,
|
|
126
|
-
url: request.url
|
|
126
|
+
url: request.url,
|
|
127
|
+
traceId: request.traceId,
|
|
128
|
+
spanId: request.spanId
|
|
127
129
|
},
|
|
128
130
|
source: _errorTools.ErrorSource.NETWORK,
|
|
129
131
|
stack: truncateResponse(request.response, configuration) || 'Failed to load',
|
package/cjs/helper/mobileUtil.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.userAgent = exports.
|
|
6
|
+
exports.userAgent = exports.isIos = exports.isAndroid = exports.JsBirdge = void 0;
|
|
7
7
|
var userAgent = navigator.userAgent.toLowerCase();
|
|
8
8
|
exports.userAgent = userAgent;
|
|
9
9
|
|
|
@@ -29,6 +29,7 @@ var JsBirdge = function JsBirdge() {
|
|
|
29
29
|
} catch (err) {}
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
+
exports.JsBirdge = JsBirdge;
|
|
32
33
|
JsBirdge.prototype = {
|
|
33
34
|
initBridge: function initBridge() {
|
|
34
35
|
var _this = this;
|
|
@@ -116,5 +117,5 @@ JsBirdge.prototype = {
|
|
|
116
117
|
}
|
|
117
118
|
}
|
|
118
119
|
};
|
|
119
|
-
var
|
|
120
|
-
exports.
|
|
120
|
+
var JsBirdge = JsBirdge;
|
|
121
|
+
exports.JsBirdge = JsBirdge;
|
package/cjs/helper/tools.js
CHANGED
|
@@ -19,6 +19,7 @@ exports.deepSnakeCase = deepSnakeCase;
|
|
|
19
19
|
exports.each = void 0;
|
|
20
20
|
exports.elapsed = elapsed;
|
|
21
21
|
exports.encodeDates = void 0;
|
|
22
|
+
exports.escapeJsonValue = escapeJsonValue;
|
|
22
23
|
exports.escapeRowData = escapeRowData;
|
|
23
24
|
exports.filter = exports.extend2Lev = exports.extend = void 0;
|
|
24
25
|
exports.find = find;
|
|
@@ -2033,4 +2034,12 @@ function escapeRowData(str) {
|
|
|
2033
2034
|
return String(str).replace(reg, function (word) {
|
|
2034
2035
|
return '\\' + word;
|
|
2035
2036
|
});
|
|
2037
|
+
}
|
|
2038
|
+
|
|
2039
|
+
function escapeJsonValue(value) {
|
|
2040
|
+
if (isString(value)) {
|
|
2041
|
+
return value;
|
|
2042
|
+
} else {
|
|
2043
|
+
return jsonStringify(value);
|
|
2044
|
+
}
|
|
2036
2045
|
}
|
package/cjs/transport.js
CHANGED
|
@@ -20,18 +20,28 @@ function addBatchPrecision(url) {
|
|
|
20
20
|
return url + (url.indexOf('?') === -1 ? '?' : '&') + 'precision=ms';
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
var httpRequest = function httpRequest(endpointUrl, bytesLimit) {
|
|
23
|
+
var httpRequest = function httpRequest(endpointUrl, bytesLimit, isLineProtocolToJson) {
|
|
24
24
|
this.endpointUrl = endpointUrl;
|
|
25
25
|
this.bytesLimit = bytesLimit;
|
|
26
|
+
this.isLineProtocolToJson = isLineProtocolToJson;
|
|
26
27
|
};
|
|
27
28
|
|
|
28
29
|
httpRequest.prototype = {
|
|
29
30
|
send: function send(data, size) {
|
|
30
31
|
var url = addBatchPrecision(this.endpointUrl);
|
|
31
32
|
|
|
32
|
-
if (navigator.sendBeacon && size < this.bytesLimit) {
|
|
33
|
+
if (navigator.sendBeacon && size < this.bytesLimit && !this.isLineProtocolToJson) {
|
|
33
34
|
var isQueued = navigator.sendBeacon(url, data);
|
|
34
35
|
|
|
36
|
+
if (isQueued) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
} else if (navigator.sendBeacon && size < this.bytesLimit && this.isLineProtocolToJson) {
|
|
40
|
+
var blob = new Blob([JSON.stringify(data)], {
|
|
41
|
+
type: 'application/json'
|
|
42
|
+
});
|
|
43
|
+
var isQueued = navigator.sendBeacon(url, blob);
|
|
44
|
+
|
|
35
45
|
if (isQueued) {
|
|
36
46
|
return;
|
|
37
47
|
}
|
|
@@ -40,7 +50,14 @@ httpRequest.prototype = {
|
|
|
40
50
|
var request = new XMLHttpRequest();
|
|
41
51
|
request.open('POST', url, true);
|
|
42
52
|
request.withCredentials = true;
|
|
43
|
-
|
|
53
|
+
|
|
54
|
+
if (this.isLineProtocolToJson) {
|
|
55
|
+
request.setRequestHeader('Content-type', 'application/json');
|
|
56
|
+
request.send(JSON.stringify(data));
|
|
57
|
+
} else {
|
|
58
|
+
request.setRequestHeader('Content-type', 'text/plain;charset=UTF-8');
|
|
59
|
+
request.send(data);
|
|
60
|
+
}
|
|
44
61
|
}
|
|
45
62
|
};
|
|
46
63
|
var HttpRequest = httpRequest;
|
|
@@ -71,33 +88,10 @@ var processedMessageByDataMap = function processedMessageByDataMap(message) {
|
|
|
71
88
|
filterFileds.push(_key);
|
|
72
89
|
|
|
73
90
|
if (_value || (0, _tools.isNumber)(_value)) {
|
|
74
|
-
rowData.tags[_key] = _value;
|
|
91
|
+
rowData.tags[_key] = (0, _tools.escapeJsonValue)(_value);
|
|
75
92
|
tagsStr.push((0, _tools.escapeRowData)(_key) + '=' + (0, _tools.escapeRowData)(_value));
|
|
76
93
|
}
|
|
77
94
|
});
|
|
78
|
-
|
|
79
|
-
if (message.tags && (0, _tools.isObject)(message.tags) && !(0, _tools.isEmptyObject)(message.tags)) {
|
|
80
|
-
// 自定义tag
|
|
81
|
-
var _tagKeys = [];
|
|
82
|
-
(0, _tools.each)(message.tags, function (_value, _key) {
|
|
83
|
-
// 如果和之前tag重名,则舍弃
|
|
84
|
-
if (filterFileds.indexOf(_key) > -1) return;
|
|
85
|
-
filterFileds.push(_key);
|
|
86
|
-
|
|
87
|
-
if (_value || (0, _tools.isNumber)(_value)) {
|
|
88
|
-
_tagKeys.push(_key);
|
|
89
|
-
|
|
90
|
-
rowData.tags[_key] = _value;
|
|
91
|
-
tagsStr.push((0, _tools.escapeRowData)(_key) + '=' + (0, _tools.escapeRowData)(_value));
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
if (_tagKeys.length) {
|
|
96
|
-
rowData.tags[CUSTOM_KEYS] = _tagKeys;
|
|
97
|
-
tagsStr.push((0, _tools.escapeRowData)(CUSTOM_KEYS) + '=' + (0, _tools.escapeRowData)(_tagKeys));
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
95
|
var fieldsStr = [];
|
|
102
96
|
(0, _tools.each)(value.fields, function (_value, _key) {
|
|
103
97
|
if ((0, _tools.isArray)(_value) && _value.length === 2) {
|
|
@@ -128,10 +122,33 @@ var processedMessageByDataMap = function processedMessageByDataMap(message) {
|
|
|
128
122
|
}
|
|
129
123
|
});
|
|
130
124
|
|
|
125
|
+
if (message.tags && (0, _tools.isObject)(message.tags) && !(0, _tools.isEmptyObject)(message.tags)) {
|
|
126
|
+
// 自定义tag
|
|
127
|
+
var _tagKeys = [];
|
|
128
|
+
(0, _tools.each)(message.tags, function (_value, _key) {
|
|
129
|
+
// 如果和之前tag重名,则舍弃
|
|
130
|
+
if (filterFileds.indexOf(_key) > -1) return;
|
|
131
|
+
filterFileds.push(_key);
|
|
132
|
+
|
|
133
|
+
if (_value || (0, _tools.isNumber)(_value)) {
|
|
134
|
+
_tagKeys.push(_key);
|
|
135
|
+
|
|
136
|
+
rowData.tags[_key] = (0, _tools.escapeJsonValue)(_value);
|
|
137
|
+
tagsStr.push((0, _tools.escapeRowData)(_key) + '=' + (0, _tools.escapeRowData)(_value));
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
if (_tagKeys.length) {
|
|
142
|
+
rowData.tags[CUSTOM_KEYS] = (0, _tools.escapeJsonValue)(_tagKeys);
|
|
143
|
+
tagsStr.push((0, _tools.escapeRowData)(CUSTOM_KEYS) + '=' + (0, _tools.escapeRowData)(_tagKeys));
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
131
147
|
if (message.type === _enums.RumEventType.LOGGER) {
|
|
132
148
|
// 这里处理日志类型数据自定义字段
|
|
133
149
|
(0, _tools.each)(message, function (value, key) {
|
|
134
150
|
if (filterFileds.indexOf(key) === -1 && ((0, _tools.isNumber)(value) || (0, _tools.isString)(value) || (0, _tools.isBoolean)(value))) {
|
|
151
|
+
rowData.tags[key] = (0, _tools.escapeJsonValue)(value);
|
|
135
152
|
tagsStr.push((0, _tools.escapeRowData)(key) + '=' + (0, _tools.escapeRowData)(value));
|
|
136
153
|
}
|
|
137
154
|
});
|
|
@@ -159,13 +176,13 @@ var processedMessageByDataMap = function processedMessageByDataMap(message) {
|
|
|
159
176
|
|
|
160
177
|
exports.processedMessageByDataMap = processedMessageByDataMap;
|
|
161
178
|
|
|
162
|
-
function batch(request, maxSize, bytesLimit, maxMessageSize, flushTimeout, beforeUnloadCallback) {
|
|
179
|
+
function batch(request, maxSize, bytesLimit, maxMessageSize, flushTimeout, isLineProtocolToJson, beforeUnloadCallback) {
|
|
163
180
|
this.request = request;
|
|
164
181
|
this.maxSize = maxSize;
|
|
165
182
|
this.bytesLimit = bytesLimit;
|
|
166
183
|
this.maxMessageSize = maxMessageSize;
|
|
167
184
|
this.flushTimeout = flushTimeout;
|
|
168
|
-
this.beforeUnloadCallback = beforeUnloadCallback;
|
|
185
|
+
this.isLineProtocolToJson = isLineProtocolToJson, this.beforeUnloadCallback = beforeUnloadCallback;
|
|
169
186
|
this.pushOnlyBuffer = [];
|
|
170
187
|
this.upsertBuffer = {};
|
|
171
188
|
this.bufferBytesSize = 0;
|
|
@@ -184,7 +201,16 @@ batch.prototype = {
|
|
|
184
201
|
flush: function flush() {
|
|
185
202
|
if (this.bufferMessageCount !== 0) {
|
|
186
203
|
var messages = this.pushOnlyBuffer.concat((0, _tools.values)(this.upsertBuffer));
|
|
187
|
-
|
|
204
|
+
if (messages.length === 0) return;
|
|
205
|
+
|
|
206
|
+
if (this.isLineProtocolToJson) {
|
|
207
|
+
this.request.send((0, _tools.map)(messages, function (rowdataStr) {
|
|
208
|
+
return JSON.parse(rowdataStr);
|
|
209
|
+
}), this.bufferBytesSize);
|
|
210
|
+
} else {
|
|
211
|
+
this.request.send(messages.join('\n'), this.bufferBytesSize);
|
|
212
|
+
}
|
|
213
|
+
|
|
188
214
|
this.pushOnlyBuffer = [];
|
|
189
215
|
this.upsertBuffer = {};
|
|
190
216
|
this.bufferBytesSize = 0;
|
|
@@ -192,6 +218,10 @@ batch.prototype = {
|
|
|
192
218
|
}
|
|
193
219
|
},
|
|
194
220
|
processSendData: function processSendData(message) {
|
|
221
|
+
if (this.isLineProtocolToJson) {
|
|
222
|
+
return JSON.stringify(processedMessageByDataMap(message).rowData);
|
|
223
|
+
}
|
|
224
|
+
|
|
195
225
|
return processedMessageByDataMap(message).rowStr;
|
|
196
226
|
},
|
|
197
227
|
sizeInBytes: function sizeInBytes(candidate) {
|
package/esm/configuration.js
CHANGED
|
@@ -37,6 +37,9 @@ export var DEFAULT_CONFIGURATION = {
|
|
|
37
37
|
// 新增
|
|
38
38
|
isServiceSampling: false,
|
|
39
39
|
// 是否不抛弃采样是数据, 采用在服务端菜样的方式
|
|
40
|
+
isJsBirdge: false,
|
|
41
|
+
// 是否需要对webview 发送数据,需要装我们对应ios sdk
|
|
42
|
+
isLineProtocolToJson: false,
|
|
40
43
|
beforeSend: function beforeSend(event) {},
|
|
41
44
|
isServerError: function isServerError(request) {
|
|
42
45
|
return false;
|
|
@@ -87,6 +90,14 @@ export function commonInit(userConfiguration, buildEnv) {
|
|
|
87
90
|
cookieOptions: buildCookieOptions(userConfiguration)
|
|
88
91
|
};
|
|
89
92
|
|
|
93
|
+
if ('isJsBirdge' in userConfiguration) {
|
|
94
|
+
transportConfiguration.isJsBirdge = userConfiguration.isJsBirdge;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if ('isLineProtocolToJson' in userConfiguration) {
|
|
98
|
+
transportConfiguration.isLineProtocolToJson = userConfiguration.isLineProtocolToJson;
|
|
99
|
+
}
|
|
100
|
+
|
|
90
101
|
if ('allowedDDTracingOrigins' in userConfiguration) {
|
|
91
102
|
transportConfiguration.allowedTracingOrigins = userConfiguration.allowedDDTracingOrigins;
|
|
92
103
|
}
|
package/esm/dataMap.js
CHANGED
package/esm/errorCollection.js
CHANGED
|
@@ -97,7 +97,9 @@ export function trackNetworkError(configuration, errorObservable) {
|
|
|
97
97
|
resource: {
|
|
98
98
|
method: request.method,
|
|
99
99
|
statusCode: request.status,
|
|
100
|
-
url: request.url
|
|
100
|
+
url: request.url,
|
|
101
|
+
traceId: request.traceId,
|
|
102
|
+
spanId: request.spanId
|
|
101
103
|
},
|
|
102
104
|
source: ErrorSource.NETWORK,
|
|
103
105
|
stack: truncateResponse(request.response, configuration) || 'Failed to load',
|
package/esm/helper/mobileUtil.js
CHANGED
package/esm/helper/tools.js
CHANGED
|
@@ -1726,4 +1726,11 @@ export function escapeRowData(str) {
|
|
|
1726
1726
|
return String(str).replace(reg, function (word) {
|
|
1727
1727
|
return '\\' + word;
|
|
1728
1728
|
});
|
|
1729
|
+
}
|
|
1730
|
+
export function escapeJsonValue(value) {
|
|
1731
|
+
if (isString(value)) {
|
|
1732
|
+
return value;
|
|
1733
|
+
} else {
|
|
1734
|
+
return jsonStringify(value);
|
|
1735
|
+
}
|
|
1729
1736
|
}
|
package/esm/transport.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addEventListener, values, findByPath, escapeRowData, each, isNumber, isArray, extend, isString, toServerDuration, isBoolean, isEmptyObject, isObject } from './helper/tools';
|
|
1
|
+
import { addEventListener, values, findByPath, escapeRowData, each, isNumber, isArray, extend, isString, toServerDuration, isBoolean, isEmptyObject, isObject, map, escapeJsonValue } from './helper/tools';
|
|
2
2
|
import { DOM_EVENT, RumEventType } from './helper/enums';
|
|
3
3
|
import { commonTags, dataMap } from './dataMap'; // https://en.wikipedia.org/wiki/UTF-8
|
|
4
4
|
|
|
@@ -10,18 +10,28 @@ function addBatchPrecision(url) {
|
|
|
10
10
|
return url + (url.indexOf('?') === -1 ? '?' : '&') + 'precision=ms';
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
var httpRequest = function httpRequest(endpointUrl, bytesLimit) {
|
|
13
|
+
var httpRequest = function httpRequest(endpointUrl, bytesLimit, isLineProtocolToJson) {
|
|
14
14
|
this.endpointUrl = endpointUrl;
|
|
15
15
|
this.bytesLimit = bytesLimit;
|
|
16
|
+
this.isLineProtocolToJson = isLineProtocolToJson;
|
|
16
17
|
};
|
|
17
18
|
|
|
18
19
|
httpRequest.prototype = {
|
|
19
20
|
send: function send(data, size) {
|
|
20
21
|
var url = addBatchPrecision(this.endpointUrl);
|
|
21
22
|
|
|
22
|
-
if (navigator.sendBeacon && size < this.bytesLimit) {
|
|
23
|
+
if (navigator.sendBeacon && size < this.bytesLimit && !this.isLineProtocolToJson) {
|
|
23
24
|
var isQueued = navigator.sendBeacon(url, data);
|
|
24
25
|
|
|
26
|
+
if (isQueued) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
} else if (navigator.sendBeacon && size < this.bytesLimit && this.isLineProtocolToJson) {
|
|
30
|
+
var blob = new Blob([JSON.stringify(data)], {
|
|
31
|
+
type: 'application/json'
|
|
32
|
+
});
|
|
33
|
+
var isQueued = navigator.sendBeacon(url, blob);
|
|
34
|
+
|
|
25
35
|
if (isQueued) {
|
|
26
36
|
return;
|
|
27
37
|
}
|
|
@@ -30,7 +40,14 @@ httpRequest.prototype = {
|
|
|
30
40
|
var request = new XMLHttpRequest();
|
|
31
41
|
request.open('POST', url, true);
|
|
32
42
|
request.withCredentials = true;
|
|
33
|
-
|
|
43
|
+
|
|
44
|
+
if (this.isLineProtocolToJson) {
|
|
45
|
+
request.setRequestHeader('Content-type', 'application/json');
|
|
46
|
+
request.send(JSON.stringify(data));
|
|
47
|
+
} else {
|
|
48
|
+
request.setRequestHeader('Content-type', 'text/plain;charset=UTF-8');
|
|
49
|
+
request.send(data);
|
|
50
|
+
}
|
|
34
51
|
}
|
|
35
52
|
};
|
|
36
53
|
export var HttpRequest = httpRequest;
|
|
@@ -59,33 +76,10 @@ export var processedMessageByDataMap = function processedMessageByDataMap(messag
|
|
|
59
76
|
filterFileds.push(_key);
|
|
60
77
|
|
|
61
78
|
if (_value || isNumber(_value)) {
|
|
62
|
-
rowData.tags[_key] = _value;
|
|
79
|
+
rowData.tags[_key] = escapeJsonValue(_value);
|
|
63
80
|
tagsStr.push(escapeRowData(_key) + '=' + escapeRowData(_value));
|
|
64
81
|
}
|
|
65
82
|
});
|
|
66
|
-
|
|
67
|
-
if (message.tags && isObject(message.tags) && !isEmptyObject(message.tags)) {
|
|
68
|
-
// 自定义tag
|
|
69
|
-
var _tagKeys = [];
|
|
70
|
-
each(message.tags, function (_value, _key) {
|
|
71
|
-
// 如果和之前tag重名,则舍弃
|
|
72
|
-
if (filterFileds.indexOf(_key) > -1) return;
|
|
73
|
-
filterFileds.push(_key);
|
|
74
|
-
|
|
75
|
-
if (_value || isNumber(_value)) {
|
|
76
|
-
_tagKeys.push(_key);
|
|
77
|
-
|
|
78
|
-
rowData.tags[_key] = _value;
|
|
79
|
-
tagsStr.push(escapeRowData(_key) + '=' + escapeRowData(_value));
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
if (_tagKeys.length) {
|
|
84
|
-
rowData.tags[CUSTOM_KEYS] = _tagKeys;
|
|
85
|
-
tagsStr.push(escapeRowData(CUSTOM_KEYS) + '=' + escapeRowData(_tagKeys));
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
83
|
var fieldsStr = [];
|
|
90
84
|
each(value.fields, function (_value, _key) {
|
|
91
85
|
if (isArray(_value) && _value.length === 2) {
|
|
@@ -116,10 +110,33 @@ export var processedMessageByDataMap = function processedMessageByDataMap(messag
|
|
|
116
110
|
}
|
|
117
111
|
});
|
|
118
112
|
|
|
113
|
+
if (message.tags && isObject(message.tags) && !isEmptyObject(message.tags)) {
|
|
114
|
+
// 自定义tag
|
|
115
|
+
var _tagKeys = [];
|
|
116
|
+
each(message.tags, function (_value, _key) {
|
|
117
|
+
// 如果和之前tag重名,则舍弃
|
|
118
|
+
if (filterFileds.indexOf(_key) > -1) return;
|
|
119
|
+
filterFileds.push(_key);
|
|
120
|
+
|
|
121
|
+
if (_value || isNumber(_value)) {
|
|
122
|
+
_tagKeys.push(_key);
|
|
123
|
+
|
|
124
|
+
rowData.tags[_key] = escapeJsonValue(_value);
|
|
125
|
+
tagsStr.push(escapeRowData(_key) + '=' + escapeRowData(_value));
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
if (_tagKeys.length) {
|
|
130
|
+
rowData.tags[CUSTOM_KEYS] = escapeJsonValue(_tagKeys);
|
|
131
|
+
tagsStr.push(escapeRowData(CUSTOM_KEYS) + '=' + escapeRowData(_tagKeys));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
119
135
|
if (message.type === RumEventType.LOGGER) {
|
|
120
136
|
// 这里处理日志类型数据自定义字段
|
|
121
137
|
each(message, function (value, key) {
|
|
122
138
|
if (filterFileds.indexOf(key) === -1 && (isNumber(value) || isString(value) || isBoolean(value))) {
|
|
139
|
+
rowData.tags[key] = escapeJsonValue(value);
|
|
123
140
|
tagsStr.push(escapeRowData(key) + '=' + escapeRowData(value));
|
|
124
141
|
}
|
|
125
142
|
});
|
|
@@ -145,13 +162,13 @@ export var processedMessageByDataMap = function processedMessageByDataMap(messag
|
|
|
145
162
|
};
|
|
146
163
|
};
|
|
147
164
|
|
|
148
|
-
function batch(request, maxSize, bytesLimit, maxMessageSize, flushTimeout, beforeUnloadCallback) {
|
|
165
|
+
function batch(request, maxSize, bytesLimit, maxMessageSize, flushTimeout, isLineProtocolToJson, beforeUnloadCallback) {
|
|
149
166
|
this.request = request;
|
|
150
167
|
this.maxSize = maxSize;
|
|
151
168
|
this.bytesLimit = bytesLimit;
|
|
152
169
|
this.maxMessageSize = maxMessageSize;
|
|
153
170
|
this.flushTimeout = flushTimeout;
|
|
154
|
-
this.beforeUnloadCallback = beforeUnloadCallback;
|
|
171
|
+
this.isLineProtocolToJson = isLineProtocolToJson, this.beforeUnloadCallback = beforeUnloadCallback;
|
|
155
172
|
this.pushOnlyBuffer = [];
|
|
156
173
|
this.upsertBuffer = {};
|
|
157
174
|
this.bufferBytesSize = 0;
|
|
@@ -170,7 +187,16 @@ batch.prototype = {
|
|
|
170
187
|
flush: function flush() {
|
|
171
188
|
if (this.bufferMessageCount !== 0) {
|
|
172
189
|
var messages = this.pushOnlyBuffer.concat(values(this.upsertBuffer));
|
|
173
|
-
|
|
190
|
+
if (messages.length === 0) return;
|
|
191
|
+
|
|
192
|
+
if (this.isLineProtocolToJson) {
|
|
193
|
+
this.request.send(map(messages, function (rowdataStr) {
|
|
194
|
+
return JSON.parse(rowdataStr);
|
|
195
|
+
}), this.bufferBytesSize);
|
|
196
|
+
} else {
|
|
197
|
+
this.request.send(messages.join('\n'), this.bufferBytesSize);
|
|
198
|
+
}
|
|
199
|
+
|
|
174
200
|
this.pushOnlyBuffer = [];
|
|
175
201
|
this.upsertBuffer = {};
|
|
176
202
|
this.bufferBytesSize = 0;
|
|
@@ -178,6 +204,10 @@ batch.prototype = {
|
|
|
178
204
|
}
|
|
179
205
|
},
|
|
180
206
|
processSendData: function processSendData(message) {
|
|
207
|
+
if (this.isLineProtocolToJson) {
|
|
208
|
+
return JSON.stringify(processedMessageByDataMap(message).rowData);
|
|
209
|
+
}
|
|
210
|
+
|
|
181
211
|
return processedMessageByDataMap(message).rowStr;
|
|
182
212
|
},
|
|
183
213
|
sizeInBytes: function sizeInBytes(candidate) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudcare/browser-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.29",
|
|
4
4
|
"main": "cjs/index.js",
|
|
5
5
|
"module": "esm/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -20,5 +20,5 @@
|
|
|
20
20
|
"author": "dataflux",
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"description": "DataFlux RUM Web 端数据指标监控",
|
|
23
|
-
"gitHead": "
|
|
23
|
+
"gitHead": "34770c27f33e4fbaaafc8743aa5e9f5ffd14bc14"
|
|
24
24
|
}
|
package/src/configuration.js
CHANGED
|
@@ -40,6 +40,8 @@ export var DEFAULT_CONFIGURATION = {
|
|
|
40
40
|
allowedDDTracingOrigins: [], //废弃
|
|
41
41
|
allowedTracingOrigins:[], // 新增
|
|
42
42
|
isServiceSampling: false, // 是否不抛弃采样是数据, 采用在服务端菜样的方式
|
|
43
|
+
isJsBirdge: false,// 是否需要对webview 发送数据,需要装我们对应ios sdk
|
|
44
|
+
isLineProtocolToJson: false,
|
|
43
45
|
beforeSend: function (event) {},
|
|
44
46
|
isServerError: function(request) {return false} // 判断请求是否为error 请求
|
|
45
47
|
}
|
|
@@ -87,6 +89,12 @@ export function commonInit(userConfiguration, buildEnv) {
|
|
|
87
89
|
isEnabled: function(feature) {return includes(enableExperimentalFeatures, feature)},
|
|
88
90
|
cookieOptions: buildCookieOptions(userConfiguration)
|
|
89
91
|
}
|
|
92
|
+
if ('isJsBirdge' in userConfiguration) {
|
|
93
|
+
transportConfiguration.isJsBirdge = userConfiguration.isJsBirdge
|
|
94
|
+
}
|
|
95
|
+
if ('isLineProtocolToJson' in userConfiguration) {
|
|
96
|
+
transportConfiguration.isLineProtocolToJson = userConfiguration.isLineProtocolToJson
|
|
97
|
+
}
|
|
90
98
|
if ('allowedDDTracingOrigins' in userConfiguration) {
|
|
91
99
|
transportConfiguration.allowedTracingOrigins =
|
|
92
100
|
userConfiguration.allowedDDTracingOrigins
|
package/src/dataMap.js
CHANGED
|
@@ -92,6 +92,8 @@ export var dataMap = {
|
|
|
92
92
|
error: {
|
|
93
93
|
type: RumEventType.ERROR,
|
|
94
94
|
tags: {
|
|
95
|
+
trace_id: '_dd.trace_id',
|
|
96
|
+
span_id: '_dd.span_id',
|
|
95
97
|
error_source: 'error.source',
|
|
96
98
|
error_type: 'error.type',
|
|
97
99
|
error_handling: 'error.handling',
|
|
@@ -101,7 +103,7 @@ export var dataMap = {
|
|
|
101
103
|
resource_url_path_group: 'error.resource.url_path_group',
|
|
102
104
|
resource_status: 'error.resource.status',
|
|
103
105
|
resource_status_group: 'error.resource.status_group',
|
|
104
|
-
resource_method: 'error.resource.method'
|
|
106
|
+
resource_method: 'error.resource.method',
|
|
105
107
|
},
|
|
106
108
|
fields: {
|
|
107
109
|
error_message: ['string', 'error.message'],
|
package/src/errorCollection.js
CHANGED
|
@@ -121,7 +121,9 @@ export function trackNetworkError(configuration, errorObservable) {
|
|
|
121
121
|
resource: {
|
|
122
122
|
method: request.method,
|
|
123
123
|
statusCode: request.status,
|
|
124
|
-
url: request.url
|
|
124
|
+
url: request.url,
|
|
125
|
+
traceId: request.traceId,
|
|
126
|
+
spanId: request.spanId,
|
|
125
127
|
},
|
|
126
128
|
source: ErrorSource.NETWORK,
|
|
127
129
|
stack:
|
package/src/helper/mobileUtil.js
CHANGED
package/src/helper/tools.js
CHANGED
package/src/transport.js
CHANGED
|
@@ -11,7 +11,9 @@ import {
|
|
|
11
11
|
toServerDuration,
|
|
12
12
|
isBoolean,
|
|
13
13
|
isEmptyObject,
|
|
14
|
-
isObject
|
|
14
|
+
isObject,
|
|
15
|
+
map,
|
|
16
|
+
escapeJsonValue
|
|
15
17
|
} from './helper/tools'
|
|
16
18
|
import { DOM_EVENT, RumEventType } from './helper/enums'
|
|
17
19
|
import { commonTags, dataMap } from './dataMap'
|
|
@@ -22,27 +24,47 @@ function addBatchPrecision(url) {
|
|
|
22
24
|
if (!url) return url
|
|
23
25
|
return url + (url.indexOf('?') === -1 ? '?' : '&') + 'precision=ms'
|
|
24
26
|
}
|
|
25
|
-
var httpRequest = function (endpointUrl, bytesLimit) {
|
|
27
|
+
var httpRequest = function (endpointUrl, bytesLimit, isLineProtocolToJson) {
|
|
26
28
|
this.endpointUrl = endpointUrl
|
|
27
29
|
this.bytesLimit = bytesLimit
|
|
30
|
+
this.isLineProtocolToJson = isLineProtocolToJson
|
|
28
31
|
}
|
|
29
32
|
httpRequest.prototype = {
|
|
30
33
|
send: function (data, size) {
|
|
34
|
+
|
|
31
35
|
var url = addBatchPrecision(this.endpointUrl)
|
|
32
|
-
if (navigator.sendBeacon && size < this.bytesLimit) {
|
|
36
|
+
if (navigator.sendBeacon && size < this.bytesLimit && !this.isLineProtocolToJson) {
|
|
33
37
|
var isQueued = navigator.sendBeacon(url, data)
|
|
34
38
|
if (isQueued) {
|
|
35
39
|
return
|
|
36
40
|
}
|
|
41
|
+
} else if (navigator.sendBeacon && size < this.bytesLimit && this.isLineProtocolToJson) {
|
|
42
|
+
const blob = new Blob([JSON.stringify(data)], {
|
|
43
|
+
type: 'application/json',
|
|
44
|
+
});
|
|
45
|
+
var isQueued = navigator.sendBeacon(url, blob)
|
|
46
|
+
if (isQueued) {
|
|
47
|
+
return
|
|
48
|
+
}
|
|
37
49
|
}
|
|
38
50
|
var request = new XMLHttpRequest()
|
|
39
51
|
request.open('POST', url, true)
|
|
40
52
|
request.withCredentials = true
|
|
41
|
-
|
|
53
|
+
if (this.isLineProtocolToJson) {
|
|
54
|
+
request.setRequestHeader('Content-type', 'application/json')
|
|
55
|
+
request.send(JSON.stringify(data))
|
|
56
|
+
} else {
|
|
57
|
+
request.setRequestHeader('Content-type', 'text/plain;charset=UTF-8')
|
|
58
|
+
request.send(data)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
42
63
|
}
|
|
43
64
|
}
|
|
44
65
|
|
|
45
66
|
export var HttpRequest = httpRequest
|
|
67
|
+
|
|
46
68
|
export var processedMessageByDataMap = function (message) {
|
|
47
69
|
if (!message || !message.type) return {
|
|
48
70
|
rowStr: '',
|
|
@@ -63,28 +85,11 @@ export var processedMessageByDataMap = function (message) {
|
|
|
63
85
|
var _value = findByPath(message, value_path)
|
|
64
86
|
filterFileds.push(_key)
|
|
65
87
|
if (_value || isNumber(_value)) {
|
|
66
|
-
rowData.tags[_key] = _value
|
|
88
|
+
rowData.tags[_key] = escapeJsonValue(_value)
|
|
67
89
|
tagsStr.push(escapeRowData(_key) + '=' + escapeRowData(_value))
|
|
68
90
|
}
|
|
69
91
|
})
|
|
70
|
-
|
|
71
|
-
// 自定义tag
|
|
72
|
-
const _tagKeys = []
|
|
73
|
-
each(message.tags, function (_value, _key) {
|
|
74
|
-
// 如果和之前tag重名,则舍弃
|
|
75
|
-
if (filterFileds.indexOf(_key) > -1) return
|
|
76
|
-
filterFileds.push(_key)
|
|
77
|
-
if (_value || isNumber(_value)) {
|
|
78
|
-
_tagKeys.push(_key)
|
|
79
|
-
rowData.tags[_key] = _value
|
|
80
|
-
tagsStr.push(escapeRowData(_key) + '=' + escapeRowData(_value))
|
|
81
|
-
}
|
|
82
|
-
})
|
|
83
|
-
if (_tagKeys.length) {
|
|
84
|
-
rowData.tags[CUSTOM_KEYS] = _tagKeys
|
|
85
|
-
tagsStr.push(escapeRowData(CUSTOM_KEYS) + '=' + escapeRowData(_tagKeys))
|
|
86
|
-
}
|
|
87
|
-
}
|
|
92
|
+
|
|
88
93
|
var fieldsStr = []
|
|
89
94
|
each(value.fields, function (_value, _key) {
|
|
90
95
|
if (isArray(_value) && _value.length === 2) {
|
|
@@ -112,6 +117,24 @@ export var processedMessageByDataMap = function (message) {
|
|
|
112
117
|
}
|
|
113
118
|
}
|
|
114
119
|
})
|
|
120
|
+
if (message.tags && isObject(message.tags) && !isEmptyObject(message.tags)) {
|
|
121
|
+
// 自定义tag
|
|
122
|
+
const _tagKeys = []
|
|
123
|
+
each(message.tags, function (_value, _key) {
|
|
124
|
+
// 如果和之前tag重名,则舍弃
|
|
125
|
+
if (filterFileds.indexOf(_key) > -1) return
|
|
126
|
+
filterFileds.push(_key)
|
|
127
|
+
if (_value || isNumber(_value)) {
|
|
128
|
+
_tagKeys.push(_key)
|
|
129
|
+
rowData.tags[_key] = escapeJsonValue(_value)
|
|
130
|
+
tagsStr.push(escapeRowData(_key) + '=' + escapeRowData(_value))
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
if (_tagKeys.length) {
|
|
134
|
+
rowData.tags[CUSTOM_KEYS] = escapeJsonValue(_tagKeys)
|
|
135
|
+
tagsStr.push(escapeRowData(CUSTOM_KEYS) + '=' + escapeRowData(_tagKeys))
|
|
136
|
+
}
|
|
137
|
+
}
|
|
115
138
|
if (message.type === RumEventType.LOGGER) {
|
|
116
139
|
// 这里处理日志类型数据自定义字段
|
|
117
140
|
|
|
@@ -120,6 +143,7 @@ export var processedMessageByDataMap = function (message) {
|
|
|
120
143
|
filterFileds.indexOf(key) === -1 &&
|
|
121
144
|
(isNumber(value) || isString(value) || isBoolean(value))
|
|
122
145
|
) {
|
|
146
|
+
rowData.tags[key] = escapeJsonValue(value)
|
|
123
147
|
tagsStr.push(escapeRowData(key) + '=' + escapeRowData(value))
|
|
124
148
|
}
|
|
125
149
|
})
|
|
@@ -147,6 +171,7 @@ function batch(
|
|
|
147
171
|
bytesLimit,
|
|
148
172
|
maxMessageSize,
|
|
149
173
|
flushTimeout,
|
|
174
|
+
isLineProtocolToJson,
|
|
150
175
|
beforeUnloadCallback
|
|
151
176
|
) {
|
|
152
177
|
this.request = request
|
|
@@ -154,6 +179,7 @@ function batch(
|
|
|
154
179
|
this.bytesLimit = bytesLimit
|
|
155
180
|
this.maxMessageSize = maxMessageSize
|
|
156
181
|
this.flushTimeout = flushTimeout
|
|
182
|
+
this.isLineProtocolToJson = isLineProtocolToJson,
|
|
157
183
|
this.beforeUnloadCallback = beforeUnloadCallback
|
|
158
184
|
this.pushOnlyBuffer = []
|
|
159
185
|
this.upsertBuffer = {}
|
|
@@ -174,7 +200,15 @@ batch.prototype = {
|
|
|
174
200
|
flush: function () {
|
|
175
201
|
if (this.bufferMessageCount !== 0) {
|
|
176
202
|
var messages = this.pushOnlyBuffer.concat(values(this.upsertBuffer))
|
|
177
|
-
|
|
203
|
+
if (messages.length === 0) return
|
|
204
|
+
if (this.isLineProtocolToJson) {
|
|
205
|
+
this.request.send(map(messages, function(rowdataStr) {
|
|
206
|
+
return JSON.parse(rowdataStr)
|
|
207
|
+
}), this.bufferBytesSize)
|
|
208
|
+
} else {
|
|
209
|
+
this.request.send(messages.join('\n'), this.bufferBytesSize)
|
|
210
|
+
}
|
|
211
|
+
|
|
178
212
|
this.pushOnlyBuffer = []
|
|
179
213
|
this.upsertBuffer = {}
|
|
180
214
|
this.bufferBytesSize = 0
|
|
@@ -183,6 +217,9 @@ batch.prototype = {
|
|
|
183
217
|
},
|
|
184
218
|
|
|
185
219
|
processSendData: function (message) {
|
|
220
|
+
if (this.isLineProtocolToJson) {
|
|
221
|
+
return JSON.stringify(processedMessageByDataMap(message).rowData)
|
|
222
|
+
}
|
|
186
223
|
return processedMessageByDataMap(message).rowStr
|
|
187
224
|
},
|
|
188
225
|
sizeInBytes: function (candidate) {
|