@cloudcare/browser-rum 3.0.17 → 3.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle/dataflux-rum.js +1 -1
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/domain/configuration.js +130 -14
- package/cjs/domain/tracing/ddtraceTracer.js +6 -43
- package/cjs/domain/tracing/jaegerTracer.js +8 -27
- package/cjs/domain/tracing/traceIdentifier.js +49 -0
- package/cjs/domain/tracing/tracer.js +25 -19
- package/cjs/domain/tracing/w3cTraceParentTracer.js +11 -22
- package/cjs/domain/tracing/zipkinMultiTracer.js +9 -28
- package/cjs/domain/tracing/zipkinSingleTracer.js +7 -20
- package/esm/boot/buildEnv.js +1 -1
- package/esm/domain/configuration.js +126 -14
- package/esm/domain/tracing/ddtraceTracer.js +5 -42
- package/esm/domain/tracing/jaegerTracer.js +8 -27
- package/esm/domain/tracing/traceIdentifier.js +40 -0
- package/esm/domain/tracing/tracer.js +23 -20
- package/esm/domain/tracing/w3cTraceParentTracer.js +11 -22
- package/esm/domain/tracing/zipkinMultiTracer.js +9 -28
- package/esm/domain/tracing/zipkinSingleTracer.js +7 -20
- package/package.json +3 -3
- package/src/domain/configuration.js +148 -19
- package/src/domain/tracing/ddtraceTracer.js +5 -46
- package/src/domain/tracing/jaegerTracer.js +11 -24
- package/src/domain/tracing/traceIdentifier.js +43 -0
- package/src/domain/tracing/tracer.js +34 -27
- package/src/domain/tracing/w3cTraceParentTracer.js +17 -21
- package/src/domain/tracing/zipkinMultiTracer.js +11 -23
- package/src/domain/tracing/zipkinSingleTracer.js +8 -18
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { assign, display, isPercentage, validateAndBuildConfiguration, isArray, TraceType, isNullUndefinedDefaultValue, DefaultPrivacyLevel, objectHasValue } from '@cloudcare/browser-core';
|
|
1
|
+
import { assign, display, isPercentage, validateAndBuildConfiguration, isArray, TraceType, isNullUndefinedDefaultValue, DefaultPrivacyLevel, objectHasValue, isMatchOption, getOrigin, each } from '@cloudcare/browser-core';
|
|
2
2
|
import { buildEnv } from '../boot/buildEnv';
|
|
3
|
+
import { isTracingOption } from '../domain/tracing/tracer';
|
|
3
4
|
export function validateAndBuildRumConfiguration(initConfiguration) {
|
|
4
5
|
if (!initConfiguration.applicationId) {
|
|
5
6
|
display.error('Application ID is not configured, no RUM data will be collected.');
|
|
@@ -17,19 +18,23 @@ export function validateAndBuildRumConfiguration(initConfiguration) {
|
|
|
17
18
|
return;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
var allowedTracingUrls = validateAndBuildTracingOptions(initConfiguration);
|
|
22
|
+
|
|
23
|
+
if (!allowedTracingUrls) {
|
|
24
|
+
return;
|
|
25
|
+
} // if (initConfiguration.allowedTracingOrigins !== undefined) {
|
|
26
|
+
// if (!isArray(initConfiguration.allowedTracingOrigins)) {
|
|
27
|
+
// display.error('Allowed Tracing Origins should be an array')
|
|
28
|
+
// return
|
|
29
|
+
// }
|
|
30
|
+
// }
|
|
31
|
+
// if (initConfiguration.allowedDDTracingOrigins !== undefined) {
|
|
32
|
+
// if (!isArray(initConfiguration.allowedDDTracingOrigins)) {
|
|
33
|
+
// display.error('Allowed Tracing Origins should be an array')
|
|
34
|
+
// return
|
|
35
|
+
// }
|
|
36
|
+
// }
|
|
26
37
|
|
|
27
|
-
if (initConfiguration.allowedDDTracingOrigins !== undefined) {
|
|
28
|
-
if (!isArray(initConfiguration.allowedDDTracingOrigins)) {
|
|
29
|
-
display.error('Allowed Tracing Origins should be an array');
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
38
|
|
|
34
39
|
if (initConfiguration.tracingSampleRate !== undefined && !isPercentage(initConfiguration.tracingSampleRate)) {
|
|
35
40
|
display.error('Tracing Sample Rate should be a number between 0 and 100');
|
|
@@ -54,7 +59,7 @@ export function validateAndBuildRumConfiguration(initConfiguration) {
|
|
|
54
59
|
actionNameAttribute: initConfiguration.actionNameAttribute,
|
|
55
60
|
sessionReplaySampleRate: isNullUndefinedDefaultValue(initConfiguration.sessionReplaySampleRate, 100),
|
|
56
61
|
tracingSampleRate: initConfiguration.tracingSampleRate,
|
|
57
|
-
|
|
62
|
+
allowedTracingUrls: allowedTracingUrls,
|
|
58
63
|
excludedActivityUrls: isNullUndefinedDefaultValue(initConfiguration.excludedActivityUrls, []),
|
|
59
64
|
trackUserInteractions: trackUserInteractions || trackFrustrations,
|
|
60
65
|
trackFrustrations: trackFrustrations,
|
|
@@ -65,4 +70,111 @@ export function validateAndBuildRumConfiguration(initConfiguration) {
|
|
|
65
70
|
// 是否需要对webview 发送数据,需要装我们对应ios sdk
|
|
66
71
|
defaultPrivacyLevel: objectHasValue(DefaultPrivacyLevel, initConfiguration.defaultPrivacyLevel) ? initConfiguration.defaultPrivacyLevel : DefaultPrivacyLevel.MASK_USER_INPUT
|
|
67
72
|
}, baseConfiguration, buildEnv);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Handles allowedTracingUrls and processes legacy allowedTracingOrigins
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
function validateAndBuildTracingOptions(initConfiguration) {
|
|
79
|
+
// Advise about parameters precedence.
|
|
80
|
+
if (initConfiguration.allowedTracingUrls !== undefined && initConfiguration.allowedTracingOrigins !== undefined) {
|
|
81
|
+
display.warn('Both allowedTracingUrls and allowedTracingOrigins (deprecated) have been defined. The parameter allowedTracingUrls will override allowedTracingOrigins.');
|
|
82
|
+
} // Handle allowedTracingUrls first
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
if (initConfiguration.allowedTracingUrls !== undefined) {
|
|
86
|
+
if (!isArray(initConfiguration.allowedTracingUrls)) {
|
|
87
|
+
display.error('Allowed Tracing URLs should be an array');
|
|
88
|
+
return;
|
|
89
|
+
} // if (initConfiguration.allowedTracingUrls.length !== 0 && initConfiguration.service === undefined) {
|
|
90
|
+
// display.error('Service needs to be configured when tracing is enabled')
|
|
91
|
+
// return
|
|
92
|
+
// }
|
|
93
|
+
// Convert from (MatchOption | TracingOption) to TracingOption, remove unknown properties
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
var tracingOptions = [];
|
|
97
|
+
each(initConfiguration.allowedTracingUrls, function (option) {
|
|
98
|
+
if (isMatchOption(option)) {
|
|
99
|
+
tracingOptions.push({
|
|
100
|
+
match: option,
|
|
101
|
+
traceType: isNullUndefinedDefaultValue(initConfiguration.traceType, TraceType.DDTRACE)
|
|
102
|
+
});
|
|
103
|
+
} else if (isTracingOption(option)) {
|
|
104
|
+
tracingOptions.push(option);
|
|
105
|
+
} else {
|
|
106
|
+
display.warn('Allowed Tracing Urls parameters should be a string, RegExp, function, or an object. Ignoring parameter', option);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
return tracingOptions;
|
|
110
|
+
} // Handle conversion of allowedTracingOrigins to allowedTracingUrls
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
if (initConfiguration.allowedTracingOrigins !== undefined) {
|
|
114
|
+
if (!isArray(initConfiguration.allowedTracingOrigins)) {
|
|
115
|
+
display.error('Allowed Tracing Origins should be an array');
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
var tracingOptions = [];
|
|
120
|
+
each(initConfiguration.allowedTracingOrigins, function (legacyMatchOption) {
|
|
121
|
+
var tracingOption = convertLegacyMatchOptionToTracingOption(legacyMatchOption, isNullUndefinedDefaultValue(initConfiguration.traceType, TraceType.DDTRACE));
|
|
122
|
+
|
|
123
|
+
if (tracingOption) {
|
|
124
|
+
tracingOptions.push(tracingOption);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
return tracingOptions;
|
|
128
|
+
} // Handle conversion of allowedDDTracingOrigins to allowedTracingUrls
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
if (initConfiguration.allowedDDTracingOrigins !== undefined) {
|
|
132
|
+
if (!isArray(initConfiguration.allowedDDTracingOrigins)) {
|
|
133
|
+
display.error('Allowed Tracing Origins should be an array');
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
var tracingOptions = [];
|
|
138
|
+
each(initConfiguration.allowedDDTracingOrigins, function (legacyMatchOption) {
|
|
139
|
+
var tracingOption = convertLegacyMatchOptionToTracingOption(legacyMatchOption, isNullUndefinedDefaultValue(initConfiguration.traceType, TraceType.DDTRACE));
|
|
140
|
+
|
|
141
|
+
if (tracingOption) {
|
|
142
|
+
tracingOptions.push(tracingOption);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
return tracingOptions;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return [];
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Converts parameters from the deprecated allowedTracingOrigins
|
|
152
|
+
* to allowedTracingUrls. Handles the change from origin to full URLs.
|
|
153
|
+
*/
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
function convertLegacyMatchOptionToTracingOption(item, traceType) {
|
|
157
|
+
var match;
|
|
158
|
+
|
|
159
|
+
if (typeof item === 'string') {
|
|
160
|
+
match = item;
|
|
161
|
+
} else if (item instanceof RegExp) {
|
|
162
|
+
match = function match(url) {
|
|
163
|
+
return item.test(getOrigin(url));
|
|
164
|
+
};
|
|
165
|
+
} else if (typeof item === 'function') {
|
|
166
|
+
match = function match(url) {
|
|
167
|
+
return item(getOrigin(url));
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (match === undefined) {
|
|
172
|
+
display.warn('Allowed Tracing Origins parameters should be a string, RegExp or function. Ignoring parameter', item);
|
|
173
|
+
return undefined;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return {
|
|
177
|
+
match: match,
|
|
178
|
+
traceType: traceType
|
|
179
|
+
};
|
|
68
180
|
}
|
|
@@ -1,49 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
this.buffer = new Uint8Array(8);
|
|
3
|
-
getCrypto().getRandomValues(this.buffer);
|
|
4
|
-
this.buffer[0] = this.buffer[0] & 0x7f;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
TraceIdentifier.prototype = {
|
|
8
|
-
// buffer: new Uint8Array(8),
|
|
9
|
-
toString: function toString(radix) {
|
|
10
|
-
var high = this.readInt32(0);
|
|
11
|
-
var low = this.readInt32(4);
|
|
12
|
-
var str = '';
|
|
13
|
-
|
|
14
|
-
while (1) {
|
|
15
|
-
var mod = high % radix * 4294967296 + low;
|
|
16
|
-
high = Math.floor(high / radix);
|
|
17
|
-
low = Math.floor(mod / radix);
|
|
18
|
-
str = (mod % radix).toString(radix) + str;
|
|
19
|
-
|
|
20
|
-
if (!high && !low) {
|
|
21
|
-
break;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return str;
|
|
26
|
-
},
|
|
27
|
-
toDecimalString: function toDecimalString() {
|
|
28
|
-
return this.toString(10);
|
|
29
|
-
},
|
|
30
|
-
readInt32: function readInt32(offset) {
|
|
31
|
-
return this.buffer[offset] * 16777216 + (this.buffer[offset + 1] << 16) + (this.buffer[offset + 2] << 8) + this.buffer[offset + 3];
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
function getCrypto() {
|
|
36
|
-
return window.crypto || window.msCrypto;
|
|
37
|
-
}
|
|
1
|
+
import { TraceIdentifier, getCrypto } from './traceIdentifier';
|
|
38
2
|
/**
|
|
39
3
|
*
|
|
40
4
|
* @param {*} configuration 配置信息
|
|
41
5
|
*/
|
|
42
6
|
|
|
43
|
-
|
|
44
7
|
export function DDtraceTracer(traceSampled) {
|
|
45
|
-
this._spanId = new TraceIdentifier()
|
|
46
|
-
this._traceId = new TraceIdentifier()
|
|
8
|
+
this._spanId = new TraceIdentifier();
|
|
9
|
+
this._traceId = new TraceIdentifier();
|
|
47
10
|
this._traceSampled = traceSampled;
|
|
48
11
|
}
|
|
49
12
|
DDtraceTracer.prototype = {
|
|
@@ -51,10 +14,10 @@ DDtraceTracer.prototype = {
|
|
|
51
14
|
return getCrypto() !== undefined;
|
|
52
15
|
},
|
|
53
16
|
getSpanId: function getSpanId() {
|
|
54
|
-
return this._spanId;
|
|
17
|
+
return this._spanId.toDecimalString();
|
|
55
18
|
},
|
|
56
19
|
getTraceId: function getTraceId() {
|
|
57
|
-
return this._traceId;
|
|
20
|
+
return this._traceId.toDecimalString();
|
|
58
21
|
},
|
|
59
22
|
makeTracingHeaders: function makeTracingHeaders() {
|
|
60
23
|
return {
|
|
@@ -1,47 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
function randomTraceId() {
|
|
3
|
-
var digits = '0123456789abcdef';
|
|
4
|
-
var n = '';
|
|
5
|
-
|
|
6
|
-
for (var i = 0; i < 16; i += 1) {
|
|
7
|
-
var rand = Math.floor(Math.random() * 16);
|
|
8
|
-
n += digits[rand];
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
return n;
|
|
12
|
-
}
|
|
1
|
+
import { TraceIdentifier, getCrypto } from './traceIdentifier';
|
|
13
2
|
/**
|
|
14
3
|
*
|
|
15
4
|
* @param {*} configuration 配置信息
|
|
16
5
|
*/
|
|
17
6
|
|
|
18
|
-
|
|
19
7
|
export function JaegerTracer(configuration, traceSampled) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (configuration.traceId128Bit) {
|
|
23
|
-
// 128bit生成traceid
|
|
24
|
-
this._traceId = randomTraceId() + rootSpanId;
|
|
25
|
-
} else {
|
|
26
|
-
this._traceId = rootSpanId;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
this._spanId = rootSpanId;
|
|
8
|
+
this._traceId = new TraceIdentifier();
|
|
9
|
+
this._spanId = new TraceIdentifier();
|
|
30
10
|
this._traceSampled = traceSampled;
|
|
11
|
+
this.is128Bit = configuration.traceId128Bit;
|
|
31
12
|
}
|
|
32
13
|
JaegerTracer.prototype = {
|
|
33
14
|
isTracingSupported: function isTracingSupported() {
|
|
34
|
-
return
|
|
15
|
+
return getCrypto() !== undefined;
|
|
35
16
|
},
|
|
36
17
|
getSpanId: function getSpanId() {
|
|
37
|
-
return this._spanId;
|
|
18
|
+
return this._spanId.toPaddedHexadecimalString();
|
|
38
19
|
},
|
|
39
20
|
getTraceId: function getTraceId() {
|
|
40
|
-
return this._traceId;
|
|
21
|
+
return this.is128Bit ? '0000000000000000' + this._traceId.toPaddedHexadecimalString() : this._traceId.toPaddedHexadecimalString();
|
|
41
22
|
},
|
|
42
23
|
getUberTraceId: function getUberTraceId() {
|
|
43
24
|
//{trace-id}:{span-id}:{parent-span-id}:{flags}
|
|
44
|
-
return this.
|
|
25
|
+
return this.getTraceId() + ':' + this.getSpanId() + ':' + '0' + ':' + (this._traceSampled ? '1' : '0');
|
|
45
26
|
},
|
|
46
27
|
makeTracingHeaders: function makeTracingHeaders() {
|
|
47
28
|
return {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export function TraceIdentifier() {
|
|
2
|
+
this.buffer = new Uint8Array(8);
|
|
3
|
+
getCrypto().getRandomValues(this.buffer);
|
|
4
|
+
this.buffer[0] = this.buffer[0] & 0x7f;
|
|
5
|
+
}
|
|
6
|
+
TraceIdentifier.prototype = {
|
|
7
|
+
// buffer: new Uint8Array(8),
|
|
8
|
+
toString: function toString(radix) {
|
|
9
|
+
var high = this.readInt32(0);
|
|
10
|
+
var low = this.readInt32(4);
|
|
11
|
+
var str = '';
|
|
12
|
+
|
|
13
|
+
do {
|
|
14
|
+
var mod = high % radix * 4294967296 + low;
|
|
15
|
+
high = Math.floor(high / radix);
|
|
16
|
+
low = Math.floor(mod / radix);
|
|
17
|
+
str = (mod % radix).toString(radix) + str;
|
|
18
|
+
} while (high || low);
|
|
19
|
+
|
|
20
|
+
return str;
|
|
21
|
+
},
|
|
22
|
+
toDecimalString: function toDecimalString() {
|
|
23
|
+
return this.toString(10);
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Format used by OTel headers
|
|
28
|
+
*/
|
|
29
|
+
toPaddedHexadecimalString() {
|
|
30
|
+
var traceId = this.toString(16);
|
|
31
|
+
return Array(17 - traceId.length).join('0') + traceId;
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
readInt32: function readInt32(offset) {
|
|
35
|
+
return this.buffer[offset] * 16777216 + (this.buffer[offset + 1] << 16) + (this.buffer[offset + 2] << 8) + this.buffer[offset + 3];
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
export function getCrypto() {
|
|
39
|
+
return window.crypto || window.msCrypto;
|
|
40
|
+
}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import { objectEntries, each, shallowClone, isArray, TraceType,
|
|
1
|
+
import { objectEntries, each, shallowClone, isArray, TraceType, performDraw, isNumber, getType, find, isMatchOption, matchList, isString } from '@cloudcare/browser-core';
|
|
2
2
|
import { DDtraceTracer } from './ddtraceTracer';
|
|
3
3
|
import { SkyWalkingTracer } from './skywalkingTracer';
|
|
4
4
|
import { JaegerTracer } from './jaegerTracer';
|
|
5
5
|
import { ZipkinSingleTracer } from './zipkinSingleTracer';
|
|
6
6
|
import { ZipkinMultiTracer } from './zipkinMultiTracer';
|
|
7
7
|
import { W3cTraceParentTracer } from './w3cTraceParentTracer';
|
|
8
|
+
export function isTracingOption(item) {
|
|
9
|
+
var expectedItem = item;
|
|
10
|
+
return getType(expectedItem) === 'object' && isMatchOption(expectedItem.match) && isString(expectedItem.traceType);
|
|
11
|
+
}
|
|
8
12
|
export function clearTracingIfNeeded(context) {
|
|
9
|
-
if (context.status === 0 && !context.isAborted) {
|
|
10
|
-
context.
|
|
11
|
-
context.
|
|
12
|
-
context.traceSampled = undefined;
|
|
13
|
+
if (context.status === 0 && !context.isAborted) {// context.traceId = undefined
|
|
14
|
+
// context.spanId = undefined
|
|
15
|
+
// context.traceSampled = undefined
|
|
13
16
|
}
|
|
14
17
|
}
|
|
15
18
|
export function startTracer(configuration, sessionManager) {
|
|
@@ -59,28 +62,24 @@ export function startTracer(configuration, sessionManager) {
|
|
|
59
62
|
}
|
|
60
63
|
};
|
|
61
64
|
}
|
|
65
|
+
export function injectHeadersIfTracingAllowed(configuration, context, sessionManager, inject) {
|
|
66
|
+
if (!sessionManager.findTrackedSession()) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
62
69
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
var flag = false;
|
|
66
|
-
each(configuration.allowedTracingOrigins, function (allowedOrigin) {
|
|
67
|
-
if (requestOrigin === allowedOrigin || allowedOrigin instanceof RegExp && allowedOrigin.test(requestOrigin)) {
|
|
68
|
-
flag = true;
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
70
|
+
var tracingOption = find(configuration.allowedTracingUrls, function (tracingOption) {
|
|
71
|
+
return matchList([tracingOption.match], context.url, true);
|
|
71
72
|
});
|
|
72
|
-
return flag;
|
|
73
|
-
}
|
|
74
73
|
|
|
75
|
-
|
|
76
|
-
if (!isAllowedUrl(configuration, context.url) || !configuration.traceType || !sessionManager.findTrackedSession()) {
|
|
74
|
+
if (!tracingOption) {
|
|
77
75
|
return;
|
|
78
76
|
}
|
|
79
77
|
|
|
80
78
|
var traceSampled = !isNumber(configuration.tracingSampleRate) || performDraw(configuration.tracingSampleRate);
|
|
81
|
-
var tracer
|
|
79
|
+
var tracer,
|
|
80
|
+
traceType = tracingOption.traceType;
|
|
82
81
|
|
|
83
|
-
switch (
|
|
82
|
+
switch (traceType) {
|
|
84
83
|
case TraceType.DDTRACE:
|
|
85
84
|
tracer = new DDtraceTracer(traceSampled);
|
|
86
85
|
break;
|
|
@@ -98,7 +97,11 @@ export function injectHeadersIfTracingAllowed(configuration, context, sessionMan
|
|
|
98
97
|
break;
|
|
99
98
|
|
|
100
99
|
case TraceType.W3C_TRACEPARENT:
|
|
101
|
-
tracer = new W3cTraceParentTracer(
|
|
100
|
+
tracer = new W3cTraceParentTracer(traceSampled);
|
|
101
|
+
break;
|
|
102
|
+
|
|
103
|
+
case TraceType.W3C_TRACEPARENT_64:
|
|
104
|
+
tracer = new W3cTraceParentTracer(traceSampled, true);
|
|
102
105
|
break;
|
|
103
106
|
|
|
104
107
|
case TraceType.ZIPKIN_SINGLE_HEADER:
|
|
@@ -1,40 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
function randomTraceId() {
|
|
3
|
-
var digits = '0123456789abcdef';
|
|
4
|
-
var n = '';
|
|
5
|
-
|
|
6
|
-
for (var i = 0; i < 16; i += 1) {
|
|
7
|
-
var rand = Math.floor(Math.random() * 16);
|
|
8
|
-
n += digits[rand];
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
return n;
|
|
12
|
-
}
|
|
1
|
+
import { TraceIdentifier, getCrypto } from './traceIdentifier';
|
|
13
2
|
/**
|
|
14
3
|
*
|
|
15
|
-
* @param {*}
|
|
4
|
+
* @param {*} traceSampled
|
|
5
|
+
* @param {*} isHexTraceId 是否需要转换成10进制上报数据
|
|
16
6
|
*/
|
|
17
7
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
this._traceId = randomTraceId() + rootSpanId;
|
|
22
|
-
this._spanId = rootSpanId;
|
|
8
|
+
export function W3cTraceParentTracer(traceSampled, isHexTraceId) {
|
|
9
|
+
this._traceId = new TraceIdentifier();
|
|
10
|
+
this._spanId = new TraceIdentifier();
|
|
23
11
|
this._traceSampled = traceSampled;
|
|
12
|
+
this.isHexTraceId = isHexTraceId;
|
|
24
13
|
}
|
|
25
14
|
W3cTraceParentTracer.prototype = {
|
|
26
15
|
isTracingSupported: function isTracingSupported() {
|
|
27
|
-
return
|
|
16
|
+
return getCrypto() !== undefined;
|
|
28
17
|
},
|
|
29
18
|
getSpanId: function getSpanId() {
|
|
30
|
-
return this._spanId;
|
|
19
|
+
return this.isHexTraceId ? this._spanId.toDecimalString() : this._spanId.toPaddedHexadecimalString();
|
|
31
20
|
},
|
|
32
21
|
getTraceId: function getTraceId() {
|
|
33
|
-
return this._traceId;
|
|
22
|
+
return this.isHexTraceId ? this._traceId.toDecimalString() : '0000000000000000' + this._traceId.toPaddedHexadecimalString();
|
|
34
23
|
},
|
|
35
24
|
getTraceParent: function getTraceParent() {
|
|
36
25
|
// '{version}-{traceId}-{spanId}-{sampleDecision}'
|
|
37
|
-
return '00-' + this._traceId + '-' + this._spanId + '-' + (this._traceSampled ? '01' : '00');
|
|
26
|
+
return '00-0000000000000000' + this._traceId.toPaddedHexadecimalString() + '-' + this._spanId.toPaddedHexadecimalString() + '-' + (this._traceSampled ? '01' : '00');
|
|
38
27
|
},
|
|
39
28
|
makeTracingHeaders: function makeTracingHeaders() {
|
|
40
29
|
return {
|
|
@@ -1,48 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
function randomTraceId() {
|
|
3
|
-
var digits = '0123456789abcdef';
|
|
4
|
-
var n = '';
|
|
5
|
-
|
|
6
|
-
for (var i = 0; i < 16; i += 1) {
|
|
7
|
-
var rand = Math.floor(Math.random() * 16);
|
|
8
|
-
n += digits[rand];
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
return n;
|
|
12
|
-
}
|
|
1
|
+
import { TraceIdentifier, getCrypto } from './traceIdentifier';
|
|
13
2
|
/**
|
|
14
3
|
*
|
|
15
4
|
* @param {*} configuration 配置信息
|
|
16
5
|
*/
|
|
17
6
|
|
|
18
|
-
|
|
19
7
|
export function ZipkinMultiTracer(configuration, traceSampled) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (configuration.traceId128Bit) {
|
|
23
|
-
// 128bit生成traceid
|
|
24
|
-
this._traceId = randomTraceId() + rootSpanId;
|
|
25
|
-
} else {
|
|
26
|
-
this._traceId = rootSpanId;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
this._spanId = rootSpanId;
|
|
8
|
+
this._traceId = new TraceIdentifier();
|
|
9
|
+
this._spanId = new TraceIdentifier();
|
|
30
10
|
this._traceSampled = traceSampled;
|
|
11
|
+
this.is128Bit = configuration.traceId128Bit;
|
|
31
12
|
}
|
|
32
13
|
ZipkinMultiTracer.prototype = {
|
|
33
14
|
isTracingSupported: function isTracingSupported() {
|
|
34
|
-
return
|
|
15
|
+
return getCrypto() !== undefined;
|
|
35
16
|
},
|
|
36
17
|
getSpanId: function getSpanId() {
|
|
37
|
-
return this._spanId;
|
|
18
|
+
return this._spanId.toPaddedHexadecimalString();
|
|
38
19
|
},
|
|
39
20
|
getTraceId: function getTraceId() {
|
|
40
|
-
return this._traceId;
|
|
21
|
+
return this.is128Bit ? '0000000000000000' + this._traceId.toPaddedHexadecimalString() : this._traceId.toPaddedHexadecimalString();
|
|
41
22
|
},
|
|
42
23
|
makeTracingHeaders: function makeTracingHeaders() {
|
|
43
24
|
return {
|
|
44
|
-
'X-B3-TraceId': this.
|
|
45
|
-
'X-B3-SpanId': this.
|
|
25
|
+
'X-B3-TraceId': this.getSpanId(),
|
|
26
|
+
'X-B3-SpanId': this.getTraceId(),
|
|
46
27
|
// 'X-B3-ParentSpanId': '',
|
|
47
28
|
'X-B3-Sampled': this._traceSampled ? '1' : '0' // 'X-B3-Flags': '0'
|
|
48
29
|
|
|
@@ -1,40 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
function randomTraceId() {
|
|
3
|
-
var digits = '0123456789abcdef';
|
|
4
|
-
var n = '';
|
|
5
|
-
|
|
6
|
-
for (var i = 0; i < 16; i += 1) {
|
|
7
|
-
var rand = Math.floor(Math.random() * 16);
|
|
8
|
-
n += digits[rand];
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
return n;
|
|
12
|
-
}
|
|
1
|
+
import { TraceIdentifier, getCrypto } from './traceIdentifier';
|
|
13
2
|
/**
|
|
14
3
|
*
|
|
15
4
|
* @param {*} configuration 配置信息
|
|
16
5
|
*/
|
|
17
6
|
|
|
18
|
-
|
|
19
7
|
export function ZipkinSingleTracer(configuration, traceSampled) {
|
|
20
|
-
|
|
21
|
-
this.
|
|
22
|
-
this._spanId = rootSpanId;
|
|
8
|
+
this._traceId = new TraceIdentifier();
|
|
9
|
+
this._spanId = new TraceIdentifier();
|
|
23
10
|
this._traceSampled = traceSampled;
|
|
24
11
|
}
|
|
25
12
|
ZipkinSingleTracer.prototype = {
|
|
26
13
|
isTracingSupported: function isTracingSupported() {
|
|
27
|
-
return
|
|
14
|
+
return getCrypto() !== undefined;
|
|
28
15
|
},
|
|
29
16
|
getSpanId: function getSpanId() {
|
|
30
|
-
return this._spanId;
|
|
17
|
+
return this._spanId.toPaddedHexadecimalString();
|
|
31
18
|
},
|
|
32
19
|
getTraceId: function getTraceId() {
|
|
33
|
-
return this._traceId;
|
|
20
|
+
return this._traceId.toPaddedHexadecimalString();
|
|
34
21
|
},
|
|
35
22
|
getB3Str: function getB3Str() {
|
|
36
23
|
//{TraceId}-{SpanId}-{SamplingState}-{ParentSpanId}
|
|
37
|
-
return this.
|
|
24
|
+
return this.getTraceId() + '-' + this.getSpanId() + '-' + (this._traceSampled ? '1' : '0');
|
|
38
25
|
},
|
|
39
26
|
makeTracingHeaders: function makeTracingHeaders() {
|
|
40
27
|
return {
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudcare/browser-rum",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.18",
|
|
4
4
|
"main": "cjs/index.js",
|
|
5
5
|
"module": "esm/index.js",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@cloudcare/browser-core": "2.0.
|
|
7
|
+
"@cloudcare/browser-core": "2.0.16"
|
|
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": "d68cc2e25637dbe6a09461ca4186b882f878c169"
|
|
33
33
|
}
|