@cloudcare/browser-rum 2.2.1 → 2.2.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 +2 -1
- package/bundle/dataflux-rum.js +1 -1
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/domain/configuration.js +7 -0
- package/cjs/domain/rumEventsCollection/resource/resourceCollection.js +1 -1
- package/cjs/domain/tracing/ddtraceTracer.js +4 -4
- package/cjs/domain/tracing/jaegerTracer.js +4 -3
- package/cjs/domain/tracing/skywalkingTracer.js +11 -10
- package/cjs/domain/tracing/tracer.js +9 -6
- package/cjs/domain/tracing/w3cTraceParentTracer.js +5 -4
- package/cjs/domain/tracing/zipkinMultiTracer.js +4 -3
- package/cjs/domain/tracing/zipkinSingleTracer.js +5 -4
- package/esm/boot/buildEnv.js +1 -1
- package/esm/domain/configuration.js +6 -0
- package/esm/domain/rumEventsCollection/resource/resourceCollection.js +1 -1
- package/esm/domain/tracing/ddtraceTracer.js +4 -4
- package/esm/domain/tracing/jaegerTracer.js +4 -3
- package/esm/domain/tracing/skywalkingTracer.js +11 -10
- package/esm/domain/tracing/tracer.js +10 -7
- package/esm/domain/tracing/w3cTraceParentTracer.js +5 -4
- package/esm/domain/tracing/zipkinMultiTracer.js +4 -3
- package/esm/domain/tracing/zipkinSingleTracer.js +5 -4
- package/package.json +3 -3
- package/src/domain/configuration.js +8 -0
- package/src/domain/rumEventsCollection/resource/resourceCollection.js +15 -11
- package/src/domain/tracing/ddtraceTracer.js +11 -11
- package/src/domain/tracing/jaegerTracer.js +36 -28
- package/src/domain/tracing/skywalkingTracer.js +94 -53
- package/src/domain/tracing/tracer.js +14 -7
- package/src/domain/tracing/w3cTraceParentTracer.js +35 -27
- package/src/domain/tracing/zipkinMultiTracer.js +29 -28
- package/src/domain/tracing/zipkinSingleTracer.js +34 -27
|
@@ -19,12 +19,12 @@ function uuid() {
|
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
23
|
-
* @param {*} traceId
|
|
24
|
-
* @param {*} traceSegmentId
|
|
25
|
-
* @param {*} applicationId
|
|
26
|
-
* @param {*} version
|
|
27
|
-
* @param {*} requestUrlHost
|
|
22
|
+
*
|
|
23
|
+
* @param {*} traceId
|
|
24
|
+
* @param {*} traceSegmentId
|
|
25
|
+
* @param {*} applicationId
|
|
26
|
+
* @param {*} version
|
|
27
|
+
* @param {*} requestUrlHost
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
30
|
|
|
@@ -44,19 +44,20 @@ function getSkyWalkingSw8(traceId, traceSegmentId, applicationId, env, version,
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
|
-
*
|
|
47
|
+
*
|
|
48
48
|
* @param {*} configuration 配置信息
|
|
49
49
|
* @param {*} requestUrl 请求的url
|
|
50
50
|
*/
|
|
51
51
|
|
|
52
52
|
|
|
53
|
-
function SkyWalkingTracer(configuration, requestUrl) {
|
|
53
|
+
function SkyWalkingTracer(configuration, requestUrl, traceSampled) {
|
|
54
54
|
this._spanId = uuid();
|
|
55
55
|
this._traceId = uuid();
|
|
56
56
|
this._applicationId = configuration.applicationId;
|
|
57
57
|
this._env = configuration.env;
|
|
58
58
|
this._version = configuration.version;
|
|
59
59
|
this._urlParse = (0, _browserCore.urlParse)(requestUrl).getParse();
|
|
60
|
+
this._traceSampled = traceSampled;
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
SkyWalkingTracer.prototype = {
|
|
@@ -80,14 +81,14 @@ SkyWalkingTracer.prototype = {
|
|
|
80
81
|
var peer = String((0, _browserCore.base64Encode)(this._urlParse.Host));
|
|
81
82
|
var index = '0'; // var values = `${1}-${traceIdStr}-${segmentId}-${index}-${service}-${instance}-${endpoint}-${peer}`;
|
|
82
83
|
|
|
83
|
-
return '1-' + traceIdStr + '-' + segmentId + '-' + index + '-' + service + '-' + instance + '-' + endpoint + '-' + peer;
|
|
84
|
+
return (this._traceSampled ? '1' : '0') + '-' + traceIdStr + '-' + segmentId + '-' + index + '-' + service + '-' + instance + '-' + endpoint + '-' + peer;
|
|
84
85
|
} catch (err) {
|
|
85
86
|
return '';
|
|
86
87
|
}
|
|
87
88
|
},
|
|
88
89
|
makeTracingHeaders: function makeTracingHeaders() {
|
|
89
90
|
return {
|
|
90
|
-
|
|
91
|
+
sw8: this.getSkyWalkingSw8()
|
|
91
92
|
};
|
|
92
93
|
}
|
|
93
94
|
};
|
|
@@ -25,6 +25,7 @@ function clearTracingIfNeeded(context) {
|
|
|
25
25
|
if (context.status === 0 && !context.isAborted) {
|
|
26
26
|
context.traceId = undefined;
|
|
27
27
|
context.spanId = undefined;
|
|
28
|
+
context.traceSampled = undefined;
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
31
|
|
|
@@ -93,31 +94,32 @@ function injectHeadersIfTracingAllowed(configuration, context, sessionManager, i
|
|
|
93
94
|
return;
|
|
94
95
|
}
|
|
95
96
|
|
|
97
|
+
var traceSampled = !(0, _browserCore.isNumber)(configuration.tracingSampleRate) || (0, _browserCore.performDraw)(configuration.tracingSampleRate);
|
|
96
98
|
var tracer;
|
|
97
99
|
|
|
98
100
|
switch (configuration.traceType) {
|
|
99
101
|
case _browserCore.TraceType.DDTRACE:
|
|
100
|
-
tracer = new _ddtraceTracer.DDtraceTracer();
|
|
102
|
+
tracer = new _ddtraceTracer.DDtraceTracer(traceSampled);
|
|
101
103
|
break;
|
|
102
104
|
|
|
103
105
|
case _browserCore.TraceType.SKYWALKING_V3:
|
|
104
|
-
tracer = new _skywalkingTracer.SkyWalkingTracer(configuration, context.url);
|
|
106
|
+
tracer = new _skywalkingTracer.SkyWalkingTracer(configuration, context.url, traceSampled);
|
|
105
107
|
break;
|
|
106
108
|
|
|
107
109
|
case _browserCore.TraceType.ZIPKIN_MULTI_HEADER:
|
|
108
|
-
tracer = new _zipkinMultiTracer.ZipkinMultiTracer(configuration);
|
|
110
|
+
tracer = new _zipkinMultiTracer.ZipkinMultiTracer(configuration, traceSampled);
|
|
109
111
|
break;
|
|
110
112
|
|
|
111
113
|
case _browserCore.TraceType.JAEGER:
|
|
112
|
-
tracer = new _jaegerTracer.JaegerTracer(configuration);
|
|
114
|
+
tracer = new _jaegerTracer.JaegerTracer(configuration, traceSampled);
|
|
113
115
|
break;
|
|
114
116
|
|
|
115
117
|
case _browserCore.TraceType.W3C_TRACEPARENT:
|
|
116
|
-
tracer = new _w3cTraceParentTracer.W3cTraceParentTracer(configuration);
|
|
118
|
+
tracer = new _w3cTraceParentTracer.W3cTraceParentTracer(configuration, traceSampled);
|
|
117
119
|
break;
|
|
118
120
|
|
|
119
121
|
case _browserCore.TraceType.ZIPKIN_SINGLE_HEADER:
|
|
120
|
-
tracer = new _zipkinSingleTracer.ZipkinSingleTracer(configuration);
|
|
122
|
+
tracer = new _zipkinSingleTracer.ZipkinSingleTracer(configuration, traceSampled);
|
|
121
123
|
break;
|
|
122
124
|
|
|
123
125
|
default:
|
|
@@ -130,5 +132,6 @@ function injectHeadersIfTracingAllowed(configuration, context, sessionManager, i
|
|
|
130
132
|
|
|
131
133
|
context.traceId = tracer.getTraceId();
|
|
132
134
|
context.spanId = tracer.getSpanId();
|
|
135
|
+
context.traceSampled = traceSampled;
|
|
133
136
|
inject(tracer.makeTracingHeaders());
|
|
134
137
|
}
|
|
@@ -18,15 +18,16 @@ function randomTraceId() {
|
|
|
18
18
|
return n;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
21
|
+
*
|
|
22
22
|
* @param {*} configuration 配置信息
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
|
|
26
|
-
function W3cTraceParentTracer(configuration) {
|
|
26
|
+
function W3cTraceParentTracer(configuration, traceSampled) {
|
|
27
27
|
var rootSpanId = randomTraceId();
|
|
28
28
|
this._traceId = randomTraceId() + rootSpanId;
|
|
29
29
|
this._spanId = rootSpanId;
|
|
30
|
+
this._traceSampled = traceSampled;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
W3cTraceParentTracer.prototype = {
|
|
@@ -41,11 +42,11 @@ W3cTraceParentTracer.prototype = {
|
|
|
41
42
|
},
|
|
42
43
|
getTraceParent: function getTraceParent() {
|
|
43
44
|
// '{version}-{traceId}-{spanId}-{sampleDecision}'
|
|
44
|
-
return '00-' + this._traceId + '-' + this._spanId + '-01';
|
|
45
|
+
return '00-' + this._traceId + '-' + this._spanId + '-' + (this._traceSampled ? '01' : '00');
|
|
45
46
|
},
|
|
46
47
|
makeTracingHeaders: function makeTracingHeaders() {
|
|
47
48
|
return {
|
|
48
|
-
|
|
49
|
+
traceparent: this.getTraceParent()
|
|
49
50
|
};
|
|
50
51
|
}
|
|
51
52
|
};
|
|
@@ -18,12 +18,12 @@ function randomTraceId() {
|
|
|
18
18
|
return n;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
21
|
+
*
|
|
22
22
|
* @param {*} configuration 配置信息
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
|
|
26
|
-
function ZipkinMultiTracer(configuration) {
|
|
26
|
+
function ZipkinMultiTracer(configuration, traceSampled) {
|
|
27
27
|
var rootSpanId = randomTraceId();
|
|
28
28
|
|
|
29
29
|
if (configuration.traceId128Bit) {
|
|
@@ -34,6 +34,7 @@ function ZipkinMultiTracer(configuration) {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
this._spanId = rootSpanId;
|
|
37
|
+
this._traceSampled = traceSampled;
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
ZipkinMultiTracer.prototype = {
|
|
@@ -51,7 +52,7 @@ ZipkinMultiTracer.prototype = {
|
|
|
51
52
|
'X-B3-TraceId': this.getTraceId(),
|
|
52
53
|
'X-B3-SpanId': this.getSpanId(),
|
|
53
54
|
// 'X-B3-ParentSpanId': '',
|
|
54
|
-
'X-B3-Sampled': '1' // 'X-B3-Flags': '0'
|
|
55
|
+
'X-B3-Sampled': this._traceSampled ? '1' : '0' // 'X-B3-Flags': '0'
|
|
55
56
|
|
|
56
57
|
};
|
|
57
58
|
}
|
|
@@ -18,15 +18,16 @@ function randomTraceId() {
|
|
|
18
18
|
return n;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
21
|
+
*
|
|
22
22
|
* @param {*} configuration 配置信息
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
|
|
26
|
-
function ZipkinSingleTracer(configuration) {
|
|
26
|
+
function ZipkinSingleTracer(configuration, traceSampled) {
|
|
27
27
|
var rootSpanId = randomTraceId();
|
|
28
28
|
this._traceId = randomTraceId() + rootSpanId;
|
|
29
29
|
this._spanId = rootSpanId;
|
|
30
|
+
this._traceSampled = traceSampled;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
ZipkinSingleTracer.prototype = {
|
|
@@ -41,11 +42,11 @@ ZipkinSingleTracer.prototype = {
|
|
|
41
42
|
},
|
|
42
43
|
getB3Str: function getB3Str() {
|
|
43
44
|
//{TraceId}-{SpanId}-{SamplingState}-{ParentSpanId}
|
|
44
|
-
return this._traceId + '-' + this._spanId + '-1';
|
|
45
|
+
return this._traceId + '-' + this._spanId + '-' + (this._traceSampled ? '1' : '0');
|
|
45
46
|
},
|
|
46
47
|
makeTracingHeaders: function makeTracingHeaders() {
|
|
47
48
|
return {
|
|
48
|
-
|
|
49
|
+
b3: this.getB3Str()
|
|
49
50
|
};
|
|
50
51
|
}
|
|
51
52
|
};
|
package/esm/boot/buildEnv.js
CHANGED
|
@@ -31,6 +31,11 @@ export function validateAndBuildRumConfiguration(initConfiguration) {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
if (initConfiguration.tracingSampleRate !== undefined && !isPercentage(initConfiguration.tracingSampleRate)) {
|
|
35
|
+
display.error('Tracing Sample Rate should be a number between 0 and 100');
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
34
39
|
if (initConfiguration.excludedActivityUrls !== undefined && !isArray(initConfiguration.excludedActivityUrls)) {
|
|
35
40
|
display.error('Excluded Activity Urls should be an array');
|
|
36
41
|
return;
|
|
@@ -47,6 +52,7 @@ export function validateAndBuildRumConfiguration(initConfiguration) {
|
|
|
47
52
|
applicationId: initConfiguration.applicationId,
|
|
48
53
|
actionNameAttribute: initConfiguration.actionNameAttribute,
|
|
49
54
|
sessionReplaySampleRate: isNullUndefinedDefaultValue(initConfiguration.sessionReplaySampleRate, 100),
|
|
55
|
+
tracingSampleRate: initConfiguration.tracingSampleRate,
|
|
50
56
|
allowedTracingOrigins: isNullUndefinedDefaultValue(initConfiguration.allowedTracingOrigins || initConfiguration.allowedDDTracingOrigins, []),
|
|
51
57
|
excludedActivityUrls: isNullUndefinedDefaultValue(initConfiguration.excludedActivityUrls, []),
|
|
52
58
|
trackInteractions: !!initConfiguration.trackInteractions || trackFrustrations,
|
|
@@ -110,7 +110,7 @@ function toPerformanceEntryRepresentation(entry) {
|
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
function computeRequestTracingInfo(request) {
|
|
113
|
-
var hasBeenTraced = request.traceId && request.spanId;
|
|
113
|
+
var hasBeenTraced = request.traceSampled && request.traceId && request.spanId;
|
|
114
114
|
|
|
115
115
|
if (!hasBeenTraced) {
|
|
116
116
|
return undefined;
|
|
@@ -36,14 +36,15 @@ function getCrypto() {
|
|
|
36
36
|
return window.crypto || window.msCrypto;
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
|
-
*
|
|
39
|
+
*
|
|
40
40
|
* @param {*} configuration 配置信息
|
|
41
41
|
*/
|
|
42
42
|
|
|
43
43
|
|
|
44
|
-
export function DDtraceTracer(
|
|
44
|
+
export function DDtraceTracer(traceSampled) {
|
|
45
45
|
this._spanId = new TraceIdentifier().toDecimalString();
|
|
46
46
|
this._traceId = new TraceIdentifier().toDecimalString();
|
|
47
|
+
this._traceSampled = traceSampled;
|
|
47
48
|
}
|
|
48
49
|
DDtraceTracer.prototype = {
|
|
49
50
|
isTracingSupported: function isTracingSupported() {
|
|
@@ -59,8 +60,7 @@ DDtraceTracer.prototype = {
|
|
|
59
60
|
return {
|
|
60
61
|
'x-datadog-origin': 'rum',
|
|
61
62
|
'x-datadog-parent-id': this.getSpanId(),
|
|
62
|
-
'x-datadog-
|
|
63
|
-
'x-datadog-sampling-priority': '1',
|
|
63
|
+
'x-datadog-sampling-priority': this._traceSampled ? '2' : '-1',
|
|
64
64
|
'x-datadog-trace-id': this.getTraceId()
|
|
65
65
|
};
|
|
66
66
|
}
|
|
@@ -11,12 +11,12 @@ function randomTraceId() {
|
|
|
11
11
|
return n;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
*
|
|
15
15
|
* @param {*} configuration 配置信息
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
export function JaegerTracer(configuration) {
|
|
19
|
+
export function JaegerTracer(configuration, traceSampled) {
|
|
20
20
|
var rootSpanId = randomTraceId(); // this._traceId = randomTraceId() + rootSpanId // 默认用128bit,兼容其他配置
|
|
21
21
|
|
|
22
22
|
if (configuration.traceId128Bit) {
|
|
@@ -27,6 +27,7 @@ export function JaegerTracer(configuration) {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
this._spanId = rootSpanId;
|
|
30
|
+
this._traceSampled = traceSampled;
|
|
30
31
|
}
|
|
31
32
|
JaegerTracer.prototype = {
|
|
32
33
|
isTracingSupported: function isTracingSupported() {
|
|
@@ -40,7 +41,7 @@ JaegerTracer.prototype = {
|
|
|
40
41
|
},
|
|
41
42
|
getUberTraceId: function getUberTraceId() {
|
|
42
43
|
//{trace-id}:{span-id}:{parent-span-id}:{flags}
|
|
43
|
-
return this._traceId + ':' + this._spanId + ':' + '0' + ':' + '1';
|
|
44
|
+
return this._traceId + ':' + this._spanId + ':' + '0' + ':' + (this._traceSampled ? '1' : '0');
|
|
44
45
|
},
|
|
45
46
|
makeTracingHeaders: function makeTracingHeaders() {
|
|
46
47
|
return {
|
|
@@ -11,12 +11,12 @@ function uuid() {
|
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
* @param {*} traceId
|
|
16
|
-
* @param {*} traceSegmentId
|
|
17
|
-
* @param {*} applicationId
|
|
18
|
-
* @param {*} version
|
|
19
|
-
* @param {*} requestUrlHost
|
|
14
|
+
*
|
|
15
|
+
* @param {*} traceId
|
|
16
|
+
* @param {*} traceSegmentId
|
|
17
|
+
* @param {*} applicationId
|
|
18
|
+
* @param {*} version
|
|
19
|
+
* @param {*} requestUrlHost
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
|
|
@@ -36,19 +36,20 @@ function getSkyWalkingSw8(traceId, traceSegmentId, applicationId, env, version,
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
|
-
*
|
|
39
|
+
*
|
|
40
40
|
* @param {*} configuration 配置信息
|
|
41
41
|
* @param {*} requestUrl 请求的url
|
|
42
42
|
*/
|
|
43
43
|
|
|
44
44
|
|
|
45
|
-
export function SkyWalkingTracer(configuration, requestUrl) {
|
|
45
|
+
export function SkyWalkingTracer(configuration, requestUrl, traceSampled) {
|
|
46
46
|
this._spanId = uuid();
|
|
47
47
|
this._traceId = uuid();
|
|
48
48
|
this._applicationId = configuration.applicationId;
|
|
49
49
|
this._env = configuration.env;
|
|
50
50
|
this._version = configuration.version;
|
|
51
51
|
this._urlParse = urlParse(requestUrl).getParse();
|
|
52
|
+
this._traceSampled = traceSampled;
|
|
52
53
|
}
|
|
53
54
|
SkyWalkingTracer.prototype = {
|
|
54
55
|
isTracingSupported: function isTracingSupported() {
|
|
@@ -71,14 +72,14 @@ SkyWalkingTracer.prototype = {
|
|
|
71
72
|
var peer = String(base64Encode(this._urlParse.Host));
|
|
72
73
|
var index = '0'; // var values = `${1}-${traceIdStr}-${segmentId}-${index}-${service}-${instance}-${endpoint}-${peer}`;
|
|
73
74
|
|
|
74
|
-
return '1-' + traceIdStr + '-' + segmentId + '-' + index + '-' + service + '-' + instance + '-' + endpoint + '-' + peer;
|
|
75
|
+
return (this._traceSampled ? '1' : '0') + '-' + traceIdStr + '-' + segmentId + '-' + index + '-' + service + '-' + instance + '-' + endpoint + '-' + peer;
|
|
75
76
|
} catch (err) {
|
|
76
77
|
return '';
|
|
77
78
|
}
|
|
78
79
|
},
|
|
79
80
|
makeTracingHeaders: function makeTracingHeaders() {
|
|
80
81
|
return {
|
|
81
|
-
|
|
82
|
+
sw8: this.getSkyWalkingSw8()
|
|
82
83
|
};
|
|
83
84
|
}
|
|
84
85
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { objectEntries, each, shallowClone, isArray, TraceType, getOrigin } from '@cloudcare/browser-core';
|
|
1
|
+
import { objectEntries, each, shallowClone, isArray, TraceType, getOrigin, performDraw, isNumber } from '@cloudcare/browser-core';
|
|
2
2
|
import { DDtraceTracer } from './ddtraceTracer';
|
|
3
3
|
import { SkyWalkingTracer } from './skywalkingTracer';
|
|
4
4
|
import { JaegerTracer } from './jaegerTracer';
|
|
@@ -9,6 +9,7 @@ export function clearTracingIfNeeded(context) {
|
|
|
9
9
|
if (context.status === 0 && !context.isAborted) {
|
|
10
10
|
context.traceId = undefined;
|
|
11
11
|
context.spanId = undefined;
|
|
12
|
+
context.traceSampled = undefined;
|
|
12
13
|
}
|
|
13
14
|
}
|
|
14
15
|
export function startTracer(configuration, sessionManager) {
|
|
@@ -76,31 +77,32 @@ export function injectHeadersIfTracingAllowed(configuration, context, sessionMan
|
|
|
76
77
|
return;
|
|
77
78
|
}
|
|
78
79
|
|
|
80
|
+
var traceSampled = !isNumber(configuration.tracingSampleRate) || performDraw(configuration.tracingSampleRate);
|
|
79
81
|
var tracer;
|
|
80
82
|
|
|
81
83
|
switch (configuration.traceType) {
|
|
82
84
|
case TraceType.DDTRACE:
|
|
83
|
-
tracer = new DDtraceTracer();
|
|
85
|
+
tracer = new DDtraceTracer(traceSampled);
|
|
84
86
|
break;
|
|
85
87
|
|
|
86
88
|
case TraceType.SKYWALKING_V3:
|
|
87
|
-
tracer = new SkyWalkingTracer(configuration, context.url);
|
|
89
|
+
tracer = new SkyWalkingTracer(configuration, context.url, traceSampled);
|
|
88
90
|
break;
|
|
89
91
|
|
|
90
92
|
case TraceType.ZIPKIN_MULTI_HEADER:
|
|
91
|
-
tracer = new ZipkinMultiTracer(configuration);
|
|
93
|
+
tracer = new ZipkinMultiTracer(configuration, traceSampled);
|
|
92
94
|
break;
|
|
93
95
|
|
|
94
96
|
case TraceType.JAEGER:
|
|
95
|
-
tracer = new JaegerTracer(configuration);
|
|
97
|
+
tracer = new JaegerTracer(configuration, traceSampled);
|
|
96
98
|
break;
|
|
97
99
|
|
|
98
100
|
case TraceType.W3C_TRACEPARENT:
|
|
99
|
-
tracer = new W3cTraceParentTracer(configuration);
|
|
101
|
+
tracer = new W3cTraceParentTracer(configuration, traceSampled);
|
|
100
102
|
break;
|
|
101
103
|
|
|
102
104
|
case TraceType.ZIPKIN_SINGLE_HEADER:
|
|
103
|
-
tracer = new ZipkinSingleTracer(configuration);
|
|
105
|
+
tracer = new ZipkinSingleTracer(configuration, traceSampled);
|
|
104
106
|
break;
|
|
105
107
|
|
|
106
108
|
default:
|
|
@@ -113,5 +115,6 @@ export function injectHeadersIfTracingAllowed(configuration, context, sessionMan
|
|
|
113
115
|
|
|
114
116
|
context.traceId = tracer.getTraceId();
|
|
115
117
|
context.spanId = tracer.getSpanId();
|
|
118
|
+
context.traceSampled = traceSampled;
|
|
116
119
|
inject(tracer.makeTracingHeaders());
|
|
117
120
|
}
|
|
@@ -11,15 +11,16 @@ function randomTraceId() {
|
|
|
11
11
|
return n;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
*
|
|
15
15
|
* @param {*} configuration 配置信息
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
export function W3cTraceParentTracer(configuration) {
|
|
19
|
+
export function W3cTraceParentTracer(configuration, traceSampled) {
|
|
20
20
|
var rootSpanId = randomTraceId();
|
|
21
21
|
this._traceId = randomTraceId() + rootSpanId;
|
|
22
22
|
this._spanId = rootSpanId;
|
|
23
|
+
this._traceSampled = traceSampled;
|
|
23
24
|
}
|
|
24
25
|
W3cTraceParentTracer.prototype = {
|
|
25
26
|
isTracingSupported: function isTracingSupported() {
|
|
@@ -33,11 +34,11 @@ W3cTraceParentTracer.prototype = {
|
|
|
33
34
|
},
|
|
34
35
|
getTraceParent: function getTraceParent() {
|
|
35
36
|
// '{version}-{traceId}-{spanId}-{sampleDecision}'
|
|
36
|
-
return '00-' + this._traceId + '-' + this._spanId + '-01';
|
|
37
|
+
return '00-' + this._traceId + '-' + this._spanId + '-' + (this._traceSampled ? '01' : '00');
|
|
37
38
|
},
|
|
38
39
|
makeTracingHeaders: function makeTracingHeaders() {
|
|
39
40
|
return {
|
|
40
|
-
|
|
41
|
+
traceparent: this.getTraceParent()
|
|
41
42
|
};
|
|
42
43
|
}
|
|
43
44
|
};
|
|
@@ -11,12 +11,12 @@ function randomTraceId() {
|
|
|
11
11
|
return n;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
*
|
|
15
15
|
* @param {*} configuration 配置信息
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
export function ZipkinMultiTracer(configuration) {
|
|
19
|
+
export function ZipkinMultiTracer(configuration, traceSampled) {
|
|
20
20
|
var rootSpanId = randomTraceId();
|
|
21
21
|
|
|
22
22
|
if (configuration.traceId128Bit) {
|
|
@@ -27,6 +27,7 @@ export function ZipkinMultiTracer(configuration) {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
this._spanId = rootSpanId;
|
|
30
|
+
this._traceSampled = traceSampled;
|
|
30
31
|
}
|
|
31
32
|
ZipkinMultiTracer.prototype = {
|
|
32
33
|
isTracingSupported: function isTracingSupported() {
|
|
@@ -43,7 +44,7 @@ ZipkinMultiTracer.prototype = {
|
|
|
43
44
|
'X-B3-TraceId': this.getTraceId(),
|
|
44
45
|
'X-B3-SpanId': this.getSpanId(),
|
|
45
46
|
// 'X-B3-ParentSpanId': '',
|
|
46
|
-
'X-B3-Sampled': '1' // 'X-B3-Flags': '0'
|
|
47
|
+
'X-B3-Sampled': this._traceSampled ? '1' : '0' // 'X-B3-Flags': '0'
|
|
47
48
|
|
|
48
49
|
};
|
|
49
50
|
}
|
|
@@ -11,15 +11,16 @@ function randomTraceId() {
|
|
|
11
11
|
return n;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
*
|
|
15
15
|
* @param {*} configuration 配置信息
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
export function ZipkinSingleTracer(configuration) {
|
|
19
|
+
export function ZipkinSingleTracer(configuration, traceSampled) {
|
|
20
20
|
var rootSpanId = randomTraceId();
|
|
21
21
|
this._traceId = randomTraceId() + rootSpanId;
|
|
22
22
|
this._spanId = rootSpanId;
|
|
23
|
+
this._traceSampled = traceSampled;
|
|
23
24
|
}
|
|
24
25
|
ZipkinSingleTracer.prototype = {
|
|
25
26
|
isTracingSupported: function isTracingSupported() {
|
|
@@ -33,11 +34,11 @@ ZipkinSingleTracer.prototype = {
|
|
|
33
34
|
},
|
|
34
35
|
getB3Str: function getB3Str() {
|
|
35
36
|
//{TraceId}-{SpanId}-{SamplingState}-{ParentSpanId}
|
|
36
|
-
return this._traceId + '-' + this._spanId + '-1';
|
|
37
|
+
return this._traceId + '-' + this._spanId + '-' + (this._traceSampled ? '1' : '0');
|
|
37
38
|
},
|
|
38
39
|
makeTracingHeaders: function makeTracingHeaders() {
|
|
39
40
|
return {
|
|
40
|
-
|
|
41
|
+
b3: this.getB3Str()
|
|
41
42
|
};
|
|
42
43
|
}
|
|
43
44
|
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudcare/browser-rum",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.2",
|
|
4
4
|
"main": "cjs/index.js",
|
|
5
5
|
"module": "esm/index.js",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@cloudcare/browser-core": "1.2.
|
|
7
|
+
"@cloudcare/browser-core": "1.2.1"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"dev": "webpack serve --open --mode=development",
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"license": "MIT",
|
|
30
30
|
"homepage": "https://github.com/CloudCare/dataflux-rum-sdk-javascript/blob/master/packages/rum/README.md",
|
|
31
31
|
"description": "DataFlux RUM Web 端数据指标监控",
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "e8411cbf5448e90b81a5e902c54cceb44e6e2501"
|
|
33
33
|
}
|
|
@@ -43,6 +43,13 @@ export function validateAndBuildRumConfiguration(initConfiguration) {
|
|
|
43
43
|
return
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
+
if (
|
|
47
|
+
initConfiguration.tracingSampleRate !== undefined &&
|
|
48
|
+
!isPercentage(initConfiguration.tracingSampleRate)
|
|
49
|
+
) {
|
|
50
|
+
display.error('Tracing Sample Rate should be a number between 0 and 100')
|
|
51
|
+
return
|
|
52
|
+
}
|
|
46
53
|
if (
|
|
47
54
|
initConfiguration.excludedActivityUrls !== undefined &&
|
|
48
55
|
!isArray(initConfiguration.excludedActivityUrls)
|
|
@@ -66,6 +73,7 @@ export function validateAndBuildRumConfiguration(initConfiguration) {
|
|
|
66
73
|
initConfiguration.sessionReplaySampleRate,
|
|
67
74
|
100
|
|
68
75
|
),
|
|
76
|
+
tracingSampleRate: initConfiguration.tracingSampleRate,
|
|
69
77
|
allowedTracingOrigins: isNullUndefinedDefaultValue(
|
|
70
78
|
initConfiguration.allowedTracingOrigins ||
|
|
71
79
|
initConfiguration.allowedDDTracingOrigins,
|
|
@@ -37,7 +37,10 @@ export function startResourceCollection(lifeCycle, configuration) {
|
|
|
37
37
|
function (entries) {
|
|
38
38
|
for (var entry of entries) {
|
|
39
39
|
if (entry.entryType === 'resource' && !isRequestKind(entry)) {
|
|
40
|
-
lifeCycle.notify(
|
|
40
|
+
lifeCycle.notify(
|
|
41
|
+
LifeCycleEventType.RAW_RUM_EVENT_COLLECTED,
|
|
42
|
+
processResourceEntry(entry)
|
|
43
|
+
)
|
|
41
44
|
}
|
|
42
45
|
}
|
|
43
46
|
}
|
|
@@ -77,16 +80,17 @@ function processRequest(request) {
|
|
|
77
80
|
tracingInfo,
|
|
78
81
|
correspondingTimingOverrides
|
|
79
82
|
)
|
|
80
|
-
return {
|
|
81
|
-
startTime: startClocks.relative,
|
|
83
|
+
return {
|
|
84
|
+
startTime: startClocks.relative,
|
|
82
85
|
rawRumEvent: resourceEvent,
|
|
83
86
|
domainContext: {
|
|
84
|
-
performanceEntry:
|
|
87
|
+
performanceEntry:
|
|
88
|
+
matchingTiming && toPerformanceEntryRepresentation(matchingTiming),
|
|
85
89
|
xhr: request.xhr,
|
|
86
90
|
response: request.response,
|
|
87
91
|
requestInput: request.input,
|
|
88
92
|
requestInit: request.init,
|
|
89
|
-
error: request.error
|
|
93
|
+
error: request.error
|
|
90
94
|
}
|
|
91
95
|
}
|
|
92
96
|
}
|
|
@@ -123,12 +127,12 @@ function processResourceEntry(entry) {
|
|
|
123
127
|
tracingInfo,
|
|
124
128
|
entryMetrics
|
|
125
129
|
)
|
|
126
|
-
return {
|
|
127
|
-
startTime: startClocks.relative,
|
|
130
|
+
return {
|
|
131
|
+
startTime: startClocks.relative,
|
|
128
132
|
rawRumEvent: resourceEvent,
|
|
129
133
|
domainContext: {
|
|
130
|
-
performanceEntry: toPerformanceEntryRepresentation(entry)
|
|
131
|
-
}
|
|
134
|
+
performanceEntry: toPerformanceEntryRepresentation(entry)
|
|
135
|
+
}
|
|
132
136
|
}
|
|
133
137
|
}
|
|
134
138
|
|
|
@@ -151,7 +155,7 @@ function toPerformanceEntryRepresentation(entry) {
|
|
|
151
155
|
return entry
|
|
152
156
|
}
|
|
153
157
|
function computeRequestTracingInfo(request) {
|
|
154
|
-
var hasBeenTraced = request.traceId && request.spanId
|
|
158
|
+
var hasBeenTraced = request.traceSampled && request.traceId && request.spanId
|
|
155
159
|
if (!hasBeenTraced) {
|
|
156
160
|
return undefined
|
|
157
161
|
}
|
|
@@ -166,4 +170,4 @@ function computeRequestTracingInfo(request) {
|
|
|
166
170
|
|
|
167
171
|
function computeEntryTracingInfo(entry) {
|
|
168
172
|
return entry.traceId ? { _dd: { traceId: entry.traceId } } : undefined
|
|
169
|
-
}
|
|
173
|
+
}
|