@cloudcare/rum-uniapp 1.0.1 → 2.0.1
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 +1 -1
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/boot/rum.entry.js +56 -1
- package/cjs/boot/rum.js +2 -2
- package/cjs/core/boundedBuffer.js +28 -0
- package/cjs/core/configuration.js +22 -1
- package/cjs/core/dataMap.js +5 -1
- package/cjs/core/transport.js +123 -69
- package/cjs/core/xhrProxy.js +3 -2
- package/cjs/helper/enums.js +11 -2
- package/cjs/helper/utils.js +189 -6
- package/cjs/rumEventsCollection/assembly.js +19 -2
- package/cjs/rumEventsCollection/page/index.js +1 -11
- package/cjs/rumEventsCollection/requestCollection.js +9 -2
- package/cjs/rumEventsCollection/resource/resourceCollection.js +21 -1
- package/cjs/rumEventsCollection/tracing/ddtraceTracer.js +50 -0
- package/cjs/rumEventsCollection/tracing/jaegerTracer.js +58 -0
- package/cjs/rumEventsCollection/tracing/skywalkingTracer.js +75 -0
- package/cjs/rumEventsCollection/tracing/tracer.js +108 -0
- package/cjs/rumEventsCollection/tracing/w3cTraceParentTracer.js +51 -0
- package/cjs/rumEventsCollection/tracing/zipkinMultiTracer.js +58 -0
- package/cjs/rumEventsCollection/tracing/zipkinSingleTracer.js +51 -0
- package/esm/boot/buildEnv.js +1 -1
- package/esm/boot/rum.entry.js +55 -2
- package/esm/boot/rum.js +2 -2
- package/esm/core/boundedBuffer.js +20 -0
- package/esm/core/configuration.js +24 -3
- package/esm/core/dataMap.js +5 -1
- package/esm/core/transport.js +120 -70
- package/esm/core/xhrProxy.js +3 -2
- package/esm/helper/enums.js +8 -0
- package/esm/helper/utils.js +168 -5
- package/esm/rumEventsCollection/assembly.js +20 -3
- package/esm/rumEventsCollection/page/index.js +1 -11
- package/esm/rumEventsCollection/requestCollection.js +8 -2
- package/esm/rumEventsCollection/resource/resourceCollection.js +22 -2
- package/esm/rumEventsCollection/tracing/ddtraceTracer.js +42 -0
- package/esm/rumEventsCollection/tracing/jaegerTracer.js +50 -0
- package/esm/rumEventsCollection/tracing/skywalkingTracer.js +66 -0
- package/esm/rumEventsCollection/tracing/tracer.js +90 -0
- package/esm/rumEventsCollection/tracing/w3cTraceParentTracer.js +43 -0
- package/esm/rumEventsCollection/tracing/zipkinMultiTracer.js +50 -0
- package/esm/rumEventsCollection/tracing/zipkinSingleTracer.js +43 -0
- package/package.json +5 -1
package/cjs/helper/utils.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.round = round;
|
|
7
|
+
exports.toServerDuration = toServerDuration;
|
|
7
8
|
exports.msToNs = msToNs;
|
|
8
9
|
exports.UUID = UUID;
|
|
9
10
|
exports.jsonStringify = jsonStringify;
|
|
@@ -19,7 +20,10 @@ exports.withSnakeCaseKeys = withSnakeCaseKeys;
|
|
|
19
20
|
exports.deepSnakeCase = deepSnakeCase;
|
|
20
21
|
exports.toSnakeCase = toSnakeCase;
|
|
21
22
|
exports.escapeRowData = escapeRowData;
|
|
22
|
-
exports.
|
|
23
|
+
exports.getOrigin = getOrigin;
|
|
24
|
+
exports.createContextManager = createContextManager;
|
|
25
|
+
exports.getActivePage = getActivePage;
|
|
26
|
+
exports.deepMixObject = exports.defineObject = exports.getOwnObjectKeys = exports.urlParse = exports.throttle = exports.now = exports.safeJSONParse = exports.isJSONString = exports.isEmptyObject = exports.isObject = exports.trim = exports.extend2Lev = exports.extend = exports.getURLSearchParams = exports.getQueryParamsFromUrl = exports.base64Encode = exports.utf8Encode = exports.areInOrder = exports.toArray = exports.isArray = exports.isNumber = exports.isBoolean = exports.isDate = exports.isString = exports.isUndefined = exports.values = exports.each = exports.isArguments = void 0;
|
|
23
27
|
|
|
24
28
|
var _enums = require("./enums");
|
|
25
29
|
|
|
@@ -32,6 +36,7 @@ var hasOwnProperty = ObjProto.hasOwnProperty;
|
|
|
32
36
|
var slice = ArrayProto.slice;
|
|
33
37
|
var toString = ObjProto.toString;
|
|
34
38
|
var nativeForEach = ArrayProto.forEach;
|
|
39
|
+
var nativeIsArray = Array.isArray;
|
|
35
40
|
var breaker = false;
|
|
36
41
|
|
|
37
42
|
var isArguments = function isArguments(obj) {
|
|
@@ -83,6 +88,14 @@ function round(num, decimals) {
|
|
|
83
88
|
return +num.toFixed(decimals);
|
|
84
89
|
}
|
|
85
90
|
|
|
91
|
+
function toServerDuration(duration) {
|
|
92
|
+
if (!isNumber(duration)) {
|
|
93
|
+
return duration;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return round(duration * 1e6, 0);
|
|
97
|
+
}
|
|
98
|
+
|
|
86
99
|
function msToNs(duration) {
|
|
87
100
|
if (typeof duration !== 'number') {
|
|
88
101
|
return duration;
|
|
@@ -121,6 +134,12 @@ var isNumber = function isNumber(obj) {
|
|
|
121
134
|
|
|
122
135
|
exports.isNumber = isNumber;
|
|
123
136
|
|
|
137
|
+
var isArray = nativeIsArray || function (obj) {
|
|
138
|
+
return toString.call(obj) === '[object Array]';
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
exports.isArray = isArray;
|
|
142
|
+
|
|
124
143
|
var toArray = function toArray(iterable) {
|
|
125
144
|
if (!iterable) return [];
|
|
126
145
|
|
|
@@ -210,6 +229,98 @@ function jsonStringify(value, replacer, space) {
|
|
|
210
229
|
return result;
|
|
211
230
|
}
|
|
212
231
|
|
|
232
|
+
var utf8Encode = function utf8Encode(string) {
|
|
233
|
+
string = (string + '').replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
234
|
+
var utftext = '',
|
|
235
|
+
start,
|
|
236
|
+
end;
|
|
237
|
+
var stringl = 0,
|
|
238
|
+
n;
|
|
239
|
+
start = end = 0;
|
|
240
|
+
stringl = string.length;
|
|
241
|
+
|
|
242
|
+
for (n = 0; n < stringl; n++) {
|
|
243
|
+
var c1 = string.charCodeAt(n);
|
|
244
|
+
var enc = null;
|
|
245
|
+
|
|
246
|
+
if (c1 < 128) {
|
|
247
|
+
end++;
|
|
248
|
+
} else if (c1 > 127 && c1 < 2048) {
|
|
249
|
+
enc = String.fromCharCode(c1 >> 6 | 192, c1 & 63 | 128);
|
|
250
|
+
} else {
|
|
251
|
+
enc = String.fromCharCode(c1 >> 12 | 224, c1 >> 6 & 63 | 128, c1 & 63 | 128);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (enc !== null) {
|
|
255
|
+
if (end > start) {
|
|
256
|
+
utftext += string.substring(start, end);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
utftext += enc;
|
|
260
|
+
start = end = n + 1;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (end > start) {
|
|
265
|
+
utftext += string.substring(start, string.length);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return utftext;
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
exports.utf8Encode = utf8Encode;
|
|
272
|
+
|
|
273
|
+
var base64Encode = function base64Encode(data) {
|
|
274
|
+
data = String(data);
|
|
275
|
+
var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
276
|
+
var o1,
|
|
277
|
+
o2,
|
|
278
|
+
o3,
|
|
279
|
+
h1,
|
|
280
|
+
h2,
|
|
281
|
+
h3,
|
|
282
|
+
h4,
|
|
283
|
+
bits,
|
|
284
|
+
i = 0,
|
|
285
|
+
ac = 0,
|
|
286
|
+
enc = '',
|
|
287
|
+
tmp_arr = [];
|
|
288
|
+
|
|
289
|
+
if (!data) {
|
|
290
|
+
return data;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
data = utf8Encode(data);
|
|
294
|
+
|
|
295
|
+
do {
|
|
296
|
+
o1 = data.charCodeAt(i++);
|
|
297
|
+
o2 = data.charCodeAt(i++);
|
|
298
|
+
o3 = data.charCodeAt(i++);
|
|
299
|
+
bits = o1 << 16 | o2 << 8 | o3;
|
|
300
|
+
h1 = bits >> 18 & 0x3f;
|
|
301
|
+
h2 = bits >> 12 & 0x3f;
|
|
302
|
+
h3 = bits >> 6 & 0x3f;
|
|
303
|
+
h4 = bits & 0x3f;
|
|
304
|
+
tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
|
|
305
|
+
} while (i < data.length);
|
|
306
|
+
|
|
307
|
+
enc = tmp_arr.join('');
|
|
308
|
+
|
|
309
|
+
switch (data.length % 3) {
|
|
310
|
+
case 1:
|
|
311
|
+
enc = enc.slice(0, -2) + '==';
|
|
312
|
+
break;
|
|
313
|
+
|
|
314
|
+
case 2:
|
|
315
|
+
enc = enc.slice(0, -1) + '=';
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
return enc;
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
exports.base64Encode = base64Encode;
|
|
323
|
+
|
|
213
324
|
function hasToJSON(value) {
|
|
214
325
|
return _typeof(value) === 'object' && value !== null && value.hasOwnProperty('toJSON');
|
|
215
326
|
}
|
|
@@ -258,6 +369,32 @@ var getQueryParamsFromUrl = function getQueryParamsFromUrl(url) {
|
|
|
258
369
|
|
|
259
370
|
exports.getQueryParamsFromUrl = getQueryParamsFromUrl;
|
|
260
371
|
|
|
372
|
+
var getURLSearchParams = function getURLSearchParams(queryString) {
|
|
373
|
+
queryString = queryString || '';
|
|
374
|
+
|
|
375
|
+
var decodeParam = function decodeParam(str) {
|
|
376
|
+
return decodeURIComponent(str);
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
var args = {};
|
|
380
|
+
var query = queryString.substring(1);
|
|
381
|
+
var pairs = query.split('&');
|
|
382
|
+
|
|
383
|
+
for (var i = 0; i < pairs.length; i++) {
|
|
384
|
+
var pos = pairs[i].indexOf('=');
|
|
385
|
+
if (pos === -1) continue;
|
|
386
|
+
var name = pairs[i].substring(0, pos);
|
|
387
|
+
var value = pairs[i].substring(pos + 1);
|
|
388
|
+
name = decodeParam(name);
|
|
389
|
+
value = decodeParam(value);
|
|
390
|
+
args[name] = value;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
return args;
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
exports.getURLSearchParams = getURLSearchParams;
|
|
397
|
+
|
|
261
398
|
function isPercentage(value) {
|
|
262
399
|
return isNumber(value) && value >= 0 && value <= 100;
|
|
263
400
|
}
|
|
@@ -456,7 +593,12 @@ function toSnakeCase(word) {
|
|
|
456
593
|
}
|
|
457
594
|
|
|
458
595
|
function escapeRowData(str) {
|
|
459
|
-
if (
|
|
596
|
+
if (_typeof(str) === 'object' && str) {
|
|
597
|
+
str = jsonStringify(str);
|
|
598
|
+
} else if (!isString(str)) {
|
|
599
|
+
return str;
|
|
600
|
+
}
|
|
601
|
+
|
|
460
602
|
var reg = /[\s=,"]/g;
|
|
461
603
|
return String(str).replace(reg, function (word) {
|
|
462
604
|
return '\\' + word;
|
|
@@ -527,8 +669,8 @@ var urlParse = function urlParse(para) {
|
|
|
527
669
|
|
|
528
670
|
URLParser.prototype.getUrl = function () {
|
|
529
671
|
var url = '';
|
|
530
|
-
url += this._values.Origin;
|
|
531
|
-
|
|
672
|
+
url += this._values.Origin; // url += this._values.Port ? ':' + this._values.Port : ''
|
|
673
|
+
|
|
532
674
|
url += this._values.Path;
|
|
533
675
|
url += this._values.QueryString ? '?' + this._values.QueryString : '';
|
|
534
676
|
return url;
|
|
@@ -549,8 +691,9 @@ var urlParse = function urlParse(para) {
|
|
|
549
691
|
}
|
|
550
692
|
}
|
|
551
693
|
|
|
694
|
+
this._values['Path'] = this._values['Path'] || '/';
|
|
552
695
|
this._values['Hostname'] = this._values['Host'].replace(/:\d+$/, '');
|
|
553
|
-
this._values['Origin'] = this._values['Protocol'] + '://' + this._values['Hostname'];
|
|
696
|
+
this._values['Origin'] = this._values['Protocol'] + '://' + this._values['Hostname'] + (this._values.Port ? ':' + this._values.Port : '');
|
|
554
697
|
};
|
|
555
698
|
|
|
556
699
|
return new URLParser(para);
|
|
@@ -617,4 +760,44 @@ var deepMixObject = function deepMixObject(targetObj) {
|
|
|
617
760
|
return targetObj;
|
|
618
761
|
};
|
|
619
762
|
|
|
620
|
-
exports.deepMixObject = deepMixObject;
|
|
763
|
+
exports.deepMixObject = deepMixObject;
|
|
764
|
+
|
|
765
|
+
function getOrigin(url) {
|
|
766
|
+
return urlParse(url).getParse().Origin;
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
function createContextManager() {
|
|
770
|
+
var context = {};
|
|
771
|
+
return {
|
|
772
|
+
get: function get() {
|
|
773
|
+
return context;
|
|
774
|
+
},
|
|
775
|
+
add: function add(key, value) {
|
|
776
|
+
if (isString(key)) {
|
|
777
|
+
context[key] = value;
|
|
778
|
+
} else {
|
|
779
|
+
console.error('key 需要传递字符串类型');
|
|
780
|
+
}
|
|
781
|
+
},
|
|
782
|
+
remove: function remove(key) {
|
|
783
|
+
delete context[key];
|
|
784
|
+
},
|
|
785
|
+
set: function set(newContext) {
|
|
786
|
+
if (isObject(newContext)) {
|
|
787
|
+
context = newContext;
|
|
788
|
+
} else {
|
|
789
|
+
console.error('content 需要传递对象类型数据');
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
};
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
function getActivePage() {
|
|
796
|
+
var curPages = typeof getCurrentPages === 'function' ? getCurrentPages() : [];
|
|
797
|
+
|
|
798
|
+
if (curPages.length) {
|
|
799
|
+
return curPages[curPages.length - 1];
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
return {};
|
|
803
|
+
}
|
|
@@ -24,17 +24,20 @@ var SessionType = {
|
|
|
24
24
|
USER: 'user'
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
function startRumAssembly(applicationId, configuration, lifeCycle, parentContexts) {
|
|
27
|
+
function startRumAssembly(applicationId, configuration, lifeCycle, parentContexts, getCommonContext) {
|
|
28
28
|
lifeCycle.subscribe(_lifeCycle.LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, function (data) {
|
|
29
29
|
var startTime = data.startTime;
|
|
30
30
|
var rawRumEvent = data.rawRumEvent;
|
|
31
31
|
var viewContext = parentContexts.findView(startTime);
|
|
32
|
+
var savedCommonContext = data.savedGlobalContext;
|
|
33
|
+
var customerContext = data.customerContext;
|
|
32
34
|
var deviceContext = {
|
|
33
35
|
device: _baseInfo["default"].deviceInfo
|
|
34
36
|
};
|
|
35
37
|
|
|
36
38
|
if (isTracked(configuration) && (viewContext || rawRumEvent.type === _enums.RumEventType.APP)) {
|
|
37
39
|
var actionContext = parentContexts.findAction(startTime);
|
|
40
|
+
var commonContext = savedCommonContext || getCommonContext();
|
|
38
41
|
var rumContext = {
|
|
39
42
|
_dd: {
|
|
40
43
|
sdkName: configuration.sdkName,
|
|
@@ -53,12 +56,26 @@ function startRumAssembly(applicationId, configuration, lifeCycle, parentContext
|
|
|
53
56
|
type: SessionType.USER
|
|
54
57
|
},
|
|
55
58
|
user: {
|
|
56
|
-
|
|
59
|
+
id: configuration.user_id || _baseInfo["default"].getClientID(),
|
|
57
60
|
is_signin: configuration.user_id ? 'T' : 'F'
|
|
58
61
|
}
|
|
59
62
|
};
|
|
60
63
|
var rumEvent = (0, _utils.extend2Lev)(rumContext, deviceContext, viewContext, actionContext, rawRumEvent);
|
|
61
64
|
var serverRumEvent = (0, _utils.withSnakeCaseKeys)(rumEvent);
|
|
65
|
+
var context = (0, _utils.extend2Lev)(commonContext.context, customerContext);
|
|
66
|
+
|
|
67
|
+
if (!(0, _utils.isEmptyObject)(context)) {
|
|
68
|
+
serverRumEvent.tags = context;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (!(0, _utils.isEmptyObject)(commonContext.user)) {
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
73
|
+
serverRumEvent.user = (0, _utils.extend2Lev)({
|
|
74
|
+
id: _baseInfo["default"].getClientID(),
|
|
75
|
+
is_signin: 'T'
|
|
76
|
+
}, commonContext.user);
|
|
77
|
+
}
|
|
78
|
+
|
|
62
79
|
lifeCycle.notify(_lifeCycle.LifeCycleEventType.RUM_EVENT_COLLECTED, serverRumEvent);
|
|
63
80
|
}
|
|
64
81
|
});
|
|
@@ -36,7 +36,7 @@ function rewritePage(configuration, lifeCycle, Vue) {
|
|
|
36
36
|
|
|
37
37
|
if (methodName === 'onShow' || methodName === 'onLoad') {
|
|
38
38
|
if (typeof currentView === 'undefined') {
|
|
39
|
-
var activePage = getActivePage();
|
|
39
|
+
var activePage = (0, _utils.getActivePage)();
|
|
40
40
|
currentView = newView(lifeCycle, activePage && activePage.route, startTime);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
@@ -231,14 +231,4 @@ function trackSetDataTime(lifeCycle, callback) {
|
|
|
231
231
|
return {
|
|
232
232
|
stop: subscribe.unsubscribe
|
|
233
233
|
};
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
function getActivePage() {
|
|
237
|
-
var curPages = getCurrentPages();
|
|
238
|
-
|
|
239
|
-
if (curPages.length) {
|
|
240
|
-
return curPages[curPages.length - 1];
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
return {};
|
|
244
234
|
}
|
|
@@ -17,10 +17,13 @@ var _utils = require("../helper/utils");
|
|
|
17
17
|
|
|
18
18
|
var _resourceUtils = require("../rumEventsCollection/resource/resourceUtils");
|
|
19
19
|
|
|
20
|
+
var _tracer = require("../rumEventsCollection/tracing/tracer");
|
|
21
|
+
|
|
20
22
|
var nextRequestIndex = 1;
|
|
21
23
|
|
|
22
24
|
function startRequestCollection(lifeCycle, configuration) {
|
|
23
|
-
|
|
25
|
+
var tracer = (0, _tracer.startTracer)(configuration);
|
|
26
|
+
trackXhr(lifeCycle, configuration, tracer);
|
|
24
27
|
trackDownload(lifeCycle, configuration);
|
|
25
28
|
}
|
|
26
29
|
|
|
@@ -43,10 +46,11 @@ function getHeaderString(header) {
|
|
|
43
46
|
return headerStr;
|
|
44
47
|
}
|
|
45
48
|
|
|
46
|
-
function trackXhr(lifeCycle, configuration) {
|
|
49
|
+
function trackXhr(lifeCycle, configuration, tracer) {
|
|
47
50
|
var xhrProxy = (0, _xhrProxy.startXhrProxy)();
|
|
48
51
|
xhrProxy.beforeSend(function (context) {
|
|
49
52
|
if ((0, _resourceUtils.isAllowedRequestUrl)(configuration, context.url)) {
|
|
53
|
+
tracer.traceXhr(context);
|
|
50
54
|
context.requestIndex = getNextRequestIndex();
|
|
51
55
|
lifeCycle.notify(_lifeCycle.LifeCycleEventType.REQUEST_STARTED, {
|
|
52
56
|
requestIndex: context.requestIndex
|
|
@@ -55,6 +59,7 @@ function trackXhr(lifeCycle, configuration) {
|
|
|
55
59
|
});
|
|
56
60
|
xhrProxy.onRequestComplete(function (context) {
|
|
57
61
|
if ((0, _resourceUtils.isAllowedRequestUrl)(configuration, context.url)) {
|
|
62
|
+
tracer.clearTracingIfCancelled(context);
|
|
58
63
|
lifeCycle.notify(_lifeCycle.LifeCycleEventType.REQUEST_COMPLETED, {
|
|
59
64
|
duration: context.duration,
|
|
60
65
|
method: context.method,
|
|
@@ -63,6 +68,8 @@ function trackXhr(lifeCycle, configuration) {
|
|
|
63
68
|
response: context.response,
|
|
64
69
|
startTime: context.startTime,
|
|
65
70
|
status: context.status,
|
|
71
|
+
traceId: context.traceId,
|
|
72
|
+
spanId: context.spanId,
|
|
66
73
|
type: context.type,
|
|
67
74
|
url: context.url
|
|
68
75
|
});
|
|
@@ -23,8 +23,10 @@ function processRequest(request) {
|
|
|
23
23
|
var type = request.type;
|
|
24
24
|
var timing = request.performance;
|
|
25
25
|
var correspondingTimingOverrides = timing ? computePerformanceEntryMetrics(timing) : undefined;
|
|
26
|
+
var tracingInfo = computeRequestTracingInfo(request);
|
|
26
27
|
var urlObj = (0, _utils.urlParse)(request.url).getParse();
|
|
27
28
|
var startTime = request.startTime;
|
|
29
|
+
console.log(request, 'request=========');
|
|
28
30
|
var resourceEvent = (0, _utils.extend2Lev)({
|
|
29
31
|
date: startTime,
|
|
30
32
|
resource: {
|
|
@@ -40,13 +42,31 @@ function processRequest(request) {
|
|
|
40
42
|
urlQuery: (0, _utils.jsonStringify)((0, _utils.getQueryParamsFromUrl)(request.url))
|
|
41
43
|
},
|
|
42
44
|
type: _enums.RumEventType.RESOURCE
|
|
43
|
-
}, correspondingTimingOverrides);
|
|
45
|
+
}, tracingInfo, correspondingTimingOverrides);
|
|
44
46
|
return {
|
|
45
47
|
startTime: startTime,
|
|
46
48
|
rawRumEvent: resourceEvent
|
|
47
49
|
};
|
|
48
50
|
}
|
|
49
51
|
|
|
52
|
+
function computeRequestTracingInfo(request) {
|
|
53
|
+
var hasBeenTraced = request.traceId && request.spanId;
|
|
54
|
+
|
|
55
|
+
if (!hasBeenTraced) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
_dd: {
|
|
61
|
+
spanId: request.spanId,
|
|
62
|
+
traceId: request.traceId
|
|
63
|
+
},
|
|
64
|
+
resource: {
|
|
65
|
+
id: (0, _utils.UUID)()
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
50
70
|
function computePerformanceEntryMetrics(timing) {
|
|
51
71
|
return {
|
|
52
72
|
resource: (0, _utils.extend2Lev)({}, {
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.DDtraceTracer = DDtraceTracer;
|
|
7
|
+
|
|
8
|
+
// === Generate a random 64-bit number in fixed-length hex format
|
|
9
|
+
function randomTraceId() {
|
|
10
|
+
var digits = '0123456789abcdef';
|
|
11
|
+
var n = '';
|
|
12
|
+
|
|
13
|
+
for (var i = 0; i < 19; i += 1) {
|
|
14
|
+
var rand = Math.floor(Math.random() * 10);
|
|
15
|
+
n += digits[rand];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return n;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @param {*} configuration 配置信息
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
function DDtraceTracer(configuration) {
|
|
27
|
+
this._spanId = randomTraceId();
|
|
28
|
+
this._traceId = randomTraceId();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
DDtraceTracer.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-datadog-origin': 'rum',
|
|
44
|
+
// 'x-datadog-parent-id': spanId.toDecimalString(),
|
|
45
|
+
'x-datadog-sampled': '1',
|
|
46
|
+
'x-datadog-sampling-priority': '1',
|
|
47
|
+
'x-datadog-trace-id': this.getTraceId()
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.JaegerTracer = JaegerTracer;
|
|
7
|
+
|
|
8
|
+
// === Generate a random 64-bit number in fixed-length hex format
|
|
9
|
+
function randomTraceId() {
|
|
10
|
+
var digits = '0123456789abcdef';
|
|
11
|
+
var n = '';
|
|
12
|
+
|
|
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
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @param {*} configuration 配置信息
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
function JaegerTracer(configuration) {
|
|
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;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
JaegerTracer.prototype = {
|
|
40
|
+
isTracingSupported: function isTracingSupported() {
|
|
41
|
+
return true;
|
|
42
|
+
},
|
|
43
|
+
getSpanId: function getSpanId() {
|
|
44
|
+
return this._spanId;
|
|
45
|
+
},
|
|
46
|
+
getTraceId: function getTraceId() {
|
|
47
|
+
return this._traceId;
|
|
48
|
+
},
|
|
49
|
+
getUberTraceId: function getUberTraceId() {
|
|
50
|
+
//{trace-id}:{span-id}:{parent-span-id}:{flags}
|
|
51
|
+
return this._traceId + ':' + this._spanId + ':' + '0' + ':' + '1';
|
|
52
|
+
},
|
|
53
|
+
makeTracingHeaders: function makeTracingHeaders() {
|
|
54
|
+
return {
|
|
55
|
+
'uber-trace-id': this.getUberTraceId()
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.SkyWalkingTracer = SkyWalkingTracer;
|
|
7
|
+
|
|
8
|
+
var _utils = require("../../helper/utils");
|
|
9
|
+
|
|
10
|
+
// start SkyWalking
|
|
11
|
+
function uuid() {
|
|
12
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
13
|
+
/* tslint:disable */
|
|
14
|
+
var r = Math.random() * 16 | 0;
|
|
15
|
+
/* tslint:disable */
|
|
16
|
+
|
|
17
|
+
var v = c === 'x' ? r : r & 0x3 | 0x8;
|
|
18
|
+
return v.toString(16);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @param {*} configuration 配置信息
|
|
24
|
+
* @param {*} requestUrl 请求的url
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
function SkyWalkingTracer(configuration, requestUrl) {
|
|
29
|
+
this._spanId = uuid();
|
|
30
|
+
this._traceId = uuid();
|
|
31
|
+
this._applicationId = configuration.applicationId;
|
|
32
|
+
this._env = configuration.env;
|
|
33
|
+
this._version = configuration.version;
|
|
34
|
+
this._urlParse = (0, _utils.urlParse)(requestUrl).getParse();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
SkyWalkingTracer.prototype = {
|
|
38
|
+
isTracingSupported: function isTracingSupported() {
|
|
39
|
+
if (this._env && this._version && this._urlParse) return true;
|
|
40
|
+
return false;
|
|
41
|
+
},
|
|
42
|
+
getSpanId: function getSpanId() {
|
|
43
|
+
return this._spanId;
|
|
44
|
+
},
|
|
45
|
+
getTraceId: function getTraceId() {
|
|
46
|
+
return this._traceId;
|
|
47
|
+
},
|
|
48
|
+
getSkyWalkingSw8: function getSkyWalkingSw8() {
|
|
49
|
+
try {
|
|
50
|
+
var traceIdStr = String((0, _utils.base64Encode)(this._traceId));
|
|
51
|
+
var segmentId = String((0, _utils.base64Encode)(this._spanId));
|
|
52
|
+
var service = String((0, _utils.base64Encode)(this._applicationId + '_rum_' + this.env));
|
|
53
|
+
var instance = String((0, _utils.base64Encode)(this._version));
|
|
54
|
+
var activePage = (0, _utils.getActivePage)();
|
|
55
|
+
var endpointPage = '';
|
|
56
|
+
|
|
57
|
+
if (activePage && activePage.route) {
|
|
58
|
+
endpointPage = activePage.route;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
var endpoint = String((0, _utils.base64Encode)(endpointPage));
|
|
62
|
+
var peer = String((0, _utils.base64Encode)(this._urlParse.Host));
|
|
63
|
+
var index = '0'; // var values = `${1}-${traceIdStr}-${segmentId}-${index}-${service}-${instance}-${endpoint}-${peer}`;
|
|
64
|
+
|
|
65
|
+
return '1-' + traceIdStr + '-' + segmentId + '-' + index + '-' + service + '-' + instance + '-' + endpoint + '-' + peer;
|
|
66
|
+
} catch (err) {
|
|
67
|
+
return '';
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
makeTracingHeaders: function makeTracingHeaders() {
|
|
71
|
+
return {
|
|
72
|
+
'sw8': this.getSkyWalkingSw8()
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
};
|