@cloudcare/rum-uniapp 2.1.17 → 2.1.20

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 (105) hide show
  1. package/README.md +42 -34
  2. package/cjs/boot/buildEnv.js +3 -4
  3. package/cjs/boot/rum.entry.js +12 -37
  4. package/cjs/boot/rum.js +2 -25
  5. package/cjs/core/baseInfo.js +6 -25
  6. package/cjs/core/boundedBuffer.js +1 -7
  7. package/cjs/core/configuration.js +15 -27
  8. package/cjs/core/contextManager.js +5 -17
  9. package/cjs/core/dataMap.js +5 -10
  10. package/cjs/core/downloadProxy.js +4 -26
  11. package/cjs/core/errorCollection.js +5 -35
  12. package/cjs/core/errorFilter.js +0 -8
  13. package/cjs/core/errorTools.js +2 -10
  14. package/cjs/core/heavyCustomerDataWarning.js +3 -9
  15. package/cjs/core/lifeCycle.js +8 -18
  16. package/cjs/core/observable.js +7 -13
  17. package/cjs/core/sdk.js +4 -13
  18. package/cjs/core/sessionManagement.js +8 -17
  19. package/cjs/core/transport.js +6 -53
  20. package/cjs/core/user.js +2 -7
  21. package/cjs/core/xhrProxy.js +4 -26
  22. package/cjs/helper/byteUtils.js +6 -12
  23. package/cjs/helper/commonContext.js +2 -3
  24. package/cjs/helper/enums.js +17 -28
  25. package/cjs/helper/jsonStringify.js +5 -12
  26. package/cjs/helper/limitModification.js +3 -21
  27. package/cjs/helper/tracekit.js +33 -145
  28. package/cjs/helper/utils.js +92 -306
  29. package/cjs/index.js +0 -1
  30. package/cjs/rumEventsCollection/action/actionCollection.js +0 -9
  31. package/cjs/rumEventsCollection/action/trackActions.js +6 -28
  32. package/cjs/rumEventsCollection/app/appCollection.js +0 -6
  33. package/cjs/rumEventsCollection/app/index.js +14 -26
  34. package/cjs/rumEventsCollection/assembly.js +0 -14
  35. package/cjs/rumEventsCollection/error/errorCollection.js +1 -16
  36. package/cjs/rumEventsCollection/internalContext.js +0 -2
  37. package/cjs/rumEventsCollection/page/index.js +5 -43
  38. package/cjs/rumEventsCollection/page/viewCollection.js +0 -8
  39. package/cjs/rumEventsCollection/parentContexts.js +3 -20
  40. package/cjs/rumEventsCollection/performanceCollection.js +0 -4
  41. package/cjs/rumEventsCollection/requestCollection.js +1 -14
  42. package/cjs/rumEventsCollection/resource/resourceCollection.js +0 -11
  43. package/cjs/rumEventsCollection/resource/resourceUtils.js +50 -46
  44. package/cjs/rumEventsCollection/setDataCollection.js +0 -16
  45. package/cjs/rumEventsCollection/tracing/ddtraceTracer.js +0 -6
  46. package/cjs/rumEventsCollection/tracing/jaegerTracer.js +3 -9
  47. package/cjs/rumEventsCollection/tracing/skywalkingTracer.js +3 -10
  48. package/cjs/rumEventsCollection/tracing/tracer.js +1 -25
  49. package/cjs/rumEventsCollection/tracing/w3cTraceParentTracer.js +1 -6
  50. package/cjs/rumEventsCollection/tracing/zipkinMultiTracer.js +3 -10
  51. package/cjs/rumEventsCollection/tracing/zipkinSingleTracer.js +1 -6
  52. package/cjs/rumEventsCollection/trackEventCounts.js +0 -8
  53. package/cjs/rumEventsCollection/trackPageActiveites.js +10 -33
  54. package/cjs/rumEventsCollection/transport/batch.js +0 -9
  55. package/esm/boot/buildEnv.js +1 -1
  56. package/esm/boot/rum.entry.js +9 -21
  57. package/esm/boot/rum.js +0 -4
  58. package/esm/core/baseInfo.js +0 -11
  59. package/esm/core/boundedBuffer.js +0 -3
  60. package/esm/core/configuration.js +13 -21
  61. package/esm/core/contextManager.js +3 -8
  62. package/esm/core/dataMap.js +2 -2
  63. package/esm/core/downloadProxy.js +2 -17
  64. package/esm/core/errorCollection.js +2 -15
  65. package/esm/core/errorFilter.js +0 -5
  66. package/esm/core/errorTools.js +0 -3
  67. package/esm/core/heavyCustomerDataWarning.js +3 -3
  68. package/esm/core/lifeCycle.js +0 -5
  69. package/esm/core/observable.js +0 -3
  70. package/esm/core/sdk.js +1 -6
  71. package/esm/core/sessionManagement.js +0 -3
  72. package/esm/core/transport.js +4 -38
  73. package/esm/core/user.js +2 -4
  74. package/esm/core/xhrProxy.js +2 -17
  75. package/esm/helper/byteUtils.js +4 -7
  76. package/esm/helper/commonContext.js +2 -2
  77. package/esm/helper/jsonStringify.js +4 -7
  78. package/esm/helper/limitModification.js +1 -11
  79. package/esm/helper/tracekit.js +30 -130
  80. package/esm/helper/utils.js +27 -125
  81. package/esm/rumEventsCollection/action/actionCollection.js +0 -4
  82. package/esm/rumEventsCollection/action/trackActions.js +6 -20
  83. package/esm/rumEventsCollection/app/appCollection.js +0 -1
  84. package/esm/rumEventsCollection/app/index.js +12 -18
  85. package/esm/rumEventsCollection/assembly.js +0 -6
  86. package/esm/rumEventsCollection/error/errorCollection.js +0 -7
  87. package/esm/rumEventsCollection/internalContext.js +0 -1
  88. package/esm/rumEventsCollection/page/index.js +5 -37
  89. package/esm/rumEventsCollection/page/viewCollection.js +0 -3
  90. package/esm/rumEventsCollection/parentContexts.js +0 -10
  91. package/esm/rumEventsCollection/requestCollection.js +0 -4
  92. package/esm/rumEventsCollection/resource/resourceCollection.js +0 -5
  93. package/esm/rumEventsCollection/resource/resourceUtils.js +48 -39
  94. package/esm/rumEventsCollection/setDataCollection.js +0 -13
  95. package/esm/rumEventsCollection/tracing/ddtraceTracer.js +0 -4
  96. package/esm/rumEventsCollection/tracing/jaegerTracer.js +3 -7
  97. package/esm/rumEventsCollection/tracing/skywalkingTracer.js +5 -9
  98. package/esm/rumEventsCollection/tracing/tracer.js +0 -14
  99. package/esm/rumEventsCollection/tracing/w3cTraceParentTracer.js +1 -4
  100. package/esm/rumEventsCollection/tracing/zipkinMultiTracer.js +3 -8
  101. package/esm/rumEventsCollection/tracing/zipkinSingleTracer.js +1 -4
  102. package/esm/rumEventsCollection/trackEventCounts.js +0 -4
  103. package/esm/rumEventsCollection/trackPageActiveites.js +9 -22
  104. package/esm/rumEventsCollection/transport/batch.js +0 -5
  105. package/package.json +6 -3
