@cloudcare/browser-rum 3.0.17 → 3.0.19

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.
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.buildEnv = void 0;
7
7
  var buildEnv = {
8
- sdkVersion: '3.0.17',
8
+ sdkVersion: '3.0.19',
9
9
  sdkName: 'df_web_rum_sdk'
10
10
  };
11
11
  exports.buildEnv = buildEnv;
@@ -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
- if (initConfiguration.allowedTracingOrigins !== undefined) {
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 (initConfiguration.allowedDDTracingOrigins !== undefined) {
41
- if (!(0, _browserCore.isArray)(initConfiguration.allowedDDTracingOrigins)) {
42
- _browserCore.display.error('Allowed Tracing Origins should be an array');
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
- allowedTracingOrigins: (0, _browserCore.isNullUndefinedDefaultValue)(initConfiguration.allowedTracingOrigins || initConfiguration.allowedDDTracingOrigins, []),
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
  }
@@ -5,64 +5,27 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.DDtraceTracer = DDtraceTracer;
7
7
 
8
- function TraceIdentifier() {
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().toDecimalString();
53
- this._traceId = new TraceIdentifier().toDecimalString();
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
- // === Generate a random 64-bit number in fixed-length hex format
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
- var rootSpanId = randomTraceId(); // this._traceId = randomTraceId() + rootSpanId // 默认用128bit,兼容其他配置
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 true;
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._traceId + ':' + this._spanId + ':' + '0' + ':' + (this._traceSampled ? '1' : '0');
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,6 +22,11 @@ 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
31
  if (context.status === 0 && !context.isAborted) {
26
32
  context.traceId = undefined;
@@ -77,27 +83,24 @@ function startTracer(configuration, sessionManager) {
77
83
  };
78
84
  }
79
85
 
80
- function isAllowedUrl(configuration, requestUrl) {
81
- var requestOrigin = (0, _browserCore.getOrigin)(requestUrl);
82
- var flag = false;
83
- (0, _browserCore.each)(configuration.allowedTracingOrigins, function (allowedOrigin) {
84
- if (requestOrigin === allowedOrigin || allowedOrigin instanceof RegExp && allowedOrigin.test(requestOrigin)) {
85
- flag = true;
86
- return false;
87
- }
86
+ function injectHeadersIfTracingAllowed(configuration, context, sessionManager, inject) {
87
+ if (!sessionManager.findTrackedSession()) {
88
+ return;
89
+ }
90
+
91
+ var tracingOption = (0, _browserCore.find)(configuration.allowedTracingUrls, function (tracingOption) {
92
+ return (0, _browserCore.matchList)([tracingOption.match], context.url, true);
88
93
  });
89
- return flag;
90
- }
91
94
 
92
- function injectHeadersIfTracingAllowed(configuration, context, sessionManager, inject) {
93
- if (!isAllowedUrl(configuration, context.url) || !configuration.traceType || !sessionManager.findTrackedSession()) {
95
+ if (!tracingOption) {
94
96
  return;
95
97
  }
96
98
 
97
99
  var traceSampled = !(0, _browserCore.isNumber)(configuration.tracingSampleRate) || (0, _browserCore.performDraw)(configuration.tracingSampleRate);
98
- var tracer;
100
+ var tracer,
101
+ traceType = tracingOption.traceType;
99
102
 
100
- switch (configuration.traceType) {
103
+ switch (traceType) {
101
104
  case _browserCore.TraceType.DDTRACE:
102
105
  tracer = new _ddtraceTracer.DDtraceTracer(traceSampled);
103
106
  break;
@@ -115,7 +118,11 @@ function injectHeadersIfTracingAllowed(configuration, context, sessionManager, i
115
118
  break;
116
119
 
117
120
  case _browserCore.TraceType.W3C_TRACEPARENT:
118
- tracer = new _w3cTraceParentTracer.W3cTraceParentTracer(configuration, traceSampled);
121
+ tracer = new _w3cTraceParentTracer.W3cTraceParentTracer(traceSampled);
122
+ break;
123
+
124
+ case _browserCore.TraceType.W3C_TRACEPARENT_64:
125
+ tracer = new _w3cTraceParentTracer.W3cTraceParentTracer(traceSampled, true);
119
126
  break;
120
127
 
121
128
  case _browserCore.TraceType.ZIPKIN_SINGLE_HEADER:
@@ -5,48 +5,48 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.W3cTraceParentTracer = W3cTraceParentTracer;
7
7
 
8
- // === Generate a random 64-bit number in fixed-length hex format
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
- }
10
+ var _browserCore = require("@cloudcare/browser-core");
17
11
 
18
- return n;
19
- }
20
12
  /**
21
13
  *
22
- * @param {*} configuration 配置信息
14
+ * @param {*} traceSampled
15
+ * @param {*} isHexTraceId 是否需要转换成10进制上报数据
23
16
  */
24
-
25
-
26
- function W3cTraceParentTracer(configuration, traceSampled) {
27
- var rootSpanId = randomTraceId();
28
- this._traceId = randomTraceId() + rootSpanId;
29
- this._spanId = rootSpanId;
17
+ function W3cTraceParentTracer(traceSampled, isHexTraceId) {
18
+ this._traceId = new _traceIdentifier.TraceIdentifier();
19
+ this._spanId = new _traceIdentifier.TraceIdentifier();
30
20
  this._traceSampled = traceSampled;
21
+ this.isHexTraceId = isHexTraceId;
31
22
  }
32
23
 
33
24
  W3cTraceParentTracer.prototype = {
34
25
  isTracingSupported: function isTracingSupported() {
35
- return true;
26
+ return (0, _traceIdentifier.getCrypto)() !== undefined;
36
27
  },
37
28
  getSpanId: function getSpanId() {
38
- return this._spanId;
29
+ return this.isHexTraceId ? this._spanId.toDecimalString() : this._spanId.toPaddedHexadecimalString();
39
30
  },
40
31
  getTraceId: function getTraceId() {
41
- return this._traceId;
32
+ return this.isHexTraceId ? this._traceId.toDecimalString() : '0000000000000000' + this._traceId.toPaddedHexadecimalString();
42
33
  },
43
34
  getTraceParent: function getTraceParent() {
44
35
  // '{version}-{traceId}-{spanId}-{sampleDecision}'
45
- return '00-' + this._traceId + '-' + this._spanId + '-' + (this._traceSampled ? '01' : '00');
36
+ return '00-0000000000000000' + this._traceId.toPaddedHexadecimalString() + '-' + this._spanId.toPaddedHexadecimalString() + '-' + (this._traceSampled ? '01' : '00');
46
37
  },
47
38
  makeTracingHeaders: function makeTracingHeaders() {
48
- return {
39
+ var baseHeaders = {
49
40
  traceparent: this.getTraceParent()
50
41
  };
42
+
43
+ if (this.isHexTraceId) {
44
+ return (0, _browserCore.assign)(baseHeaders, {
45
+ 'x-gc-trace-id': this.getTraceId(),
46
+ 'x-gc-span-id': this.getSpanId()
47
+ });
48
+ }
49
+
50
+ return baseHeaders;
51
51
  }
52
52
  };
@@ -5,52 +5,33 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.ZipkinMultiTracer = ZipkinMultiTracer;
7
7
 
8
- // === Generate a random 64-bit number in fixed-length hex format
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
- var rootSpanId = randomTraceId();
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 true;
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.getTraceId(),
53
- 'X-B3-SpanId': this.getSpanId(),
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
 
@@ -5,44 +5,31 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.ZipkinSingleTracer = ZipkinSingleTracer;
7
7
 
8
- // === Generate a random 64-bit number in fixed-length hex format
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 ZipkinSingleTracer(configuration, traceSampled) {
27
- var rootSpanId = randomTraceId();
28
- this._traceId = randomTraceId() + rootSpanId;
29
- this._spanId = rootSpanId;
15
+ this._traceId = new _traceIdentifier.TraceIdentifier();
16
+ this._spanId = new _traceIdentifier.TraceIdentifier();
30
17
  this._traceSampled = traceSampled;
31
18
  }
32
19
 
33
20
  ZipkinSingleTracer.prototype = {
34
21
  isTracingSupported: function isTracingSupported() {
35
- return true;
22
+ return (0, _traceIdentifier.getCrypto)() !== undefined;
36
23
  },
37
24
  getSpanId: function getSpanId() {
38
- return this._spanId;
25
+ return this._spanId.toPaddedHexadecimalString();
39
26
  },
40
27
  getTraceId: function getTraceId() {
41
- return this._traceId;
28
+ return this._traceId.toPaddedHexadecimalString();
42
29
  },
43
30
  getB3Str: function getB3Str() {
44
31
  //{TraceId}-{SpanId}-{SamplingState}-{ParentSpanId}
45
- return this._traceId + '-' + this._spanId + '-' + (this._traceSampled ? '1' : '0');
32
+ return this.getTraceId() + '-' + this.getSpanId() + '-' + (this._traceSampled ? '1' : '0');
46
33
  },
47
34
  makeTracingHeaders: function makeTracingHeaders() {
48
35
  return {
@@ -1,4 +1,4 @@
1
1
  export var buildEnv = {
2
- sdkVersion: '3.0.17',
2
+ sdkVersion: '3.0.19',
3
3
  sdkName: 'df_web_rum_sdk'
4
4
  };