@cloudcare/rum-uniapp 1.0.3 → 2.1.2

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 (70) hide show
  1. package/README.md +11 -8
  2. package/cjs/boot/buildEnv.js +1 -1
  3. package/cjs/boot/rum.entry.js +73 -2
  4. package/cjs/boot/rum.js +15 -3
  5. package/cjs/core/baseInfo.js +0 -6
  6. package/cjs/core/boundedBuffer.js +28 -0
  7. package/cjs/core/configuration.js +26 -1
  8. package/cjs/core/dataMap.js +5 -1
  9. package/cjs/core/errorCollection.js +5 -6
  10. package/cjs/core/errorFilter.js +47 -0
  11. package/cjs/core/errorTools.js +2 -1
  12. package/cjs/core/lifeCycle.js +1 -0
  13. package/cjs/core/sdk.js +0 -1
  14. package/cjs/core/sessionManagement.js +45 -0
  15. package/cjs/core/transport.js +114 -69
  16. package/cjs/core/xhrProxy.js +3 -2
  17. package/cjs/helper/enums.js +22 -7
  18. package/cjs/helper/limitModification.js +83 -0
  19. package/cjs/helper/tracekit.js +1 -1
  20. package/cjs/helper/utils.js +248 -6
  21. package/cjs/rumEventsCollection/action/actionCollection.js +19 -1
  22. package/cjs/rumEventsCollection/app/appCollection.js +0 -1
  23. package/cjs/rumEventsCollection/assembly.js +41 -14
  24. package/cjs/rumEventsCollection/error/errorCollection.js +37 -5
  25. package/cjs/rumEventsCollection/internalContext.js +34 -0
  26. package/cjs/rumEventsCollection/page/index.js +2 -11
  27. package/cjs/rumEventsCollection/requestCollection.js +9 -2
  28. package/cjs/rumEventsCollection/resource/resourceCollection.js +20 -2
  29. package/cjs/rumEventsCollection/tracing/ddtraceTracer.js +50 -0
  30. package/cjs/rumEventsCollection/tracing/jaegerTracer.js +58 -0
  31. package/cjs/rumEventsCollection/tracing/skywalkingTracer.js +75 -0
  32. package/cjs/rumEventsCollection/tracing/tracer.js +108 -0
  33. package/cjs/rumEventsCollection/tracing/w3cTraceParentTracer.js +51 -0
  34. package/cjs/rumEventsCollection/tracing/zipkinMultiTracer.js +58 -0
  35. package/cjs/rumEventsCollection/tracing/zipkinSingleTracer.js +51 -0
  36. package/esm/boot/buildEnv.js +1 -1
  37. package/esm/boot/rum.entry.js +71 -3
  38. package/esm/boot/rum.js +13 -3
  39. package/esm/core/baseInfo.js +0 -5
  40. package/esm/core/boundedBuffer.js +20 -0
  41. package/esm/core/configuration.js +28 -3
  42. package/esm/core/dataMap.js +5 -1
  43. package/esm/core/errorCollection.js +5 -6
  44. package/esm/core/errorFilter.js +38 -0
  45. package/esm/core/errorTools.js +2 -1
  46. package/esm/core/lifeCycle.js +1 -0
  47. package/esm/core/sdk.js +0 -1
  48. package/esm/core/sessionManagement.js +20 -0
  49. package/esm/core/transport.js +111 -70
  50. package/esm/core/xhrProxy.js +3 -2
  51. package/esm/helper/enums.js +16 -2
  52. package/esm/helper/limitModification.js +57 -0
  53. package/esm/helper/tracekit.js +1 -1
  54. package/esm/helper/utils.js +213 -5
  55. package/esm/rumEventsCollection/action/actionCollection.js +20 -2
  56. package/esm/rumEventsCollection/app/appCollection.js +0 -1
  57. package/esm/rumEventsCollection/assembly.js +40 -15
  58. package/esm/rumEventsCollection/error/errorCollection.js +36 -5
  59. package/esm/rumEventsCollection/internalContext.js +27 -0
  60. package/esm/rumEventsCollection/page/index.js +2 -11
  61. package/esm/rumEventsCollection/requestCollection.js +8 -2
  62. package/esm/rumEventsCollection/resource/resourceCollection.js +21 -3
  63. package/esm/rumEventsCollection/tracing/ddtraceTracer.js +42 -0
  64. package/esm/rumEventsCollection/tracing/jaegerTracer.js +50 -0
  65. package/esm/rumEventsCollection/tracing/skywalkingTracer.js +66 -0
  66. package/esm/rumEventsCollection/tracing/tracer.js +90 -0
  67. package/esm/rumEventsCollection/tracing/w3cTraceParentTracer.js +43 -0
  68. package/esm/rumEventsCollection/tracing/zipkinMultiTracer.js +50 -0
  69. package/esm/rumEventsCollection/tracing/zipkinSingleTracer.js +43 -0
  70. package/package.json +1 -1
