@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
|
@@ -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.22",
|
|
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.18"
|
|
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": "677c6f4023801b95eada2bacf237290848ddfb08"
|
|
33
33
|
}
|
package/src/boot/rumPublicApi.js
CHANGED
|
@@ -12,7 +12,9 @@ import {
|
|
|
12
12
|
ActionType,
|
|
13
13
|
ErrorSource,
|
|
14
14
|
isEmptyObject,
|
|
15
|
-
|
|
15
|
+
deepClone,
|
|
16
|
+
formatDate,
|
|
17
|
+
createHandlingStack
|
|
16
18
|
} from '@cloudcare/browser-core'
|
|
17
19
|
|
|
18
20
|
export function makeRumPublicApi(startRumImpl) {
|
|
@@ -48,8 +50,7 @@ export function makeRumPublicApi(startRumImpl) {
|
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
function clonedCommonContext() {
|
|
51
|
-
return
|
|
52
|
-
{},
|
|
53
|
+
return deepClone(
|
|
53
54
|
{
|
|
54
55
|
context: globalContextManager.get(),
|
|
55
56
|
user: user
|
|
@@ -69,7 +70,6 @@ export function makeRumPublicApi(startRumImpl) {
|
|
|
69
70
|
// if (userConfiguration.publicApiKey) {
|
|
70
71
|
// userConfiguration.clientToken = userConfiguration.publicApiKey
|
|
71
72
|
// }
|
|
72
|
-
|
|
73
73
|
var _startRumImpl = startRumImpl(userConfiguration, function () {
|
|
74
74
|
return {
|
|
75
75
|
user: user,
|
|
@@ -164,14 +164,14 @@ export function makeRumPublicApi(startRumImpl) {
|
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
},
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
167
|
+
addAction: function (name, context) {
|
|
168
|
+
addActionStrategy({
|
|
169
|
+
name: name,
|
|
170
|
+
context: deepClone(context),
|
|
171
|
+
startClocks: clocksNow(),
|
|
172
|
+
type: ActionType.CUSTOM,
|
|
173
|
+
})
|
|
174
|
+
},
|
|
175
175
|
|
|
176
176
|
/**
|
|
177
177
|
* @deprecated use addAction instead
|
|
@@ -180,28 +180,16 @@ export function makeRumPublicApi(startRumImpl) {
|
|
|
180
180
|
// rumPublicApi.addAction(name, context)
|
|
181
181
|
// },
|
|
182
182
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
// checkedSource = source
|
|
194
|
-
// } else {
|
|
195
|
-
// console.error(`DD_RUM.addError: Invalid source '${source}'`)
|
|
196
|
-
// checkedSource = ErrorSource.CUSTOM
|
|
197
|
-
// }
|
|
198
|
-
// addErrorStrategy({
|
|
199
|
-
// error: error,
|
|
200
|
-
// context: extend2Lev({}, context),
|
|
201
|
-
// source: checkedSource,
|
|
202
|
-
// startClocks: clocksNow()
|
|
203
|
-
// })
|
|
204
|
-
// },
|
|
183
|
+
addError: function (error, context) {
|
|
184
|
+
const handlingStack = createHandlingStack()
|
|
185
|
+
addErrorStrategy({
|
|
186
|
+
error: error,
|
|
187
|
+
handlingStack:handlingStack,
|
|
188
|
+
context: deepClone(context),
|
|
189
|
+
startClocks: clocksNow(),
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
},
|
|
205
193
|
|
|
206
194
|
// addTiming: function (name) {
|
|
207
195
|
// addTimingStrategy(name)
|
package/src/domain/.DS_Store
CHANGED
|
Binary file
|
package/src/domain/assembly.js
CHANGED
|
@@ -38,7 +38,7 @@ export function startRumAssembly(
|
|
|
38
38
|
function (data) {
|
|
39
39
|
var startTime = data.startTime
|
|
40
40
|
var rawRumEvent = data.rawRumEvent
|
|
41
|
-
var savedCommonContext = data.
|
|
41
|
+
var savedCommonContext = data.savedCommonContext
|
|
42
42
|
var customerContext = data.customerContext
|
|
43
43
|
var viewContext = parentContexts.findView(startTime)
|
|
44
44
|
var deviceContext = {
|
|
@@ -73,21 +73,30 @@ 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
|
-
var context = extend2Lev(commonContext.context, customerContext)
|
|
99
|
+
var context = extend2Lev({},commonContext.context, customerContext)
|
|
91
100
|
if (!isEmptyObject(context)) {
|
|
92
101
|
serverRumEvent.tags = context
|
|
93
102
|
}
|
|
@@ -112,7 +121,6 @@ export function startRumAssembly(
|
|
|
112
121
|
// ) {
|
|
113
122
|
// console.log(serverRumEvent, '======serverRumEvent-====')
|
|
114
123
|
// }
|
|
115
|
-
console.log(serverRumEvent, '======serverRumEvent-====')
|
|
116
124
|
lifeCycle.notify(
|
|
117
125
|
LifeCycleEventType.RUM_EVENT_COLLECTED,
|
|
118
126
|
serverRumEvent
|
|
@@ -92,7 +92,6 @@ export function trackFetch(lifeCycle, configuration, tracer) {
|
|
|
92
92
|
fetchProxy.onRequestComplete(function (context) {
|
|
93
93
|
if (isAllowedRequestUrl(configuration, context.url)) {
|
|
94
94
|
tracer.clearTracingIfCancelled(context)
|
|
95
|
-
console.log(context.duration, 'duration=====')
|
|
96
95
|
lifeCycle.notify(LifeCycleEventType.REQUEST_COMPLETED, {
|
|
97
96
|
duration: context.duration,
|
|
98
97
|
method: context.method,
|
|
@@ -5,7 +5,12 @@ import {
|
|
|
5
5
|
urlParse,
|
|
6
6
|
replaceNumberCharByPath,
|
|
7
7
|
RumEventType,
|
|
8
|
-
LifeCycleEventType
|
|
8
|
+
LifeCycleEventType,
|
|
9
|
+
computeStackTrace,
|
|
10
|
+
formatUnknownError,
|
|
11
|
+
ErrorHandling,
|
|
12
|
+
extend,
|
|
13
|
+
ErrorSource
|
|
9
14
|
} from '@cloudcare/browser-core'
|
|
10
15
|
export function startErrorCollection(lifeCycle, configuration) {
|
|
11
16
|
startAutomaticErrorCollection(configuration).subscribe(function (error) {
|
|
@@ -18,15 +23,19 @@ export function doStartErrorCollection(lifeCycle) {
|
|
|
18
23
|
lifeCycle.subscribe(LifeCycleEventType.RAW_ERROR_COLLECTED, function (error) {
|
|
19
24
|
lifeCycle.notify(
|
|
20
25
|
LifeCycleEventType.RAW_RUM_EVENT_COLLECTED,
|
|
21
|
-
|
|
26
|
+
extend({
|
|
27
|
+
customerContext:error.customerContext,
|
|
28
|
+
savedCommonContext: error.savedCommonContext,
|
|
29
|
+
}, processError(error.error))
|
|
30
|
+
|
|
22
31
|
)
|
|
23
32
|
})
|
|
24
33
|
return {
|
|
25
34
|
addError: function (customError, savedCommonContext) {
|
|
26
35
|
var rawError = computeRawError(
|
|
27
36
|
customError.error,
|
|
37
|
+
customError.handlingStack,
|
|
28
38
|
customError.startClocks,
|
|
29
|
-
customError.source
|
|
30
39
|
)
|
|
31
40
|
lifeCycle.notify(LifeCycleEventType.RAW_ERROR_COLLECTED, {
|
|
32
41
|
customerContext: customError.context,
|
|
@@ -36,7 +45,15 @@ export function doStartErrorCollection(lifeCycle) {
|
|
|
36
45
|
}
|
|
37
46
|
}
|
|
38
47
|
}
|
|
39
|
-
|
|
48
|
+
function computeRawError(error, handlingStack, startClocks) {
|
|
49
|
+
const stackTrace = error instanceof Error ? computeStackTrace(error) : undefined
|
|
50
|
+
return extend({
|
|
51
|
+
startClocks:startClocks,
|
|
52
|
+
source: ErrorSource.CUSTOM,
|
|
53
|
+
originalError: error,
|
|
54
|
+
handling: ErrorHandling.HANDLED,
|
|
55
|
+
},formatUnknownError(stackTrace, error, 'Provided', handlingStack))
|
|
56
|
+
}
|
|
40
57
|
function processError(error) {
|
|
41
58
|
var resource = error.resource
|
|
42
59
|
if (resource) {
|
|
@@ -60,6 +77,8 @@ function processError(error) {
|
|
|
60
77
|
source: error.source,
|
|
61
78
|
stack: error.stack,
|
|
62
79
|
type: error.type,
|
|
80
|
+
handling_stack: error.handlingStack,
|
|
81
|
+
handling: error.handling,
|
|
63
82
|
starttime: getTimestamp(error.startClocks.relative)
|
|
64
83
|
},
|
|
65
84
|
type: RumEventType.ERROR
|
|
@@ -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
|
+
}
|
package/src/domain/rumSession.js
CHANGED
|
@@ -7,7 +7,8 @@ export var RUM_SESSION_KEY = 'rum'
|
|
|
7
7
|
export var RumTrackingType = {
|
|
8
8
|
NOT_TRACKED: '0',
|
|
9
9
|
TRACKED_WITH_RESOURCES: '1',
|
|
10
|
-
TRACKED_WITHOUT_RESOURCES: '2'
|
|
10
|
+
TRACKED_WITHOUT_RESOURCES: '2',
|
|
11
|
+
TRACKED_WITH_SERVICE: '3' // 采样数据添加额外的tag,不舍弃,直接上报到服务端
|
|
11
12
|
}
|
|
12
13
|
export function startRumSession(configuration, lifeCycle) {
|
|
13
14
|
var session = startSessionManagement(
|
|
@@ -33,12 +34,16 @@ export function startRumSession(configuration, lifeCycle) {
|
|
|
33
34
|
session.getId() !== undefined && isTracked(session.getTrackingType())
|
|
34
35
|
)
|
|
35
36
|
},
|
|
37
|
+
isTrackedWidthService: function() {
|
|
38
|
+
return session.getId() !== undefined && session.getTrackingType() === RumTrackingType.TRACKED_WITH_SERVICE
|
|
39
|
+
},
|
|
36
40
|
isTrackedWithResource: function () {
|
|
41
|
+
var trackingType = session.getTrackingType()
|
|
37
42
|
return (
|
|
38
43
|
session.getId() !== undefined &&
|
|
39
|
-
|
|
44
|
+
(trackingType === RumTrackingType.TRACKED_WITH_RESOURCES || trackingType === RumTrackingType.TRACKED_WITH_SERVICE)
|
|
40
45
|
)
|
|
41
|
-
}
|
|
46
|
+
},
|
|
42
47
|
}
|
|
43
48
|
}
|
|
44
49
|
|
|
@@ -47,9 +52,19 @@ function computeSessionState(configuration, rawTrackingType) {
|
|
|
47
52
|
if (hasValidRumSession(rawTrackingType)) {
|
|
48
53
|
trackingType = rawTrackingType
|
|
49
54
|
} else if (!performDraw(configuration.sampleRate)) {
|
|
50
|
-
|
|
55
|
+
if (configuration.isServiceSampling) {
|
|
56
|
+
trackingType = RumTrackingType.TRACKED_WITH_SERVICE
|
|
57
|
+
} else {
|
|
58
|
+
trackingType = RumTrackingType.NOT_TRACKED
|
|
59
|
+
}
|
|
60
|
+
|
|
51
61
|
} else if (!performDraw(configuration.resourceSampleRate)) {
|
|
52
|
-
trackingType = RumTrackingType.TRACKED_WITHOUT_RESOURCES
|
|
62
|
+
// trackingType = RumTrackingType.TRACKED_WITHOUT_RESOURCES
|
|
63
|
+
if (configuration.isServiceSampling) {
|
|
64
|
+
trackingType = RumTrackingType.TRACKED_WITH_SERVICE
|
|
65
|
+
} else {
|
|
66
|
+
trackingType = RumTrackingType.TRACKED_WITHOUT_RESOURCES
|
|
67
|
+
}
|
|
53
68
|
} else {
|
|
54
69
|
trackingType = RumTrackingType.TRACKED_WITH_RESOURCES
|
|
55
70
|
}
|
|
@@ -63,13 +78,15 @@ function hasValidRumSession(trackingType) {
|
|
|
63
78
|
return (
|
|
64
79
|
trackingType === RumTrackingType.NOT_TRACKED ||
|
|
65
80
|
trackingType === RumTrackingType.TRACKED_WITH_RESOURCES ||
|
|
66
|
-
trackingType === RumTrackingType.TRACKED_WITHOUT_RESOURCES
|
|
81
|
+
trackingType === RumTrackingType.TRACKED_WITHOUT_RESOURCES ||
|
|
82
|
+
trackingType === RumTrackingType.TRACKED_WITH_SERVICE
|
|
67
83
|
)
|
|
68
84
|
}
|
|
69
85
|
|
|
70
86
|
function isTracked(rumSessionType) {
|
|
71
87
|
return (
|
|
72
88
|
rumSessionType === RumTrackingType.TRACKED_WITH_RESOURCES ||
|
|
73
|
-
rumSessionType === RumTrackingType.TRACKED_WITHOUT_RESOURCES
|
|
89
|
+
rumSessionType === RumTrackingType.TRACKED_WITHOUT_RESOURCES ||
|
|
90
|
+
rumSessionType === RumTrackingType.TRACKED_WITH_SERVICE
|
|
74
91
|
)
|
|
75
92
|
}
|
|
@@ -0,0 +1,70 @@
|
|
|
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 (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
|
+
|
|
17
|
+
high = Math.floor(high / radix)
|
|
18
|
+
low = Math.floor(mod / radix)
|
|
19
|
+
str = (mod % radix).toString(radix) + str
|
|
20
|
+
|
|
21
|
+
if (!high && !low) {
|
|
22
|
+
break
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return str
|
|
26
|
+
},
|
|
27
|
+
toDecimalString: function () {
|
|
28
|
+
return this.toString(10)
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
readInt32: function (offset) {
|
|
32
|
+
return (
|
|
33
|
+
this.buffer[offset] * 16777216 +
|
|
34
|
+
(this.buffer[offset + 1] << 16) +
|
|
35
|
+
(this.buffer[offset + 2] << 8) +
|
|
36
|
+
this.buffer[offset + 3]
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function getCrypto() {
|
|
41
|
+
return window.crypto || window.msCrypto
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
*
|
|
45
|
+
* @param {*} configuration 配置信息
|
|
46
|
+
*/
|
|
47
|
+
export function DDtraceTracer(configuration) {
|
|
48
|
+
this._spanId = new TraceIdentifier().toDecimalString()
|
|
49
|
+
this._traceId = new TraceIdentifier().toDecimalString()
|
|
50
|
+
}
|
|
51
|
+
DDtraceTracer.prototype = {
|
|
52
|
+
isTracingSupported: function() {
|
|
53
|
+
return getCrypto() !== undefined
|
|
54
|
+
},
|
|
55
|
+
getSpanId:function() {
|
|
56
|
+
return this._spanId
|
|
57
|
+
},
|
|
58
|
+
getTraceId: function() {
|
|
59
|
+
return this._traceId
|
|
60
|
+
},
|
|
61
|
+
makeTracingHeaders: function() {
|
|
62
|
+
return {
|
|
63
|
+
'x-datadog-origin': 'rum',
|
|
64
|
+
// 'x-datadog-parent-id': spanId.toDecimalString(),
|
|
65
|
+
'x-datadog-sampled': '1',
|
|
66
|
+
'x-datadog-sampling-priority': '1',
|
|
67
|
+
'x-datadog-trace-id': this.getTraceId()
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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 JaegerTracer(configuration) {
|
|
17
|
+
const rootSpanId = randomTraceId();
|
|
18
|
+
// this._traceId = randomTraceId() + rootSpanId // 默认用128bit,兼容其他配置
|
|
19
|
+
if (configuration.traceId128Bit) {
|
|
20
|
+
// 128bit生成traceid
|
|
21
|
+
this._traceId = randomTraceId() + rootSpanId
|
|
22
|
+
} else {
|
|
23
|
+
this._traceId = rootSpanId
|
|
24
|
+
}
|
|
25
|
+
this._spanId = rootSpanId
|
|
26
|
+
}
|
|
27
|
+
JaegerTracer.prototype = {
|
|
28
|
+
isTracingSupported: function() {
|
|
29
|
+
return true
|
|
30
|
+
},
|
|
31
|
+
getSpanId:function() {
|
|
32
|
+
return this._spanId
|
|
33
|
+
},
|
|
34
|
+
getTraceId: function() {
|
|
35
|
+
return this._traceId
|
|
36
|
+
},
|
|
37
|
+
getUberTraceId: function() {
|
|
38
|
+
//{trace-id}:{span-id}:{parent-span-id}:{flags}
|
|
39
|
+
return this._traceId + ':' + this._spanId + ':' + '0' + ':' + '1'
|
|
40
|
+
},
|
|
41
|
+
makeTracingHeaders: function() {
|
|
42
|
+
return {
|
|
43
|
+
'uber-trace-id': this.getUberTraceId(),
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import {base64Encode, urlParse} from '@cloudcare/browser-core'
|
|
2
|
+
// start SkyWalking
|
|
3
|
+
function uuid() {
|
|
4
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
5
|
+
/* tslint:disable */
|
|
6
|
+
const r = (Math.random() * 16) | 0;
|
|
7
|
+
/* tslint:disable */
|
|
8
|
+
const v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
9
|
+
|
|
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
|
+
function getSkyWalkingSw8(traceId, traceSegmentId, applicationId, env ,version,requestUrlHost) {
|
|
22
|
+
try {
|
|
23
|
+
var traceIdStr = String(base64Encode(traceId));
|
|
24
|
+
var segmentId = String(base64Encode(traceSegmentId));
|
|
25
|
+
var service = String(base64Encode(applicationId + '_rum_' + env));
|
|
26
|
+
var instance = String(base64Encode(version));
|
|
27
|
+
var endpoint = String(base64Encode(window.location.href));
|
|
28
|
+
var peer = String(base64Encode(requestUrlHost));
|
|
29
|
+
var index = '0'
|
|
30
|
+
// var values = `${1}-${traceIdStr}-${segmentId}-${index}-${service}-${instance}-${endpoint}-${peer}`;
|
|
31
|
+
return '1-' + traceIdStr + '-'+ segmentId + '-' +index + '-'+ service + '-'+ instance + '-'+ endpoint + '-'+ peer
|
|
32
|
+
} catch(err) {
|
|
33
|
+
return ''
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
*
|
|
38
|
+
* @param {*} configuration 配置信息
|
|
39
|
+
* @param {*} requestUrl 请求的url
|
|
40
|
+
*/
|
|
41
|
+
export function SkyWalkingTracer(configuration, requestUrl) {
|
|
42
|
+
this._spanId = uuid()
|
|
43
|
+
this._traceId = uuid()
|
|
44
|
+
this._applicationId = configuration.applicationId
|
|
45
|
+
this._env = configuration.env
|
|
46
|
+
this._version = configuration.version
|
|
47
|
+
this._urlParse = urlParse(requestUrl).getParse()
|
|
48
|
+
}
|
|
49
|
+
SkyWalkingTracer.prototype = {
|
|
50
|
+
isTracingSupported: function() {
|
|
51
|
+
if (this._env && this._version && this._urlParse) return true
|
|
52
|
+
return false
|
|
53
|
+
},
|
|
54
|
+
getSpanId:function() {
|
|
55
|
+
return this._spanId
|
|
56
|
+
},
|
|
57
|
+
getTraceId: function() {
|
|
58
|
+
return this._traceId
|
|
59
|
+
},
|
|
60
|
+
getSkyWalkingSw8:function() {
|
|
61
|
+
try {
|
|
62
|
+
var traceIdStr = String(base64Encode(this._traceId));
|
|
63
|
+
var segmentId = String(base64Encode(this._spanId));
|
|
64
|
+
var service = String(base64Encode(this._applicationId + '_rum_' + this.env));
|
|
65
|
+
var instance = String(base64Encode(this._version));
|
|
66
|
+
var endpoint = String(base64Encode(window.location.href));
|
|
67
|
+
var peer = String(base64Encode(this._urlParse.Host));
|
|
68
|
+
var index = '0'
|
|
69
|
+
// var values = `${1}-${traceIdStr}-${segmentId}-${index}-${service}-${instance}-${endpoint}-${peer}`;
|
|
70
|
+
return '1-' + traceIdStr + '-'+ segmentId + '-' +index + '-'+ service + '-'+ instance + '-'+ endpoint + '-'+ peer
|
|
71
|
+
} catch(err) {
|
|
72
|
+
return ''
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
makeTracingHeaders: function() {
|
|
76
|
+
return {
|
|
77
|
+
'sw8': this.getSkyWalkingSw8(),
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|