@cloudcare/browser-core 1.0.15 → 1.0.18
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 +32 -2
- package/cjs/cookie.js +4 -0
- package/cjs/dataMap.js +2 -0
- package/cjs/errorCollection.js +9 -5
- package/cjs/helper/enums.js +16 -2
- package/cjs/helper/errorTools.js +39 -1
- package/cjs/helper/tools.js +116 -3
- package/cjs/sessionManagement.js +2 -0
- package/cjs/transport.js +4 -1
- package/esm/configuration.js +32 -3
- package/esm/cookie.js +4 -0
- package/esm/dataMap.js +2 -0
- package/esm/errorCollection.js +11 -7
- package/esm/helper/enums.js +12 -0
- package/esm/helper/errorTools.js +37 -2
- package/esm/helper/tools.js +113 -3
- package/esm/sessionManagement.js +2 -0
- package/esm/transport.js +4 -1
- package/package.json +2 -2
- package/src/configuration.js +26 -4
- package/src/cookie.js +5 -1
- package/src/dataMap.js +2 -0
- package/src/errorCollection.js +12 -7
- package/src/helper/enums.js +13 -0
- package/src/helper/errorTools.js +39 -2
- package/src/helper/tools.js +108 -4
- package/src/sessionManagement.js +2 -0
- package/src/transport.js +4 -1
package/cjs/configuration.js
CHANGED
|
@@ -14,6 +14,8 @@ var _cookie = require("./cookie");
|
|
|
14
14
|
|
|
15
15
|
var _urlPolyfill = require("./helper/urlPolyfill");
|
|
16
16
|
|
|
17
|
+
var _enums = require("./helper/enums");
|
|
18
|
+
|
|
17
19
|
var TRIM_REGIX = /^\s+|\s+$/g;
|
|
18
20
|
var DEFAULT_CONFIGURATION = {
|
|
19
21
|
resourceSampleRate: 100,
|
|
@@ -39,10 +41,16 @@ var DEFAULT_CONFIGURATION = {
|
|
|
39
41
|
batchBytesLimit: 16 * _tools.ONE_KILO_BYTE,
|
|
40
42
|
datakitUrl: '',
|
|
41
43
|
logsEndpoint: '',
|
|
44
|
+
traceType: _enums.TraceType.DDTRACE,
|
|
45
|
+
traceId128Bit: false,
|
|
42
46
|
trackInteractions: false,
|
|
43
47
|
//是否开启交互action收集
|
|
44
48
|
allowedDDTracingOrigins: [],
|
|
45
|
-
|
|
49
|
+
//废弃
|
|
50
|
+
allowedTracingOrigins: [],
|
|
51
|
+
// 新增
|
|
52
|
+
isServiceSampling: false,
|
|
53
|
+
// 是否不抛弃采样是数据, 采用在服务端菜样的方式
|
|
46
54
|
beforeSend: function beforeSend(event) {},
|
|
47
55
|
isServerError: function isServerError(request) {
|
|
48
56
|
return false;
|
|
@@ -83,6 +91,7 @@ function commonInit(userConfiguration, buildEnv) {
|
|
|
83
91
|
applicationId: userConfiguration.applicationId,
|
|
84
92
|
env: userConfiguration.env || '',
|
|
85
93
|
version: userConfiguration.version || '',
|
|
94
|
+
service: userConfiguration.service || 'browser',
|
|
86
95
|
sdkVersion: buildEnv.sdkVersion,
|
|
87
96
|
sdkName: buildEnv.sdkName,
|
|
88
97
|
datakitUrl: getDatakitUrl(userConfiguration.datakitUrl || userConfiguration.datakitOrigin),
|
|
@@ -94,7 +103,11 @@ function commonInit(userConfiguration, buildEnv) {
|
|
|
94
103
|
};
|
|
95
104
|
|
|
96
105
|
if ('allowedDDTracingOrigins' in userConfiguration) {
|
|
97
|
-
transportConfiguration.
|
|
106
|
+
transportConfiguration.allowedTracingOrigins = userConfiguration.allowedDDTracingOrigins;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if ('allowedTracingOrigins' in userConfiguration) {
|
|
110
|
+
transportConfiguration.allowedTracingOrigins = userConfiguration.allowedTracingOrigins;
|
|
98
111
|
}
|
|
99
112
|
|
|
100
113
|
if ('sampleRate' in userConfiguration) {
|
|
@@ -113,9 +126,26 @@ function commonInit(userConfiguration, buildEnv) {
|
|
|
113
126
|
transportConfiguration.isServerError = userConfiguration.isServerError;
|
|
114
127
|
}
|
|
115
128
|
|
|
129
|
+
if ('traceId128Bit' in userConfiguration) {
|
|
130
|
+
transportConfiguration.traceId128Bit = !!userConfiguration.traceId128Bit;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if ('traceType' in userConfiguration && hasTraceType(userConfiguration.traceType)) {
|
|
134
|
+
transportConfiguration.traceType = userConfiguration.traceType;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if ('isServiceSampling' in userConfiguration && (0, _tools.isBoolean)(userConfiguration.isServiceSampling)) {
|
|
138
|
+
transportConfiguration.isServiceSampling = userConfiguration.isServiceSampling;
|
|
139
|
+
}
|
|
140
|
+
|
|
116
141
|
return (0, _tools.extend2Lev)({}, DEFAULT_CONFIGURATION, transportConfiguration);
|
|
117
142
|
}
|
|
118
143
|
|
|
144
|
+
function hasTraceType(traceType) {
|
|
145
|
+
if (traceType && (0, _tools.values)(_enums.TraceType).indexOf(traceType) > -1) return true;
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
|
|
119
149
|
function mustUseSecureCookie(userConfiguration) {
|
|
120
150
|
return !!userConfiguration.useSecureSessionCookie || !!userConfiguration.useCrossSiteSessionCookie;
|
|
121
151
|
}
|
package/cjs/cookie.js
CHANGED
package/cjs/dataMap.js
CHANGED
|
@@ -18,6 +18,7 @@ var commonTags = {
|
|
|
18
18
|
user_name: 'user.name',
|
|
19
19
|
session_id: 'session.id',
|
|
20
20
|
session_type: 'session.type',
|
|
21
|
+
session_sampling: 'session.is_sampling',
|
|
21
22
|
is_signin: 'user.is_signin',
|
|
22
23
|
os: 'device.os',
|
|
23
24
|
os_version: 'device.os_version',
|
|
@@ -101,6 +102,7 @@ var dataMap = {
|
|
|
101
102
|
tags: {
|
|
102
103
|
error_source: 'error.source',
|
|
103
104
|
error_type: 'error.type',
|
|
105
|
+
error_handling: 'error.handling',
|
|
104
106
|
resource_url: 'error.resource.url',
|
|
105
107
|
resource_url_host: 'error.resource.url_host',
|
|
106
108
|
resource_url_path: 'error.resource.url_path',
|
package/cjs/errorCollection.js
CHANGED
|
@@ -46,14 +46,16 @@ function startConsoleTracking(errorObservable) {
|
|
|
46
46
|
|
|
47
47
|
console.error = function () {
|
|
48
48
|
originalConsoleError.apply(console, arguments);
|
|
49
|
-
|
|
49
|
+
var handlingStack = (0, _errorTools.createHandlingStack)();
|
|
50
|
+
errorObservable.notify((0, _tools.extend)({}, buildErrorFromParams((0, _tools.toArray)(arguments), handlingStack), {
|
|
50
51
|
source: _errorTools.ErrorSource.CONSOLE,
|
|
51
|
-
startClocks: (0, _tools.clocksNow)()
|
|
52
|
+
startClocks: (0, _tools.clocksNow)(),
|
|
53
|
+
handling: _enums.ErrorHandling.HANDLED
|
|
52
54
|
}));
|
|
53
55
|
};
|
|
54
56
|
}
|
|
55
57
|
|
|
56
|
-
function buildErrorFromParams(params) {
|
|
58
|
+
function buildErrorFromParams(params, handlingStack) {
|
|
57
59
|
var firstErrorParam = (0, _tools.find)(params, function (param) {
|
|
58
60
|
return param instanceof Error;
|
|
59
61
|
});
|
|
@@ -63,7 +65,8 @@ function buildErrorFromParams(params) {
|
|
|
63
65
|
}).join(' ');
|
|
64
66
|
return {
|
|
65
67
|
message: message,
|
|
66
|
-
stack: firstErrorParam ? (0, _errorTools.toStackTraceString)((0, _tracekit.computeStackTrace)(firstErrorParam)) : undefined
|
|
68
|
+
stack: firstErrorParam ? (0, _errorTools.toStackTraceString)((0, _tracekit.computeStackTrace)(firstErrorParam)) : undefined,
|
|
69
|
+
handlingStack: handlingStack
|
|
67
70
|
};
|
|
68
71
|
}
|
|
69
72
|
|
|
@@ -93,7 +96,8 @@ function startRuntimeErrorTracking(errorObservable) {
|
|
|
93
96
|
stack: error.stack,
|
|
94
97
|
type: error.type,
|
|
95
98
|
source: _errorTools.ErrorSource.SOURCE,
|
|
96
|
-
startClocks: (0, _tools.clocksNow)()
|
|
99
|
+
startClocks: (0, _tools.clocksNow)(),
|
|
100
|
+
handling: _enums.ErrorHandling.UNHANDLED
|
|
97
101
|
});
|
|
98
102
|
};
|
|
99
103
|
|
package/cjs/helper/enums.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.RequestType = exports.RumEventType = exports.ActionType = exports.ResourceType = exports.DOM_EVENT = void 0;
|
|
6
|
+
exports.ErrorHandling = exports.TraceType = exports.RequestType = exports.RumEventType = exports.ActionType = exports.ResourceType = exports.DOM_EVENT = void 0;
|
|
7
7
|
var DOM_EVENT = {
|
|
8
8
|
BEFORE_UNLOAD: 'beforeunload',
|
|
9
9
|
CLICK: 'click',
|
|
@@ -53,4 +53,18 @@ var RequestType = {
|
|
|
53
53
|
FETCH: ResourceType.FETCH,
|
|
54
54
|
XHR: ResourceType.XHR
|
|
55
55
|
};
|
|
56
|
-
exports.RequestType = RequestType;
|
|
56
|
+
exports.RequestType = RequestType;
|
|
57
|
+
var TraceType = {
|
|
58
|
+
DDTRACE: 'ddtrace',
|
|
59
|
+
ZIPKIN_MULTI_HEADER: 'zipkin',
|
|
60
|
+
ZIPKIN_SINGLE_HEADER: 'zipkin_single_header',
|
|
61
|
+
W3C_TRACEPARENT: 'w3c_traceparent',
|
|
62
|
+
SKYWALKING_V3: 'skywalking_v3',
|
|
63
|
+
JAEGER: 'jaeger'
|
|
64
|
+
};
|
|
65
|
+
exports.TraceType = TraceType;
|
|
66
|
+
var ErrorHandling = {
|
|
67
|
+
HANDLED: 'handled',
|
|
68
|
+
UNHANDLED: 'unhandled'
|
|
69
|
+
};
|
|
70
|
+
exports.ErrorHandling = ErrorHandling;
|
package/cjs/helper/errorTools.js
CHANGED
|
@@ -4,12 +4,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.formatUnknownError = formatUnknownError;
|
|
7
|
+
exports.createHandlingStack = createHandlingStack;
|
|
7
8
|
exports.toStackTraceString = toStackTraceString;
|
|
8
9
|
exports.formatErrorMessage = formatErrorMessage;
|
|
9
10
|
exports.ErrorSource = void 0;
|
|
10
11
|
|
|
11
12
|
var _tools = require("./tools");
|
|
12
13
|
|
|
14
|
+
var _tracekit = require("../tracekit");
|
|
15
|
+
|
|
13
16
|
var ErrorSource = {
|
|
14
17
|
AGENT: 'agent',
|
|
15
18
|
CONSOLE: 'console',
|
|
@@ -20,11 +23,12 @@ var ErrorSource = {
|
|
|
20
23
|
};
|
|
21
24
|
exports.ErrorSource = ErrorSource;
|
|
22
25
|
|
|
23
|
-
function formatUnknownError(stackTrace, errorObject, nonErrorPrefix) {
|
|
26
|
+
function formatUnknownError(stackTrace, errorObject, nonErrorPrefix, handlingStack) {
|
|
24
27
|
if (!stackTrace || stackTrace.message === undefined && !(errorObject instanceof Error)) {
|
|
25
28
|
return {
|
|
26
29
|
message: nonErrorPrefix + '' + JSON.stringify(errorObject),
|
|
27
30
|
stack: 'No stack, consider using an instance of Error',
|
|
31
|
+
handlingStack: handlingStack,
|
|
28
32
|
type: stackTrace && stackTrace.name
|
|
29
33
|
};
|
|
30
34
|
}
|
|
@@ -32,9 +36,43 @@ function formatUnknownError(stackTrace, errorObject, nonErrorPrefix) {
|
|
|
32
36
|
return {
|
|
33
37
|
message: stackTrace.message || 'Empty message',
|
|
34
38
|
stack: toStackTraceString(stackTrace),
|
|
39
|
+
handlingStack: handlingStack,
|
|
35
40
|
type: stackTrace.name
|
|
36
41
|
};
|
|
37
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
Creates a stacktrace without SDK internal frames.
|
|
45
|
+
|
|
46
|
+
Constraints:
|
|
47
|
+
- Has to be called at the utmost position of the call stack.
|
|
48
|
+
- No internal monitoring should encapsulate the function, that is why we need to use callMonitored inside of it.
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
function createHandlingStack() {
|
|
53
|
+
/**
|
|
54
|
+
* Skip the two internal frames:
|
|
55
|
+
* - SDK API (console.error, ...)
|
|
56
|
+
* - this function
|
|
57
|
+
* in order to keep only the user calls
|
|
58
|
+
*/
|
|
59
|
+
var internalFramesToSkip = 2;
|
|
60
|
+
var error = new Error();
|
|
61
|
+
var formattedStack; // IE needs to throw the error to fill in the stack trace
|
|
62
|
+
|
|
63
|
+
if (!error.stack) {
|
|
64
|
+
try {
|
|
65
|
+
throw error;
|
|
66
|
+
} catch (e) {
|
|
67
|
+
(0, _tools.noop)();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
var stackTrace = (0, _tracekit.computeStackTrace)(error);
|
|
72
|
+
stackTrace.stack = stackTrace.stack.slice(internalFramesToSkip);
|
|
73
|
+
formattedStack = toStackTraceString(stackTrace);
|
|
74
|
+
return formattedStack;
|
|
75
|
+
}
|
|
38
76
|
|
|
39
77
|
function toStackTraceString(stack) {
|
|
40
78
|
var result = stack.name || 'Error' + ': ' + stack.message;
|
package/cjs/helper/tools.js
CHANGED
|
@@ -5,6 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.UUID = UUID;
|
|
7
7
|
exports.replaceNumberCharByPath = replaceNumberCharByPath;
|
|
8
|
+
exports.getType = getType;
|
|
9
|
+
exports.mergeInto = mergeInto;
|
|
10
|
+
exports.deepClone = deepClone;
|
|
8
11
|
exports.getStatusGroup = getStatusGroup;
|
|
9
12
|
exports.jsonStringify = jsonStringify;
|
|
10
13
|
exports.noop = noop;
|
|
@@ -803,8 +806,8 @@ var urlParse = function urlParse(para) {
|
|
|
803
806
|
|
|
804
807
|
URLParser.prototype.getUrl = function () {
|
|
805
808
|
var url = '';
|
|
806
|
-
url += this._values.Origin;
|
|
807
|
-
|
|
809
|
+
url += this._values.Origin; // url += this._values.Port ? ':' + this._values.Port : ''
|
|
810
|
+
|
|
808
811
|
url += this._values.Path;
|
|
809
812
|
url += this._values.QueryString ? '?' + this._values.QueryString : '';
|
|
810
813
|
return url;
|
|
@@ -825,8 +828,11 @@ var urlParse = function urlParse(para) {
|
|
|
825
828
|
}
|
|
826
829
|
}
|
|
827
830
|
|
|
831
|
+
this._values['Path'] = this._values['Path'] || '/';
|
|
828
832
|
this._values['Hostname'] = this._values['Host'].replace(/:\d+$/, '');
|
|
829
|
-
this._values['Origin'] = this._values['Protocol'] + '://' + this._values['Hostname'];
|
|
833
|
+
this._values['Origin'] = this._values['Protocol'] + '://' + this._values['Hostname'] + (this._values.Port ? ':' + this._values.Port : ''); // this._values['Hostname'] = this._values['Host'].replace(/:\d+$/, '')
|
|
834
|
+
// this._values['Origin'] =
|
|
835
|
+
// this._values['Protocol'] + '://' + this._values['Hostname']
|
|
830
836
|
};
|
|
831
837
|
|
|
832
838
|
return new URLParser(para);
|
|
@@ -1309,6 +1315,113 @@ var getURLSearchParams = function getURLSearchParams(queryString) {
|
|
|
1309
1315
|
|
|
1310
1316
|
exports.getURLSearchParams = getURLSearchParams;
|
|
1311
1317
|
|
|
1318
|
+
function createCircularReferenceChecker() {
|
|
1319
|
+
if (typeof WeakSet !== 'undefined') {
|
|
1320
|
+
var set = new WeakSet();
|
|
1321
|
+
return {
|
|
1322
|
+
hasAlreadyBeenSeen: function hasAlreadyBeenSeen(value) {
|
|
1323
|
+
var has = set.has(value);
|
|
1324
|
+
|
|
1325
|
+
if (!has) {
|
|
1326
|
+
set.add(value);
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
return has;
|
|
1330
|
+
}
|
|
1331
|
+
};
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
var array = [];
|
|
1335
|
+
return {
|
|
1336
|
+
hasAlreadyBeenSeen: function hasAlreadyBeenSeen(value) {
|
|
1337
|
+
var has = array.indexOf(value) >= 0;
|
|
1338
|
+
|
|
1339
|
+
if (!has) {
|
|
1340
|
+
array.push(value);
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
return has;
|
|
1344
|
+
}
|
|
1345
|
+
};
|
|
1346
|
+
}
|
|
1347
|
+
/**
|
|
1348
|
+
* Similar to `typeof`, but distinguish plain objects from `null` and arrays
|
|
1349
|
+
*/
|
|
1350
|
+
|
|
1351
|
+
|
|
1352
|
+
function getType(value) {
|
|
1353
|
+
if (value === null) {
|
|
1354
|
+
return 'null';
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
if (Array.isArray(value)) {
|
|
1358
|
+
return 'array';
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
return _typeof(value);
|
|
1362
|
+
}
|
|
1363
|
+
/**
|
|
1364
|
+
* Iterate over source and affect its sub values into destination, recursively.
|
|
1365
|
+
* If the source and destination can't be merged, return source.
|
|
1366
|
+
*/
|
|
1367
|
+
|
|
1368
|
+
|
|
1369
|
+
function mergeInto(destination, source, circularReferenceChecker) {
|
|
1370
|
+
// ignore the source if it is undefined
|
|
1371
|
+
if (typeof circularReferenceChecker === 'undefined') {
|
|
1372
|
+
circularReferenceChecker = createCircularReferenceChecker();
|
|
1373
|
+
}
|
|
1374
|
+
|
|
1375
|
+
if (source === undefined) {
|
|
1376
|
+
return destination;
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
if (_typeof(source) !== 'object' || source === null) {
|
|
1380
|
+
// primitive values - just return source
|
|
1381
|
+
return source;
|
|
1382
|
+
} else if (source instanceof Date) {
|
|
1383
|
+
return new Date(source.getTime());
|
|
1384
|
+
} else if (source instanceof RegExp) {
|
|
1385
|
+
var flags = source.flags || // old browsers compatibility
|
|
1386
|
+
[source.global ? 'g' : '', source.ignoreCase ? 'i' : '', source.multiline ? 'm' : '', source.sticky ? 'y' : '', source.unicode ? 'u' : ''].join('');
|
|
1387
|
+
return new RegExp(source.source, flags);
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
if (circularReferenceChecker.hasAlreadyBeenSeen(source)) {
|
|
1391
|
+
// remove circular references
|
|
1392
|
+
return undefined;
|
|
1393
|
+
} else if (Array.isArray(source)) {
|
|
1394
|
+
var merged = Array.isArray(destination) ? destination : [];
|
|
1395
|
+
|
|
1396
|
+
for (var i = 0; i < source.length; ++i) {
|
|
1397
|
+
merged[i] = mergeInto(merged[i], source[i], circularReferenceChecker);
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1400
|
+
return merged;
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
var merged = getType(destination) === 'object' ? destination : {};
|
|
1404
|
+
|
|
1405
|
+
for (var key in source) {
|
|
1406
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
1407
|
+
merged[key] = mergeInto(merged[key], source[key], circularReferenceChecker);
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
return merged;
|
|
1412
|
+
}
|
|
1413
|
+
/**
|
|
1414
|
+
* A simplistic implementation of a deep clone algorithm.
|
|
1415
|
+
* Caveats:
|
|
1416
|
+
* - It doesn't maintain prototype chains - don't use with instances of custom classes.
|
|
1417
|
+
* - It doesn't handle Map and Set
|
|
1418
|
+
*/
|
|
1419
|
+
|
|
1420
|
+
|
|
1421
|
+
function deepClone(value) {
|
|
1422
|
+
return mergeInto(undefined, value);
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1312
1425
|
var _URL = function _URL(url) {
|
|
1313
1426
|
var result = {};
|
|
1314
1427
|
var basicProps = ['hash', 'host', 'hostname', 'href', 'origin', 'password', 'pathname', 'port', 'protocol', 'search', 'username'];
|
package/cjs/sessionManagement.js
CHANGED
|
@@ -53,6 +53,7 @@ function startSessionManagement(options, productKey, computeSessionState) {
|
|
|
53
53
|
var currentSession = retrieveActiveSession(sessionCookie);
|
|
54
54
|
var currentSessionId = currentSession.id;
|
|
55
55
|
var expandOrRenewSession = (0, _tools.throttle)(function () {
|
|
56
|
+
sessionCookie.clearCache();
|
|
56
57
|
var session = retrieveActiveSession(sessionCookie);
|
|
57
58
|
var state = computeSessionState(session[productKey]);
|
|
58
59
|
session[productKey] = state.trackingType;
|
|
@@ -72,6 +73,7 @@ function startSessionManagement(options, productKey, computeSessionState) {
|
|
|
72
73
|
}, _cookie.COOKIE_ACCESS_DELAY);
|
|
73
74
|
|
|
74
75
|
var expandSession = function expandSession() {
|
|
76
|
+
sessionCookie.clearCache();
|
|
75
77
|
var session = retrieveActiveSession(sessionCookie);
|
|
76
78
|
persistSession(session, sessionCookie);
|
|
77
79
|
};
|
package/cjs/transport.js
CHANGED
|
@@ -47,7 +47,10 @@ var HttpRequest = httpRequest;
|
|
|
47
47
|
exports.HttpRequest = HttpRequest;
|
|
48
48
|
|
|
49
49
|
var processedMessageByDataMap = function processedMessageByDataMap(message) {
|
|
50
|
-
if (!message || !message.type) return
|
|
50
|
+
if (!message || !message.type) return {
|
|
51
|
+
rowStr: '',
|
|
52
|
+
rowData: undefined
|
|
53
|
+
};
|
|
51
54
|
var rowData = {
|
|
52
55
|
tags: {},
|
|
53
56
|
fields: {}
|
package/esm/configuration.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ONE_KILO_BYTE, ONE_SECOND, extend2Lev, isArray, includes, isFunction, isBoolean } from './helper/tools';
|
|
1
|
+
import { ONE_KILO_BYTE, ONE_SECOND, extend2Lev, isArray, includes, isFunction, isBoolean, values } from './helper/tools';
|
|
2
2
|
import { getCurrentSite } from './cookie';
|
|
3
3
|
import { haveSameOrigin } from './helper/urlPolyfill';
|
|
4
|
+
import { TraceType } from './helper/enums';
|
|
4
5
|
var TRIM_REGIX = /^\s+|\s+$/g;
|
|
5
6
|
export var DEFAULT_CONFIGURATION = {
|
|
6
7
|
resourceSampleRate: 100,
|
|
@@ -26,10 +27,16 @@ export var DEFAULT_CONFIGURATION = {
|
|
|
26
27
|
batchBytesLimit: 16 * ONE_KILO_BYTE,
|
|
27
28
|
datakitUrl: '',
|
|
28
29
|
logsEndpoint: '',
|
|
30
|
+
traceType: TraceType.DDTRACE,
|
|
31
|
+
traceId128Bit: false,
|
|
29
32
|
trackInteractions: false,
|
|
30
33
|
//是否开启交互action收集
|
|
31
34
|
allowedDDTracingOrigins: [],
|
|
32
|
-
|
|
35
|
+
//废弃
|
|
36
|
+
allowedTracingOrigins: [],
|
|
37
|
+
// 新增
|
|
38
|
+
isServiceSampling: false,
|
|
39
|
+
// 是否不抛弃采样是数据, 采用在服务端菜样的方式
|
|
33
40
|
beforeSend: function beforeSend(event) {},
|
|
34
41
|
isServerError: function isServerError(request) {
|
|
35
42
|
return false;
|
|
@@ -69,6 +76,7 @@ export function commonInit(userConfiguration, buildEnv) {
|
|
|
69
76
|
applicationId: userConfiguration.applicationId,
|
|
70
77
|
env: userConfiguration.env || '',
|
|
71
78
|
version: userConfiguration.version || '',
|
|
79
|
+
service: userConfiguration.service || 'browser',
|
|
72
80
|
sdkVersion: buildEnv.sdkVersion,
|
|
73
81
|
sdkName: buildEnv.sdkName,
|
|
74
82
|
datakitUrl: getDatakitUrl(userConfiguration.datakitUrl || userConfiguration.datakitOrigin),
|
|
@@ -80,7 +88,11 @@ export function commonInit(userConfiguration, buildEnv) {
|
|
|
80
88
|
};
|
|
81
89
|
|
|
82
90
|
if ('allowedDDTracingOrigins' in userConfiguration) {
|
|
83
|
-
transportConfiguration.
|
|
91
|
+
transportConfiguration.allowedTracingOrigins = userConfiguration.allowedDDTracingOrigins;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if ('allowedTracingOrigins' in userConfiguration) {
|
|
95
|
+
transportConfiguration.allowedTracingOrigins = userConfiguration.allowedTracingOrigins;
|
|
84
96
|
}
|
|
85
97
|
|
|
86
98
|
if ('sampleRate' in userConfiguration) {
|
|
@@ -99,9 +111,26 @@ export function commonInit(userConfiguration, buildEnv) {
|
|
|
99
111
|
transportConfiguration.isServerError = userConfiguration.isServerError;
|
|
100
112
|
}
|
|
101
113
|
|
|
114
|
+
if ('traceId128Bit' in userConfiguration) {
|
|
115
|
+
transportConfiguration.traceId128Bit = !!userConfiguration.traceId128Bit;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if ('traceType' in userConfiguration && hasTraceType(userConfiguration.traceType)) {
|
|
119
|
+
transportConfiguration.traceType = userConfiguration.traceType;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if ('isServiceSampling' in userConfiguration && isBoolean(userConfiguration.isServiceSampling)) {
|
|
123
|
+
transportConfiguration.isServiceSampling = userConfiguration.isServiceSampling;
|
|
124
|
+
}
|
|
125
|
+
|
|
102
126
|
return extend2Lev({}, DEFAULT_CONFIGURATION, transportConfiguration);
|
|
103
127
|
}
|
|
104
128
|
|
|
129
|
+
function hasTraceType(traceType) {
|
|
130
|
+
if (traceType && values(TraceType).indexOf(traceType) > -1) return true;
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
|
|
105
134
|
function mustUseSecureCookie(userConfiguration) {
|
|
106
135
|
return !!userConfiguration.useSecureSessionCookie || !!userConfiguration.useCrossSiteSessionCookie;
|
|
107
136
|
}
|
package/esm/cookie.js
CHANGED
package/esm/dataMap.js
CHANGED
|
@@ -10,6 +10,7 @@ export var commonTags = {
|
|
|
10
10
|
user_name: 'user.name',
|
|
11
11
|
session_id: 'session.id',
|
|
12
12
|
session_type: 'session.type',
|
|
13
|
+
session_sampling: 'session.is_sampling',
|
|
13
14
|
is_signin: 'user.is_signin',
|
|
14
15
|
os: 'device.os',
|
|
15
16
|
os_version: 'device.os_version',
|
|
@@ -92,6 +93,7 @@ export var dataMap = {
|
|
|
92
93
|
tags: {
|
|
93
94
|
error_source: 'error.source',
|
|
94
95
|
error_type: 'error.type',
|
|
96
|
+
error_handling: 'error.handling',
|
|
95
97
|
resource_url: 'error.resource.url',
|
|
96
98
|
resource_url_host: 'error.resource.url_host',
|
|
97
99
|
resource_url_path: 'error.resource.url_path',
|
package/esm/errorCollection.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { toArray, jsonStringify, find, clocksNow, map, extend } from './helper/tools';
|
|
2
|
-
import { ErrorSource, formatUnknownError, toStackTraceString, formatErrorMessage } from './helper/errorTools';
|
|
2
|
+
import { ErrorSource, formatUnknownError, toStackTraceString, formatErrorMessage, createHandlingStack } from './helper/errorTools';
|
|
3
3
|
import { computeStackTrace, subscribe, unsubscribe } from './tracekit';
|
|
4
4
|
import { Observable } from './helper/observable';
|
|
5
5
|
import { isIntakeRequest } from './configuration';
|
|
6
|
-
import { RequestType } from './helper/enums';
|
|
6
|
+
import { RequestType, ErrorHandling } from './helper/enums';
|
|
7
7
|
import { resetXhrProxy, startXhrProxy } from './xhrProxy';
|
|
8
8
|
import { resetFetchProxy, startFetchProxy } from './fetchProxy';
|
|
9
9
|
var errorObservable;
|
|
@@ -23,14 +23,16 @@ export function startConsoleTracking(errorObservable) {
|
|
|
23
23
|
|
|
24
24
|
console.error = function () {
|
|
25
25
|
originalConsoleError.apply(console, arguments);
|
|
26
|
-
|
|
26
|
+
var handlingStack = createHandlingStack();
|
|
27
|
+
errorObservable.notify(extend({}, buildErrorFromParams(toArray(arguments), handlingStack), {
|
|
27
28
|
source: ErrorSource.CONSOLE,
|
|
28
|
-
startClocks: clocksNow()
|
|
29
|
+
startClocks: clocksNow(),
|
|
30
|
+
handling: ErrorHandling.HANDLED
|
|
29
31
|
}));
|
|
30
32
|
};
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
function buildErrorFromParams(params) {
|
|
35
|
+
function buildErrorFromParams(params, handlingStack) {
|
|
34
36
|
var firstErrorParam = find(params, function (param) {
|
|
35
37
|
return param instanceof Error;
|
|
36
38
|
});
|
|
@@ -40,7 +42,8 @@ function buildErrorFromParams(params) {
|
|
|
40
42
|
}).join(' ');
|
|
41
43
|
return {
|
|
42
44
|
message: message,
|
|
43
|
-
stack: firstErrorParam ? toStackTraceString(computeStackTrace(firstErrorParam)) : undefined
|
|
45
|
+
stack: firstErrorParam ? toStackTraceString(computeStackTrace(firstErrorParam)) : undefined,
|
|
46
|
+
handlingStack: handlingStack
|
|
44
47
|
};
|
|
45
48
|
}
|
|
46
49
|
|
|
@@ -69,7 +72,8 @@ export function startRuntimeErrorTracking(errorObservable) {
|
|
|
69
72
|
stack: error.stack,
|
|
70
73
|
type: error.type,
|
|
71
74
|
source: ErrorSource.SOURCE,
|
|
72
|
-
startClocks: clocksNow()
|
|
75
|
+
startClocks: clocksNow(),
|
|
76
|
+
handling: ErrorHandling.UNHANDLED
|
|
73
77
|
});
|
|
74
78
|
};
|
|
75
79
|
|
package/esm/helper/enums.js
CHANGED
|
@@ -42,4 +42,16 @@ export var RumEventType = {
|
|
|
42
42
|
export var RequestType = {
|
|
43
43
|
FETCH: ResourceType.FETCH,
|
|
44
44
|
XHR: ResourceType.XHR
|
|
45
|
+
};
|
|
46
|
+
export var TraceType = {
|
|
47
|
+
DDTRACE: 'ddtrace',
|
|
48
|
+
ZIPKIN_MULTI_HEADER: 'zipkin',
|
|
49
|
+
ZIPKIN_SINGLE_HEADER: 'zipkin_single_header',
|
|
50
|
+
W3C_TRACEPARENT: 'w3c_traceparent',
|
|
51
|
+
SKYWALKING_V3: 'skywalking_v3',
|
|
52
|
+
JAEGER: 'jaeger'
|
|
53
|
+
};
|
|
54
|
+
export var ErrorHandling = {
|
|
55
|
+
HANDLED: 'handled',
|
|
56
|
+
UNHANDLED: 'unhandled'
|
|
45
57
|
};
|
package/esm/helper/errorTools.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { each } from './tools';
|
|
1
|
+
import { each, noop } from './tools';
|
|
2
|
+
import { computeStackTrace } from '../tracekit';
|
|
2
3
|
export var ErrorSource = {
|
|
3
4
|
AGENT: 'agent',
|
|
4
5
|
CONSOLE: 'console',
|
|
@@ -7,11 +8,12 @@ export var ErrorSource = {
|
|
|
7
8
|
LOGGER: 'logger',
|
|
8
9
|
CUSTOM: 'custom'
|
|
9
10
|
};
|
|
10
|
-
export function formatUnknownError(stackTrace, errorObject, nonErrorPrefix) {
|
|
11
|
+
export function formatUnknownError(stackTrace, errorObject, nonErrorPrefix, handlingStack) {
|
|
11
12
|
if (!stackTrace || stackTrace.message === undefined && !(errorObject instanceof Error)) {
|
|
12
13
|
return {
|
|
13
14
|
message: nonErrorPrefix + '' + JSON.stringify(errorObject),
|
|
14
15
|
stack: 'No stack, consider using an instance of Error',
|
|
16
|
+
handlingStack: handlingStack,
|
|
15
17
|
type: stackTrace && stackTrace.name
|
|
16
18
|
};
|
|
17
19
|
}
|
|
@@ -19,9 +21,42 @@ export function formatUnknownError(stackTrace, errorObject, nonErrorPrefix) {
|
|
|
19
21
|
return {
|
|
20
22
|
message: stackTrace.message || 'Empty message',
|
|
21
23
|
stack: toStackTraceString(stackTrace),
|
|
24
|
+
handlingStack: handlingStack,
|
|
22
25
|
type: stackTrace.name
|
|
23
26
|
};
|
|
24
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
Creates a stacktrace without SDK internal frames.
|
|
30
|
+
|
|
31
|
+
Constraints:
|
|
32
|
+
- Has to be called at the utmost position of the call stack.
|
|
33
|
+
- No internal monitoring should encapsulate the function, that is why we need to use callMonitored inside of it.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
export function createHandlingStack() {
|
|
37
|
+
/**
|
|
38
|
+
* Skip the two internal frames:
|
|
39
|
+
* - SDK API (console.error, ...)
|
|
40
|
+
* - this function
|
|
41
|
+
* in order to keep only the user calls
|
|
42
|
+
*/
|
|
43
|
+
var internalFramesToSkip = 2;
|
|
44
|
+
var error = new Error();
|
|
45
|
+
var formattedStack; // IE needs to throw the error to fill in the stack trace
|
|
46
|
+
|
|
47
|
+
if (!error.stack) {
|
|
48
|
+
try {
|
|
49
|
+
throw error;
|
|
50
|
+
} catch (e) {
|
|
51
|
+
noop();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
var stackTrace = computeStackTrace(error);
|
|
56
|
+
stackTrace.stack = stackTrace.stack.slice(internalFramesToSkip);
|
|
57
|
+
formattedStack = toStackTraceString(stackTrace);
|
|
58
|
+
return formattedStack;
|
|
59
|
+
}
|
|
25
60
|
export function toStackTraceString(stack) {
|
|
26
61
|
var result = stack.name || 'Error' + ': ' + stack.message;
|
|
27
62
|
each(stack.stack, function (frame) {
|
package/esm/helper/tools.js
CHANGED
|
@@ -625,8 +625,8 @@ export var urlParse = function urlParse(para) {
|
|
|
625
625
|
|
|
626
626
|
URLParser.prototype.getUrl = function () {
|
|
627
627
|
var url = '';
|
|
628
|
-
url += this._values.Origin;
|
|
629
|
-
|
|
628
|
+
url += this._values.Origin; // url += this._values.Port ? ':' + this._values.Port : ''
|
|
629
|
+
|
|
630
630
|
url += this._values.Path;
|
|
631
631
|
url += this._values.QueryString ? '?' + this._values.QueryString : '';
|
|
632
632
|
return url;
|
|
@@ -647,8 +647,11 @@ export var urlParse = function urlParse(para) {
|
|
|
647
647
|
}
|
|
648
648
|
}
|
|
649
649
|
|
|
650
|
+
this._values['Path'] = this._values['Path'] || '/';
|
|
650
651
|
this._values['Hostname'] = this._values['Host'].replace(/:\d+$/, '');
|
|
651
|
-
this._values['Origin'] = this._values['Protocol'] + '://' + this._values['Hostname'];
|
|
652
|
+
this._values['Origin'] = this._values['Protocol'] + '://' + this._values['Hostname'] + (this._values.Port ? ':' + this._values.Port : ''); // this._values['Hostname'] = this._values['Host'].replace(/:\d+$/, '')
|
|
653
|
+
// this._values['Origin'] =
|
|
654
|
+
// this._values['Protocol'] + '://' + this._values['Hostname']
|
|
652
655
|
};
|
|
653
656
|
|
|
654
657
|
return new URLParser(para);
|
|
@@ -1095,6 +1098,113 @@ export var getURLSearchParams = function getURLSearchParams(queryString) {
|
|
|
1095
1098
|
|
|
1096
1099
|
return args;
|
|
1097
1100
|
};
|
|
1101
|
+
|
|
1102
|
+
function createCircularReferenceChecker() {
|
|
1103
|
+
if (typeof WeakSet !== 'undefined') {
|
|
1104
|
+
var set = new WeakSet();
|
|
1105
|
+
return {
|
|
1106
|
+
hasAlreadyBeenSeen(value) {
|
|
1107
|
+
var has = set.has(value);
|
|
1108
|
+
|
|
1109
|
+
if (!has) {
|
|
1110
|
+
set.add(value);
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
return has;
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
};
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
var array = [];
|
|
1120
|
+
return {
|
|
1121
|
+
hasAlreadyBeenSeen(value) {
|
|
1122
|
+
var has = array.indexOf(value) >= 0;
|
|
1123
|
+
|
|
1124
|
+
if (!has) {
|
|
1125
|
+
array.push(value);
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
return has;
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
};
|
|
1132
|
+
}
|
|
1133
|
+
/**
|
|
1134
|
+
* Similar to `typeof`, but distinguish plain objects from `null` and arrays
|
|
1135
|
+
*/
|
|
1136
|
+
|
|
1137
|
+
|
|
1138
|
+
export function getType(value) {
|
|
1139
|
+
if (value === null) {
|
|
1140
|
+
return 'null';
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
if (Array.isArray(value)) {
|
|
1144
|
+
return 'array';
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
return typeof value;
|
|
1148
|
+
}
|
|
1149
|
+
/**
|
|
1150
|
+
* Iterate over source and affect its sub values into destination, recursively.
|
|
1151
|
+
* If the source and destination can't be merged, return source.
|
|
1152
|
+
*/
|
|
1153
|
+
|
|
1154
|
+
export function mergeInto(destination, source, circularReferenceChecker) {
|
|
1155
|
+
// ignore the source if it is undefined
|
|
1156
|
+
if (typeof circularReferenceChecker === 'undefined') {
|
|
1157
|
+
circularReferenceChecker = createCircularReferenceChecker();
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
if (source === undefined) {
|
|
1161
|
+
return destination;
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
if (typeof source !== 'object' || source === null) {
|
|
1165
|
+
// primitive values - just return source
|
|
1166
|
+
return source;
|
|
1167
|
+
} else if (source instanceof Date) {
|
|
1168
|
+
return new Date(source.getTime());
|
|
1169
|
+
} else if (source instanceof RegExp) {
|
|
1170
|
+
var flags = source.flags || // old browsers compatibility
|
|
1171
|
+
[source.global ? 'g' : '', source.ignoreCase ? 'i' : '', source.multiline ? 'm' : '', source.sticky ? 'y' : '', source.unicode ? 'u' : ''].join('');
|
|
1172
|
+
return new RegExp(source.source, flags);
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
if (circularReferenceChecker.hasAlreadyBeenSeen(source)) {
|
|
1176
|
+
// remove circular references
|
|
1177
|
+
return undefined;
|
|
1178
|
+
} else if (Array.isArray(source)) {
|
|
1179
|
+
var merged = Array.isArray(destination) ? destination : [];
|
|
1180
|
+
|
|
1181
|
+
for (var i = 0; i < source.length; ++i) {
|
|
1182
|
+
merged[i] = mergeInto(merged[i], source[i], circularReferenceChecker);
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
return merged;
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
var merged = getType(destination) === 'object' ? destination : {};
|
|
1189
|
+
|
|
1190
|
+
for (var key in source) {
|
|
1191
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
1192
|
+
merged[key] = mergeInto(merged[key], source[key], circularReferenceChecker);
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
return merged;
|
|
1197
|
+
}
|
|
1198
|
+
/**
|
|
1199
|
+
* A simplistic implementation of a deep clone algorithm.
|
|
1200
|
+
* Caveats:
|
|
1201
|
+
* - It doesn't maintain prototype chains - don't use with instances of custom classes.
|
|
1202
|
+
* - It doesn't handle Map and Set
|
|
1203
|
+
*/
|
|
1204
|
+
|
|
1205
|
+
export function deepClone(value) {
|
|
1206
|
+
return mergeInto(undefined, value);
|
|
1207
|
+
}
|
|
1098
1208
|
export var _URL = function _URL(url) {
|
|
1099
1209
|
var result = {};
|
|
1100
1210
|
var basicProps = ['hash', 'host', 'hostname', 'href', 'origin', 'password', 'pathname', 'port', 'protocol', 'search', 'username'];
|
package/esm/sessionManagement.js
CHANGED
|
@@ -31,6 +31,7 @@ export function startSessionManagement(options, productKey, computeSessionState)
|
|
|
31
31
|
var currentSession = retrieveActiveSession(sessionCookie);
|
|
32
32
|
var currentSessionId = currentSession.id;
|
|
33
33
|
var expandOrRenewSession = throttle(function () {
|
|
34
|
+
sessionCookie.clearCache();
|
|
34
35
|
var session = retrieveActiveSession(sessionCookie);
|
|
35
36
|
var state = computeSessionState(session[productKey]);
|
|
36
37
|
session[productKey] = state.trackingType;
|
|
@@ -50,6 +51,7 @@ export function startSessionManagement(options, productKey, computeSessionState)
|
|
|
50
51
|
}, COOKIE_ACCESS_DELAY);
|
|
51
52
|
|
|
52
53
|
var expandSession = function expandSession() {
|
|
54
|
+
sessionCookie.clearCache();
|
|
53
55
|
var session = retrieveActiveSession(sessionCookie);
|
|
54
56
|
persistSession(session, sessionCookie);
|
|
55
57
|
};
|
package/esm/transport.js
CHANGED
|
@@ -35,7 +35,10 @@ httpRequest.prototype = {
|
|
|
35
35
|
};
|
|
36
36
|
export var HttpRequest = httpRequest;
|
|
37
37
|
export var processedMessageByDataMap = function processedMessageByDataMap(message) {
|
|
38
|
-
if (!message || !message.type) return
|
|
38
|
+
if (!message || !message.type) return {
|
|
39
|
+
rowStr: '',
|
|
40
|
+
rowData: undefined
|
|
41
|
+
};
|
|
39
42
|
var rowData = {
|
|
40
43
|
tags: {},
|
|
41
44
|
fields: {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudcare/browser-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.18",
|
|
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": "677c6f4023801b95eada2bacf237290848ddfb08"
|
|
24
24
|
}
|
package/src/configuration.js
CHANGED
|
@@ -5,10 +5,12 @@ import {
|
|
|
5
5
|
isArray,
|
|
6
6
|
includes,
|
|
7
7
|
isFunction,
|
|
8
|
-
isBoolean
|
|
8
|
+
isBoolean,
|
|
9
|
+
values
|
|
9
10
|
} from './helper/tools'
|
|
10
11
|
import { getCurrentSite } from './cookie'
|
|
11
12
|
import { haveSameOrigin } from './helper/urlPolyfill'
|
|
13
|
+
import { TraceType } from './helper/enums'
|
|
12
14
|
var TRIM_REGIX = /^\s+|\s+$/g
|
|
13
15
|
export var DEFAULT_CONFIGURATION = {
|
|
14
16
|
resourceSampleRate: 100,
|
|
@@ -32,8 +34,12 @@ export var DEFAULT_CONFIGURATION = {
|
|
|
32
34
|
batchBytesLimit: 16 * ONE_KILO_BYTE,
|
|
33
35
|
datakitUrl: '',
|
|
34
36
|
logsEndpoint: '',
|
|
37
|
+
traceType: TraceType.DDTRACE,
|
|
38
|
+
traceId128Bit: false,
|
|
35
39
|
trackInteractions: false, //是否开启交互action收集
|
|
36
|
-
allowedDDTracingOrigins: [],
|
|
40
|
+
allowedDDTracingOrigins: [], //废弃
|
|
41
|
+
allowedTracingOrigins:[], // 新增
|
|
42
|
+
isServiceSampling: false, // 是否不抛弃采样是数据, 采用在服务端菜样的方式
|
|
37
43
|
beforeSend: function (event) {},
|
|
38
44
|
isServerError: function(request) {return false} // 判断请求是否为error 请求
|
|
39
45
|
}
|
|
@@ -71,6 +77,7 @@ export function commonInit(userConfiguration, buildEnv) {
|
|
|
71
77
|
applicationId: userConfiguration.applicationId,
|
|
72
78
|
env: userConfiguration.env || '',
|
|
73
79
|
version: userConfiguration.version || '',
|
|
80
|
+
service: userConfiguration.service || 'browser',
|
|
74
81
|
sdkVersion: buildEnv.sdkVersion,
|
|
75
82
|
sdkName: buildEnv.sdkName,
|
|
76
83
|
datakitUrl: getDatakitUrl(
|
|
@@ -81,10 +88,12 @@ export function commonInit(userConfiguration, buildEnv) {
|
|
|
81
88
|
cookieOptions: buildCookieOptions(userConfiguration)
|
|
82
89
|
}
|
|
83
90
|
if ('allowedDDTracingOrigins' in userConfiguration) {
|
|
84
|
-
transportConfiguration.
|
|
91
|
+
transportConfiguration.allowedTracingOrigins =
|
|
85
92
|
userConfiguration.allowedDDTracingOrigins
|
|
86
93
|
}
|
|
87
|
-
|
|
94
|
+
if ('allowedTracingOrigins' in userConfiguration) {
|
|
95
|
+
transportConfiguration.allowedTracingOrigins = userConfiguration.allowedTracingOrigins
|
|
96
|
+
}
|
|
88
97
|
if ('sampleRate' in userConfiguration) {
|
|
89
98
|
transportConfiguration.sampleRate = userConfiguration.sampleRate
|
|
90
99
|
}
|
|
@@ -100,8 +109,21 @@ export function commonInit(userConfiguration, buildEnv) {
|
|
|
100
109
|
if ('isServerError' in userConfiguration && isFunction(userConfiguration.isServerError) && isBoolean(userConfiguration.isServerError())) {
|
|
101
110
|
transportConfiguration.isServerError = userConfiguration.isServerError
|
|
102
111
|
}
|
|
112
|
+
if ('traceId128Bit' in userConfiguration) {
|
|
113
|
+
transportConfiguration.traceId128Bit = !!userConfiguration.traceId128Bit
|
|
114
|
+
}
|
|
115
|
+
if ('traceType' in userConfiguration && hasTraceType(userConfiguration.traceType)) {
|
|
116
|
+
transportConfiguration.traceType = userConfiguration.traceType
|
|
117
|
+
}
|
|
118
|
+
if ('isServiceSampling' in userConfiguration && isBoolean(userConfiguration.isServiceSampling)) {
|
|
119
|
+
transportConfiguration.isServiceSampling = userConfiguration.isServiceSampling
|
|
120
|
+
}
|
|
103
121
|
return extend2Lev({}, DEFAULT_CONFIGURATION, transportConfiguration)
|
|
104
122
|
}
|
|
123
|
+
function hasTraceType(traceType) {
|
|
124
|
+
if (traceType && values(TraceType).indexOf(traceType) > -1) return true
|
|
125
|
+
return false
|
|
126
|
+
}
|
|
105
127
|
function mustUseSecureCookie(userConfiguration) {
|
|
106
128
|
return (
|
|
107
129
|
!!userConfiguration.useSecureSessionCookie ||
|
package/src/cookie.js
CHANGED
package/src/dataMap.js
CHANGED
|
@@ -10,6 +10,7 @@ export var commonTags = {
|
|
|
10
10
|
user_name: 'user.name',
|
|
11
11
|
session_id: 'session.id',
|
|
12
12
|
session_type: 'session.type',
|
|
13
|
+
session_sampling: 'session.is_sampling',
|
|
13
14
|
is_signin: 'user.is_signin',
|
|
14
15
|
os: 'device.os',
|
|
15
16
|
os_version: 'device.os_version',
|
|
@@ -92,6 +93,7 @@ export var dataMap = {
|
|
|
92
93
|
tags: {
|
|
93
94
|
error_source: 'error.source',
|
|
94
95
|
error_type: 'error.type',
|
|
96
|
+
error_handling: 'error.handling',
|
|
95
97
|
resource_url: 'error.resource.url',
|
|
96
98
|
resource_url_host: 'error.resource.url_host',
|
|
97
99
|
resource_url_path: 'error.resource.url_path',
|
package/src/errorCollection.js
CHANGED
|
@@ -10,12 +10,13 @@ import {
|
|
|
10
10
|
ErrorSource,
|
|
11
11
|
formatUnknownError,
|
|
12
12
|
toStackTraceString,
|
|
13
|
-
formatErrorMessage
|
|
13
|
+
formatErrorMessage,
|
|
14
|
+
createHandlingStack
|
|
14
15
|
} from './helper/errorTools'
|
|
15
16
|
import { computeStackTrace, subscribe, unsubscribe } from './tracekit'
|
|
16
17
|
import { Observable } from './helper/observable'
|
|
17
18
|
import { isIntakeRequest } from './configuration'
|
|
18
|
-
import { RequestType } from './helper/enums'
|
|
19
|
+
import { RequestType, ErrorHandling } from './helper/enums'
|
|
19
20
|
import { resetXhrProxy, startXhrProxy } from './xhrProxy'
|
|
20
21
|
import { resetFetchProxy, startFetchProxy } from './fetchProxy'
|
|
21
22
|
|
|
@@ -37,16 +38,18 @@ export function startConsoleTracking(errorObservable) {
|
|
|
37
38
|
originalConsoleError = console.error
|
|
38
39
|
console.error = function () {
|
|
39
40
|
originalConsoleError.apply(console, arguments)
|
|
41
|
+
const handlingStack = createHandlingStack()
|
|
40
42
|
errorObservable.notify(
|
|
41
|
-
extend({}, buildErrorFromParams(toArray(arguments)), {
|
|
43
|
+
extend({}, buildErrorFromParams(toArray(arguments), handlingStack), {
|
|
42
44
|
source: ErrorSource.CONSOLE,
|
|
43
|
-
startClocks: clocksNow()
|
|
45
|
+
startClocks: clocksNow(),
|
|
46
|
+
handling: ErrorHandling.HANDLED
|
|
44
47
|
})
|
|
45
48
|
)
|
|
46
49
|
}
|
|
47
50
|
}
|
|
48
51
|
|
|
49
|
-
function buildErrorFromParams(params) {
|
|
52
|
+
function buildErrorFromParams(params, handlingStack) {
|
|
50
53
|
var firstErrorParam = find(params, function (param) {
|
|
51
54
|
return param instanceof Error
|
|
52
55
|
})
|
|
@@ -58,7 +61,8 @@ function buildErrorFromParams(params) {
|
|
|
58
61
|
message: message,
|
|
59
62
|
stack: firstErrorParam
|
|
60
63
|
? toStackTraceString(computeStackTrace(firstErrorParam))
|
|
61
|
-
: undefined
|
|
64
|
+
: undefined,
|
|
65
|
+
handlingStack: handlingStack
|
|
62
66
|
}
|
|
63
67
|
}
|
|
64
68
|
|
|
@@ -86,7 +90,8 @@ export function startRuntimeErrorTracking(errorObservable) {
|
|
|
86
90
|
stack: error.stack,
|
|
87
91
|
type: error.type,
|
|
88
92
|
source: ErrorSource.SOURCE,
|
|
89
|
-
startClocks: clocksNow()
|
|
93
|
+
startClocks: clocksNow(),
|
|
94
|
+
handling: ErrorHandling.UNHANDLED
|
|
90
95
|
})
|
|
91
96
|
}
|
|
92
97
|
|
package/src/helper/enums.js
CHANGED
|
@@ -45,3 +45,16 @@ export var RequestType = {
|
|
|
45
45
|
FETCH: ResourceType.FETCH,
|
|
46
46
|
XHR: ResourceType.XHR
|
|
47
47
|
}
|
|
48
|
+
|
|
49
|
+
export var TraceType = {
|
|
50
|
+
DDTRACE: 'ddtrace',
|
|
51
|
+
ZIPKIN_MULTI_HEADER: 'zipkin',
|
|
52
|
+
ZIPKIN_SINGLE_HEADER: 'zipkin_single_header',
|
|
53
|
+
W3C_TRACEPARENT: 'w3c_traceparent',
|
|
54
|
+
SKYWALKING_V3: 'skywalking_v3',
|
|
55
|
+
JAEGER: 'jaeger',
|
|
56
|
+
}
|
|
57
|
+
export var ErrorHandling = {
|
|
58
|
+
HANDLED: 'handled',
|
|
59
|
+
UNHANDLED: 'unhandled',
|
|
60
|
+
}
|
package/src/helper/errorTools.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { each } from './tools'
|
|
1
|
+
import { each , noop} from './tools'
|
|
2
|
+
import { computeStackTrace} from '../tracekit'
|
|
3
|
+
|
|
2
4
|
export var ErrorSource = {
|
|
3
5
|
AGENT: 'agent',
|
|
4
6
|
CONSOLE: 'console',
|
|
@@ -7,7 +9,8 @@ export var ErrorSource = {
|
|
|
7
9
|
LOGGER: 'logger',
|
|
8
10
|
CUSTOM: 'custom'
|
|
9
11
|
}
|
|
10
|
-
|
|
12
|
+
|
|
13
|
+
export function formatUnknownError(stackTrace, errorObject, nonErrorPrefix,handlingStack) {
|
|
11
14
|
if (
|
|
12
15
|
!stackTrace ||
|
|
13
16
|
(stackTrace.message === undefined && !(errorObject instanceof Error))
|
|
@@ -15,16 +18,50 @@ export function formatUnknownError(stackTrace, errorObject, nonErrorPrefix) {
|
|
|
15
18
|
return {
|
|
16
19
|
message: nonErrorPrefix + '' + JSON.stringify(errorObject),
|
|
17
20
|
stack: 'No stack, consider using an instance of Error',
|
|
21
|
+
handlingStack:handlingStack,
|
|
18
22
|
type: stackTrace && stackTrace.name
|
|
19
23
|
}
|
|
20
24
|
}
|
|
21
25
|
return {
|
|
22
26
|
message: stackTrace.message || 'Empty message',
|
|
23
27
|
stack: toStackTraceString(stackTrace),
|
|
28
|
+
handlingStack:handlingStack,
|
|
24
29
|
type: stackTrace.name
|
|
25
30
|
}
|
|
26
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
Creates a stacktrace without SDK internal frames.
|
|
34
|
+
|
|
35
|
+
Constraints:
|
|
36
|
+
- Has to be called at the utmost position of the call stack.
|
|
37
|
+
- No internal monitoring should encapsulate the function, that is why we need to use callMonitored inside of it.
|
|
38
|
+
*/
|
|
39
|
+
export function createHandlingStack() {
|
|
40
|
+
/**
|
|
41
|
+
* Skip the two internal frames:
|
|
42
|
+
* - SDK API (console.error, ...)
|
|
43
|
+
* - this function
|
|
44
|
+
* in order to keep only the user calls
|
|
45
|
+
*/
|
|
46
|
+
const internalFramesToSkip = 2
|
|
47
|
+
const error = new Error()
|
|
48
|
+
let formattedStack
|
|
27
49
|
|
|
50
|
+
// IE needs to throw the error to fill in the stack trace
|
|
51
|
+
if (!error.stack) {
|
|
52
|
+
try {
|
|
53
|
+
throw error
|
|
54
|
+
} catch (e) {
|
|
55
|
+
noop()
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const stackTrace = computeStackTrace(error)
|
|
60
|
+
stackTrace.stack = stackTrace.stack.slice(internalFramesToSkip)
|
|
61
|
+
formattedStack = toStackTraceString(stackTrace)
|
|
62
|
+
|
|
63
|
+
return formattedStack
|
|
64
|
+
}
|
|
28
65
|
export function toStackTraceString(stack) {
|
|
29
66
|
var result = stack.name || 'Error' + ': ' + stack.message
|
|
30
67
|
each(stack.stack, function (frame) {
|
package/src/helper/tools.js
CHANGED
|
@@ -613,7 +613,7 @@ export var urlParse = function (para) {
|
|
|
613
613
|
URLParser.prototype.getUrl = function () {
|
|
614
614
|
var url = ''
|
|
615
615
|
url += this._values.Origin
|
|
616
|
-
url += this._values.Port ? ':' + this._values.Port : ''
|
|
616
|
+
// url += this._values.Port ? ':' + this._values.Port : ''
|
|
617
617
|
url += this._values.Path
|
|
618
618
|
url += this._values.QueryString ? '?' + this._values.QueryString : ''
|
|
619
619
|
return url
|
|
@@ -629,9 +629,13 @@ export var urlParse = function (para) {
|
|
|
629
629
|
this._values[c] = b[this._fields[c]]
|
|
630
630
|
}
|
|
631
631
|
}
|
|
632
|
-
this._values['
|
|
633
|
-
|
|
634
|
-
|
|
632
|
+
this._values['Path'] = this._values['Path'] || '/'
|
|
633
|
+
this._values['Hostname'] = this._values['Host'].replace(/:\d+$/, '')
|
|
634
|
+
this._values['Origin'] =
|
|
635
|
+
this._values['Protocol'] + '://' + this._values['Hostname'] + (this._values.Port ? ':' + this._values.Port : '')
|
|
636
|
+
// this._values['Hostname'] = this._values['Host'].replace(/:\d+$/, '')
|
|
637
|
+
// this._values['Origin'] =
|
|
638
|
+
// this._values['Protocol'] + '://' + this._values['Hostname']
|
|
635
639
|
}
|
|
636
640
|
return new URLParser(para)
|
|
637
641
|
}
|
|
@@ -1060,7 +1064,107 @@ export var getURLSearchParams = function (queryString) {
|
|
|
1060
1064
|
}
|
|
1061
1065
|
return args
|
|
1062
1066
|
}
|
|
1067
|
+
function createCircularReferenceChecker() {
|
|
1068
|
+
if (typeof WeakSet !== 'undefined') {
|
|
1069
|
+
var set = new WeakSet()
|
|
1070
|
+
return {
|
|
1071
|
+
hasAlreadyBeenSeen(value) {
|
|
1072
|
+
var has = set.has(value)
|
|
1073
|
+
if (!has) {
|
|
1074
|
+
set.add(value)
|
|
1075
|
+
}
|
|
1076
|
+
return has
|
|
1077
|
+
},
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
var array = []
|
|
1081
|
+
return {
|
|
1082
|
+
hasAlreadyBeenSeen(value) {
|
|
1083
|
+
var has = array.indexOf(value) >= 0
|
|
1084
|
+
if (!has) {
|
|
1085
|
+
array.push(value)
|
|
1086
|
+
}
|
|
1087
|
+
return has
|
|
1088
|
+
},
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
/**
|
|
1092
|
+
* Similar to `typeof`, but distinguish plain objects from `null` and arrays
|
|
1093
|
+
*/
|
|
1094
|
+
export function getType(value) {
|
|
1095
|
+
if (value === null) {
|
|
1096
|
+
return 'null'
|
|
1097
|
+
}
|
|
1098
|
+
if (Array.isArray(value)) {
|
|
1099
|
+
return 'array'
|
|
1100
|
+
}
|
|
1101
|
+
return typeof value
|
|
1102
|
+
}
|
|
1103
|
+
/**
|
|
1104
|
+
* Iterate over source and affect its sub values into destination, recursively.
|
|
1105
|
+
* If the source and destination can't be merged, return source.
|
|
1106
|
+
*/
|
|
1107
|
+
export function mergeInto(
|
|
1108
|
+
destination,
|
|
1109
|
+
source,
|
|
1110
|
+
circularReferenceChecker
|
|
1111
|
+
) {
|
|
1112
|
+
// ignore the source if it is undefined
|
|
1113
|
+
if (typeof circularReferenceChecker === 'undefined') {
|
|
1114
|
+
circularReferenceChecker = createCircularReferenceChecker()
|
|
1115
|
+
}
|
|
1116
|
+
if (source === undefined) {
|
|
1117
|
+
return destination
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
if (typeof source !== 'object' || source === null) {
|
|
1121
|
+
// primitive values - just return source
|
|
1122
|
+
return source
|
|
1123
|
+
} else if (source instanceof Date) {
|
|
1124
|
+
return new Date(source.getTime())
|
|
1125
|
+
} else if (source instanceof RegExp) {
|
|
1126
|
+
var flags =
|
|
1127
|
+
source.flags ||
|
|
1128
|
+
// old browsers compatibility
|
|
1129
|
+
[
|
|
1130
|
+
source.global ? 'g' : '',
|
|
1131
|
+
source.ignoreCase ? 'i' : '',
|
|
1132
|
+
source.multiline ? 'm' : '',
|
|
1133
|
+
source.sticky ? 'y' : '',
|
|
1134
|
+
source.unicode ? 'u' : '',
|
|
1135
|
+
].join('')
|
|
1136
|
+
return new RegExp(source.source, flags)
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
if (circularReferenceChecker.hasAlreadyBeenSeen(source)) {
|
|
1140
|
+
// remove circular references
|
|
1141
|
+
return undefined
|
|
1142
|
+
} else if (Array.isArray(source)) {
|
|
1143
|
+
var merged= Array.isArray(destination) ? destination : []
|
|
1144
|
+
for (var i = 0; i < source.length; ++i) {
|
|
1145
|
+
merged[i] = mergeInto(merged[i], source[i], circularReferenceChecker)
|
|
1146
|
+
}
|
|
1147
|
+
return merged
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
var merged = getType(destination) === 'object' ? destination : {}
|
|
1151
|
+
for (var key in source) {
|
|
1152
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
1153
|
+
merged[key] = mergeInto(merged[key], source[key], circularReferenceChecker)
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
return merged
|
|
1157
|
+
}
|
|
1063
1158
|
|
|
1159
|
+
/**
|
|
1160
|
+
* A simplistic implementation of a deep clone algorithm.
|
|
1161
|
+
* Caveats:
|
|
1162
|
+
* - It doesn't maintain prototype chains - don't use with instances of custom classes.
|
|
1163
|
+
* - It doesn't handle Map and Set
|
|
1164
|
+
*/
|
|
1165
|
+
export function deepClone(value){
|
|
1166
|
+
return mergeInto(undefined, value)
|
|
1167
|
+
}
|
|
1064
1168
|
export var _URL = function (url) {
|
|
1065
1169
|
var result = {}
|
|
1066
1170
|
var basicProps = [
|
package/src/sessionManagement.js
CHANGED
|
@@ -41,6 +41,7 @@ export function startSessionManagement(
|
|
|
41
41
|
var currentSession = retrieveActiveSession(sessionCookie)
|
|
42
42
|
var currentSessionId = currentSession.id
|
|
43
43
|
var expandOrRenewSession = throttle(function () {
|
|
44
|
+
sessionCookie.clearCache()
|
|
44
45
|
var session = retrieveActiveSession(sessionCookie)
|
|
45
46
|
var state = computeSessionState(session[productKey])
|
|
46
47
|
session[productKey] = state.trackingType
|
|
@@ -59,6 +60,7 @@ export function startSessionManagement(
|
|
|
59
60
|
}, COOKIE_ACCESS_DELAY)
|
|
60
61
|
|
|
61
62
|
var expandSession = function () {
|
|
63
|
+
sessionCookie.clearCache()
|
|
62
64
|
var session = retrieveActiveSession(sessionCookie)
|
|
63
65
|
persistSession(session, sessionCookie)
|
|
64
66
|
}
|
package/src/transport.js
CHANGED
|
@@ -44,7 +44,10 @@ httpRequest.prototype = {
|
|
|
44
44
|
|
|
45
45
|
export var HttpRequest = httpRequest
|
|
46
46
|
export var processedMessageByDataMap = function (message) {
|
|
47
|
-
if (!message || !message.type) return
|
|
47
|
+
if (!message || !message.type) return {
|
|
48
|
+
rowStr: '',
|
|
49
|
+
rowData: undefined
|
|
50
|
+
}
|
|
48
51
|
var rowData = { tags: {}, fields: {} }
|
|
49
52
|
var hasFileds = false
|
|
50
53
|
var rowStr = ''
|