@cloudcare/browser-core 1.1.2 → 1.2.0
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/{cookie.js → browser/cookie.js} +6 -37
- package/cjs/browser/fetchObservable.js +91 -0
- package/cjs/browser/xhrObservable.js +118 -0
- package/cjs/configuration/configuration.js +70 -0
- package/cjs/configuration/transportConfiguration.js +64 -0
- package/cjs/console/consoleObservable.js +84 -0
- package/cjs/dataMap.js +26 -21
- package/cjs/error/trackRuntimeError.js +27 -0
- package/cjs/helper/catchUserErrors.js +20 -0
- package/cjs/helper/contextHistory.js +134 -0
- package/cjs/helper/createEventRateLimiter.js +47 -0
- package/cjs/helper/deviceInfo.js +8 -25
- package/cjs/helper/display.js +31 -0
- package/cjs/helper/enums.js +28 -2
- package/cjs/helper/errorTools.js +63 -2
- package/cjs/helper/instrumentMethod.js +93 -0
- package/cjs/helper/lifeCycle.js +5 -3
- package/cjs/helper/observable.js +40 -2
- package/cjs/helper/tools.js +217 -11
- package/cjs/index.js +153 -23
- package/cjs/init.js +17 -27
- package/cjs/report/reportObservable.js +112 -0
- package/cjs/session/sessionConstants.js +13 -0
- package/cjs/session/sessionCookieStore.js +188 -0
- package/cjs/session/sessionManagement.js +96 -0
- package/cjs/session/sessionStore.js +150 -0
- package/cjs/synthetics/syntheticsWorkerValues.js +32 -0
- package/cjs/synthetics/usr.js +32 -0
- package/cjs/tracekit/computeStackTrace.js +73 -563
- package/cjs/tracekit/index.js +3 -15
- package/cjs/tracekit/tracekit.js +113 -0
- package/cjs/transport/batch.js +332 -0
- package/cjs/transport/httpRequest.js +112 -0
- package/cjs/transport/index.js +29 -0
- package/cjs/transport/sendWithRetryStrategy.js +177 -0
- package/cjs/transport/startBatchWithReplica.js +24 -0
- package/esm/{cookie.js → browser/cookie.js} +4 -35
- package/esm/browser/fetchObservable.js +77 -0
- package/esm/browser/xhrObservable.js +106 -0
- package/esm/configuration/configuration.js +55 -0
- package/esm/configuration/transportConfiguration.js +54 -0
- package/esm/console/consoleObservable.js +70 -0
- package/esm/dataMap.js +26 -21
- package/esm/error/trackRuntimeError.js +16 -0
- package/esm/helper/catchUserErrors.js +12 -0
- package/esm/helper/contextHistory.js +106 -0
- package/esm/helper/createEventRateLimiter.js +38 -0
- package/esm/helper/deviceInfo.js +6 -25
- package/esm/helper/display.js +21 -0
- package/esm/helper/enums.js +25 -1
- package/esm/helper/errorTools.js +58 -3
- package/esm/helper/instrumentMethod.js +81 -0
- package/esm/helper/lifeCycle.js +5 -3
- package/esm/helper/observable.js +39 -3
- package/esm/helper/tools.js +173 -3
- package/esm/index.js +17 -7
- package/esm/init.js +17 -22
- package/esm/report/reportObservable.js +98 -0
- package/esm/session/sessionConstants.js +3 -0
- package/esm/session/sessionCookieStore.js +168 -0
- package/esm/session/sessionManagement.js +78 -0
- package/esm/session/sessionStore.js +139 -0
- package/esm/synthetics/syntheticsWorkerValues.js +15 -0
- package/esm/synthetics/usr.js +18 -0
- package/esm/tracekit/computeStackTrace.js +73 -557
- package/esm/tracekit/index.js +1 -1
- package/esm/tracekit/tracekit.js +103 -0
- package/esm/transport/batch.js +316 -0
- package/esm/transport/httpRequest.js +104 -0
- package/esm/transport/index.js +3 -0
- package/esm/transport/sendWithRetryStrategy.js +165 -0
- package/esm/transport/startBatchWithReplica.js +15 -0
- package/package.json +2 -2
- package/src/.DS_Store +0 -0
- package/src/{cookie.js → browser/cookie.js} +6 -34
- package/src/browser/fetchObservable.js +86 -0
- package/src/browser/xhrObservable.js +102 -0
- package/src/configuration/configuration.js +61 -0
- package/src/configuration/transportConfiguration.js +42 -0
- package/src/console/consoleObservable.js +65 -0
- package/src/dataMap.js +26 -21
- package/src/error/trackRuntimeError.js +19 -0
- package/src/helper/catchUserErrors.js +12 -0
- package/src/helper/contextHistory.js +85 -0
- package/src/helper/createEventRateLimiter.js +37 -0
- package/src/helper/deviceInfo.js +5 -51
- package/src/helper/display.js +21 -0
- package/src/helper/enums.js +38 -14
- package/src/helper/errorTools.js +76 -12
- package/src/helper/instrumentMethod.js +97 -0
- package/src/helper/lifeCycle.js +5 -3
- package/src/helper/observable.js +33 -2
- package/src/helper/tools.js +159 -5
- package/src/index.js +18 -7
- package/src/init.js +17 -18
- package/src/report/reportObservable.js +113 -0
- package/src/session/sessionConstants.js +3 -0
- package/src/session/sessionCookieStore.js +159 -0
- package/src/session/sessionManagement.js +89 -0
- package/src/session/sessionStore.js +139 -0
- package/src/synthetics/syntheticsWorkerValues.js +22 -0
- package/src/synthetics/usr.js +18 -0
- package/src/tracekit/computeStackTrace.js +75 -551
- package/src/tracekit/index.js +1 -1
- package/src/tracekit/tracekit.js +100 -0
- package/src/transport/batch.js +289 -0
- package/src/transport/httpRequest.js +109 -0
- package/src/transport/index.js +3 -0
- package/src/transport/sendWithRetryStrategy.js +186 -0
- package/src/transport/startBatchWithReplica.js +26 -0
- package/cjs/configuration.js +0 -184
- package/cjs/errorCollection.js +0 -167
- package/cjs/fetchProxy.js +0 -162
- package/cjs/helper/errorFilter.js +0 -47
- package/cjs/sessionManagement.js +0 -221
- package/cjs/tracekit/report.js +0 -289
- package/cjs/transport.js +0 -373
- package/cjs/xhrProxy.js +0 -122
- package/esm/configuration.js +0 -167
- package/esm/errorCollection.js +0 -141
- package/esm/fetchProxy.js +0 -116
- package/esm/helper/errorFilter.js +0 -38
- package/esm/sessionManagement.js +0 -195
- package/esm/tracekit/report.js +0 -273
- package/esm/transport.js +0 -357
- package/esm/xhrProxy.js +0 -110
- package/src/configuration.js +0 -156
- package/src/errorCollection.js +0 -170
- package/src/fetchProxy.js +0 -109
- package/src/helper/errorFilter.js +0 -38
- package/src/sessionManagement.js +0 -224
- package/src/tracekit/report.js +0 -284
- package/src/transport.js +0 -380
- package/src/xhrProxy.js +0 -106
package/cjs/transport.js
DELETED
|
@@ -1,373 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.processedMessageByDataMap = exports.HttpRequest = exports.Batch = void 0;
|
|
7
|
-
|
|
8
|
-
var _tools = require("./helper/tools");
|
|
9
|
-
|
|
10
|
-
var _enums = require("./helper/enums");
|
|
11
|
-
|
|
12
|
-
var _dataMap = require("./dataMap");
|
|
13
|
-
|
|
14
|
-
var _init = require("./init");
|
|
15
|
-
|
|
16
|
-
// https://en.wikipedia.org/wiki/UTF-8
|
|
17
|
-
var HAS_MULTI_BYTES_CHARACTERS = /[^\u0000-\u007F]/;
|
|
18
|
-
var CUSTOM_KEYS = 'custom_keys';
|
|
19
|
-
|
|
20
|
-
function addBatchPrecision(url) {
|
|
21
|
-
if (!url) return url;
|
|
22
|
-
return url + (url.indexOf('?') === -1 ? '?' : '&') + 'precision=ms';
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
var global = (0, _init.getGlobalObject)();
|
|
26
|
-
|
|
27
|
-
var httpRequest = function httpRequest(endpointUrl, bytesLimit, isLineProtocolToJson) {
|
|
28
|
-
this.endpointUrl = endpointUrl;
|
|
29
|
-
this.bytesLimit = bytesLimit;
|
|
30
|
-
this.isLineProtocolToJson = isLineProtocolToJson;
|
|
31
|
-
var isRealNavigator = Object.prototype.toString.call(global && global.navigator) === '[object Navigator]';
|
|
32
|
-
var hasSendBeacon = isRealNavigator && typeof global.navigator.sendBeacon === 'function';
|
|
33
|
-
|
|
34
|
-
if (hasSendBeacon) {
|
|
35
|
-
this.sendBeacon = global.navigator.sendBeacon.bind(global.navigator);
|
|
36
|
-
} else {
|
|
37
|
-
this.sendBeacon = undefined;
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
httpRequest.prototype = {
|
|
42
|
-
send: function send(data, size) {
|
|
43
|
-
var url = addBatchPrecision(this.endpointUrl);
|
|
44
|
-
|
|
45
|
-
if (this.sendBeacon && size < this.bytesLimit && !this.isLineProtocolToJson) {
|
|
46
|
-
var isQueued = this.sendBeacon(url, data);
|
|
47
|
-
|
|
48
|
-
if (isQueued) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
} else if (this.sendBeacon && size < this.bytesLimit && this.isLineProtocolToJson) {
|
|
52
|
-
var blob = new Blob([JSON.stringify(data)], {
|
|
53
|
-
type: 'application/json'
|
|
54
|
-
});
|
|
55
|
-
var isQueued = this.sendBeacon(url, blob);
|
|
56
|
-
|
|
57
|
-
if (isQueued) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
var request = new XMLHttpRequest();
|
|
63
|
-
request.open('POST', url, true);
|
|
64
|
-
request.withCredentials = true;
|
|
65
|
-
|
|
66
|
-
if (this.isLineProtocolToJson) {
|
|
67
|
-
request.setRequestHeader('Content-type', 'application/json');
|
|
68
|
-
request.send(JSON.stringify(data));
|
|
69
|
-
} else {
|
|
70
|
-
request.setRequestHeader('Content-type', 'text/plain;charset=UTF-8');
|
|
71
|
-
request.send(data);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
var HttpRequest = httpRequest;
|
|
76
|
-
exports.HttpRequest = HttpRequest;
|
|
77
|
-
|
|
78
|
-
var processedMessageByDataMap = function processedMessageByDataMap(message) {
|
|
79
|
-
if (!message || !message.type) return {
|
|
80
|
-
rowStr: '',
|
|
81
|
-
rowData: undefined
|
|
82
|
-
};
|
|
83
|
-
var rowData = {
|
|
84
|
-
tags: {},
|
|
85
|
-
fields: {}
|
|
86
|
-
};
|
|
87
|
-
var hasFileds = false;
|
|
88
|
-
var rowStr = '';
|
|
89
|
-
(0, _tools.each)(_dataMap.dataMap, function (value, key) {
|
|
90
|
-
if (value.type === message.type) {
|
|
91
|
-
rowStr += key + ',';
|
|
92
|
-
rowData.measurement = key;
|
|
93
|
-
var tagsStr = [];
|
|
94
|
-
var tags = (0, _tools.extend)({}, _dataMap.commonTags, value.tags);
|
|
95
|
-
var filterFileds = ['date', 'type', CUSTOM_KEYS]; // 已经在datamap中定义过的fields和tags
|
|
96
|
-
|
|
97
|
-
(0, _tools.each)(tags, function (value_path, _key) {
|
|
98
|
-
var _value = (0, _tools.findByPath)(message, value_path);
|
|
99
|
-
|
|
100
|
-
filterFileds.push(_key);
|
|
101
|
-
|
|
102
|
-
if (_value || (0, _tools.isNumber)(_value)) {
|
|
103
|
-
rowData.tags[_key] = (0, _tools.escapeJsonValue)(_value);
|
|
104
|
-
tagsStr.push((0, _tools.escapeRowData)(_key) + '=' + (0, _tools.escapeRowData)(_value));
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
var fieldsStr = [];
|
|
108
|
-
(0, _tools.each)(value.fields, function (_value, _key) {
|
|
109
|
-
if ((0, _tools.isArray)(_value) && _value.length === 2) {
|
|
110
|
-
var type = _value[0],
|
|
111
|
-
value_path = _value[1];
|
|
112
|
-
|
|
113
|
-
var _valueData = (0, _tools.findByPath)(message, value_path);
|
|
114
|
-
|
|
115
|
-
filterFileds.push(_key);
|
|
116
|
-
|
|
117
|
-
if (_valueData || (0, _tools.isNumber)(_valueData)) {
|
|
118
|
-
rowData.fields[_key] = _valueData; // 这里不需要转译
|
|
119
|
-
// _valueData =
|
|
120
|
-
// type === 'string'
|
|
121
|
-
// ? '"' +
|
|
122
|
-
// _valueData.replace(/[\\]*"/g, '"').replace(/"/g, '\\"') +
|
|
123
|
-
// '"'
|
|
124
|
-
// : escapeRowData(_valueData)
|
|
125
|
-
|
|
126
|
-
fieldsStr.push((0, _tools.escapeRowData)(_key) + '=' + (0, _tools.escapeRowField)(_valueData));
|
|
127
|
-
}
|
|
128
|
-
} else if ((0, _tools.isString)(_value)) {
|
|
129
|
-
var _valueData = (0, _tools.findByPath)(message, _value);
|
|
130
|
-
|
|
131
|
-
filterFileds.push(_key);
|
|
132
|
-
|
|
133
|
-
if (_valueData || (0, _tools.isNumber)(_valueData)) {
|
|
134
|
-
rowData.fields[_key] = _valueData; // 这里不需要转译
|
|
135
|
-
|
|
136
|
-
fieldsStr.push((0, _tools.escapeRowData)(_key) + '=' + (0, _tools.escapeRowField)(_valueData));
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
if (message.tags && (0, _tools.isObject)(message.tags) && !(0, _tools.isEmptyObject)(message.tags)) {
|
|
142
|
-
// 自定义tag, 存储成field
|
|
143
|
-
var _tagKeys = [];
|
|
144
|
-
(0, _tools.each)(message.tags, function (_value, _key) {
|
|
145
|
-
// 如果和之前tag重名,则舍弃
|
|
146
|
-
if (filterFileds.indexOf(_key) > -1) return;
|
|
147
|
-
filterFileds.push(_key);
|
|
148
|
-
|
|
149
|
-
if (_value || (0, _tools.isNumber)(_value)) {
|
|
150
|
-
_tagKeys.push(_key);
|
|
151
|
-
|
|
152
|
-
rowData.fields[_key] = _value; // 这里不需要转译
|
|
153
|
-
|
|
154
|
-
fieldsStr.push((0, _tools.escapeRowData)(_key) + '=' + (0, _tools.escapeRowField)(_value));
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
if (_tagKeys.length) {
|
|
159
|
-
rowData.fields[CUSTOM_KEYS] = (0, _tools.escapeRowField)(_tagKeys);
|
|
160
|
-
fieldsStr.push((0, _tools.escapeRowData)(CUSTOM_KEYS) + '=' + (0, _tools.escapeRowField)(_tagKeys));
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (message.type === _enums.RumEventType.LOGGER) {
|
|
165
|
-
// 这里处理日志类型数据自定义字段
|
|
166
|
-
(0, _tools.each)(message, function (value, key) {
|
|
167
|
-
if (filterFileds.indexOf(key) === -1 && ((0, _tools.isNumber)(value) || (0, _tools.isString)(value) || (0, _tools.isBoolean)(value))) {
|
|
168
|
-
rowData.fields[key] = value; // 这里不需要转译
|
|
169
|
-
|
|
170
|
-
fieldsStr.push((0, _tools.escapeRowData)(key) + '=' + (0, _tools.escapeRowField)(value));
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (tagsStr.length) {
|
|
176
|
-
rowStr += tagsStr.join(',');
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
if (fieldsStr.length) {
|
|
180
|
-
rowStr += ' ';
|
|
181
|
-
rowStr += fieldsStr.join(',');
|
|
182
|
-
hasFileds = true;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
rowStr = rowStr + ' ' + message.date;
|
|
186
|
-
rowData.time = (0, _tools.toServerDuration)(message.date); // 这里不需要转译
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
return {
|
|
190
|
-
rowStr: hasFileds ? rowStr : '',
|
|
191
|
-
rowData: hasFileds ? rowData : undefined
|
|
192
|
-
};
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
exports.processedMessageByDataMap = processedMessageByDataMap;
|
|
196
|
-
|
|
197
|
-
var batch = function batch(request, maxSize, bytesLimit, maxMessageSize, flushTimeout, isLineProtocolToJson, beforeUnloadCallback) {
|
|
198
|
-
this.request = request;
|
|
199
|
-
this.maxSize = maxSize;
|
|
200
|
-
this.bytesLimit = bytesLimit;
|
|
201
|
-
this.maxMessageSize = maxMessageSize;
|
|
202
|
-
this.flushTimeout = flushTimeout;
|
|
203
|
-
this.isLineProtocolToJson = isLineProtocolToJson;
|
|
204
|
-
this.beforeUnloadCallback = beforeUnloadCallback;
|
|
205
|
-
this.pushOnlyBuffer = [];
|
|
206
|
-
this.upsertBuffer = {};
|
|
207
|
-
this.bufferBytesSize = 0;
|
|
208
|
-
this.bufferMessageCount = 0;
|
|
209
|
-
this.flushOnVisibilityHidden();
|
|
210
|
-
this.flushPeriodically();
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
batch.prototype = {
|
|
214
|
-
add: function add(message) {
|
|
215
|
-
this.addOrUpdate(message);
|
|
216
|
-
},
|
|
217
|
-
upsert: function upsert(message, key) {
|
|
218
|
-
this.addOrUpdate(message, key);
|
|
219
|
-
},
|
|
220
|
-
flush: function flush() {
|
|
221
|
-
if (this.bufferMessageCount !== 0) {
|
|
222
|
-
var messages = this.pushOnlyBuffer.concat((0, _tools.values)(this.upsertBuffer));
|
|
223
|
-
if (messages.length === 0) return;
|
|
224
|
-
|
|
225
|
-
if (this.isLineProtocolToJson) {
|
|
226
|
-
this.request.send((0, _tools.map)(messages, function (rowdataStr) {
|
|
227
|
-
return JSON.parse(rowdataStr);
|
|
228
|
-
}), this.bufferBytesSize);
|
|
229
|
-
} else {
|
|
230
|
-
this.request.send(messages.join('\n'), this.bufferBytesSize);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
this.pushOnlyBuffer = [];
|
|
234
|
-
this.upsertBuffer = {};
|
|
235
|
-
this.bufferBytesSize = 0;
|
|
236
|
-
this.bufferMessageCount = 0;
|
|
237
|
-
}
|
|
238
|
-
},
|
|
239
|
-
processSendData: function processSendData(message) {
|
|
240
|
-
if (this.isLineProtocolToJson) {
|
|
241
|
-
return JSON.stringify(processedMessageByDataMap(message).rowData);
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
return processedMessageByDataMap(message).rowStr;
|
|
245
|
-
},
|
|
246
|
-
sizeInBytes: function sizeInBytes(candidate) {
|
|
247
|
-
// Accurate byte size computations can degrade performances when there is a lot of events to process
|
|
248
|
-
if (!HAS_MULTI_BYTES_CHARACTERS.test(candidate)) {
|
|
249
|
-
return candidate.length;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if (window.TextEncoder !== undefined) {
|
|
253
|
-
return new TextEncoder().encode(candidate).length;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
return new Blob([candidate]).size;
|
|
257
|
-
},
|
|
258
|
-
addOrUpdate: function addOrUpdate(message, key) {
|
|
259
|
-
var process = this.process(message);
|
|
260
|
-
if (!process.processedMessage || process.processedMessage === '') return;
|
|
261
|
-
|
|
262
|
-
if (process.messageBytesSize >= this.maxMessageSize) {
|
|
263
|
-
console.warn('Discarded a message whose size was bigger than the maximum allowed size' + this.maxMessageSize + 'KB.');
|
|
264
|
-
return;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
if (this.hasMessageFor(key)) {
|
|
268
|
-
this.remove(key);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
if (this.willReachedBytesLimitWith(process.messageBytesSize)) {
|
|
272
|
-
this.flush();
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
this.push(process.processedMessage, process.messageBytesSize, key);
|
|
276
|
-
|
|
277
|
-
if (this.isFull()) {
|
|
278
|
-
this.flush();
|
|
279
|
-
}
|
|
280
|
-
},
|
|
281
|
-
process: function process(message) {
|
|
282
|
-
var processedMessage = '';
|
|
283
|
-
var processedMessage = this.processSendData(message);
|
|
284
|
-
var messageBytesSize = this.sizeInBytes(processedMessage);
|
|
285
|
-
return {
|
|
286
|
-
processedMessage: processedMessage,
|
|
287
|
-
messageBytesSize: messageBytesSize
|
|
288
|
-
};
|
|
289
|
-
},
|
|
290
|
-
push: function push(processedMessage, messageBytesSize, key) {
|
|
291
|
-
if (this.bufferMessageCount > 0) {
|
|
292
|
-
// \n separator at serialization
|
|
293
|
-
this.bufferBytesSize += 1;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
if (key !== undefined) {
|
|
297
|
-
this.upsertBuffer[key] = processedMessage;
|
|
298
|
-
} else {
|
|
299
|
-
this.pushOnlyBuffer.push(processedMessage);
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
this.bufferBytesSize += messageBytesSize;
|
|
303
|
-
this.bufferMessageCount += 1;
|
|
304
|
-
},
|
|
305
|
-
remove: function remove(key) {
|
|
306
|
-
var removedMessage = this.upsertBuffer[key];
|
|
307
|
-
delete this.upsertBuffer[key];
|
|
308
|
-
var messageBytesSize = this.sizeInBytes(removedMessage);
|
|
309
|
-
this.bufferBytesSize -= messageBytesSize;
|
|
310
|
-
this.bufferMessageCount -= 1;
|
|
311
|
-
|
|
312
|
-
if (this.bufferMessageCount > 0) {
|
|
313
|
-
this.bufferBytesSize -= 1;
|
|
314
|
-
}
|
|
315
|
-
},
|
|
316
|
-
hasMessageFor: function hasMessageFor(key) {
|
|
317
|
-
return key !== undefined && this.upsertBuffer[key] !== undefined;
|
|
318
|
-
},
|
|
319
|
-
willReachedBytesLimitWith: function willReachedBytesLimitWith(messageBytesSize) {
|
|
320
|
-
// byte of the separator at the end of the message
|
|
321
|
-
return this.bufferBytesSize + messageBytesSize + 1 >= this.bytesLimit;
|
|
322
|
-
},
|
|
323
|
-
isFull: function isFull() {
|
|
324
|
-
return this.bufferMessageCount === this.maxSize || this.bufferBytesSize >= this.bytesLimit;
|
|
325
|
-
},
|
|
326
|
-
flushPeriodically: function flushPeriodically() {
|
|
327
|
-
var _this = this;
|
|
328
|
-
|
|
329
|
-
setTimeout(function () {
|
|
330
|
-
_this.flush();
|
|
331
|
-
|
|
332
|
-
_this.flushPeriodically();
|
|
333
|
-
}, _this.flushTimeout);
|
|
334
|
-
},
|
|
335
|
-
flushOnVisibilityHidden: function flushOnVisibilityHidden() {
|
|
336
|
-
var _this = this;
|
|
337
|
-
/**
|
|
338
|
-
* With sendBeacon, requests are guaranteed to be successfully sent during document unload
|
|
339
|
-
*/
|
|
340
|
-
// @ts-ignore this function is not always defined
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
if (global.navigator.sendBeacon) {
|
|
344
|
-
/**
|
|
345
|
-
* beforeunload is called before visibilitychange
|
|
346
|
-
* register first to be sure to be called before flush on beforeunload
|
|
347
|
-
* caveat: unload can still be canceled by another listener
|
|
348
|
-
*/
|
|
349
|
-
(0, _tools.addEventListener)(window, _enums.DOM_EVENT.BEFORE_UNLOAD, _this.beforeUnloadCallback);
|
|
350
|
-
/**
|
|
351
|
-
* Only event that guarantee to fire on mobile devices when the page transitions to background state
|
|
352
|
-
* (e.g. when user switches to a different application, goes to homescreen, etc), or is being unloaded.
|
|
353
|
-
*/
|
|
354
|
-
|
|
355
|
-
(0, _tools.addEventListener)(document, _enums.DOM_EVENT.VISIBILITY_CHANGE, function () {
|
|
356
|
-
if (document.visibilityState === 'hidden') {
|
|
357
|
-
_this.flush();
|
|
358
|
-
}
|
|
359
|
-
});
|
|
360
|
-
/**
|
|
361
|
-
* Safari does not support yet to send a request during:
|
|
362
|
-
* - a visibility change during doc unload (cf: https://bugs.webkit.org/show_bug.cgi?id=194897)
|
|
363
|
-
* - a page hide transition (cf: https://bugs.webkit.org/show_bug.cgi?id=188329)
|
|
364
|
-
*/
|
|
365
|
-
|
|
366
|
-
(0, _tools.addEventListener)(window, _enums.DOM_EVENT.BEFORE_UNLOAD, function () {
|
|
367
|
-
_this.flush();
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
};
|
|
372
|
-
var Batch = batch;
|
|
373
|
-
exports.Batch = Batch;
|
package/cjs/xhrProxy.js
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.resetXhrProxy = resetXhrProxy;
|
|
7
|
-
exports.startXhrProxy = startXhrProxy;
|
|
8
|
-
|
|
9
|
-
var _urlPolyfill = require("./helper/urlPolyfill");
|
|
10
|
-
|
|
11
|
-
var _tools = require("./helper/tools");
|
|
12
|
-
|
|
13
|
-
var xhrProxySingleton;
|
|
14
|
-
var beforeSendCallbacks = [];
|
|
15
|
-
var onRequestCompleteCallbacks = [];
|
|
16
|
-
var originalXhrOpen;
|
|
17
|
-
var originalXhrSend;
|
|
18
|
-
var originalXhrAbort;
|
|
19
|
-
|
|
20
|
-
function startXhrProxy() {
|
|
21
|
-
if (!xhrProxySingleton) {
|
|
22
|
-
proxyXhr();
|
|
23
|
-
xhrProxySingleton = {
|
|
24
|
-
beforeSend: function beforeSend(callback) {
|
|
25
|
-
beforeSendCallbacks.push(callback);
|
|
26
|
-
},
|
|
27
|
-
onRequestComplete: function onRequestComplete(callback) {
|
|
28
|
-
onRequestCompleteCallbacks.push(callback);
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return xhrProxySingleton;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function resetXhrProxy() {
|
|
37
|
-
if (xhrProxySingleton) {
|
|
38
|
-
xhrProxySingleton = undefined;
|
|
39
|
-
beforeSendCallbacks.length = 0;
|
|
40
|
-
onRequestCompleteCallbacks.length = 0;
|
|
41
|
-
XMLHttpRequest.prototype.open = originalXhrOpen;
|
|
42
|
-
XMLHttpRequest.prototype.send = originalXhrSend;
|
|
43
|
-
XMLHttpRequest.prototype.abort = originalXhrAbort;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function proxyXhr() {
|
|
48
|
-
originalXhrOpen = XMLHttpRequest.prototype.open;
|
|
49
|
-
originalXhrSend = XMLHttpRequest.prototype.send;
|
|
50
|
-
originalXhrAbort = XMLHttpRequest.prototype.abort;
|
|
51
|
-
|
|
52
|
-
XMLHttpRequest.prototype.open = function (method, url) {
|
|
53
|
-
// WARN: since this data structure is tied to the instance, it is shared by both logs and rum
|
|
54
|
-
// and can be used by different code versions depending on customer setup
|
|
55
|
-
// so it should stay compatible with older versions
|
|
56
|
-
this._dataflux_xhr = {
|
|
57
|
-
method: method,
|
|
58
|
-
startTime: -1,
|
|
59
|
-
// computed in send call
|
|
60
|
-
url: (0, _urlPolyfill.normalizeUrl)(url)
|
|
61
|
-
};
|
|
62
|
-
return originalXhrOpen.apply(this, arguments);
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
XMLHttpRequest.prototype.send = function (body) {
|
|
66
|
-
var _this = this;
|
|
67
|
-
|
|
68
|
-
if (this._dataflux_xhr) {
|
|
69
|
-
var xhrPendingContext = this._dataflux_xhr;
|
|
70
|
-
xhrPendingContext.startTime = (0, _tools.relativeNow)();
|
|
71
|
-
xhrPendingContext.startClocks = (0, _tools.clocksNow)();
|
|
72
|
-
xhrPendingContext.isAborted = false;
|
|
73
|
-
var originalOnreadystatechange = this.onreadystatechange;
|
|
74
|
-
|
|
75
|
-
this.onreadystatechange = function () {
|
|
76
|
-
if (this.readyState === XMLHttpRequest.DONE) {
|
|
77
|
-
reportXhr();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (originalOnreadystatechange) {
|
|
81
|
-
originalOnreadystatechange.apply(this, arguments);
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
var hasBeenReported = false;
|
|
86
|
-
|
|
87
|
-
var reportXhr = function reportXhr() {
|
|
88
|
-
_this.removeEventListener('loadend', reportXhr);
|
|
89
|
-
|
|
90
|
-
if (hasBeenReported) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
hasBeenReported = true;
|
|
95
|
-
var xhrCompleteContext = (0, _tools.extend)({}, xhrPendingContext, {
|
|
96
|
-
duration: (0, _tools.elapsed)(xhrPendingContext.startClocks.relative, (0, _tools.relativeNow)()),
|
|
97
|
-
response: _this.response,
|
|
98
|
-
status: _this.status
|
|
99
|
-
});
|
|
100
|
-
(0, _tools.each)(onRequestCompleteCallbacks, function (callback) {
|
|
101
|
-
callback(xhrCompleteContext, _this);
|
|
102
|
-
});
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
_this.addEventListener('loadend', reportXhr);
|
|
106
|
-
|
|
107
|
-
(0, _tools.each)(beforeSendCallbacks, function (callback) {
|
|
108
|
-
callback(xhrPendingContext, _this);
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return originalXhrSend.apply(_this, arguments);
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
XMLHttpRequest.prototype.abort = function () {
|
|
116
|
-
if (this._dataflux_xhr) {
|
|
117
|
-
this._dataflux_xhr.isAborted = true;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return originalXhrAbort.apply(this, arguments);
|
|
121
|
-
};
|
|
122
|
-
}
|
package/esm/configuration.js
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import { ONE_KILO_BYTE, ONE_SECOND, extend2Lev, isArray, includes, isFunction, isBoolean, values } from './helper/tools';
|
|
2
|
-
import { getCurrentSite } from './cookie';
|
|
3
|
-
import { haveSameOrigin } from './helper/urlPolyfill';
|
|
4
|
-
import { TraceType } from './helper/enums';
|
|
5
|
-
var TRIM_REGIX = /^\s+|\s+$/g;
|
|
6
|
-
export var DEFAULT_CONFIGURATION = {
|
|
7
|
-
resourceSampleRate: 100,
|
|
8
|
-
sampleRate: 100,
|
|
9
|
-
flushTimeout: 30 * ONE_SECOND,
|
|
10
|
-
maxErrorsByMinute: 3000,
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Logs intake limit
|
|
14
|
-
*/
|
|
15
|
-
maxBatchSize: 50,
|
|
16
|
-
maxMessageSize: 256 * ONE_KILO_BYTE,
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* arbitrary value, byte precision not needed
|
|
20
|
-
*/
|
|
21
|
-
requestErrorResponseLengthLimit: 32 * ONE_KILO_BYTE,
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* beacon payload max queue size implementation is 64kb
|
|
25
|
-
* ensure that we leave room for logs, rum and potential other users
|
|
26
|
-
*/
|
|
27
|
-
batchBytesLimit: 16 * ONE_KILO_BYTE,
|
|
28
|
-
datakitUrl: '',
|
|
29
|
-
logsEndpoint: '',
|
|
30
|
-
traceType: TraceType.DDTRACE,
|
|
31
|
-
traceId128Bit: false,
|
|
32
|
-
trackInteractions: false,
|
|
33
|
-
//是否开启交互action收集
|
|
34
|
-
allowedDDTracingOrigins: [],
|
|
35
|
-
//废弃
|
|
36
|
-
allowedTracingOrigins: [],
|
|
37
|
-
// 新增
|
|
38
|
-
isServiceSampling: false,
|
|
39
|
-
// 是否不抛弃采样是数据, 采用在服务端菜样的方式
|
|
40
|
-
isJsBirdge: false,
|
|
41
|
-
// 是否需要对webview 发送数据,需要装我们对应ios sdk
|
|
42
|
-
isLineProtocolToJson: false,
|
|
43
|
-
beforeSend: function beforeSend(event) {},
|
|
44
|
-
isServerError: function isServerError(request) {
|
|
45
|
-
return false;
|
|
46
|
-
} // 判断请求是否为error 请求
|
|
47
|
-
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
function trim(str) {
|
|
51
|
-
return str.replace(TRIM_REGIX, '');
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export function buildCookieOptions(userConfiguration) {
|
|
55
|
-
var cookieOptions = {};
|
|
56
|
-
cookieOptions.secure = mustUseSecureCookie(userConfiguration);
|
|
57
|
-
cookieOptions.crossSite = !!userConfiguration.useCrossSiteSessionCookie;
|
|
58
|
-
|
|
59
|
-
if (!!userConfiguration.trackSessionAcrossSubdomains) {
|
|
60
|
-
cookieOptions.domain = getCurrentSite();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return cookieOptions;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function getDatakitUrl(url) {
|
|
67
|
-
if (url.lastIndexOf('/') === url.length - 1) return trim(url) + 'v1/write/rum';
|
|
68
|
-
return trim(url) + '/v1/write/rum';
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function getLogsEndPoint(url) {
|
|
72
|
-
if (url.lastIndexOf('/') === url.length - 1) return trim(url) + 'v1/write/logging';
|
|
73
|
-
return trim(url) + '/v1/write/logging';
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function commonInit(userConfiguration, buildEnv) {
|
|
77
|
-
var enableExperimentalFeatures = isArray(userConfiguration.enableExperimentalFeatures) ? userConfiguration.enableExperimentalFeatures : [];
|
|
78
|
-
var transportConfiguration = {
|
|
79
|
-
applicationId: userConfiguration.applicationId,
|
|
80
|
-
env: userConfiguration.env || '',
|
|
81
|
-
version: userConfiguration.version || '',
|
|
82
|
-
service: userConfiguration.service || 'browser',
|
|
83
|
-
sdkVersion: buildEnv.sdkVersion,
|
|
84
|
-
sdkName: buildEnv.sdkName,
|
|
85
|
-
datakitUrl: getDatakitUrl(userConfiguration.datakitUrl || userConfiguration.datakitOrigin),
|
|
86
|
-
logsEndpoint: getLogsEndPoint(userConfiguration.datakitOrigin),
|
|
87
|
-
isEnabled: function isEnabled(feature) {
|
|
88
|
-
return includes(enableExperimentalFeatures, feature);
|
|
89
|
-
},
|
|
90
|
-
cookieOptions: buildCookieOptions(userConfiguration)
|
|
91
|
-
};
|
|
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
|
-
|
|
101
|
-
if ('allowedDDTracingOrigins' in userConfiguration) {
|
|
102
|
-
transportConfiguration.allowedTracingOrigins = userConfiguration.allowedDDTracingOrigins;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if ('allowedTracingOrigins' in userConfiguration) {
|
|
106
|
-
transportConfiguration.allowedTracingOrigins = userConfiguration.allowedTracingOrigins;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if ('sampleRate' in userConfiguration) {
|
|
110
|
-
transportConfiguration.sampleRate = userConfiguration.sampleRate;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if ('resourceSampleRate' in userConfiguration) {
|
|
114
|
-
transportConfiguration.resourceSampleRate = userConfiguration.resourceSampleRate;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if ('trackInteractions' in userConfiguration) {
|
|
118
|
-
transportConfiguration.trackInteractions = !!userConfiguration.trackInteractions;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if ('isServerError' in userConfiguration && isFunction(userConfiguration.isServerError) && isBoolean(userConfiguration.isServerError())) {
|
|
122
|
-
transportConfiguration.isServerError = userConfiguration.isServerError;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if ('traceId128Bit' in userConfiguration) {
|
|
126
|
-
transportConfiguration.traceId128Bit = !!userConfiguration.traceId128Bit;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if ('traceType' in userConfiguration && hasTraceType(userConfiguration.traceType)) {
|
|
130
|
-
transportConfiguration.traceType = userConfiguration.traceType;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if ('isServiceSampling' in userConfiguration && isBoolean(userConfiguration.isServiceSampling)) {
|
|
134
|
-
transportConfiguration.isServiceSampling = userConfiguration.isServiceSampling;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return extend2Lev({}, DEFAULT_CONFIGURATION, transportConfiguration);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function hasTraceType(traceType) {
|
|
141
|
-
if (traceType && values(TraceType).indexOf(traceType) > -1) return true;
|
|
142
|
-
return false;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function mustUseSecureCookie(userConfiguration) {
|
|
146
|
-
return !!userConfiguration.useSecureSessionCookie || !!userConfiguration.useCrossSiteSessionCookie;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export function isIntakeRequest(url, configuration) {
|
|
150
|
-
// return haveSameOrigin(url, configuration.datakitUrl)
|
|
151
|
-
var notTakeRequest = [configuration.datakitUrl];
|
|
152
|
-
|
|
153
|
-
if (configuration.logsEndpoint) {
|
|
154
|
-
notTakeRequest.push(configuration.logsEndpoint);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
var isIntake = false;
|
|
158
|
-
|
|
159
|
-
for (var _url of notTakeRequest) {
|
|
160
|
-
if (url.indexOf(_url) === 0) {
|
|
161
|
-
isIntake = true;
|
|
162
|
-
break;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
return isIntake;
|
|
167
|
-
}
|