@cloudcare/browser-rum 3.0.6 → 3.0.7
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/bundle/dataflux-rum.js +1 -1
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/boot/recorderApi.js +1 -1
- package/cjs/boot/rum.js +16 -7
- package/cjs/boot/rumPublicApi.js +27 -55
- package/cjs/domain/assembly.js +2 -2
- package/cjs/domain/contexts/commonContext.js +14 -0
- package/cjs/domain/performanceCollection.js +3 -3
- package/cjs/domain/replay/record/serialize.js +7 -5
- package/cjs/domain/replay/segmentCollection/segmentCollection.js +2 -2
- package/cjs/domain/replay/segmentCollection/startDeflateWorker.js +2 -2
- package/cjs/domain/rumEventsCollection/actions/clickChain.js +3 -3
- package/cjs/domain/rumEventsCollection/view/trackInitialViewTimings.js +34 -10
- package/cjs/domain/rumEventsCollection/view/trackViewEventCounts.js +1 -1
- package/cjs/domain/rumEventsCollection/view/trackViews.js +45 -67
- package/cjs/domain/rumEventsCollection/view/viewCollection.js +2 -1
- package/cjs/domain/rumSessionManager.js +3 -1
- package/cjs/domain/waitPageActivityEnd.js +9 -9
- package/cjs/transport/startRumBatch.js +20 -6
- package/esm/boot/buildEnv.js +1 -1
- package/esm/boot/recorderApi.js +1 -1
- package/esm/boot/rum.js +15 -7
- package/esm/boot/rumPublicApi.js +25 -54
- package/esm/domain/assembly.js +2 -2
- package/esm/domain/contexts/commonContext.js +7 -0
- package/esm/domain/performanceCollection.js +2 -2
- package/esm/domain/replay/record/serialize.js +7 -5
- package/esm/domain/replay/segmentCollection/segmentCollection.js +1 -1
- package/esm/domain/replay/segmentCollection/startDeflateWorker.js +3 -3
- package/esm/domain/rumEventsCollection/actions/clickChain.js +1 -1
- package/esm/domain/rumEventsCollection/view/trackInitialViewTimings.js +33 -10
- package/esm/domain/rumEventsCollection/view/trackViewEventCounts.js +1 -1
- package/esm/domain/rumEventsCollection/view/trackViews.js +46 -68
- package/esm/domain/rumEventsCollection/view/viewCollection.js +2 -1
- package/esm/domain/rumSessionManager.js +3 -1
- package/esm/domain/waitPageActivityEnd.js +3 -3
- package/esm/transport/startRumBatch.js +21 -7
- package/package.json +31 -31
- package/src/boot/recorderApi.js +1 -0
- package/src/boot/rum.js +29 -9
- package/src/boot/rumPublicApi.js +37 -51
- package/src/domain/assembly.js +2 -2
- package/src/domain/contexts/commonContext.js +11 -0
- package/src/domain/performanceCollection.js +4 -2
- package/src/domain/replay/record/serialize.js +6 -5
- package/src/domain/replay/segmentCollection/segmentCollection.js +3 -1
- package/src/domain/replay/segmentCollection/startDeflateWorker.js +8 -3
- package/src/domain/rumEventsCollection/actions/clickChain.js +6 -1
- package/src/domain/rumEventsCollection/view/trackInitialViewTimings.js +42 -11
- package/src/domain/rumEventsCollection/view/trackViewEventCounts.js +1 -1
- package/src/domain/rumEventsCollection/view/trackViews.js +69 -77
- package/src/domain/rumEventsCollection/view/viewCollection.js +2 -1
- package/src/domain/rumSessionManager.js +3 -1
- package/src/domain/waitPageActivityEnd.js +8 -5
- package/src/transport/startRumBatch.js +35 -12
|
@@ -1,17 +1,28 @@
|
|
|
1
|
-
import { addEventListeners, elapsed, extend, DOM_EVENT, find, findLast, LifeCycleEventType, ONE_MINUTE } from '@cloudcare/browser-core';
|
|
1
|
+
import { addEventListeners, elapsed, extend, DOM_EVENT, find, findLast, LifeCycleEventType, ONE_MINUTE, setTimeout, relativeNow } from '@cloudcare/browser-core';
|
|
2
2
|
import { trackFirstHidden } from './trackFirstHidden'; // Discard LCP and FCP timings above a certain delay to avoid incorrect data
|
|
3
3
|
// It happens in some cases like sleep mode or some browser implementations
|
|
4
4
|
|
|
5
5
|
export var TIMING_MAXIMUM_DELAY = 10 * ONE_MINUTE;
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* The initial view can finish quickly, before some metrics can be produced (ex: before the page load
|
|
8
|
+
* event, or the first input). Also, we don't want to trigger a view update indefinitely, to avoid
|
|
9
|
+
* updates on views that ended a long time ago. Keep watching for metrics after the view ends for a
|
|
10
|
+
* limited amount of time.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export var KEEP_TRACKING_TIMINGS_AFTER_VIEW_DELAY = 5 * ONE_MINUTE;
|
|
14
|
+
export function trackInitialViewTimings(lifeCycle, setLoadEvent, scheduleViewUpdate) {
|
|
7
15
|
var timings = {};
|
|
8
16
|
|
|
9
17
|
function setTimings(newTimings) {
|
|
10
18
|
timings = extend(timings, newTimings);
|
|
11
|
-
|
|
19
|
+
scheduleViewUpdate();
|
|
12
20
|
}
|
|
13
21
|
|
|
14
|
-
var _trackNavigationTimings = trackNavigationTimings(lifeCycle,
|
|
22
|
+
var _trackNavigationTimings = trackNavigationTimings(lifeCycle, function (newTimings) {
|
|
23
|
+
setLoadEvent(newTimings.loadEvent);
|
|
24
|
+
setTimings(newTimings);
|
|
25
|
+
});
|
|
15
26
|
|
|
16
27
|
var stopNavigationTracking = _trackNavigationTimings.stop;
|
|
17
28
|
|
|
@@ -39,12 +50,19 @@ export function trackInitialViewTimings(lifeCycle, callback) {
|
|
|
39
50
|
});
|
|
40
51
|
|
|
41
52
|
var stopFIDTracking = _trackFirstInputTimings.stop;
|
|
53
|
+
|
|
54
|
+
function stop() {
|
|
55
|
+
stopNavigationTracking();
|
|
56
|
+
stopFCPTracking();
|
|
57
|
+
stopLCPTracking();
|
|
58
|
+
stopFIDTracking();
|
|
59
|
+
}
|
|
60
|
+
|
|
42
61
|
return {
|
|
43
|
-
stop:
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
stopFIDTracking();
|
|
62
|
+
stop: stop,
|
|
63
|
+
timings: timings,
|
|
64
|
+
scheduleStop: function scheduleStop() {
|
|
65
|
+
setTimeout(stop, KEEP_TRACKING_TIMINGS_AFTER_VIEW_DELAY);
|
|
48
66
|
}
|
|
49
67
|
};
|
|
50
68
|
}
|
|
@@ -64,7 +82,12 @@ export function trackNavigationTimings(lifeCycle, callback) {
|
|
|
64
82
|
loadEventEnd: entry.loadEventEnd,
|
|
65
83
|
loadEventStart: entry.loadEventStart,
|
|
66
84
|
domContentLoadedEventEnd: entry.domContentLoadedEventEnd,
|
|
67
|
-
domContentLoadedEventStart: entry.domContentLoadedEventStart
|
|
85
|
+
domContentLoadedEventStart: entry.domContentLoadedEventStart,
|
|
86
|
+
// In some cases the value reported is negative or is larger
|
|
87
|
+
// than the current page time. Ignore these cases:
|
|
88
|
+
// https://github.com/GoogleChrome/web-vitals/issues/137
|
|
89
|
+
// https://github.com/GoogleChrome/web-vitals/issues/162
|
|
90
|
+
firstByte: entry.responseStart >= 0 && entry.responseStart <= relativeNow() ? entry.responseStart : undefined
|
|
68
91
|
});
|
|
69
92
|
}
|
|
70
93
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ONE_MINUTE } from '@cloudcare/browser-core';
|
|
1
|
+
import { ONE_MINUTE, setTimeout } from '@cloudcare/browser-core';
|
|
2
2
|
import { trackEventCounts } from '../../trackEventCounts'; // Some events are not being counted as they transcend views. To reduce the occurrence;
|
|
3
3
|
// an arbitrary delay is added for stopping event counting after the view ends.
|
|
4
4
|
//
|
|
@@ -1,70 +1,41 @@
|
|
|
1
|
-
import { shallowClone, assign, elapsed, UUID, ONE_MINUTE, throttle, clocksNow, clocksOrigin, timeStampNow, looksLikeRelativeTime, ViewLoadingType, LifeCycleEventType, PageExitReason, isHashAnAnchor, getPathFromHash } from '@cloudcare/browser-core';
|
|
1
|
+
import { shallowClone, assign, elapsed, UUID, ONE_MINUTE, throttle, clocksNow, clocksOrigin, timeStampNow, looksLikeRelativeTime, ViewLoadingType, LifeCycleEventType, PageExitReason, isHashAnAnchor, getPathFromHash, noop, setInterval, clearInterval, isNullUndefinedDefaultValue } from '@cloudcare/browser-core';
|
|
2
2
|
import { trackInitialViewTimings } from './trackInitialViewTimings';
|
|
3
3
|
import { trackViewMetrics } from './trackViewMetrics';
|
|
4
4
|
import { trackViewEventCounts } from './trackViewEventCounts';
|
|
5
5
|
export var THROTTLE_VIEW_UPDATE_PERIOD = 3000;
|
|
6
6
|
export var SESSION_KEEP_ALIVE_INTERVAL = 5 * ONE_MINUTE;
|
|
7
7
|
export function trackViews(location, lifeCycle, domMutationObservable, configuration, locationChangeObservable, areViewsTrackedAutomatically, initialViewOptions) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var initialView = _trackInitialView.initialView;
|
|
12
|
-
var currentView = initialView;
|
|
13
|
-
|
|
14
|
-
var _startViewLifeCycle = startViewLifeCycle();
|
|
8
|
+
function startNewView(loadingType, startClocks, viewOptions) {
|
|
9
|
+
return newView(lifeCycle, domMutationObservable, configuration, location, loadingType, startClocks, viewOptions);
|
|
10
|
+
}
|
|
15
11
|
|
|
16
|
-
var
|
|
12
|
+
var currentView = startNewView(ViewLoadingType.INITIAL_LOAD, clocksOrigin(), initialViewOptions);
|
|
13
|
+
startViewLifeCycle();
|
|
17
14
|
var locationChangeSubscription;
|
|
18
15
|
|
|
19
16
|
if (areViewsTrackedAutomatically) {
|
|
20
17
|
locationChangeSubscription = renewViewOnLocationChange(locationChangeObservable);
|
|
21
18
|
}
|
|
22
19
|
|
|
23
|
-
function trackInitialView(options) {
|
|
24
|
-
var initialView = newView(lifeCycle, domMutationObservable, configuration, location, ViewLoadingType.INITIAL_LOAD, clocksOrigin(), options);
|
|
25
|
-
|
|
26
|
-
var _trackInitialViewTimings = trackInitialViewTimings(lifeCycle, function (timings) {
|
|
27
|
-
initialView.updateTimings(timings);
|
|
28
|
-
initialView.scheduleUpdate();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
return {
|
|
32
|
-
initialView: initialView,
|
|
33
|
-
stop: _trackInitialViewTimings.stop
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function trackViewChange(startClocks, viewOptions) {
|
|
38
|
-
return newView(lifeCycle, domMutationObservable, configuration, location, ViewLoadingType.ROUTE_CHANGE, startClocks, viewOptions);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
20
|
function startViewLifeCycle() {
|
|
42
21
|
lifeCycle.subscribe(LifeCycleEventType.SESSION_RENEWED, function () {
|
|
43
|
-
|
|
44
|
-
currentView.end(); // Renew view on session renewal
|
|
45
|
-
|
|
46
|
-
currentView = trackViewChange(undefined, {
|
|
22
|
+
startNewView(ViewLoadingType.ROUTE_CHANGE, undefined, {
|
|
47
23
|
name: currentView.name,
|
|
48
24
|
service: currentView.service,
|
|
49
25
|
version: currentView.version
|
|
50
26
|
});
|
|
27
|
+
});
|
|
28
|
+
lifeCycle.subscribe(LifeCycleEventType.SESSION_EXPIRED, function () {
|
|
29
|
+
currentView.end({
|
|
30
|
+
sessionIsActive: false
|
|
31
|
+
});
|
|
51
32
|
}); // End the current view on page unload
|
|
52
33
|
|
|
53
34
|
lifeCycle.subscribe(LifeCycleEventType.PAGE_EXITED, function (pageExitEvent) {
|
|
54
35
|
if (pageExitEvent.reason === PageExitReason.UNLOADING || pageExitEvent.reason === PageExitReason.PAGEHIDE) {
|
|
55
36
|
currentView.end();
|
|
56
|
-
currentView.triggerUpdate();
|
|
57
|
-
}
|
|
58
|
-
}); // Session keep alive
|
|
59
|
-
|
|
60
|
-
var keepAliveInterval = window.setInterval(function () {
|
|
61
|
-
currentView.triggerUpdate();
|
|
62
|
-
}, SESSION_KEEP_ALIVE_INTERVAL);
|
|
63
|
-
return {
|
|
64
|
-
stop: function stop() {
|
|
65
|
-
clearInterval(keepAliveInterval);
|
|
66
37
|
}
|
|
67
|
-
};
|
|
38
|
+
});
|
|
68
39
|
}
|
|
69
40
|
|
|
70
41
|
function renewViewOnLocationChange(locationChangeObservable) {
|
|
@@ -74,8 +45,7 @@ export function trackViews(location, lifeCycle, domMutationObservable, configura
|
|
|
74
45
|
|
|
75
46
|
if (areDifferentLocation(oldLocation, newLocation)) {
|
|
76
47
|
currentView.end();
|
|
77
|
-
currentView.
|
|
78
|
-
currentView = trackViewChange();
|
|
48
|
+
currentView = startNewView(ViewLoadingType.ROUTE_CHANGE);
|
|
79
49
|
return;
|
|
80
50
|
}
|
|
81
51
|
});
|
|
@@ -88,20 +58,18 @@ export function trackViews(location, lifeCycle, domMutationObservable, configura
|
|
|
88
58
|
}
|
|
89
59
|
|
|
90
60
|
currentView.addTiming(name, time);
|
|
91
|
-
currentView.scheduleUpdate();
|
|
92
61
|
},
|
|
93
62
|
startView: function startView(options, startClocks) {
|
|
94
|
-
currentView.end(
|
|
95
|
-
|
|
96
|
-
|
|
63
|
+
currentView.end({
|
|
64
|
+
endClocks: startClocks
|
|
65
|
+
});
|
|
66
|
+
currentView = startNewView(ViewLoadingType.ROUTE_CHANGE, startClocks, options);
|
|
97
67
|
},
|
|
98
68
|
stop: function stop() {
|
|
99
69
|
if (locationChangeSubscription) {
|
|
100
70
|
locationChangeSubscription.unsubscribe();
|
|
101
71
|
}
|
|
102
72
|
|
|
103
|
-
stopInitialViewTracking();
|
|
104
|
-
stopViewLifeCycle();
|
|
105
73
|
currentView.end();
|
|
106
74
|
}
|
|
107
75
|
};
|
|
@@ -114,11 +82,11 @@ function newView(lifeCycle, domMutationObservable, configuration, initialLocatio
|
|
|
114
82
|
}
|
|
115
83
|
|
|
116
84
|
var id = UUID();
|
|
117
|
-
var timings = {};
|
|
118
85
|
var customTimings = {};
|
|
119
86
|
var documentVersion = 0;
|
|
120
87
|
var endClocks;
|
|
121
88
|
var location = shallowClone(initialLocation);
|
|
89
|
+
var sessionIsActive = true;
|
|
122
90
|
var name;
|
|
123
91
|
var service;
|
|
124
92
|
var version;
|
|
@@ -150,14 +118,25 @@ function newView(lifeCycle, domMutationObservable, configuration, initialLocatio
|
|
|
150
118
|
var stopViewMetricsTracking = _trackViewMetrics.stop;
|
|
151
119
|
var viewMetrics = _trackViewMetrics.viewMetrics;
|
|
152
120
|
|
|
121
|
+
var _trackInitialViewTimings = loadingType === ViewLoadingType.INITIAL_LOAD ? trackInitialViewTimings(lifeCycle, setLoadEvent, scheduleViewUpdate) : {
|
|
122
|
+
scheduleStop: noop,
|
|
123
|
+
timings: {}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
var scheduleStopInitialViewTimingsTracking = _trackInitialViewTimings.scheduleStop;
|
|
127
|
+
var timings = _trackInitialViewTimings.timings;
|
|
128
|
+
|
|
153
129
|
var _trackViewEventCounts = trackViewEventCounts(lifeCycle, id, scheduleViewUpdate);
|
|
154
130
|
|
|
155
131
|
var scheduleStopEventCountsTracking = _trackViewEventCounts.scheduleStop;
|
|
156
|
-
var eventCounts = _trackViewEventCounts.eventCounts; //
|
|
132
|
+
var eventCounts = _trackViewEventCounts.eventCounts; // Session keep alive
|
|
133
|
+
|
|
134
|
+
var keepAliveIntervalId = setInterval(triggerViewUpdate, SESSION_KEEP_ALIVE_INTERVAL); // Initial view update
|
|
157
135
|
|
|
158
136
|
triggerViewUpdate();
|
|
159
137
|
|
|
160
138
|
function triggerViewUpdate() {
|
|
139
|
+
cancelScheduleViewUpdate();
|
|
161
140
|
documentVersion += 1;
|
|
162
141
|
var currentEnd = endClocks === undefined ? timeStampNow() : endClocks.timeStamp;
|
|
163
142
|
lifeCycle.notify(LifeCycleEventType.VIEW_UPDATED, assign({
|
|
@@ -173,6 +152,7 @@ function newView(lifeCycle, domMutationObservable, configuration, initialLocatio
|
|
|
173
152
|
timings: timings,
|
|
174
153
|
duration: elapsed(startClocks.timeStamp, currentEnd),
|
|
175
154
|
isActive: endClocks === undefined,
|
|
155
|
+
sessionIsActive: sessionIsActive,
|
|
176
156
|
eventCounts: eventCounts
|
|
177
157
|
}, viewMetrics));
|
|
178
158
|
}
|
|
@@ -182,33 +162,31 @@ function newView(lifeCycle, domMutationObservable, configuration, initialLocatio
|
|
|
182
162
|
service: service,
|
|
183
163
|
version: version,
|
|
184
164
|
scheduleUpdate: scheduleViewUpdate,
|
|
185
|
-
end: function end(
|
|
186
|
-
if (
|
|
187
|
-
|
|
165
|
+
end: function end(options) {
|
|
166
|
+
if (endClocks) {
|
|
167
|
+
// view already ended
|
|
168
|
+
return;
|
|
188
169
|
}
|
|
189
170
|
|
|
190
|
-
endClocks =
|
|
171
|
+
endClocks = isNullUndefinedDefaultValue(options && options.endClocks, clocksNow());
|
|
172
|
+
sessionIsActive = isNullUndefinedDefaultValue(options && options.sessionIsActive, true);
|
|
191
173
|
lifeCycle.notify(LifeCycleEventType.VIEW_ENDED, {
|
|
192
174
|
endClocks: endClocks
|
|
193
175
|
});
|
|
176
|
+
clearInterval(keepAliveIntervalId);
|
|
194
177
|
stopViewMetricsTracking();
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
triggerUpdate: function triggerUpdate() {
|
|
198
|
-
// cancel any pending view updates execution
|
|
199
|
-
cancelScheduleViewUpdate();
|
|
178
|
+
scheduleStopInitialViewTimingsTracking();
|
|
179
|
+
scheduleStopEventCountsTracking();
|
|
200
180
|
triggerViewUpdate();
|
|
201
181
|
},
|
|
202
|
-
updateTimings: function updateTimings(newTimings) {
|
|
203
|
-
timings = newTimings;
|
|
204
|
-
|
|
205
|
-
if (newTimings.loadEvent !== undefined) {
|
|
206
|
-
setLoadEvent(newTimings.loadEvent);
|
|
207
|
-
}
|
|
208
|
-
},
|
|
209
182
|
addTiming: function addTiming(name, time) {
|
|
183
|
+
if (endClocks) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
210
187
|
var relativeTime = looksLikeRelativeTime(time) ? time : elapsed(startClocks.timeStamp, time);
|
|
211
188
|
customTimings[sanitizeTiming(name)] = relativeTime;
|
|
189
|
+
scheduleViewUpdate();
|
|
212
190
|
}
|
|
213
191
|
};
|
|
214
192
|
}
|
|
@@ -101,7 +101,8 @@ function processViewUpdate(view, foregroundContexts, recorderApi) {
|
|
|
101
101
|
in_foreground_periods: foregroundContexts.selectInForegroundPeriodsFor(view.startClocks.relative, view.duration)
|
|
102
102
|
},
|
|
103
103
|
session: {
|
|
104
|
-
has_replay: replayStats ? true : undefined
|
|
104
|
+
has_replay: replayStats ? true : undefined,
|
|
105
|
+
is_active: view.sessionIsActive ? undefined : false
|
|
105
106
|
}
|
|
106
107
|
};
|
|
107
108
|
|
|
@@ -36,7 +36,9 @@ export function startRumSessionManager(configuration, lifeCycle) {
|
|
|
36
36
|
plan: plan,
|
|
37
37
|
sessionReplayAllowed: plan === RumSessionPlan.WITH_SESSION_REPLAY
|
|
38
38
|
};
|
|
39
|
-
}
|
|
39
|
+
},
|
|
40
|
+
expire: sessionManager.expire,
|
|
41
|
+
expireObservable: sessionManager.expireObservable
|
|
40
42
|
};
|
|
41
43
|
}
|
|
42
44
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Observable, each, timeStampNow, LifeCycleEventType, some, matchList, instrumentMethodAndCallOriginal } from '@cloudcare/browser-core'; // Delay to wait for a page activity to validate the tracking process
|
|
1
|
+
import { Observable, each, timeStampNow, LifeCycleEventType, some, matchList, instrumentMethodAndCallOriginal, setTimeout, clearTimeout } from '@cloudcare/browser-core'; // Delay to wait for a page activity to validate the tracking process
|
|
2
2
|
|
|
3
3
|
export var PAGE_ACTIVITY_VALIDATION_DELAY = 100; // Delay to wait after a page activity to end the tracking process
|
|
4
4
|
|
|
@@ -46,12 +46,12 @@ export function doWaitPageActivityEnd(pageActivityObservable, pageActivityEndCal
|
|
|
46
46
|
hadActivity: false
|
|
47
47
|
});
|
|
48
48
|
}, PAGE_ACTIVITY_VALIDATION_DELAY);
|
|
49
|
-
var maxDurationTimeoutId = maxDuration
|
|
49
|
+
var maxDurationTimeoutId = maxDuration !== undefined ? setTimeout(function () {
|
|
50
50
|
return complete({
|
|
51
51
|
hadActivity: true,
|
|
52
52
|
end: timeStampNow()
|
|
53
53
|
});
|
|
54
|
-
}, maxDuration);
|
|
54
|
+
}, maxDuration) : undefined;
|
|
55
55
|
var pageActivitySubscription = pageActivityObservable.subscribe(function (data) {
|
|
56
56
|
var isBusy = data.isBusy;
|
|
57
57
|
clearTimeout(validationTimeoutId);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Batch, createHttpRequest, LifeCycleEventType, RumEventType } from '@cloudcare/browser-core';
|
|
2
|
-
export function startRumBatch(configuration, lifeCycle, reportError, pageExitObservable) {
|
|
3
|
-
var batch = makeRumBatch(configuration, reportError, pageExitObservable);
|
|
1
|
+
import { Batch, createHttpRequest, LifeCycleEventType, RumEventType, createFlushController } from '@cloudcare/browser-core';
|
|
2
|
+
export function startRumBatch(configuration, lifeCycle, reportError, pageExitObservable, sessionExpireObservable) {
|
|
3
|
+
var batch = makeRumBatch(configuration, reportError, pageExitObservable, sessionExpireObservable);
|
|
4
4
|
lifeCycle.subscribe(LifeCycleEventType.RUM_EVENT_COLLECTED, function (serverRumEvent) {
|
|
5
5
|
if (serverRumEvent.type === RumEventType.VIEW) {
|
|
6
6
|
batch.upsert(serverRumEvent, serverRumEvent.view.id);
|
|
@@ -10,14 +10,28 @@ export function startRumBatch(configuration, lifeCycle, reportError, pageExitObs
|
|
|
10
10
|
});
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
function makeRumBatch(configuration, reportError, pageExitObservable) {
|
|
14
|
-
var
|
|
13
|
+
function makeRumBatch(configuration, reportError, pageExitObservable, sessionExpireObservable) {
|
|
14
|
+
var rumBatch = createRumBatch(configuration.datakitUrl);
|
|
15
|
+
var primaryBatch = rumBatch.batch;
|
|
16
|
+
var primaryFlushController = rumBatch.flushController;
|
|
15
17
|
|
|
16
|
-
function createRumBatch(endpointUrl
|
|
17
|
-
|
|
18
|
+
function createRumBatch(endpointUrl) {
|
|
19
|
+
var flushController = createFlushController({
|
|
20
|
+
messagesLimit: configuration.batchMessagesLimit,
|
|
21
|
+
bytesLimit: configuration.batchBytesLimit,
|
|
22
|
+
durationLimit: configuration.flushTimeout,
|
|
23
|
+
pageExitObservable: pageExitObservable,
|
|
24
|
+
sessionExpireObservable: sessionExpireObservable
|
|
25
|
+
});
|
|
26
|
+
var batch = new Batch(createHttpRequest(endpointUrl, configuration.batchBytesLimit, reportError), flushController, configuration.messageBytesLimit);
|
|
27
|
+
return {
|
|
28
|
+
batch: batch,
|
|
29
|
+
flushController: flushController
|
|
30
|
+
};
|
|
18
31
|
}
|
|
19
32
|
|
|
20
33
|
return {
|
|
34
|
+
flushObservable: primaryFlushController.flushObservable,
|
|
21
35
|
add: function add(message) {
|
|
22
36
|
primaryBatch.add(message);
|
|
23
37
|
},
|
package/package.json
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
2
|
+
"name": "@cloudcare/browser-rum",
|
|
3
|
+
"version": "3.0.7",
|
|
4
|
+
"main": "cjs/index.js",
|
|
5
|
+
"module": "esm/index.js",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@cloudcare/browser-core": "2.0.5"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"dev": "webpack serve --open --mode=development",
|
|
11
|
+
"build": "run-p build:cjs build:esm build:bundle",
|
|
12
|
+
"build:cjs": "rm -rf cjs && babel --config-file ./babel.cjs.json --out-dir cjs ./src && npm run replace-build-env cjs",
|
|
13
|
+
"build:esm": "rm -rf esm && babel --config-file ./babel.esm.json --out-dir esm ./src && npm run replace-build-env esm",
|
|
14
|
+
"build:bundle": "rm -rf bundle && webpack --config webpack.config.js --mode=production && npm run replace-build-env bundle ",
|
|
15
|
+
"replace-build-env": "node scripts/replace-build-env.js",
|
|
16
|
+
"publish:oss": "npm run build && node ./scripts/publish-oss.js",
|
|
17
|
+
"publish:oss:test": "npm run build && node ./scripts/publish-oss.js test"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"dataflux",
|
|
21
|
+
"rum",
|
|
22
|
+
"sdk"
|
|
23
|
+
],
|
|
24
|
+
"repository": {
|
|
25
|
+
"url": "https://github.com/DataFlux-cn/datakit-js",
|
|
26
|
+
"type": "git"
|
|
27
|
+
},
|
|
28
|
+
"author": "dataflux",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"homepage": "https://github.com/CloudCare/dataflux-rum-sdk-javascript/blob/master/packages/rum/README.md",
|
|
31
|
+
"description": "DataFlux RUM Web 端数据指标监控",
|
|
32
|
+
"gitHead": "d73a29f283e62c5b13fe0b0f710b7e1e186267bc"
|
|
33
33
|
}
|
package/src/boot/recorderApi.js
CHANGED
package/src/boot/rum.js
CHANGED
|
@@ -16,14 +16,16 @@ import { startInternalContext } from '../domain/contexts/internalContext'
|
|
|
16
16
|
import { startForegroundContexts } from '../domain/contexts/foregroundContexts'
|
|
17
17
|
import { startUrlContexts } from '../domain/contexts/urlContexts'
|
|
18
18
|
import { startViewContexts } from '../domain/contexts/viewContexts'
|
|
19
|
+
import { buildCommonContext } from '../domain/contexts/commonContext'
|
|
19
20
|
import { startErrorCollection } from '../domain/rumEventsCollection/error/errorCollection'
|
|
20
21
|
import { startViewCollection } from '../domain/rumEventsCollection/view/viewCollection'
|
|
21
22
|
import { startRequestCollection } from '../domain/requestCollection'
|
|
22
23
|
import { startResourceCollection } from '../domain/rumEventsCollection/resource/resourceCollection'
|
|
23
24
|
export function startRum(
|
|
24
25
|
configuration,
|
|
25
|
-
getCommonContext,
|
|
26
26
|
recorderApi,
|
|
27
|
+
globalContextManager,
|
|
28
|
+
userContextManager,
|
|
27
29
|
initialViewOptions
|
|
28
30
|
) {
|
|
29
31
|
var lifeCycle = new LifeCycle()
|
|
@@ -35,26 +37,40 @@ export function startRum(
|
|
|
35
37
|
pageExitObservable.subscribe(function (event) {
|
|
36
38
|
lifeCycle.notify(LifeCycleEventType.PAGE_EXITED, event)
|
|
37
39
|
})
|
|
38
|
-
startRumBatch(configuration, lifeCycle, reportError, pageExitObservable)
|
|
39
40
|
var session = startRumSessionManager(configuration, lifeCycle)
|
|
41
|
+
|
|
42
|
+
var batch = startRumBatch(
|
|
43
|
+
configuration,
|
|
44
|
+
lifeCycle,
|
|
45
|
+
reportError,
|
|
46
|
+
pageExitObservable,
|
|
47
|
+
session.expireObservable
|
|
48
|
+
)
|
|
40
49
|
var userSession = startCacheUsrCache(configuration)
|
|
41
50
|
var domMutationObservable = createDOMMutationObservable()
|
|
42
51
|
var locationChangeObservable = createLocationChangeObservable(location)
|
|
43
52
|
var _startRumEventCollection = startRumEventCollection(
|
|
44
|
-
location,
|
|
45
53
|
lifeCycle,
|
|
46
54
|
configuration,
|
|
55
|
+
location,
|
|
47
56
|
session,
|
|
48
57
|
userSession,
|
|
49
58
|
locationChangeObservable,
|
|
50
59
|
domMutationObservable,
|
|
51
|
-
|
|
60
|
+
function () {
|
|
61
|
+
return buildCommonContext(
|
|
62
|
+
globalContextManager,
|
|
63
|
+
userContextManager,
|
|
64
|
+
recorderApi
|
|
65
|
+
)
|
|
66
|
+
},
|
|
52
67
|
reportError
|
|
53
68
|
)
|
|
54
69
|
var viewContexts = _startRumEventCollection.viewContexts
|
|
55
70
|
var urlContexts = _startRumEventCollection.urlContexts
|
|
56
71
|
var actionContexts = _startRumEventCollection.actionContexts
|
|
57
72
|
var foregroundContexts = _startRumEventCollection.foregroundContexts
|
|
73
|
+
var addAction = _startRumEventCollection.addAction
|
|
58
74
|
startLongTaskCollection(lifeCycle, session)
|
|
59
75
|
startResourceCollection(lifeCycle, configuration)
|
|
60
76
|
|
|
@@ -85,7 +101,7 @@ export function startRum(
|
|
|
85
101
|
urlContexts
|
|
86
102
|
)
|
|
87
103
|
return {
|
|
88
|
-
addAction:
|
|
104
|
+
addAction: addAction,
|
|
89
105
|
addError: addError,
|
|
90
106
|
addTiming: addTiming,
|
|
91
107
|
configuration: configuration,
|
|
@@ -93,19 +109,22 @@ export function startRum(
|
|
|
93
109
|
viewContexts: viewContexts,
|
|
94
110
|
session: session,
|
|
95
111
|
startView: startView,
|
|
112
|
+
stopSession: function () {
|
|
113
|
+
session.expire()
|
|
114
|
+
},
|
|
96
115
|
getInternalContext: internalContext.get
|
|
97
116
|
}
|
|
98
117
|
}
|
|
99
118
|
|
|
100
119
|
export function startRumEventCollection(
|
|
101
|
-
location,
|
|
102
120
|
lifeCycle,
|
|
103
121
|
configuration,
|
|
122
|
+
location,
|
|
104
123
|
sessionManager,
|
|
105
124
|
userSessionManager,
|
|
106
125
|
locationChangeObservable,
|
|
107
126
|
domMutationObservable,
|
|
108
|
-
|
|
127
|
+
buildCommonContext,
|
|
109
128
|
reportError
|
|
110
129
|
) {
|
|
111
130
|
var viewContexts = startViewContexts(lifeCycle)
|
|
@@ -122,6 +141,7 @@ export function startRumEventCollection(
|
|
|
122
141
|
foregroundContexts
|
|
123
142
|
)
|
|
124
143
|
var actionContexts = _startActionCollection.actionContexts
|
|
144
|
+
var addAction = _startActionCollection.addAction
|
|
125
145
|
startRumAssembly(
|
|
126
146
|
configuration,
|
|
127
147
|
lifeCycle,
|
|
@@ -130,14 +150,14 @@ export function startRumEventCollection(
|
|
|
130
150
|
viewContexts,
|
|
131
151
|
urlContexts,
|
|
132
152
|
actionContexts,
|
|
133
|
-
|
|
153
|
+
buildCommonContext,
|
|
134
154
|
reportError
|
|
135
155
|
)
|
|
136
156
|
return {
|
|
137
157
|
viewContexts: viewContexts,
|
|
138
158
|
urlContexts: urlContexts,
|
|
139
159
|
foregroundContexts: foregroundContexts,
|
|
140
|
-
addAction:
|
|
160
|
+
addAction: addAction,
|
|
141
161
|
actionContexts: actionContexts,
|
|
142
162
|
stop: function () {
|
|
143
163
|
viewContexts.stop()
|