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