@cloudcare/browser-rum 2.1.5 → 2.2.0

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 (135) hide show
  1. package/README.md +1 -2
  2. package/bundle/dataflux-rum.js +1 -1
  3. package/cjs/boot/buildEnv.js +1 -1
  4. package/cjs/boot/rum.js +57 -48
  5. package/cjs/boot/rumPublicApi.js +169 -134
  6. package/cjs/domain/assembly.js +58 -44
  7. package/cjs/domain/configuration.js +67 -0
  8. package/cjs/domain/contexts/internalContext.js +45 -0
  9. package/cjs/domain/contexts/urlContexts.js +68 -0
  10. package/cjs/domain/contexts/viewContexts.js +43 -0
  11. package/cjs/domain/domMutationCollection.js +44 -31
  12. package/cjs/domain/{rumEventsCollection/view/trackLocationChanges.js → locationChangeObservable.js} +25 -25
  13. package/cjs/domain/performanceCollection.js +55 -24
  14. package/cjs/domain/requestCollection.js +117 -0
  15. package/cjs/domain/rumEventsCollection/actions/actionCollection.js +22 -4
  16. package/cjs/domain/rumEventsCollection/actions/clickChain.js +82 -0
  17. package/cjs/domain/rumEventsCollection/actions/computeFrustration.js +78 -0
  18. package/cjs/domain/rumEventsCollection/actions/getActionNameFromElement.js +60 -47
  19. package/cjs/domain/rumEventsCollection/actions/getSelectorsFromElement.js +163 -0
  20. package/cjs/domain/rumEventsCollection/actions/listenActionEvents.js +74 -0
  21. package/cjs/domain/rumEventsCollection/actions/trackClickActions.js +263 -0
  22. package/cjs/domain/rumEventsCollection/error/errorCollection.js +33 -53
  23. package/cjs/domain/rumEventsCollection/error/trackConsoleError.js +26 -0
  24. package/cjs/domain/rumEventsCollection/error/trackReportError.js +26 -0
  25. package/cjs/domain/rumEventsCollection/longTask/longTaskCollection.js +46 -17
  26. package/cjs/domain/rumEventsCollection/resource/resourceCollection.js +49 -9
  27. package/cjs/domain/rumEventsCollection/view/trackFirstHidden.js +7 -5
  28. package/cjs/domain/rumEventsCollection/view/trackInitialViewTimings.js +61 -24
  29. package/cjs/domain/rumEventsCollection/view/trackViewMetrics.js +91 -51
  30. package/cjs/domain/rumEventsCollection/view/trackViews.js +119 -86
  31. package/cjs/domain/rumEventsCollection/view/viewCollection.js +41 -31
  32. package/cjs/domain/rumSessionManager.js +95 -0
  33. package/cjs/domain/tracing/tracer.js +9 -10
  34. package/cjs/domain/trackEventCounts.js +9 -6
  35. package/cjs/domain/usr/index.js +30 -0
  36. package/cjs/domain/waitPageActivityEnd.js +163 -0
  37. package/cjs/transport/startRumBatch.js +38 -0
  38. package/esm/boot/buildEnv.js +1 -1
  39. package/esm/boot/rum.js +55 -48
  40. package/esm/boot/rumPublicApi.js +167 -135
  41. package/esm/domain/assembly.js +58 -44
  42. package/esm/domain/configuration.js +53 -0
  43. package/esm/domain/contexts/internalContext.js +38 -0
  44. package/esm/domain/contexts/urlContexts.js +58 -0
  45. package/esm/domain/contexts/viewContexts.js +32 -0
  46. package/esm/domain/domMutationCollection.js +43 -33
  47. package/esm/domain/{rumEventsCollection/view/trackLocationChanges.js → locationChangeObservable.js} +26 -24
  48. package/esm/domain/performanceCollection.js +56 -26
  49. package/esm/domain/requestCollection.js +102 -0
  50. package/esm/domain/rumEventsCollection/actions/actionCollection.js +23 -5
  51. package/esm/domain/rumEventsCollection/actions/clickChain.js +69 -0
  52. package/esm/domain/rumEventsCollection/actions/computeFrustration.js +64 -0
  53. package/esm/domain/rumEventsCollection/actions/getActionNameFromElement.js +60 -47
  54. package/esm/domain/rumEventsCollection/actions/getSelectorsFromElement.js +139 -0
  55. package/esm/domain/rumEventsCollection/actions/listenActionEvents.js +66 -0
  56. package/esm/domain/rumEventsCollection/actions/trackClickActions.js +244 -0
  57. package/esm/domain/rumEventsCollection/error/errorCollection.js +32 -54
  58. package/esm/domain/rumEventsCollection/error/trackConsoleError.js +18 -0
  59. package/esm/domain/rumEventsCollection/error/trackReportError.js +18 -0
  60. package/esm/domain/rumEventsCollection/longTask/longTaskCollection.js +30 -18
  61. package/esm/domain/rumEventsCollection/resource/resourceCollection.js +31 -9
  62. package/esm/domain/rumEventsCollection/view/trackFirstHidden.js +8 -6
  63. package/esm/domain/rumEventsCollection/view/trackInitialViewTimings.js +43 -26
  64. package/esm/domain/rumEventsCollection/view/trackViewMetrics.js +75 -51
  65. package/esm/domain/rumEventsCollection/view/trackViews.js +120 -85
  66. package/esm/domain/rumEventsCollection/view/viewCollection.js +42 -32
  67. package/esm/domain/rumSessionManager.js +80 -0
  68. package/esm/domain/tracing/skywalkingTracer.js +1 -1
  69. package/esm/domain/tracing/tracer.js +8 -9
  70. package/esm/domain/trackEventCounts.js +9 -6
  71. package/esm/domain/usr/index.js +17 -0
  72. package/esm/domain/waitPageActivityEnd.js +147 -0
  73. package/esm/transport/startRumBatch.js +30 -0
  74. package/package.json +3 -3
  75. package/src/boot/rum.js +79 -59
  76. package/src/boot/rumPublicApi.js +165 -171
  77. package/src/domain/.DS_Store +0 -0
  78. package/src/domain/assembly.js +77 -54
  79. package/src/domain/configuration.js +69 -0
  80. package/src/domain/contexts/internalContext.js +39 -0
  81. package/src/domain/contexts/urlContexts.js +76 -0
  82. package/src/domain/contexts/viewContexts.js +37 -0
  83. package/src/domain/domMutationCollection.js +48 -32
  84. package/src/domain/{rumEventsCollection/view/trackLocationChanges.js → locationChangeObservable.js} +28 -28
  85. package/src/domain/performanceCollection.js +62 -45
  86. package/src/domain/requestCollection.js +103 -0
  87. package/src/domain/rumEventsCollection/actions/actionCollection.js +34 -11
  88. package/src/domain/rumEventsCollection/actions/clickChain.js +90 -0
  89. package/src/domain/rumEventsCollection/actions/computeFrustration.js +84 -0
  90. package/src/domain/rumEventsCollection/actions/getActionNameFromElement.js +73 -62
  91. package/src/domain/rumEventsCollection/actions/getSelectorsFromElement.js +157 -0
  92. package/src/domain/rumEventsCollection/actions/listenActionEvents.js +85 -0
  93. package/src/domain/rumEventsCollection/actions/trackClickActions.js +326 -0
  94. package/src/domain/rumEventsCollection/error/errorCollection.js +53 -69
  95. package/src/domain/rumEventsCollection/error/trackConsoleError.js +21 -0
  96. package/src/domain/rumEventsCollection/error/trackReportError.js +22 -0
  97. package/src/domain/rumEventsCollection/longTask/longTaskCollection.js +29 -18
  98. package/src/domain/rumEventsCollection/resource/resourceCollection.js +39 -23
  99. package/src/domain/rumEventsCollection/view/trackFirstHidden.js +9 -6
  100. package/src/domain/rumEventsCollection/view/trackInitialViewTimings.js +63 -42
  101. package/src/domain/rumEventsCollection/view/trackViewMetrics.js +80 -61
  102. package/src/domain/rumEventsCollection/view/trackViews.js +171 -134
  103. package/src/domain/rumEventsCollection/view/viewCollection.js +69 -49
  104. package/src/domain/rumSessionManager.js +90 -0
  105. package/src/domain/tracing/jaegerTracer.js +5 -5
  106. package/src/domain/tracing/skywalkingTracer.js +3 -3
  107. package/src/domain/tracing/tracer.js +50 -38
  108. package/src/domain/tracing/w3cTraceParentTracer.js +5 -5
  109. package/src/domain/tracing/zipkinMultiTracer.js +5 -5
  110. package/src/domain/tracing/zipkinSingleTracer.js +5 -5
  111. package/src/domain/trackEventCounts.js +10 -6
  112. package/src/domain/usr/index.js +16 -0
  113. package/src/domain/waitPageActivityEnd.js +192 -0
  114. package/src/transport/startRumBatch.js +48 -0
  115. package/cjs/domain/internalContext.js +0 -34
  116. package/cjs/domain/parentContexts.js +0 -143
  117. package/cjs/domain/requestCollections.js +0 -131
  118. package/cjs/domain/rumEventsCollection/actions/trackActions.js +0 -114
  119. package/cjs/domain/rumSession.js +0 -82
  120. package/cjs/domain/trackPageActivities.js +0 -166
  121. package/cjs/transport/batch.js +0 -81
  122. package/esm/domain/internalContext.js +0 -27
  123. package/esm/domain/parentContexts.js +0 -130
  124. package/esm/domain/requestCollections.js +0 -118
  125. package/esm/domain/rumEventsCollection/actions/trackActions.js +0 -103
  126. package/esm/domain/rumSession.js +0 -70
  127. package/esm/domain/trackPageActivities.js +0 -149
  128. package/esm/transport/batch.js +0 -74
  129. package/src/domain/internalContext.js +0 -28
  130. package/src/domain/parentContexts.js +0 -171
  131. package/src/domain/requestCollections.js +0 -118
  132. package/src/domain/rumEventsCollection/actions/trackActions.js +0 -113
  133. package/src/domain/rumSession.js +0 -92
  134. package/src/domain/trackPageActivities.js +0 -170
  135. package/src/transport/batch.js +0 -85
