@cloudcare/browser-rum 2.2.1 → 2.2.3

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.
Files changed (34) hide show
  1. package/README.md +2 -1
  2. package/bundle/dataflux-rum.js +1 -1
  3. package/cjs/boot/buildEnv.js +1 -1
  4. package/cjs/domain/configuration.js +7 -0
  5. package/cjs/domain/rumEventsCollection/resource/resourceCollection.js +1 -1
  6. package/cjs/domain/tracing/ddtraceTracer.js +4 -4
  7. package/cjs/domain/tracing/jaegerTracer.js +4 -3
  8. package/cjs/domain/tracing/skywalkingTracer.js +11 -10
  9. package/cjs/domain/tracing/tracer.js +9 -6
  10. package/cjs/domain/tracing/w3cTraceParentTracer.js +5 -4
  11. package/cjs/domain/tracing/zipkinMultiTracer.js +4 -3
  12. package/cjs/domain/tracing/zipkinSingleTracer.js +5 -4
  13. package/esm/boot/buildEnv.js +1 -1
  14. package/esm/boot/rumPublicApi.js +1 -1
  15. package/esm/domain/configuration.js +6 -0
  16. package/esm/domain/rumEventsCollection/resource/resourceCollection.js +1 -1
  17. package/esm/domain/tracing/ddtraceTracer.js +4 -4
  18. package/esm/domain/tracing/jaegerTracer.js +4 -3
  19. package/esm/domain/tracing/skywalkingTracer.js +11 -10
  20. package/esm/domain/tracing/tracer.js +10 -7
  21. package/esm/domain/tracing/w3cTraceParentTracer.js +5 -4
  22. package/esm/domain/tracing/zipkinMultiTracer.js +4 -3
  23. package/esm/domain/tracing/zipkinSingleTracer.js +5 -4
  24. package/package.json +3 -3
  25. package/src/boot/rumPublicApi.js +30 -45
  26. package/src/domain/configuration.js +8 -0
  27. package/src/domain/rumEventsCollection/resource/resourceCollection.js +15 -11
  28. package/src/domain/tracing/ddtraceTracer.js +11 -11
  29. package/src/domain/tracing/jaegerTracer.js +36 -28
  30. package/src/domain/tracing/skywalkingTracer.js +94 -53
  31. package/src/domain/tracing/tracer.js +14 -7
  32. package/src/domain/tracing/w3cTraceParentTracer.js +35 -27
  33. package/src/domain/tracing/zipkinMultiTracer.js +29 -28
  34. package/src/domain/tracing/zipkinSingleTracer.js +34 -27
@@ -7,77 +7,65 @@ import {
7
7
  buildCookieOptions,
8
8
  createContextManager,
9
9
  clocksNow,
10
- extend2Lev,
11
10
  timeStampNow,
12
11
  ActionType,
13
- isEmptyObject,
14
12
  deepClone,
15
- formatDate,
16
13
  createHandlingStack
17
14
  } from '@cloudcare/browser-core'