@@ -1,24 +1,22 @@
1
1
  import { msToNs, toArray, extend } from '../../helper/utils';
2
2
  import { isIntakeRequest } from '../../core/configuration';
3
-
4
3
  function areInOrder() {
5
4
  var numbers = toArray(arguments);
6
-
7
5
  for (var i = 1; i < numbers.length; i += 1) {
8
6
  if (numbers[i - 1] > numbers[i]) {
9
7
  return false;
10
8
  }
11
9
  }
12
-
13
10
  return true;
14
11
  }
15
-
16
12
  export function computePerformanceResourceDuration(entry) {
17
13
  // Safari duration is always 0 on timings blocked by cross origin policies.
18
14
  if (entry.startTime < entry.responseEnd) {
19
15
  return msToNs(entry.responseEnd - entry.startTime);
20
16
  }
21
- } // interface PerformanceResourceDetails {
17
+ }
18
+
19
+ // interface PerformanceResourceDetails {
22
20
  // redirect?: PerformanceResourceDetailsElement
23
21
  // dns?: PerformanceResourceDetailsElement
24
22
  // connect?: PerformanceResourceDetailsElement
@@ -40,71 +38,88 @@ export function computePerformanceResourceDuration(entry) {
40
38
  // page_trans float 内容传输时间 responseEnd - responseStart
41
39
  // page_dom float DOM解析耗时 domInteractive - responseEnd
42
40
  // page_resource_load_time float 资源加载时间 loadEventStart - domContentLoadedEventEnd
41
+
43
42
  // navigationStart:当前浏览器窗口的前一个网页关闭,发生unload事件时的Unix毫秒时间戳。如果没有前一个网页,则等于fetchStart属性。
43
+
44
44
  // · unloadEventStart:如果前一个网页与当前网页属于同一个域名,则返回前一个网页的unload事件发生时的Unix毫秒时间戳。如果没有前一个网页,或者之前的网页跳转不是在同一个域名内,则返回值为0。
45
+
45
46
  // · unloadEventEnd:如果前一个网页与当前网页属于同一个域名,则返回前一个网页unload事件的回调函数结束时的Unix毫秒时间戳。如果没有前一个网页,或者之前的网页跳转不是在同一个域名内,则返回值为0。
47
+
46
48
  // · redirectStart:返回第一个HTTP跳转开始时的Unix毫秒时间戳。如果没有跳转,或者不是同一个域名内部的跳转,则返回值为0。
49
+
47
50
  // · redirectEnd:返回最后一个HTTP跳转结束时(即跳转回应的最后一个字节接受完成时)的Unix毫秒时间戳。如果没有跳转,或者不是同一个域名内部的跳转,则返回值为0。
51
+
48
52
  // · fetchStart:返回浏览器准备使用HTTP请求读取文档时的Unix毫秒时间戳。该事件在网页查询本地缓存之前发生。
53
+
49
54
  // · domainLookupStart:返回域名查询开始时的Unix毫秒时间戳。如果使用持久连接,或者信息是从本地缓存获取的,则返回值等同于fetchStart属性的值。
55
+
50
56
  // · domainLookupEnd:返回域名查询结束时的Unix毫秒时间戳。如果使用持久连接,或者信息是从本地缓存获取的,则返回值等同于fetchStart属性的值。
57
+
51
58
  // · connectStart:返回HTTP请求开始向服务器发送时的Unix毫秒时间戳。如果使用持久连接(persistent connection),则返回值等同于fetchStart属性的值。
59
+
52
60
  // · connectEnd:返回浏览器与服务器之间的连接建立时的Unix毫秒时间戳。如果建立的是持久连接,则返回值等同于fetchStart属性的值。连接建立指的是所有握手和认证过程全部结束。
61
+
53
62
  // · secureConnectionStart:返回浏览器与服务器开始安全链接的握手时的Unix毫秒时间戳。如果当前网页不要求安全连接,则返回0。
63
+
54
64
  // · requestStart:返回浏览器向服务器发出HTTP请求时(或开始读取本地缓存时)的Unix毫秒时间戳。
65
+
55
66
  // · responseStart:返回浏览器从服务器收到(或从本地缓存读取)第一个字节时的Unix毫秒时间戳。
67
+
56
68
  // · responseEnd:返回浏览器从服务器收到(或从本地缓存读取)最后一个字节时(如果在此之前HTTP连接已经关闭,则返回关闭时)的Unix毫秒时间戳。
69
+
57
70
  // · domLoading:返回当前网页DOM结构开始解析时(即Document.readyState属性变为“loading”、相应的readystatechange事件触发时)的Unix毫秒时间戳。
71
+
58
72
  // · domInteractive:返回当前网页DOM结构结束解析、开始加载内嵌资源时(即Document.readyState属性变为“interactive”、相应的readystatechange事件触发时)的Unix毫秒时间戳。
73
+
59
74
  // · domContentLoadedEventStart:返回当前网页DOMContentLoaded事件发生时(即DOM结构解析完毕、所有脚本开始运行时)的Unix毫秒时间戳。
75
+
60
76
  // · domContentLoadedEventEnd:返回当前网页所有需要执行的脚本执行完成时的Unix毫秒时间戳。
77
+
61
78
  // · domComplete:返回当前网页DOM结构生成时(即Document.readyState属性变为“complete”,以及相应的readystatechange事件发生时)的Unix毫秒时间戳。
79
+
62
80
  // · loadEventStart:返回当前网页load事件的回调函数开始时的Unix毫秒时间戳。如果该事件还没有发生,返回0。
63
- // · loadEventEnd:返回当前网页load事件的回调函数运行结束时的Unix毫秒时间戳。如果该事件还没有发生,返回0
64
81
 
82
+ // · loadEventEnd:返回当前网页load事件的回调函数运行结束时的Unix毫秒时间戳。如果该事件还没有发生,返回0
65
83
  export function computePerformanceResourceDetails(entry) {
66
84
  var validEntry = toValidEntry(entry);
67
-
68
85
  if (!validEntry) {
69
86
  return undefined;
70
87
  }
71
-
72
88
  var startTime = validEntry.startTime,
73
- fetchStart = validEntry.fetchStart,
74
- redirectStart = validEntry.redirectStart,
75
- redirectEnd = validEntry.redirectEnd,
76
- domainLookupStart = validEntry.domainLookupStart || validEntry.domainLookUpStart,
77
- domainLookupEnd = validEntry.domainLookupEnd || validEntry.domainLookUpEnd,
78
- connectStart = validEntry.connectStart,
79
- SSLconnectionStart = validEntry.SSLconnectionStart,
80
- SSLconnectionEnd = validEntry.SSLconnectionEnd,
81
- connectEnd = validEntry.connectEnd,
82
- requestStart = validEntry.requestStart,
83
- responseStart = validEntry.responseStart,
84
- responseEnd = validEntry.responseEnd;
89
+ fetchStart = validEntry.fetchStart,
90
+ redirectStart = validEntry.redirectStart,
91
+ redirectEnd = validEntry.redirectEnd,
92
+ domainLookupStart = validEntry.domainLookupStart || validEntry.domainLookUpStart,
93
+ domainLookupEnd = validEntry.domainLookupEnd || validEntry.domainLookUpEnd,
94
+ connectStart = validEntry.connectStart,
95
+ SSLconnectionStart = validEntry.SSLconnectionStart,
96
+ SSLconnectionEnd = validEntry.SSLconnectionEnd,
97
+ connectEnd = validEntry.connectEnd,
98
+ requestStart = validEntry.requestStart,
99
+ responseStart = validEntry.responseStart,
100
+ responseEnd = validEntry.responseEnd;
85
101
  var details = {
86
102
  firstbyte: formatTiming(startTime, domainLookupStart, responseStart),
87
103
  trans: formatTiming(startTime, responseStart, responseEnd),
88
104
  ttfb: formatTiming(startTime, requestStart, responseStart)
89
- }; // Make sure a connection occurred
90
-
105
+ };
106
+ // Make sure a connection occurred
91
107
  if (connectEnd !== fetchStart) {
92
- details.tcp = formatTiming(startTime, connectStart, connectEnd); // Make sure a secure connection occurred
108
+ details.tcp = formatTiming(startTime, connectStart, connectEnd);
93
109
 
110
+ // Make sure a secure connection occurred
94
111
  if (areInOrder(connectStart, SSLconnectionStart, SSLconnectionEnd)) {
95
112
  details.ssl = formatTiming(startTime, SSLconnectionStart, SSLconnectionEnd);
96
113
  }
97
- } // Make sure a domain lookup occurred
98
-
114
+ }
99
115
 