package/cjs/boot/rum.js CHANGED
@@ -6,93 +6,102 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.startRum = startRum;
7
7
  exports.startRumEventCollection = startRumEventCollection;
8
8
 
9
- var _rumSession = require("../domain/rumSession");
9
+ var _rumSessionManager = require("../domain/rumSessionManager");
10
10
 
11
- var _browserCore = require("@cloudcare/browser-core");
11
+ var _usr = require("../domain/usr");
12
12
 
13
- var _buildEnv = require("./buildEnv");
13
+ var _browserCore = require("@cloudcare/browser-core");
14
14
 
15
15
  var _performanceCollection = require("../domain/performanceCollection");
16
16
 
17
17
  var _domMutationCollection = require("../domain/domMutationCollection");
18
18
 
19
+ var _locationChangeObservable = require("../domain/locationChangeObservable");
20
+
19
21
  var _longTaskCollection = require("../domain/rumEventsCollection/longTask/longTaskCollection");
20
22
 
21
23
  var _actionCollection = require("../domain/rumEventsCollection/actions/actionCollection");
22
24
 
23
- var _parentContexts = require("../domain/parentContexts");
24
-
25
- var _batch = require("../transport/batch");
25
+ var _startRumBatch = require("../transport/startRumBatch");
26
26
 