@@ -6,6 +6,7 @@ var hasOwnProperty = ObjProto.hasOwnProperty;
6
6
  var slice = ArrayProto.slice;
7
7
  var toString = ObjProto.toString;
8
8
  var nativeForEach = ArrayProto.forEach;
9
+ var nativeIsArray = Array.isArray;
9
10
  var breaker = false;
10
11
  export var isArguments = function isArguments(obj) {
11
12
  return !!(obj && hasOwnProperty.call(obj, 'callee'));
@@ -43,9 +44,43 @@ export var values = function values(obj) {
43
44
  });
44
45
  return results;
45
46
  };
47
+ export var keys = function keys(obj) {
48
+ var results = [];
49
+
50
+ if (obj === null) {
51
+ return results;
52
+ }
53
+
54
+ each(obj, function (value, key) {
55
+ results[results.length] = key;
56
+ });
57
+ return results;
58
+ };
59
+ export var indexOf = function indexOf(arr, target) {
60
+ var indexOf = arr.indexOf;
61
+
62
+ if (indexOf) {
63
+ return indexOf.call(arr, target);
64
+ } else {
65
+ for (var i = 0; i < arr.length; i++) {
66
+ if (target === arr[i]) {
67
+ return i;
68
+ }
69
+ }
70
+
71
+ return -1;
72
+ }
73
+ };
46
74
  export function round(num, decimals) {
47
75
  return +num.toFixed(decimals);
48
76
  }
