@cloudcare/rum-uniapp 2.2.2 → 2.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/core/baseInfo.js +68 -16
- package/cjs/core/configuration.js +2 -1
- package/cjs/core/dataMap.js +14 -5
- package/cjs/core/xhrProxy.js +17 -13
- package/cjs/rumEventsCollection/action/trackActions.js +6 -2
- package/cjs/rumEventsCollection/tracing/ddtraceTracer.js +8 -1
- package/cjs/rumEventsCollection/tracing/jaegerTracer.js +9 -2
- package/cjs/rumEventsCollection/tracing/skywalkingTracer.js +11 -4
- package/cjs/rumEventsCollection/tracing/tracer.js +1 -1
- package/cjs/rumEventsCollection/tracing/w3cTraceParentTracer.js +10 -3
- package/cjs/rumEventsCollection/tracing/zipkinMultiTracer.js +8 -1
- package/cjs/rumEventsCollection/tracing/zipkinSingleTracer.js +10 -3
- package/esm/boot/buildEnv.js +1 -1
- package/esm/core/baseInfo.js +68 -16
- package/esm/core/configuration.js +2 -1
- package/esm/core/dataMap.js +14 -5
- package/esm/core/xhrProxy.js +17 -13
- package/esm/rumEventsCollection/action/trackActions.js +6 -2
- package/esm/rumEventsCollection/tracing/ddtraceTracer.js +8 -1
- package/esm/rumEventsCollection/tracing/jaegerTracer.js +9 -2
- package/esm/rumEventsCollection/tracing/skywalkingTracer.js +11 -4
- package/esm/rumEventsCollection/tracing/tracer.js +1 -1
- package/esm/rumEventsCollection/tracing/w3cTraceParentTracer.js +10 -3
- package/esm/rumEventsCollection/tracing/zipkinMultiTracer.js +8 -1
- package/esm/rumEventsCollection/tracing/zipkinSingleTracer.js +10 -3
- package/package.json +1 -1
package/cjs/boot/buildEnv.js
CHANGED
package/cjs/core/baseInfo.js
CHANGED
|
@@ -8,6 +8,7 @@ var _sdk = require("../core/sdk");
|
|
|
8
8
|
var _utils = require("../helper/utils");
|
|
9
9
|
var _enums = require("../helper/enums");
|
|
10
10
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
11
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
12
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
12
13
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
13
14
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
@@ -23,28 +24,79 @@ var BaseInfo = /*#__PURE__*/function () {
|
|
|
23
24
|
key: "getDeviceInfo",
|
|
24
25
|
value: function getDeviceInfo() {
|
|
25
26
|
try {
|
|
26
|
-
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
// 设备信息
|
|
28
|
+
var deviceInfo = {};
|
|
29
|
+
if (_sdk.sdk.getDeviceInfo) {
|
|
30
|
+
deviceInfo = _sdk.sdk.getDeviceInfo();
|
|
31
|
+
} else {
|
|
32
|
+
var systemInfo = _sdk.sdk.getSystemInfoSync();
|
|
33
|
+
deviceInfo = _defineProperty({
|
|
34
|
+
deviceBrand: systemInfo.deviceBrand,
|
|
35
|
+
deviceId: systemInfo.deviceId,
|
|
36
|
+
deviceModel: systemInfo.deviceModel,
|
|
37
|
+
deviceType: systemInfo.deviceType,
|
|
38
|
+
deviceOrientation: systemInfo.deviceOrientation,
|
|
39
|
+
devicePixelRatio: systemInfo.devicePixelRatio,
|
|
40
|
+
system: systemInfo.system
|
|
41
|
+
}, "devicePixelRatio", systemInfo.devicePixelRatio);
|
|
42
|
+
}
|
|
43
|
+
var appBaseInfo = {};
|
|
44
|
+
if (_sdk.sdk.getAppBaseInfo) {
|
|
45
|
+
appBaseInfo = _sdk.sdk.getAppBaseInfo();
|
|
31
46
|
} else {
|
|
32
|
-
|
|
47
|
+
var _systemInfo = _sdk.sdk.getSystemInfoSync();
|
|
48
|
+
appBaseInfo = {
|
|
49
|
+
appId: _systemInfo.appId,
|
|
50
|
+
appName: _systemInfo.appName,
|
|
51
|
+
appVersion: _systemInfo.appVersion,
|
|
52
|
+
appVersionCode: _systemInfo.appVersionCode,
|
|
53
|
+
appLanguage: _systemInfo.appLanguage,
|
|
54
|
+
appWgtVersion: _systemInfo.appWgtVersion,
|
|
55
|
+
hostName: _systemInfo.hostName,
|
|
56
|
+
hostVersion: _systemInfo.hostVersion,
|
|
57
|
+
hostLanguage: _systemInfo.hostLanguage
|
|
58
|
+
};
|
|
33
59
|
}
|
|
60
|
+
var windowInfo = {};
|
|
61
|
+
if (_sdk.sdk.getWindowInfo) {
|
|
62
|
+
windowInfo = _sdk.sdk.getWindowInfo();
|
|
63
|
+
} else {
|
|
64
|
+
var _systemInfo2 = _sdk.sdk.getSystemInfoSync();
|
|
65
|
+
windowInfo = {
|
|
66
|
+
screenWidth: _systemInfo2.screenWidth,
|
|
67
|
+
screenHeight: _systemInfo2.screenHeight,
|
|
68
|
+
statusBarHeight: _systemInfo2.statusBarHeight,
|
|
69
|
+
windowWidth: _systemInfo2.windowWidth,
|
|
70
|
+
windowHeight: _systemInfo2.windowHeight,
|
|
71
|
+
windowTop: _systemInfo2.windowTop,
|
|
72
|
+
windowBottom: _systemInfo2.windowBottom,
|
|
73
|
+
screenTop: _systemInfo2.screenTop
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
var osInfo = deviceInfo.system.split(' ');
|
|
77
|
+
var osVersion = osInfo.length > 1 && osInfo[1];
|
|
34
78
|
var osVersionMajor = osVersion && osVersion.split('.').length && osVersion.split('.')[0];
|
|
35
79
|
this.deviceInfo = {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
80
|
+
deviceUuid: deviceInfo.deviceId,
|
|
81
|
+
deviceId: deviceInfo.deviceId,
|
|
82
|
+
brand: deviceInfo.deviceBrand,
|
|
83
|
+
model: deviceInfo.deviceModel,
|
|
84
|
+
type: deviceInfo.deviceType,
|
|
85
|
+
pixelRatio: deviceInfo.devicePixelRatio,
|
|
86
|
+
orientation: deviceInfo.deviceOrientation,
|
|
87
|
+
os: osInfo.length > 0 && osInfo[0],
|
|
39
88
|
osVersion: osVersion,
|
|
40
89
|
osVersionMajor: osVersionMajor,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
90
|
+
appVersion: appBaseInfo.appVersion,
|
|
91
|
+
appId: appBaseInfo.appId,
|
|
92
|
+
appName: appBaseInfo.appName,
|
|
93
|
+
appVersionCode: appBaseInfo.appVersionCode,
|
|
94
|
+
appLanguage: appBaseInfo.appLanguage,
|
|
95
|
+
appWgtVersion: appBaseInfo.appWgtVersion,
|
|
96
|
+
platform: appBaseInfo.hostName,
|
|
97
|
+
platformVersion: appBaseInfo.hostVersion,
|
|
98
|
+
platformLanguage: appBaseInfo.hostLanguage,
|
|
99
|
+
screenSize: "".concat(windowInfo.screenWidth, "*").concat(windowInfo.screenHeight, " ")
|
|
48
100
|
};
|
|
49
101
|
} catch (e) {
|
|
50
102
|
this.deviceInfo = {};
|
|
@@ -66,7 +66,8 @@ function commonInit(userConfiguration, buildEnv) {
|
|
|
66
66
|
sdkName: buildEnv.sdkName,
|
|
67
67
|
datakitUrl: getDatakitEndPoint(userConfiguration),
|
|
68
68
|
tags: userConfiguration.tags || [],
|
|
69
|
-
injectTraceHeader: userConfiguration.injectTraceHeader && (0, _catchUserErrors.catchUserErrors)(userConfiguration.injectTraceHeader, 'injectTraceHeader threw an error:')
|
|
69
|
+
injectTraceHeader: userConfiguration.injectTraceHeader && (0, _catchUserErrors.catchUserErrors)(userConfiguration.injectTraceHeader, 'injectTraceHeader threw an error:'),
|
|
70
|
+
generateTraceId: userConfiguration.generateTraceId && (0, _catchUserErrors.catchUserErrors)(userConfiguration.generateTraceId, 'generateTraceId threw an error:')
|
|
70
71
|
};
|
|
71
72
|
if ('trackInteractions' in userConfiguration) {
|
|
72
73
|
transportConfiguration.trackInteractions = !!userConfiguration.trackInteractions;
|
package/cjs/core/dataMap.js
CHANGED
|
@@ -19,18 +19,27 @@ var commonTags = exports.commonTags = {
|
|
|
19
19
|
session_id: 'session.id',
|
|
20
20
|
session_type: 'session.type',
|
|
21
21
|
is_signin: 'user.is_signin',
|
|
22
|
+
platform: 'device.platform',
|
|
23
|
+
platform_version: 'device.platform_version',
|
|
24
|
+
platform_language: 'device.platform_language',
|
|
25
|
+
device_uuid: 'device.device_uuid',
|
|
26
|
+
device_id: 'device.device_id',
|
|
22
27
|
device: 'device.brand',
|
|
28
|
+
brand: 'device.brand',
|
|
23
29
|
model: 'device.model',
|
|
24
|
-
|
|
30
|
+
device_type: 'device.type',
|
|
31
|
+
pixel_ratio: 'device.pixel_ratio',
|
|
32
|
+
orientation: 'device.orientation',
|
|
25
33
|
os: 'device.os',
|
|
26
|
-
app: 'device.app',
|
|
27
34
|
os_version: 'device.os_version',
|
|
28
35
|
os_version_major: 'device.os_version_major',
|
|
36
|
+
device_app_version: 'device.app_version',
|
|
37
|
+
device_app_id: 'device.app_id',
|
|
38
|
+
device_app_version_code: 'device.app_version_code',
|
|
39
|
+
device_app_language: 'device.app_language',
|
|
40
|
+
device_app_wgt_version: 'device.app_wgt_version',
|
|
29
41
|
screen_size: 'device.screen_size',
|
|
30
42
|
network_type: 'device.network_type',
|
|
31
|
-
platform: 'device.platform',
|
|
32
|
-
platform_version: 'device.platform_version',
|
|
33
|
-
app_framework_version: 'device.framework_version',
|
|
34
43
|
view_id: 'page.id',
|
|
35
44
|
view_name: 'page.route',
|
|
36
45
|
view_referer: 'page.referer'
|
package/cjs/core/xhrProxy.js
CHANGED
|
@@ -49,19 +49,23 @@ function proxyXhr(userConfiguration) {
|
|
|
49
49
|
};
|
|
50
50
|
dataflux_xhr.startTime = (0, _utils.now)();
|
|
51
51
|
var originalSuccess = arguments[0].success;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
if (originalSuccess) {
|
|
53
|
+
arguments[0].success = function () {
|
|
54
|
+
reportXhr(arguments[0]);
|
|
55
|
+
if (typeof originalSuccess === 'function') {
|
|
56
|
+
originalSuccess.apply(_this, arguments);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
58
60
|
var originalFail = arguments[0].fail;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
if (originalFail) {
|
|
62
|
+
arguments[0].fail = function () {
|
|
63
|
+
reportXhr(arguments[0]);
|
|
64
|
+
if (typeof originalFail === 'function') {
|
|
65
|
+
originalFail.apply(_this, arguments);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
65
69
|
var hasBeenReported = false;
|
|
66
70
|
var reportXhr = function reportXhr(res) {
|
|
67
71
|
if (hasBeenReported) {
|
|
@@ -69,7 +73,7 @@ function proxyXhr(userConfiguration) {
|
|
|
69
73
|
}
|
|
70
74
|
hasBeenReported = true;
|
|
71
75
|
dataflux_xhr.duration = (0, _utils.now)() - dataflux_xhr.startTime;
|
|
72
|
-
dataflux_xhr.response = JSON.stringify(res.data);
|
|
76
|
+
dataflux_xhr.response = res.data && JSON.stringify(res.data) || {};
|
|
73
77
|
dataflux_xhr.header = res.header || {};
|
|
74
78
|
dataflux_xhr.profile = res.profile;
|
|
75
79
|
dataflux_xhr.status = res.statusCode || res.status || 0;
|
|
@@ -28,7 +28,9 @@ function trackActions(lifeCycle, Vue) {
|
|
|
28
28
|
Page = function Page(page) {
|
|
29
29
|
try {
|
|
30
30
|
hookClick(page);
|
|
31
|
-
} catch (error) {
|
|
31
|
+
} catch (error) {
|
|
32
|
+
console.error('error===', error);
|
|
33
|
+
}
|
|
32
34
|
return originPage(page);
|
|
33
35
|
};
|
|
34
36
|
var originComponent = Component;
|
|
@@ -38,7 +40,9 @@ function trackActions(lifeCycle, Vue) {
|
|
|
38
40
|
component.methods.onLoad = function () {
|
|
39
41
|
try {
|
|
40
42
|
hookClick(this);
|
|
41
|
-
} catch (error) {
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.error('error===', error);
|
|
45
|
+
}
|
|
42
46
|
return originOnLoad.apply(this, arguments);
|
|
43
47
|
};
|
|
44
48
|
}
|
|
@@ -15,12 +15,18 @@ function randomTraceId() {
|
|
|
15
15
|
return n;
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
18
|
+
*
|
|
19
19
|
* @param {*} configuration 配置信息
|
|
20
20
|
*/
|
|
21
21
|
function DDtraceTracer(configuration) {
|
|
22
22
|
this._spanId = randomTraceId();
|
|
23
23
|
this._traceId = randomTraceId();
|
|
24
|
+
if (configuration.generateTraceId && typeof configuration.generateTraceId === 'function') {
|
|
25
|
+
var customTraceId = configuration.generateTraceId();
|
|
26
|
+
if (typeof customTraceId === 'string') {
|
|
27
|
+
this.customTraceId = customTraceId;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
24
30
|
}
|
|
25
31
|
DDtraceTracer.prototype = {
|
|
26
32
|
isTracingSupported: function isTracingSupported() {
|
|
@@ -30,6 +36,7 @@ DDtraceTracer.prototype = {
|
|
|
30
36
|
return this._spanId;
|
|
31
37
|
},
|
|
32
38
|
getTraceId: function getTraceId() {
|
|
39
|
+
if (this.customTraceId) return this.customTraceId;
|
|
33
40
|
return this._traceId;
|
|
34
41
|
},
|
|
35
42
|
makeTracingHeaders: function makeTracingHeaders() {
|
|
@@ -16,7 +16,7 @@ function randomTraceId() {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
*
|
|
20
20
|
* @param {*} configuration 配置信息
|
|
21
21
|
*/
|
|
22
22
|
function JaegerTracer(configuration) {
|
|
@@ -29,6 +29,12 @@ function JaegerTracer(configuration) {
|
|
|
29
29
|
this._traceId = rootSpanId;
|
|
30
30
|
}
|
|
31
31
|
this._spanId = rootSpanId;
|
|
32
|
+
if (configuration.generateTraceId && typeof configuration.generateTraceId === 'function') {
|
|
33
|
+
var customTraceId = configuration.generateTraceId();
|
|
34
|
+
if (typeof customTraceId === 'string') {
|
|
35
|
+
this.customTraceId = customTraceId;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
32
38
|
}
|
|
33
39
|
JaegerTracer.prototype = {
|
|
34
40
|
isTracingSupported: function isTracingSupported() {
|
|
@@ -38,11 +44,12 @@ JaegerTracer.prototype = {
|
|
|
38
44
|
return this._spanId;
|
|
39
45
|
},
|
|
40
46
|
getTraceId: function getTraceId() {
|
|
47
|
+
if (this.customTraceId) return this.customTraceId;
|
|
41
48
|
return this._traceId;
|
|
42
49
|
},
|
|
43
50
|
getUberTraceId: function getUberTraceId() {
|
|
44
51
|
//{trace-id}:{span-id}:{parent-span-id}:{flags}
|
|
45
|
-
return this.
|
|
52
|
+
return this.getTraceId() + ':' + this.getSpanId() + ':' + '0' + ':' + '1';
|
|
46
53
|
},
|
|
47
54
|
makeTracingHeaders: function makeTracingHeaders() {
|
|
48
55
|
return {
|
|
@@ -17,7 +17,7 @@ function uuid() {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
20
|
+
*
|
|
21
21
|
* @param {*} configuration 配置信息
|
|
22
22
|
* @param {*} requestUrl 请求的url
|
|
23
23
|
*/
|
|
@@ -28,6 +28,12 @@ function SkyWalkingTracer(configuration, requestUrl) {
|
|
|
28
28
|
this._env = configuration.env;
|
|
29
29
|
this._version = configuration.version;
|
|
30
30
|
this._urlParse = (0, _utils.urlParse)(requestUrl).getParse();
|
|
31
|
+
if (configuration.generateTraceId && typeof configuration.generateTraceId === 'function') {
|
|
32
|
+
var customTraceId = configuration.generateTraceId();
|
|
33
|
+
if (typeof customTraceId === 'string') {
|
|
34
|
+
this.customTraceId = customTraceId;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
31
37
|
}
|
|
32
38
|
SkyWalkingTracer.prototype = {
|
|
33
39
|
isTracingSupported: function isTracingSupported() {
|
|
@@ -38,12 +44,13 @@ SkyWalkingTracer.prototype = {
|
|
|
38
44
|
return this._spanId;
|
|
39
45
|
},
|
|
40
46
|
getTraceId: function getTraceId() {
|
|
47
|
+
if (this.customTraceId) return this.customTraceId;
|
|
41
48
|
return this._traceId;
|
|
42
49
|
},
|
|
43
50
|
getSkyWalkingSw8: function getSkyWalkingSw8() {
|
|
44
51
|
try {
|
|
45
|
-
var traceIdStr = String((0, _utils.base64Encode)(this.
|
|
46
|
-
var segmentId = String((0, _utils.base64Encode)(this.
|
|
52
|
+
var traceIdStr = String((0, _utils.base64Encode)(this.getTraceId()));
|
|
53
|
+
var segmentId = String((0, _utils.base64Encode)(this.getSpanId()));
|
|
47
54
|
var service = String((0, _utils.base64Encode)(this._applicationId + '_rum_' + this.env));
|
|
48
55
|
var instance = String((0, _utils.base64Encode)(this._version));
|
|
49
56
|
var activePage = (0, _utils.getActivePage)();
|
|
@@ -62,7 +69,7 @@ SkyWalkingTracer.prototype = {
|
|
|
62
69
|
},
|
|
63
70
|
makeTracingHeaders: function makeTracingHeaders() {
|
|
64
71
|
return {
|
|
65
|
-
|
|
72
|
+
sw8: this.getSkyWalkingSw8()
|
|
66
73
|
};
|
|
67
74
|
}
|
|
68
75
|
};
|
|
@@ -55,7 +55,7 @@ function injectHeadersIfTracingAllowed(configuration, context, inject) {
|
|
|
55
55
|
var tracer;
|
|
56
56
|
switch (configuration.traceType) {
|
|
57
57
|
case _enums.TraceType.DDTRACE:
|
|
58
|
-
tracer = new _ddtraceTracer.DDtraceTracer();
|
|
58
|
+
tracer = new _ddtraceTracer.DDtraceTracer(configuration);
|
|
59
59
|
break;
|
|
60
60
|
case _enums.TraceType.SKYWALKING_V3:
|
|
61
61
|
tracer = new _skywalkingTracer.SkyWalkingTracer(configuration, context.url);
|
|
@@ -16,13 +16,19 @@ function randomTraceId() {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
*
|
|
20
20
|
* @param {*} configuration 配置信息
|
|
21
21
|
*/
|
|
22
22
|
function W3cTraceParentTracer(configuration) {
|
|
23
23
|
var rootSpanId = randomTraceId();
|
|
24
24
|
this._traceId = randomTraceId() + rootSpanId;
|
|
25
25
|
this._spanId = rootSpanId;
|
|
26
|
+
if (configuration.generateTraceId && typeof configuration.generateTraceId === 'function') {
|
|
27
|
+
var customTraceId = configuration.generateTraceId();
|
|
28
|
+
if (typeof customTraceId === 'string') {
|
|
29
|
+
this.customTraceId = customTraceId;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
26
32
|
}
|
|
27
33
|
W3cTraceParentTracer.prototype = {
|
|
28
34
|
isTracingSupported: function isTracingSupported() {
|
|
@@ -32,15 +38,16 @@ W3cTraceParentTracer.prototype = {
|
|
|
32
38
|
return this._spanId;
|
|
33
39
|
},
|
|
34
40
|
getTraceId: function getTraceId() {
|
|
41
|
+
if (this.customTraceId) return this.customTraceId;
|
|
35
42
|
return this._traceId;
|
|
36
43
|
},
|
|
37
44
|
getTraceParent: function getTraceParent() {
|
|
38
45
|
// '{version}-{traceId}-{spanId}-{sampleDecision}'
|
|
39
|
-
return '00-' + this.
|
|
46
|
+
return '00-' + this.getTraceId() + '-' + this.getSpanId() + '-01';
|
|
40
47
|
},
|
|
41
48
|
makeTracingHeaders: function makeTracingHeaders() {
|
|
42
49
|
return {
|
|
43
|
-
|
|
50
|
+
traceparent: this.getTraceParent()
|
|
44
51
|
};
|
|
45
52
|
}
|
|
46
53
|
};
|
|
@@ -16,7 +16,7 @@ function randomTraceId() {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
*
|
|
20
20
|
* @param {*} configuration 配置信息
|
|
21
21
|
*/
|
|
22
22
|
function ZipkinMultiTracer(configuration) {
|
|
@@ -28,6 +28,12 @@ function ZipkinMultiTracer(configuration) {
|
|
|
28
28
|
this._traceId = rootSpanId;
|
|
29
29
|
}
|
|
30
30
|
this._spanId = rootSpanId;
|
|
31
|
+
if (configuration.generateTraceId && typeof configuration.generateTraceId === 'function') {
|
|
32
|
+
var customTraceId = configuration.generateTraceId();
|
|
33
|
+
if (typeof customTraceId === 'string') {
|
|
34
|
+
this.customTraceId = customTraceId;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
31
37
|
}
|
|
32
38
|
ZipkinMultiTracer.prototype = {
|
|
33
39
|
isTracingSupported: function isTracingSupported() {
|
|
@@ -37,6 +43,7 @@ ZipkinMultiTracer.prototype = {
|
|
|
37
43
|
return this._spanId;
|
|
38
44
|
},
|
|
39
45
|
getTraceId: function getTraceId() {
|
|
46
|
+
if (this.customTraceId) return this.customTraceId;
|
|
40
47
|
return this._traceId;
|
|
41
48
|
},
|
|
42
49
|
makeTracingHeaders: function makeTracingHeaders() {
|
|
@@ -16,13 +16,19 @@ function randomTraceId() {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
*
|
|
20
20
|
* @param {*} configuration 配置信息
|
|
21
21
|
*/
|
|
22
22
|
function ZipkinSingleTracer(configuration) {
|
|
23
23
|
var rootSpanId = randomTraceId();
|
|
24
24
|
this._traceId = randomTraceId() + rootSpanId;
|
|
25
25
|
this._spanId = rootSpanId;
|
|
26
|
+
if (configuration.generateTraceId && typeof configuration.generateTraceId === 'function') {
|
|
27
|
+
var customTraceId = configuration.generateTraceId();
|
|
28
|
+
if (typeof customTraceId === 'string') {
|
|
29
|
+
this.customTraceId = customTraceId;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
26
32
|
}
|
|
27
33
|
ZipkinSingleTracer.prototype = {
|
|
28
34
|
isTracingSupported: function isTracingSupported() {
|
|
@@ -32,15 +38,16 @@ ZipkinSingleTracer.prototype = {
|
|
|
32
38
|
return this._spanId;
|
|
33
39
|
},
|
|
34
40
|
getTraceId: function getTraceId() {
|
|
41
|
+
if (this.customTraceId) return this.customTraceId;
|
|
35
42
|
return this._traceId;
|
|
36
43
|
},
|
|
37
44
|
getB3Str: function getB3Str() {
|
|
38
45
|
//{TraceId}-{SpanId}-{SamplingState}-{ParentSpanId}
|
|
39
|
-
return this.
|
|
46
|
+
return this.getTraceId() + '-' + this.getSpanId() + '-1';
|
|
40
47
|
},
|
|
41
48
|
makeTracingHeaders: function makeTracingHeaders() {
|
|
42
49
|
return {
|
|
43
|
-
|
|
50
|
+
b3: this.getB3Str()
|
|
44
51
|
};
|
|
45
52
|
}
|
|
46
53
|
};
|
package/esm/boot/buildEnv.js
CHANGED
package/esm/core/baseInfo.js
CHANGED
|
@@ -8,28 +8,80 @@ class BaseInfo {
|
|
|
8
8
|
}
|
|
9
9
|
getDeviceInfo() {
|
|
10
10
|
try {
|
|
11
|
-
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
// 设备信息
|
|
12
|
+
var deviceInfo = {};
|
|
13
|
+
if (sdk.getDeviceInfo) {
|
|
14
|
+
deviceInfo = sdk.getDeviceInfo();
|
|
15
|
+
} else {
|
|
16
|
+
var systemInfo = sdk.getSystemInfoSync();
|
|
17
|
+
deviceInfo = {
|
|
18
|
+
deviceBrand: systemInfo.deviceBrand,
|
|
19
|
+
deviceId: systemInfo.deviceId,
|
|
20
|
+
deviceModel: systemInfo.deviceModel,
|
|
21
|
+
deviceType: systemInfo.deviceType,
|
|
22
|
+
deviceOrientation: systemInfo.deviceOrientation,
|
|
23
|
+
devicePixelRatio: systemInfo.devicePixelRatio,
|
|
24
|
+
system: systemInfo.system,
|
|
25
|
+
devicePixelRatio: systemInfo.devicePixelRatio
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
var appBaseInfo = {};
|
|
29
|
+
if (sdk.getAppBaseInfo) {
|
|
30
|
+
appBaseInfo = sdk.getAppBaseInfo();
|
|
16
31
|
} else {
|
|
17
|
-
|
|
32
|
+
var _systemInfo = sdk.getSystemInfoSync();
|
|
33
|
+
appBaseInfo = {
|
|
34
|
+
appId: _systemInfo.appId,
|
|
35
|
+
appName: _systemInfo.appName,
|
|
36
|
+
appVersion: _systemInfo.appVersion,
|
|
37
|
+
appVersionCode: _systemInfo.appVersionCode,
|
|
38
|
+
appLanguage: _systemInfo.appLanguage,
|
|
39
|
+
appWgtVersion: _systemInfo.appWgtVersion,
|
|
40
|
+
hostName: _systemInfo.hostName,
|
|
41
|
+
hostVersion: _systemInfo.hostVersion,
|
|
42
|
+
hostLanguage: _systemInfo.hostLanguage
|
|
43
|
+
};
|
|
18
44
|
}
|
|
45
|
+
var windowInfo = {};
|
|
46
|
+
if (sdk.getWindowInfo) {
|
|
47
|
+
windowInfo = sdk.getWindowInfo();
|
|
48
|
+
} else {
|
|
49
|
+
var _systemInfo2 = sdk.getSystemInfoSync();
|
|
50
|
+
windowInfo = {
|
|
51
|
+
screenWidth: _systemInfo2.screenWidth,
|
|
52
|
+
screenHeight: _systemInfo2.screenHeight,
|
|
53
|
+
statusBarHeight: _systemInfo2.statusBarHeight,
|
|
54
|
+
windowWidth: _systemInfo2.windowWidth,
|
|
55
|
+
windowHeight: _systemInfo2.windowHeight,
|
|
56
|
+
windowTop: _systemInfo2.windowTop,
|
|
57
|
+
windowBottom: _systemInfo2.windowBottom,
|
|
58
|
+
screenTop: _systemInfo2.screenTop
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
var osInfo = deviceInfo.system.split(' ');
|
|
62
|
+
var osVersion = osInfo.length > 1 && osInfo[1];
|
|
19
63
|
var osVersionMajor = osVersion && osVersion.split('.').length && osVersion.split('.')[0];
|
|
20
64
|
this.deviceInfo = {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
65
|
+
deviceUuid: deviceInfo.deviceId,
|
|
66
|
+
deviceId: deviceInfo.deviceId,
|
|
67
|
+
brand: deviceInfo.deviceBrand,
|
|
68
|
+
model: deviceInfo.deviceModel,
|
|
69
|
+
type: deviceInfo.deviceType,
|
|
70
|
+
pixelRatio: deviceInfo.devicePixelRatio,
|
|
71
|
+
orientation: deviceInfo.deviceOrientation,
|
|
72
|
+
os: osInfo.length > 0 && osInfo[0],
|
|
24
73
|
osVersion: osVersion,
|
|
25
74
|
osVersionMajor: osVersionMajor,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
75
|
+
appVersion: appBaseInfo.appVersion,
|
|
76
|
+
appId: appBaseInfo.appId,
|
|
77
|
+
appName: appBaseInfo.appName,
|
|
78
|
+
appVersionCode: appBaseInfo.appVersionCode,
|
|
79
|
+
appLanguage: appBaseInfo.appLanguage,
|
|
80
|
+
appWgtVersion: appBaseInfo.appWgtVersion,
|
|
81
|
+
platform: appBaseInfo.hostName,
|
|
82
|
+
platformVersion: appBaseInfo.hostVersion,
|
|
83
|
+
platformLanguage: appBaseInfo.hostLanguage,
|
|
84
|
+
screenSize: "".concat(windowInfo.screenWidth, "*").concat(windowInfo.screenHeight, " ")
|
|
33
85
|
};
|
|
34
86
|
} catch (e) {
|
|
35
87
|
this.deviceInfo = {};
|
|
@@ -58,7 +58,8 @@ export function commonInit(userConfiguration, buildEnv) {
|
|
|
58
58
|
sdkName: buildEnv.sdkName,
|
|
59
59
|
datakitUrl: getDatakitEndPoint(userConfiguration),
|
|
60
60
|
tags: userConfiguration.tags || [],
|
|
61
|
-
injectTraceHeader: userConfiguration.injectTraceHeader && catchUserErrors(userConfiguration.injectTraceHeader, 'injectTraceHeader threw an error:')
|
|
61
|
+
injectTraceHeader: userConfiguration.injectTraceHeader && catchUserErrors(userConfiguration.injectTraceHeader, 'injectTraceHeader threw an error:'),
|
|
62
|
+
generateTraceId: userConfiguration.generateTraceId && catchUserErrors(userConfiguration.generateTraceId, 'generateTraceId threw an error:')
|
|
62
63
|
};
|
|
63
64
|
if ('trackInteractions' in userConfiguration) {
|
|
64
65
|
transportConfiguration.trackInteractions = !!userConfiguration.trackInteractions;
|
package/esm/core/dataMap.js
CHANGED
|
@@ -13,18 +13,27 @@ export var commonTags = {
|
|
|
13
13
|
session_id: 'session.id',
|
|
14
14
|
session_type: 'session.type',
|
|
15
15
|
is_signin: 'user.is_signin',
|
|
16
|
+
platform: 'device.platform',
|
|
17
|
+
platform_version: 'device.platform_version',
|
|
18
|
+
platform_language: 'device.platform_language',
|
|
19
|
+
device_uuid: 'device.device_uuid',
|
|
20
|
+
device_id: 'device.device_id',
|
|
16
21
|
device: 'device.brand',
|
|
22
|
+
brand: 'device.brand',
|
|
17
23
|
model: 'device.model',
|
|
18
|
-
|
|
24
|
+
device_type: 'device.type',
|
|
25
|
+
pixel_ratio: 'device.pixel_ratio',
|
|
26
|
+
orientation: 'device.orientation',
|
|
19
27
|
os: 'device.os',
|
|
20
|
-
app: 'device.app',
|
|
21
28
|
os_version: 'device.os_version',
|
|
22
29
|
os_version_major: 'device.os_version_major',
|
|
30
|
+
device_app_version: 'device.app_version',
|
|
31
|
+
device_app_id: 'device.app_id',
|
|
32
|
+
device_app_version_code: 'device.app_version_code',
|
|
33
|
+
device_app_language: 'device.app_language',
|
|
34
|
+
device_app_wgt_version: 'device.app_wgt_version',
|
|
23
35
|
screen_size: 'device.screen_size',
|
|
24
36
|
network_type: 'device.network_type',
|
|
25
|
-
platform: 'device.platform',
|
|
26
|
-
platform_version: 'device.platform_version',
|
|
27
|
-
app_framework_version: 'device.framework_version',
|
|
28
37
|
view_id: 'page.id',
|
|
29
38
|
view_name: 'page.route',
|
|
30
39
|
view_referer: 'page.referer'
|
package/esm/core/xhrProxy.js
CHANGED
|
@@ -41,19 +41,23 @@ function proxyXhr(userConfiguration) {
|
|
|
41
41
|
};
|
|
42
42
|
dataflux_xhr.startTime = now();
|
|
43
43
|
var originalSuccess = arguments[0].success;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
if (originalSuccess) {
|
|
45
|
+
arguments[0].success = function () {
|
|
46
|
+
reportXhr(arguments[0]);
|
|
47
|
+
if (typeof originalSuccess === 'function') {
|
|
48
|
+
originalSuccess.apply(_this, arguments);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
50
52
|
var originalFail = arguments[0].fail;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
if (originalFail) {
|
|
54
|
+
arguments[0].fail = function () {
|
|
55
|
+
reportXhr(arguments[0]);
|
|
56
|
+
if (typeof originalFail === 'function') {
|
|
57
|
+
originalFail.apply(_this, arguments);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
57
61
|
var hasBeenReported = false;
|
|
58
62
|
var reportXhr = function reportXhr(res) {
|
|
59
63
|
if (hasBeenReported) {
|
|
@@ -61,7 +65,7 @@ function proxyXhr(userConfiguration) {
|
|
|
61
65
|
}
|
|
62
66
|
hasBeenReported = true;
|
|
63
67
|
dataflux_xhr.duration = now() - dataflux_xhr.startTime;
|
|
64
|
-
dataflux_xhr.response = JSON.stringify(res.data);
|
|
68
|
+
dataflux_xhr.response = res.data && JSON.stringify(res.data) || {};
|
|
65
69
|
dataflux_xhr.header = res.header || {};
|
|
66
70
|
dataflux_xhr.profile = res.profile;
|
|
67
71
|
dataflux_xhr.status = res.statusCode || res.status || 0;
|
|
@@ -22,7 +22,9 @@ export function trackActions(lifeCycle, Vue) {
|
|
|
22
22
|
Page = function Page(page) {
|
|
23
23
|
try {
|
|
24
24
|
hookClick(page);
|
|
25
|
-
} catch (error) {
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.error('error===', error);
|
|
27
|
+
}
|
|
26
28
|
return originPage(page);
|
|
27
29
|
};
|
|
28
30
|
var originComponent = Component;
|
|
@@ -32,7 +34,9 @@ export function trackActions(lifeCycle, Vue) {
|
|
|
32
34
|
component.methods.onLoad = function () {
|
|
33
35
|
try {
|
|
34
36
|
hookClick(this);
|
|
35
|
-
} catch (error) {
|
|
37
|
+
} catch (error) {
|
|
38
|
+
console.error('error===', error);
|
|
39
|
+
}
|
|
36
40
|
return originOnLoad.apply(this, arguments);
|
|
37
41
|
};
|
|
38
42
|
}
|
|
@@ -9,12 +9,18 @@ function randomTraceId() {
|
|
|
9
9
|
return n;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
*
|
|
13
13
|
* @param {*} configuration 配置信息
|
|
14
14
|
*/
|
|
15
15
|
export function DDtraceTracer(configuration) {
|
|
16
16
|
this._spanId = randomTraceId();
|
|
17
17
|
this._traceId = randomTraceId();
|
|
18
|
+
if (configuration.generateTraceId && typeof configuration.generateTraceId === 'function') {
|
|
19
|
+
var customTraceId = configuration.generateTraceId();
|
|
20
|
+
if (typeof customTraceId === 'string') {
|
|
21
|
+
this.customTraceId = customTraceId;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
18
24
|
}
|
|
19
25
|
DDtraceTracer.prototype = {
|
|
20
26
|
isTracingSupported: function isTracingSupported() {
|
|
@@ -24,6 +30,7 @@ DDtraceTracer.prototype = {
|
|
|
24
30
|
return this._spanId;
|
|
25
31
|
},
|
|
26
32
|
getTraceId: function getTraceId() {
|
|
33
|
+
if (this.customTraceId) return this.customTraceId;
|
|
27
34
|
return this._traceId;
|
|
28
35
|
},
|
|
29
36
|
makeTracingHeaders: function makeTracingHeaders() {
|
|
@@ -10,7 +10,7 @@ function randomTraceId() {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
*
|
|
14
14
|
* @param {*} configuration 配置信息
|
|
15
15
|
*/
|
|
16
16
|
export function JaegerTracer(configuration) {
|
|
@@ -23,6 +23,12 @@ export function JaegerTracer(configuration) {
|
|
|
23
23
|
this._traceId = rootSpanId;
|
|
24
24
|
}
|
|
25
25
|
this._spanId = rootSpanId;
|
|
26
|
+
if (configuration.generateTraceId && typeof configuration.generateTraceId === 'function') {
|
|
27
|
+
var customTraceId = configuration.generateTraceId();
|
|
28
|
+
if (typeof customTraceId === 'string') {
|
|
29
|
+
this.customTraceId = customTraceId;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
26
32
|
}
|
|
27
33
|
JaegerTracer.prototype = {
|
|
28
34
|
isTracingSupported: function isTracingSupported() {
|
|
@@ -32,11 +38,12 @@ JaegerTracer.prototype = {
|
|
|
32
38
|
return this._spanId;
|
|
33
39
|
},
|
|
34
40
|
getTraceId: function getTraceId() {
|
|
41
|
+
if (this.customTraceId) return this.customTraceId;
|
|
35
42
|
return this._traceId;
|
|
36
43
|
},
|
|
37
44
|
getUberTraceId: function getUberTraceId() {
|
|
38
45
|
//{trace-id}:{span-id}:{parent-span-id}:{flags}
|
|
39
|
-
return this.
|
|
46
|
+
return this.getTraceId() + ':' + this.getSpanId() + ':' + '0' + ':' + '1';
|
|
40
47
|
},
|
|
41
48
|
makeTracingHeaders: function makeTracingHeaders() {
|
|
42
49
|
return {
|
|
@@ -11,7 +11,7 @@ function uuid() {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
*
|
|
15
15
|
* @param {*} configuration 配置信息
|
|
16
16
|
* @param {*} requestUrl 请求的url
|
|
17
17
|
*/
|
|
@@ -22,6 +22,12 @@ export function SkyWalkingTracer(configuration, requestUrl) {
|
|
|
22
22
|
this._env = configuration.env;
|
|
23
23
|
this._version = configuration.version;
|
|
24
24
|
this._urlParse = urlParse(requestUrl).getParse();
|
|
25
|
+
if (configuration.generateTraceId && typeof configuration.generateTraceId === 'function') {
|
|
26
|
+
var customTraceId = configuration.generateTraceId();
|
|
27
|
+
if (typeof customTraceId === 'string') {
|
|
28
|
+
this.customTraceId = customTraceId;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
25
31
|
}
|
|
26
32
|
SkyWalkingTracer.prototype = {
|
|
27
33
|
isTracingSupported: function isTracingSupported() {
|
|
@@ -32,12 +38,13 @@ SkyWalkingTracer.prototype = {
|
|
|
32
38
|
return this._spanId;
|
|
33
39
|
},
|
|
34
40
|
getTraceId: function getTraceId() {
|
|
41
|
+
if (this.customTraceId) return this.customTraceId;
|
|
35
42
|
return this._traceId;
|
|
36
43
|
},
|
|
37
44
|
getSkyWalkingSw8: function getSkyWalkingSw8() {
|
|
38
45
|
try {
|
|
39
|
-
var traceIdStr = String(base64Encode(this.
|
|
40
|
-
var segmentId = String(base64Encode(this.
|
|
46
|
+
var traceIdStr = String(base64Encode(this.getTraceId()));
|
|
47
|
+
var segmentId = String(base64Encode(this.getSpanId()));
|
|
41
48
|
var service = String(base64Encode(this._applicationId + '_rum_' + this.env));
|
|
42
49
|
var instance = String(base64Encode(this._version));
|
|
43
50
|
var activePage = getActivePage();
|
|
@@ -56,7 +63,7 @@ SkyWalkingTracer.prototype = {
|
|
|
56
63
|
},
|
|
57
64
|
makeTracingHeaders: function makeTracingHeaders() {
|
|
58
65
|
return {
|
|
59
|
-
|
|
66
|
+
sw8: this.getSkyWalkingSw8()
|
|
60
67
|
};
|
|
61
68
|
}
|
|
62
69
|
};
|
|
@@ -47,7 +47,7 @@ export function injectHeadersIfTracingAllowed(configuration, context, inject) {
|
|
|
47
47
|
var tracer;
|
|
48
48
|
switch (configuration.traceType) {
|
|
49
49
|
case TraceType.DDTRACE:
|
|
50
|
-
tracer = new DDtraceTracer();
|
|
50
|
+
tracer = new DDtraceTracer(configuration);
|
|
51
51
|
break;
|
|
52
52
|
case TraceType.SKYWALKING_V3:
|
|
53
53
|
tracer = new SkyWalkingTracer(configuration, context.url);
|
|
@@ -10,13 +10,19 @@ function randomTraceId() {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
*
|
|
14
14
|
* @param {*} configuration 配置信息
|
|
15
15
|
*/
|
|
16
16
|
export function W3cTraceParentTracer(configuration) {
|
|
17
17
|
var rootSpanId = randomTraceId();
|
|
18
18
|
this._traceId = randomTraceId() + rootSpanId;
|
|
19
19
|
this._spanId = rootSpanId;
|
|
20
|
+
if (configuration.generateTraceId && typeof configuration.generateTraceId === 'function') {
|
|
21
|
+
var customTraceId = configuration.generateTraceId();
|
|
22
|
+
if (typeof customTraceId === 'string') {
|
|
23
|
+
this.customTraceId = customTraceId;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
20
26
|
}
|
|
21
27
|
W3cTraceParentTracer.prototype = {
|
|
22
28
|
isTracingSupported: function isTracingSupported() {
|
|
@@ -26,15 +32,16 @@ W3cTraceParentTracer.prototype = {
|
|
|
26
32
|
return this._spanId;
|
|
27
33
|
},
|
|
28
34
|
getTraceId: function getTraceId() {
|
|
35
|
+
if (this.customTraceId) return this.customTraceId;
|
|
29
36
|
return this._traceId;
|
|
30
37
|
},
|
|
31
38
|
getTraceParent: function getTraceParent() {
|
|
32
39
|
// '{version}-{traceId}-{spanId}-{sampleDecision}'
|
|
33
|
-
return '00-' + this.
|
|
40
|
+
return '00-' + this.getTraceId() + '-' + this.getSpanId() + '-01';
|
|
34
41
|
},
|
|
35
42
|
makeTracingHeaders: function makeTracingHeaders() {
|
|
36
43
|
return {
|
|
37
|
-
|
|
44
|
+
traceparent: this.getTraceParent()
|
|
38
45
|
};
|
|
39
46
|
}
|
|
40
47
|
};
|
|
@@ -10,7 +10,7 @@ function randomTraceId() {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
*
|
|
14
14
|
* @param {*} configuration 配置信息
|
|
15
15
|
*/
|
|
16
16
|
export function ZipkinMultiTracer(configuration) {
|
|
@@ -22,6 +22,12 @@ export function ZipkinMultiTracer(configuration) {
|
|
|
22
22
|
this._traceId = rootSpanId;
|
|
23
23
|
}
|
|
24
24
|
this._spanId = rootSpanId;
|
|
25
|
+
if (configuration.generateTraceId && typeof configuration.generateTraceId === 'function') {
|
|
26
|
+
var customTraceId = configuration.generateTraceId();
|
|
27
|
+
if (typeof customTraceId === 'string') {
|
|
28
|
+
this.customTraceId = customTraceId;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
25
31
|
}
|
|
26
32
|
ZipkinMultiTracer.prototype = {
|
|
27
33
|
isTracingSupported: function isTracingSupported() {
|
|
@@ -31,6 +37,7 @@ ZipkinMultiTracer.prototype = {
|
|
|
31
37
|
return this._spanId;
|
|
32
38
|
},
|
|
33
39
|
getTraceId: function getTraceId() {
|
|
40
|
+
if (this.customTraceId) return this.customTraceId;
|
|
34
41
|
return this._traceId;
|
|
35
42
|
},
|
|
36
43
|
makeTracingHeaders: function makeTracingHeaders() {
|
|
@@ -10,13 +10,19 @@ function randomTraceId() {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
*
|
|
14
14
|
* @param {*} configuration 配置信息
|
|
15
15
|
*/
|
|
16
16
|
export function ZipkinSingleTracer(configuration) {
|
|
17
17
|
var rootSpanId = randomTraceId();
|
|
18
18
|
this._traceId = randomTraceId() + rootSpanId;
|
|
19
19
|
this._spanId = rootSpanId;
|
|
20
|
+
if (configuration.generateTraceId && typeof configuration.generateTraceId === 'function') {
|
|
21
|
+
var customTraceId = configuration.generateTraceId();
|
|
22
|
+
if (typeof customTraceId === 'string') {
|
|
23
|
+
this.customTraceId = customTraceId;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
20
26
|
}
|
|
21
27
|
ZipkinSingleTracer.prototype = {
|
|
22
28
|
isTracingSupported: function isTracingSupported() {
|
|
@@ -26,15 +32,16 @@ ZipkinSingleTracer.prototype = {
|
|
|
26
32
|
return this._spanId;
|
|
27
33
|
},
|
|
28
34
|
getTraceId: function getTraceId() {
|
|
35
|
+
if (this.customTraceId) return this.customTraceId;
|
|
29
36
|
return this._traceId;
|
|
30
37
|
},
|
|
31
38
|
getB3Str: function getB3Str() {
|
|
32
39
|
//{TraceId}-{SpanId}-{SamplingState}-{ParentSpanId}
|
|
33
|
-
return this.
|
|
40
|
+
return this.getTraceId() + '-' + this.getSpanId() + '-1';
|
|
34
41
|
},
|
|
35
42
|
makeTracingHeaders: function makeTracingHeaders() {
|
|
36
43
|
return {
|
|
37
|
-
|
|
44
|
+
b3: this.getB3Str()
|
|
38
45
|
};
|
|
39
46
|
}
|
|
40
47
|
};
|