116
+ // Make sure a domain lookup occurred
100
117
  if (domainLookupEnd !== fetchStart) {
101
118
  details.dns = formatTiming(startTime, domainLookupStart, domainLookupEnd);
102
119
  }
103
-
104
120
  if (hasRedirection(entry)) {
105
121
  details.redirect = formatTiming(startTime, redirectStart, redirectEnd);
106
122
  }
107
-
108
123
  return details;
109
124
  }
110
125
  export function toValidEntry(entry) {
@@ -128,32 +143,29 @@ export function toValidEntry(entry) {
128
143
  if (!areInOrder(entry.startTime, entry.fetchStart, entry.domainLookupStart, entry.domainLookupEnd, entry.connectStart, entry.connectEnd, entry.requestStart, entry.responseStart, entry.responseEnd)) {
129
144
  return undefined;
130
145
  }
131
-
132
146
  if (!hasRedirection(entry)) {
133
147
  return entry;
134
148
  }
135
-
136
149
  var redirectStart = entry.redirectStart;
137
- var redirectEnd = entry.redirectEnd; // Firefox doesn't provide redirect timings on cross origin requests.
150
+ var redirectEnd = entry.redirectEnd;
151
+ // Firefox doesn't provide redirect timings on cross origin requests.
138
152
  // Provide a default for those.
139
-
140
153
  if (redirectStart < entry.startTime) {
141
154
  redirectStart = entry.startTime;
142
155
  }
143
-
144
156
  if (redirectEnd < entry.startTime) {
145
157
  redirectEnd = entry.fetchStart;
146
- } // Make sure redirect timings are in order
147
-
158
+ }
148
159
 
160
+ // Make sure redirect timings are in order
149
161
  if (!areInOrder(entry.startTime, redirectStart, redirectEnd, entry.fetchStart)) {
150
162
  return undefined;
151
163
  }
152
-
153
164
  return extend({}, entry, {
154
165
  redirectEnd: redirectEnd,
155
166
  redirectStart: redirectStart
156
- }); // return {
167
+ });
168
+ // return {
157
169
  // ...entry,
