@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/esm/domain/assembly.js
CHANGED
|
@@ -1,67 +1,72 @@
|
|
|
1
|
-
import { extend2Lev, withSnakeCaseKeys, timeStampNow, isEmptyObject, LifeCycleEventType, RumEventType, deviceInfo,
|
|
1
|
+
import { extend2Lev, withSnakeCaseKeys, timeStampNow, isEmptyObject, LifeCycleEventType, RumEventType, deviceInfo, currentDrift, createEventRateLimiter, limitModification, display } from '@cloudcare/browser-core';
|
|
2
2
|
var SessionType = {
|
|
3
3
|
SYNTHETICS: 'synthetics',
|
|
4
4
|
USER: 'user'
|
|
5
5
|
};
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
var VIEW_EVENTS_MODIFIABLE_FIELD_PATHS = [// Fields with sensitive data
|
|
7
|
+
'view.url', 'view.referrer', 'action.target.name', 'error.message', 'error.stack', 'error.resource.url', 'resource.url'];
|
|
8
|
+
var OTHER_EVENTS_MODIFIABLE_FIELD_PATHS = VIEW_EVENTS_MODIFIABLE_FIELD_PATHS.concat([// User-customizable field
|
|
9
|
+
'tags']);
|
|
10
|
+
export function startRumAssembly(configuration, lifeCycle, sessionManager, userSessionManager, viewContexts, urlContexts, actionContexts, getCommonContext, reportError) {
|
|
11
|
+
var eventRateLimiters = {};
|
|
12
|
+
eventRateLimiters[RumEventType.ERROR] = createEventRateLimiter(RumEventType.ERROR, configuration.eventRateLimiterThreshold, reportError);
|
|
13
|
+
eventRateLimiters[RumEventType.ACTION] = createEventRateLimiter(RumEventType.ACTION, configuration.eventRateLimiterThreshold, reportError);
|
|
13
14
|
lifeCycle.subscribe(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, function (data) {
|
|
14
15
|
var startTime = data.startTime;
|
|
15
16
|
var rawRumEvent = data.rawRumEvent;
|
|
16
17
|
var savedCommonContext = data.savedCommonContext;
|
|
17
18
|
var customerContext = data.customerContext;
|
|
18
|
-
var
|
|
19
|
-
var
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
var domainContext = data.domainContext;
|
|
20
|
+
var viewContext = viewContexts.findView(startTime);
|
|
21
|
+
var urlContext = urlContexts.findUrl(startTime);
|
|
22
|
+
var session = sessionManager.findTrackedSession(rawRumEvent.type !== RumEventType.VIEW ? startTime : undefined);
|
|
22
23
|
|
|
23
|
-
if (session
|
|
24
|
-
var
|
|
24
|
+
if (session && viewContext && urlContext) {
|
|
25
|
+
var actionId = actionContexts.findActionId(startTime);
|
|
25
26
|
var commonContext = savedCommonContext || getCommonContext();
|
|
26
27
|
var rumContext = {
|
|
27
28
|
_dd: {
|
|
28
29
|
sdkName: configuration.sdkName,
|
|
29
30
|
sdkVersion: configuration.sdkVersion,
|
|
30
|
-
|
|
31
|
-
version: configuration.version,
|
|
32
|
-
service: configuration.service
|
|
31
|
+
drift: currentDrift()
|
|
33
32
|
},
|
|
34
33
|
terminal: {
|
|
35
34
|
type: 'web'
|
|
36
35
|
},
|
|
37
36
|
application: {
|
|
38
|
-
id: applicationId
|
|
37
|
+
id: configuration.applicationId
|
|
39
38
|
},
|
|
40
|
-
device:
|
|
39
|
+
device: deviceInfo,
|
|
40
|
+
env: configuration.env || '',
|
|
41
|
+
service: viewContext.service || configuration.service || 'browser',
|
|
42
|
+
version: viewContext.version || configuration.version || '',
|
|
41
43
|
source: 'browser',
|
|
42
44
|
date: timeStampNow(),
|
|
43
45
|
user: {
|
|
44
|
-
id:
|
|
46
|
+
id: userSessionManager.getId(),
|
|
45
47
|
is_signin: 'F'
|
|
46
48
|
},
|
|
47
49
|
session: {
|
|
48
50
|
// must be computed on each event because synthetics instrumentation can be done after sdk execution
|
|
49
51
|
// cf https://github.com/puppeteer/puppeteer/issues/3667
|
|
50
|
-
type: getSessionType()
|
|
51
|
-
|
|
52
|
+
type: getSessionType(),
|
|
53
|
+
id: session.id
|
|
54
|
+
},
|
|
55
|
+
view: {
|
|
56
|
+
id: viewContext.id,
|
|
57
|
+
name: viewContext.name,
|
|
58
|
+
url: urlContext.url,
|
|
59
|
+
referrer: urlContext.referrer,
|
|
60
|
+
host: urlContext.host,
|
|
61
|
+
path: urlContext.path,
|
|
62
|
+
pathGroup: urlContext.pathGroup,
|
|
63
|
+
urlQuery: urlContext.urlQuery
|
|
64
|
+
},
|
|
65
|
+
action: needToAssembleWithAction(rawRumEvent) && actionId ? {
|
|
66
|
+
id: actionId
|
|
67
|
+
} : undefined
|
|
52
68
|
};
|
|
53
|
-
var
|
|
54
|
-
|
|
55
|
-
if (session.isTrackedWidthService()) {
|
|
56
|
-
// 如果是触发了采样的数据,则加上额外的tag
|
|
57
|
-
sessionAliasTag = {
|
|
58
|
-
session: {
|
|
59
|
-
is_sampling: '1'
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
var rumEvent = needToAssembleWithAction(rawRumEvent) ? extend2Lev(rumContext, deviceContext, sessionAliasTag, viewContext, actionContext, rawRumEvent) : extend2Lev(rumContext, deviceContext, sessionAliasTag, viewContext, rawRumEvent);
|
|
69
|
+
var rumEvent = extend2Lev(rumContext, viewContext, rawRumEvent);
|
|
65
70
|
var serverRumEvent = withSnakeCaseKeys(rumEvent);
|
|
66
71
|
var context = extend2Lev({}, commonContext.context, customerContext);
|
|
67
72
|
|
|
@@ -76,41 +81,50 @@ export function startRumAssembly(applicationId, configuration, lifeCycle, sessio
|
|
|
76
81
|
if (!isEmptyObject(commonContext.user)) {
|
|
77
82
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
78
83
|
serverRumEvent.user = extend2Lev({
|
|
79
|
-
id: session.getAnonymousID(),
|
|
84
|
+
// id: session.getAnonymousID(),
|
|
80
85
|
is_signin: 'T'
|
|
81
86
|
}, commonContext.user);
|
|
82
87
|
}
|
|
83
88
|
|
|
84
|
-
if (shouldSend(serverRumEvent, configuration.beforeSend,
|
|
85
|
-
|
|
86
|
-
|
|
89
|
+
if (shouldSend(serverRumEvent, configuration.beforeSend, eventRateLimiters, domainContext)) {
|
|
90
|
+
if (isEmptyObject(serverRumEvent.tags)) {
|
|
91
|
+
delete serverRumEvent.tags;
|
|
92
|
+
} // if (
|
|
93
|
+
// serverRumEvent.type === 'error'
|
|
87
94
|
// ) {
|
|
88
95
|
// console.log(serverRumEvent, '======serverRumEvent-====')
|
|
89
96
|
// }
|
|
97
|
+
// console.log('======serverRumEvent-====', serverRumEvent )
|
|
98
|
+
|
|
99
|
+
|
|
90
100
|
lifeCycle.notify(LifeCycleEventType.RUM_EVENT_COLLECTED, serverRumEvent);
|
|
91
101
|
}
|
|
92
102
|
}
|
|
93
103
|
});
|
|
94
104
|
}
|
|
95
105
|
|
|
96
|
-
function shouldSend(event, beforeSend,
|
|
106
|
+
function shouldSend(event, beforeSend, eventRateLimiters, domainContext) {
|
|
97
107
|
if (beforeSend) {
|
|
98
|
-
var result = limitModification(event,
|
|
108
|
+
var result = limitModification(event, event.type === RumEventType.VIEW ? VIEW_EVENTS_MODIFIABLE_FIELD_PATHS : OTHER_EVENTS_MODIFIABLE_FIELD_PATHS, function (event) {
|
|
109
|
+
return beforeSend(event, domainContext);
|
|
110
|
+
});
|
|
99
111
|
|
|
100
112
|
if (result === false && event.type !== RumEventType.VIEW) {
|
|
101
113
|
return false;
|
|
102
114
|
}
|
|
103
115
|
|
|
104
116
|
if (result === false) {
|
|
105
|
-
|
|
117
|
+
display.warn("Can't dismiss view events using beforeSend!");
|
|
106
118
|
}
|
|
107
119
|
}
|
|
108
120
|
|
|
109
|
-
|
|
110
|
-
|
|
121
|
+
var rateLimitReached = false;
|
|
122
|
+
|
|
123
|
+
if (eventRateLimiters[event.type]) {
|
|
124
|
+
rateLimitReached = eventRateLimiters[event.type].isLimitReached();
|
|
111
125
|
}
|
|
112
126
|
|
|
113
|
-
return
|
|
127
|
+
return !rateLimitReached;
|
|
114
128
|
}
|
|
115
129
|
|
|
116
130
|
function needToAssembleWithAction(event) {
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { assign, display, isPercentage, validateAndBuildConfiguration, isArray, TraceType, isNullUndefinedDefaultValue } from '@cloudcare/browser-core';
|
|
2
|
+
import { buildEnv } from '../boot/buildEnv';
|
|
3
|
+
export function validateAndBuildRumConfiguration(initConfiguration) {
|
|
4
|
+
if (!initConfiguration.applicationId) {
|
|
5
|
+
display.error('Application ID is not configured, no RUM data will be collected.');
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
if (!initConfiguration.datakitUrl && !initConfiguration.datakitOrigin) {
|
|
10
|
+
display.error('datakitOrigin is not configured, no RUM data will be collected.');
|
|
11
|
+
return false;
|
|
12
|
+
} // TODO remove fallback in next major
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
if (initConfiguration.sessionReplaySampleRate !== undefined && !isPercentage(initConfiguration.sessionReplaySampleRate)) {
|
|
16
|
+
display.error('Premium Sample Rate should be a number between 0 and 100');
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (initConfiguration.allowedTracingOrigins !== undefined) {
|
|
21
|
+
if (!isArray(initConfiguration.allowedTracingOrigins)) {
|
|
22
|
+
display.error('Allowed Tracing Origins should be an array');
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (initConfiguration.allowedDDTracingOrigins !== undefined) {
|
|
28
|
+
if (!isArray(initConfiguration.allowedDDTracingOrigins)) {
|
|
29
|
+
display.error('Allowed Tracing Origins should be an array');
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (initConfiguration.excludedActivityUrls !== undefined && !isArray(initConfiguration.excludedActivityUrls)) {
|
|
35
|
+
display.error('Excluded Activity Urls should be an array');
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
var baseConfiguration = validateAndBuildConfiguration(initConfiguration);
|
|
40
|
+
|
|
41
|
+
if (!baseConfiguration) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
var trackFrustrations = !!initConfiguration.trackFrustrations;
|
|
46
|
+
return assign({
|
|
47
|
+
applicationId: initConfiguration.applicationId,
|
|
48
|
+
actionNameAttribute: initConfiguration.actionNameAttribute,
|
|
49
|
+
sessionReplaySampleRate: isNullUndefinedDefaultValue(initConfiguration.sessionReplaySampleRate, 100),
|
|
50
|
+
allowedTracingOrigins: isNullUndefinedDefaultValue(initConfiguration.allowedTracingOrigins || initConfiguration.allowedDDTracingOrigins, []),
|
|
51
|
+
excludedActivityUrls: isNullUndefinedDefaultValue(initConfiguration.excludedActivityUrls, []),
|
|
52
|
+
trackInteractions: !!initConfiguration.trackInteractions || trackFrustrations,
|
|
53
|
+
trackFrustrations: trackFrustrations,
|
|
54
|
+
trackViewsManually: !!initConfiguration.trackViewsManually,
|
|
55
|
+
traceType: isNullUndefinedDefaultValue(initConfiguration.traceType, TraceType.DDTRACE),
|
|
56
|
+
traceId128Bit: !!initConfiguration.traceId128Bit,
|
|
57
|
+
isJsBirdge: !!initConfiguration.isJsBirdge // 是否需要对webview 发送数据,需要装我们对应ios sdk
|
|
58
|
+
|
|
59
|
+
}, baseConfiguration, buildEnv);
|
|
60
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
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 get(startTime) {
|
|
8
|
+
var viewContext = viewContexts.findView(startTime);
|
|
9
|
+
var urlContext = urlContexts.findUrl(startTime);
|
|
10
|
+
var session = sessionManager.findTrackedSession(startTime);
|
|
11
|
+
|
|
12
|
+
if (session && viewContext && urlContext) {
|
|
13
|
+
var actionId = actionContexts.findActionId(startTime);
|
|
14
|
+
return {
|
|
15
|
+
application: {
|
|
16
|
+
id: applicationId
|
|
17
|
+
},
|
|
18
|
+
session: {
|
|
19
|
+
id: session.id
|
|
20
|
+
},
|
|
21
|
+
userAction: actionId ? {
|
|
22
|
+
id: actionId
|
|
23
|
+
} : undefined,
|
|
24
|
+
view: {
|
|
25
|
+
id: viewContext.id,
|
|
26
|
+
name: viewContext.name,
|
|
27
|
+
url: urlContext.url,
|
|
28
|
+
referrer: urlContext.referrer,
|
|
29
|
+
host: urlContext.host,
|
|
30
|
+
path: urlContext.pathname,
|
|
31
|
+
pathGroup: urlContext.pathGroup,
|
|
32
|
+
urlQuery: urlContext.urlQuery
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { LifeCycleEventType, SESSION_TIME_OUT_DELAY, relativeNow, ContextHistory, replaceNumberCharByPath, jsonStringify, getQueryParamsFromUrl } from '@cloudcare/browser-core';
|
|
2
|
+
/**
|
|
3
|
+
* We want to attach to an event:
|
|
4
|
+
* - the url corresponding to its start
|
|
5
|
+
* - the referrer corresponding to the previous view url (or document referrer for initial view)
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export var URL_CONTEXT_TIME_OUT_DELAY = SESSION_TIME_OUT_DELAY;
|
|
9
|
+
export function startUrlContexts(lifeCycle, locationChangeObservable, location) {
|
|
10
|
+
var urlContextHistory = new ContextHistory(URL_CONTEXT_TIME_OUT_DELAY);
|
|
11
|
+
var previousViewUrl;
|
|
12
|
+
lifeCycle.subscribe(LifeCycleEventType.VIEW_ENDED, function (data) {
|
|
13
|
+
urlContextHistory.closeActive(data.endClocks.relative);
|
|
14
|
+
});
|
|
15
|
+
lifeCycle.subscribe(LifeCycleEventType.VIEW_CREATED, function (data) {
|
|
16
|
+
var viewUrl = location.href;
|
|
17
|
+
urlContextHistory.add(buildUrlContext({
|
|
18
|
+
url: viewUrl,
|
|
19
|
+
location: location,
|
|
20
|
+
referrer: !previousViewUrl ? document.referrer : previousViewUrl
|
|
21
|
+
}), data.startClocks.relative);
|
|
22
|
+
previousViewUrl = viewUrl;
|
|
23
|
+
});
|
|
24
|
+
var locationChangeSubscription = locationChangeObservable.subscribe(function (data) {
|
|
25
|
+
var current = urlContextHistory.find();
|
|
26
|
+
|
|
27
|
+
if (current) {
|
|
28
|
+
var changeTime = relativeNow();
|
|
29
|
+
urlContextHistory.closeActive(changeTime);
|
|
30
|
+
urlContextHistory.add(buildUrlContext({
|
|
31
|
+
url: data.newLocation.href,
|
|
32
|
+
location: data.newLocation,
|
|
33
|
+
referrer: current.referrer
|
|
34
|
+
}), changeTime);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
function buildUrlContext(data) {
|
|
39
|
+
return {
|
|
40
|
+
url: data.url,
|
|
41
|
+
referrer: data.referrer,
|
|
42
|
+
host: data.location.host,
|
|
43
|
+
path: data.location.pathname,
|
|
44
|
+
pathGroup: replaceNumberCharByPath(data.location.pathname),
|
|
45
|
+
urlQuery: jsonStringify(getQueryParamsFromUrl(data.location.href))
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
findUrl: function findUrl(startTime) {
|
|
51
|
+
return urlContextHistory.find(startTime);
|
|
52
|
+
},
|
|
53
|
+
stop: function stop() {
|
|
54
|
+
locationChangeSubscription.unsubscribe();
|
|
55
|
+
urlContextHistory.stop();
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { SESSION_TIME_OUT_DELAY, ContextHistory, LifeCycleEventType } from '@cloudcare/browser-core';
|
|
2
|
+
export var VIEW_CONTEXT_TIME_OUT_DELAY = SESSION_TIME_OUT_DELAY;
|
|
3
|
+
export function startViewContexts(lifeCycle) {
|
|
4
|
+
var viewContextHistory = new ContextHistory(VIEW_CONTEXT_TIME_OUT_DELAY);
|
|
5
|
+
lifeCycle.subscribe(LifeCycleEventType.VIEW_CREATED, function (view) {
|
|
6
|
+
viewContextHistory.add(buildViewContext(view), view.startClocks.relative);
|
|
7
|
+
});
|
|
8
|
+
lifeCycle.subscribe(LifeCycleEventType.VIEW_ENDED, function (data) {
|
|
9
|
+
viewContextHistory.closeActive(data.endClocks.relative);
|
|
10
|
+
});
|
|
11
|
+
lifeCycle.subscribe(LifeCycleEventType.SESSION_RENEWED, function () {
|
|
12
|
+
viewContextHistory.reset();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
function buildViewContext(view) {
|
|
16
|
+
return {
|
|
17
|
+
service: view.service,
|
|
18
|
+
version: view.version,
|
|
19
|
+
id: view.id,
|
|
20
|
+
name: view.name
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
findView: function findView(startTime) {
|
|
26
|
+
return viewContextHistory.find(startTime);
|
|
27
|
+
},
|
|
28
|
+
stop: function stop() {
|
|
29
|
+
viewContextHistory.stop();
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -1,23 +1,58 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { noop, Observable } from '@cloudcare/browser-core';
|
|
2
|
+
export function createDOMMutationObservable() {
|
|
3
|
+
var MutationObserver = getMutationObserverConstructor();
|
|
4
|
+
var observable = new Observable(function () {
|
|
5
|
+
if (!MutationObserver) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
2
8
|
|
|
3
|
-
function
|
|
9
|
+
var observer = new MutationObserver(function () {
|
|
10
|
+
return observable.notify();
|
|
11
|
+
});
|
|
12
|
+
observer.observe(document, {
|
|
13
|
+
attributes: true,
|
|
14
|
+
characterData: true,
|
|
15
|
+
childList: true,
|
|
16
|
+
subtree: true
|
|
17
|
+
});
|
|
18
|
+
return function () {
|
|
19
|
+
return observer.disconnect();
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
return observable;
|
|
23
|
+
}
|
|
24
|
+
export function getMutationObserverConstructor() {
|
|
4
25
|
var constructor;
|
|
5
|
-
var browserWindow = window; // Angular uses Zone.js to provide a context persisting
|
|
26
|
+
var browserWindow = window; // Angular uses Zone.js to provide a context persisting across async tasks. Zone.js replaces the
|
|
6
27
|
// global MutationObserver constructor with a patched version to support the context propagation.
|
|
7
28
|
// There is an ongoing issue[1][2] with this setup when using a MutationObserver within a Angular
|
|
8
29
|
// component: on some occasions, the callback is being called in an infinite loop, causing the
|
|
9
30
|
// page to freeze (even if the callback is completely empty).
|
|
10
31
|
//
|
|
11
|
-
// To work around this issue, we
|
|
12
|
-
//
|
|
32
|
+
// To work around this issue, we try to get the original MutationObserver constructor stored by
|
|
33
|
+
// Zone.js.
|
|
13
34
|
//
|
|
14
35
|
// [1] https://github.com/angular/angular/issues/26948
|
|
15
36
|
// [2] https://github.com/angular/angular/issues/31712
|
|
16
37
|
|
|
17
38
|
if (browserWindow.Zone) {
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
|
|
39
|
+
var zoneSymbol = browserWindow.Zone.__symbol__; // Zone.js 0.8.6+ is storing original class constructors into the browser 'window' object[3].
|
|
40
|
+
//
|
|
41
|
+
// [3] https://github.com/angular/angular/blob/6375fa79875c0fe7b815efc45940a6e6f5c9c9eb/packages/zone.js/lib/common/utils.ts#L288
|
|
42
|
+
|
|
43
|
+
constructor = browserWindow[zoneSymbol('MutationObserver')];
|
|
44
|
+
|
|
45
|
+
if (!constructor && browserWindow.MutationObserver) {
|
|
46
|
+
// Anterior Zone.js versions (used in Angular 2) does not expose the original MutationObserver
|
|
47
|
+
// in the 'window' object. Luckily, the patched MutationObserver class is storing an original
|
|
48
|
+
// instance in its properties[4]. Let's get the original MutationObserver constructor from
|
|
49
|
+
// there.
|
|
50
|
+
//
|
|
51
|
+
// [4] https://github.com/angular/zone.js/blob/v0.8.5/lib/common/utils.ts#L412
|
|
52
|
+
var patchedInstance = new browserWindow.MutationObserver(noop);
|
|
53
|
+
var originalInstance = patchedInstance[zoneSymbol('originalInstance')];
|
|
54
|
+
constructor = originalInstance && originalInstance.constructor;
|
|
55
|
+
}
|
|
21
56
|
}
|
|
22
57
|
|
|
23
58
|
if (!constructor) {
|
|
@@ -25,29 +60,4 @@ function getMutationObserverConstructor() {
|
|
|
25
60
|
}
|
|
26
61
|
|
|
27
62
|
return constructor;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function startDOMMutationCollection(lifeCycle) {
|
|
31
|
-
var observer;
|
|
32
|
-
var MutationObserver = getMutationObserverConstructor();
|
|
33
|
-
|
|
34
|
-
if (MutationObserver) {
|
|
35
|
-
observer = new MutationObserver(function () {
|
|
36
|
-
lifeCycle.notify(LifeCycleEventType.DOM_MUTATED);
|
|
37
|
-
});
|
|
38
|
-
observer.observe(document.documentElement, {
|
|
39
|
-
attributes: true,
|
|
40
|
-
characterData: true,
|
|
41
|
-
childList: true,
|
|
42
|
-
subtree: true
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return {
|
|
47
|
-
stop: function stop() {
|
|
48
|
-
if (observer) {
|
|
49
|
-
observer.disconnect();
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
63
|
}
|
package/esm/domain/{rumEventsCollection/view/trackLocationChanges.js → locationChangeObservable.js}
RENAMED
|
@@ -1,20 +1,32 @@
|
|
|
1
|
-
import { addEventListener, DOM_EVENT } from '@cloudcare/browser-core';
|
|
2
|
-
export function
|
|
3
|
-
var
|
|
1
|
+
import { addEventListener, DOM_EVENT, Observable, shallowClone } from '@cloudcare/browser-core';
|
|
2
|
+
export function createLocationChangeObservable(location) {
|
|
3
|
+
var currentLocation = shallowClone(location);
|
|
4
|
+
var observable = new Observable(function () {
|
|
5
|
+
var _trackHistory = trackHistory(onLocationChange);
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
var _trackHash = trackHash(onLocationChange);
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
return function () {
|
|
10
|
+
_trackHistory.stop();
|
|
11
|
+
|
|
12
|
+
_trackHash.stop();
|
|
13
|
+
};
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
function onLocationChange() {
|
|
17
|
+
if (currentLocation.href === location.href) {
|
|
18
|
+
return;
|
|
13
19
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
|
|
21
|
+
var newLocation = shallowClone(location);
|
|
22
|
+
observable.notify({
|
|
23
|
+
newLocation: newLocation,
|
|
24
|
+
oldLocation: currentLocation
|
|
25
|
+
});
|
|
26
|
+
currentLocation = newLocation;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return observable;
|
|
18
30
|
}
|
|
19
31
|
|
|
20
32
|
function trackHistory(onHistoryChange) {
|
|
@@ -51,14 +63,4 @@ function trackHistory(onHistoryChange) {
|
|
|
51
63
|
|
|
52
64
|
function trackHash(onHashChange) {
|
|
53
65
|
return addEventListener(window, DOM_EVENT.HASH_CHANGE, onHashChange);
|
|
54
|
-
}
|
|
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
66
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addEventListeners, addEventListener, getRelativeTime, isNumber, includes, each, extend, DOM_EVENT, LifeCycleEventType } from '@cloudcare/browser-core';
|
|
1
|
+
import { addEventListeners, addEventListener, getRelativeTime, isNumber, includes, each, extend, filter, dateNow, relativeNow, DOM_EVENT, LifeCycleEventType } from '@cloudcare/browser-core';
|
|
2
2
|
import { FAKE_INITIAL_DOCUMENT, isAllowedRequestUrl } from './rumEventsCollection/resource/resourceUtils';
|
|
3
3
|
|
|
4
4
|
function supportPerformanceObject() {
|
|
@@ -10,20 +10,48 @@ export function supportPerformanceTimingEvent(entryType) {
|
|
|
10
10
|
}
|
|
11
11
|
export function startPerformanceCollection(lifeCycle, configuration) {
|
|
12
12
|
retrieveInitialDocumentResourceTiming(function (timing) {
|
|
13
|
-
|
|
13
|
+
handleRumPerformanceEntries(lifeCycle, configuration, [timing]);
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
if (supportPerformanceObject()) {
|
|
17
|
-
|
|
17
|
+
var performanceEntries = performance.getEntries(); // Because the performance entry list can be quite large
|
|
18
|
+
// delay the computation to prevent the SDK from blocking the main thread on init
|
|
19
|
+
|
|
20
|
+
setTimeout(function () {
|
|
21
|
+
handleRumPerformanceEntries(lifeCycle, configuration, performanceEntries);
|
|
22
|
+
});
|
|
18
23
|
}
|
|
19
24
|
|
|
20
25
|
if (window.PerformanceObserver) {
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
var handlePerformanceEntryList = function handlePerformanceEntryList(entries) {
|
|
27
|
+
handleRumPerformanceEntries(lifeCycle, configuration, entries.getEntries());
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
var mainEntries = ['resource', 'navigation', 'longtask', 'paint'];
|
|
31
|
+
var experimentalEntries = ['largest-contentful-paint', 'first-input', 'layout-shift'];
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
// Experimental entries are not retrieved by performance.getEntries()
|
|
35
|
+
// use a single PerformanceObserver with buffered flag by type
|
|
36
|
+
// to get values that could happen before SDK init
|
|
37
|
+
each(experimentalEntries, function (type) {
|
|
38
|
+
var observer = new PerformanceObserver(handlePerformanceEntryList);
|
|
39
|
+
observer.observe({
|
|
40
|
+
type: type,
|
|
41
|
+
buffered: true
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
} catch (e) {
|
|
45
|
+
// Some old browser versions (ex: chrome 67) don't support the PerformanceObserver type and buffered options
|
|
46
|
+
// In these cases, fallback to PerformanceObserver with entryTypes
|
|
47
|
+
each(experimentalEntries, function (type) {
|
|
48
|
+
mainEntries.push(type);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
var mainObserver = new PerformanceObserver(handlePerformanceEntryList);
|
|
53
|
+
mainObserver.observe({
|
|
54
|
+
entryTypes: mainEntries
|
|
27
55
|
});
|
|
28
56
|
|
|
29
57
|
if (supportPerformanceObject() && 'addEventListener' in performance) {
|
|
@@ -36,13 +64,13 @@ export function startPerformanceCollection(lifeCycle, configuration) {
|
|
|
36
64
|
|
|
37
65
|
if (!supportPerformanceTimingEvent('navigation')) {
|
|
38
66
|
retrieveNavigationTiming(function (timing) {
|
|
39
|
-
|
|
67
|
+
handleRumPerformanceEntries(lifeCycle, configuration, [timing]);
|
|
40
68
|
});
|
|
41
69
|
}
|
|
42
70
|
|
|
43
71
|
if (!supportPerformanceTimingEvent('first-input')) {
|
|
44
|
-
retrieveFirstInputTiming(timing
|
|
45
|
-
|
|
72
|
+
retrieveFirstInputTiming(function (timing) {
|
|
73
|
+
return handleRumPerformanceEntries(lifeCycle, configuration, [timing]);
|
|
46
74
|
});
|
|
47
75
|
}
|
|
48
76
|
}
|
|
@@ -91,7 +119,7 @@ function retrieveNavigationTiming(callback) {
|
|
|
91
119
|
|
|
92
120
|
|
|
93
121
|
function retrieveFirstInputTiming(callback) {
|
|
94
|
-
var startTimeStamp =
|
|
122
|
+
var startTimeStamp = dateNow();
|
|
95
123
|
var timingSent = false;
|
|
96
124
|
var listeners = addEventListeners(window, [DOM_EVENT.CLICK, DOM_EVENT.MOUSE_DOWN, DOM_EVENT.KEY_DOWN, DOM_EVENT.TOUCH_START, DOM_EVENT.POINTER_DOWN], function (evt) {
|
|
97
125
|
// Only count cancelable events, which should trigger behavior important to the user.
|
|
@@ -104,7 +132,7 @@ function retrieveFirstInputTiming(callback) {
|
|
|
104
132
|
|
|
105
133
|
var timing = {
|
|
106
134
|
entryType: 'first-input',
|
|
107
|
-
processingStart:
|
|
135
|
+
processingStart: relativeNow(),
|
|
108
136
|
startTime: evt.timeStamp
|
|
109
137
|
};
|
|
110
138
|
|
|
@@ -146,7 +174,7 @@ function retrieveFirstInputTiming(callback) {
|
|
|
146
174
|
|
|
147
175
|
var delay = timing.processingStart - timing.startTime;
|
|
148
176
|
|
|
149
|
-
if (delay >= 0 && delay <
|
|
177
|
+
if (delay >= 0 && delay < dateNow() - startTimeStamp) {
|
|
150
178
|
callback(timing);
|
|
151
179
|
}
|
|
152
180
|
}
|
|
@@ -177,20 +205,17 @@ function computeRelativePerformanceTiming() {
|
|
|
177
205
|
return result;
|
|
178
206
|
}
|
|
179
207
|
|
|
180
|
-
function
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
208
|
+
function handleRumPerformanceEntries(lifeCycle, configuration, entries) {
|
|
209
|
+
var rumPerformanceEntries = filter(entries, function (entry) {
|
|
210
|
+
return entry.entryType === 'resource' || entry.entryType === 'navigation' || entry.entryType === 'paint' || entry.entryType === 'longtask' || entry.entryType === 'largest-contentful-paint' || entry.entryType === 'first-input' || entry.entryType === 'layout-shift';
|
|
211
|
+
});
|
|
212
|
+
var rumAllowedPerformanceEntries = filter(rumPerformanceEntries, function (entry) {
|
|
213
|
+
return !isIncompleteNavigation(entry) && !isForbiddenResource(configuration, entry);
|
|
185
214
|
});
|
|
186
|
-
}
|
|
187
215
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
return;
|
|
216
|
+
if (rumAllowedPerformanceEntries.length) {
|
|
217
|
+
lifeCycle.notify(LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED, rumAllowedPerformanceEntries);
|
|
191
218
|
}
|
|
192
|
-
|
|
193
|
-
lifeCycle.notify(LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, entry);
|
|
194
219
|
}
|
|
195
220
|
|
|
196
221
|
function isIncompleteNavigation(entry) {
|
|
@@ -199,4 +224,9 @@ function isIncompleteNavigation(entry) {
|
|
|
199
224
|
|
|
200
225
|
function isForbiddenResource(configuration, entry) {
|
|
201
226
|
return entry.entryType === 'resource' && !isAllowedRequestUrl(configuration, entry.name);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export function supportPerformanceEntry() {
|
|
230
|
+
// Safari 10 doesn't support PerformanceEntry
|
|
231
|
+
return typeof PerformanceEntry === 'function';
|
|
202
232
|
}
|