@cloudcare/browser-rum 3.0.16 → 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/assembly.js +27 -8
- package/cjs/domain/configuration.js +130 -14
- package/cjs/domain/rumEventsCollection/actions/actionCollection.js +1 -1
- package/cjs/domain/rumEventsCollection/resource/resourceCollection.js +2 -2
- package/cjs/domain/rumEventsCollection/view/viewCollection.js +1 -1
- 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/assembly.js +28 -9
- package/esm/domain/configuration.js +126 -14
- package/esm/domain/rumEventsCollection/actions/actionCollection.js +1 -1
- package/esm/domain/rumEventsCollection/resource/resourceCollection.js +2 -2
- package/esm/domain/rumEventsCollection/view/viewCollection.js +1 -1
- 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/assembly.js +47 -23
- package/src/domain/configuration.js +148 -19
- package/src/domain/rumEventsCollection/actions/actionCollection.js +1 -1
- package/src/domain/rumEventsCollection/resource/resourceCollection.js +2 -2
- package/src/domain/rumEventsCollection/view/viewCollection.js +1 -1
- 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
package/cjs/boot/buildEnv.js
CHANGED
package/cjs/domain/assembly.js
CHANGED
|
@@ -11,12 +11,31 @@ var SessionType = {
|
|
|
11
11
|
SYNTHETICS: 'synthetics',
|
|
12
12
|
USER: 'user'
|
|
13
13
|
};
|
|
14
|
-
var
|
|
15
|
-
'view.url'
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
var VIEW_MODIFIABLE_FIELD_PATHS = {
|
|
15
|
+
'view.url': 'string',
|
|
16
|
+
'view.referrer': 'string'
|
|
17
|
+
};
|
|
18
|
+
var USER_CUSTOMIZABLE_FIELD_PATHS = {
|
|
19
|
+
tags: 'object',
|
|
20
|
+
'_gc.trace_id': 'string',
|
|
21
|
+
'_gc.span_id': 'string'
|
|
22
|
+
};
|
|
23
|
+
var modifiableFieldPathsByEvent = {};
|
|
18
24
|
|
|
19
25
|
function startRumAssembly(configuration, lifeCycle, sessionManager, userSessionManager, viewContexts, urlContexts, actionContexts, buildCommonContext, reportError) {
|
|
26
|
+
modifiableFieldPathsByEvent[_browserCore.RumEventType.VIEW] = VIEW_MODIFIABLE_FIELD_PATHS;
|
|
27
|
+
modifiableFieldPathsByEvent[_browserCore.RumEventType.ERROR] = (0, _browserCore.assign)({
|
|
28
|
+
'error.message': 'string',
|
|
29
|
+
'error.stack': 'string',
|
|
30
|
+
'error.resource.url': 'string'
|
|
31
|
+
}, USER_CUSTOMIZABLE_FIELD_PATHS, VIEW_MODIFIABLE_FIELD_PATHS);
|
|
32
|
+
modifiableFieldPathsByEvent[_browserCore.RumEventType.RESOURCE] = (0, _browserCore.assign)({
|
|
33
|
+
'resource.url': 'string'
|
|
34
|
+
}, USER_CUSTOMIZABLE_FIELD_PATHS, VIEW_MODIFIABLE_FIELD_PATHS);
|
|
35
|
+
modifiableFieldPathsByEvent[_browserCore.RumEventType.ACTION] = (0, _browserCore.assign)({
|
|
36
|
+
'action.target.name': 'string'
|
|
37
|
+
}, USER_CUSTOMIZABLE_FIELD_PATHS, VIEW_MODIFIABLE_FIELD_PATHS);
|
|
38
|
+
modifiableFieldPathsByEvent[_browserCore.RumEventType.LONG_TASK] = (0, _browserCore.assign)({}, USER_CUSTOMIZABLE_FIELD_PATHS, VIEW_MODIFIABLE_FIELD_PATHS);
|
|
20
39
|
var eventRateLimiters = {};
|
|
21
40
|
eventRateLimiters[_browserCore.RumEventType.ERROR] = (0, _browserCore.createEventRateLimiter)(_browserCore.RumEventType.ERROR, configuration.eventRateLimiterThreshold, reportError);
|
|
22
41
|
eventRateLimiters[_browserCore.RumEventType.ACTION] = (0, _browserCore.createEventRateLimiter)(_browserCore.RumEventType.ACTION, configuration.eventRateLimiterThreshold, reportError);
|
|
@@ -34,7 +53,7 @@ function startRumAssembly(configuration, lifeCycle, sessionManager, userSessionM
|
|
|
34
53
|
var actionId = actionContexts.findActionId(startTime);
|
|
35
54
|
var commonContext = savedCommonContext || buildCommonContext();
|
|
36
55
|
var rumContext = {
|
|
37
|
-
|
|
56
|
+
_gc: {
|
|
38
57
|
sdkName: configuration.sdkName,
|
|
39
58
|
sdkVersion: configuration.sdkVersion,
|
|
40
59
|
drift: (0, _browserCore.currentDrift)()
|
|
@@ -95,7 +114,7 @@ function startRumAssembly(configuration, lifeCycle, sessionManager, userSessionM
|
|
|
95
114
|
}, commonContext.user);
|
|
96
115
|
}
|
|
97
116
|
|
|
98
|
-
if (shouldSend(serverRumEvent, configuration.beforeSend,
|
|
117
|
+
if (shouldSend(serverRumEvent, configuration.beforeSend, domainContext, eventRateLimiters)) {
|
|
99
118
|
if ((0, _browserCore.isEmptyObject)(serverRumEvent.tags)) {
|
|
100
119
|
delete serverRumEvent.tags;
|
|
101
120
|
}
|
|
@@ -106,9 +125,9 @@ function startRumAssembly(configuration, lifeCycle, sessionManager, userSessionM
|
|
|
106
125
|
});
|
|
107
126
|
}
|
|
108
127
|
|
|
109
|
-
function shouldSend(event, beforeSend,
|
|
128
|
+
function shouldSend(event, beforeSend, domainContext, eventRateLimiters) {
|
|
110
129
|
if (beforeSend) {
|
|
111
|
-
var result = (0, _browserCore.limitModification)(event, event.type
|
|
130
|
+
var result = (0, _browserCore.limitModification)(event, modifiableFieldPathsByEvent[event.type], function (event) {
|
|
112
131
|
return beforeSend(event, domainContext);
|
|
113
132
|
});
|
|
114
133
|
|
|
@@ -9,6 +9,8 @@ var _browserCore = require("@cloudcare/browser-core");
|
|
|
9
9
|
|
|
10
10
|
var _buildEnv = require("../boot/buildEnv");
|
|
11
11
|
|
|
12
|
+
var _tracer = require("../domain/tracing/tracer");
|
|
13
|
+
|
|
12
14
|
function validateAndBuildRumConfiguration(initConfiguration) {
|
|
13
15
|
if (!initConfiguration.applicationId) {
|
|
14
16
|
_browserCore.display.error('Application ID is not configured, no RUM data will be collected.');
|
|
@@ -29,21 +31,23 @@ function validateAndBuildRumConfiguration(initConfiguration) {
|
|
|
29
31
|
return;
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
|
|
33
|
-
if (!(0, _browserCore.isArray)(initConfiguration.allowedTracingOrigins)) {
|
|
34
|
-
_browserCore.display.error('Allowed Tracing Origins should be an array');
|
|
35
|
-
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
34
|
+
var allowedTracingUrls = validateAndBuildTracingOptions(initConfiguration);
|
|
39
35
|
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
if (!allowedTracingUrls) {
|
|
37
|
+
return;
|
|
38
|
+
} // if (initConfiguration.allowedTracingOrigins !== undefined) {
|
|
39
|
+
// if (!isArray(initConfiguration.allowedTracingOrigins)) {
|
|
40
|
+
// display.error('Allowed Tracing Origins should be an array')
|
|
41
|
+
// return
|
|
42
|
+
// }
|
|
43
|
+
// }
|
|
44
|
+
// if (initConfiguration.allowedDDTracingOrigins !== undefined) {
|
|
45
|
+
// if (!isArray(initConfiguration.allowedDDTracingOrigins)) {
|
|
46
|
+
// display.error('Allowed Tracing Origins should be an array')
|
|
47
|
+
// return
|
|
48
|
+
// }
|
|
49
|
+
// }
|
|
43
50
|
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
51
|
|
|
48
52
|
if (initConfiguration.tracingSampleRate !== undefined && !(0, _browserCore.isPercentage)(initConfiguration.tracingSampleRate)) {
|
|
49
53
|
_browserCore.display.error('Tracing Sample Rate should be a number between 0 and 100');
|
|
@@ -70,7 +74,7 @@ function validateAndBuildRumConfiguration(initConfiguration) {
|
|
|
70
74
|
actionNameAttribute: initConfiguration.actionNameAttribute,
|
|
71
75
|
sessionReplaySampleRate: (0, _browserCore.isNullUndefinedDefaultValue)(initConfiguration.sessionReplaySampleRate, 100),
|
|
72
76
|
tracingSampleRate: initConfiguration.tracingSampleRate,
|
|
73
|
-
|
|
77
|
+
allowedTracingUrls: allowedTracingUrls,
|
|
74
78
|
excludedActivityUrls: (0, _browserCore.isNullUndefinedDefaultValue)(initConfiguration.excludedActivityUrls, []),
|
|
75
79
|
trackUserInteractions: trackUserInteractions || trackFrustrations,
|
|
76
80
|
trackFrustrations: trackFrustrations,
|
|
@@ -81,4 +85,116 @@ function validateAndBuildRumConfiguration(initConfiguration) {
|
|
|
81
85
|
// 是否需要对webview 发送数据,需要装我们对应ios sdk
|
|
82
86
|
defaultPrivacyLevel: (0, _browserCore.objectHasValue)(_browserCore.DefaultPrivacyLevel, initConfiguration.defaultPrivacyLevel) ? initConfiguration.defaultPrivacyLevel : _browserCore.DefaultPrivacyLevel.MASK_USER_INPUT
|
|
83
87
|
}, baseConfiguration, _buildEnv.buildEnv);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Handles allowedTracingUrls and processes legacy allowedTracingOrigins
|
|
91
|
+
*/
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
function validateAndBuildTracingOptions(initConfiguration) {
|
|
95
|
+
// Advise about parameters precedence.
|
|
96
|
+
if (initConfiguration.allowedTracingUrls !== undefined && initConfiguration.allowedTracingOrigins !== undefined) {
|
|
97
|
+
_browserCore.display.warn('Both allowedTracingUrls and allowedTracingOrigins (deprecated) have been defined. The parameter allowedTracingUrls will override allowedTracingOrigins.');
|
|
98
|
+
} // Handle allowedTracingUrls first
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
if (initConfiguration.allowedTracingUrls !== undefined) {
|
|
102
|
+
if (!(0, _browserCore.isArray)(initConfiguration.allowedTracingUrls)) {
|
|
103
|
+
_browserCore.display.error('Allowed Tracing URLs should be an array');
|
|
104
|
+
|
|
105
|
+
return;
|
|
106
|
+
} // if (initConfiguration.allowedTracingUrls.length !== 0 && initConfiguration.service === undefined) {
|
|
107
|
+
// display.error('Service needs to be configured when tracing is enabled')
|
|
108
|
+
// return
|
|
109
|
+
// }
|
|
110
|
+
// Convert from (MatchOption | TracingOption) to TracingOption, remove unknown properties
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
var tracingOptions = [];
|
|
114
|
+
(0, _browserCore.each)(initConfiguration.allowedTracingUrls, function (option) {
|
|
115
|
+
if ((0, _browserCore.isMatchOption)(option)) {
|
|
116
|
+
tracingOptions.push({
|
|
117
|
+
match: option,
|
|
118
|
+
traceType: (0, _browserCore.isNullUndefinedDefaultValue)(initConfiguration.traceType, _browserCore.TraceType.DDTRACE)
|
|
119
|
+
});
|
|
120
|
+
} else if ((0, _tracer.isTracingOption)(option)) {
|
|
121
|
+
tracingOptions.push(option);
|
|
122
|
+
} else {
|
|
123
|
+
_browserCore.display.warn('Allowed Tracing Urls parameters should be a string, RegExp, function, or an object. Ignoring parameter', option);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
return tracingOptions;
|
|
127
|
+
} // Handle conversion of allowedTracingOrigins to allowedTracingUrls
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
if (initConfiguration.allowedTracingOrigins !== undefined) {
|
|
131
|
+
if (!(0, _browserCore.isArray)(initConfiguration.allowedTracingOrigins)) {
|
|
132
|
+
_browserCore.display.error('Allowed Tracing Origins should be an array');
|
|
133
|
+
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
var tracingOptions = [];
|
|
138
|
+
(0, _browserCore.each)(initConfiguration.allowedTracingOrigins, function (legacyMatchOption) {
|
|
139
|
+
var tracingOption = convertLegacyMatchOptionToTracingOption(legacyMatchOption, (0, _browserCore.isNullUndefinedDefaultValue)(initConfiguration.traceType, _browserCore.TraceType.DDTRACE));
|
|
140
|
+
|
|
141
|
+
if (tracingOption) {
|
|
142
|
+
tracingOptions.push(tracingOption);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
return tracingOptions;
|
|
146
|
+
} // Handle conversion of allowedDDTracingOrigins to allowedTracingUrls
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
if (initConfiguration.allowedDDTracingOrigins !== undefined) {
|
|
150
|
+
if (!(0, _browserCore.isArray)(initConfiguration.allowedDDTracingOrigins)) {
|
|
151
|
+
_browserCore.display.error('Allowed Tracing Origins should be an array');
|
|
152
|
+
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
var tracingOptions = [];
|
|
157
|
+
(0, _browserCore.each)(initConfiguration.allowedDDTracingOrigins, function (legacyMatchOption) {
|
|
158
|
+
var tracingOption = convertLegacyMatchOptionToTracingOption(legacyMatchOption, (0, _browserCore.isNullUndefinedDefaultValue)(initConfiguration.traceType, _browserCore.TraceType.DDTRACE));
|
|
159
|
+
|
|
160
|
+
if (tracingOption) {
|
|
161
|
+
tracingOptions.push(tracingOption);
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
return tracingOptions;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return [];
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Converts parameters from the deprecated allowedTracingOrigins
|
|
171
|
+
* to allowedTracingUrls. Handles the change from origin to full URLs.
|
|
172
|
+
*/
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
function convertLegacyMatchOptionToTracingOption(item, traceType) {
|
|
176
|
+
var match;
|
|
177
|
+
|
|
178
|
+
if (typeof item === 'string') {
|
|
179
|
+
match = item;
|
|
180
|
+
} else if (item instanceof RegExp) {
|
|
181
|
+
match = function match(url) {
|
|
182
|
+
return item.test((0, _browserCore.getOrigin)(url));
|
|
183
|
+
};
|
|
184
|
+
} else if (typeof item === 'function') {
|
|
185
|
+
match = function match(url) {
|
|
186
|
+
return item((0, _browserCore.getOrigin)(url));
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (match === undefined) {
|
|
191
|
+
_browserCore.display.warn('Allowed Tracing Origins parameters should be a string, RegExp or function. Ignoring parameter', item);
|
|
192
|
+
|
|
193
|
+
return undefined;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return {
|
|
197
|
+
match: match,
|
|
198
|
+
traceType: traceType
|
|
199
|
+
};
|
|
84
200
|
}
|
|
@@ -130,7 +130,7 @@ function computeRequestTracingInfo(request) {
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
return {
|
|
133
|
-
|
|
133
|
+
_gc: {
|
|
134
134
|
spanId: request.spanId,
|
|
135
135
|
traceId: request.traceId
|
|
136
136
|
},
|
|
@@ -142,7 +142,7 @@ function computeRequestTracingInfo(request) {
|
|
|
142
142
|
|
|
143
143
|
function computeEntryTracingInfo(entry) {
|
|
144
144
|
return entry.traceId ? {
|
|
145
|
-
|
|
145
|
+
_gc: {
|
|
146
146
|
traceId: entry.traceId
|
|
147
147
|
}
|
|
148
148
|
} : undefined;
|
|
@@ -69,7 +69,7 @@ function computePerformanceViewDetails(entry) {
|
|
|
69
69
|
function processViewUpdate(view, foregroundContexts, recorderApi) {
|
|
70
70
|
var replayStats = recorderApi.getReplayStats(view.id);
|
|
71
71
|
var viewEvent = {
|
|
72
|
-
|
|
72
|
+
_gc: {
|
|
73
73
|
document_version: view.documentVersion,
|
|
74
74
|
replay_stats: replayStats
|
|
75
75
|
},
|
|
@@ -5,64 +5,27 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.DDtraceTracer = DDtraceTracer;
|
|
7
7
|
|
|
8
|
-
|
|
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;
|
|
8
|
+
var _traceIdentifier = require("./traceIdentifier");
|
|
26
9
|
|
|
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
10
|
/**
|
|
46
11
|
*
|
|
47
12
|
* @param {*} configuration 配置信息
|
|
48
13
|
*/
|
|
49
|
-
|
|
50
|
-
|
|
51
14
|
function DDtraceTracer(traceSampled) {
|
|
52
|
-
this._spanId = new TraceIdentifier()
|
|
53
|
-
this._traceId = new TraceIdentifier()
|
|
15
|
+
this._spanId = new _traceIdentifier.TraceIdentifier();
|
|
16
|
+
this._traceId = new _traceIdentifier.TraceIdentifier();
|
|
54
17
|
this._traceSampled = traceSampled;
|
|
55
18
|
}
|
|
56
19
|
|
|
57
20
|
DDtraceTracer.prototype = {
|
|
58
21
|
isTracingSupported: function isTracingSupported() {
|
|
59
|
-
return getCrypto() !== undefined;
|
|
22
|
+
return (0, _traceIdentifier.getCrypto)() !== undefined;
|
|
60
23
|
},
|
|
61
24
|
getSpanId: function getSpanId() {
|
|
62
|
-
return this._spanId;
|
|
25
|
+
return this._spanId.toDecimalString();
|
|
63
26
|
},
|
|
64
27
|
getTraceId: function getTraceId() {
|
|
65
|
-
return this._traceId;
|
|
28
|
+
return this._traceId.toDecimalString();
|
|
66
29
|
},
|
|
67
30
|
makeTracingHeaders: function makeTracingHeaders() {
|
|
68
31
|
return {
|
|
@@ -5,51 +5,32 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.JaegerTracer = JaegerTracer;
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
function randomTraceId() {
|
|
10
|
-
var digits = '0123456789abcdef';
|
|
11
|
-
var n = '';
|
|
8
|
+
var _traceIdentifier = require("./traceIdentifier");
|
|
12
9
|
|
|
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
10
|
/**
|
|
21
11
|
*
|
|
22
12
|
* @param {*} configuration 配置信息
|
|
23
13
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
14
|
function JaegerTracer(configuration, traceSampled) {
|
|
27
|
-
|
|
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;
|
|
15
|
+
this._traceId = new _traceIdentifier.TraceIdentifier();
|
|
16
|
+
this._spanId = new _traceIdentifier.TraceIdentifier();
|
|
37
17
|
this._traceSampled = traceSampled;
|
|
18
|
+
this.is128Bit = configuration.traceId128Bit;
|
|
38
19
|
}
|
|
39
20
|
|
|
40
21
|
JaegerTracer.prototype = {
|
|
41
22
|
isTracingSupported: function isTracingSupported() {
|
|
42
|
-
return
|
|
23
|
+
return (0, _traceIdentifier.getCrypto)() !== undefined;
|
|
43
24
|
},
|
|
44
25
|
getSpanId: function getSpanId() {
|
|
45
|
-
return this._spanId;
|
|
26
|
+
return this._spanId.toPaddedHexadecimalString();
|
|
46
27
|
},
|
|
47
28
|
getTraceId: function getTraceId() {
|
|
48
|
-
return this._traceId;
|
|
29
|
+
return this.is128Bit ? '0000000000000000' + this._traceId.toPaddedHexadecimalString() : this._traceId.toPaddedHexadecimalString();
|
|
49
30
|
},
|
|
50
31
|
getUberTraceId: function getUberTraceId() {
|
|
51
32
|
//{trace-id}:{span-id}:{parent-span-id}:{flags}
|
|
52
|
-
return this.
|
|
33
|
+
return this.getTraceId() + ':' + this.getSpanId() + ':' + '0' + ':' + (this._traceSampled ? '1' : '0');
|
|
53
34
|
},
|
|
54
35
|
makeTracingHeaders: function makeTracingHeaders() {
|
|
55
36
|
return {
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.TraceIdentifier = TraceIdentifier;
|
|
7
|
+
exports.getCrypto = getCrypto;
|
|
8
|
+
|
|
9
|
+
function TraceIdentifier() {
|
|
10
|
+
this.buffer = new Uint8Array(8);
|
|
11
|
+
getCrypto().getRandomValues(this.buffer);
|
|
12
|
+
this.buffer[0] = this.buffer[0] & 0x7f;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
TraceIdentifier.prototype = {
|
|
16
|
+
// buffer: new Uint8Array(8),
|
|
17
|
+
toString: function toString(radix) {
|
|
18
|
+
var high = this.readInt32(0);
|
|
19
|
+
var low = this.readInt32(4);
|
|
20
|
+
var str = '';
|
|
21
|
+
|
|
22
|
+
do {
|
|
23
|
+
var mod = high % radix * 4294967296 + low;
|
|
24
|
+
high = Math.floor(high / radix);
|
|
25
|
+
low = Math.floor(mod / radix);
|
|
26
|
+
str = (mod % radix).toString(radix) + str;
|
|
27
|
+
} while (high || low);
|
|
28
|
+
|
|
29
|
+
return str;
|
|
30
|
+
},
|
|
31
|
+
toDecimalString: function toDecimalString() {
|
|
32
|
+
return this.toString(10);
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Format used by OTel headers
|
|
37
|
+
*/
|
|
38
|
+
toPaddedHexadecimalString: function toPaddedHexadecimalString() {
|
|
39
|
+
var traceId = this.toString(16);
|
|
40
|
+
return Array(17 - traceId.length).join('0') + traceId;
|
|
41
|
+
},
|
|
42
|
+
readInt32: function readInt32(offset) {
|
|
43
|
+
return this.buffer[offset] * 16777216 + (this.buffer[offset + 1] << 16) + (this.buffer[offset + 2] << 8) + this.buffer[offset + 3];
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
function getCrypto() {
|
|
48
|
+
return window.crypto || window.msCrypto;
|
|
49
|
+
}
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.clearTracingIfNeeded = clearTracingIfNeeded;
|
|
7
7
|
exports.injectHeadersIfTracingAllowed = injectHeadersIfTracingAllowed;
|
|
8
|
+
exports.isTracingOption = isTracingOption;
|
|
8
9
|
exports.startTracer = startTracer;
|
|
9
10
|
|
|
10
11
|
var _browserCore = require("@cloudcare/browser-core");
|
|
@@ -21,11 +22,15 @@ var _zipkinMultiTracer = require("./zipkinMultiTracer");
|
|
|
21
22
|
|
|
22
23
|
var _w3cTraceParentTracer = require("./w3cTraceParentTracer");
|
|
23
24
|
|
|
25
|
+
function isTracingOption(item) {
|
|
26
|
+
var expectedItem = item;
|
|
27
|
+
return (0, _browserCore.getType)(expectedItem) === 'object' && (0, _browserCore.isMatchOption)(expectedItem.match) && (0, _browserCore.isString)(expectedItem.traceType);
|
|
28
|
+
}
|
|
29
|
+
|
|
24
30
|
function clearTracingIfNeeded(context) {
|
|
25
|
-
if (context.status === 0 && !context.isAborted) {
|
|
26
|
-
context.
|
|
27
|
-
context.
|
|
28
|
-
context.traceSampled = undefined;
|
|
31
|
+
if (context.status === 0 && !context.isAborted) {// context.traceId = undefined
|
|
32
|
+
// context.spanId = undefined
|
|
33
|
+
// context.traceSampled = undefined
|
|
29
34
|
}
|
|
30
35
|
}
|
|
31
36
|
|
|
@@ -77,27 +82,24 @@ function startTracer(configuration, sessionManager) {
|
|
|
77
82
|
};
|
|
78
83
|
}
|
|
79
84
|
|
|
80
|
-
function
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
85
|
+
function injectHeadersIfTracingAllowed(configuration, context, sessionManager, inject) {
|
|
86
|
+
if (!sessionManager.findTrackedSession()) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
var tracingOption = (0, _browserCore.find)(configuration.allowedTracingUrls, function (tracingOption) {
|
|
91
|
+
return (0, _browserCore.matchList)([tracingOption.match], context.url, true);
|
|
88
92
|
});
|
|
89
|
-
return flag;
|
|
90
|
-
}
|
|
91
93
|
|
|
92
|
-
|
|
93
|
-
if (!isAllowedUrl(configuration, context.url) || !configuration.traceType || !sessionManager.findTrackedSession()) {
|
|
94
|
+
if (!tracingOption) {
|
|
94
95
|
return;
|
|
95
96
|
}
|
|
96
97
|
|
|
97
98
|
var traceSampled = !(0, _browserCore.isNumber)(configuration.tracingSampleRate) || (0, _browserCore.performDraw)(configuration.tracingSampleRate);
|
|
98
|
-
var tracer
|
|
99
|
+
var tracer,
|
|
100
|
+
traceType = tracingOption.traceType;
|
|
99
101
|
|
|
100
|
-
switch (
|
|
102
|
+
switch (traceType) {
|
|
101
103
|
case _browserCore.TraceType.DDTRACE:
|
|
102
104
|
tracer = new _ddtraceTracer.DDtraceTracer(traceSampled);
|
|
103
105
|
break;
|
|
@@ -115,7 +117,11 @@ function injectHeadersIfTracingAllowed(configuration, context, sessionManager, i
|
|
|
115
117
|
break;
|
|
116
118
|
|
|
117
119
|
case _browserCore.TraceType.W3C_TRACEPARENT:
|
|
118
|
-
tracer = new _w3cTraceParentTracer.W3cTraceParentTracer(
|
|
120
|
+
tracer = new _w3cTraceParentTracer.W3cTraceParentTracer(traceSampled);
|
|
121
|
+
break;
|
|
122
|
+
|
|
123
|
+
case _browserCore.TraceType.W3C_TRACEPARENT_64:
|
|
124
|
+
tracer = new _w3cTraceParentTracer.W3cTraceParentTracer(traceSampled, true);
|
|
119
125
|
break;
|
|
120
126
|
|
|
121
127
|
case _browserCore.TraceType.ZIPKIN_SINGLE_HEADER:
|
|
@@ -5,44 +5,33 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.W3cTraceParentTracer = W3cTraceParentTracer;
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
function randomTraceId() {
|
|
10
|
-
var digits = '0123456789abcdef';
|
|
11
|
-
var n = '';
|
|
8
|
+
var _traceIdentifier = require("./traceIdentifier");
|
|
12
9
|
|
|
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
10
|
/**
|
|
21
11
|
*
|
|
22
|
-
* @param {*}
|
|
12
|
+
* @param {*} traceSampled
|
|
13
|
+
* @param {*} isHexTraceId 是否需要转换成10进制上报数据
|
|
23
14
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
var rootSpanId = randomTraceId();
|
|
28
|
-
this._traceId = randomTraceId() + rootSpanId;
|
|
29
|
-
this._spanId = rootSpanId;
|
|
15
|
+
function W3cTraceParentTracer(traceSampled, isHexTraceId) {
|
|
16
|
+
this._traceId = new _traceIdentifier.TraceIdentifier();
|
|
17
|
+
this._spanId = new _traceIdentifier.TraceIdentifier();
|
|
30
18
|
this._traceSampled = traceSampled;
|
|
19
|
+
this.isHexTraceId = isHexTraceId;
|
|
31
20
|
}
|
|
32
21
|
|
|
33
22
|
W3cTraceParentTracer.prototype = {
|
|
34
23
|
isTracingSupported: function isTracingSupported() {
|
|
35
|
-
return
|
|
24
|
+
return (0, _traceIdentifier.getCrypto)() !== undefined;
|
|
36
25
|
},
|
|
37
26
|
getSpanId: function getSpanId() {
|
|
38
|
-
return this._spanId;
|
|
27
|
+
return this.isHexTraceId ? this._spanId.toDecimalString() : this._spanId.toPaddedHexadecimalString();
|
|
39
28
|
},
|
|
40
29
|
getTraceId: function getTraceId() {
|
|
41
|
-
return this._traceId;
|
|
30
|
+
return this.isHexTraceId ? this._traceId.toDecimalString() : '0000000000000000' + this._traceId.toPaddedHexadecimalString();
|
|
42
31
|
},
|
|
43
32
|
getTraceParent: function getTraceParent() {
|
|
44
33
|
// '{version}-{traceId}-{spanId}-{sampleDecision}'
|
|
45
|
-
return '00-' + this._traceId + '-' + this._spanId + '-' + (this._traceSampled ? '01' : '00');
|
|
34
|
+
return '00-0000000000000000' + this._traceId.toPaddedHexadecimalString() + '-' + this._spanId.toPaddedHexadecimalString() + '-' + (this._traceSampled ? '01' : '00');
|
|
46
35
|
},
|
|
47
36
|
makeTracingHeaders: function makeTracingHeaders() {
|
|
48
37
|
return {
|
|
@@ -5,52 +5,33 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.ZipkinMultiTracer = ZipkinMultiTracer;
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
function randomTraceId() {
|
|
10
|
-
var digits = '0123456789abcdef';
|
|
11
|
-
var n = '';
|
|
8
|
+
var _traceIdentifier = require("./traceIdentifier");
|
|
12
9
|
|
|
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
10
|
/**
|
|
21
11
|
*
|
|
22
12
|
* @param {*} configuration 配置信息
|
|
23
13
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
14
|
function ZipkinMultiTracer(configuration, traceSampled) {
|
|
27
|
-
|
|
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;
|
|
15
|
+
this._traceId = new _traceIdentifier.TraceIdentifier();
|
|
16
|
+
this._spanId = new _traceIdentifier.TraceIdentifier();
|
|
37
17
|
this._traceSampled = traceSampled;
|
|
18
|
+
this.is128Bit = configuration.traceId128Bit;
|
|
38
19
|
}
|
|
39
20
|
|
|
40
21
|
ZipkinMultiTracer.prototype = {
|
|
41
22
|
isTracingSupported: function isTracingSupported() {
|
|
42
|
-
return
|
|
23
|
+
return (0, _traceIdentifier.getCrypto)() !== undefined;
|
|
43
24
|
},
|
|
44
25
|
getSpanId: function getSpanId() {
|
|
45
|
-
return this._spanId;
|
|
26
|
+
return this._spanId.toPaddedHexadecimalString();
|
|
46
27
|
},
|
|
47
28
|
getTraceId: function getTraceId() {
|
|
48
|
-
return this._traceId;
|
|
29
|
+
return this.is128Bit ? '0000000000000000' + this._traceId.toPaddedHexadecimalString() : this._traceId.toPaddedHexadecimalString();
|
|
49
30
|
},
|
|
50
31
|
makeTracingHeaders: function makeTracingHeaders() {
|
|
51
32
|
return {
|
|
52
|
-
'X-B3-TraceId': this.
|
|
53
|
-
'X-B3-SpanId': this.
|
|
33
|
+
'X-B3-TraceId': this.getSpanId(),
|
|
34
|
+
'X-B3-SpanId': this.getTraceId(),
|
|
54
35
|
// 'X-B3-ParentSpanId': '',
|
|
55
36
|
'X-B3-Sampled': this._traceSampled ? '1' : '0' // 'X-B3-Flags': '0'
|
|
56
37
|
|