158
170
  // redirectEnd,
159
171
  // redirectStart
@@ -164,17 +176,14 @@ function hasRedirection(entry) {
164
176
  // The only time fetchStart is different than startTime is if a redirection occurred.
165
177
  return entry.fetchStart !== entry.startTime;
166
178
  }
167
-
168
179
  function formatTiming(origin, start, end) {
169
180
  return msToNs(end - start);
170
181
  }
171
-
172
182
  export function computeSize(entry) {
173
183
  // Make sure a request actually occurred
174
184
  if (entry.startTime < entry.responseStart) {
175
185
  return entry.receivedBytedCount;
176
186
  }
177
-
178
187
  return undefined;
179
188
  }
180
189
  export function isAllowedRequestUrl(configuration, url) {
@@ -1,31 +1,24 @@
1
1
  import { LifeCycleEventType } from '../core/lifeCycle';
2
2
  import { now } from '../helper/utils';
3
3
  import { tracker } from '../core/sdk';
4
-
5
4
  function resetSetData(data, callback, lifeCycle, mpInstance) {
6
5
  var pendingStartTimestamp = now();
7
-
8
6
  var _callback = function _callback() {
9
7
  lifeCycle.notify(LifeCycleEventType.PAGE_SET_DATA_UPDATE, {
10
8
  pendingStartTimestamp: pendingStartTimestamp,
11
9
  updateEndTimestamp: now()
12
10
  });
13
-
14
11
  if (typeof callback === 'function') {
15
12
  callback.call(mpInstance);
16
13
  }
17
14
  };
18
-
19
15
  return _callback;
20
16
  }
21
-
22
17
  function proxyPage(pageOptions, lifeCycle) {
23
18
  var userDefinedMethod = pageOptions['onLoad'];
24
-
25
19
  pageOptions['onLoad'] = function () {
26
20
  var mpInstance = this.$scope;
27
21
  var setData = mpInstance.setData;
28
-
29
22
  if (typeof setData === 'function') {
30
23
  try {
31
24
  // 这里暂时这么处理 只读属性 会抛出错误
@@ -42,15 +35,12 @@ function proxyPage(pageOptions, lifeCycle) {
42
35
  });
43
36
  }
44
37
  }
45
-
46
38
  return userDefinedMethod && userDefinedMethod.apply(this, arguments);
47
39
  };
48
40
  }