18
- import {validateAndBuildRumConfiguration} from '../domain/configuration'
15
+ import { validateAndBuildRumConfiguration } from '../domain/configuration'
19
16
  export function makeRumPublicApi(startRumImpl) {
20
17
  var isAlreadyInitialized = false
21
18
 
22
19
  var globalContextManager = createContextManager()
23
20
  var userContextManager = createContextManager()
24
21
  var bufferApiCalls = new BoundedBuffer()
25
- var addTimingStrategy = function(name, time){
22
+ var addTimingStrategy = function (name, time) {
26
23
  if (typeof time === 'undefined') {
27
24
  time = timeStampNow()
28
25
  }
29
- bufferApiCalls.add(function() {
26
+ bufferApiCalls.add(function () {
30
27
  return addTimingStrategy(name, time)
31
28
  })
32
29
  }
33
- var startViewStrategy = function(options, startClocks){
30
+ var startViewStrategy = function (options, startClocks) {
34
31
  if (typeof startClocks === 'undefined') {
35
32
  startClocks = clocksNow()
36
33
  }
37
- bufferApiCalls.add(function() {
34
+ bufferApiCalls.add(function () {
38
35
  return startViewStrategy(options, startClocks)
39
36
  })
40
37
  }
41
- var addActionStrategy = function(
42
- action,
43
- commonContext
44
- ) {
38
+ var addActionStrategy = function (action, commonContext) {
45
39
  if (typeof commonContext == 'undefined') {
46
40
  commonContext = {
47
41
  context: globalContextManager.getContext(),
48
- user: userContextManager.getContext(),
42
+ user: userContextManager.getContext()
49
43
  }
50
44
  }
51
- bufferApiCalls.add(function() {
45
+ bufferApiCalls.add(function () {
52
46
  return addActionStrategy(action, commonContext)
53
47
  })
54
48
  }
55
- var addErrorStrategy = function(
56
- providedError,
57
- commonContext
58
- ) {
49
+ var addErrorStrategy = function (providedError, commonContext) {
59
50
  if (typeof commonContext == 'undefined') {
60
51
  commonContext = {
61
52
  context: globalContextManager.getContext(),
62
- user: userContextManager.getContext(),
53
+ user: userContextManager.getContext()
63
54
  }
64
55
  }
65
- bufferApiCalls.add(function() {
56
+ bufferApiCalls.add(function () {
66
57
  return addErrorStrategy(providedError, commonContext)
67
58
  })
68
59
  }
69
60
 
70
-
71
61
  var getInternalContextStrategy = function () {
72
62
  return undefined
73
63
  }
74
- var getInitConfigurationStrategy = function() {
64
+ var getInitConfigurationStrategy = function () {
75
65
  return undefined
76
66
  }
77
67
 
78
-
79
68
  function initRum(initConfiguration) {
80
-
81
69
  if (!canHandleSession(initConfiguration)) {
82
70
  return
83
71
  }
@@ -100,12 +88,12 @@ export function makeRumPublicApi(startRumImpl) {
100
88
  var beforeInitCalls = bufferApiCalls
101
89
  bufferApiCalls = new BoundedBuffer()
102
90
 
103
- startViewStrategy = function(options){
91
+ startViewStrategy = function (options) {
104
92
  doStartRum(configuration, options)
105
93
  }
106
94
  beforeInitCalls.drain()
107
95
  }
108
- getInitConfigurationStrategy = function() {
96
+ getInitConfigurationStrategy = function () {
109
97
  return deepClone(initConfiguration)
110
98
  }
111
99
 
@@ -114,10 +102,10 @@ export function makeRumPublicApi(startRumImpl) {
114
102
  function doStartRum(configuration, initialViewOptions) {
115
103
  var startRumResults = startRumImpl(
116
104
  configuration,
117
- function() {
105
+ function () {
118
106
  return {
119
107
  user: userContextManager.getContext(),
120
- context: globalContextManager.getContext(),
108
+ context: globalContextManager.getContext()
121
109
  }
122
110
  },
123
111
  initialViewOptions
@@ -126,11 +114,12 @@ export function makeRumPublicApi(startRumImpl) {
126
114
  addActionStrategy = startRumResults.addAction
127
115
  addErrorStrategy = startRumResults.addError
128
116
  addTimingStrategy = startRumResults.addTiming
129
- getInternalContextStrategy = startRumResults.getInternalContext
117
+ getInternalContextStrategy = startRumResults.getInternalContext
130
118
  bufferApiCalls.drain()
131
119
  }
132
- var startView = function(options) {
133
- var sanitizedOptions = typeof options === 'object' ? options : { name: options }
120
+ var startView = function (options) {
121
+ var sanitizedOptions =
122
+ typeof options === 'object' ? options : { name: options }
134
123
  startViewStrategy(sanitizedOptions)
135
124
  }
136
125
  var rumPublicApi = makePublicApi({
@@ -153,24 +142,21 @@ export function makeRumPublicApi(startRumImpl) {
153
142
 
154
143
  clearGlobalContext: globalContextManager.clearContext,
155
144
 
156
- getInitConfiguration: function() {
145
+ getInitConfiguration: function () {
157
146
  return getInitConfigurationStrategy()
158
147
  },
159
148
  getInternalContext: function (startTime) {
160
149
  return getInternalContextStrategy(startTime)
161
150
  },
162
- addDebugSession: function (id) {
163
- },
164
- clearDebugSession: function () {
165
- },
166
- getDebugSession: function () {
167
- },
151
+ addDebugSession: function (id) {},
152
+ clearDebugSession: function () {},
153
+ getDebugSession: function () {},
168
154
  addAction: function (name, context) {
169
155
  addActionStrategy({
170
156
  name: name,
171
157
  context: deepClone(context),
172
158
  startClocks: clocksNow(),
173
- type: ActionType.CUSTOM,
159
+ type: ActionType.CUSTOM
174
160
  })
175
161
  },
176
162
 
@@ -185,12 +171,12 @@ export function makeRumPublicApi(startRumImpl) {
185
171
  var handlingStack = createHandlingStack()
186
172
  addErrorStrategy({
187
173
  error: error,
188
- handlingStack:handlingStack,
174
+ handlingStack: handlingStack,
189
175
  context: deepClone(context),
190
- startClocks: clocksNow(),
176
+ startClocks: clocksNow()
191
177
  })
192
178
  },
193
- addTiming: function(name, time){
179
+ addTiming: function (name, time) {
194
180
  addTimingStrategy(name, time)
195
181
  },
196
182
  setUser: function (newUser) {
@@ -201,7 +187,7 @@ export function makeRumPublicApi(startRumImpl) {
201
187
  }
202
188
  },
203
189
  getUser: userContextManager.getContext,
204
- setUserProperty: function(key, property){
190
+ setUserProperty: function (key, property) {
205
191
  var newUser = {}
206
192
  newUser[key] = property
207
193
  var sanitizedProperty = sanitizeUser(newUser)[key]
@@ -234,7 +220,7 @@ export function makeRumPublicApi(startRumImpl) {
234
220
  display.warn('Cookies are not authorized, we will not send any data.')
235
221
  return false
236
222
  }
237
-
223
+
238
224
  if (isLocalFile()) {
239
225
  display.error('Execution is not allowed in the current context.')
240
226
  return false
@@ -254,4 +240,3 @@ export function makeRumPublicApi(startRumImpl) {
254
240
  return window.location.protocol === 'file:'
255
241
  }
256
242
  }
257
-
@@ -43,6 +43,13 @@ export function validateAndBuildRumConfiguration(initConfiguration) {
43
43
  return
44
44
  }
45
45
  }
46
+ if (
47
+ initConfiguration.tracingSampleRate !== undefined &&
48
+ !isPercentage(initConfiguration.tracingSampleRate)
49
+ ) {
50
+ display.error('Tracing Sample Rate should be a number between 0 and 100')
51
+ return
52
+ }
46
53
  if (
47
54
  initConfiguration.excludedActivityUrls !== undefined &&
48
55
  !isArray(initConfiguration.excludedActivityUrls)
@@ -66,6 +73,7 @@ export function validateAndBuildRumConfiguration(initConfiguration) {
66
73
  initConfiguration.sessionReplaySampleRate,
67
74
  100
68
75
  ),
76
+ tracingSampleRate: initConfiguration.tracingSampleRate,
69
77
  allowedTracingOrigins: isNullUndefinedDefaultValue(
70
78
  initConfiguration.allowedTracingOrigins ||
71
79
  initConfiguration.allowedDDTracingOrigins,
@@ -37,7 +37,10 @@ export function startResourceCollection(lifeCycle, configuration) {
37
37
  function (entries) {
38
38
  for (var entry of entries) {
39
39
  if (entry.entryType === 'resource' && !isRequestKind(entry)) {
40
- lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, processResourceEntry(entry))
40
+ lifeCycle.notify(
41
+ LifeCycleEventType.RAW_RUM_EVENT_COLLECTED,
42
+ processResourceEntry(entry)
43
+ )
41
44
  }
42
45
  }
43
46
  }
@@ -77,16 +80,17 @@ function processRequest(request) {
77
80
  tracingInfo,
78
81
  correspondingTimingOverrides
79
82
  )
80
- return {
81
- startTime: startClocks.relative,
83
+ return {
84
+ startTime: startClocks.relative,
82
85
  rawRumEvent: resourceEvent,
83
86
  domainContext: {
84
- performanceEntry: matchingTiming && toPerformanceEntryRepresentation(matchingTiming),
87
+ performanceEntry:
88
+ matchingTiming && toPerformanceEntryRepresentation(matchingTiming),
85
89
  xhr: request.xhr,
86
90
  response: request.response,
87
91
  requestInput: request.input,
88
92
  requestInit: request.init,
89
- error: request.error,
93
+ error: request.error
90
94
  }
91
95
  }
92
96
  }
@@ -123,12 +127,12 @@ function processResourceEntry(entry) {
123
127
  tracingInfo,
124
128
  entryMetrics
125
129
  )
126
- return {
127
- startTime: startClocks.relative,
130
+ return {
131
+ startTime: startClocks.relative,
128
132
  rawRumEvent: resourceEvent,
129
133
  domainContext: {
130
- performanceEntry: toPerformanceEntryRepresentation(entry),
131
- },
134
+ performanceEntry: toPerformanceEntryRepresentation(entry)
135
+ }
132
136
  }
133
137
  }
134
138
 
@@ -151,7 +155,7 @@ function toPerformanceEntryRepresentation(entry) {
151
155
  return entry
152
156
  }
153
157
  function computeRequestTracingInfo(request) {
154
- var hasBeenTraced = request.traceId && request.spanId
158
+ var hasBeenTraced = request.traceSampled && request.traceId && request.spanId
155
159
  if (!hasBeenTraced) {
156
160
  return undefined
157
161
  }
@@ -166,4 +170,4 @@ function computeRequestTracingInfo(request) {
166
170
 
167
171
  function computeEntryTracingInfo(entry) {
168
172
  return entry.traceId ? { _dd: { traceId: entry.traceId } } : undefined
169
- }
173
+ }
@@ -41,30 +41,30 @@ function getCrypto() {
41
41
  return window.crypto || window.msCrypto
42
42
  }
43
43
  /**
44
- *
44
+ *
45
45
  * @param {*} configuration 配置信息
46
46
  */
47
- export function DDtraceTracer(configuration) {
48
- this._spanId = new TraceIdentifier().toDecimalString()
49
- this._traceId = new TraceIdentifier().toDecimalString()
47
+ export function DDtraceTracer(traceSampled) {
48
+ this._spanId = new TraceIdentifier().toDecimalString()
49
+ this._traceId = new TraceIdentifier().toDecimalString()
50
+ this._traceSampled = traceSampled
50
51
  }
51
52
  DDtraceTracer.prototype = {
52
- isTracingSupported: function() {
53
+ isTracingSupported: function () {
53
54
  return getCrypto() !== undefined
54
55
  },
55
- getSpanId:function() {
56
+ getSpanId: function () {
56
57
  return this._spanId
57
58
  },
58
- getTraceId: function() {
59
+ getTraceId: function () {
59
60
  return this._traceId
60
61
  },
61
- makeTracingHeaders: function() {
62
+ makeTracingHeaders: function () {
62
63
  return {
63
64
  'x-datadog-origin': 'rum',
64
65
  'x-datadog-parent-id': this.getSpanId(),
65
- 'x-datadog-sampled': '1',
66
- 'x-datadog-sampling-priority': '1',
66
+ 'x-datadog-sampling-priority': this._traceSampled ? '2' : '-1',
67
67
  'x-datadog-trace-id': this.getTraceId()
68
68
  }
69
69
  }
70
- }
70
+ }
@@ -1,20 +1,20 @@
1
1
  // === Generate a random 64-bit number in fixed-length hex format
2
2
  function randomTraceId() {
3
- var digits = '0123456789abcdef';
4
- var n = '';
3
+ var digits = '0123456789abcdef'
4
+ var n = ''
5
5
  for (var i = 0; i < 16; i += 1) {
6
- var rand = Math.floor(Math.random() * 16);
7
- n += digits[rand];
6
+ var rand = Math.floor(Math.random() * 16)
7
+ n += digits[rand]
8
8
  }
9
- return n;
9
+ return n
10
10
  }
11
11
 
12
12
  /**
13
- *
13
+ *
14
14
  * @param {*} configuration 配置信息
15
15
  */
16
- export function JaegerTracer(configuration) {
17
- var rootSpanId = randomTraceId();
16
+ export function JaegerTracer(configuration, traceSampled) {
17
+ var rootSpanId = randomTraceId()
18
18
  // this._traceId = randomTraceId() + rootSpanId // 默认用128bit,兼容其他配置
19
19
  if (configuration.traceId128Bit) {
20
20
  // 128bit生成traceid
@@ -23,25 +23,33 @@ function randomTraceId() {
23
23
  this._traceId = rootSpanId
24
24
  }
25
25
  this._spanId = rootSpanId
26
+ this._traceSampled = traceSampled
26
27
  }
27
28
  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
- }
29
+ isTracingSupported: function () {
30
+ return true
31
+ },
32
+ getSpanId: function () {
33
+ return this._spanId
34
+ },
35
+ getTraceId: function () {
36
+ return this._traceId
37
+ },
38
+ getUberTraceId: function () {
39
+ //{trace-id}:{span-id}:{parent-span-id}:{flags}
40
+ return (
41
+ this._traceId +
42
+ ':' +
43
+ this._spanId +
44
+ ':' +
45
+ '0' +
46
+ ':' +
47
+ (this._traceSampled ? '1' : '0')
48
+ )
49
+ },
50
+ makeTracingHeaders: function () {
51
+ return {
52
+ 'uber-trace-id': this.getUberTraceId()
53
+ }
54
+ }
55
+ }
@@ -1,80 +1,121 @@
1
- import {base64Encode, urlParse} from '@cloudcare/browser-core'
1
+ import { base64Encode, urlParse } from '@cloudcare/browser-core'
2
2
  // start SkyWalking
3
3
  function uuid() {
4
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c){
4
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
5
5
  /* tslint:disable */
6
- var r = (Math.random() * 16) | 0;
6
+ var r = (Math.random() * 16) | 0
7
7
  /* tslint:disable */
8
- var v = c === 'x' ? r : (r & 0x3) | 0x8;
8
+ var v = c === 'x' ? r : (r & 0x3) | 0x8
9
9
 
10
- return v.toString(16);
11
- });
10
+ return v.toString(16)
11
+ })
12
12
  }
13
13
  /**
14
- *
15
- * @param {*} traceId
16
- * @param {*} traceSegmentId
17
- * @param {*} applicationId
18
- * @param {*} version
19
- * @param {*} requestUrlHost
14
+ *
15
+ * @param {*} traceId
16
+ * @param {*} traceSegmentId
17
+ * @param {*} applicationId
18
+ * @param {*} version
19
+ * @param {*} requestUrlHost
20
20
  */
21
- function getSkyWalkingSw8(traceId, traceSegmentId, applicationId, env ,version,requestUrlHost) {
21
+ function getSkyWalkingSw8(
22
+ traceId,
23
+ traceSegmentId,
24
+ applicationId,
25
+ env,
26
+ version,
27
+ requestUrlHost
28
+ ) {
22
29
  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));
30
+ var traceIdStr = String(base64Encode(traceId))
31
+ var segmentId = String(base64Encode(traceSegmentId))
32
+ var service = String(base64Encode(applicationId + '_rum_' + env))
33
+ var instance = String(base64Encode(version))
34
+ var endpoint = String(base64Encode(window.location.href))
35
+ var peer = String(base64Encode(requestUrlHost))
29
36
  var index = '0'
30
37
  // var values = `${1}-${traceIdStr}-${segmentId}-${index}-${service}-${instance}-${endpoint}-${peer}`;
31
- return '1-' + traceIdStr + '-'+ segmentId + '-' +index + '-'+ service + '-'+ instance + '-'+ endpoint + '-'+ peer
32
- } catch(err) {
38
+ return (
39
+ '1-' +
40
+ traceIdStr +
41
+ '-' +
42
+ segmentId +
43
+ '-' +
44
+ index +
45
+ '-' +
46
+ service +
47
+ '-' +
48
+ instance +
49
+ '-' +
50
+ endpoint +
51
+ '-' +
52
+ peer
53
+ )
54
+ } catch (err) {
33
55
  return ''
34
56
  }
35
57
  }
36
58
  /**
37
- *
59
+ *
38
60
  * @param {*} configuration 配置信息
39
61
  * @param {*} requestUrl 请求的url
40
62
  */
41
- export function SkyWalkingTracer(configuration, requestUrl) {
63
+ export function SkyWalkingTracer(configuration, requestUrl, traceSampled) {
42
64
  this._spanId = uuid()
43
65
  this._traceId = uuid()
44
66
  this._applicationId = configuration.applicationId
45
67
  this._env = configuration.env
46
68
  this._version = configuration.version
47
69
  this._urlParse = urlParse(requestUrl).getParse()
70
+ this._traceSampled = traceSampled
48
71
  }
49
72
  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
+ isTracingSupported: function () {
74
+ if (this._env && this._version && this._urlParse) return true
75
+ return false
76
+ },
77
+ getSpanId: function () {
78
+ return this._spanId
79
+ },
80
+ getTraceId: function () {
81
+ return this._traceId
82
+ },
83
+ getSkyWalkingSw8: function () {
84
+ try {
85
+ var traceIdStr = String(base64Encode(this._traceId))
86
+ var segmentId = String(base64Encode(this._spanId))
87
+ var service = String(
88
+ base64Encode(this._applicationId + '_rum_' + this.env)
89
+ )
90
+ var instance = String(base64Encode(this._version))
91
+ var endpoint = String(base64Encode(window.location.href))
92
+ var peer = String(base64Encode(this._urlParse.Host))
93
+ var index = '0'
94
+ // var values = `${1}-${traceIdStr}-${segmentId}-${index}-${service}-${instance}-${endpoint}-${peer}`;
95
+ return (
96
+ (this._traceSampled ? '1' : '0') +
97
+ '-' +
98
+ traceIdStr +
99
+ '-' +
100
+ segmentId +
101
+ '-' +
102
+ index +
103
+ '-' +
104
+ service +
105
+ '-' +
106
+ instance +
107
+ '-' +
108
+ endpoint +
109
+ '-' +
110
+ peer
111
+ )
112
+ } catch (err) {
113
+ return ''
114
+ }
115
+ },
116
+ makeTracingHeaders: function () {
117
+ return {
118
+ sw8: this.getSkyWalkingSw8()
119
+ }
73
120
  }
74
- },
75
- makeTracingHeaders: function() {
76
- return {
77
- 'sw8': this.getSkyWalkingSw8(),
78
- }
79
- }
80
- }
121
+ }
@@ -4,7 +4,9 @@ import {
4
4
  shallowClone,
5
5
  isArray,
6
6
  TraceType,
7
- getOrigin
7
+ getOrigin,
8
+ performDraw,
9
+ isNumber
8
10
  } from '@cloudcare/browser-core'
9
11
  import { DDtraceTracer } from './ddtraceTracer'
10
12
  import { SkyWalkingTracer } from './skywalkingTracer'
@@ -17,6 +19,7 @@ export function clearTracingIfNeeded(context) {
17
19
  if (context.status === 0 && !context.isAborted) {
18
20
  context.traceId = undefined
19
21
  context.spanId = undefined
22
+ context.traceSampled = undefined
20
23
  }
21
24
  }
22
25
 
@@ -109,25 +112,28 @@ export function injectHeadersIfTracingAllowed(
109
112
  ) {
110
113
  return
111
114
  }
115
+ var traceSampled =
116
+ !isNumber(configuration.tracingSampleRate) ||
117
+ performDraw(configuration.tracingSampleRate)
112
118
  var tracer
113
119
  switch (configuration.traceType) {
114
120
  case TraceType.DDTRACE:
115
- tracer = new DDtraceTracer()
121
+ tracer = new DDtraceTracer(traceSampled)
116
122
  break
117
123
  case TraceType.SKYWALKING_V3:
118
- tracer = new SkyWalkingTracer(configuration, context.url)
124
+ tracer = new SkyWalkingTracer(configuration, context.url, traceSampled)
119
125
  break
120
126
  case TraceType.ZIPKIN_MULTI_HEADER:
121
- tracer = new ZipkinMultiTracer(configuration)
127
+ tracer = new ZipkinMultiTracer(configuration, traceSampled)
122
128
  break
123
129
  case TraceType.JAEGER:
124
- tracer = new JaegerTracer(configuration)
130
+ tracer = new JaegerTracer(configuration, traceSampled)
125
131
  break
126
132
  case TraceType.W3C_TRACEPARENT:
127
- tracer = new W3cTraceParentTracer(configuration)
133
+ tracer = new W3cTraceParentTracer(configuration, traceSampled)
128
134
  break
129
135
  case TraceType.ZIPKIN_SINGLE_HEADER:
130
- tracer = new ZipkinSingleTracer(configuration)
136
+ tracer = new ZipkinSingleTracer(configuration, traceSampled)
131
137
  break
132
138
  default:
133
139
  break
@@ -138,5 +144,6 @@ export function injectHeadersIfTracingAllowed(
138
144
 
139
145
  context.traceId = tracer.getTraceId()
140
146
  context.spanId = tracer.getSpanId()
147
+ context.traceSampled = traceSampled
141
148
  inject(tracer.makeTracingHeaders())
142
149
  }