@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/domain/assembly.js
CHANGED
|
@@ -6,33 +6,54 @@ import {
|
|
|
6
6
|
LifeCycleEventType,
|
|
7
7
|
RumEventType,
|
|
8
8
|
deviceInfo,
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
currentDrift,
|
|
10
|
+
createEventRateLimiter,
|
|
11
|
+
limitModification,
|
|
12
|
+
display
|
|
11
13
|
} from '@cloudcare/browser-core'
|
|
12
14
|
var SessionType = {
|
|
13
15
|
SYNTHETICS: 'synthetics',
|
|
14
16
|
USER: 'user'
|
|
15
17
|
}
|
|
16
|
-
|
|
18
|
+
|
|
19
|
+
var VIEW_EVENTS_MODIFIABLE_FIELD_PATHS = [
|
|
20
|
+
// Fields with sensitive data
|
|
17
21
|
'view.url',
|
|
18
22
|
'view.referrer',
|
|
19
23
|
'action.target.name',
|
|
20
24
|
'error.message',
|
|
21
25
|
'error.stack',
|
|
22
26
|
'error.resource.url',
|
|
23
|
-
'resource.url'
|
|
27
|
+
'resource.url',
|
|
24
28
|
]
|
|
29
|
+
|
|
30
|
+
var OTHER_EVENTS_MODIFIABLE_FIELD_PATHS = VIEW_EVENTS_MODIFIABLE_FIELD_PATHS.concat([
|
|
31
|
+
// User-customizable field
|
|
32
|
+
'tags',
|
|
33
|
+
])
|
|
25
34
|
export function startRumAssembly(
|
|
26
|
-
applicationId,
|
|
27
35
|
configuration,
|
|
28
36
|
lifeCycle,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
37
|
+
sessionManager,
|
|
38
|
+
userSessionManager,
|
|
39
|
+
viewContexts,
|
|
40
|
+
urlContexts,
|
|
41
|
+
actionContexts,
|
|
42
|
+
getCommonContext,
|
|
43
|
+
reportError
|
|
32
44
|
) {
|
|
33
|
-
var
|
|
34
|
-
|
|
35
|
-
|
|
45
|
+
var eventRateLimiters = {
|
|
46
|
+
}
|
|
47
|
+
eventRateLimiters[RumEventType.ERROR] = createEventRateLimiter(
|
|
48
|
+
RumEventType.ERROR,
|
|
49
|
+
configuration.eventRateLimiterThreshold,
|
|
50
|
+
reportError
|
|
51
|
+
)
|
|
52
|
+
eventRateLimiters[RumEventType.ACTION] = createEventRateLimiter(
|
|
53
|
+
RumEventType.ACTION,
|
|
54
|
+
configuration.eventRateLimiterThreshold,
|
|
55
|
+
reportError
|
|
56
|
+
)
|
|
36
57
|
lifeCycle.subscribe(
|
|
37
58
|
LifeCycleEventType.RAW_RUM_EVENT_COLLECTED,
|
|
38
59
|
function (data) {
|
|
@@ -40,63 +61,59 @@ export function startRumAssembly(
|
|
|
40
61
|
var rawRumEvent = data.rawRumEvent
|
|
41
62
|
var savedCommonContext = data.savedCommonContext
|
|
42
63
|
var customerContext = data.customerContext
|
|
43
|
-
var
|
|
44
|
-
var
|
|
45
|
-
|
|
46
|
-
|
|
64
|
+
var domainContext = data.domainContext
|
|
65
|
+
var viewContext = viewContexts.findView(startTime)
|
|
66
|
+
var urlContext = urlContexts.findUrl(startTime)
|
|
67
|
+
var session = sessionManager.findTrackedSession(rawRumEvent.type !== RumEventType.VIEW ? startTime : undefined)
|
|
47
68
|
if (
|
|
48
|
-
session
|
|
69
|
+
session &&
|
|
49
70
|
viewContext &&
|
|
50
|
-
|
|
71
|
+
urlContext
|
|
51
72
|
) {
|
|
52
|
-
var
|
|
73
|
+
var actionId = actionContexts.findActionId(startTime)
|
|
53
74
|
var commonContext = savedCommonContext || getCommonContext()
|
|
54
75
|
var rumContext = {
|
|
55
76
|
_dd: {
|
|
56
77
|
sdkName: configuration.sdkName,
|
|
57
78
|
sdkVersion: configuration.sdkVersion,
|
|
58
|
-
|
|
59
|
-
version: configuration.version,
|
|
60
|
-
service: configuration.service,
|
|
79
|
+
drift: currentDrift()
|
|
61
80
|
},
|
|
62
81
|
terminal: {
|
|
63
82
|
type: 'web'
|
|
64
83
|
},
|
|
65
84
|
application: {
|
|
66
|
-
id: applicationId
|
|
85
|
+
id: configuration.applicationId
|
|
67
86
|
},
|
|
68
|
-
device:
|
|
87
|
+
device: deviceInfo,
|
|
88
|
+
env: configuration.env || '',
|
|
89
|
+
service: viewContext.service || configuration.service || 'browser',
|
|
90
|
+
version: viewContext.version || configuration.version || '',
|
|
69
91
|
source: 'browser',
|
|
70
92
|
date: timeStampNow(),
|
|
71
93
|
user: {
|
|
72
|
-
id:
|
|
94
|
+
id: userSessionManager.getId(),
|
|
73
95
|
is_signin: 'F'
|
|
74
96
|
},
|
|
75
97
|
session: {
|
|
76
98
|
// must be computed on each event because synthetics instrumentation can be done after sdk execution
|
|
77
99
|
// cf https://github.com/puppeteer/puppeteer/issues/3667
|
|
78
100
|
type: getSessionType(),
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
101
|
+
id: session.id,
|
|
102
|
+
},
|
|
103
|
+
view: {
|
|
104
|
+
id: viewContext.id,
|
|
105
|
+
name: viewContext.name,
|
|
106
|
+
url: urlContext.url,
|
|
107
|
+
referrer: urlContext.referrer,
|
|
108
|
+
host: urlContext.host,
|
|
109
|
+
path: urlContext.path,
|
|
110
|
+
pathGroup: urlContext.pathGroup,
|
|
111
|
+
urlQuery: urlContext.urlQuery
|
|
112
|
+
},
|
|
113
|
+
action: needToAssembleWithAction(rawRumEvent) && actionId ? { id: actionId } : undefined,
|
|
89
114
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
rumContext,
|
|
93
|
-
deviceContext,
|
|
94
|
-
sessionAliasTag,
|
|
95
|
-
viewContext,
|
|
96
|
-
actionContext,
|
|
97
|
-
rawRumEvent
|
|
98
|
-
)
|
|
99
|
-
: extend2Lev(rumContext, deviceContext, sessionAliasTag, viewContext, rawRumEvent)
|
|
115
|
+
|
|
116
|
+
var rumEvent = extend2Lev(rumContext, viewContext, rawRumEvent)
|
|
100
117
|
var serverRumEvent = withSnakeCaseKeys(rumEvent)
|
|
101
118
|
var context = extend2Lev({},commonContext.context, customerContext)
|
|
102
119
|
if (!isEmptyObject(context)) {
|
|
@@ -109,19 +126,24 @@ export function startRumAssembly(
|
|
|
109
126
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
110
127
|
serverRumEvent.user = extend2Lev(
|
|
111
128
|
{
|
|
112
|
-
id: session.getAnonymousID(),
|
|
129
|
+
// id: session.getAnonymousID(),
|
|
113
130
|
is_signin: 'T'
|
|
114
131
|
},
|
|
115
132
|
commonContext.user
|
|
116
133
|
)
|
|
117
134
|
}
|
|
118
135
|
|
|
119
|
-
if (shouldSend(serverRumEvent, configuration.beforeSend,
|
|
136
|
+
if (shouldSend(serverRumEvent, configuration.beforeSend, eventRateLimiters, domainContext)) {
|
|
137
|
+
|
|
138
|
+
if (isEmptyObject(serverRumEvent.tags)) {
|
|
139
|
+
delete serverRumEvent.tags
|
|
140
|
+
}
|
|
120
141
|
// if (
|
|
121
|
-
// serverRumEvent.type === '
|
|
142
|
+
// serverRumEvent.type === 'error'
|
|
122
143
|
// ) {
|
|
123
144
|
// console.log(serverRumEvent, '======serverRumEvent-====')
|
|
124
145
|
// }
|
|
146
|
+
// console.log('======serverRumEvent-====', serverRumEvent )
|
|
125
147
|
lifeCycle.notify(
|
|
126
148
|
LifeCycleEventType.RUM_EVENT_COLLECTED,
|
|
127
149
|
serverRumEvent
|
|
@@ -132,24 +154,25 @@ export function startRumAssembly(
|
|
|
132
154
|
)
|
|
133
155
|
}
|
|
134
156
|
|
|
135
|
-
function shouldSend(event, beforeSend,
|
|
157
|
+
function shouldSend(event, beforeSend, eventRateLimiters, domainContext) {
|
|
136
158
|
if (beforeSend) {
|
|
137
159
|
var result = limitModification(
|
|
138
160
|
event,
|
|
139
|
-
|
|
140
|
-
beforeSend
|
|
161
|
+
event.type === RumEventType.VIEW ? VIEW_EVENTS_MODIFIABLE_FIELD_PATHS : OTHER_EVENTS_MODIFIABLE_FIELD_PATHS,
|
|
162
|
+
function(event) { return beforeSend(event, domainContext) }
|
|
141
163
|
)
|
|
142
164
|
if (result === false && event.type !== RumEventType.VIEW) {
|
|
143
165
|
return false
|
|
144
166
|
}
|
|
145
167
|
if (result === false) {
|
|
146
|
-
|
|
168
|
+
display.warn("Can't dismiss view events using beforeSend!")
|
|
147
169
|
}
|
|
148
170
|
}
|
|
149
|
-
|
|
150
|
-
|
|
171
|
+
var rateLimitReached = false
|
|
172
|
+
if (eventRateLimiters[event.type]) {
|
|
173
|
+
rateLimitReached = eventRateLimiters[event.type].isLimitReached()
|
|
151
174
|
}
|
|
152
|
-
return
|
|
175
|
+
return !rateLimitReached
|
|
153
176
|
}
|
|
154
177
|
function needToAssembleWithAction(event) {
|
|
155
178
|
return (
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assign,
|
|
3
|
+
display,
|
|
4
|
+
isPercentage,
|
|
5
|
+
validateAndBuildConfiguration,
|
|
6
|
+
isArray,
|
|
7
|
+
TraceType,
|
|
8
|
+
isNullUndefinedDefaultValue
|
|
9
|
+
} from '@cloudcare/browser-core'
|
|
10
|
+
import { buildEnv } from '../boot/buildEnv'
|
|
11
|
+
|
|
12
|
+
export function validateAndBuildRumConfiguration(initConfiguration) {
|
|
13
|
+
if (!initConfiguration.applicationId) {
|
|
14
|
+
display.error(
|
|
15
|
+
'Application ID is not configured, no RUM data will be collected.'
|
|
16
|
+
)
|
|
17
|
+
return
|
|
18
|
+
}
|
|
19
|
+
if (!initConfiguration.datakitUrl && !initConfiguration.datakitOrigin) {
|
|
20
|
+
display.error(
|
|
21
|
+
'datakitOrigin is not configured, no RUM data will be collected.'
|
|
22
|
+
)
|
|
23
|
+
return false
|
|
24
|
+
}
|
|
25
|
+
// TODO remove fallback in next major
|
|
26
|
+
if (
|
|
27
|
+
initConfiguration.sessionReplaySampleRate !== undefined &&
|
|
28
|
+
!isPercentage(initConfiguration.sessionReplaySampleRate)
|
|
29
|
+
) {
|
|
30
|
+
display.error('Premium Sample Rate should be a number between 0 and 100')
|
|
31
|
+
return
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (initConfiguration.allowedTracingOrigins !== undefined) {
|
|
35
|
+
if (!isArray(initConfiguration.allowedTracingOrigins)) {
|
|
36
|
+
display.error('Allowed Tracing Origins should be an array')
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (initConfiguration.allowedDDTracingOrigins !== undefined) {
|
|
41
|
+
if (!isArray(initConfiguration.allowedDDTracingOrigins)) {
|
|
42
|
+
display.error('Allowed Tracing Origins should be an array')
|
|
43
|
+
return
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (
|
|
47
|
+
initConfiguration.excludedActivityUrls !== undefined &&
|
|
48
|
+
!isArray(initConfiguration.excludedActivityUrls)
|
|
49
|
+
) {
|
|
50
|
+
display.error('Excluded Activity Urls should be an array')
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
var baseConfiguration = validateAndBuildConfiguration(initConfiguration)
|
|
55
|
+
if (!baseConfiguration) {
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
var trackFrustrations = !!initConfiguration.trackFrustrations
|
|
60
|
+
|
|
61
|
+
return assign(
|
|
62
|
+
{
|
|
63
|
+
applicationId: initConfiguration.applicationId,
|
|
64
|
+
actionNameAttribute: initConfiguration.actionNameAttribute,
|
|
65
|
+
sessionReplaySampleRate: isNullUndefinedDefaultValue(
|
|
66
|
+
initConfiguration.sessionReplaySampleRate,
|
|
67
|
+
100
|
|
68
|
+
),
|
|
69
|
+
allowedTracingOrigins: isNullUndefinedDefaultValue(
|
|
70
|
+
initConfiguration.allowedTracingOrigins ||
|
|
71
|
+
initConfiguration.allowedDDTracingOrigins,
|
|
72
|
+
[]
|
|
73
|
+
),
|
|
74
|
+
excludedActivityUrls: isNullUndefinedDefaultValue(
|
|
75
|
+
initConfiguration.excludedActivityUrls,
|
|
76
|
+
[]
|
|
77
|
+
),
|
|
78
|
+
trackInteractions:
|
|
79
|
+
!!initConfiguration.trackInteractions || trackFrustrations,
|
|
80
|
+
trackFrustrations: trackFrustrations,
|
|
81
|
+
trackViewsManually: !!initConfiguration.trackViewsManually,
|
|
82
|
+
traceType: isNullUndefinedDefaultValue(
|
|
83
|
+
initConfiguration.traceType,
|
|
84
|
+
TraceType.DDTRACE
|
|
85
|
+
),
|
|
86
|
+
traceId128Bit: !!initConfiguration.traceId128Bit,
|
|
87
|
+
isJsBirdge: !!initConfiguration.isJsBirdge // 是否需要对webview 发送数据,需要装我们对应ios sdk
|
|
88
|
+
},
|
|
89
|
+
baseConfiguration,
|
|
90
|
+
buildEnv
|
|
91
|
+
)
|
|
92
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal context keep returning v1 format
|
|
3
|
+
* to not break compatibility with logs data format
|
|
4
|
+
*/
|
|
5
|
+
export function startInternalContext(applicationId, sessionManager, viewContexts, actionContexts, urlContexts) {
|
|
6
|
+
return {
|
|
7
|
+
get: function (startTime) {
|
|
8
|
+
var viewContext = viewContexts.findView(startTime)
|
|
9
|
+
var urlContext = urlContexts.findUrl(startTime)
|
|
10
|
+
var session = sessionManager.findTrackedSession(startTime)
|
|
11
|
+
if (session && viewContext && urlContext) {
|
|
12
|
+
var actionId = actionContexts.findActionId(startTime)
|
|
13
|
+
return {
|
|
14
|
+
application: {
|
|
15
|
+
id: applicationId
|
|
16
|
+
},
|
|
17
|
+
session: {
|
|
18
|
+
id: session.id
|
|
19
|
+
},
|
|
20
|
+
userAction: actionId
|
|
21
|
+
? {
|
|
22
|
+
id: actionId
|
|
23
|
+
}
|
|
24
|
+
: undefined,
|
|
25
|
+
view: {
|
|
26
|
+
id: viewContext.id,
|
|
27
|
+
name: viewContext.name,
|
|
28
|
+
url: urlContext.url,
|
|
29
|
+
referrer: urlContext.referrer,
|
|
30
|
+
host: urlContext.host,
|
|
31
|
+
path: urlContext.pathname,
|
|
32
|
+
pathGroup: urlContext.pathGroup,
|
|
33
|
+
urlQuery: urlContext.urlQuery
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { LifeCycleEventType, SESSION_TIME_OUT_DELAY, relativeNow, ContextHistory, replaceNumberCharByPath, jsonStringify, getQueryParamsFromUrl } from '@cloudcare/browser-core'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* We want to attach to an event:
|
|
5
|
+
* - the url corresponding to its start
|
|
6
|
+
* - the referrer corresponding to the previous view url (or document referrer for initial view)
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export var URL_CONTEXT_TIME_OUT_DELAY = SESSION_TIME_OUT_DELAY
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
export function startUrlContexts(
|
|
13
|
+
lifeCycle,
|
|
14
|
+
locationChangeObservable,
|
|
15
|
+
location
|
|
16
|
+
) {
|
|
17
|
+
var urlContextHistory = new ContextHistory(URL_CONTEXT_TIME_OUT_DELAY)
|
|
18
|
+
|
|
19
|
+
var previousViewUrl
|
|
20
|
+
|
|
21
|
+
lifeCycle.subscribe(LifeCycleEventType.VIEW_ENDED, function(data) {
|
|
22
|
+
urlContextHistory.closeActive(data.endClocks.relative)
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
lifeCycle.subscribe(LifeCycleEventType.VIEW_CREATED, function(data ){
|
|
26
|
+
var viewUrl = location.href
|
|
27
|
+
urlContextHistory.add(
|
|
28
|
+
buildUrlContext({
|
|
29
|
+
url: viewUrl,
|
|
30
|
+
location: location,
|
|
31
|
+
referrer: !previousViewUrl ? document.referrer : previousViewUrl,
|
|
32
|
+
}),
|
|
33
|
+
data.startClocks.relative
|
|
34
|
+
)
|
|
35
|
+
previousViewUrl = viewUrl
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
var locationChangeSubscription = locationChangeObservable.subscribe(function(data) {
|
|
39
|
+
var current = urlContextHistory.find()
|
|
40
|
+
if (current) {
|
|
41
|
+
var changeTime = relativeNow()
|
|
42
|
+
urlContextHistory.closeActive(changeTime)
|
|
43
|
+
urlContextHistory.add(
|
|
44
|
+
buildUrlContext({
|
|
45
|
+
url: data.newLocation.href,
|
|
46
|
+
location: data.newLocation,
|
|
47
|
+
referrer: current.referrer,
|
|
48
|
+
}),
|
|
49
|
+
changeTime
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
function buildUrlContext(data) {
|
|
55
|
+
return {
|
|
56
|
+
url: data.url,
|
|
57
|
+
referrer: data.referrer,
|
|
58
|
+
host: data.location.host,
|
|
59
|
+
path: data.location.pathname,
|
|
60
|
+
pathGroup: replaceNumberCharByPath(data.location.pathname),
|
|
61
|
+
urlQuery: jsonStringify(
|
|
62
|
+
getQueryParamsFromUrl(data.location.href)
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
findUrl: function(startTime){
|
|
69
|
+
return urlContextHistory.find(startTime)
|
|
70
|
+
},
|
|
71
|
+
stop: function(){
|
|
72
|
+
locationChangeSubscription.unsubscribe()
|
|
73
|
+
urlContextHistory.stop()
|
|
74
|
+
},
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { SESSION_TIME_OUT_DELAY, ContextHistory, LifeCycleEventType } from '@cloudcare/browser-core'
|
|
2
|
+
|
|
3
|
+
export var VIEW_CONTEXT_TIME_OUT_DELAY = SESSION_TIME_OUT_DELAY
|
|
4
|
+
|
|
5
|
+
export function startViewContexts(lifeCycle) {
|
|
6
|
+
var viewContextHistory = new ContextHistory(VIEW_CONTEXT_TIME_OUT_DELAY)
|
|
7
|
+
|
|
8
|
+
lifeCycle.subscribe(LifeCycleEventType.VIEW_CREATED, function(view){
|
|
9
|
+
viewContextHistory.add(buildViewContext(view), view.startClocks.relative)
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
lifeCycle.subscribe(LifeCycleEventType.VIEW_ENDED, function(data) {
|
|
13
|
+
viewContextHistory.closeActive(data.endClocks.relative)
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
lifeCycle.subscribe(LifeCycleEventType.SESSION_RENEWED, function() {
|
|
17
|
+
viewContextHistory.reset()
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
function buildViewContext(view) {
|
|
21
|
+
return {
|
|
22
|
+
service: view.service,
|
|
23
|
+
version: view.version,
|
|
24
|
+
id: view.id,
|
|
25
|
+
name: view.name,
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
findView: function(startTime) {
|
|
31
|
+
return viewContextHistory.find(startTime)
|
|
32
|
+
},
|
|
33
|
+
stop: function() {
|
|
34
|
+
viewContextHistory.stop()
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -1,53 +1,69 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { noop, Observable } from '@cloudcare/browser-core'
|
|
2
2
|
|
|
3
|
-
function
|
|
3
|
+
export function createDOMMutationObservable() {
|
|
4
|
+
var MutationObserver = getMutationObserverConstructor()
|
|
5
|
+
|
|
6
|
+
var observable = new Observable(function () {
|
|
7
|
+
if (!MutationObserver) {
|
|
8
|
+
return
|
|
9
|
+
}
|
|
10
|
+
var observer = new MutationObserver(function () {
|
|
11
|
+
return observable.notify()
|
|
12
|
+
})
|
|
13
|
+
observer.observe(document, {
|
|
14
|
+
attributes: true,
|
|
15
|
+
characterData: true,
|
|
16
|
+
childList: true,
|
|
17
|
+
subtree: true
|
|
18
|
+
})
|
|
19
|
+
return function () {
|
|
20
|
+
return observer.disconnect()
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
return observable
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function getMutationObserverConstructor() {
|
|
4
27
|
var constructor
|
|
5
28
|
var browserWindow = window
|
|
6
29
|
|
|
7
|
-
// Angular uses Zone.js to provide a context persisting
|
|
30
|
+
// Angular uses Zone.js to provide a context persisting across async tasks. Zone.js replaces the
|
|
8
31
|
// global MutationObserver constructor with a patched version to support the context propagation.
|
|
9
32
|
// There is an ongoing issue[1][2] with this setup when using a MutationObserver within a Angular
|
|
10
33
|
// component: on some occasions, the callback is being called in an infinite loop, causing the
|
|
11
34
|
// page to freeze (even if the callback is completely empty).
|
|
12
35
|
//
|
|
13
|
-
// To work around this issue, we
|
|
14
|
-
//
|
|
36
|
+
// To work around this issue, we try to get the original MutationObserver constructor stored by
|
|
37
|
+
// Zone.js.
|
|
15
38
|
//
|
|
16
39
|
// [1] https://github.com/angular/angular/issues/26948
|
|
17
40
|
// [2] https://github.com/angular/angular/issues/31712
|
|
18
41
|
if (browserWindow.Zone) {
|
|
19
|
-
var
|
|
20
|
-
constructor = browserWindow[symbol]
|
|
21
|
-
}
|
|
42
|
+
var zoneSymbol = browserWindow.Zone.__symbol__
|
|
22
43
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
44
|
+
// Zone.js 0.8.6+ is storing original class constructors into the browser 'window' object[3].
|
|
45
|
+
//
|
|
46
|
+
// [3] https://github.com/angular/angular/blob/6375fa79875c0fe7b815efc45940a6e6f5c9c9eb/packages/zone.js/lib/common/utils.ts#L288
|
|
47
|
+
constructor = browserWindow[zoneSymbol('MutationObserver')]
|
|
26
48
|
|
|
27
|
-
|
|
28
|
-
|
|
49
|
+
if (!constructor && browserWindow.MutationObserver) {
|
|
50
|
+
// Anterior Zone.js versions (used in Angular 2) does not expose the original MutationObserver
|
|
51
|
+
// in the 'window' object. Luckily, the patched MutationObserver class is storing an original
|
|
52
|
+
// instance in its properties[4]. Let's get the original MutationObserver constructor from
|
|
53
|
+
// there.
|
|
54
|
+
//
|
|
55
|
+
// [4] https://github.com/angular/zone.js/blob/v0.8.5/lib/common/utils.ts#L412
|
|
29
56
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
var MutationObserver = getMutationObserverConstructor()
|
|
33
|
-
if (MutationObserver) {
|
|
34
|
-
observer = new MutationObserver(function () {
|
|
35
|
-
lifeCycle.notify(LifeCycleEventType.DOM_MUTATED)
|
|
36
|
-
})
|
|
57
|
+
var patchedInstance = new browserWindow.MutationObserver(noop)
|
|
58
|
+
var originalInstance = patchedInstance[zoneSymbol('originalInstance')]
|
|
37
59
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
characterData: true,
|
|
41
|
-
childList: true,
|
|
42
|
-
subtree: true
|
|
43
|
-
})
|
|
60
|
+
constructor = originalInstance && originalInstance.constructor
|
|
61
|
+
}
|
|
44
62
|
}
|
|
45
63
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (observer) {
|
|
49
|
-
observer.disconnect()
|
|
50
|
-
}
|
|
51
|
-
}
|
|
64
|
+
if (!constructor) {
|
|
65
|
+
constructor = browserWindow.MutationObserver
|
|
52
66
|
}
|
|
67
|
+
|
|
68
|
+
return constructor
|
|
53
69
|
}
|
package/src/domain/{rumEventsCollection/view/trackLocationChanges.js → locationChangeObservable.js}
RENAMED
|
@@ -1,24 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import {
|
|
2
|
+
addEventListener,
|
|
3
|
+
DOM_EVENT,
|
|
4
|
+
Observable,
|
|
5
|
+
shallowClone,
|
|
6
|
+
} from '@cloudcare/browser-core'
|
|
7
|
+
|
|
8
|
+
export function createLocationChangeObservable(location) {
|
|
9
|
+
var currentLocation = shallowClone(location)
|
|
10
|
+
var observable = new Observable(function(){
|
|
11
|
+
var _trackHistory = trackHistory(onLocationChange)
|
|
12
|
+
var _trackHash = trackHash(onLocationChange)
|
|
13
|
+
return function() {
|
|
14
|
+
_trackHistory.stop()
|
|
15
|
+
_trackHash.stop()
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
function onLocationChange() {
|
|
20
|
+
if (currentLocation.href === location.href) {
|
|
21
|
+
return
|
|
11
22
|
}
|
|
23
|
+
var newLocation = shallowClone(location)
|
|
24
|
+
observable.notify({
|
|
25
|
+
newLocation: newLocation,
|
|
26
|
+
oldLocation: currentLocation,
|
|
27
|
+
})
|
|
28
|
+
currentLocation = newLocation
|
|
12
29
|
}
|
|
13
|
-
}
|
|
14
30
|
|
|
15
|
-
|
|
16
|
-
return (
|
|
17
|
-
currentLocation.pathname !== otherLocation.pathname ||
|
|
18
|
-
(!isHashAnAnchor(otherLocation.hash) &&
|
|
19
|
-
getPathFromHash(otherLocation.hash) !==
|
|
20
|
-
getPathFromHash(currentLocation.hash))
|
|
21
|
-
)
|
|
31
|
+
return observable
|
|
22
32
|
}
|
|
23
33
|
|
|
24
34
|
function trackHistory(onHistoryChange) {
|
|
@@ -52,13 +62,3 @@ function trackHistory(onHistoryChange) {
|
|
|
52
62
|
function trackHash(onHashChange) {
|
|
53
63
|
return addEventListener(window, DOM_EVENT.HASH_CHANGE, onHashChange)
|
|
54
64
|
}
|
|
55
|
-
|
|
56
|
-
function isHashAnAnchor(hash) {
|
|
57
|
-
var correspondingId = hash.substr(1)
|
|
58
|
-
return !!document.getElementById(correspondingId)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function getPathFromHash(hash) {
|
|
62
|
-
var index = hash.indexOf('?')
|
|
63
|
-
return index < 0 ? hash : hash.slice(0, index)
|
|
64
|
-
}
|