@cloudcare/browser-rum 3.0.6 → 3.0.8

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.
Files changed (64) hide show
  1. package/bundle/dataflux-rum.js +1 -1
  2. package/cjs/boot/buildEnv.js +1 -1
  3. package/cjs/boot/recorderApi.js +1 -1
  4. package/cjs/boot/rum.js +16 -7
  5. package/cjs/boot/rumPublicApi.js +27 -55
  6. package/cjs/domain/assembly.js +2 -2
  7. package/cjs/domain/contexts/commonContext.js +14 -0
  8. package/cjs/domain/performanceCollection.js +3 -3
  9. package/cjs/domain/replay/record/serialize.js +7 -5
  10. package/cjs/domain/replay/segmentCollection/segmentCollection.js +2 -2
  11. package/cjs/domain/replay/segmentCollection/startDeflateWorker.js +2 -2
  12. package/cjs/domain/rumEventsCollection/actions/clickChain.js +3 -3
  13. package/cjs/domain/rumEventsCollection/actions/getActionNameFromElement.js +0 -1
  14. package/cjs/domain/rumEventsCollection/view/trackFirstHidden.js +4 -4
  15. package/cjs/domain/rumEventsCollection/view/trackInitialViewTimings.js +42 -18
  16. package/cjs/domain/rumEventsCollection/view/trackViewEventCounts.js +1 -1
  17. package/cjs/domain/rumEventsCollection/view/trackViews.js +45 -67
  18. package/cjs/domain/rumEventsCollection/view/viewCollection.js +2 -1
  19. package/cjs/domain/rumSessionManager.js +3 -1
  20. package/cjs/domain/tracing/getDocumentTraceId.js +1 -1
  21. package/cjs/domain/waitPageActivityEnd.js +9 -9
  22. package/cjs/transport/startRumBatch.js +20 -6
  23. package/esm/boot/buildEnv.js +1 -1
  24. package/esm/boot/recorderApi.js +1 -1
  25. package/esm/boot/rum.js +15 -7
  26. package/esm/boot/rumPublicApi.js +25 -54
  27. package/esm/domain/assembly.js +2 -2
  28. package/esm/domain/contexts/commonContext.js +7 -0
  29. package/esm/domain/performanceCollection.js +2 -2
  30. package/esm/domain/replay/record/serialize.js +7 -5
  31. package/esm/domain/replay/segmentCollection/segmentCollection.js +1 -1
  32. package/esm/domain/replay/segmentCollection/startDeflateWorker.js +3 -3
  33. package/esm/domain/rumEventsCollection/actions/clickChain.js +1 -1
  34. package/esm/domain/rumEventsCollection/actions/getActionNameFromElement.js +0 -1
  35. package/esm/domain/rumEventsCollection/view/trackFirstHidden.js +4 -4
  36. package/esm/domain/rumEventsCollection/view/trackInitialViewTimings.js +39 -16
  37. package/esm/domain/rumEventsCollection/view/trackViewEventCounts.js +1 -1
  38. package/esm/domain/rumEventsCollection/view/trackViews.js +46 -68
  39. package/esm/domain/rumEventsCollection/view/viewCollection.js +2 -1
  40. package/esm/domain/rumSessionManager.js +3 -1
  41. package/esm/domain/tracing/getDocumentTraceId.js +1 -1
  42. package/esm/domain/waitPageActivityEnd.js +3 -3
  43. package/esm/transport/startRumBatch.js +21 -7
  44. package/package.json +31 -31
  45. package/src/boot/recorderApi.js +1 -0
  46. package/src/boot/rum.js +29 -9
  47. package/src/boot/rumPublicApi.js +37 -51
  48. package/src/domain/assembly.js +2 -2
  49. package/src/domain/contexts/commonContext.js +11 -0
  50. package/src/domain/performanceCollection.js +4 -2
  51. package/src/domain/replay/record/serialize.js +6 -5
  52. package/src/domain/replay/segmentCollection/segmentCollection.js +3 -1
  53. package/src/domain/replay/segmentCollection/startDeflateWorker.js +8 -3
  54. package/src/domain/rumEventsCollection/actions/clickChain.js +6 -1
  55. package/src/domain/rumEventsCollection/actions/getActionNameFromElement.js +0 -1
  56. package/src/domain/rumEventsCollection/view/trackFirstHidden.js +4 -4
  57. package/src/domain/rumEventsCollection/view/trackInitialViewTimings.js +53 -17
  58. package/src/domain/rumEventsCollection/view/trackViewEventCounts.js +1 -1
  59. package/src/domain/rumEventsCollection/view/trackViews.js +69 -77
  60. package/src/domain/rumEventsCollection/view/viewCollection.js +2 -1
  61. package/src/domain/rumSessionManager.js +3 -1
  62. package/src/domain/tracing/getDocumentTraceId.js +1 -1
  63. package/src/domain/waitPageActivityEnd.js +8 -5
  64. package/src/transport/startRumBatch.js +35 -12
