@cloudcare/rum-uniapp 2.1.18 → 2.1.22

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 (107) hide show
  1. package/README.md +42 -34
  2. package/cjs/boot/buildEnv.js +3 -4
  3. package/cjs/boot/rum.entry.js +11 -36
  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 +11 -19
  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 +32 -145
  28. package/cjs/helper/utils.js +92 -306
  29. package/cjs/index.js +0 -1
  30. package/cjs/main.js +10 -0
  31. package/cjs/rumEventsCollection/action/actionCollection.js +0 -9
  32. package/cjs/rumEventsCollection/action/trackActions.js +46 -39
  33. package/cjs/rumEventsCollection/app/appCollection.js +0 -6
  34. package/cjs/rumEventsCollection/app/index.js +14 -25
  35. package/cjs/rumEventsCollection/assembly.js +0 -14
  36. package/cjs/rumEventsCollection/error/errorCollection.js +1 -16
  37. package/cjs/rumEventsCollection/internalContext.js +0 -2
  38. package/cjs/rumEventsCollection/page/index.js +19 -49
  39. package/cjs/rumEventsCollection/page/viewCollection.js +0 -8
  40. package/cjs/rumEventsCollection/parentContexts.js +3 -20
  41. package/cjs/rumEventsCollection/performanceCollection.js +0 -4
  42. package/cjs/rumEventsCollection/requestCollection.js +1 -14
  43. package/cjs/rumEventsCollection/resource/resourceCollection.js +0 -11
  44. package/cjs/rumEventsCollection/resource/resourceUtils.js +50 -46
  45. package/cjs/rumEventsCollection/setDataCollection.js +0 -16
  46. package/cjs/rumEventsCollection/tracing/ddtraceTracer.js +0 -6
  47. package/cjs/rumEventsCollection/tracing/jaegerTracer.js +3 -9
  48. package/cjs/rumEventsCollection/tracing/skywalkingTracer.js +3 -10
  49. package/cjs/rumEventsCollection/tracing/tracer.js +1 -25
  50. package/cjs/rumEventsCollection/tracing/w3cTraceParentTracer.js +1 -6
  51. package/cjs/rumEventsCollection/tracing/zipkinMultiTracer.js +3 -10
  52. package/cjs/rumEventsCollection/tracing/zipkinSingleTracer.js +1 -6
  53. package/cjs/rumEventsCollection/trackEventCounts.js +0 -8
  54. package/cjs/rumEventsCollection/trackPageActiveites.js +10 -33
  55. package/cjs/rumEventsCollection/transport/batch.js +0 -9
  56. package/esm/boot/buildEnv.js +1 -1
  57. package/esm/boot/rum.entry.js +8 -20
  58. package/esm/boot/rum.js +0 -4
  59. package/esm/core/baseInfo.js +0 -11
  60. package/esm/core/boundedBuffer.js +0 -3
  61. package/esm/core/configuration.js +13 -21
  62. package/esm/core/contextManager.js +3 -8
  63. package/esm/core/dataMap.js +2 -2
  64. package/esm/core/downloadProxy.js +2 -17
  65. package/esm/core/errorCollection.js +2 -15
  66. package/esm/core/errorFilter.js +0 -5
  67. package/esm/core/errorTools.js +0 -3
  68. package/esm/core/heavyCustomerDataWarning.js +3 -3
  69. package/esm/core/lifeCycle.js +0 -5
  70. package/esm/core/observable.js +0 -3
  71. package/esm/core/sdk.js +8 -12
  72. package/esm/core/sessionManagement.js +0 -3
  73. package/esm/core/transport.js +4 -38
  74. package/esm/core/user.js +2 -4
  75. package/esm/core/xhrProxy.js +2 -17
  76. package/esm/helper/byteUtils.js +4 -7
  77. package/esm/helper/commonContext.js +2 -2
  78. package/esm/helper/jsonStringify.js +4 -7
  79. package/esm/helper/limitModification.js +1 -11
  80. package/esm/helper/tracekit.js +29 -130
  81. package/esm/helper/utils.js +27 -125
  82. package/esm/main.js +4 -0
  83. package/esm/rumEventsCollection/action/actionCollection.js +0 -4
  84. package/esm/rumEventsCollection/action/trackActions.js +46 -31
  85. package/esm/rumEventsCollection/app/appCollection.js +0 -1
  86. package/esm/rumEventsCollection/app/index.js +12 -17
  87. package/esm/rumEventsCollection/assembly.js +0 -6
  88. package/esm/rumEventsCollection/error/errorCollection.js +0 -7
  89. package/esm/rumEventsCollection/internalContext.js +0 -1
  90. package/esm/rumEventsCollection/page/index.js +19 -43
  91. package/esm/rumEventsCollection/page/viewCollection.js +0 -3
  92. package/esm/rumEventsCollection/parentContexts.js +0 -10
  93. package/esm/rumEventsCollection/requestCollection.js +0 -4
  94. package/esm/rumEventsCollection/resource/resourceCollection.js +0 -5
  95. package/esm/rumEventsCollection/resource/resourceUtils.js +48 -39
  96. package/esm/rumEventsCollection/setDataCollection.js +0 -13
  97. package/esm/rumEventsCollection/tracing/ddtraceTracer.js +0 -4
  98. package/esm/rumEventsCollection/tracing/jaegerTracer.js +3 -7
  99. package/esm/rumEventsCollection/tracing/skywalkingTracer.js +5 -9
  100. package/esm/rumEventsCollection/tracing/tracer.js +0 -14
  101. package/esm/rumEventsCollection/tracing/w3cTraceParentTracer.js +1 -4
  102. package/esm/rumEventsCollection/tracing/zipkinMultiTracer.js +3 -8
  103. package/esm/rumEventsCollection/tracing/zipkinSingleTracer.js +1 -4
  104. package/esm/rumEventsCollection/trackEventCounts.js +0 -4
  105. package/esm/rumEventsCollection/trackPageActiveites.js +9 -22
  106. package/esm/rumEventsCollection/transport/batch.js +0 -5
  107. package/package.json +7 -4
