@cloudcare/browser-rum 2.0.19 → 2.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -11
- package/bundle/dataflux-rum.js +1 -1
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/boot/rumPublicApi.js +18 -31
- package/cjs/domain/assembly.js +14 -4
- package/cjs/domain/requestCollections.js +0 -1
- package/cjs/domain/rumEventsCollection/actions/actionCollection.js +5 -1
- package/cjs/domain/rumEventsCollection/error/errorCollection.js +17 -2
- package/cjs/domain/rumEventsCollection/resource/resourceCollection.js +2 -2
- package/cjs/domain/rumSession.js +21 -6
- package/cjs/domain/tracing/ddtraceTracer.js +75 -0
- package/cjs/domain/tracing/jaegerTracer.js +58 -0
- package/cjs/domain/tracing/skywalkingTracer.js +93 -0
- package/cjs/domain/tracing/tracer.js +51 -60
- package/cjs/domain/tracing/w3cTraceParentTracer.js +51 -0
- package/cjs/domain/tracing/zipkinMultiTracer.js +58 -0
- package/cjs/domain/tracing/zipkinSingleTracer.js +51 -0
- package/esm/boot/buildEnv.js +1 -1
- package/esm/boot/rumPublicApi.js +19 -32
- package/esm/domain/assembly.js +14 -4
- package/esm/domain/requestCollections.js +0 -1
- package/esm/domain/rumEventsCollection/actions/actionCollection.js +5 -1
- package/esm/domain/rumEventsCollection/error/errorCollection.js +18 -3
- package/esm/domain/rumEventsCollection/resource/resourceCollection.js +2 -2
- package/esm/domain/rumSession.js +21 -6
- package/esm/domain/tracing/ddtraceTracer.js +67 -0
- package/esm/domain/tracing/jaegerTracer.js +50 -0
- package/esm/domain/tracing/skywalkingTracer.js +84 -0
- package/esm/domain/tracing/tracer.js +44 -57
- package/esm/domain/tracing/w3cTraceParentTracer.js +43 -0
- package/esm/domain/tracing/zipkinMultiTracer.js +50 -0
- package/esm/domain/tracing/zipkinSingleTracer.js +43 -0
- package/package.json +3 -3
- package/src/boot/rumPublicApi.js +22 -34
- package/src/domain/.DS_Store +0 -0
- package/src/domain/assembly.js +14 -6
- package/src/domain/requestCollections.js +0 -1
- package/src/domain/rumEventsCollection/actions/actionCollection.js +5 -1
- package/src/domain/rumEventsCollection/error/errorCollection.js +23 -4
- package/src/domain/rumEventsCollection/resource/matchRequestTiming.js +1 -0
- package/src/domain/rumEventsCollection/resource/resourceCollection.js +3 -4
- package/src/domain/rumSession.js +24 -7
- package/src/domain/tracing/ddtraceTracer.js +70 -0
- package/src/domain/tracing/jaegerTracer.js +47 -0
- package/src/domain/tracing/skywalkingTracer.js +80 -0
- package/src/domain/tracing/tracer.js +40 -68
- package/src/domain/tracing/w3cTraceParentTracer.js +40 -0
- package/src/domain/tracing/zipkinMultiTracer.js +46 -0
- package/src/domain/tracing/zipkinSingleTracer.js +40 -0
|
@@ -3,8 +3,15 @@ import {
|
|
|
3
3
|
each,
|
|
4
4
|
extend,
|
|
5
5
|
isArray,
|
|
6
|
+
TraceType,
|
|
6
7
|
getOrigin
|
|
7
8
|
} from '@cloudcare/browser-core'
|
|
9
|
+
import { DDtraceTracer} from './ddtraceTracer'
|
|
10
|
+
import { SkyWalkingTracer} from './skywalkingTracer'
|
|
11
|
+
import { JaegerTracer} from './jaegerTracer'
|
|
12
|
+
import { ZipkinSingleTracer} from './zipkinSingleTracer'
|
|
13
|
+
import { ZipkinMultiTracer} from './zipkinMultiTracer'
|
|
14
|
+
import { W3cTraceParentTracer} from './w3cTraceParentTracer'
|
|
8
15
|
|
|
9
16
|
export function clearTracingIfCancelled(context) {
|
|
10
17
|
if (context.status === 0) {
|
|
@@ -53,20 +60,10 @@ export function startTracer(configuration) {
|
|
|
53
60
|
}
|
|
54
61
|
}
|
|
55
62
|
}
|
|
56
|
-
|
|
57
|
-
function injectHeadersIfTracingAllowed(configuration, context, inject) {
|
|
58
|
-
if (!isTracingSupported() || !isAllowedUrl(configuration, context.url)) {
|
|
59
|
-
return
|
|
60
|
-
}
|
|
61
|
-
context.traceId = new TraceIdentifier()
|
|
62
|
-
context.spanId = new TraceIdentifier()
|
|
63
|
-
inject(makeTracingHeaders(context.traceId, context.spanId))
|
|
64
|
-
}
|
|
65
|
-
|
|
66
63
|
function isAllowedUrl(configuration, requestUrl) {
|
|
67
64
|
var requestOrigin = getOrigin(requestUrl)
|
|
68
65
|
var flag = false
|
|
69
|
-
each(configuration.
|
|
66
|
+
each(configuration.allowedTracingOrigins, function (allowedOrigin) {
|
|
70
67
|
if (
|
|
71
68
|
requestOrigin === allowedOrigin ||
|
|
72
69
|
(allowedOrigin instanceof RegExp && allowedOrigin.test(requestOrigin))
|
|
@@ -78,63 +75,38 @@ function isAllowedUrl(configuration, requestUrl) {
|
|
|
78
75
|
return flag
|
|
79
76
|
}
|
|
80
77
|
|
|
81
|
-
export function
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
function getCrypto() {
|
|
86
|
-
return window.crypto || window.msCrypto
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function makeTracingHeaders(traceId, spanId) {
|
|
90
|
-
return {
|
|
91
|
-
'x-datadog-origin': 'rum',
|
|
92
|
-
// 'x-datadog-parent-id': spanId.toDecimalString(),
|
|
93
|
-
'x-datadog-sampled': '1',
|
|
94
|
-
'x-datadog-sampling-priority': '1',
|
|
95
|
-
'x-datadog-trace-id': traceId.toDecimalString()
|
|
78
|
+
export function injectHeadersIfTracingAllowed(configuration, context, inject) {
|
|
79
|
+
if (!isAllowedUrl(configuration, context.url) || !configuration.traceType) {
|
|
80
|
+
return
|
|
96
81
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return str
|
|
125
|
-
},
|
|
126
|
-
toDecimalString: function () {
|
|
127
|
-
return this.toString(10)
|
|
128
|
-
},
|
|
129
|
-
|
|
130
|
-
readInt32: function (offset) {
|
|
131
|
-
return (
|
|
132
|
-
this.buffer[offset] * 16777216 +
|
|
133
|
-
(this.buffer[offset + 1] << 16) +
|
|
134
|
-
(this.buffer[offset + 2] << 8) +
|
|
135
|
-
this.buffer[offset + 3]
|
|
136
|
-
)
|
|
82
|
+
var tracer;
|
|
83
|
+
switch(configuration.traceType) {
|
|
84
|
+
case TraceType.DDTRACE:
|
|
85
|
+
tracer = new DDtraceTracer();
|
|
86
|
+
break;
|
|
87
|
+
case TraceType.SKYWALKING_V3:
|
|
88
|
+
tracer = new SkyWalkingTracer(configuration, context.url);
|
|
89
|
+
break;
|
|
90
|
+
case TraceType.ZIPKIN_MULTI_HEADER:
|
|
91
|
+
tracer = new ZipkinMultiTracer(configuration);
|
|
92
|
+
break;
|
|
93
|
+
case TraceType.JAEGER:
|
|
94
|
+
tracer = new JaegerTracer(configuration);
|
|
95
|
+
break;
|
|
96
|
+
case TraceType.W3C_TRACEPARENT:
|
|
97
|
+
tracer = new W3cTraceParentTracer(configuration);
|
|
98
|
+
break;
|
|
99
|
+
case TraceType.ZIPKIN_SINGLE_HEADER:
|
|
100
|
+
tracer = new ZipkinSingleTracer(configuration);
|
|
101
|
+
break;
|
|
102
|
+
default:
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
if (!tracer || !tracer.isTracingSupported()) {
|
|
106
|
+
return
|
|
137
107
|
}
|
|
138
|
-
}
|
|
139
108
|
|
|
140
|
-
|
|
109
|
+
context.traceId = tracer.getTraceId()
|
|
110
|
+
context.spanId = tracer.getSpanId()
|
|
111
|
+
inject(tracer.makeTracingHeaders())
|
|
112
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// === Generate a random 64-bit number in fixed-length hex format
|
|
2
|
+
function randomTraceId() {
|
|
3
|
+
const digits = '0123456789abcdef';
|
|
4
|
+
let n = '';
|
|
5
|
+
for (let i = 0; i < 16; i += 1) {
|
|
6
|
+
const rand = Math.floor(Math.random() * 16);
|
|
7
|
+
n += digits[rand];
|
|
8
|
+
}
|
|
9
|
+
return n;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param {*} configuration 配置信息
|
|
15
|
+
*/
|
|
16
|
+
export function W3cTraceParentTracer(configuration) {
|
|
17
|
+
const rootSpanId = randomTraceId();
|
|
18
|
+
this._traceId = randomTraceId() + rootSpanId
|
|
19
|
+
this._spanId = rootSpanId
|
|
20
|
+
}
|
|
21
|
+
W3cTraceParentTracer.prototype = {
|
|
22
|
+
isTracingSupported: function() {
|
|
23
|
+
return true
|
|
24
|
+
},
|
|
25
|
+
getSpanId:function() {
|
|
26
|
+
return this._spanId
|
|
27
|
+
},
|
|
28
|
+
getTraceId: function() {
|
|
29
|
+
return this._traceId
|
|
30
|
+
},
|
|
31
|
+
getTraceParent: function() {
|
|
32
|
+
// '{version}-{traceId}-{spanId}-{sampleDecision}'
|
|
33
|
+
return '00-' + this._traceId + '-' + this._spanId + '-01'
|
|
34
|
+
},
|
|
35
|
+
makeTracingHeaders: function() {
|
|
36
|
+
return {
|
|
37
|
+
'traceparent': this.getTraceParent()
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// === Generate a random 64-bit number in fixed-length hex format
|
|
2
|
+
function randomTraceId() {
|
|
3
|
+
const digits = '0123456789abcdef';
|
|
4
|
+
let n = '';
|
|
5
|
+
for (let i = 0; i < 16; i += 1) {
|
|
6
|
+
const rand = Math.floor(Math.random() * 16);
|
|
7
|
+
n += digits[rand];
|
|
8
|
+
}
|
|
9
|
+
return n;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param {*} configuration 配置信息
|
|
15
|
+
*/
|
|
16
|
+
export function ZipkinMultiTracer(configuration) {
|
|
17
|
+
const rootSpanId = randomTraceId();
|
|
18
|
+
if (configuration.traceId128Bit) {
|
|
19
|
+
// 128bit生成traceid
|
|
20
|
+
this._traceId = randomTraceId() + rootSpanId
|
|
21
|
+
} else {
|
|
22
|
+
this._traceId = rootSpanId
|
|
23
|
+
}
|
|
24
|
+
this._spanId = rootSpanId
|
|
25
|
+
}
|
|
26
|
+
ZipkinMultiTracer.prototype = {
|
|
27
|
+
isTracingSupported: function() {
|
|
28
|
+
return true
|
|
29
|
+
},
|
|
30
|
+
getSpanId:function() {
|
|
31
|
+
return this._spanId
|
|
32
|
+
},
|
|
33
|
+
getTraceId: function() {
|
|
34
|
+
return this._traceId
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
makeTracingHeaders: function() {
|
|
38
|
+
return {
|
|
39
|
+
'X-B3-TraceId': this.getTraceId(),
|
|
40
|
+
'X-B3-SpanId': this.getSpanId(),
|
|
41
|
+
// 'X-B3-ParentSpanId': '',
|
|
42
|
+
'X-B3-Sampled': '1',
|
|
43
|
+
// 'X-B3-Flags': '0'
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// === Generate a random 64-bit number in fixed-length hex format
|
|
2
|
+
function randomTraceId() {
|
|
3
|
+
const digits = '0123456789abcdef';
|
|
4
|
+
let n = '';
|
|
5
|
+
for (let i = 0; i < 16; i += 1) {
|
|
6
|
+
const rand = Math.floor(Math.random() * 16);
|
|
7
|
+
n += digits[rand];
|
|
8
|
+
}
|
|
9
|
+
return n;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param {*} configuration 配置信息
|
|
15
|
+
*/
|
|
16
|
+
export function ZipkinSingleTracer(configuration) {
|
|
17
|
+
const rootSpanId = randomTraceId();
|
|
18
|
+
this._traceId = randomTraceId() + rootSpanId
|
|
19
|
+
this._spanId = rootSpanId
|
|
20
|
+
}
|
|
21
|
+
ZipkinSingleTracer.prototype = {
|
|
22
|
+
isTracingSupported: function() {
|
|
23
|
+
return true
|
|
24
|
+
},
|
|
25
|
+
getSpanId:function() {
|
|
26
|
+
return this._spanId
|
|
27
|
+
},
|
|
28
|
+
getTraceId: function() {
|
|
29
|
+
return this._traceId
|
|
30
|
+
},
|
|
31
|
+
getB3Str: function() {
|
|
32
|
+
//{TraceId}-{SpanId}-{SamplingState}-{ParentSpanId}
|
|
33
|
+
return this._traceId + '-' + this._spanId + '-1'
|
|
34
|
+
},
|
|
35
|
+
makeTracingHeaders: function() {
|
|
36
|
+
return {
|
|
37
|
+
'b3': this.getB3Str()
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|