@cloudcare/browser-rum 2.0.18 → 2.0.21
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/domain/assembly.js +12 -1
- package/cjs/domain/rumEventsCollection/error/errorCollection.js +20 -8
- 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/domain/assembly.js +12 -1
- package/esm/domain/rumEventsCollection/error/errorCollection.js +20 -9
- 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 +0 -1
- package/src/domain/.DS_Store +0 -0
- package/src/domain/assembly.js +12 -3
- package/src/domain/rumEventsCollection/error/errorCollection.js +25 -11
- 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
package/esm/domain/rumSession.js
CHANGED
|
@@ -3,7 +3,9 @@ export var RUM_SESSION_KEY = 'rum';
|
|
|
3
3
|
export var RumTrackingType = {
|
|
4
4
|
NOT_TRACKED: '0',
|
|
5
5
|
TRACKED_WITH_RESOURCES: '1',
|
|
6
|
-
TRACKED_WITHOUT_RESOURCES: '2'
|
|
6
|
+
TRACKED_WITHOUT_RESOURCES: '2',
|
|
7
|
+
TRACKED_WITH_SERVICE: '3' // 采样数据添加额外的tag,不舍弃,直接上报到服务端
|
|
8
|
+
|
|
7
9
|
};
|
|
8
10
|
export function startRumSession(configuration, lifeCycle) {
|
|
9
11
|
var session = startSessionManagement(configuration.cookieOptions, RUM_SESSION_KEY, function (rawTrackingType) {
|
|
@@ -21,8 +23,12 @@ export function startRumSession(configuration, lifeCycle) {
|
|
|
21
23
|
isTracked: function isTracked() {
|
|
22
24
|
return session.getId() !== undefined && _isTracked(session.getTrackingType());
|
|
23
25
|
},
|
|
26
|
+
isTrackedWidthService: function isTrackedWidthService() {
|
|
27
|
+
return session.getId() !== undefined && session.getTrackingType() === RumTrackingType.TRACKED_WITH_SERVICE;
|
|
28
|
+
},
|
|
24
29
|
isTrackedWithResource: function isTrackedWithResource() {
|
|
25
|
-
|
|
30
|
+
var trackingType = session.getTrackingType();
|
|
31
|
+
return session.getId() !== undefined && (trackingType === RumTrackingType.TRACKED_WITH_RESOURCES || trackingType === RumTrackingType.TRACKED_WITH_SERVICE);
|
|
26
32
|
}
|
|
27
33
|
};
|
|
28
34
|
}
|
|
@@ -33,9 +39,18 @@ function computeSessionState(configuration, rawTrackingType) {
|
|
|
33
39
|
if (hasValidRumSession(rawTrackingType)) {
|
|
34
40
|
trackingType = rawTrackingType;
|
|
35
41
|
} else if (!performDraw(configuration.sampleRate)) {
|
|
36
|
-
|
|
42
|
+
if (configuration.isServiceSampling) {
|
|
43
|
+
trackingType = RumTrackingType.TRACKED_WITH_SERVICE;
|
|
44
|
+
} else {
|
|
45
|
+
trackingType = RumTrackingType.NOT_TRACKED;
|
|
46
|
+
}
|
|
37
47
|
} else if (!performDraw(configuration.resourceSampleRate)) {
|
|
38
|
-
trackingType = RumTrackingType.TRACKED_WITHOUT_RESOURCES
|
|
48
|
+
// trackingType = RumTrackingType.TRACKED_WITHOUT_RESOURCES
|
|
49
|
+
if (configuration.isServiceSampling) {
|
|
50
|
+
trackingType = RumTrackingType.TRACKED_WITH_SERVICE;
|
|
51
|
+
} else {
|
|
52
|
+
trackingType = RumTrackingType.TRACKED_WITHOUT_RESOURCES;
|
|
53
|
+
}
|
|
39
54
|
} else {
|
|
40
55
|
trackingType = RumTrackingType.TRACKED_WITH_RESOURCES;
|
|
41
56
|
}
|
|
@@ -47,9 +62,9 @@ function computeSessionState(configuration, rawTrackingType) {
|
|
|
47
62
|
}
|
|
48
63
|
|
|
49
64
|
function hasValidRumSession(trackingType) {
|
|
50
|
-
return trackingType === RumTrackingType.NOT_TRACKED || trackingType === RumTrackingType.TRACKED_WITH_RESOURCES || trackingType === RumTrackingType.TRACKED_WITHOUT_RESOURCES;
|
|
65
|
+
return trackingType === RumTrackingType.NOT_TRACKED || trackingType === RumTrackingType.TRACKED_WITH_RESOURCES || trackingType === RumTrackingType.TRACKED_WITHOUT_RESOURCES || trackingType === RumTrackingType.TRACKED_WITH_SERVICE;
|
|
51
66
|
}
|
|
52
67
|
|
|
53
68
|
function _isTracked(rumSessionType) {
|
|
54
|
-
return rumSessionType === RumTrackingType.TRACKED_WITH_RESOURCES || rumSessionType === RumTrackingType.TRACKED_WITHOUT_RESOURCES;
|
|
69
|
+
return rumSessionType === RumTrackingType.TRACKED_WITH_RESOURCES || rumSessionType === RumTrackingType.TRACKED_WITHOUT_RESOURCES || rumSessionType === RumTrackingType.TRACKED_WITH_SERVICE;
|
|
55
70
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
function TraceIdentifier() {
|
|
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
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* @param {*} configuration 配置信息
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
export function DDtraceTracer(configuration) {
|
|
45
|
+
this._spanId = new TraceIdentifier().toDecimalString();
|
|
46
|
+
this._traceId = new TraceIdentifier().toDecimalString();
|
|
47
|
+
}
|
|
48
|
+
DDtraceTracer.prototype = {
|
|
49
|
+
isTracingSupported: function isTracingSupported() {
|
|
50
|
+
return getCrypto() !== undefined;
|
|
51
|
+
},
|
|
52
|
+
getSpanId: function getSpanId() {
|
|
53
|
+
return this._spanId;
|
|
54
|
+
},
|
|
55
|
+
getTraceId: function getTraceId() {
|
|
56
|
+
return this._traceId;
|
|
57
|
+
},
|
|
58
|
+
makeTracingHeaders: function makeTracingHeaders() {
|
|
59
|
+
return {
|
|
60
|
+
'x-datadog-origin': 'rum',
|
|
61
|
+
// 'x-datadog-parent-id': spanId.toDecimalString(),
|
|
62
|
+
'x-datadog-sampled': '1',
|
|
63
|
+
'x-datadog-sampling-priority': '1',
|
|
64
|
+
'x-datadog-trace-id': this.getTraceId()
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// === Generate a random 64-bit number in fixed-length hex format
|
|
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
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @param {*} configuration 配置信息
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
export function JaegerTracer(configuration) {
|
|
20
|
+
var rootSpanId = randomTraceId(); // this._traceId = randomTraceId() + rootSpanId // 默认用128bit,兼容其他配置
|
|
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;
|
|
30
|
+
}
|
|
31
|
+
JaegerTracer.prototype = {
|
|
32
|
+
isTracingSupported: function isTracingSupported() {
|
|
33
|
+
return true;
|
|
34
|
+
},
|
|
35
|
+
getSpanId: function getSpanId() {
|
|
36
|
+
return this._spanId;
|
|
37
|
+
},
|
|
38
|
+
getTraceId: function getTraceId() {
|
|
39
|
+
return this._traceId;
|
|
40
|
+
},
|
|
41
|
+
getUberTraceId: function getUberTraceId() {
|
|
42
|
+
//{trace-id}:{span-id}:{parent-span-id}:{flags}
|
|
43
|
+
return this._traceId + ':' + this._spanId + ':' + '0' + ':' + '1';
|
|
44
|
+
},
|
|
45
|
+
makeTracingHeaders: function makeTracingHeaders() {
|
|
46
|
+
return {
|
|
47
|
+
'uber-trace-id': this.getUberTraceId()
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { base64Encode, urlParse } from '@cloudcare/browser-core'; // start SkyWalking
|
|
2
|
+
|
|
3
|
+
function uuid() {
|
|
4
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
|
|
5
|
+
/* tslint:disable */
|
|
6
|
+
var r = Math.random() * 16 | 0;
|
|
7
|
+
/* tslint:disable */
|
|
8
|
+
|
|
9
|
+
var v = c === 'x' ? r : r & 0x3 | 0x8;
|
|
10
|
+
return v.toString(16);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @param {*} traceId
|
|
16
|
+
* @param {*} traceSegmentId
|
|
17
|
+
* @param {*} applicationId
|
|
18
|
+
* @param {*} version
|
|
19
|
+
* @param {*} requestUrlHost
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
function getSkyWalkingSw8(traceId, traceSegmentId, applicationId, env, version, requestUrlHost) {
|
|
24
|
+
try {
|
|
25
|
+
var traceIdStr = String(base64Encode(traceId));
|
|
26
|
+
var segmentId = String(base64Encode(traceSegmentId));
|
|
27
|
+
var service = String(base64Encode(applicationId + '_rum_' + env));
|
|
28
|
+
var instance = String(base64Encode(version));
|
|
29
|
+
var endpoint = String(base64Encode(window.location.href));
|
|
30
|
+
var peer = String(base64Encode(requestUrlHost));
|
|
31
|
+
var index = '0'; // var values = `${1}-${traceIdStr}-${segmentId}-${index}-${service}-${instance}-${endpoint}-${peer}`;
|
|
32
|
+
|
|
33
|
+
return '1-' + traceIdStr + '-' + segmentId + '-' + index + '-' + service + '-' + instance + '-' + endpoint + '-' + peer;
|
|
34
|
+
} catch (err) {
|
|
35
|
+
return '';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* @param {*} configuration 配置信息
|
|
41
|
+
* @param {*} requestUrl 请求的url
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
export function SkyWalkingTracer(configuration, requestUrl) {
|
|
46
|
+
this._spanId = uuid();
|
|
47
|
+
this._traceId = uuid();
|
|
48
|
+
this._applicationId = configuration.applicationId;
|
|
49
|
+
this._env = configuration.env;
|
|
50
|
+
this._version = configuration.version;
|
|
51
|
+
this._urlParse = urlParse(requestUrl).getParse();
|
|
52
|
+
}
|
|
53
|
+
SkyWalkingTracer.prototype = {
|
|
54
|
+
isTracingSupported: function isTracingSupported() {
|
|
55
|
+
if (this._env && this._version && this._urlParse) return true;
|
|
56
|
+
return false;
|
|
57
|
+
},
|
|
58
|
+
getSpanId: function getSpanId() {
|
|
59
|
+
return this._spanId;
|
|
60
|
+
},
|
|
61
|
+
getTraceId: function getTraceId() {
|
|
62
|
+
return this._traceId;
|
|
63
|
+
},
|
|
64
|
+
getSkyWalkingSw8: function getSkyWalkingSw8() {
|
|
65
|
+
try {
|
|
66
|
+
var traceIdStr = String(base64Encode(this._traceId));
|
|
67
|
+
var segmentId = String(base64Encode(this._spanId));
|
|
68
|
+
var service = String(base64Encode(this._applicationId + '_rum_' + this.env));
|
|
69
|
+
var instance = String(base64Encode(this._version));
|
|
70
|
+
var endpoint = String(base64Encode(window.location.href));
|
|
71
|
+
var peer = String(base64Encode(this._urlParse.Host));
|
|
72
|
+
var index = '0'; // var values = `${1}-${traceIdStr}-${segmentId}-${index}-${service}-${instance}-${endpoint}-${peer}`;
|
|
73
|
+
|
|
74
|
+
return '1-' + traceIdStr + '-' + segmentId + '-' + index + '-' + service + '-' + instance + '-' + endpoint + '-' + peer;
|
|
75
|
+
} catch (err) {
|
|
76
|
+
return '';
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
makeTracingHeaders: function makeTracingHeaders() {
|
|
80
|
+
return {
|
|
81
|
+
'sw8': this.getSkyWalkingSw8()
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
};
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import { objectEntries, each, extend, isArray, getOrigin } from '@cloudcare/browser-core';
|
|
1
|
+
import { objectEntries, each, extend, isArray, TraceType, getOrigin } from '@cloudcare/browser-core';
|
|
2
|
+
import { DDtraceTracer } from './ddtraceTracer';
|
|
3
|
+
import { SkyWalkingTracer } from './skywalkingTracer';
|
|
4
|
+
import { JaegerTracer } from './jaegerTracer';
|
|
5
|
+
import { ZipkinSingleTracer } from './zipkinSingleTracer';
|
|
6
|
+
import { ZipkinMultiTracer } from './zipkinMultiTracer';
|
|
7
|
+
import { W3cTraceParentTracer } from './w3cTraceParentTracer';
|
|
2
8
|
export function clearTracingIfCancelled(context) {
|
|
3
9
|
if (context.status === 0) {
|
|
4
10
|
context.traceId = undefined;
|
|
@@ -40,20 +46,10 @@ export function startTracer(configuration) {
|
|
|
40
46
|
};
|
|
41
47
|
}
|
|
42
48
|
|
|
43
|
-
function injectHeadersIfTracingAllowed(configuration, context, inject) {
|
|
44
|
-
if (!isTracingSupported() || !isAllowedUrl(configuration, context.url)) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
context.traceId = new TraceIdentifier();
|
|
49
|
-
context.spanId = new TraceIdentifier();
|
|
50
|
-
inject(makeTracingHeaders(context.traceId, context.spanId));
|
|
51
|
-
}
|
|
52
|
-
|
|
53
49
|
function isAllowedUrl(configuration, requestUrl) {
|
|
54
50
|
var requestOrigin = getOrigin(requestUrl);
|
|
55
51
|
var flag = false;
|
|
56
|
-
each(configuration.
|
|
52
|
+
each(configuration.allowedTracingOrigins, function (allowedOrigin) {
|
|
57
53
|
if (requestOrigin === allowedOrigin || allowedOrigin instanceof RegExp && allowedOrigin.test(requestOrigin)) {
|
|
58
54
|
flag = true;
|
|
59
55
|
return false;
|
|
@@ -62,56 +58,47 @@ function isAllowedUrl(configuration, requestUrl) {
|
|
|
62
58
|
return flag;
|
|
63
59
|
}
|
|
64
60
|
|
|
65
|
-
export function
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
export function injectHeadersIfTracingAllowed(configuration, context, inject) {
|
|
62
|
+
if (!isAllowedUrl(configuration, context.url) || !configuration.traceType) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
68
65
|
|
|
69
|
-
|
|
70
|
-
return window.crypto || window.msCrypto;
|
|
71
|
-
}
|
|
66
|
+
var tracer;
|
|
72
67
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
'x-datadog-sampled': '1',
|
|
78
|
-
'x-datadog-sampling-priority': '1',
|
|
79
|
-
'x-datadog-trace-id': traceId.toDecimalString()
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
/* tslint:disable:no-bitwise */
|
|
68
|
+
switch (configuration.traceType) {
|
|
69
|
+
case TraceType.DDTRACE:
|
|
70
|
+
tracer = new DDtraceTracer();
|
|
71
|
+
break;
|
|
83
72
|
|
|
73
|
+
case TraceType.SKYWALKING_V3:
|
|
74
|
+
tracer = new SkyWalkingTracer(configuration, context.url);
|
|
75
|
+
break;
|
|
84
76
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
this.buffer[0] = this.buffer[0] & 0x7f;
|
|
89
|
-
}
|
|
90
|
-
TraceIdentifier.prototype = {
|
|
91
|
-
// buffer: new Uint8Array(8),
|
|
92
|
-
toString: function toString(radix) {
|
|
93
|
-
var high = this.readInt32(0);
|
|
94
|
-
var low = this.readInt32(4);
|
|
95
|
-
var str = '';
|
|
77
|
+
case TraceType.ZIPKIN_MULTI_HEADER:
|
|
78
|
+
tracer = new ZipkinMultiTracer(configuration);
|
|
79
|
+
break;
|
|
96
80
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
low = Math.floor(mod / radix);
|
|
101
|
-
str = (mod % radix).toString(radix) + str;
|
|
81
|
+
case TraceType.JAEGER:
|
|
82
|
+
tracer = new JaegerTracer(configuration);
|
|
83
|
+
break;
|
|
102
84
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
85
|
+
case TraceType.W3C_TRACEPARENT:
|
|
86
|
+
tracer = new W3cTraceParentTracer(configuration);
|
|
87
|
+
break;
|
|
88
|
+
|
|
89
|
+
case TraceType.ZIPKIN_SINGLE_HEADER:
|
|
90
|
+
tracer = new ZipkinSingleTracer(configuration);
|
|
91
|
+
break;
|
|
107
92
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
toDecimalString: function toDecimalString() {
|
|
111
|
-
return this.toString(10);
|
|
112
|
-
},
|
|
113
|
-
readInt32: function readInt32(offset) {
|
|
114
|
-
return this.buffer[offset] * 16777216 + (this.buffer[offset + 1] << 16) + (this.buffer[offset + 2] << 8) + this.buffer[offset + 3];
|
|
93
|
+
default:
|
|
94
|
+
break;
|
|
115
95
|
}
|
|
116
|
-
|
|
117
|
-
|
|
96
|
+
|
|
97
|
+
if (!tracer || !tracer.isTracingSupported()) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
context.traceId = tracer.getTraceId();
|
|
102
|
+
context.spanId = tracer.getSpanId();
|
|
103
|
+
inject(tracer.makeTracingHeaders());
|
|
104
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// === Generate a random 64-bit number in fixed-length hex format
|
|
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
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @param {*} configuration 配置信息
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
export function W3cTraceParentTracer(configuration) {
|
|
20
|
+
var rootSpanId = randomTraceId();
|
|
21
|
+
this._traceId = randomTraceId() + rootSpanId;
|
|
22
|
+
this._spanId = rootSpanId;
|
|
23
|
+
}
|
|
24
|
+
W3cTraceParentTracer.prototype = {
|
|
25
|
+
isTracingSupported: function isTracingSupported() {
|
|
26
|
+
return true;
|
|
27
|
+
},
|
|
28
|
+
getSpanId: function getSpanId() {
|
|
29
|
+
return this._spanId;
|
|
30
|
+
},
|
|
31
|
+
getTraceId: function getTraceId() {
|
|
32
|
+
return this._traceId;
|
|
33
|
+
},
|
|
34
|
+
getTraceParent: function getTraceParent() {
|
|
35
|
+
// '{version}-{traceId}-{spanId}-{sampleDecision}'
|
|
36
|
+
return '00-' + this._traceId + '-' + this._spanId + '-01';
|
|
37
|
+
},
|
|
38
|
+
makeTracingHeaders: function makeTracingHeaders() {
|
|
39
|
+
return {
|
|
40
|
+
'traceparent': this.getTraceParent()
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// === Generate a random 64-bit number in fixed-length hex format
|
|
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
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @param {*} configuration 配置信息
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
export function ZipkinMultiTracer(configuration) {
|
|
20
|
+
var rootSpanId = randomTraceId();
|
|
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;
|
|
30
|
+
}
|
|
31
|
+
ZipkinMultiTracer.prototype = {
|
|
32
|
+
isTracingSupported: function isTracingSupported() {
|
|
33
|
+
return true;
|
|
34
|
+
},
|
|
35
|
+
getSpanId: function getSpanId() {
|
|
36
|
+
return this._spanId;
|
|
37
|
+
},
|
|
38
|
+
getTraceId: function getTraceId() {
|
|
39
|
+
return this._traceId;
|
|
40
|
+
},
|
|
41
|
+
makeTracingHeaders: function makeTracingHeaders() {
|
|
42
|
+
return {
|
|
43
|
+
'X-B3-TraceId': this.getTraceId(),
|
|
44
|
+
'X-B3-SpanId': this.getSpanId(),
|
|
45
|
+
// 'X-B3-ParentSpanId': '',
|
|
46
|
+
'X-B3-Sampled': '1' // 'X-B3-Flags': '0'
|
|
47
|
+
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// === Generate a random 64-bit number in fixed-length hex format
|
|
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
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @param {*} configuration 配置信息
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
export function ZipkinSingleTracer(configuration) {
|
|
20
|
+
var rootSpanId = randomTraceId();
|
|
21
|
+
this._traceId = randomTraceId() + rootSpanId;
|
|
22
|
+
this._spanId = rootSpanId;
|
|
23
|
+
}
|
|
24
|
+
ZipkinSingleTracer.prototype = {
|
|
25
|
+
isTracingSupported: function isTracingSupported() {
|
|
26
|
+
return true;
|
|
27
|
+
},
|
|
28
|
+
getSpanId: function getSpanId() {
|
|
29
|
+
return this._spanId;
|
|
30
|
+
},
|
|
31
|
+
getTraceId: function getTraceId() {
|
|
32
|
+
return this._traceId;
|
|
33
|
+
},
|
|
34
|
+
getB3Str: function getB3Str() {
|
|
35
|
+
//{TraceId}-{SpanId}-{SamplingState}-{ParentSpanId}
|
|
36
|
+
return this._traceId + '-' + this._spanId + '-1';
|
|
37
|
+
},
|
|
38
|
+
makeTracingHeaders: function makeTracingHeaders() {
|
|
39
|
+
return {
|
|
40
|
+
'b3': this.getB3Str()
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudcare/browser-rum",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.21",
|
|
4
4
|
"main": "cjs/index.js",
|
|
5
5
|
"module": "esm/index.js",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@cloudcare/browser-core": "1.0.
|
|
7
|
+
"@cloudcare/browser-core": "1.0.17"
|
|
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": "aa44bc2dbca2017e36e0561d810825e89715d847"
|
|
33
33
|
}
|
package/src/boot/rumPublicApi.js
CHANGED
|
@@ -69,7 +69,6 @@ export function makeRumPublicApi(startRumImpl) {
|
|
|
69
69
|
// if (userConfiguration.publicApiKey) {
|
|
70
70
|
// userConfiguration.clientToken = userConfiguration.publicApiKey
|
|
71
71
|
// }
|
|
72
|
-
|
|
73
72
|
var _startRumImpl = startRumImpl(userConfiguration, function () {
|
|
74
73
|
return {
|
|
75
74
|
user: user,
|
package/src/domain/.DS_Store
CHANGED
|
Binary file
|
package/src/domain/assembly.js
CHANGED
|
@@ -73,19 +73,28 @@ export function startRumAssembly(
|
|
|
73
73
|
session: {
|
|
74
74
|
// must be computed on each event because synthetics instrumentation can be done after sdk execution
|
|
75
75
|
// cf https://github.com/puppeteer/puppeteer/issues/3667
|
|
76
|
-
type: getSessionType()
|
|
76
|
+
type: getSessionType(),
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
var sessionAliasTag = {}
|
|
80
|
+
if (session.isTrackedWidthService()) {
|
|
81
|
+
// 如果是触发了采样的数据,则加上额外的tag
|
|
82
|
+
sessionAliasTag = {
|
|
83
|
+
session: {
|
|
84
|
+
is_sampling: '1'
|
|
85
|
+
}
|
|
77
86
|
}
|
|
78
87
|
}
|
|
79
|
-
|
|
80
88
|
var rumEvent = needToAssembleWithAction(rawRumEvent)
|
|
81
89
|
? extend2Lev(
|
|
82
90
|
rumContext,
|
|
83
91
|
deviceContext,
|
|
92
|
+
sessionAliasTag,
|
|
84
93
|
viewContext,
|
|
85
94
|
actionContext,
|
|
86
95
|
rawRumEvent
|
|
87
96
|
)
|
|
88
|
-
: extend2Lev(rumContext, deviceContext, viewContext, rawRumEvent)
|
|
97
|
+
: extend2Lev(rumContext, deviceContext, sessionAliasTag, viewContext, rawRumEvent)
|
|
89
98
|
var serverRumEvent = withSnakeCaseKeys(rumEvent)
|
|
90
99
|
var context = extend2Lev(commonContext.context, customerContext)
|
|
91
100
|
if (!isEmptyObject(context)) {
|
|
@@ -5,7 +5,12 @@ import {
|
|
|
5
5
|
urlParse,
|
|
6
6
|
replaceNumberCharByPath,
|
|
7
7
|
RumEventType,
|
|
8
|
-
LifeCycleEventType
|
|
8
|
+
LifeCycleEventType,
|
|
9
|
+
formatUnknownError,
|
|
10
|
+
computeStackTrace,
|
|
11
|
+
ErrorHandling,
|
|
12
|
+
ErrorSource,
|
|
13
|
+
extend
|
|
9
14
|
} from '@cloudcare/browser-core'
|
|
10
15
|
export function startErrorCollection(lifeCycle, configuration) {
|
|
11
16
|
startAutomaticErrorCollection(configuration).subscribe(function (error) {
|
|
@@ -23,20 +28,29 @@ export function doStartErrorCollection(lifeCycle) {
|
|
|
23
28
|
})
|
|
24
29
|
return {
|
|
25
30
|
addError: function (customError, savedCommonContext) {
|
|
26
|
-
var rawError = computeRawError(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
)
|
|
31
|
-
lifeCycle.notify(LifeCycleEventType.RAW_ERROR_COLLECTED, {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
})
|
|
31
|
+
// var rawError = computeRawError(
|
|
32
|
+
// customError.error,
|
|
33
|
+
// customError.handlingStack,
|
|
34
|
+
// customError.startClocks
|
|
35
|
+
// )
|
|
36
|
+
// lifeCycle.notify(LifeCycleEventType.RAW_ERROR_COLLECTED, {
|
|
37
|
+
// customerContext: customError.context,
|
|
38
|
+
// savedCommonContext: savedCommonContext,
|
|
39
|
+
// error: rawError
|
|
40
|
+
// })
|
|
36
41
|
}
|
|
37
42
|
}
|
|
38
43
|
}
|
|
44
|
+
// function computeRawError(error, handlingStack, startTime) {
|
|
45
|
+
// const stackTrace = error instanceof Error ? computeStackTrace(error) : undefined
|
|
46
|
+
// return extend({
|
|
47
|
+
// startTime:startTime,
|
|
48
|
+
// source: ErrorSource.CUSTOM,
|
|
49
|
+
// originalError: error,
|
|
50
|
+
// handling: ErrorHandling.HANDLED
|
|
51
|
+
// }, formatUnknownError(stackTrace, error, 'Provided', handlingStack) )
|
|
39
52
|
|
|
53
|
+
// }
|
|
40
54
|
function processError(error) {
|
|
41
55
|
var resource = error.resource
|
|
42
56
|
if (resource) {
|
|
@@ -26,6 +26,7 @@ export function matchRequestTiming(request) {
|
|
|
26
26
|
var candidates = map(sameNameEntries, function (entry) {
|
|
27
27
|
return entry.toJSON()
|
|
28
28
|
})
|
|
29
|
+
|
|
29
30
|
candidates = filter(candidates, toValidEntry)
|
|
30
31
|
candidates = filter(candidates, function (entry) {
|
|
31
32
|
return isBetween(
|
|
@@ -56,7 +56,6 @@ export function startResourceCollection(lifeCycle, configuration, session) {
|
|
|
56
56
|
function processRequest(request) {
|
|
57
57
|
var type =
|
|
58
58
|
request.type === RequestType.XHR ? ResourceType.XHR : ResourceType.FETCH
|
|
59
|
-
|
|
60
59
|
var matchingTiming = matchRequestTiming(request)
|
|
61
60
|
var startClocks = matchingTiming
|
|
62
61
|
? relativeToClocks(matchingTiming.startTime)
|
|
@@ -143,8 +142,8 @@ function computeRequestTracingInfo(request) {
|
|
|
143
142
|
}
|
|
144
143
|
return {
|
|
145
144
|
_dd: {
|
|
146
|
-
spanId: request.spanId
|
|
147
|
-
traceId: request.traceId
|
|
145
|
+
spanId: request.spanId,
|
|
146
|
+
traceId: request.traceId
|
|
148
147
|
},
|
|
149
148
|
resource: { id: UUID() }
|
|
150
149
|
}
|
|
@@ -152,4 +151,4 @@ function computeRequestTracingInfo(request) {
|
|
|
152
151
|
|
|
153
152
|
function computeEntryTracingInfo(entry) {
|
|
154
153
|
return entry.traceId ? { _dd: { traceId: entry.traceId } } : undefined
|
|
155
|
-
}
|
|
154
|
+
}
|