27
27
  var _assembly = require("../domain/assembly");
28
28
 
29
- var _internalContext = require("../domain/internalContext");
29
+ var _internalContext = require("../domain/contexts/internalContext");
30
+
31
+ var _urlContexts = require("../domain/contexts/urlContexts");
32
+
33
+ var _viewContexts = require("../domain/contexts/viewContexts");
30
34
 
31
35
  var _errorCollection = require("../domain/rumEventsCollection/error/errorCollection");
32
36
 
33
37
  var _viewCollection = require("../domain/rumEventsCollection/view/viewCollection");
34
38
 
35
- var _requestCollections = require("../domain/requestCollections");
39
+ var _requestCollection = require("../domain/requestCollection");
36
40
 
37
41
  var _resourceCollection = require("../domain/rumEventsCollection/resource/resourceCollection");
38
42
 
39
- function startRum(userConfiguration, getCommonContext) {
43
+ function startRum(configuration, getCommonContext, initialViewOptions) {
40
44
  var lifeCycle = new _browserCore.LifeCycle();
41
- var configuration = (0, _browserCore.commonInit)(userConfiguration, _buildEnv.buildEnv);
42
- var session = (0, _rumSession.startRumSession)(configuration, lifeCycle);
43
45
 
44
- var _startRumEventCollection = startRumEventCollection(userConfiguration.applicationId, location, lifeCycle, configuration, session, getCommonContext);
46
+ var reportError = function reportError(error) {
47
+ lifeCycle.notify(_browserCore.LifeCycleEventType.RAW_ERROR_COLLECTED, {
48
+ error: error
49
+ });
50
+ };
51
+
52
+ (0, _startRumBatch.startRumBatch)(configuration, lifeCycle, reportError);
53
+ var session = (0, _rumSessionManager.startRumSessionManager)(configuration, lifeCycle);
54
+ var userSession = (0, _usr.startCacheUsrCache)(configuration);
55
+ var domMutationObservable = (0, _domMutationCollection.createDOMMutationObservable)();
56
+ var locationChangeObservable = (0, _locationChangeObservable.createLocationChangeObservable)(location);
57
+
58
+ var _startRumEventCollection = startRumEventCollection(location, lifeCycle, configuration, session, userSession, locationChangeObservable, domMutationObservable, getCommonContext, reportError);
45
59
 
46
- var parentContexts = _startRumEventCollection.parentContexts;
47
- (0, _requestCollections.startRequestCollection)(lifeCycle, configuration);
60
+ var viewContexts = _startRumEventCollection.viewContexts;
61
+ var urlContexts = _startRumEventCollection.urlContexts;
62
+ var actionContexts = _startRumEventCollection.actionContexts;
63
+ (0, _longTaskCollection.startLongTaskCollection)(lifeCycle, session);
64
+ (0, _resourceCollection.startResourceCollection)(lifeCycle, configuration);
65
+
66
+ var _startViewCollection = (0, _viewCollection.startViewCollection)(lifeCycle, configuration, location, domMutationObservable, locationChangeObservable, initialViewOptions);
67
+
68
+ var addTiming = _startViewCollection.addTiming;
69
+ var startView = _startViewCollection.startView;
70
+
71
+ var _startErrorCollection = (0, _errorCollection.startErrorCollection)(lifeCycle, configuration);
72
+
73
+ var addError = _startErrorCollection.addError;
74
+ (0, _requestCollection.startRequestCollection)(lifeCycle, configuration, session);
48
75
  (0, _performanceCollection.startPerformanceCollection)(lifeCycle, configuration);
49
- (0, _domMutationCollection.startDOMMutationCollection)(lifeCycle);
50
- var internalContext = (0, _internalContext.startInternalContext)(userConfiguration.applicationId, session, parentContexts);
76
+ var internalContext = (0, _internalContext.startInternalContext)(configuration.applicationId, session, viewContexts, actionContexts, urlContexts);
51
77
  return {
52
78
  addAction: _startRumEventCollection.addAction,
53
- addError: _startRumEventCollection.addError,
54
- addTiming: _startRumEventCollection.addTiming,
79
+ addError: addError,
80
+ addTiming: addTiming,
55
81
  configuration: configuration,
56
82
  lifeCycle: lifeCycle,
57
- parentContexts: parentContexts,
83
+ viewContexts: viewContexts,
58
84
  session: session,
85
+ startView: startView,
59
86
  getInternalContext: internalContext.get
60
87
  };
61
88
  }
62
89
 
63
- function startRumEventCollection(applicationId, location, lifeCycle, configuration, session, getCommonContext) {
64
- var parentContexts = (0, _parentContexts.startParentContexts)(lifeCycle, session);
65
- var batch = (0, _batch.startRumBatch)(configuration, lifeCycle);
66
- (0, _assembly.startRumAssembly)(applicationId, configuration, lifeCycle, session, parentContexts, getCommonContext);
67
- (0, _longTaskCollection.startLongTaskCollection)(lifeCycle);
68
- (0, _resourceCollection.startResourceCollection)(lifeCycle, configuration, session);
69
-
70
- var _startViewCollection = (0, _viewCollection.startViewCollection)(lifeCycle, configuration, location);
90
+ function startRumEventCollection(location, lifeCycle, configuration, sessionManager, userSessionManager, locationChangeObservable, domMutationObservable, getCommonContext, reportError) {
91
+ var viewContexts = (0, _viewContexts.startViewContexts)(lifeCycle);
92
+ var urlContexts = (0, _urlContexts.startUrlContexts)(lifeCycle, locationChangeObservable, location);
71
93
 
72
- var addTiming = _startViewCollection.addTiming;
73
- var stopViewCollection = _startViewCollection.stop;
74
-
75
- var _startErrorCollection = (0, _errorCollection.startErrorCollection)(lifeCycle, configuration);
76
-
77
- var _startActionCollection = (0, _actionCollection.startActionCollection)(lifeCycle, configuration);
94
+ var _startActionCollection = (0, _actionCollection.startActionCollection)(lifeCycle, domMutationObservable, configuration);
78
95
 
96
+ var actionContexts = _startActionCollection.actionContexts;
97
+ (0, _assembly.startRumAssembly)(configuration, lifeCycle, sessionManager, userSessionManager, viewContexts, urlContexts, actionContexts, getCommonContext, reportError);
79
98
  return {
99
+ viewContexts: viewContexts,
100
+ urlContexts: urlContexts,
80
101
  addAction: _startActionCollection.addAction,
81
- addTiming: addTiming,
82
- parentContexts: parentContexts,
83
- addError: _startErrorCollection.addError,
102
+ actionContexts: actionContexts,
84
103
  stop: function stop() {
85
- stopViewCollection();
86
- batch.stop();
104
+ viewContexts.stop();
87
105
  }
88
- }; // return {
89
- // addAction,
90
- // addError,
91
- // parentContexts,
92
- // stop() {
93
- // // prevent batch from previous tests to keep running and send unwanted requests
94
- // // could be replaced by stopping all the component when they will all have a stop method
95
- // batch.stop()
96
- // }
97
- // }
106
+ };
98
107
  }
@@ -7,134 +7,161 @@ exports.makeRumPublicApi = makeRumPublicApi;
7
7
 
8
8
  var _browserCore = require("@cloudcare/browser-core");
9
9
 
10
+ var _configuration = require("../domain/configuration");
11
+
10
12
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
11
13
 
12
14
  function makeRumPublicApi(startRumImpl) {
13
15
  var isAlreadyInitialized = false;
14
16
  var globalContextManager = (0, _browserCore.createContextManager)();
15
- var user = {};
17
+ var userContextManager = (0, _browserCore.createContextManager)();
18
+ var bufferApiCalls = new _browserCore.BoundedBuffer();
16
19
 
17
- var getInternalContextStrategy = function getInternalContextStrategy() {
18
- return undefined;
19
- };
20
+ var _addTimingStrategy = function addTimingStrategy(name, time) {
21
+ if (typeof time === 'undefined') {
22
+ time = (0, _browserCore.timeStampNow)();
23
+ }
20
24
 
21
- var getDebugSessionStrategy = function getDebugSessionStrategy() {
22
- return {};
25
+ bufferApiCalls.add(function () {
26
+ return _addTimingStrategy(name, time);
27
+ });
23
28
  };
24
29
 
25
- var clearDebugSessionStrategy = function clearDebugSessionStrategy() {};
26
-
27
- var beforeInitAddSession = new _browserCore.BoundedBuffer();
30
+ var _startViewStrategy = function startViewStrategy(options, startClocks) {
31
+ if (typeof startClocks === 'undefined') {
32
+ startClocks = (0, _browserCore.clocksNow)();
33
+ }
28
34
 
29
- var addSessionStrategy = function addSessionStrategy(id) {
30
- beforeInitAddSession.add([id, (0, _browserCore.timeStampNow)()]);
35
+ bufferApiCalls.add(function () {
36
+ return _startViewStrategy(options, startClocks);
37
+ });
31
38
  };
32
39
 
33
- var beforeInitAddTiming = new _browserCore.BoundedBuffer();
40
+ var _addActionStrategy = function addActionStrategy(action, commonContext) {
41
+ if (typeof commonContext == 'undefined') {
42
+ commonContext = {
43
+ context: globalContextManager.getContext(),
44
+ user: userContextManager.getContext()
45
+ };
46
+ }
34
47
 
35
- var addTimingStrategy = function addTimingStrategy(name) {
36
- beforeInitAddTiming.add([name, (0, _browserCore.clocksNow)()]);
48
+ bufferApiCalls.add(function () {
49
+ return _addActionStrategy(action, commonContext);
50
+ });
37
51
  };
38
52
 
39
- var beforeInitAddAction = new _browserCore.BoundedBuffer();
53
+ var _addErrorStrategy = function addErrorStrategy(providedError, commonContext) {
54
+ if (typeof commonContext == 'undefined') {
55
+ commonContext = {
56
+ context: globalContextManager.getContext(),
57
+ user: userContextManager.getContext()
58
+ };
59
+ }
40
60
 
41
- var addActionStrategy = function addActionStrategy(action) {
42
- beforeInitAddAction.add([action, clonedCommonContext()]);
61
+ bufferApiCalls.add(function () {
62
+ return _addErrorStrategy(providedError, commonContext);
63
+ });
43
64
  };
44
65
 
45
- var beforeInitAddError = new _browserCore.BoundedBuffer();
66
+ var getInternalContextStrategy = function getInternalContextStrategy() {
67
+ return undefined;
68
+ };
46
69
 
47
- var addErrorStrategy = function addErrorStrategy(providedError) {
48
- beforeInitAddError.add([providedError, clonedCommonContext()]);
70
+ var getInitConfigurationStrategy = function getInitConfigurationStrategy() {
71
+ return undefined;
49
72
  };
50
73
 
51
- function clonedCommonContext() {
52
- return (0, _browserCore.deepClone)({
53
- context: globalContextManager.get(),
54
- user: user
55
- });
74
+ function initRum(initConfiguration) {
75
+ if (!canHandleSession(initConfiguration)) {
76
+ return;
77
+ }
78
+
79
+ if (!canInitRum(initConfiguration)) {
80
+ return;
81
+ }
82
+
83
+ var configuration = (0, _configuration.validateAndBuildRumConfiguration)(initConfiguration);
84
+
85
+ if (!configuration) {
86
+ return;
87
+ }
88
+
89
+ if (!configuration.trackViewsManually) {
90
+ doStartRum(configuration);
91
+ } else {
92
+ // drain beforeInitCalls by buffering them until we start RUM
93
+ // if we get a startView, drain re-buffered calls before continuing to drain beforeInitCalls
94
+ // in order to ensure that calls are processed in order
95
+ var beforeInitCalls = bufferApiCalls;
96
+ bufferApiCalls = new _browserCore.BoundedBuffer();
97
+
98
+ _startViewStrategy = function _startViewStrategy(options) {
99
+ doStartRum(configuration, options);
100
+ };
101
+
102
+ beforeInitCalls.drain();
103
+ }
104
+
105
+ getInitConfigurationStrategy = function getInitConfigurationStrategy() {
106
+ return (0, _browserCore.deepClone)(initConfiguration);
107
+ };
108
+
109
+ isAlreadyInitialized = true;
110
+ }
111
+
112
+ function doStartRum(configuration, initialViewOptions) {
113
+ var startRumResults = startRumImpl(configuration, function () {
114
+ return {
115
+ user: userContextManager.getContext(),
116
+ context: globalContextManager.getContext()
117
+ };
118
+ }, initialViewOptions);
119
+ _startViewStrategy = startRumResults.startView;
120
+ _addActionStrategy = startRumResults.addAction;
121
+ _addErrorStrategy = startRumResults.addError;
122
+ _addTimingStrategy = startRumResults.addTiming;
123
+ getInternalContextStrategy = startRumResults.getInternalContext;
124
+ bufferApiCalls.drain();
56
125
  }
57
126
 
127
+ var startView = function startView(options) {
128
+ var sanitizedOptions = _typeof(options) === 'object' ? options : {
129
+ name: options
130
+ };
131
+
132
+ _startViewStrategy(sanitizedOptions);
133
+ };
134
+
58
135
  var rumPublicApi = (0, _browserCore.makePublicApi)({
59
- init: function init(userConfiguration) {
60
- if (!(0, _browserCore.checkCookiesAuthorized)((0, _browserCore.buildCookieOptions)(userConfiguration)) || !(0, _browserCore.checkIsNotLocalFile)() || !canInitRum(userConfiguration)) {
61
- return;
62
- } // if (userConfiguration.publicApiKey) {
63
- // userConfiguration.clientToken = userConfiguration.publicApiKey
64
- // }
65
-
66
-
67
- var _startRumImpl = startRumImpl(userConfiguration, function () {
68
- return {
69
- user: user,
70
- context: globalContextManager.get()
71
- };
72
- });
136
+ init: initRum,
73
137
 
74
- addSessionStrategy = _startRumImpl.session.addDebugSession;
75
- addActionStrategy = _startRumImpl.addAction;
76
- addErrorStrategy = _startRumImpl.addError;
77
- addTimingStrategy = _startRumImpl.addTiming;
78
- getDebugSessionStrategy = _startRumImpl.session.getDebugSession;
79
- clearDebugSessionStrategy = _startRumImpl.session.clearDebugSession;
80
- getInternalContextStrategy = _startRumImpl.getInternalContext;
81
- beforeInitAddSession.drain(function (data) {
82
- var id = data[0];
83
- var created_time = data[1];
84
- addSessionStrategy(id, created_time);
85
- });
86
- beforeInitAddAction.drain(function (data) {
87
- var action = data[0];
88
- var commonContext = data[1];
89
- addActionStrategy(action, commonContext);
90
- });
91
- beforeInitAddError.drain(function (data) {
92
- var error = data[0];
93
- var commonContext = data[1];
94
- addErrorStrategy(error, commonContext);
95
- });
96
- beforeInitAddTiming.drain(function (data) {
97
- var name = data[0];
98
- var endClocks = data[1];
99
- addTimingStrategy(name, endClocks);
100
- });
101
- isAlreadyInitialized = true;
102
- },
138
+ /** @deprecated: use setGlobalContextProperty instead */
103
139
  addRumGlobalContext: globalContextManager.add,
140
+ setGlobalContextProperty: globalContextManager.setContextProperty,
141
+
142
+ /** @deprecated: use removeGlobalContextProperty instead */
104
143
  removeRumGlobalContext: globalContextManager.remove,
144
+ removeGlobalContextProperty: globalContextManager.removeContextProperty,
145
+
146
+ /** @deprecated: use getGlobalContext instead */
105
147
  getRumGlobalContext: globalContextManager.get,
148
+ getGlobalContext: globalContextManager.getContext,
149
+
150
+ /** @deprecated: use setGlobalContext instead */
106
151
  setRumGlobalContext: globalContextManager.set,
152
+ setGlobalContext: globalContextManager.setContext,
153
+ clearGlobalContext: globalContextManager.clearContext,
154
+ getInitConfiguration: function getInitConfiguration() {
155
+ return getInitConfigurationStrategy();
156
+ },
107
157
  getInternalContext: function getInternalContext(startTime) {
108
158
  return getInternalContextStrategy(startTime);
109
159
  },
110
- addDebugSession: function addDebugSession(id) {
111
- addSessionStrategy(id);
112
- this.getDebugSession();
113
- },
114
- clearDebugSession: function clearDebugSession() {
115
- clearDebugSessionStrategy();
116
- console.log('%c应用已关闭调试模式!!!', 'font-size: 18px;color:yellow');
117
- },
118
- getDebugSession: function getDebugSession() {
119
- var debugInfo = getDebugSessionStrategy();
120
-
121
- if ((0, _browserCore.isEmptyObject)(debugInfo)) {
122
- console.log('%c应用未开启调试模式!!!可以调用%caddDebugSession%c开启', 'font-size: 18px;color:yellow', 'font-size: 18px;color:red;font-weight: bold', 'font-size: 18px;color:yellow');
123
- return debugInfo;
124
- } else {
125
- var formatTime = (0, _browserCore.formatDate)(new Date(+debugInfo.created));
126
- var did = debugInfo.id;
127
- console.log('%c应用已开启调试模式!!!调试信息如下:', 'font-size: 18px;color:yellow');
128
- console.log('%c调试模式session id: %c' + did, 'font-size: 18px;color:yellow', 'font-size: 18px;color:red;font-weight: bold');
129
- console.log('%c调试模式开始时间: %c' + formatTime, 'font-size: 18px;color:yellow', 'font-size: 18px;color:red;font-weight: bold');
130
- console.log('%c可以调用%cclearDebugSession%c关闭调试模式', 'font-size: 18px;color:yellow', 'font-size: 18px;color:red;font-weight: bold', 'font-size: 18px;color:yellow');
131
- return (0, _browserCore.extend2Lev)(debugInfo, {
132
- format_created: formatTime
133
- });
134
- }
135
- },
160
+ addDebugSession: function addDebugSession(id) {},
161
+ clearDebugSession: function clearDebugSession() {},
162
+ getDebugSession: function getDebugSession() {},
136
163
  addAction: function addAction(name, context) {
137
- addActionStrategy({
164
+ _addActionStrategy({
138
165
  name: name,
139
166
  context: (0, _browserCore.deepClone)(context),
140
167
  startClocks: (0, _browserCore.clocksNow)(),
@@ -150,79 +177,87 @@ function makeRumPublicApi(startRumImpl) {
150
177
  // },
151
178
  addError: function addError(error, context) {
152
179
  var handlingStack = (0, _browserCore.createHandlingStack)();
153
- addErrorStrategy({
180
+
181
+ _addErrorStrategy({
154
182
  error: error,
155
183
  handlingStack: handlingStack,
156
184
  context: (0, _browserCore.deepClone)(context),
157
185
  startClocks: (0, _browserCore.clocksNow)()
158
186
  });
159
187
  },
160
- // addTiming: function (name) {
161
- // addTimingStrategy(name)
162
- // },
188
+ addTiming: function addTiming(name, time) {
189
+ _addTimingStrategy(name, time);
190
+ },
163
191
  setUser: function setUser(newUser) {
164
- var sanitizedUser = sanitizeUser(newUser);
165
-
166
- if (sanitizedUser) {
167
- user = sanitizedUser;
192
+ if (_typeof(newUser) !== 'object' || !newUser) {
193
+ _browserCore.display.error('Unsupported user:', newUser);
168
194
  } else {
169
- console.error('Unsupported user:', newUser);
195
+ userContextManager.setContext(sanitizeUser(newUser));
170
196
  }
171
197
  },
172
- removeUser: function removeUser() {
173
- user = {};
174
- }
198
+ getUser: userContextManager.getContext,
199
+ setUserProperty: function setUserProperty(key, property) {
200
+ var newUser = {};
201
+ newUser[key] = property;
202
+ var sanitizedProperty = sanitizeUser(newUser)[key];
203
+ userContextManager.setContextProperty(key, sanitizedProperty);
204
+ },
205
+ removeUserProperty: userContextManager.removeContextProperty,
206
+
207
+ /** @deprecated: renamed to clearUser */
208
+ removeUser: userContextManager.clearContext,
209
+ clearUser: userContextManager.clearContext,
210
+ startView: startView
175
211
  });
176
212
  return rumPublicApi;
177
213
 
178
214
  function sanitizeUser(newUser) {
179
- if (_typeof(newUser) !== 'object' || !newUser) {
180
- return;
181
- }
215
+ var shallowClonedUser = (0, _browserCore.assign)(newUser, {});
182
216
 
183
- var result = (0, _browserCore.extend2Lev)({}, newUser);
184
-
185
- if ('id' in result) {
186
- result.id = String(result.id);
217
+ if ('id' in shallowClonedUser) {
218
+ shallowClonedUser.id = String(shallowClonedUser.id);
187
219
  }
188
220
 
189
- if ('name' in result) {
190
- result.name = String(result.name);
221
+ if ('name' in shallowClonedUser) {
222
+ shallowClonedUser.name = String(shallowClonedUser.name);
191
223
  }
192
224
 
193
- if ('email' in result) {
194
- result.email = String(result.email);
225
+ if ('email' in shallowClonedUser) {
226
+ shallowClonedUser.email = String(shallowClonedUser.email);
195
227
  }
196
228
 
197
- return result;
229
+ return shallowClonedUser;
198
230
  }
199
231
 
200
- function canInitRum(userConfiguration) {
201
- if (isAlreadyInitialized) {
202
- console.error('DATAFLUX_RUM is already initialized.');
203
- return false;
204
- }
232
+ function canHandleSession(initConfiguration) {
233
+ if (!(0, _browserCore.areCookiesAuthorized)((0, _browserCore.buildCookieOptions)(initConfiguration))) {
234
+ _browserCore.display.warn('Cookies are not authorized, we will not send any data.');
205
235
 
206
- if (!userConfiguration.applicationId) {
207
- console.error('Application ID is not configured, no RUM data will be collected.');
208
236
  return false;
209
237
  }
210
238
 
211
- if (!userConfiguration.datakitUrl && !userConfiguration.datakitOrigin) {
212
- console.error('datakitOrigin is not configured, no RUM data will be collected.');
213
- return false;
214
- }
239
+ if (isLocalFile()) {
240
+ _browserCore.display.error('Execution is not allowed in the current context.');
215
241
 
216
- if (userConfiguration.sampleRate !== undefined && !(0, _browserCore.isPercentage)(userConfiguration.sampleRate)) {
217
- console.error('Sample Rate should be a number between 0 and 100');
218
242
  return false;
219
243
  }
220
244
 
221
- if (userConfiguration.resourceSampleRate !== undefined && !(0, _browserCore.isPercentage)(userConfiguration.resourceSampleRate)) {
222
- console.error('Resource Sample Rate should be a number between 0 and 100');
245
+ return true;
246
+ }
247
+
248
+ function canInitRum(initConfiguration) {
249
+ if (isAlreadyInitialized) {
250
+ if (!initConfiguration.silentMultipleInit) {
251
+ _browserCore.display.error('DATAFLUX_RUM is already initialized.');
252
+ }
253
+
223
254
  return false;
224
255
  }
225
256
 
226
257
  return true;
227
258
  }
259
+
260
+ function isLocalFile() {
261
+ return window.location.protocol === 'file:';
262
+ }
228
263
  }