@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
@@ -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,14 +1,11 @@
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
9
  if (wx && typeof wx === 'object' && typeof wx.request === 'function') {
13
10
  // 微信
14
11
  tracker = wx;
@@ -33,13 +30,11 @@ function getSDK() {
33
30
  } catch (err) {
34
31
  console.warn('unsupport platform, Fail to start');
35
32
  }
36
-
37
33
  return {
38
34
  sdk,
39
35
  tracker
40
36
  };
41
37
  }
42
-
43
38
  var instance = getSDK();
44
39
  export var sdk = instance.sdk;
45
40
  export var tracker = instance.tracker;
@@ -8,13 +8,10 @@ export class sessionManagement {
8
8
  this.sessionId = UUID();
9
9
  this.isTrack = performDraw(configuration.sampleRate);
10
10
  }
11
-
12
11
  getSessionId() {
13
12
  return this.sessionId;
14
13
  }
15
-
16
14
  isTracked() {
17
15
  return this.isTrack;
18
16
  }
19
-
20
17
  }
@@ -2,21 +2,19 @@ import { findByPath, escapeRowData, isNumber, each, isString, values, extend, is
2
2
  import { sdk } from '../core/sdk';
3
3
  import { computeBytesCount } from '../helper/byteUtils';
4
4
  import { LifeCycleEventType } from '../core/lifeCycle';
5
- import { commonTags, dataMap, commonFields } from './dataMap'; // https://en.wikipedia.org/wiki/UTF-8
5
+ import { commonTags, dataMap, commonFields } from './dataMap';
6
6
 
7
+ // https://en.wikipedia.org/wiki/UTF-8
7
8
  var HAS_MULTI_BYTES_CHARACTERS = /[^\u0000-\u007F]/;
8
9
  var CUSTOM_KEYS = 'custom_keys';
9
-
10
10
  function addBatchPrecision(url) {
11
11
  if (!url) return url;
12
12
  return url + (url.indexOf('?') === -1 ? '?' : '&') + 'precision=ms';
13
13
  }
14
-
15
14
  var httpRequest = function httpRequest(endpointUrl, bytesLimit) {
16
15
  this.endpointUrl = endpointUrl;
17
16
  this.bytesLimit = bytesLimit;
18
17
  };
19
-
20
18
  httpRequest.prototype = {
21
19
  send: function send(data) {
22
20
  var url = addBatchPrecision(this.endpointUrl);
@@ -49,17 +47,13 @@ export var processedMessageByDataMap = function processedMessageByDataMap(messag
49
47
  } else {
50
48
  rowStr += key + ',';
51
49
  }
52
-
53
50
  rowData.measurement = key;
54
51
  var tagsStr = [];
55
52
  var tags = extend({}, commonTags, value.tags);
56
53
  var filterFileds = ['date', 'type', CUSTOM_KEYS]; // 已经在datamap中定义过的fields和tags
57
-
58
54
  each(tags, function (value_path, _key) {
59
55
  var _value = findByPath(message, value_path);
60
-
61
56
  filterFileds.push(_key);
62
-
63
57
  if (_value || isNumber(_value)) {
64
58
  rowData.tags[_key] = escapeJsonValue(_value);
65
59
  tagsStr.push(escapeRowData(_key) + '=' + escapeRowData(_value));
@@ -70,30 +64,22 @@ export var processedMessageByDataMap = function processedMessageByDataMap(messag
70
64
  each(fields, function (_value, _key) {
71
65
  if (isArray(_value) && _value.length === 2) {
72
66
  var type = _value[0],
73
- value_path = _value[1];
74
-
67
+ value_path = _value[1];
75
68
  var _valueData = findByPath(message, value_path);
76
-
77
69
  filterFileds.push(_key);
78
-
79
70
  if (_valueData || isNumber(_valueData)) {
80
71
  rowData.fields[_key] = _valueData; // 这里不需要转译
81
-
82
72
  fieldsStr.push(escapeRowData(_key) + '=' + escapeRowField(_valueData));
83
73
  }
84
74
  } else if (isString(_value)) {
85
75
  var _valueData = findByPath(message, _value);
86
-
87
76
  filterFileds.push(_key);
88
-
89
77
  if (_valueData || isNumber(_valueData)) {
90
78
  rowData.fields[_key] = _valueData; // 这里不需要转译
91
-
92
79
  fieldsStr.push(escapeRowData(_key) + '=' + escapeRowField(_valueData));
93
80
  }
94
81
  }
95
82
  });
96
-
97
83
  if (message.tags && isObject(message.tags) && !isEmptyObject(message.tags)) {
98
84
  // 自定义tag, 存储成field
99
85
  var _tagKeys = [];
@@ -101,42 +87,35 @@ export var processedMessageByDataMap = function processedMessageByDataMap(messag
101
87
  // 如果和之前tag重名,则舍弃
102
88
  if (filterFileds.indexOf(_key) > -1) return;
103
89
  filterFileds.push(_key);
104
-
105
90
  if (_value || isNumber(_value)) {
106
91
  _tagKeys.push(_key);
107
-
108
92
  rowData.fields[_key] = _value; // 这里不需要转译
109
-
110
93
  fieldsStr.push(escapeRowData(_key) + '=' + escapeRowField(_value));
111
94
  }
112
95
  });
113
-
114
96
  if (_tagKeys.length) {
115
97
  rowData.fields[CUSTOM_KEYS] = escapeRowField(_tagKeys);
116
98
  fieldsStr.push(escapeRowData(CUSTOM_KEYS) + '=' + escapeRowField(_tagKeys));
117
99
  }
118
100
  }
119
-
120
101
  if (tagsStr.length) {
121
102
  rowStr += tagsStr.join(',');
122
103
  }
123
-
124
104
  if (fieldsStr.length) {
125
105
  rowStr += ' ';
126
106
  rowStr += fieldsStr.join(',');
127
107
  hasFileds = true;
128
108
  }
129
-
130
109
  rowStr = rowStr + ' ' + message.date;
131
110
  rowData.time = toServerDuration(message.date); // 这里不需要转译
132
111
  }
133
112
  });
113
+
134
114
  return {
135
115
  rowStr: hasFileds ? rowStr : '',
136
116
  rowData: hasFileds ? rowData : undefined
137
117
  };
138
118
  };
139
-
140
119
  function batch(request, maxSize, bytesLimit, maxMessageSize, flushTimeout, lifeCycle) {
141
120
  this.request = request;
142
121
  this.maxSize = maxSize;
@@ -151,7 +130,6 @@ function batch(request, maxSize, bytesLimit, maxMessageSize, flushTimeout, lifeC
151
130
  this.flushOnVisibilityHidden();
152
131
  this.flushPeriodically();
153
132
  }
154
-
155
133
  batch.prototype = {
156
134
  add: function add(message) {
157
135
  this.addOrUpdate(message);
@@ -175,22 +153,17 @@ batch.prototype = {
175
153
  addOrUpdate: function addOrUpdate(message, key) {
176
154
  var process = this.process(message);
177
155
  if (!process.processedMessage || process.processedMessage === '') return;
178
-
179
156
  if (process.messageBytesSize >= this.maxMessageSize) {
180
157
  console.warn('Discarded a message whose size was bigger than the maximum allowed size' + this.maxMessageSize + 'KB.');
181
158
  return;
182
159
  }
183
-
184
160
  if (this.hasMessageFor(key)) {
185
161
  this.remove(key);
186
162
  }
187
-
188
163
  if (this.willReachedBytesLimitWith(process.messageBytesSize)) {
189
164
  this.flush();
190
165
  }
191
-
192
166
  this.push(process.processedMessage, process.messageBytesSize, key);
193
-
194
167
  if (this.isFull()) {
195
168
  this.flush();
196
169
  }
@@ -208,13 +181,11 @@ batch.prototype = {
208
181
  // \n separator at serialization
209
182
  this.bufferBytesSize += 1;
210
183
  }
211
-
212
184
  if (key !== undefined) {
213
185
  this.upsertBuffer[key] = processedMessage;
214
186
  } else {
215
187
  this.pushOnlyBuffer.push(processedMessage);
216
188
  }
217
-
218
189
  this.bufferBytesSize += messageBytesSize;
219
190
  this.bufferMessageCount += 1;
220
191
  },
@@ -224,7 +195,6 @@ batch.prototype = {
224
195
  var messageBytesSize = computeBytesCount(removedMessage);
225
196
  this.bufferBytesSize -= messageBytesSize;
226
197
  this.bufferMessageCount -= 1;
227
-
228
198
  if (this.bufferMessageCount > 0) {
229
199
  this.bufferBytesSize -= 1;
230
200
  }
@@ -241,10 +211,8 @@ batch.prototype = {
241
211
  },
242
212
  flushPeriodically: function flushPeriodically() {
243
213
  var _this = this;
244
-
245
214
  setTimeout(function () {
246
215
  _this.flush();
247
-
248
216
  _this.flushPeriodically();
249
217
  }, _this.flushTimeout);
250
218
  },
@@ -254,8 +222,6 @@ batch.prototype = {
254
222
  * With sendBeacon, requests are guaranteed to be successfully sent during document unload
255
223
  */
256
224
  // @ts-ignore this function is not always defined
257
-
258
-
259
225
  this.lifeCycle.subscribe(LifeCycleEventType.APP_HIDE, function () {
260
226
  _this.flush();
261
227
  });