@cloudcare/rum-uniapp 2.0.1 → 2.1.3

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 (48) hide show
  1. package/README.md +11 -8
  2. package/cjs/boot/buildEnv.js +1 -1
  3. package/cjs/boot/rum.entry.js +24 -8
  4. package/cjs/boot/rum.js +14 -2
  5. package/cjs/core/baseInfo.js +0 -6
  6. package/cjs/core/configuration.js +4 -0
  7. package/cjs/core/errorCollection.js +5 -6
  8. package/cjs/core/errorFilter.js +47 -0
  9. package/cjs/core/errorTools.js +16 -8
  10. package/cjs/core/lifeCycle.js +1 -0
  11. package/cjs/core/sdk.js +0 -1
  12. package/cjs/core/sessionManagement.js +45 -0
  13. package/cjs/core/transport.js +0 -9
  14. package/cjs/helper/enums.js +13 -7
  15. package/cjs/helper/limitModification.js +83 -0
  16. package/cjs/helper/tracekit.js +1 -1
  17. package/cjs/helper/utils.js +86 -1
  18. package/cjs/rumEventsCollection/action/actionCollection.js +19 -1
  19. package/cjs/rumEventsCollection/app/appCollection.js +0 -1
  20. package/cjs/rumEventsCollection/assembly.js +25 -15
  21. package/cjs/rumEventsCollection/error/errorCollection.js +37 -5
  22. package/cjs/rumEventsCollection/internalContext.js +34 -0
  23. package/cjs/rumEventsCollection/page/index.js +1 -0
  24. package/cjs/rumEventsCollection/resource/resourceCollection.js +0 -1
  25. package/esm/boot/buildEnv.js +1 -1
  26. package/esm/boot/rum.entry.js +24 -9
  27. package/esm/boot/rum.js +12 -2
  28. package/esm/core/baseInfo.js +0 -5
  29. package/esm/core/configuration.js +4 -0
  30. package/esm/core/errorCollection.js +5 -6
  31. package/esm/core/errorFilter.js +38 -0
  32. package/esm/core/errorTools.js +14 -8
  33. package/esm/core/lifeCycle.js +1 -0
  34. package/esm/core/sdk.js +0 -1
  35. package/esm/core/sessionManagement.js +20 -0
  36. package/esm/core/transport.js +0 -9
  37. package/esm/helper/enums.js +8 -2
  38. package/esm/helper/limitModification.js +57 -0
  39. package/esm/helper/tracekit.js +1 -1
  40. package/esm/helper/utils.js +68 -0
  41. package/esm/rumEventsCollection/action/actionCollection.js +20 -2
  42. package/esm/rumEventsCollection/app/appCollection.js +0 -1
  43. package/esm/rumEventsCollection/assembly.js +24 -16
  44. package/esm/rumEventsCollection/error/errorCollection.js +36 -5
  45. package/esm/rumEventsCollection/internalContext.js +27 -0
  46. package/esm/rumEventsCollection/page/index.js +1 -0
  47. package/esm/rumEventsCollection/resource/resourceCollection.js +0 -1
  48. package/package.json +1 -1
@@ -44,6 +44,33 @@ export var values = function values(obj) {
44
44
  });
45
45
  return results;
46
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
+ };
47
74
  export function round(num, decimals) {
48
75
  return +num.toFixed(decimals);
49
76
  }
@@ -665,4 +692,45 @@ export function getActivePage() {
665
692
  }
666
693
 
667
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;
668
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,28 +1,26 @@
1
- import { extend2Lev, withSnakeCaseKeys, performDraw, isEmptyObject } 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, getCommonContext) {
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);
19
- var savedCommonContext = data.savedGlobalContext;
17
+ var savedCommonContext = data.savedCommonContext;
20
18
  var customerContext = data.customerContext;
21
19
  var deviceContext = {
22
20
  device: baseInfo.deviceInfo
23
21
  };
24
22
 
25
- if (isTracked(configuration) && (viewContext || rawRumEvent.type === RumEventType.APP)) {
23
+ if (session.isTracked() && (viewContext || rawRumEvent.type === RumEventType.APP)) {
26
24
  var actionContext = parentContexts.findAction(startTime);
27
25
  var commonContext = savedCommonContext || getCommonContext();
28
26
  var rumContext = {
@@ -39,7 +37,7 @@ export function startRumAssembly(applicationId, configuration, lifeCycle, parent
39
37
  device: {},
40
38
  date: new Date().getTime(),
41
39
  session: {
42
- id: baseInfo.getSessionId(),
40
+ id: session.getSessionId(),
43
41
  type: SessionType.USER
44
42
  },
45
43
  user: {
@@ -49,7 +47,7 @@ export function startRumAssembly(applicationId, configuration, lifeCycle, parent
49
47
  };
50
48
  var rumEvent = extend2Lev(rumContext, deviceContext, viewContext, actionContext, rawRumEvent);
51
49
  var serverRumEvent = withSnakeCaseKeys(rumEvent);
52
- var context = extend2Lev(commonContext.context, customerContext);
50
+ var context = extend2Lev({}, commonContext.context, customerContext);
53
51
 
54
52
  if (!isEmptyObject(context)) {
55
53
  serverRumEvent.tags = context;
@@ -63,7 +61,17 @@ export function startRumAssembly(applicationId, configuration, lifeCycle, parent
63
61
  }, commonContext.user);
64
62
  }
65
63
 
66
- lifeCycle.notify(LifeCycleEventType.RUM_EVENT_COLLECTED, serverRumEvent);
64
+ if (shouldSend(serverRumEvent, errorFilter)) {
65
+ lifeCycle.notify(LifeCycleEventType.RUM_EVENT_COLLECTED, serverRumEvent);
66
+ }
67
67
  }
68
68
  });
69
+ }
70
+
71
+ function shouldSend(event, errorFilter) {
72
+ if (event.type === RumEventType.ERROR) {
73
+ return !errorFilter.isLimitReached();
74
+ }
75
+
76
+ return true;
69
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
+ }
@@ -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
 
@@ -15,7 +15,6 @@ function processRequest(request) {
15
15
  var tracingInfo = computeRequestTracingInfo(request);
16
16
  var urlObj = urlParse(request.url).getParse();
17
17
  var startTime = request.startTime;
18
- console.log(request, 'request=========');
19
18
  var resourceEvent = extend2Lev({
20
19
  date: startTime,
21
20
  resource: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudcare/rum-uniapp",
3
- "version": "2.0.1",
3
+ "version": "2.1.3",
4
4
  "main": "cjs/index.js",
5
5
  "module": "esm/index.js",
6
6
  "miniprogram": "cjs",