49
-
50
41
  export function startSetDataColloction(lifeCycle, Vue) {
51
42
  if (Vue && Vue.extend) {
52
43
  var originVueExtend = Vue.extend;
53
-
54
44
  Vue.extend = function (vueOptions) {
55
45
  proxyPage(vueOptions, lifeCycle);
56
46
  return originVueExtend.call(this, vueOptions);
@@ -58,14 +48,11 @@ export function startSetDataColloction(lifeCycle, Vue) {
58
48
  } else {
59
49
  if (!tracker) return;
60
50
  var originCreatePage = tracker.createPage;
61
-
62
51
  tracker.createPage = function (pageOptions) {
63
52
  proxyPage(pageOptions, lifeCycle);
64
53
  return originCreatePage.call(this, pageOptions);
65
54
  };
66
-
67
55
  var originCreateComponent = tracker.createComponent;
68
-
69
56
  tracker.createComponent = function (component) {
70
57
  proxyPage(component, lifeCycle);
71
58
  return originCreateComponent.call(this, component);
@@ -2,20 +2,16 @@
2
2
  function randomTraceId() {
3
3
  var digits = '0123456789abcdef';
4
4
  var n = '';
5
-
6
5
  for (var i = 0; i < 19; i += 1) {
7
6
  var rand = Math.floor(Math.random() * 10);
8
7
  n += digits[rand];
9
8
  }
10
-
11
9
  return n;
12
10
  }
13
11
  /**
14
12
  *
15
13
  * @param {*} configuration 配置信息
16
14
  */
17
-
18
-
19
15
  export function DDtraceTracer(configuration) {
20
16
  this._spanId = randomTraceId();
21
17
  this._traceId = randomTraceId();
@@ -2,30 +2,26 @@
2
2
  function randomTraceId() {
3
3
  var digits = '0123456789abcdef';
4
4
  var n = '';
5
-
6
5
  for (var i = 0; i < 16; i += 1) {
7
6
  var rand = Math.floor(Math.random() * 16);
8
7
  n += digits[rand];
9
8
  }
10
-
11
9
  return n;
12
10
  }
11
+
13
12
  /**
14
13
  *
15
14
  * @param {*} configuration 配置信息
16
15
  */
17
-
18
-
19
16
  export function JaegerTracer(configuration) {
20
- var rootSpanId = randomTraceId(); // this._traceId = randomTraceId() + rootSpanId // 默认用128bit,兼容其他配置
21
-
17
+ var rootSpanId = randomTraceId();
18
+ // this._traceId = randomTraceId() + rootSpanId // 默认用128bit,兼容其他配置
22
19
  if (configuration.traceId128Bit) {
23
20
  // 128bit生成traceid
24
21
  this._traceId = randomTraceId() + rootSpanId;
25
22
  } else {
26
23
  this._traceId = rootSpanId;
27
24
  }
28
-
29
25
  this._spanId = rootSpanId;
30
26
  }
31
27
  JaegerTracer.prototype = {
@@ -1,22 +1,20 @@
1
- import { base64Encode, urlParse, getActivePage } from '../../helper/utils'; // start SkyWalking
2
-
1
+ import { base64Encode, urlParse, getActivePage } from '../../helper/utils';
2
+ // start SkyWalking
3
3
  function uuid() {
4
4
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
5
5
  /* tslint:disable */
6
6
  var r = Math.random() * 16 | 0;
7
7
  /* tslint:disable */
8
-
9
8
  var v = c === 'x' ? r : r & 0x3 | 0x8;
10
9
  return v.toString(16);
11
10
  });
12
11
  }
12
+
13
13
  /**
14
14
  *
15
15
  * @param {*} configuration 配置信息
16
16
  * @param {*} requestUrl 请求的url
17
17
  */
18
-
19
-
20
18
  export function SkyWalkingTracer(configuration, requestUrl) {
21
19
  this._spanId = uuid();
22
20
  this._traceId = uuid();
@@ -44,15 +42,13 @@ SkyWalkingTracer.prototype = {
44
42
  var instance = String(base64Encode(this._version));
45
43
  var activePage = getActivePage();
46
44
  var endpointPage = '';
47
-
48
45
  if (activePage && activePage.route) {
49
46
  endpointPage = activePage.route;
50
47
  }
51
-
52
48
  var endpoint = String(base64Encode(endpointPage));
53
49
  var peer = String(base64Encode(this._urlParse.Host));
54
- var index = '0'; // var values = `${1}-${traceIdStr}-${segmentId}-${index}-${service}-${instance}-${endpoint}-${peer}`;
55
-
50
+ var index = '0';
51
+ // var values = `${1}-${traceIdStr}-${segmentId}-${index}-${service}-${instance}-${endpoint}-${peer}`;
56
52
  return '1-' + traceIdStr + '-' + segmentId + '-' + index + '-' + service + '-' + instance + '-' + endpoint + '-' + peer;
57
53
  } catch (err) {
58
54
  return '';
@@ -19,19 +19,16 @@ export function startTracer(configuration) {
19
19
  return injectHeadersIfTracingAllowed(configuration, context, function (tracingHeaders) {
20
20
  context.option = extend({}, context.option);
21
21
  var header = {};
22
-
23
22
  if (context.option.header) {
24
23
  each(context.option.header, function (value, key) {
25
24
  header[key] = value;
26
25
  });
27
26
  }
28
-
29
27
  context.option.header = extend(header, tracingHeaders);
30
28
  });
31
29
  }
32
30
  };
33
31
  }
34
-
35
32
  function isAllowedUrl(configuration, requestUrl) {
36
33
  var requestOrigin = getOrigin(requestUrl);
37
34
  var flag = false;
@@ -43,47 +40,36 @@ function isAllowedUrl(configuration, requestUrl) {
43
40
  });
44
41
  return flag;
45
42
  }
46
-
47
43
  export function injectHeadersIfTracingAllowed(configuration, context, inject) {
48
44
  if (!isAllowedUrl(configuration, context.url) || !configuration.traceType) {
49
45
  return;
50
46
  }
51
-
52
47
  var tracer;
53
-
54
48
  switch (configuration.traceType) {
55
49
  case TraceType.DDTRACE:
56
50
  tracer = new DDtraceTracer();
57
51
  break;
58
-
59
52
  case TraceType.SKYWALKING_V3:
60
53
  tracer = new SkyWalkingTracer(configuration, context.url);
61
54
  break;
62
-
63
55
  case TraceType.ZIPKIN_MULTI_HEADER:
64
56
  tracer = new ZipkinMultiTracer(configuration);
65
57
  break;
66
-
67
58
  case TraceType.JAEGER:
68
59
  tracer = new JaegerTracer(configuration);
69
60
  break;
70
-
71
61
  case TraceType.W3C_TRACEPARENT:
72
62
  tracer = new W3cTraceParentTracer(configuration);
73
63
  break;
74
-
75
64
  case TraceType.ZIPKIN_SINGLE_HEADER:
76
65
  tracer = new ZipkinSingleTracer(configuration);
77
66
  break;
78
-
79
67
  default:
80
68
  break;
81
69
  }
82
-
83
70
  if (!tracer || !tracer.isTracingSupported()) {
84
71
  return;
85
72
  }
86
-
87
73
  context.traceId = tracer.getTraceId();
88
74
  context.spanId = tracer.getSpanId();
89
75
  inject(tracer.makeTracingHeaders());
@@ -2,20 +2,17 @@
2
2
  function randomTraceId() {
3
3
  var digits = '0123456789abcdef';
4
4
  var n = '';
5
-
6
5
  for (var i = 0; i < 16; i += 1) {
7
6
  var rand = Math.floor(Math.random() * 16);
8
7
  n += digits[rand];
9
8
  }
10
-
11
9
  return n;
12
10
  }
11
+
13
12
  /**
14
13
  *
15
14
  * @param {*} configuration 配置信息
16
15
  */
17
-
18
-
19
16
  export function W3cTraceParentTracer(configuration) {
20
17
  var rootSpanId = randomTraceId();
21
18
  this._traceId = randomTraceId() + rootSpanId;
@@ -2,30 +2,25 @@
2
2
  function randomTraceId() {
3
3
  var digits = '0123456789abcdef';
4
4
  var n = '';
5
-
6
5
  for (var i = 0; i < 16; i += 1) {
7
6
  var rand = Math.floor(Math.random() * 16);
8
7
  n += digits[rand];
9
8
  }
10
-
11
9
  return n;
12
10
  }
11
+
13
12
  /**
14
13
  *
15
14
  * @param {*} configuration 配置信息
16
15
  */
17
-
18
-
19
16
  export function ZipkinMultiTracer(configuration) {
20
17
  var rootSpanId = randomTraceId();
21
-
22
18
  if (configuration.traceId128Bit) {
23
19
  // 128bit生成traceid
24
20
  this._traceId = randomTraceId() + rootSpanId;
25
21
  } else {
26
22
  this._traceId = rootSpanId;
27
23
  }
28
-
29
24
  this._spanId = rootSpanId;
30
25
  }
31
26
  ZipkinMultiTracer.prototype = {
@@ -43,8 +38,8 @@ ZipkinMultiTracer.prototype = {
43
38
  'X-B3-TraceId': this.getTraceId(),
44
39
  'X-B3-SpanId': this.getSpanId(),
45
40
  // 'X-B3-ParentSpanId': '',
46
- 'X-B3-Sampled': '1' // 'X-B3-Flags': '0'
47
-
41
+ 'X-B3-Sampled': '1'
42
+ // 'X-B3-Flags': '0'
48
43
  };
49
44
  }
50
45
  };
@@ -2,20 +2,17 @@
2
2
  function randomTraceId() {
3
3
  var digits = '0123456789abcdef';
4
4
  var n = '';
5
-
6
5
  for (var i = 0; i < 16; i += 1) {
7
6
  var rand = Math.floor(Math.random() * 16);
8
7
  n += digits[rand];
9
8
  }
10
-
11
9
  return n;
12
10
  }
11
+
13
12
  /**
14
13
  *
15
14
  * @param {*} configuration 配置信息
16
15
  */
17
-
18
-
19
16
  export function ZipkinSingleTracer(configuration) {
20
17
  var rootSpanId = randomTraceId();
21
18
  this._traceId = randomTraceId() + rootSpanId;
@@ -5,7 +5,6 @@ export function trackEventCounts(lifeCycle, callback) {
5
5
  if (typeof callback === 'undefined') {
6
6
  callback = noop;
7
7
  }
8
-
9
8
  var eventCounts = {
10
9
  errorCount: 0,
11
10
  resourceCount: 0,
@@ -14,18 +13,15 @@ export function trackEventCounts(lifeCycle, callback) {
14
13
  };
15
14
  var subscription = lifeCycle.subscribe(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, function (data) {
16
15
  var rawRumEvent = data.rawRumEvent;
17
-
18
16
  switch (rawRumEvent.type) {
19
17
  case RumEventType.ERROR:
20
18
  eventCounts.errorCount += 1;
21
19
  callback(eventCounts);
22
20
  break;
23
-
24
21
  case RumEventType.RESOURCE:
25
22
  eventCounts.resourceCount += 1;
26
23
  callback(eventCounts);
27
24
  break;
28
-
29
25
  case RumEventType.ACTION:
30
26
  eventCounts.userActionCount += 1;
31
27
  callback(eventCounts);
@@ -1,31 +1,28 @@
1
1
  import { each, now } from '../helper/utils';
2
2
  import { LifeCycleEventType } from '../core/lifeCycle';
3
- import { Observable } from '../core/observable'; // Delay to wait for a page activity to validate the tracking process
4
-
5
- export var PAGE_ACTIVITY_VALIDATION_DELAY = 100; // Delay to wait after a page activity to end the tracking process
6
-
7
- export var PAGE_ACTIVITY_END_DELAY = 100; // Maximum duration of the tracking process
8
-
3
+ import { Observable } from '../core/observable';
4
+ // Delay to wait for a page activity to validate the tracking process
5
+ export var PAGE_ACTIVITY_VALIDATION_DELAY = 100;
6
+ // Delay to wait after a page activity to end the tracking process
7
+ export var PAGE_ACTIVITY_END_DELAY = 100;
8
+ // Maximum duration of the tracking process
9
9
  export var PAGE_ACTIVITY_MAX_DURATION = 10000;
10
10
  export function waitIdlePageActivity(lifeCycle, completionCallback) {
11
11
  var _trackPageActivities = trackPageActivities(lifeCycle);
12
-
13
12
  var pageActivitiesObservable = _trackPageActivities.observable;
14
13
  var stopPageActivitiesTracking = _trackPageActivities.stop;
15
-
16
14
  var _waitPageActivitiesCompletion = waitPageActivitiesCompletion(pageActivitiesObservable, stopPageActivitiesTracking, completionCallback);
17
-
18
15
  var stopWaitPageActivitiesCompletion = _waitPageActivitiesCompletion.stop;
19
-
20
16
  function stop() {
21
17
  stopWaitPageActivitiesCompletion();
22
18
  stopPageActivitiesTracking();
23
19
  }
24
-
25
20
  return {
26
21
  stop: stop
27
22
  };
28
- } // Automatic action collection lifecycle overview:
23
+ }
24
+
25
+ // Automatic action collection lifecycle overview:
29
26
  // (Start new trackPageActivities)
30
27
  // .-------------------'--------------------.
31
28
  // v v
@@ -49,7 +46,6 @@ export function waitIdlePageActivity(lifeCycle, completionCallback) {
49
46
  //
50
47
  // Note: because MAX_DURATION > VALIDATION_DELAY, we are sure that if the process is still alive
51
48
  // after MAX_DURATION, it has been validated.
52
-
53
49
  export function trackPageActivities(lifeCycle) {
54
50
  var observable = new Observable();
55
51
  var subscriptions = [];
@@ -64,7 +60,6 @@ export function trackPageActivities(lifeCycle) {
64
60
  if (firstRequestIndex === undefined) {
65
61
  firstRequestIndex = startEvent.requestIndex;
66
62
  }
67
-
68
63
  pendingRequestsCount += 1;
69
64
  notifyPageActivity();
70
65
  }));
@@ -73,17 +68,14 @@ export function trackPageActivities(lifeCycle) {
73
68
  if (firstRequestIndex === undefined || request.requestIndex < firstRequestIndex) {
74
69
  return;
75
70
  }
76
-
77
71
  pendingRequestsCount -= 1;
78
72
  notifyPageActivity();
79
73
  }));
80
-
81
74
  function notifyPageActivity() {
82
75
  observable.notify({
83
76
  isBusy: pendingRequestsCount > 0
84
77
  });
85
78
  }
86
-
87
79
  return {
88
80
  observable: observable,
89
81
  stop: function stop() {
@@ -112,7 +104,6 @@ export function waitPageActivitiesCompletion(pageActivitiesObservable, stopPageA
112
104
  clearTimeout(validationTimeoutId);
113
105
  clearTimeout(idleTimeoutId);
114
106
  var lastChangeTime = now();
115
-
116
107
  if (!isBusy) {
117
108
  idleTimeoutId = setTimeout(function () {
118
109
  complete({
@@ -122,7 +113,6 @@ export function waitPageActivitiesCompletion(pageActivitiesObservable, stopPageA
122
113
  }, PAGE_ACTIVITY_END_DELAY);
123
114
  }
124
115
  });
125
-
126
116
  function stop() {
127
117
  hasCompleted = true;
128
118
  clearTimeout(validationTimeoutId);
@@ -130,16 +120,13 @@ export function waitPageActivitiesCompletion(pageActivitiesObservable, stopPageA
130
120
  clearTimeout(maxDurationTimeoutId);
131
121
  stopPageActivitiesTracking();
132
122
  }
133
-
134
123
  function complete(params) {
135
124
  if (hasCompleted) {
136
125
  return;
137
126
  }
138
-
139
127
  stop();
140
128
  completionCallback(params);
141
129
  }
142
-
143
130
  return {
144
131
  stop: stop
145
132
  };
@@ -16,21 +16,17 @@ export function startRumBatch(configuration, lifeCycle) {
16
16
  }
17
17
  };
18
18
  }
19
-
20
19
  function makeRumBatch(configuration, lifeCycle) {
21
20
  var primaryBatch = createRumBatch(configuration.datakitUrl, lifeCycle);
22
-
23
21
  function createRumBatch(endpointUrl, lifeCycle) {
24
22
  return new Batch(new HttpRequest(endpointUrl, configuration.batchBytesLimit), configuration.maxBatchSize, configuration.batchBytesLimit, configuration.maxMessageSize, configuration.flushTimeout, lifeCycle);
25
23
  }
26
-
27
24
  var stopped = false;
28
25
  return {
29
26
  add: function add(message) {
30
27
  if (stopped) {
31
28
  return;
32
29
  }
33
-
34
30
  primaryBatch.add(message);
35
31
  },
36
32
  stop: function stop() {
@@ -40,7 +36,6 @@ function makeRumBatch(configuration, lifeCycle) {
40
36
  if (stopped) {
41
37
  return;
42
38
  }
43
-
44
39
  primaryBatch.upsert(message, key);
45
40
  }
46
41
  };