@@ -10,50 +10,40 @@ import { sdk } from '../core/sdk';
10
10
  export var makeRum = function makeRum(startRumImpl) {
11
11
  var isAlreadyInitialized = false;
12
12
  var globalContextManager = createContextManager(CustomerDataType.GlobalContext);
13
- var userContextManager = createContextManager(CustomerDataType.User); // var user = {}
14
-
13
+ var userContextManager = createContextManager(CustomerDataType.User);
14
+ // var user = {}
15
15
  var getInternalContextStrategy = function getInternalContextStrategy() {
16
16
  return undefined;
17
17
  };
18
-
19
18
  var bufferApiCalls = new BoundedBuffer();
20
-
21
19
  var _addActionStrategy = function addActionStrategy(action, commonContext) {
22
20
  if (typeof commonContext == 'undefined') {
23
21
  commonContext = buildCommonContext(globalContextManager, userContextManager);
24
22
  }
25
-
26
23
  bufferApiCalls.add(function () {
27
24
  return _addActionStrategy(action, commonContext);
28
25
  });
29
26
  };
30
-
31
27
  var _addErrorStrategy = function addErrorStrategy(providedError, commonContext) {
32
28
  if (typeof commonContext == 'undefined') {
33
29
  commonContext = buildCommonContext(globalContextManager, userContextManager);
34
30
  }
35
-
36
31
  bufferApiCalls.add(function () {
37
32
  return _addErrorStrategy(providedError, commonContext);
38
33
  });
39
34
  };
40
-
41
35
  var rumGlobal = {
42
36
  init: function init(Vue, userConfiguration) {
43
37
  if (typeof userConfiguration === 'undefined') {
44
38
  userConfiguration = {};
45
39
  }
46
-
47
40
  if (!Vue) return;
48
-
49
41
  if (!canInitRum(userConfiguration)) {
50
42
  return;
51
43
  }
52
-
53
44
  var _startRumImpl = startRumImpl(Vue, userConfiguration, function () {
54
45
  return buildCommonContext(globalContextManager, userContextManager);
55
46
  });
56
-
57
47
  getInternalContextStrategy = _startRumImpl.getInternalContext;
58
48
  _addActionStrategy = _startRumImpl.addAction;
59
49
  _addErrorStrategy = _startRumImpl.addError;
@@ -104,33 +94,31 @@ export var makeRum = function makeRum(startRumImpl) {
104
94
  removeUser: userContextManager.clearContext
105
95
  };
106
96
  return rumGlobal;
107
-
108
97
  function canInitRum(userConfiguration) {
109
98
  if (!sdk) {
110
99
  console.error('DATAFLUX_RUM unsupport platform, Fail to start.');
111
100
  return false;
112
101
  }
113
-
114
102
  if (isAlreadyInitialized) {
115
103
  console.error('DATAFLUX_RUM is already initialized.');
116
104
  return false;
117
105
  }
118
-
119
106
  if (!userConfiguration.applicationId) {
120
107
  console.error('Application ID is not configured, no RUM data will be collected.');
121
108
  return false;
122
109
  }
123
-
124
- if (!userConfiguration.datakitOrigin) {
125
- console.error('datakitOrigin is not configured, no RUM data will be collected.');
110
+ if (!userConfiguration.site && !userConfiguration.datakitOrigin && !userConfiguration.datakitUrl) {
111
+ console.error('datakitOrigin or site is not configured, no RUM data will be collected.');
112
+ return false;
113
+ }
114
+ if (userConfiguration.site && !userConfiguration.clientToken) {
115
+ console.error('clientToken is not configured, no RUM data will be collected.');
126
116
  return false;
127
117
  }
128
-
129
118
  if (userConfiguration.sampleRate !== undefined && !isPercentage(userConfiguration.sampleRate)) {
130
119
  console.error('Sample Rate should be a number between 0 and 100');
131
120
  return false;
132
121
  }
133
-
134
122
  return true;
135
123
  }
136
124
  };
package/esm/boot/rum.js CHANGED
@@ -24,15 +24,11 @@ export var startRum = function startRum(Vue, userConfiguration, getCommonContext
24
24
  startAppCollection(lifeCycle, configuration);
25
25
  startResourceCollection(lifeCycle, configuration);
26
26
  startViewCollection(lifeCycle, configuration, Vue);
27
-
28
27
  var _startErrorCollection = startErrorCollection(lifeCycle, configuration);
29
-
30
28
  startRequestCollection(lifeCycle, configuration);
31
29
  startPagePerformanceObservable(lifeCycle, configuration);
32
30
  startSetDataColloction(lifeCycle, Vue);
33
-
34
31
  var _startActionCollection = startActionCollection(lifeCycle, configuration, Vue);
35
-
36
32
  var internalContext = startInternalContext(userConfiguration.applicationId, session, parentContexts);
37
33
  return {
38
34
  addAction: _startActionCollection.addAction,
@@ -1,25 +1,21 @@
1
1
  import { sdk } from '../core/sdk';
2
2
  import { UUID } from '../helper/utils';
3
3
  import { CLIENT_ID_TOKEN } from '../helper/enums';
4
-
5
4
  class BaseInfo {
6
5
  constructor() {
7
6
  this.getDeviceInfo();
8
7
  this.getNetWork();
9
8
  }
10
-
11
9
  getDeviceInfo() {
12
10
  try {
13
11
  var deviceInfo = sdk.getSystemInfoSync();
14
12
  var osInfo = deviceInfo.system.split(' ');
15
13
  var osVersion = '';
16
-
17
14
  if (osInfo.length > 1) {
18
15
  osVersion = osInfo[1];
19
16
  } else {
20
17
  osVersion = osInfo[0] || '';
21
18
  }
22
-
23
19
  var osVersionMajor = osVersion && osVersion.split('.').length && osVersion.split('.')[0];
24
20
  this.deviceInfo = {
25
21
  screenSize: "".concat(deviceInfo.screenWidth, "*").concat(deviceInfo.screenHeight, " "),
@@ -39,18 +35,14 @@ class BaseInfo {
39
35
  this.deviceInfo = {};
40
36
  }
41
37
  }
42
-
43
38
  getClientID() {
44
39
  var clienetId = sdk.getStorageSync(CLIENT_ID_TOKEN);
45
-
46
40
  if (!clienetId) {
47
41
  clienetId = UUID();
48
42
  sdk.setStorageSync(CLIENT_ID_TOKEN, clienetId);
49
43
  }
50
-
51
44
  return clienetId;
52
45
  }
53
-
54
46
  getNetWork() {
55
47
  sdk.getNetworkType({
56
48
  success: e => {
@@ -61,7 +53,6 @@ class BaseInfo {
61
53
  this.deviceInfo.network = e.networkType ? e.networkType : 'unknown';
62
54
  });
63
55
  }
64
-
65
56
  getLaunchOptions() {
66
57
  if (sdk.getLaunchOptionsSync) {
67
58
  var res = sdk.getLaunchOptionsSync();
@@ -73,7 +64,5 @@ class BaseInfo {
73
64
  return {};
74
65
  }
75
66
  }
76
-
77
67
  }
78
-
79
68
  export default new BaseInfo();
@@ -1,14 +1,11 @@
1
1
  import { each } from '../helper/utils';
2
2
  var BUFFER_LIMIT = 500;
3
-
4
3
  var _BoundedBuffer = function _BoundedBuffer() {
5
4
  this.buffer = [];
6
5
  };
7
-
8
6
  _BoundedBuffer.prototype = {
9
7
  add: function add(callback) {
10
8
  var length = this.buffer.push(callback);
11
-
12
9
  if (length > BUFFER_LIMIT) {
13
10
  this.buffer.splice(0, 1);
14
11
  }
@@ -5,20 +5,17 @@ export var DEFAULT_CONFIGURATION = {
5
5
  sampleRate: 100,
6
6
  flushTimeout: 30 * ONE_SECOND,
7
7
  maxErrorsByMinute: 3000,
8
-
9
8
  /**
10
9
  * Logs intake limit
11
10
  */
12
11
  maxBatchSize: 50,
13
12
  maxMessageSize: 256 * ONE_KILO_BYTE,
14
-
15
13
  /**
16
14
  * beacon payload max queue size implementation is 64kb
17
15
  * ensure that we leave room for logs, rum and potential other users
18
16
  */
19
17
  batchBytesLimit: 16 * ONE_KILO_BYTE,
20
18
  datakitUrl: '',
21
-
22
19
  /**
23
20
  * arbitrary value, byte precision not needed
24
21
  */
@@ -32,18 +29,24 @@ export var DEFAULT_CONFIGURATION = {
32
29
  isIntakeUrl: function isIntakeUrl(url) {
33
30
  return false;
34
31
  } // 自定义方法根据请求资源 url 判断是否需要采集对应资源数据,默认都采集。 返回:false 表示要采集,true 表示不需要采集
35
-
36
32
  };
37
33
 
38
34
  function trim(str) {
39
35
  return str.replace(TRIM_REGIX, '');
40
36
  }
41
-
42
- function getDatakitUrlUrl(url) {
43
- if (url && url.lastIndexOf('/') === url.length - 1) return trim(url) + 'v1/write/rum';
44
- return trim(url) + '/v1/write/rum';
37
+ function getDatakitEndPoint(configuration) {
38
+ var url = configuration.datakitOrigin || configuration.datakitUrl || configuration.site;
39
+ var endpoint = url;
40
+ if (url && url.lastIndexOf('/') === url.length - 1) {
41
+ endpoint = trim(url) + 'v1/write/rum';
42
+ } else {
43
+ endpoint = trim(url) + '/v1/write/rum';
44
+ }
45
+ if (configuration.site && configuration.clientToken) {
46
+ endpoint = endpoint + '?token=' + configuration.clientToken + '&to_headless=true';
47
+ }
48
+ return endpoint;
45
49
  }
46
-
47
50
  export function commonInit(userConfiguration, buildEnv) {
48
51
  var transportConfiguration = {
49
52
  applicationId: userConfiguration.applicationId,
@@ -52,52 +55,41 @@ export function commonInit(userConfiguration, buildEnv) {
52
55
  service: userConfiguration.service || 'miniapp',
53
56
  sdkVersion: buildEnv.sdkVersion,
54
57
  sdkName: buildEnv.sdkName,
55
- datakitUrl: getDatakitUrlUrl(userConfiguration.datakitUrl || userConfiguration.datakitOrigin),
58
+ datakitUrl: getDatakitEndPoint(userConfiguration),
56
59
  tags: userConfiguration.tags || []
57
60
  };
58
-
59
61
  if ('trackInteractions' in userConfiguration) {
60
62
  transportConfiguration.trackInteractions = !!userConfiguration.trackInteractions;
61
63
  }
62
-
63
64
  if ('allowedTracingOrigins' in userConfiguration) {
64
65
  transportConfiguration.allowedTracingOrigins = userConfiguration.allowedTracingOrigins;
65
66
  }
66
-
67
67
  if ('traceId128Bit' in userConfiguration) {
68
68
  transportConfiguration.traceId128Bit = !!userConfiguration.traceId128Bit;
69
69
  }
70
-
71
70
  if ('traceType' in userConfiguration && hasTraceType(userConfiguration.traceType)) {
72
71
  transportConfiguration.traceType = userConfiguration.traceType;
73
72
  }
74
-
75
73
  if ('sampleRate' in userConfiguration) {
76
74
  transportConfiguration.sampleRate = userConfiguration.sampleRate;
77
75
  }
78
-
79
76
  if ('isVue2' in userConfiguration) {
80
77
  transportConfiguration.isVue2 = userConfiguration.isVue2;
81
78
  }
82
-
83
79
  if ('isIntakeUrl' in userConfiguration && isFunction(userConfiguration.isIntakeUrl) && isBoolean(userConfiguration.isIntakeUrl())) {
84
80
  transportConfiguration.isIntakeUrl = userConfiguration.isIntakeUrl;
85
81
  }
86
-
87
82
  return extend2Lev(DEFAULT_CONFIGURATION, transportConfiguration);
88
83
  }
89
-
90
84
  function hasTraceType(traceType) {
91
85
  if (traceType && values(TraceType).indexOf(traceType) > -1) return true;
92
86
  return false;
93
87
  }
94
-
95
88
  var haveSameOrigin = function haveSameOrigin(url1, url2) {
96
89
  var parseUrl1 = urlParse(url1).getParse();
97
90
  var parseUrl2 = urlParse(url2).getParse();
98
91
  return parseUrl1.Origin === parseUrl2.Origin;
99
92
  };
100
-
101
93
  export function isIntakeRequest(url, configuration) {
102
94
  // return haveSameOrigin(url, configuration.datakitUrl)
103
95
  return url.indexOf(configuration.datakitUrl) === 0 || configuration.isIntakeUrl(url);
@@ -7,15 +7,14 @@ export function createContextManager(customerDataType, computeBytesCountImpl) {
7
7
  if (typeof computeBytesCountImpl === 'undefined') {
8
8
  computeBytesCountImpl = computeBytesCount;
9
9
  }
10
-
11
10
  var context = {};
12
11
  var bytesCountCache;
13
- var alreadyWarned = false; // Throttle the bytes computation to minimize the impact on performance.
14
- // Especially useful if the user call context APIs synchronously multiple times in a row
12
+ var alreadyWarned = false;
15
13
 
14
+ // Throttle the bytes computation to minimize the impact on performance.
15
+ // Especially useful if the user call context APIs synchronously multiple times in a row
16
16
  var computeBytesCountThrottled = throttle(function (context) {
17
17
  bytesCountCache = computeBytesCountImpl(jsonStringify(context));
18
-
19
18
  if (!alreadyWarned) {
20
19
  alreadyWarned = warnIfCustomerDataLimitReached(bytesCountCache, customerDataType);
21
20
  }
@@ -24,24 +23,20 @@ export function createContextManager(customerDataType, computeBytesCountImpl) {
24
23
  getBytesCount: function getBytesCount() {
25
24
  return bytesCountCache;
26
25
  },
27
-
28
26
  /** @deprecated use getContext instead */
29
27
  get: function get() {
30
28
  return context;
31
29
  },
32
-
33
30
  /** @deprecated use setContextProperty instead */
34
31
  add: function add(key, value) {
35
32
  context[key] = value;
36
33
  computeBytesCountThrottled(context);
37
34
  },
38
-
39
35
  /** @deprecated renamed to removeContextProperty */
40
36
  remove: function remove(key) {
41
37
  delete context[key];
42
38
  computeBytesCountThrottled(context);
43
39
  },
44
-
45
40
  /** @deprecated use setContext instead */
46
41
  set: function set(newContext) {
47
42
  context = newContext;
@@ -1,5 +1,5 @@
1
- import { RumEventType } from '../helper/enums'; // 需要用双引号将字符串类型的field value括起来, 这里有数组标示[string, path]
2
-
1
+ import { RumEventType } from '../helper/enums';
2
+ // 需要用双引号将字符串类型的field value括起来, 这里有数组标示[string, path]
3
3
  export var commonTags = {
4
4
  sdk_name: '_dd.sdk_name',
5
5
  sdk_version: '_dd.sdk_version',
@@ -17,7 +17,6 @@ export function startDownloadProxy(userConfiguration) {
17
17
  }
18
18
  };
19
19
  }
20
-
21
20
  return downloadProxySingleton;
22
21
  }
23
22
  export function resetDownloadProxy() {
@@ -28,13 +27,10 @@ export function resetDownloadProxy() {
28
27
  sdk.downloadFile = originalDownloadRequest;
29
28
  }
30
29
  }
31
-
32
30
  function proxyDownload(userConfiguration) {
33
31
  originalDownloadRequest = sdk.downloadFile;
34
-
35
32
  sdk.downloadFile = function () {
36
33
  var _this = this;
37
-
38
34
  var dataflux_xhr = {
39
35
  method: 'GET',
40
36
  startTime: 0,
@@ -44,36 +40,28 @@ function proxyDownload(userConfiguration) {
44
40
  };
45
41
  dataflux_xhr.startTime = now();
46
42
  var originalSuccess = arguments[0].success;
47
-
48
43
  if (typeof originalSuccess === 'function') {
49
44
  arguments[0].success = function () {
50
45
  reportXhr(arguments[0]);
51
-
52
46
  if (originalSuccess) {
53
47
  originalSuccess.apply(_this, arguments);
54
48
  }
55
49
  };
56
50
  }
57
-
58
51
  var originalFail = arguments[0].fail;
59
-
60
52
  if (typeof originalFail === 'function') {
61
53
  arguments[0].fail = function () {
62
54
  reportXhr(arguments[0]);
63
-
64
55
  if (originalFail) {
65
56
  originalFail.apply(_this, arguments);
66
57
  }
67
58
  };
68
59
  }
69
-
70
60
  var hasBeenReported = false;
71
-
72
61
  var reportXhr = function reportXhr(res) {
73
62
  if (hasBeenReported) {
74
63
  return;
75
64
  }
76
-
77
65
  hasBeenReported = true;
78
66
  dataflux_xhr.duration = now() - dataflux_xhr.startTime;
79
67
  dataflux_xhr.response = JSON.stringify({
@@ -87,16 +75,14 @@ function proxyDownload(userConfiguration) {
87
75
  callback(dataflux_xhr);
88
76
  });
89
77
  };
90
-
91
78
  beforeSendCallbacks.forEach(function (callback) {
92
79
  callback(dataflux_xhr);
93
80
  });
94
- var result = originalDownloadRequest.apply(this, arguments); // 判断结果是否为promise
95
-
81
+ var result = originalDownloadRequest.apply(this, arguments);
82
+ // 判断结果是否为promise
96
83
  var isPromise = function isPromise(obj) {
97
84
  return !!obj && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function";
98
85
  };
99
-
100
86
  if (isPromise(result) && userConfiguration.isVue2) {
101
87
  // vue2 版本,success, fail 都在then返回
102
88
  return result.then(function (res) {
@@ -105,7 +91,6 @@ function proxyDownload(userConfiguration) {
105
91
  } else {
106
92
  reportXhr(res[1]);
107
93
  }
108
-
109
94
  return res;
110
95
  });
111
96
  } else if (isPromise(result) && !userConfiguration.isVue2) {
@@ -9,7 +9,6 @@ import { resetDownloadProxy, startDownloadProxy } from './downloadProxy';
9
9
  var originalConsoleError;
10
10
  export function startConsoleTracking(errorObservable) {
11
11
  originalConsoleError = console.error;
12
-
13
12
  console.error = function () {
14
13
  originalConsoleError.apply(console, arguments);
15
14
  var args = toArray(arguments);
@@ -27,19 +26,15 @@ export function startConsoleTracking(errorObservable) {
27
26
  export function stopConsoleTracking() {
28
27
  console.error = originalConsoleError;
29
28
  }
30
-
31
29
  function formatConsoleParameters(param) {
32
30
  if (typeof param === 'string') {
33
31
  return param;
34
32
  }
35
-
36
33
  if (param instanceof Error) {
37
34
  return toStackTraceString(computeStackTrace(param));
38
35
  }
39
-
40
36
  return JSON.stringify(param, undefined, 2);
41
37
  }
42
-
43
38
  export function filterErrors(configuration, errorObservable) {
44
39
  var errorCount = 0;
45
40
  var filteredErrorObservable = new Observable();
@@ -73,7 +68,6 @@ export function startRuntimeErrorTracking(errorObservable) {
73
68
  startTime: now()
74
69
  });
75
70
  };
76
-
77
71
  report.subscribe(traceKitReportHandler);
78
72
  }
79
73
  export function stopRuntimeErrorTracking() {
@@ -85,7 +79,8 @@ export function startAutomaticErrorCollection(configuration) {
85
79
  errorObservable = new Observable();
86
80
  trackNetworkError(configuration, errorObservable);
87
81
  startConsoleTracking(errorObservable);
88
- startRuntimeErrorTracking(errorObservable); // filteredErrorsObservable = filterErrors(configuration, errorObservable)
82
+ startRuntimeErrorTracking(errorObservable);
83
+ // filteredErrorsObservable = filterErrors(configuration, errorObservable)
89
84
  }
90
85
 
91
86
  return errorObservable;
@@ -97,7 +92,6 @@ export function trackNetworkError(configuration, errorObservable) {
97
92
  startDownloadProxy(configuration).onRequestComplete(function (context) {
98
93
  return handleCompleteRequest(context.type, context);
99
94
  });
100
-
101
95
  function handleCompleteRequest(type, request) {
102
96
  if (!isIntakeRequest(request.url, configuration) && (isRejected(request) || isServerError(request))) {
103
97
  errorObservable.notify({
@@ -116,7 +110,6 @@ export function trackNetworkError(configuration, errorObservable) {
116
110
  });
117
111
  }
118
112
  }
119
-
120
113
  return {
121
114
  stop: function stop() {
122
115
  resetXhrProxy();
@@ -124,27 +117,21 @@ export function trackNetworkError(configuration, errorObservable) {
124
117
  }
125
118
  };
126
119
  }
127
-
128
120
  function isRejected(request) {
129
121
  return request.status === 0 && request.responseType !== 'opaque';
130
122
  }
131
-
132
123
  function isServerError(request) {
133
124
  return request.status >= 500;
134
125
  }
135
-
136
126
  function truncateResponse(response, configuration) {
137
127
  if (response && response.length > configuration.requestErrorResponseLengthLimit) {
138
128
  return response.substring(0, configuration.requestErrorResponseLengthLimit) + '...';
139
129
  }
140
-
141
130
  return response;
142
131
  }
143
-
144
132
  function format(type) {
145
133
  if (RequestType.XHR === type) {
146
134
  return 'XHR';
147
135
  }
148
-
149
136
  return RequestType.DOWNLOAD;
150
137
  }
@@ -10,17 +10,13 @@ export function createErrorFilter(configuration, onLimitReached) {
10
10
  errorCount = 0;
11
11
  }, ONE_MINUTE);
12
12
  }
13
-
14
13
  errorCount += 1;
15
-
16
14
  if (errorCount <= configuration.maxErrorsByMinute || allowNextError) {
17
15
  allowNextError = false;
18
16
  return false;
19
17
  }
20
-
21
18
  if (errorCount === configuration.maxErrorsByMinute + 1) {
22
19
  allowNextError = true;
23
-
24
20
  try {
25
21
  onLimitReached({
26
22
  message: "Reached max number of errors by minute: ".concat(configuration.maxErrorsByMinute),
@@ -31,7 +27,6 @@ export function createErrorFilter(configuration, onLimitReached) {
31
27
  allowNextError = false;
32
28
  }
33
29
  }
34
-
35
30
  return true;
36
31
  }
37
32
  };
@@ -15,7 +15,6 @@ export function formatUnknownError(stackTrace, errorObject, nonErrorPrefix) {
15
15
  type: stackTrace && stackTrace.name
16
16
  };
17
17
  }
18
-
19
18
  return {
20
19
  message: stackTrace.message || 'Empty message',
21
20
  stack: toStackTraceString(stackTrace),
@@ -24,7 +23,6 @@ export function formatUnknownError(stackTrace, errorObject, nonErrorPrefix) {
24
23
  }
25
24
  export function toStackTraceString(stack) {
26
25
  var result = stack.name || 'Error' + ': ' + stack.message;
27
-
28
26
  if (isArray(stack.stack)) {
29
27
  stack.stack.forEach(function (frame) {
30
28
  var func = frame.func === '?' ? '<anonymous>' : frame.func;
@@ -34,6 +32,5 @@ export function toStackTraceString(stack) {
34
32
  result += '\n at ' + func + args + ' @ ' + frame.url + line + column;
35
33
  });
36
34
  }
37
-
38
35
  return result;
39
36
  }
@@ -1,7 +1,8 @@
1
- import { ONE_KIBI_BYTE } from '../helper/byteUtils'; // RUM and logs batch bytes limit is 16KB
1
+ import { ONE_KIBI_BYTE } from '../helper/byteUtils';
2
+
3
+ // RUM and logs batch bytes limit is 16KB
2
4
  // ensure that we leave room for other event attributes and maintain a decent amount of event per batch
3
5
  // (3KB (customer data) + 1KB (other attributes)) * 4 (events per batch) = 16KB
4
-
5
6
  export var CUSTOMER_DATA_BYTES_LIMIT = 3 * ONE_KIBI_BYTE;
6
7
  export var CustomerDataType = {
7
8
  FeatureFlag: 'feature flag evaluation',
@@ -14,6 +15,5 @@ export function warnIfCustomerDataLimitReached(bytesCount, customerDataType) {
14
15
  console.warn('The ' + customerDataType + 'data is over ' + CUSTOMER_DATA_BYTES_LIMIT / ONE_KIBI_BYTE + " KiB. On low connectivity, the SDK has the potential to exhaust the user's upload bandwidth.");
15
16
  return true;
16
17
  }
17
-
18
18
  return false;
19
19
  }
@@ -2,20 +2,16 @@ export class LifeCycle {
2
2
  constructor() {
3
3
  this.callbacks = {};
4
4
  }
5
-
6
5
  notify(eventType, data) {
7
6
  var eventCallbacks = this.callbacks[eventType];
8
-
9
7
  if (eventCallbacks) {
10
8
  eventCallbacks.forEach(callback => callback(data));
11
9
  }
12
10
  }
13
-
14
11
  subscribe(eventType, callback) {
15
12
  if (!this.callbacks[eventType]) {
16
13
  this.callbacks[eventType] = [];
17
14
  }
18
-
19
15
  this.callbacks[eventType].push(callback);
20
16
  return {
21
17
  unsubscribe: () => {
@@ -23,7 +19,6 @@ export class LifeCycle {
23
19
  }
24
20
  };
25
21
  }
26
-
27
22
  }
28
23
  export var LifeCycleEventType = {
29
24
  PERFORMANCE_ENTRY_COLLECTED: 'PERFORMANCE_ENTRY_COLLECTED',
@@ -2,15 +2,12 @@ export class Observable {
2
2
  constructor() {
3
3
  this.observers = [];
4
4
  }
5
-
6
5
  subscribe(f) {
7
6
  this.observers.push(f);
8
7
  }
9
-
10
8
  notify(data) {
11
9
  this.observers.forEach(function (observer) {
12
10
  observer(data);
13
11
  });
14
12
  }
15
-
16
13
  }
package/esm/core/sdk.js CHANGED
@@ -1,45 +1,41 @@
1
1
  import { deepMixObject } from '../helper/utils';
2
-
3
2
  function getSDK() {
4
3
  var sdk = null,
5
- tracker = '';
6
-
4
+ tracker = '';
7
5
  try {
8
6
  if (uni && typeof uni === 'object' && typeof uni.request === 'function') {
9
7
  sdk = uni;
10
8
  }
11
-
12
- if (wx && typeof wx === 'object' && typeof wx.request === 'function') {
9
+ if (typeof wx === 'object' && typeof wx.request === 'function') {
13
10
  // 微信
14
11
  tracker = wx;
15
- } else if (my && typeof my === 'object' && typeof my.request === 'function') {
12
+ } else if (typeof my === 'object' && typeof my.request === 'function') {
16
13
  // 支付宝
17
14
  tracker = my;
18
- } else if (tt && typeof tt === 'object' && typeof tt.request === 'function') {
15
+ } else if (typeof tt === 'object' && typeof tt.request === 'function') {
19
16
  // 头条
20
17
  tracker = tt;
21
- } else if (dd && typeof dd === 'object' && typeof dd.request === 'function') {
18
+ } else if (typeof dd === 'object' && typeof dd.request === 'function') {
22
19
  // dingding
23
20
  tracker = dd;
24
- } else if (qq && typeof qq === 'object' && typeof qq.request === 'function') {
21
+ } else if (typeof qq === 'object' && typeof qq.request === 'function') {
25
22
  // QQ 小程序、QQ 小游戏
26
23
  tracker = qq;
27
- } else if (swan && typeof swan === 'object' && typeof swan.request === 'function') {
24
+ } else if (typeof swan === 'object' && typeof swan.request === 'function') {
28
25
  // 百度小程序
29
26
  tracker = swan;
30
27
  } else {
31
28
  tracker = uni;
32
29
  }
30
+ // tracker = uni
33
31
  } catch (err) {
34
32
  console.warn('unsupport platform, Fail to start');
35
33
  }
36
-
37
34
  return {
38
35
  sdk,
39
36
  tracker
40
37
  };
41
38
  }
42
-
43
39
  var instance = getSDK();
44
40
  export var sdk = instance.sdk;
45
41
  export var tracker = instance.tracker;