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