@cloudcare/rum-uniapp 1.0.3 → 2.1.2
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/README.md +11 -8
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/boot/rum.entry.js +73 -2
- package/cjs/boot/rum.js +15 -3
- package/cjs/core/baseInfo.js +0 -6
- package/cjs/core/boundedBuffer.js +28 -0
- package/cjs/core/configuration.js +26 -1
- package/cjs/core/dataMap.js +5 -1
- package/cjs/core/errorCollection.js +5 -6
- package/cjs/core/errorFilter.js +47 -0
- package/cjs/core/errorTools.js +2 -1
- package/cjs/core/lifeCycle.js +1 -0
- package/cjs/core/sdk.js +0 -1
- package/cjs/core/sessionManagement.js +45 -0
- package/cjs/core/transport.js +114 -69
- package/cjs/core/xhrProxy.js +3 -2
- package/cjs/helper/enums.js +22 -7
- package/cjs/helper/limitModification.js +83 -0
- package/cjs/helper/tracekit.js +1 -1
- package/cjs/helper/utils.js +248 -6
- package/cjs/rumEventsCollection/action/actionCollection.js +19 -1
- package/cjs/rumEventsCollection/app/appCollection.js +0 -1
- package/cjs/rumEventsCollection/assembly.js +41 -14
- package/cjs/rumEventsCollection/error/errorCollection.js +37 -5
- package/cjs/rumEventsCollection/internalContext.js +34 -0
- package/cjs/rumEventsCollection/page/index.js +2 -11
- package/cjs/rumEventsCollection/requestCollection.js +9 -2
- package/cjs/rumEventsCollection/resource/resourceCollection.js +20 -2
- package/cjs/rumEventsCollection/tracing/ddtraceTracer.js +50 -0
- package/cjs/rumEventsCollection/tracing/jaegerTracer.js +58 -0
- package/cjs/rumEventsCollection/tracing/skywalkingTracer.js +75 -0
- package/cjs/rumEventsCollection/tracing/tracer.js +108 -0
- package/cjs/rumEventsCollection/tracing/w3cTraceParentTracer.js +51 -0
- package/cjs/rumEventsCollection/tracing/zipkinMultiTracer.js +58 -0
- package/cjs/rumEventsCollection/tracing/zipkinSingleTracer.js +51 -0
- package/esm/boot/buildEnv.js +1 -1
- package/esm/boot/rum.entry.js +71 -3
- package/esm/boot/rum.js +13 -3
- package/esm/core/baseInfo.js +0 -5
- package/esm/core/boundedBuffer.js +20 -0
- package/esm/core/configuration.js +28 -3
- package/esm/core/dataMap.js +5 -1
- package/esm/core/errorCollection.js +5 -6
- package/esm/core/errorFilter.js +38 -0
- package/esm/core/errorTools.js +2 -1
- package/esm/core/lifeCycle.js +1 -0
- package/esm/core/sdk.js +0 -1
- package/esm/core/sessionManagement.js +20 -0
- package/esm/core/transport.js +111 -70
- package/esm/core/xhrProxy.js +3 -2
- package/esm/helper/enums.js +16 -2
- package/esm/helper/limitModification.js +57 -0
- package/esm/helper/tracekit.js +1 -1
- package/esm/helper/utils.js +213 -5
- package/esm/rumEventsCollection/action/actionCollection.js +20 -2
- package/esm/rumEventsCollection/app/appCollection.js +0 -1
- package/esm/rumEventsCollection/assembly.js +40 -15
- package/esm/rumEventsCollection/error/errorCollection.js +36 -5
- package/esm/rumEventsCollection/internalContext.js +27 -0
- package/esm/rumEventsCollection/page/index.js +2 -11
- package/esm/rumEventsCollection/requestCollection.js +8 -2
- package/esm/rumEventsCollection/resource/resourceCollection.js +21 -3
- package/esm/rumEventsCollection/tracing/ddtraceTracer.js +42 -0
- package/esm/rumEventsCollection/tracing/jaegerTracer.js +50 -0
- package/esm/rumEventsCollection/tracing/skywalkingTracer.js +66 -0
- package/esm/rumEventsCollection/tracing/tracer.js +90 -0
- package/esm/rumEventsCollection/tracing/w3cTraceParentTracer.js +43 -0
- package/esm/rumEventsCollection/tracing/zipkinMultiTracer.js +50 -0
- package/esm/rumEventsCollection/tracing/zipkinSingleTracer.js +43 -0
- package/package.json +1 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.startInternalContext = startInternalContext;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Internal context keep returning v1 format
|
|
10
|
+
* to not break compatibility with logs data format
|
|
11
|
+
*/
|
|
12
|
+
function startInternalContext(applicationId, session, parentContexts) {
|
|
13
|
+
return {
|
|
14
|
+
get: function get(startTime) {
|
|
15
|
+
var viewContext = parentContexts.findView(startTime);
|
|
16
|
+
|
|
17
|
+
if (session.isTracked() && viewContext) {
|
|
18
|
+
var actionContext = parentContexts.findAction(startTime);
|
|
19
|
+
return {
|
|
20
|
+
application: {
|
|
21
|
+
id: applicationId
|
|
22
|
+
},
|
|
23
|
+
session: {
|
|
24
|
+
id: session.getSessionId()
|
|
25
|
+
},
|
|
26
|
+
userAction: actionContext ? {
|
|
27
|
+
id: actionContext.userAction.id
|
|
28
|
+
} : undefined,
|
|
29
|
+
page: viewContext.page
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -36,7 +36,7 @@ function rewritePage(configuration, lifeCycle, Vue) {
|
|
|
36
36
|
|
|
37
37
|
if (methodName === 'onShow' || methodName === 'onLoad') {
|
|
38
38
|
if (typeof currentView === 'undefined') {
|
|
39
|
-
var activePage = getActivePage();
|
|
39
|
+
var activePage = (0, _utils.getActivePage)();
|
|
40
40
|
currentView = newView(lifeCycle, activePage && activePage.route, startTime);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
@@ -48,6 +48,7 @@ function rewritePage(configuration, lifeCycle, Vue) {
|
|
|
48
48
|
|
|
49
49
|
if (methodName === 'onUnload' || methodName === 'onHide') {
|
|
50
50
|
currentView.end();
|
|
51
|
+
currentView = undefined;
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
54
|
|
|
@@ -231,14 +232,4 @@ function trackSetDataTime(lifeCycle, callback) {
|
|
|
231
232
|
return {
|
|
232
233
|
stop: subscribe.unsubscribe
|
|
233
234
|
};
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
function getActivePage() {
|
|
237
|
-
var curPages = getCurrentPages();
|
|
238
|
-
|
|
239
|
-
if (curPages.length) {
|
|
240
|
-
return curPages[curPages.length - 1];
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
return {};
|
|
244
235
|
}
|
|
@@ -17,10 +17,13 @@ var _utils = require("../helper/utils");
|
|
|
17
17
|
|
|
18
18
|
var _resourceUtils = require("../rumEventsCollection/resource/resourceUtils");
|
|
19
19
|
|
|
20
|
+
var _tracer = require("../rumEventsCollection/tracing/tracer");
|
|
21
|
+
|
|
20
22
|
var nextRequestIndex = 1;
|
|
21
23
|
|
|
22
24
|
function startRequestCollection(lifeCycle, configuration) {
|
|
23
|
-
|
|
25
|
+
var tracer = (0, _tracer.startTracer)(configuration);
|
|
26
|
+
trackXhr(lifeCycle, configuration, tracer);
|
|
24
27
|
trackDownload(lifeCycle, configuration);
|
|
25
28
|
}
|
|
26
29
|
|
|
@@ -43,10 +46,11 @@ function getHeaderString(header) {
|
|
|
43
46
|
return headerStr;
|
|
44
47
|
}
|
|
45
48
|
|
|
46
|
-
function trackXhr(lifeCycle, configuration) {
|
|
49
|
+
function trackXhr(lifeCycle, configuration, tracer) {
|
|
47
50
|
var xhrProxy = (0, _xhrProxy.startXhrProxy)();
|
|
48
51
|
xhrProxy.beforeSend(function (context) {
|
|
49
52
|
if ((0, _resourceUtils.isAllowedRequestUrl)(configuration, context.url)) {
|
|
53
|
+
tracer.traceXhr(context);
|
|
50
54
|
context.requestIndex = getNextRequestIndex();
|
|
51
55
|
lifeCycle.notify(_lifeCycle.LifeCycleEventType.REQUEST_STARTED, {
|
|
52
56
|
requestIndex: context.requestIndex
|
|
@@ -55,6 +59,7 @@ function trackXhr(lifeCycle, configuration) {
|
|
|
55
59
|
});
|
|
56
60
|
xhrProxy.onRequestComplete(function (context) {
|
|
57
61
|
if ((0, _resourceUtils.isAllowedRequestUrl)(configuration, context.url)) {
|
|
62
|
+
tracer.clearTracingIfCancelled(context);
|
|
58
63
|
lifeCycle.notify(_lifeCycle.LifeCycleEventType.REQUEST_COMPLETED, {
|
|
59
64
|
duration: context.duration,
|
|
60
65
|
method: context.method,
|
|
@@ -63,6 +68,8 @@ function trackXhr(lifeCycle, configuration) {
|
|
|
63
68
|
response: context.response,
|
|
64
69
|
startTime: context.startTime,
|
|
65
70
|
status: context.status,
|
|
71
|
+
traceId: context.traceId,
|
|
72
|
+
spanId: context.spanId,
|
|
66
73
|
type: context.type,
|
|
67
74
|
url: context.url
|
|
68
75
|
});
|
|
@@ -23,9 +23,9 @@ function processRequest(request) {
|
|
|
23
23
|
var type = request.type;
|
|
24
24
|
var timing = request.performance;
|
|
25
25
|
var correspondingTimingOverrides = timing ? computePerformanceEntryMetrics(timing) : undefined;
|
|
26
|
+
var tracingInfo = computeRequestTracingInfo(request);
|
|
26
27
|
var urlObj = (0, _utils.urlParse)(request.url).getParse();
|
|
27
28
|
var startTime = request.startTime;
|
|
28
|
-
console.log(request, 'request=========');
|
|
29
29
|
var resourceEvent = (0, _utils.extend2Lev)({
|
|
30
30
|
date: startTime,
|
|
31
31
|
resource: {
|
|
@@ -41,13 +41,31 @@ function processRequest(request) {
|
|
|
41
41
|
urlQuery: (0, _utils.jsonStringify)((0, _utils.getQueryParamsFromUrl)(request.url))
|
|
42
42
|
},
|
|
43
43
|
type: _enums.RumEventType.RESOURCE
|
|
44
|
-
}, correspondingTimingOverrides);
|
|
44
|
+
}, tracingInfo, correspondingTimingOverrides);
|
|
45
45
|
return {
|
|
46
46
|
startTime: startTime,
|
|
47
47
|
rawRumEvent: resourceEvent
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
function computeRequestTracingInfo(request) {
|
|
52
|
+
var hasBeenTraced = request.traceId && request.spanId;
|
|
53
|
+
|
|
54
|
+
if (!hasBeenTraced) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
_dd: {
|
|
60
|
+
spanId: request.spanId,
|
|
61
|
+
traceId: request.traceId
|
|
62
|
+
},
|
|
63
|
+
resource: {
|
|
64
|
+
id: (0, _utils.UUID)()
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
51
69
|
function computePerformanceEntryMetrics(timing) {
|
|
52
70
|
return {
|
|
53
71
|
resource: (0, _utils.extend2Lev)({}, {
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.DDtraceTracer = DDtraceTracer;
|
|
7
|
+
|
|
8
|
+
// === Generate a random 64-bit number in fixed-length hex format
|
|
9
|
+
function randomTraceId() {
|
|
10
|
+
var digits = '0123456789abcdef';
|
|
11
|
+
var n = '';
|
|
12
|
+
|
|
13
|
+
for (var i = 0; i < 19; i += 1) {
|
|
14
|
+
var rand = Math.floor(Math.random() * 10);
|
|
15
|
+
n += digits[rand];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return n;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @param {*} configuration 配置信息
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
function DDtraceTracer(configuration) {
|
|
27
|
+
this._spanId = randomTraceId();
|
|
28
|
+
this._traceId = randomTraceId();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
DDtraceTracer.prototype = {
|
|
32
|
+
isTracingSupported: function isTracingSupported() {
|
|
33
|
+
return true;
|
|
34
|
+
},
|
|
35
|
+
getSpanId: function getSpanId() {
|
|
36
|
+
return this._spanId;
|
|
37
|
+
},
|
|
38
|
+
getTraceId: function getTraceId() {
|
|
39
|
+
return this._traceId;
|
|
40
|
+
},
|
|
41
|
+
makeTracingHeaders: function makeTracingHeaders() {
|
|
42
|
+
return {
|
|
43
|
+
'x-datadog-origin': 'rum',
|
|
44
|
+
// 'x-datadog-parent-id': spanId.toDecimalString(),
|
|
45
|
+
'x-datadog-sampled': '1',
|
|
46
|
+
'x-datadog-sampling-priority': '1',
|
|
47
|
+
'x-datadog-trace-id': this.getTraceId()
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.JaegerTracer = JaegerTracer;
|
|
7
|
+
|
|
8
|
+
// === Generate a random 64-bit number in fixed-length hex format
|
|
9
|
+
function randomTraceId() {
|
|
10
|
+
var digits = '0123456789abcdef';
|
|
11
|
+
var n = '';
|
|
12
|
+
|
|
13
|
+
for (var i = 0; i < 16; i += 1) {
|
|
14
|
+
var rand = Math.floor(Math.random() * 16);
|
|
15
|
+
n += digits[rand];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return n;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @param {*} configuration 配置信息
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
function JaegerTracer(configuration) {
|
|
27
|
+
var rootSpanId = randomTraceId(); // this._traceId = randomTraceId() + rootSpanId // 默认用128bit,兼容其他配置
|
|
28
|
+
|
|
29
|
+
if (configuration.traceId128Bit) {
|
|
30
|
+
// 128bit生成traceid
|
|
31
|
+
this._traceId = randomTraceId() + rootSpanId;
|
|
32
|
+
} else {
|
|
33
|
+
this._traceId = rootSpanId;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
this._spanId = rootSpanId;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
JaegerTracer.prototype = {
|
|
40
|
+
isTracingSupported: function isTracingSupported() {
|
|
41
|
+
return true;
|
|
42
|
+
},
|
|
43
|
+
getSpanId: function getSpanId() {
|
|
44
|
+
return this._spanId;
|
|
45
|
+
},
|
|
46
|
+
getTraceId: function getTraceId() {
|
|
47
|
+
return this._traceId;
|
|
48
|
+
},
|
|
49
|
+
getUberTraceId: function getUberTraceId() {
|
|
50
|
+
//{trace-id}:{span-id}:{parent-span-id}:{flags}
|
|
51
|
+
return this._traceId + ':' + this._spanId + ':' + '0' + ':' + '1';
|
|
52
|
+
},
|
|
53
|
+
makeTracingHeaders: function makeTracingHeaders() {
|
|
54
|
+
return {
|
|
55
|
+
'uber-trace-id': this.getUberTraceId()
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.SkyWalkingTracer = SkyWalkingTracer;
|
|
7
|
+
|
|
8
|
+
var _utils = require("../../helper/utils");
|
|
9
|
+
|
|
10
|
+
// start SkyWalking
|
|
11
|
+
function uuid() {
|
|
12
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
13
|
+
/* tslint:disable */
|
|
14
|
+
var r = Math.random() * 16 | 0;
|
|
15
|
+
/* tslint:disable */
|
|
16
|
+
|
|
17
|
+
var v = c === 'x' ? r : r & 0x3 | 0x8;
|
|
18
|
+
return v.toString(16);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @param {*} configuration 配置信息
|
|
24
|
+
* @param {*} requestUrl 请求的url
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
function SkyWalkingTracer(configuration, requestUrl) {
|
|
29
|
+
this._spanId = uuid();
|
|
30
|
+
this._traceId = uuid();
|
|
31
|
+
this._applicationId = configuration.applicationId;
|
|
32
|
+
this._env = configuration.env;
|
|
33
|
+
this._version = configuration.version;
|
|
34
|
+
this._urlParse = (0, _utils.urlParse)(requestUrl).getParse();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
SkyWalkingTracer.prototype = {
|
|
38
|
+
isTracingSupported: function isTracingSupported() {
|
|
39
|
+
if (this._env && this._version && this._urlParse) return true;
|
|
40
|
+
return false;
|
|
41
|
+
},
|
|
42
|
+
getSpanId: function getSpanId() {
|
|
43
|
+
return this._spanId;
|
|
44
|
+
},
|
|
45
|
+
getTraceId: function getTraceId() {
|
|
46
|
+
return this._traceId;
|
|
47
|
+
},
|
|
48
|
+
getSkyWalkingSw8: function getSkyWalkingSw8() {
|
|
49
|
+
try {
|
|
50
|
+
var traceIdStr = String((0, _utils.base64Encode)(this._traceId));
|
|
51
|
+
var segmentId = String((0, _utils.base64Encode)(this._spanId));
|
|
52
|
+
var service = String((0, _utils.base64Encode)(this._applicationId + '_rum_' + this.env));
|
|
53
|
+
var instance = String((0, _utils.base64Encode)(this._version));
|
|
54
|
+
var activePage = (0, _utils.getActivePage)();
|
|
55
|
+
var endpointPage = '';
|
|
56
|
+
|
|
57
|
+
if (activePage && activePage.route) {
|
|
58
|
+
endpointPage = activePage.route;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
var endpoint = String((0, _utils.base64Encode)(endpointPage));
|
|
62
|
+
var peer = String((0, _utils.base64Encode)(this._urlParse.Host));
|
|
63
|
+
var index = '0'; // var values = `${1}-${traceIdStr}-${segmentId}-${index}-${service}-${instance}-${endpoint}-${peer}`;
|
|
64
|
+
|
|
65
|
+
return '1-' + traceIdStr + '-' + segmentId + '-' + index + '-' + service + '-' + instance + '-' + endpoint + '-' + peer;
|
|
66
|
+
} catch (err) {
|
|
67
|
+
return '';
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
makeTracingHeaders: function makeTracingHeaders() {
|
|
71
|
+
return {
|
|
72
|
+
'sw8': this.getSkyWalkingSw8()
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.clearTracingIfCancelled = clearTracingIfCancelled;
|
|
7
|
+
exports.startTracer = startTracer;
|
|
8
|
+
exports.injectHeadersIfTracingAllowed = injectHeadersIfTracingAllowed;
|
|
9
|
+
|
|
10
|
+
var _utils = require("../../helper/utils");
|
|
11
|
+
|
|
12
|
+
var _enums = require("../../helper/enums");
|
|
13
|
+
|
|
14
|
+
var _ddtraceTracer = require("./ddtraceTracer");
|
|
15
|
+
|
|
16
|
+
var _skywalkingTracer = require("./skywalkingTracer");
|
|
17
|
+
|
|
18
|
+
var _jaegerTracer = require("./jaegerTracer");
|
|
19
|
+
|
|
20
|
+
var _zipkinSingleTracer = require("./zipkinSingleTracer");
|
|
21
|
+
|
|
22
|
+
var _zipkinMultiTracer = require("./zipkinMultiTracer");
|
|
23
|
+
|
|
24
|
+
var _w3cTraceParentTracer = require("./w3cTraceParentTracer");
|
|
25
|
+
|
|
26
|
+
function clearTracingIfCancelled(context) {
|
|
27
|
+
if (context.status === 0) {
|
|
28
|
+
context.traceId = undefined;
|
|
29
|
+
context.spanId = undefined;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function startTracer(configuration) {
|
|
34
|
+
return {
|
|
35
|
+
clearTracingIfCancelled: clearTracingIfCancelled,
|
|
36
|
+
traceXhr: function traceXhr(context) {
|
|
37
|
+
return injectHeadersIfTracingAllowed(configuration, context, function (tracingHeaders) {
|
|
38
|
+
context.option = (0, _utils.extend)({}, context.option);
|
|
39
|
+
var header = {};
|
|
40
|
+
|
|
41
|
+
if (context.option.header) {
|
|
42
|
+
(0, _utils.each)(context.option.header, function (value, key) {
|
|
43
|
+
header[key] = value;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
context.option.header = (0, _utils.extend)(header, tracingHeaders);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function isAllowedUrl(configuration, requestUrl) {
|
|
54
|
+
var requestOrigin = (0, _utils.getOrigin)(requestUrl);
|
|
55
|
+
var flag = false;
|
|
56
|
+
(0, _utils.each)(configuration.allowedTracingOrigins, function (allowedOrigin) {
|
|
57
|
+
if (requestOrigin === allowedOrigin || allowedOrigin instanceof RegExp && allowedOrigin.test(requestOrigin)) {
|
|
58
|
+
flag = true;
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return flag;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function injectHeadersIfTracingAllowed(configuration, context, inject) {
|
|
66
|
+
if (!isAllowedUrl(configuration, context.url) || !configuration.traceType) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
var tracer;
|
|
71
|
+
|
|
72
|
+
switch (configuration.traceType) {
|
|
73
|
+
case _enums.TraceType.DDTRACE:
|
|
74
|
+
tracer = new _ddtraceTracer.DDtraceTracer();
|
|
75
|
+
break;
|
|
76
|
+
|
|
77
|
+
case _enums.TraceType.SKYWALKING_V3:
|
|
78
|
+
tracer = new _skywalkingTracer.SkyWalkingTracer(configuration, context.url);
|
|
79
|
+
break;
|
|
80
|
+
|
|
81
|
+
case _enums.TraceType.ZIPKIN_MULTI_HEADER:
|
|
82
|
+
tracer = new _zipkinMultiTracer.ZipkinMultiTracer(configuration);
|
|
83
|
+
break;
|
|
84
|
+
|
|
85
|
+
case _enums.TraceType.JAEGER:
|
|
86
|
+
tracer = new _jaegerTracer.JaegerTracer(configuration);
|
|
87
|
+
break;
|
|
88
|
+
|
|
89
|
+
case _enums.TraceType.W3C_TRACEPARENT:
|
|
90
|
+
tracer = new _w3cTraceParentTracer.W3cTraceParentTracer(configuration);
|
|
91
|
+
break;
|
|
92
|
+
|
|
93
|
+
case _enums.TraceType.ZIPKIN_SINGLE_HEADER:
|
|
94
|
+
tracer = new _zipkinSingleTracer.ZipkinSingleTracer(configuration);
|
|
95
|
+
break;
|
|
96
|
+
|
|
97
|
+
default:
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (!tracer || !tracer.isTracingSupported()) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
context.traceId = tracer.getTraceId();
|
|
106
|
+
context.spanId = tracer.getSpanId();
|
|
107
|
+
inject(tracer.makeTracingHeaders());
|
|
108
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.W3cTraceParentTracer = W3cTraceParentTracer;
|
|
7
|
+
|
|
8
|
+
// === Generate a random 64-bit number in fixed-length hex format
|
|
9
|
+
function randomTraceId() {
|
|
10
|
+
var digits = '0123456789abcdef';
|
|
11
|
+
var n = '';
|
|
12
|
+
|
|
13
|
+
for (var i = 0; i < 16; i += 1) {
|
|
14
|
+
var rand = Math.floor(Math.random() * 16);
|
|
15
|
+
n += digits[rand];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return n;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @param {*} configuration 配置信息
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
function W3cTraceParentTracer(configuration) {
|
|
27
|
+
var rootSpanId = randomTraceId();
|
|
28
|
+
this._traceId = randomTraceId() + rootSpanId;
|
|
29
|
+
this._spanId = rootSpanId;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
W3cTraceParentTracer.prototype = {
|
|
33
|
+
isTracingSupported: function isTracingSupported() {
|
|
34
|
+
return true;
|
|
35
|
+
},
|
|
36
|
+
getSpanId: function getSpanId() {
|
|
37
|
+
return this._spanId;
|
|
38
|
+
},
|
|
39
|
+
getTraceId: function getTraceId() {
|
|
40
|
+
return this._traceId;
|
|
41
|
+
},
|
|
42
|
+
getTraceParent: function getTraceParent() {
|
|
43
|
+
// '{version}-{traceId}-{spanId}-{sampleDecision}'
|
|
44
|
+
return '00-' + this._traceId + '-' + this._spanId + '-01';
|
|
45
|
+
},
|
|
46
|
+
makeTracingHeaders: function makeTracingHeaders() {
|
|
47
|
+
return {
|
|
48
|
+
'traceparent': this.getTraceParent()
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ZipkinMultiTracer = ZipkinMultiTracer;
|
|
7
|
+
|
|
8
|
+
// === Generate a random 64-bit number in fixed-length hex format
|
|
9
|
+
function randomTraceId() {
|
|
10
|
+
var digits = '0123456789abcdef';
|
|
11
|
+
var n = '';
|
|
12
|
+
|
|
13
|
+
for (var i = 0; i < 16; i += 1) {
|
|
14
|
+
var rand = Math.floor(Math.random() * 16);
|
|
15
|
+
n += digits[rand];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return n;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @param {*} configuration 配置信息
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
function ZipkinMultiTracer(configuration) {
|
|
27
|
+
var rootSpanId = randomTraceId();
|
|
28
|
+
|
|
29
|
+
if (configuration.traceId128Bit) {
|
|
30
|
+
// 128bit生成traceid
|
|
31
|
+
this._traceId = randomTraceId() + rootSpanId;
|
|
32
|
+
} else {
|
|
33
|
+
this._traceId = rootSpanId;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
this._spanId = rootSpanId;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
ZipkinMultiTracer.prototype = {
|
|
40
|
+
isTracingSupported: function isTracingSupported() {
|
|
41
|
+
return true;
|
|
42
|
+
},
|
|
43
|
+
getSpanId: function getSpanId() {
|
|
44
|
+
return this._spanId;
|
|
45
|
+
},
|
|
46
|
+
getTraceId: function getTraceId() {
|
|
47
|
+
return this._traceId;
|
|
48
|
+
},
|
|
49
|
+
makeTracingHeaders: function makeTracingHeaders() {
|
|
50
|
+
return {
|
|
51
|
+
'X-B3-TraceId': this.getTraceId(),
|
|
52
|
+
'X-B3-SpanId': this.getSpanId(),
|
|
53
|
+
// 'X-B3-ParentSpanId': '',
|
|
54
|
+
'X-B3-Sampled': '1' // 'X-B3-Flags': '0'
|
|
55
|
+
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ZipkinSingleTracer = ZipkinSingleTracer;
|
|
7
|
+
|
|
8
|
+
// === Generate a random 64-bit number in fixed-length hex format
|
|
9
|
+
function randomTraceId() {
|
|
10
|
+
var digits = '0123456789abcdef';
|
|
11
|
+
var n = '';
|
|
12
|
+
|
|
13
|
+
for (var i = 0; i < 16; i += 1) {
|
|
14
|
+
var rand = Math.floor(Math.random() * 16);
|
|
15
|
+
n += digits[rand];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return n;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @param {*} configuration 配置信息
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
function ZipkinSingleTracer(configuration) {
|
|
27
|
+
var rootSpanId = randomTraceId();
|
|
28
|
+
this._traceId = randomTraceId() + rootSpanId;
|
|
29
|
+
this._spanId = rootSpanId;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
ZipkinSingleTracer.prototype = {
|
|
33
|
+
isTracingSupported: function isTracingSupported() {
|
|
34
|
+
return true;
|
|
35
|
+
},
|
|
36
|
+
getSpanId: function getSpanId() {
|
|
37
|
+
return this._spanId;
|
|
38
|
+
},
|
|
39
|
+
getTraceId: function getTraceId() {
|
|
40
|
+
return this._traceId;
|
|
41
|
+
},
|
|
42
|
+
getB3Str: function getB3Str() {
|
|
43
|
+
//{TraceId}-{SpanId}-{SamplingState}-{ParentSpanId}
|
|
44
|
+
return this._traceId + '-' + this._spanId + '-1';
|
|
45
|
+
},
|
|
46
|
+
makeTracingHeaders: function makeTracingHeaders() {
|
|
47
|
+
return {
|
|
48
|
+
'b3': this.getB3Str()
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
};
|
package/esm/boot/buildEnv.js
CHANGED