77
+ export function toServerDuration(duration) {
78
+ if (!isNumber(duration)) {
79
+ return duration;
80
+ }
81
+
82
+ return round(duration * 1e6, 0);
83
+ }
49
84
  export function msToNs(duration) {
50
85
  if (typeof duration !== 'number') {
51
86
  return duration;
@@ -68,6 +103,9 @@ export var isBoolean = function isBoolean(obj) {
68
103
  export var isNumber = function isNumber(obj) {
69
104
  return toString.call(obj) === '[object Number]' && /[\d\.]+/.test(String(obj));
70
105
  };
106
+ export var isArray = nativeIsArray || function (obj) {
107
+ return toString.call(obj) === '[object Array]';
108
+ };
71
109
  export var toArray = function toArray(iterable) {
72
110
  if (!iterable) return [];
73
111
 
@@ -149,6 +187,92 @@ export function jsonStringify(value, replacer, space) {
149
187
 
150
188
  return result;
151
189
  }
190
+ export var utf8Encode = function utf8Encode(string) {
191
+ string = (string + '').replace(/\r\n/g, '\n').replace(/\r/g, '\n');
192
+ var utftext = '',
193
+ start,
194
+ end;
195
+ var stringl = 0,
196
+ n;
197
+ start = end = 0;
198
+ stringl = string.length;
199
+
200
+ for (n = 0; n < stringl; n++) {
201
+ var c1 = string.charCodeAt(n);
202
+ var enc = null;
203
+
204
+ if (c1 < 128) {
205
+ end++;
206
+ } else if (c1 > 127 && c1 < 2048) {
207
+ enc = String.fromCharCode(c1 >> 6 | 192, c1 & 63 | 128);
208
+ } else {
209
+ enc = String.fromCharCode(c1 >> 12 | 224, c1 >> 6 & 63 | 128, c1 & 63 | 128);
210
+ }
211
+
212
+ if (enc !== null) {
213
+ if (end > start) {
214
+ utftext += string.substring(start, end);
215
+ }
216
+
217
+ utftext += enc;
218
+ start = end = n + 1;
219
+ }
220
+ }
221
+
222
+ if (end > start) {
223
+ utftext += string.substring(start, string.length);
224
+ }
225
+
226
+ return utftext;
227
+ };
228
+ export var base64Encode = function base64Encode(data) {
229
+ data = String(data);
230
+ var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
231
+ var o1,
232
+ o2,
233
+ o3,
234
+ h1,
235
+ h2,
236
+ h3,
237
+ h4,
238
+ bits,
239
+ i = 0,
240
+ ac = 0,
241
+ enc = '',
242
+ tmp_arr = [];
243
+
244
+ if (!data) {
245
+ return data;
246
+ }
247
+
248
+ data = utf8Encode(data);
249
+
250
+ do {
251
+ o1 = data.charCodeAt(i++);
252
+ o2 = data.charCodeAt(i++);
253
+ o3 = data.charCodeAt(i++);
254
+ bits = o1 << 16 | o2 << 8 | o3;
255
+ h1 = bits >> 18 & 0x3f;
256
+ h2 = bits >> 12 & 0x3f;
257
+ h3 = bits >> 6 & 0x3f;
258
+ h4 = bits & 0x3f;
259
+ tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
260
+ } while (i < data.length);
261
+
262
+ enc = tmp_arr.join('');
263
+
264
+ switch (data.length % 3) {
265
+ case 1:
266
+ enc = enc.slice(0, -2) + '==';
267
+ break;
268
+
269
+ case 2:
270
+ enc = enc.slice(0, -1) + '=';
271
+ break;
272
+ }
273
+
274
+ return enc;
275
+ };
152
276
 
153
277
  function hasToJSON(value) {
154
278
  return typeof value === 'object' && value !== null && value.hasOwnProperty('toJSON');
@@ -376,7 +500,12 @@ export function toSnakeCase(word) {
376
500
  }).replace(/-/g, '_');
377
501
  }
378
502
  export function escapeRowData(str) {
379
- if (!isString(str)) return str;
503
+ if (typeof str === 'object' && str) {
504
+ str = jsonStringify(str);
505
+ } else if (!isString(str)) {
506
+ return str;
507
+ }
508
+
380
509
  var reg = /[\s=,"]/g;
381
510
  return String(str).replace(reg, function (word) {
382
511
  return '\\' + word;
@@ -446,8 +575,8 @@ export var urlParse = function urlParse(para) {
446
575
 
447
576
  URLParser.prototype.getUrl = function () {
448
577
  var url = '';
449
- url += this._values.Origin;
450
- url += this._values.Port ? ':' + this._values.Port : '';
578
+ url += this._values.Origin; // url += this._values.Port ? ':' + this._values.Port : ''
579
+
451
580
  url += this._values.Path;
452
581
  url += this._values.QueryString ? '?' + this._values.QueryString : '';
453
582
  return url;
@@ -468,8 +597,9 @@ export var urlParse = function urlParse(para) {
468
597
  }
469
598
  }
470
599
 
600
+ this._values['Path'] = this._values['Path'] || '/';
471
601
  this._values['Hostname'] = this._values['Host'].replace(/:\d+$/, '');
472
- this._values['Origin'] = this._values['Protocol'] + '://' + this._values['Hostname'];
602
+ this._values['Origin'] = this._values['Protocol'] + '://' + this._values['Hostname'] + (this._values.Port ? ':' + this._values.Port : '');
473
603
  };
474
604
 
475
605
  return new URLParser(para);
@@ -525,4 +655,82 @@ export var deepMixObject = function deepMixObject(targetObj) {
525
655
  }
526
656
 
527
657
  return targetObj;
528
- };
658
+ };
659
+ export function getOrigin(url) {
660
+ return urlParse(url).getParse().Origin;
661
+ }
662
+ export function createContextManager() {
663
+ var context = {};
664
+ return {
665
+ get: function get() {
666
+ return context;
667
+ },
668
+ add: function add(key, value) {
669
+ if (isString(key)) {
670
+ context[key] = value;
671
+ } else {
672
+ console.error('key 需要传递字符串类型');
673
+ }
674
+ },
675
+ remove: function remove(key) {
676
+ delete context[key];
677
+ },
678
+ set: function set(newContext) {
679
+ if (isObject(newContext)) {
680
+ context = newContext;
681
+ } else {
682
+ console.error('content 需要传递对象类型数据');
683
+ }
684
+ }
685
+ };
686
+ }
687
+ export function getActivePage() {
688
+ var curPages = typeof getCurrentPages === 'function' ? getCurrentPages() : [];
689
+
690
+ if (curPages.length) {
691
+ return curPages[curPages.length - 1];
692
+ }
693
+
694
+ return {};
695
+ }
696
+ export function findCommaSeparatedValue(rawString, name) {
697
+ var matches = rawString.match('(?:^|;)\\s*' + name + '\\s*=\\s*([^;]+)');
698
+ return matches ? matches[1] : undefined;
699
+ }
700
+ export var ONE_SECOND = 1000;
701
+ export var ONE_MINUTE = 60 * ONE_SECOND;
702
+ export var ONE_HOUR = 60 * ONE_MINUTE;
703
+ export var ONE_KILO_BYTE = 1024;
704
+ export function defineGlobal(global, name, api) {
705
+ global[name] = api;
706
+ }
707
+ export function getGlobalObject() {
708
+ if (typeof globalThis === 'object') {
709
+ return globalThis;
710
+ }
711
+
712
+ Object.defineProperty(Object.prototype, '_dd_temp_', {
713
+ get: function get() {
714
+ return this;
715
+ },
716
+ configurable: true
717
+ }); // @ts-ignore
718
+
719
+ var globalObject = _dd_temp_; // @ts-ignore
720
+
721
+ delete Object.prototype._dd_temp_;
722
+
723
+ if (typeof globalObject !== 'object') {
724
+ // on safari _dd_temp_ is available on window but not globally
725
+ // fallback on other browser globals check
726
+ if (typeof self === 'object') {
727
+ globalObject = self;
728
+ } else if (typeof window === 'object') {
729
+ globalObject = window;
730
+ } else {
731
+ globalObject = {};
732
+ }
733
+ }
734
+
735
+ return globalObject;
736
+ }
@@ -1,6 +1,6 @@
1
1
  import { msToNs, extend2Lev } from '../../helper/utils';
2
2
  import { LifeCycleEventType } from '../../core/lifeCycle';
3
- import { RumEventType } from '../../helper/enums';
3
+ import { RumEventType, ActionType } from '../../helper/enums';
4
4
  import { trackActions } from './trackActions';
5
5
  export function startActionCollection(lifeCycle, configuration, Vue) {
6
6
  lifeCycle.subscribe(LifeCycleEventType.AUTO_ACTION_COMPLETED, function (action) {
@@ -10,10 +10,18 @@ export function startActionCollection(lifeCycle, configuration, Vue) {
10
10
  if (configuration.trackInteractions) {
11
11
  trackActions(lifeCycle, Vue);
12
12
  }
13
+
14
+ return {
15
+ addAction: function addAction(action, savedCommonContext) {
16
+ lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, extend2Lev({
17
+ savedCommonContext: savedCommonContext
18
+ }, processAction(action)));
19
+ }
20
+ };
13
21
  }
14
22
 
15
23
  function processAction(action) {
16
- var autoActionProperties = {
24
+ var autoActionProperties = isAutoAction(action) ? {
17
25
  action: {
18
26
  error: {
19
27
  count: action.counts.errorCount
@@ -27,7 +35,12 @@ function processAction(action) {
27
35
  count: action.counts.resourceCount
28
36
  }
29
37
  }
38
+ } : {
39
+ action: {
40
+ loadingTime: 0
41
+ }
30
42
  };
43
+ var customerContext = !isAutoAction(action) ? action.context : undefined;
31
44
  var actionEvent = extend2Lev({
32
45
  action: {
33
46
  target: {
@@ -39,7 +52,12 @@ function processAction(action) {
39
52
  type: RumEventType.ACTION
40
53
  }, autoActionProperties);
41
54
  return {
55
+ customerContext: customerContext,
42
56
  rawRumEvent: actionEvent,
43
57
  startTime: action.startClocks
44
58
  };
59
+ }
60
+
61
+ function isAutoAction(action) {
62
+ return action.type !== ActionType.custom;
45
63
  }
@@ -20,7 +20,6 @@ function processAppUpdate(appinfo) {
20
20
  duration: msToNs(appinfo.duration)
21
21
  }
22
22
  };
23
- console.log(appEvent, 'appEvent====');
24
23
  return {
25
24
  rawRumEvent: appEvent,
26
25
  startTime: appinfo.startTime
@@ -1,27 +1,28 @@
1
- import { extend2Lev, withSnakeCaseKeys, performDraw } from '../helper/utils';
1
+ import { extend2Lev, withSnakeCaseKeys, isEmptyObject } from '../helper/utils';
2
2
  import { LifeCycleEventType } from '../core/lifeCycle';
3
3
  import { RumEventType } from '../helper/enums';
4
4
  import baseInfo from '../core/baseInfo';
5
-
6
- function isTracked(configuration) {
7
- return performDraw(configuration.sampleRate);
8
- }
9
-
10
- var SessionType = {
11
- SYNTHETICS: 'synthetics',
12
- USER: 'user'
13
- };
14
- export function startRumAssembly(applicationId, configuration, lifeCycle, parentContexts) {
5
+ import { SessionType } from '../core/sessionManagement';
6
+ import { createErrorFilter } from '../core/errorFilter';
7
+ export function startRumAssembly(applicationId, configuration, session, lifeCycle, parentContexts, getCommonContext) {
8
+ var errorFilter = createErrorFilter(configuration, function (error) {
9
+ lifeCycle.notify(LifeCycleEventType.RAW_ERROR_COLLECTED, {
10
+ error: error
11
+ });
12
+ });
15
13
  lifeCycle.subscribe(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, function (data) {
16
14
  var startTime = data.startTime;
17
15
  var rawRumEvent = data.rawRumEvent;
18
16
  var viewContext = parentContexts.findView(startTime);
17
+ var savedCommonContext = data.savedCommonContext;
18
+ var customerContext = data.customerContext;
19
19
  var deviceContext = {
20
20
  device: baseInfo.deviceInfo
21
21
  };
22
22
 
23
- if (isTracked(configuration) && (viewContext || rawRumEvent.type === RumEventType.APP)) {
23
+ if (session.isTracked() && (viewContext || rawRumEvent.type === RumEventType.APP)) {
24
24
  var actionContext = parentContexts.findAction(startTime);
25
+ var commonContext = savedCommonContext || getCommonContext();
25
26
  var rumContext = {
26
27
  _dd: {
27
28
  sdkName: configuration.sdkName,
@@ -36,17 +37,41 @@ export function startRumAssembly(applicationId, configuration, lifeCycle, parent
36
37
  device: {},
37
38
  date: new Date().getTime(),
38
39
  session: {
39
- id: baseInfo.getSessionId(),
40
+ id: session.getSessionId(),
40
41
  type: SessionType.USER
41
42
  },
42
43
  user: {
43
- user_id: configuration.user_id || baseInfo.getClientID(),
44
+ id: configuration.user_id || baseInfo.getClientID(),
44
45
  is_signin: configuration.user_id ? 'T' : 'F'
45
46
  }
46
47
  };
47
48
  var rumEvent = extend2Lev(rumContext, deviceContext, viewContext, actionContext, rawRumEvent);
48
49
  var serverRumEvent = withSnakeCaseKeys(rumEvent);
49
- lifeCycle.notify(LifeCycleEventType.RUM_EVENT_COLLECTED, serverRumEvent);
50
+ var context = extend2Lev({}, commonContext.context, customerContext);
51
+
52
+ if (!isEmptyObject(context)) {
53
+ serverRumEvent.tags = context;
54
+ }
55
+
56
+ if (!isEmptyObject(commonContext.user)) {
57
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
58
+ serverRumEvent.user = extend2Lev({
59
+ id: baseInfo.getClientID(),
60
+ is_signin: 'T'
61
+ }, commonContext.user);
62
+ }
63
+
64
+ if (shouldSend(serverRumEvent, errorFilter)) {
65
+ lifeCycle.notify(LifeCycleEventType.RUM_EVENT_COLLECTED, serverRumEvent);
66
+ }
50
67
  }
51
68
  });
69
+ }
70
+
71
+ function shouldSend(event, errorFilter) {
72
+ if (event.type === RumEventType.ERROR) {
73
+ return !errorFilter.isLimitReached();
74
+ }
75
+
76
+ return true;
52
77
  }
@@ -3,13 +3,44 @@ import { RumEventType } from '../../helper/enums';
3
3
  import { LifeCycleEventType } from '../../core/lifeCycle';
4
4
  import { urlParse, replaceNumberCharByPath, getStatusGroup } from '../../helper/utils';
5
5
  export function startErrorCollection(lifeCycle, configuration) {
6
- return doStartErrorCollection(lifeCycle, configuration, startAutomaticErrorCollection(configuration));
7
- }
8
- export function doStartErrorCollection(lifeCycle, configuration, observable) {
9
- observable.subscribe(function (error) {
10
- lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, processError(error));
6
+ // return doStartErrorCollection(
7
+ // lifeCycle,
8
+ // configuration,
9
+ // startAutomaticErrorCollection(configuration),
10
+ // )
11
+ startAutomaticErrorCollection(configuration).subscribe(function (error) {
12
+ lifeCycle.notify(LifeCycleEventType.RAW_ERROR_COLLECTED, {
13
+ error: error
14
+ });
11
15
  });
16
+ return doStartErrorCollection(lifeCycle);
12
17
  }
18
+ export function doStartErrorCollection(lifeCycle) {
19
+ lifeCycle.subscribe(LifeCycleEventType.RAW_ERROR_COLLECTED, function (error) {
20
+ lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, processError(error.error));
21
+ });
22
+ return {
23
+ addError: function addError(customError, savedCommonContext) {// var rawError = computeRawError(
24
+ // customError.error,
25
+ // customError.startTime,
26
+ // customError.source
27
+ // )
28
+ // lifeCycle.notify(LifeCycleEventType.RAW_ERROR_COLLECTED, {
29
+ // customerContext: customError.context,
30
+ // savedCommonContext: savedCommonContext,
31
+ // error: rawError
32
+ // })
33
+ }
34
+ };
35
+ } // function computeRawError(error, handlingStack, startClocks) {
36
+ // const stackTrace = error instanceof Error ? computeStackTrace(error) : undefined
37
+ // return extend({
38
+ // startClocks,
39
+ // source: ErrorSource.CUSTOM,
40
+ // originalError: error,
41
+ // handling: ErrorHandling.HANDLED
42
+ // }, formatUnknownError(stackTrace, error, 'Provided', handlingStack) )
43
+ // }
13
44
 
14
45
  function processError(error) {
15
46
  var resource = error.resource;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Internal context keep returning v1 format
3
+ * to not break compatibility with logs data format
4
+ */
5
+ export function startInternalContext(applicationId, session, parentContexts) {
6
+ return {
7
+ get: function get(startTime) {
8
+ var viewContext = parentContexts.findView(startTime);
9
+
10
+ if (session.isTracked() && viewContext) {
11
+ var actionContext = parentContexts.findAction(startTime);
12
+ return {
13
+ application: {
14
+ id: applicationId
15
+ },
16
+ session: {
17
+ id: session.getSessionId()
18
+ },
19
+ userAction: actionContext ? {
20
+ id: actionContext.userAction.id
21
+ } : undefined,
22
+ page: viewContext.page
23
+ };
24
+ }
25
+ }
26
+ };
27
+ }
@@ -1,4 +1,4 @@
1
- import { extend, now, throttle, UUID, isNumber } from '../../helper/utils';
1
+ import { extend, now, throttle, UUID, isNumber, getActivePage } from '../../helper/utils';
2
2
  import { trackEventCounts } from '../trackEventCounts';
3
3
  import { LifeCycleEventType } from '../../core/lifeCycle';
4
4
  import { sdk } from '../../core/sdk'; // 劫持原小程序App方法
@@ -34,6 +34,7 @@ export function rewritePage(configuration, lifeCycle, Vue) {
34
34
 
35
35
  if (methodName === 'onUnload' || methodName === 'onHide') {
36
36
  currentView.end();
37
+ currentView = undefined;
37
38
  }
38
39
  }
39
40
 
@@ -213,14 +214,4 @@ function trackSetDataTime(lifeCycle, callback) {
213
214
  return {
214
215
  stop: subscribe.unsubscribe
215
216
  };
216
- }
217
-
218
- function getActivePage() {
219
- var curPages = getCurrentPages();
220
-
221
- if (curPages.length) {
222
- return curPages[curPages.length - 1];
223
- }
224
-
225
- return {};
226
217
  }
@@ -3,9 +3,11 @@ import { startDownloadProxy } from '../core/downloadProxy';
3
3
  import { LifeCycleEventType } from '../core/lifeCycle';
4
4
  import { isObject } from '../helper/utils';
5
5
  import { isAllowedRequestUrl } from '../rumEventsCollection/resource/resourceUtils';
6
+ import { startTracer } from '../rumEventsCollection/tracing/tracer';
6
7
  var nextRequestIndex = 1;
7
8
  export function startRequestCollection(lifeCycle, configuration) {
8
- trackXhr(lifeCycle, configuration);
9
+ var tracer = startTracer(configuration);
10
+ trackXhr(lifeCycle, configuration, tracer);
9
11
  trackDownload(lifeCycle, configuration);
10
12
  }
11
13
 
@@ -28,10 +30,11 @@ function getHeaderString(header) {
28
30
  return headerStr;
29
31
  }
30
32
 
31
- export function trackXhr(lifeCycle, configuration) {
33
+ export function trackXhr(lifeCycle, configuration, tracer) {
32
34
  var xhrProxy = startXhrProxy();
33
35
  xhrProxy.beforeSend(function (context) {
34
36
  if (isAllowedRequestUrl(configuration, context.url)) {
37
+ tracer.traceXhr(context);
35
38
  context.requestIndex = getNextRequestIndex();
36
39
  lifeCycle.notify(LifeCycleEventType.REQUEST_STARTED, {
37
40
  requestIndex: context.requestIndex
@@ -40,6 +43,7 @@ export function trackXhr(lifeCycle, configuration) {
40
43
  });
41
44
  xhrProxy.onRequestComplete(function (context) {
42
45
  if (isAllowedRequestUrl(configuration, context.url)) {
46
+ tracer.clearTracingIfCancelled(context);
43
47
  lifeCycle.notify(LifeCycleEventType.REQUEST_COMPLETED, {
44
48
  duration: context.duration,
45
49
  method: context.method,
@@ -48,6 +52,8 @@ export function trackXhr(lifeCycle, configuration) {
48
52
  response: context.response,
49
53
  startTime: context.startTime,
50
54
  status: context.status,
55
+ traceId: context.traceId,
56
+ spanId: context.spanId,
51
57
  type: context.type,
52
58
  url: context.url
53
59
  });
@@ -1,6 +1,6 @@
1
1
  import { computePerformanceResourceDuration, computePerformanceResourceDetails, computeSize } from './resourceUtils';
2
2
  import { LifeCycleEventType } from '../../core/lifeCycle';
3
- import { msToNs, extend2Lev, urlParse, getQueryParamsFromUrl, replaceNumberCharByPath, jsonStringify, getStatusGroup } from '../../helper/utils';
3
+ import { msToNs, extend2Lev, urlParse, getQueryParamsFromUrl, replaceNumberCharByPath, jsonStringify, UUID, getStatusGroup } from '../../helper/utils';
4
4
  import { RumEventType } from '../../helper/enums';
5
5
  export function startResourceCollection(lifeCycle, configuration) {
6
6
  lifeCycle.subscribe(LifeCycleEventType.REQUEST_COMPLETED, function (request) {
@@ -12,9 +12,9 @@ function processRequest(request) {
12
12
  var type = request.type;
13
13
  var timing = request.performance;
14
14
  var correspondingTimingOverrides = timing ? computePerformanceEntryMetrics(timing) : undefined;
15
+ var tracingInfo = computeRequestTracingInfo(request);
15
16
  var urlObj = urlParse(request.url).getParse();
16
17
  var startTime = request.startTime;
17
- console.log(request, 'request=========');
18
18
  var resourceEvent = extend2Lev({
19
19
  date: startTime,
20
20
  resource: {
@@ -30,13 +30,31 @@ function processRequest(request) {
30
30
  urlQuery: jsonStringify(getQueryParamsFromUrl(request.url))
31
31
  },
32
32
  type: RumEventType.RESOURCE
33
- }, correspondingTimingOverrides);
33
+ }, tracingInfo, correspondingTimingOverrides);
34
34
  return {
35
35
  startTime: startTime,
36
36
  rawRumEvent: resourceEvent
37
37
  };
38
38
  }
39
39
 
40
+ function computeRequestTracingInfo(request) {
41
+ var hasBeenTraced = request.traceId && request.spanId;
42
+
43
+ if (!hasBeenTraced) {
44
+ return undefined;
45
+ }
46
+
47
+ return {
48
+ _dd: {
49
+ spanId: request.spanId,
50
+ traceId: request.traceId
51
+ },
52
+ resource: {
53
+ id: UUID()
54
+ }
55
+ };
56
+ }
57
+
40
58
  function computePerformanceEntryMetrics(timing) {
41
59
  return {
42
60
  resource: extend2Lev({}, {
@@ -0,0 +1,42 @@
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 < 19; i += 1) {
7
+ var rand = Math.floor(Math.random() * 10);
8
+ n += digits[rand];
9
+ }
10
+
11
+ return n;
12
+ }
13
+ /**
14
+ *
15
+ * @param {*} configuration 配置信息
16
+ */
17
+
18
+
19
+ export function DDtraceTracer(configuration) {
20
+ this._spanId = randomTraceId();
21
+ this._traceId = randomTraceId();
22
+ }
23
+ DDtraceTracer.prototype = {
24
+ isTracingSupported: function isTracingSupported() {
25
+ return true;
26
+ },
27
+ getSpanId: function getSpanId() {
28
+ return this._spanId;
29
+ },
30
+ getTraceId: function getTraceId() {
31
+ return this._traceId;
32
+ },
33
+ makeTracingHeaders: function makeTracingHeaders() {
34
+ return {
35
+ 'x-datadog-origin': 'rum',
36
+ // 'x-datadog-parent-id': spanId.toDecimalString(),
37
+ 'x-datadog-sampled': '1',
38
+ 'x-datadog-sampling-priority': '1',
39
+ 'x-datadog-trace-id': this.getTraceId()
40
+ };
41
+ }
42
+ };