@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.
- package/README.md +1 -2
- package/bundle/dataflux-rum.js +1 -1
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/boot/rum.js +57 -48
- package/cjs/boot/rumPublicApi.js +169 -134
- package/cjs/domain/assembly.js +58 -44
- package/cjs/domain/configuration.js +67 -0
- package/cjs/domain/contexts/internalContext.js +45 -0
- package/cjs/domain/contexts/urlContexts.js +68 -0
- package/cjs/domain/contexts/viewContexts.js +43 -0
- package/cjs/domain/domMutationCollection.js +44 -31
- package/cjs/domain/{rumEventsCollection/view/trackLocationChanges.js → locationChangeObservable.js} +25 -25
- package/cjs/domain/performanceCollection.js +55 -24
- package/cjs/domain/requestCollection.js +117 -0
- package/cjs/domain/rumEventsCollection/actions/actionCollection.js +22 -4
- package/cjs/domain/rumEventsCollection/actions/clickChain.js +82 -0
- package/cjs/domain/rumEventsCollection/actions/computeFrustration.js +78 -0
- package/cjs/domain/rumEventsCollection/actions/getActionNameFromElement.js +60 -47
- package/cjs/domain/rumEventsCollection/actions/getSelectorsFromElement.js +163 -0
- package/cjs/domain/rumEventsCollection/actions/listenActionEvents.js +74 -0
- package/cjs/domain/rumEventsCollection/actions/trackClickActions.js +263 -0
- package/cjs/domain/rumEventsCollection/error/errorCollection.js +33 -53
- package/cjs/domain/rumEventsCollection/error/trackConsoleError.js +26 -0
- package/cjs/domain/rumEventsCollection/error/trackReportError.js +26 -0
- package/cjs/domain/rumEventsCollection/longTask/longTaskCollection.js +46 -17
- package/cjs/domain/rumEventsCollection/resource/resourceCollection.js +49 -9
- package/cjs/domain/rumEventsCollection/view/trackFirstHidden.js +7 -5
- package/cjs/domain/rumEventsCollection/view/trackInitialViewTimings.js +61 -24
- package/cjs/domain/rumEventsCollection/view/trackViewMetrics.js +91 -51
- package/cjs/domain/rumEventsCollection/view/trackViews.js +119 -86
- package/cjs/domain/rumEventsCollection/view/viewCollection.js +41 -31
- package/cjs/domain/rumSessionManager.js +95 -0
- package/cjs/domain/tracing/tracer.js +8 -9
- package/cjs/domain/trackEventCounts.js +9 -6
- package/cjs/domain/usr/index.js +30 -0
- package/cjs/domain/waitPageActivityEnd.js +163 -0
- package/cjs/transport/startRumBatch.js +38 -0
- package/esm/boot/buildEnv.js +1 -1
- package/esm/boot/rum.js +55 -48
- package/esm/boot/rumPublicApi.js +167 -135
- package/esm/domain/assembly.js +58 -44
- package/esm/domain/configuration.js +53 -0
- package/esm/domain/contexts/internalContext.js +38 -0
- package/esm/domain/contexts/urlContexts.js +58 -0
- package/esm/domain/contexts/viewContexts.js +32 -0
- package/esm/domain/domMutationCollection.js +43 -33
- package/esm/domain/{rumEventsCollection/view/trackLocationChanges.js → locationChangeObservable.js} +26 -24
- package/esm/domain/performanceCollection.js +56 -26
- package/esm/domain/requestCollection.js +102 -0
- package/esm/domain/rumEventsCollection/actions/actionCollection.js +23 -5
- package/esm/domain/rumEventsCollection/actions/clickChain.js +69 -0
- package/esm/domain/rumEventsCollection/actions/computeFrustration.js +64 -0
- package/esm/domain/rumEventsCollection/actions/getActionNameFromElement.js +60 -47
- package/esm/domain/rumEventsCollection/actions/getSelectorsFromElement.js +139 -0
- package/esm/domain/rumEventsCollection/actions/listenActionEvents.js +66 -0
- package/esm/domain/rumEventsCollection/actions/trackClickActions.js +244 -0
- package/esm/domain/rumEventsCollection/error/errorCollection.js +32 -54
- package/esm/domain/rumEventsCollection/error/trackConsoleError.js +18 -0
- package/esm/domain/rumEventsCollection/error/trackReportError.js +18 -0
- package/esm/domain/rumEventsCollection/longTask/longTaskCollection.js +30 -18
- package/esm/domain/rumEventsCollection/resource/resourceCollection.js +31 -9
- package/esm/domain/rumEventsCollection/view/trackFirstHidden.js +8 -6
- package/esm/domain/rumEventsCollection/view/trackInitialViewTimings.js +43 -26
- package/esm/domain/rumEventsCollection/view/trackViewMetrics.js +75 -51
- package/esm/domain/rumEventsCollection/view/trackViews.js +120 -85
- package/esm/domain/rumEventsCollection/view/viewCollection.js +42 -32
- package/esm/domain/rumSessionManager.js +80 -0
- package/esm/domain/tracing/skywalkingTracer.js +1 -1
- package/esm/domain/tracing/tracer.js +7 -8
- package/esm/domain/trackEventCounts.js +9 -6
- package/esm/domain/usr/index.js +17 -0
- package/esm/domain/waitPageActivityEnd.js +147 -0
- package/esm/transport/startRumBatch.js +30 -0
- package/package.json +3 -3
- package/src/boot/rum.js +79 -59
- package/src/boot/rumPublicApi.js +165 -171
- package/src/domain/assembly.js +77 -54
- package/src/domain/configuration.js +69 -0
- package/src/domain/contexts/internalContext.js +39 -0
- package/src/domain/contexts/urlContexts.js +76 -0
- package/src/domain/contexts/viewContexts.js +37 -0
- package/src/domain/domMutationCollection.js +48 -32
- package/src/domain/{rumEventsCollection/view/trackLocationChanges.js → locationChangeObservable.js} +28 -28
- package/src/domain/performanceCollection.js +62 -45
- package/src/domain/requestCollection.js +103 -0
- package/src/domain/rumEventsCollection/actions/actionCollection.js +34 -11
- package/src/domain/rumEventsCollection/actions/clickChain.js +90 -0
- package/src/domain/rumEventsCollection/actions/computeFrustration.js +84 -0
- package/src/domain/rumEventsCollection/actions/getActionNameFromElement.js +73 -62
- package/src/domain/rumEventsCollection/actions/getSelectorsFromElement.js +157 -0
- package/src/domain/rumEventsCollection/actions/listenActionEvents.js +85 -0
- package/src/domain/rumEventsCollection/actions/trackClickActions.js +326 -0
- package/src/domain/rumEventsCollection/error/errorCollection.js +53 -69
- package/src/domain/rumEventsCollection/error/trackConsoleError.js +21 -0
- package/src/domain/rumEventsCollection/error/trackReportError.js +22 -0
- package/src/domain/rumEventsCollection/longTask/longTaskCollection.js +29 -18
- package/src/domain/rumEventsCollection/resource/resourceCollection.js +39 -23
- package/src/domain/rumEventsCollection/view/trackFirstHidden.js +9 -6
- package/src/domain/rumEventsCollection/view/trackInitialViewTimings.js +63 -42
- package/src/domain/rumEventsCollection/view/trackViewMetrics.js +80 -61
- package/src/domain/rumEventsCollection/view/trackViews.js +171 -134
- package/src/domain/rumEventsCollection/view/viewCollection.js +69 -49
- package/src/domain/rumSessionManager.js +90 -0
- package/src/domain/tracing/jaegerTracer.js +5 -5
- package/src/domain/tracing/skywalkingTracer.js +3 -3
- package/src/domain/tracing/tracer.js +50 -38
- package/src/domain/tracing/w3cTraceParentTracer.js +5 -5
- package/src/domain/tracing/zipkinMultiTracer.js +5 -5
- package/src/domain/tracing/zipkinSingleTracer.js +5 -5
- package/src/domain/trackEventCounts.js +10 -6
- package/src/domain/usr/index.js +16 -0
- package/src/domain/waitPageActivityEnd.js +192 -0
- package/src/transport/startRumBatch.js +48 -0
- package/cjs/domain/internalContext.js +0 -34
- package/cjs/domain/parentContexts.js +0 -143
- package/cjs/domain/requestCollections.js +0 -131
- package/cjs/domain/rumEventsCollection/actions/trackActions.js +0 -114
- package/cjs/domain/rumSession.js +0 -82
- package/cjs/domain/trackPageActivities.js +0 -166
- package/cjs/transport/batch.js +0 -81
- package/esm/domain/internalContext.js +0 -27
- package/esm/domain/parentContexts.js +0 -130
- package/esm/domain/requestCollections.js +0 -118
- package/esm/domain/rumEventsCollection/actions/trackActions.js +0 -103
- package/esm/domain/rumSession.js +0 -70
- package/esm/domain/trackPageActivities.js +0 -149
- package/esm/transport/batch.js +0 -74
- package/src/domain/internalContext.js +0 -28
- package/src/domain/parentContexts.js +0 -171
- package/src/domain/requestCollections.js +0 -118
- package/src/domain/rumEventsCollection/actions/trackActions.js +0 -113
- package/src/domain/rumSession.js +0 -92
- package/src/domain/trackPageActivities.js +0 -170
- package/src/transport/batch.js +0 -85
package/esm/boot/rum.js
CHANGED
|
@@ -1,74 +1,81 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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 {
|
|
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 {
|
|
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/
|
|
16
|
+
import { startRequestCollection } from '../domain/requestCollection';
|
|
15
17
|
import { startResourceCollection } from '../domain/rumEventsCollection/resource/resourceCollection';
|
|
16
|
-
export function startRum(
|
|
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
|
|
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
|
|
24
|
-
startRequestCollection(lifeCycle, configuration);
|
|
48
|
+
var addError = _startErrorCollection.addError;
|
|
49
|
+
startRequestCollection(lifeCycle, configuration, session);
|
|
25
50
|
startPerformanceCollection(lifeCycle, configuration);
|
|
26
|
-
|
|
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:
|
|
31
|
-
addTiming:
|
|
54
|
+
addError: addError,
|
|
55
|
+
addTiming: addTiming,
|
|
32
56
|
configuration: configuration,
|
|
33
57
|
lifeCycle: lifeCycle,
|
|
34
|
-
|
|
58
|
+
viewContexts: viewContexts,
|
|
35
59
|
session: session,
|
|
60
|
+
startView: startView,
|
|
36
61
|
getInternalContext: internalContext.get
|
|
37
62
|
};
|
|
38
63
|
}
|
|
39
|
-
export function startRumEventCollection(
|
|
40
|
-
var
|
|
41
|
-
var
|
|
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
|
|
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
|
-
|
|
58
|
-
parentContexts: parentContexts,
|
|
59
|
-
addError: _startErrorCollection.addError,
|
|
76
|
+
actionContexts: actionContexts,
|
|
60
77
|
stop: function stop() {
|
|
61
|
-
|
|
62
|
-
batch.stop();
|
|
78
|
+
viewContexts.stop();
|
|
63
79
|
}
|
|
64
|
-
};
|
|
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
|
}
|
package/esm/boot/rumPublicApi.js
CHANGED
|
@@ -1,130 +1,156 @@
|
|
|
1
|
-
import { makePublicApi,
|
|
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
|
|
6
|
+
var userContextManager = createContextManager();
|
|
7
|
+
var bufferApiCalls = new BoundedBuffer();
|
|
6
8
|
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
var _addTimingStrategy = function addTimingStrategy(name, time) {
|
|
10
|
+
if (typeof time === 'undefined') {
|
|
11
|
+
time = timeStampNow();
|
|
12
|
+
}
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
bufferApiCalls.add(function () {
|
|
15
|
+
return _addTimingStrategy(name, time);
|
|
16
|
+
});
|
|
13
17
|
};
|
|
14
18
|
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
var _startViewStrategy = function startViewStrategy(options, startClocks) {
|
|
20
|
+
if (typeof startClocks === 'undefined') {
|
|
21
|
+
startClocks = clocksNow();
|
|
22
|
+
}
|
|
18
23
|
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
bufferApiCalls.add(function () {
|
|
25
|
+
return _startViewStrategy(options, startClocks);
|
|
26
|
+
});
|
|
21
27
|
};
|
|
22
28
|
|
|
23
|
-
var
|
|
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
|
-
|
|
26
|
-
|
|
37
|
+
bufferApiCalls.add(function () {
|
|
38
|
+
return _addActionStrategy(action, commonContext);
|
|
39
|
+
});
|
|
27
40
|
};
|
|
28
41
|
|
|
29
|
-
var
|
|
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
|
-
|
|
32
|
-
|
|
50
|
+
bufferApiCalls.add(function () {
|
|
51
|
+
return _addErrorStrategy(providedError, commonContext);
|
|
52
|
+
});
|
|
33
53
|
};
|
|
34
54
|
|
|
35
|
-
var
|
|
55
|
+
var getInternalContextStrategy = function getInternalContextStrategy() {
|
|
56
|
+
return undefined;
|
|
57
|
+
};
|
|
36
58
|
|
|
37
|
-
var
|
|
38
|
-
|
|
59
|
+
var getInitConfigurationStrategy = function getInitConfigurationStrategy() {
|
|
60
|
+
return undefined;
|
|
39
61
|
};
|
|
40
62
|
|
|
41
|
-
function
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
102
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
151
|
-
|
|
152
|
-
|
|
177
|
+
addTiming: function addTiming(name, time) {
|
|
178
|
+
_addTimingStrategy(name, time);
|
|
179
|
+
},
|
|
153
180
|
setUser: function setUser(newUser) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
if (sanitizedUser) {
|
|
157
|
-
user = sanitizedUser;
|
|
181
|
+
if (typeof newUser !== 'object' || !newUser) {
|
|
182
|
+
display.error('Unsupported user:', newUser);
|
|
158
183
|
} else {
|
|
159
|
-
|
|
184
|
+
userContextManager.setContext(sanitizeUser(newUser));
|
|
160
185
|
}
|
|
161
186
|
},
|
|
162
|
-
|
|
163
|
-
|
|
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
|
-
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
var result = extend2Lev({}, newUser);
|
|
204
|
+
var shallowClonedUser = assign(newUser, {});
|
|
174
205
|
|
|
175
|
-
if ('id' in
|
|
176
|
-
|
|
206
|
+
if ('id' in shallowClonedUser) {
|
|
207
|
+
shallowClonedUser.id = String(shallowClonedUser.id);
|
|
177
208
|
}
|
|
178
209
|
|
|
179
|
-
if ('name' in
|
|
180
|
-
|
|
210
|
+
if ('name' in shallowClonedUser) {
|
|
211
|
+
shallowClonedUser.name = String(shallowClonedUser.name);
|
|
181
212
|
}
|
|
182
213
|
|
|
183
|
-
if ('email' in
|
|
184
|
-
|
|
214
|
+
if ('email' in shallowClonedUser) {
|
|
215
|
+
shallowClonedUser.email = String(shallowClonedUser.email);
|
|
185
216
|
}
|
|
186
217
|
|
|
187
|
-
return
|
|
218
|
+
return shallowClonedUser;
|
|
188
219
|
}
|
|
189
220
|
|
|
190
|
-
function
|
|
191
|
-
if (
|
|
192
|
-
|
|
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 (
|
|
197
|
-
|
|
227
|
+
if (isLocalFile()) {
|
|
228
|
+
display.error('Execution is not allowed in the current context.');
|
|
198
229
|
return false;
|
|
199
230
|
}
|
|
200
231
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
return false;
|
|
204
|
-
}
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
205
234
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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
|
}
|