@cloudcare/browser-rum 2.0.19 → 2.0.22
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 +16 -11
- package/bundle/dataflux-rum.js +1 -1
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/boot/rumPublicApi.js +18 -31
- package/cjs/domain/assembly.js +14 -4
- package/cjs/domain/requestCollections.js +0 -1
- package/cjs/domain/rumEventsCollection/actions/actionCollection.js +5 -1
- package/cjs/domain/rumEventsCollection/error/errorCollection.js +17 -2
- package/cjs/domain/rumEventsCollection/resource/resourceCollection.js +2 -2
- package/cjs/domain/rumSession.js +21 -6
- package/cjs/domain/tracing/ddtraceTracer.js +75 -0
- package/cjs/domain/tracing/jaegerTracer.js +58 -0
- package/cjs/domain/tracing/skywalkingTracer.js +93 -0
- package/cjs/domain/tracing/tracer.js +51 -60
- package/cjs/domain/tracing/w3cTraceParentTracer.js +51 -0
- package/cjs/domain/tracing/zipkinMultiTracer.js +58 -0
- package/cjs/domain/tracing/zipkinSingleTracer.js +51 -0
- package/esm/boot/buildEnv.js +1 -1
- package/esm/boot/rumPublicApi.js +19 -32
- package/esm/domain/assembly.js +14 -4
- package/esm/domain/requestCollections.js +0 -1
- package/esm/domain/rumEventsCollection/actions/actionCollection.js +5 -1
- package/esm/domain/rumEventsCollection/error/errorCollection.js +18 -3
- package/esm/domain/rumEventsCollection/resource/resourceCollection.js +2 -2
- package/esm/domain/rumSession.js +21 -6
- package/esm/domain/tracing/ddtraceTracer.js +67 -0
- package/esm/domain/tracing/jaegerTracer.js +50 -0
- package/esm/domain/tracing/skywalkingTracer.js +84 -0
- package/esm/domain/tracing/tracer.js +44 -57
- package/esm/domain/tracing/w3cTraceParentTracer.js +43 -0
- package/esm/domain/tracing/zipkinMultiTracer.js +50 -0
- package/esm/domain/tracing/zipkinSingleTracer.js +43 -0
- package/package.json +3 -3
- package/src/boot/rumPublicApi.js +22 -34
- package/src/domain/.DS_Store +0 -0
- package/src/domain/assembly.js +14 -6
- package/src/domain/requestCollections.js +0 -1
- package/src/domain/rumEventsCollection/actions/actionCollection.js +5 -1
- package/src/domain/rumEventsCollection/error/errorCollection.js +23 -4
- package/src/domain/rumEventsCollection/resource/matchRequestTiming.js +1 -0
- package/src/domain/rumEventsCollection/resource/resourceCollection.js +3 -4
- package/src/domain/rumSession.js +24 -7
- package/src/domain/tracing/ddtraceTracer.js +70 -0
- package/src/domain/tracing/jaegerTracer.js +47 -0
- package/src/domain/tracing/skywalkingTracer.js +80 -0
- package/src/domain/tracing/tracer.js +40 -68
- package/src/domain/tracing/w3cTraceParentTracer.js +40 -0
- package/src/domain/tracing/zipkinMultiTracer.js +46 -0
- package/src/domain/tracing/zipkinSingleTracer.js +40 -0
|
@@ -42,7 +42,11 @@ function processAction(action) {
|
|
|
42
42
|
count: action.counts.resourceCount
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
} :
|
|
45
|
+
} : {
|
|
46
|
+
action: {
|
|
47
|
+
loadingTime: 0
|
|
48
|
+
}
|
|
49
|
+
};
|
|
46
50
|
var customerContext = !isAutoAction(action) ? action.context : undefined;
|
|
47
51
|
var actionEvent = (0, _browserCore.extend2Lev)({
|
|
48
52
|
action: {
|
|
@@ -19,11 +19,14 @@ function startErrorCollection(lifeCycle, configuration) {
|
|
|
19
19
|
|
|
20
20
|
function doStartErrorCollection(lifeCycle) {
|
|
21
21
|
lifeCycle.subscribe(_browserCore.LifeCycleEventType.RAW_ERROR_COLLECTED, function (error) {
|
|
22
|
-
lifeCycle.notify(_browserCore.LifeCycleEventType.RAW_RUM_EVENT_COLLECTED,
|
|
22
|
+
lifeCycle.notify(_browserCore.LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, (0, _browserCore.extend)({
|
|
23
|
+
customerContext: error.customerContext,
|
|
24
|
+
savedCommonContext: error.savedCommonContext
|
|
25
|
+
}, processError(error.error)));
|
|
23
26
|
});
|
|
24
27
|
return {
|
|
25
28
|
addError: function addError(customError, savedCommonContext) {
|
|
26
|
-
var rawError = computeRawError(customError.error, customError.
|
|
29
|
+
var rawError = computeRawError(customError.error, customError.handlingStack, customError.startClocks);
|
|
27
30
|
lifeCycle.notify(_browserCore.LifeCycleEventType.RAW_ERROR_COLLECTED, {
|
|
28
31
|
customerContext: customError.context,
|
|
29
32
|
savedCommonContext: savedCommonContext,
|
|
@@ -33,6 +36,16 @@ function doStartErrorCollection(lifeCycle) {
|
|
|
33
36
|
};
|
|
34
37
|
}
|
|
35
38
|
|
|
39
|
+
function computeRawError(error, handlingStack, startClocks) {
|
|
40
|
+
var stackTrace = error instanceof Error ? (0, _browserCore.computeStackTrace)(error) : undefined;
|
|
41
|
+
return (0, _browserCore.extend)({
|
|
42
|
+
startClocks: startClocks,
|
|
43
|
+
source: _browserCore.ErrorSource.CUSTOM,
|
|
44
|
+
originalError: error,
|
|
45
|
+
handling: _browserCore.ErrorHandling.HANDLED
|
|
46
|
+
}, (0, _browserCore.formatUnknownError)(stackTrace, error, 'Provided', handlingStack));
|
|
47
|
+
}
|
|
48
|
+
|
|
36
49
|
function processError(error) {
|
|
37
50
|
var resource = error.resource;
|
|
38
51
|
|
|
@@ -57,6 +70,8 @@ function processError(error) {
|
|
|
57
70
|
source: error.source,
|
|
58
71
|
stack: error.stack,
|
|
59
72
|
type: error.type,
|
|
73
|
+
handling_stack: error.handlingStack,
|
|
74
|
+
handling: error.handling,
|
|
60
75
|
starttime: (0, _browserCore.getTimestamp)(error.startClocks.relative)
|
|
61
76
|
},
|
|
62
77
|
type: _browserCore.RumEventType.ERROR
|
|
@@ -106,8 +106,8 @@ function computeRequestTracingInfo(request) {
|
|
|
106
106
|
|
|
107
107
|
return {
|
|
108
108
|
_dd: {
|
|
109
|
-
spanId: request.spanId
|
|
110
|
-
traceId: request.traceId
|
|
109
|
+
spanId: request.spanId,
|
|
110
|
+
traceId: request.traceId
|
|
111
111
|
},
|
|
112
112
|
resource: {
|
|
113
113
|
id: (0, _browserCore.UUID)()
|
package/cjs/domain/rumSession.js
CHANGED
|
@@ -13,7 +13,9 @@ exports.RUM_SESSION_KEY = RUM_SESSION_KEY;
|
|
|
13
13
|
var RumTrackingType = {
|
|
14
14
|
NOT_TRACKED: '0',
|
|
15
15
|
TRACKED_WITH_RESOURCES: '1',
|
|
16
|
-
TRACKED_WITHOUT_RESOURCES: '2'
|
|
16
|
+
TRACKED_WITHOUT_RESOURCES: '2',
|
|
17
|
+
TRACKED_WITH_SERVICE: '3' // 采样数据添加额外的tag,不舍弃,直接上报到服务端
|
|
18
|
+
|
|
17
19
|
};
|
|
18
20
|
exports.RumTrackingType = RumTrackingType;
|
|
19
21
|
|
|
@@ -33,8 +35,12 @@ function startRumSession(configuration, lifeCycle) {
|
|
|
33
35
|
isTracked: function isTracked() {
|
|
34
36
|
return session.getId() !== undefined && _isTracked(session.getTrackingType());
|
|
35
37
|
},
|
|
38
|
+
isTrackedWidthService: function isTrackedWidthService() {
|
|
39
|
+
return session.getId() !== undefined && session.getTrackingType() === RumTrackingType.TRACKED_WITH_SERVICE;
|
|
40
|
+
},
|
|
36
41
|
isTrackedWithResource: function isTrackedWithResource() {
|
|
37
|
-
|
|
42
|
+
var trackingType = session.getTrackingType();
|
|
43
|
+
return session.getId() !== undefined && (trackingType === RumTrackingType.TRACKED_WITH_RESOURCES || trackingType === RumTrackingType.TRACKED_WITH_SERVICE);
|
|
38
44
|
}
|
|
39
45
|
};
|
|
40
46
|
}
|
|
@@ -45,9 +51,18 @@ function computeSessionState(configuration, rawTrackingType) {
|
|
|
45
51
|
if (hasValidRumSession(rawTrackingType)) {
|
|
46
52
|
trackingType = rawTrackingType;
|
|
47
53
|
} else if (!(0, _browserCore.performDraw)(configuration.sampleRate)) {
|
|
48
|
-
|
|
54
|
+
if (configuration.isServiceSampling) {
|
|
55
|
+
trackingType = RumTrackingType.TRACKED_WITH_SERVICE;
|
|
56
|
+
} else {
|
|
57
|
+
trackingType = RumTrackingType.NOT_TRACKED;
|
|
58
|
+
}
|
|
49
59
|
} else if (!(0, _browserCore.performDraw)(configuration.resourceSampleRate)) {
|
|
50
|
-
trackingType = RumTrackingType.TRACKED_WITHOUT_RESOURCES
|
|
60
|
+
// trackingType = RumTrackingType.TRACKED_WITHOUT_RESOURCES
|
|
61
|
+
if (configuration.isServiceSampling) {
|
|
62
|
+
trackingType = RumTrackingType.TRACKED_WITH_SERVICE;
|
|
63
|
+
} else {
|
|
64
|
+
trackingType = RumTrackingType.TRACKED_WITHOUT_RESOURCES;
|
|
65
|
+
}
|
|
51
66
|
} else {
|
|
52
67
|
trackingType = RumTrackingType.TRACKED_WITH_RESOURCES;
|
|
53
68
|
}
|
|
@@ -59,9 +74,9 @@ function computeSessionState(configuration, rawTrackingType) {
|
|
|
59
74
|
}
|
|
60
75
|
|
|
61
76
|
function hasValidRumSession(trackingType) {
|
|
62
|
-
return trackingType === RumTrackingType.NOT_TRACKED || trackingType === RumTrackingType.TRACKED_WITH_RESOURCES || trackingType === RumTrackingType.TRACKED_WITHOUT_RESOURCES;
|
|
77
|
+
return trackingType === RumTrackingType.NOT_TRACKED || trackingType === RumTrackingType.TRACKED_WITH_RESOURCES || trackingType === RumTrackingType.TRACKED_WITHOUT_RESOURCES || trackingType === RumTrackingType.TRACKED_WITH_SERVICE;
|
|
63
78
|
}
|
|
64
79
|
|
|
65
80
|
function _isTracked(rumSessionType) {
|
|
66
|
-
return rumSessionType === RumTrackingType.TRACKED_WITH_RESOURCES || rumSessionType === RumTrackingType.TRACKED_WITHOUT_RESOURCES;
|
|
81
|
+
return rumSessionType === RumTrackingType.TRACKED_WITH_RESOURCES || rumSessionType === RumTrackingType.TRACKED_WITHOUT_RESOURCES || rumSessionType === RumTrackingType.TRACKED_WITH_SERVICE;
|
|
67
82
|
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.DDtraceTracer = DDtraceTracer;
|
|
7
|
+
|
|
8
|
+
function TraceIdentifier() {
|
|
9
|
+
this.buffer = new Uint8Array(8);
|
|
10
|
+
getCrypto().getRandomValues(this.buffer);
|
|
11
|
+
this.buffer[0] = this.buffer[0] & 0x7f;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
TraceIdentifier.prototype = {
|
|
15
|
+
// buffer: new Uint8Array(8),
|
|
16
|
+
toString: function toString(radix) {
|
|
17
|
+
var high = this.readInt32(0);
|
|
18
|
+
var low = this.readInt32(4);
|
|
19
|
+
var str = '';
|
|
20
|
+
|
|
21
|
+
while (1) {
|
|
22
|
+
var mod = high % radix * 4294967296 + low;
|
|
23
|
+
high = Math.floor(high / radix);
|
|
24
|
+
low = Math.floor(mod / radix);
|
|
25
|
+
str = (mod % radix).toString(radix) + str;
|
|
26
|
+
|
|
27
|
+
if (!high && !low) {
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return str;
|
|
33
|
+
},
|
|
34
|
+
toDecimalString: function toDecimalString() {
|
|
35
|
+
return this.toString(10);
|
|
36
|
+
},
|
|
37
|
+
readInt32: function readInt32(offset) {
|
|
38
|
+
return this.buffer[offset] * 16777216 + (this.buffer[offset + 1] << 16) + (this.buffer[offset + 2] << 8) + this.buffer[offset + 3];
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
function getCrypto() {
|
|
43
|
+
return window.crypto || window.msCrypto;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
* @param {*} configuration 配置信息
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
function DDtraceTracer(configuration) {
|
|
52
|
+
this._spanId = new TraceIdentifier().toDecimalString();
|
|
53
|
+
this._traceId = new TraceIdentifier().toDecimalString();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
DDtraceTracer.prototype = {
|
|
57
|
+
isTracingSupported: function isTracingSupported() {
|
|
58
|
+
return getCrypto() !== undefined;
|
|
59
|
+
},
|
|
60
|
+
getSpanId: function getSpanId() {
|
|
61
|
+
return this._spanId;
|
|
62
|
+
},
|
|
63
|
+
getTraceId: function getTraceId() {
|
|
64
|
+
return this._traceId;
|
|
65
|
+
},
|
|
66
|
+
makeTracingHeaders: function makeTracingHeaders() {
|
|
67
|
+
return {
|
|
68
|
+
'x-datadog-origin': 'rum',
|
|
69
|
+
// 'x-datadog-parent-id': spanId.toDecimalString(),
|
|
70
|
+
'x-datadog-sampled': '1',
|
|
71
|
+
'x-datadog-sampling-priority': '1',
|
|
72
|
+
'x-datadog-trace-id': this.getTraceId()
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
};
|
|
@@ -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,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.SkyWalkingTracer = SkyWalkingTracer;
|
|
7
|
+
|
|
8
|
+
var _browserCore = require("@cloudcare/browser-core");
|
|
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 {*} traceId
|
|
24
|
+
* @param {*} traceSegmentId
|
|
25
|
+
* @param {*} applicationId
|
|
26
|
+
* @param {*} version
|
|
27
|
+
* @param {*} requestUrlHost
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
function getSkyWalkingSw8(traceId, traceSegmentId, applicationId, env, version, requestUrlHost) {
|
|
32
|
+
try {
|
|
33
|
+
var traceIdStr = String((0, _browserCore.base64Encode)(traceId));
|
|
34
|
+
var segmentId = String((0, _browserCore.base64Encode)(traceSegmentId));
|
|
35
|
+
var service = String((0, _browserCore.base64Encode)(applicationId + '_rum_' + env));
|
|
36
|
+
var instance = String((0, _browserCore.base64Encode)(version));
|
|
37
|
+
var endpoint = String((0, _browserCore.base64Encode)(window.location.href));
|
|
38
|
+
var peer = String((0, _browserCore.base64Encode)(requestUrlHost));
|
|
39
|
+
var index = '0'; // var values = `${1}-${traceIdStr}-${segmentId}-${index}-${service}-${instance}-${endpoint}-${peer}`;
|
|
40
|
+
|
|
41
|
+
return '1-' + traceIdStr + '-' + segmentId + '-' + index + '-' + service + '-' + instance + '-' + endpoint + '-' + peer;
|
|
42
|
+
} catch (err) {
|
|
43
|
+
return '';
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
*
|
|
48
|
+
* @param {*} configuration 配置信息
|
|
49
|
+
* @param {*} requestUrl 请求的url
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
function SkyWalkingTracer(configuration, requestUrl) {
|
|
54
|
+
this._spanId = uuid();
|
|
55
|
+
this._traceId = uuid();
|
|
56
|
+
this._applicationId = configuration.applicationId;
|
|
57
|
+
this._env = configuration.env;
|
|
58
|
+
this._version = configuration.version;
|
|
59
|
+
this._urlParse = (0, _browserCore.urlParse)(requestUrl).getParse();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
SkyWalkingTracer.prototype = {
|
|
63
|
+
isTracingSupported: function isTracingSupported() {
|
|
64
|
+
if (this._env && this._version && this._urlParse) return true;
|
|
65
|
+
return false;
|
|
66
|
+
},
|
|
67
|
+
getSpanId: function getSpanId() {
|
|
68
|
+
return this._spanId;
|
|
69
|
+
},
|
|
70
|
+
getTraceId: function getTraceId() {
|
|
71
|
+
return this._traceId;
|
|
72
|
+
},
|
|
73
|
+
getSkyWalkingSw8: function getSkyWalkingSw8() {
|
|
74
|
+
try {
|
|
75
|
+
var traceIdStr = String((0, _browserCore.base64Encode)(this._traceId));
|
|
76
|
+
var segmentId = String((0, _browserCore.base64Encode)(this._spanId));
|
|
77
|
+
var service = String((0, _browserCore.base64Encode)(this._applicationId + '_rum_' + this.env));
|
|
78
|
+
var instance = String((0, _browserCore.base64Encode)(this._version));
|
|
79
|
+
var endpoint = String((0, _browserCore.base64Encode)(window.location.href));
|
|
80
|
+
var peer = String((0, _browserCore.base64Encode)(this._urlParse.Host));
|
|
81
|
+
var index = '0'; // var values = `${1}-${traceIdStr}-${segmentId}-${index}-${service}-${instance}-${endpoint}-${peer}`;
|
|
82
|
+
|
|
83
|
+
return '1-' + traceIdStr + '-' + segmentId + '-' + index + '-' + service + '-' + instance + '-' + endpoint + '-' + peer;
|
|
84
|
+
} catch (err) {
|
|
85
|
+
return '';
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
makeTracingHeaders: function makeTracingHeaders() {
|
|
89
|
+
return {
|
|
90
|
+
'sw8': this.getSkyWalkingSw8()
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
};
|
|
@@ -5,11 +5,22 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.clearTracingIfCancelled = clearTracingIfCancelled;
|
|
7
7
|
exports.startTracer = startTracer;
|
|
8
|
-
exports.
|
|
9
|
-
exports.TraceIdentifier = TraceIdentifier;
|
|
8
|
+
exports.injectHeadersIfTracingAllowed = injectHeadersIfTracingAllowed;
|
|
10
9
|
|
|
11
10
|
var _browserCore = require("@cloudcare/browser-core");
|
|
12
11
|
|
|
12
|
+
var _ddtraceTracer = require("./ddtraceTracer");
|
|
13
|
+
|
|
14
|
+
var _skywalkingTracer = require("./skywalkingTracer");
|
|
15
|
+
|
|
16
|
+
var _jaegerTracer = require("./jaegerTracer");
|
|
17
|
+
|
|
18
|
+
var _zipkinSingleTracer = require("./zipkinSingleTracer");
|
|
19
|
+
|
|
20
|
+
var _zipkinMultiTracer = require("./zipkinMultiTracer");
|
|
21
|
+
|
|
22
|
+
var _w3cTraceParentTracer = require("./w3cTraceParentTracer");
|
|
23
|
+
|
|
13
24
|
function clearTracingIfCancelled(context) {
|
|
14
25
|
if (context.status === 0) {
|
|
15
26
|
context.traceId = undefined;
|
|
@@ -52,20 +63,10 @@ function startTracer(configuration) {
|
|
|
52
63
|
};
|
|
53
64
|
}
|
|
54
65
|
|
|
55
|
-
function injectHeadersIfTracingAllowed(configuration, context, inject) {
|
|
56
|
-
if (!isTracingSupported() || !isAllowedUrl(configuration, context.url)) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
context.traceId = new TraceIdentifier();
|
|
61
|
-
context.spanId = new TraceIdentifier();
|
|
62
|
-
inject(makeTracingHeaders(context.traceId, context.spanId));
|
|
63
|
-
}
|
|
64
|
-
|
|
65
66
|
function isAllowedUrl(configuration, requestUrl) {
|
|
66
67
|
var requestOrigin = (0, _browserCore.getOrigin)(requestUrl);
|
|
67
68
|
var flag = false;
|
|
68
|
-
(0, _browserCore.each)(configuration.
|
|
69
|
+
(0, _browserCore.each)(configuration.allowedTracingOrigins, function (allowedOrigin) {
|
|
69
70
|
if (requestOrigin === allowedOrigin || allowedOrigin instanceof RegExp && allowedOrigin.test(requestOrigin)) {
|
|
70
71
|
flag = true;
|
|
71
72
|
return false;
|
|
@@ -74,57 +75,47 @@ function isAllowedUrl(configuration, requestUrl) {
|
|
|
74
75
|
return flag;
|
|
75
76
|
}
|
|
76
77
|
|
|
77
|
-
function
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
function injectHeadersIfTracingAllowed(configuration, context, inject) {
|
|
79
|
+
if (!isAllowedUrl(configuration, context.url) || !configuration.traceType) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
80
82
|
|
|
81
|
-
|
|
82
|
-
return window.crypto || window.msCrypto;
|
|
83
|
-
}
|
|
83
|
+
var tracer;
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
'x-datadog-sampled': '1',
|
|
90
|
-
'x-datadog-sampling-priority': '1',
|
|
91
|
-
'x-datadog-trace-id': traceId.toDecimalString()
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
/* tslint:disable:no-bitwise */
|
|
85
|
+
switch (configuration.traceType) {
|
|
86
|
+
case _browserCore.TraceType.DDTRACE:
|
|
87
|
+
tracer = new _ddtraceTracer.DDtraceTracer();
|
|
88
|
+
break;
|
|
95
89
|
|
|
90
|
+
case _browserCore.TraceType.SKYWALKING_V3:
|
|
91
|
+
tracer = new _skywalkingTracer.SkyWalkingTracer(configuration, context.url);
|
|
92
|
+
break;
|
|
96
93
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
this.buffer[0] = this.buffer[0] & 0x7f;
|
|
101
|
-
}
|
|
94
|
+
case _browserCore.TraceType.ZIPKIN_MULTI_HEADER:
|
|
95
|
+
tracer = new _zipkinMultiTracer.ZipkinMultiTracer(configuration);
|
|
96
|
+
break;
|
|
102
97
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
while (1) {
|
|
111
|
-
var mod = high % radix * 4294967296 + low;
|
|
112
|
-
high = Math.floor(high / radix);
|
|
113
|
-
low = Math.floor(mod / radix);
|
|
114
|
-
str = (mod % radix).toString(radix) + str;
|
|
115
|
-
|
|
116
|
-
if (!high && !low) {
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
98
|
+
case _browserCore.TraceType.JAEGER:
|
|
99
|
+
tracer = new _jaegerTracer.JaegerTracer(configuration);
|
|
100
|
+
break;
|
|
101
|
+
|
|
102
|
+
case _browserCore.TraceType.W3C_TRACEPARENT:
|
|
103
|
+
tracer = new _w3cTraceParentTracer.W3cTraceParentTracer(configuration);
|
|
104
|
+
break;
|
|
120
105
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return this.buffer[offset] * 16777216 + (this.buffer[offset + 1] << 16) + (this.buffer[offset + 2] << 8) + this.buffer[offset + 3];
|
|
106
|
+
case _browserCore.TraceType.ZIPKIN_SINGLE_HEADER:
|
|
107
|
+
tracer = new _zipkinSingleTracer.ZipkinSingleTracer(configuration);
|
|
108
|
+
break;
|
|
109
|
+
|
|
110
|
+
default:
|
|
111
|
+
break;
|
|
128
112
|
}
|
|
129
|
-
|
|
130
|
-
|
|
113
|
+
|
|
114
|
+
if (!tracer || !tracer.isTracingSupported()) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
context.traceId = tracer.getTraceId();
|
|
119
|
+
context.spanId = tracer.getSpanId();
|
|
120
|
+
inject(tracer.makeTracingHeaders());
|
|
121
|
+
}
|
|
@@ -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