@@ -1,4 +1,4 @@
1
- import { ONE_SECOND, every } from '@cloudcare/browser-core';
1
+ import { ONE_SECOND, every, setTimeout, clearTimeout } from '@cloudcare/browser-core';
2
2
  export var MAX_DURATION_BETWEEN_CLICKS = ONE_SECOND;
3
3
  export var MAX_DISTANCE_BETWEEN_CLICKS = 100;
4
4
  var ClickChainStatus = {
@@ -211,7 +211,6 @@ function getTextualContent(element, userProgrammaticAttribute) {
211
211
  * from a parent element innerText.
212
212
  *
213
213
  * [1]: https://web.archive.org/web/20210602165716/http://perfectionkills.com/the-poor-misunderstood-innerText/#diff-with-textContent
214
- * [2]: https://github.com/DataDog/browser-sdk/issues/1084
215
214
  */
216
215
 
217
216
 
@@ -1,9 +1,9 @@
1
1
  import { DOM_EVENT, addEventListeners } from '@cloudcare/browser-core';
2
2
  var trackFirstHiddenSingleton;
3
3
  var stopListeners;
4
- export function trackFirstHidden(emitter) {
5
- if (typeof emitter === 'undefined') {
6
- emitter = window;
4
+ export function trackFirstHidden(eventTarget) {
5
+ if (typeof eventTarget === 'undefined') {
6
+ eventTarget = window;
7
7
  }
8
8
 
9
9
  if (!trackFirstHiddenSingleton) {
@@ -15,7 +15,7 @@ export function trackFirstHidden(emitter) {
15
15
  trackFirstHiddenSingleton = {
16
16
  timeStamp: Infinity
17
17
  };
18
- var listeners = addEventListeners(emitter, [DOM_EVENT.PAGE_HIDE, DOM_EVENT.VISIBILITY_CHANGE], function (event) {
18
+ var listeners = addEventListeners(eventTarget, [DOM_EVENT.PAGE_HIDE, DOM_EVENT.VISIBILITY_CHANGE], function (event) {
19
19
  if (event.type === 'pagehide' || document.visibilityState === 'hidden') {
20
20
  trackFirstHiddenSingleton.timeStamp = event.timeStamp;
21
21
  stopListeners();
@@ -1,35 +1,46 @@
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
- export function trackInitialViewTimings(lifeCycle, callback) {
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
- callback(timings);
19
+ scheduleViewUpdate();
12
20
  }
13
21
 
14
- var _trackNavigationTimings = trackNavigationTimings(lifeCycle, setTimings);
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
 
18
- var _trackFirstContentfulPaint = trackFirstContentfulPaint(lifeCycle, function (firstContentfulPaint) {
29
+ var _trackFirstContentfulPaintTiming = trackFirstContentfulPaintTiming(lifeCycle, function (firstContentfulPaint) {
19
30
  setTimings({
20
31
  firstContentfulPaint: firstContentfulPaint
21
32
  });
22
33
  });
23
34
 
24
- var stopFCPTracking = _trackFirstContentfulPaint.stop;
35
+ var stopFCPTracking = _trackFirstContentfulPaintTiming.stop;
25
36
 
26
- var _trackLargestContentfulPaint = trackLargestContentfulPaint(lifeCycle, window, function (largestContentfulPaint) {
37
+ var _trackLargestContentfulPaintTiming = trackLargestContentfulPaintTiming(lifeCycle, window, function (largestContentfulPaint) {
27
38
  setTimings({
28
39
  largestContentfulPaint: largestContentfulPaint
29
40
  });
30
41
  });
31
42
 
32
- var stopLCPTracking = _trackLargestContentfulPaint.stop;
43
+ var stopLCPTracking = _trackLargestContentfulPaintTiming.stop;
33
44
 
34
45
  var _trackFirstInputTimings = trackFirstInputTimings(lifeCycle, function (firttime) {
35
46
  setTimings({
@@ -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: function stop() {
44
- stopNavigationTracking();
45
- stopFCPTracking();
46
- stopLCPTracking();
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
  }
@@ -73,7 +96,7 @@ export function trackNavigationTimings(lifeCycle, callback) {
73
96
  stop: subscribe.unsubscribe
74
97
  };
75
98
  }
76
- export function trackFirstContentfulPaint(lifeCycle, callback) {
99
+ export function trackFirstContentfulPaintTiming(lifeCycle, callback) {
77
100
  var firstHidden = trackFirstHidden();
78
101
  var subscribe = lifeCycle.subscribe(LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED, function (entries) {
79
102
  var fcpEntry = find(entries, function (entry) {
@@ -95,7 +118,7 @@ export function trackFirstContentfulPaint(lifeCycle, callback) {
95
118
  * Reference implementation: https://github.com/GoogleChrome/web-vitals/blob/master/src/getLCP.ts
96
119
  */
97
120
 
98
- export function trackLargestContentfulPaint(lifeCycle, emitter, callback) {
121
+ export function trackLargestContentfulPaintTiming(lifeCycle, emitter, callback) {
99
122
  var firstHidden = trackFirstHidden(); // Ignore entries that come after the first user interaction. According to the documentation, the
100
123
  // browser should not send largest-contentful-paint entries after a user interact with the page,
101
124
  // but the web-vitals reference implementation uses this as a safeguard.
@@ -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
- var _trackInitialView = trackInitialView(initialViewOptions);
9
-
10
- var stopInitialViewTracking = _trackInitialView.stop;
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 stopViewLifeCycle = _startViewLifeCycle.stop;
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
- // do not trigger view update to avoid wrong data
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.triggerUpdate();
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(startClocks);
95
- currentView.triggerUpdate();
96
- currentView = trackViewChange(startClocks, options);
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; // Initial view update
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(clocks) {
186
- if (typeof clocks === 'undefined') {
187
- clocks = clocksNow();
165
+ end: function end(options) {
166
+ if (endClocks) {
167
+ // view already ended
168
+ return;
188
169
  }
189
170
 
190
- endClocks = clocks;
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
- scheduleStopEventCountsTracking;
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
  /**
@@ -70,7 +70,7 @@ export function findTraceComment(document) {
70
70
 
71
71
  function getTraceCommentFromNode(node) {
72
72
  if (node && isCommentNode(node)) {
73
- var match = node.data.match(/^\s*DATADOG;(.*?)\s*$/);
73
+ var match = node.data.match(/^\s*GUANCE;(.*?)\s*$/);
74
74
 
75
75
  if (match) {
76
76
  return match[1];
@@ -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 && setTimeout(function () {
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 primaryBatch = createRumBatch(configuration.datakitUrl);
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, unloadCallback) {
17
- return new Batch(createHttpRequest(endpointUrl, configuration.batchBytesLimit, reportError), configuration.batchMessagesLimit, configuration.batchBytesLimit, configuration.messageBytesLimit, configuration.flushTimeout, pageExitObservable);
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
- "name": "@cloudcare/browser-rum",
3
- "version": "3.0.6",
4
- "main": "cjs/index.js",
5
- "module": "esm/index.js",
6
- "dependencies": {
7
- "@cloudcare/browser-core": "2.0.4"
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": "c8c2e9dfd59732cdadc5c7869eba9d7ddf6abeb2"
2
+ "name": "@cloudcare/browser-rum",
3
+ "version": "3.0.8",
4
+ "main": "cjs/index.js",
5
+ "module": "esm/index.js",
6
+ "dependencies": {
7
+ "@cloudcare/browser-core": "2.0.6"
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": "ffbab227685c4ea3bf9b26e6e5e9c00233e64bb2"
33
33
  }
@@ -161,6 +161,7 @@ function isBrowserSupported() {
161
161
  // this test is not sufficient.
162
162
  typeof Array.from === 'function' &&
163
163
  typeof CSSSupportsRule === 'function' &&
164
+ typeof URL.createObjectURL === 'function' &&
164
165
  'forEach' in NodeList.prototype
165
166
  )
166
167
  }
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
- getCommonContext,
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: _startRumEventCollection.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
- getCommonContext,
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
- getCommonContext,
153
+ buildCommonContext,
134
154
  reportError
135
155
  )
136
156
  return {
137
157
  viewContexts: viewContexts,
138
158
  urlContexts: urlContexts,
139
159
  foregroundContexts: foregroundContexts,
140
- addAction: _startActionCollection.addAction,
160
+ addAction: addAction,
141
161
  actionContexts: actionContexts,
142
162
  stop: function () {
143
163
  viewContexts.stop()