@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
@@ -13,7 +13,11 @@ import {
13
13
  LifeCycleEventType,
14
14
  PageExitReason,
15
15
  isHashAnAnchor,
16
- getPathFromHash
16
+ getPathFromHash,
17
+ noop,
18
+ setInterval,
19
+ clearInterval,
20
+ isNullUndefinedDefaultValue
17
21
  } from '@cloudcare/browser-core'
18
22
 
19
23
  import { trackInitialViewTimings } from './trackInitialViewTimings'
@@ -31,64 +35,41 @@ export function trackViews(
31
35
  areViewsTrackedAutomatically,
32
36
  initialViewOptions
33
37
  ) {
34
- var _trackInitialView = trackInitialView(initialViewOptions)
35
- var stopInitialViewTracking = _trackInitialView.stop
36
- var initialView = _trackInitialView.initialView
37
- var currentView = initialView
38
-
39
- var _startViewLifeCycle = startViewLifeCycle()
40
- var stopViewLifeCycle = _startViewLifeCycle.stop
41
- var locationChangeSubscription
42
- if (areViewsTrackedAutomatically) {
43
- locationChangeSubscription = renewViewOnLocationChange(
44
- locationChangeObservable
45
- )
46
- }
47
-
48
- function trackInitialView(options) {
49
- var initialView = newView(
50
- lifeCycle,
51
- domMutationObservable,
52
- configuration,
53
- location,
54
- ViewLoadingType.INITIAL_LOAD,
55
- clocksOrigin(),
56
- options
57
- )
58
- var _trackInitialViewTimings = trackInitialViewTimings(
59
- lifeCycle,
60
- function (timings) {
61
- initialView.updateTimings(timings)
62
- initialView.scheduleUpdate()
63
- }
64
- )
65
- return { initialView: initialView, stop: _trackInitialViewTimings.stop }
66
- }
67
-
68
- function trackViewChange(startClocks, viewOptions) {
38
+ function startNewView(loadingType, startClocks, viewOptions) {
69
39
  return newView(
70
40
  lifeCycle,
71
41
  domMutationObservable,
72
42
  configuration,
73
43
  location,
74
- ViewLoadingType.ROUTE_CHANGE,
44
+ loadingType,
75
45
  startClocks,
76
46
  viewOptions
77
47
  )
78
48
  }
79
-
49
+ var currentView = startNewView(
50
+ ViewLoadingType.INITIAL_LOAD,
51
+ clocksOrigin(),
52
+ initialViewOptions
53
+ )
54
+ startViewLifeCycle()
55
+ var locationChangeSubscription
56
+ if (areViewsTrackedAutomatically) {
57
+ locationChangeSubscription = renewViewOnLocationChange(
58
+ locationChangeObservable
59
+ )
60
+ }
80
61
  function startViewLifeCycle() {
81
62
  lifeCycle.subscribe(LifeCycleEventType.SESSION_RENEWED, function () {
82
- // do not trigger view update to avoid wrong data
83
- currentView.end()
84
- // Renew view on session renewal
85
- currentView = trackViewChange(undefined, {
63
+ startNewView(ViewLoadingType.ROUTE_CHANGE, undefined, {
86
64
  name: currentView.name,
87
65
  service: currentView.service,
88
66
  version: currentView.version
89
67
  })
90
68
  })
91
69
 
70
+ lifeCycle.subscribe(LifeCycleEventType.SESSION_EXPIRED, function () {
71
+ currentView.end({ sessionIsActive: false })
72
+ })
92
73
  // End the current view on page unload
93
74
  lifeCycle.subscribe(
94
75
  LifeCycleEventType.PAGE_EXITED,
@@ -98,20 +79,9 @@ export function trackViews(
98
79
  pageExitEvent.reason === PageExitReason.PAGEHIDE
99
80
  ) {
100
81
  currentView.end()
101
- currentView.triggerUpdate()
102
82
  }
103
83
  }
104
84
  )
105
- // Session keep alive
106
- var keepAliveInterval = window.setInterval(function () {
107
- currentView.triggerUpdate()
108
- }, SESSION_KEEP_ALIVE_INTERVAL)
109
-
110
- return {
111
- stop: function () {
112
- clearInterval(keepAliveInterval)
113
- }
114
- }
115
85
  }
116
86
 
117
87
  function renewViewOnLocationChange(locationChangeObservable) {
@@ -120,8 +90,7 @@ export function trackViews(
120
90
  var newLocation = params.newLocation
121
91
  if (areDifferentLocation(oldLocation, newLocation)) {
122
92
  currentView.end()
123
- currentView.triggerUpdate()
124
- currentView = trackViewChange()
93
+ currentView = startNewView(ViewLoadingType.ROUTE_CHANGE)
125
94
  return
126
95
  }
127
96
  })
@@ -133,19 +102,19 @@ export function trackViews(
133
102
  time = timeStampNow()
134
103
  }
135
104
  currentView.addTiming(name, time)
136
- currentView.scheduleUpdate()
137
105
  },
138
106
  startView: function (options, startClocks) {
139
- currentView.end(startClocks)
140
- currentView.triggerUpdate()
141
- currentView = trackViewChange(startClocks, options)
107
+ currentView.end({ endClocks: startClocks })
108
+ currentView = startNewView(
109
+ ViewLoadingType.ROUTE_CHANGE,
110
+ startClocks,
111
+ options
112
+ )
142
113
  },
143
114
  stop: function () {
144
115
  if (locationChangeSubscription) {
145
116
  locationChangeSubscription.unsubscribe()
146
117
  }
147
- stopInitialViewTracking()
148
- stopViewLifeCycle()
149
118
  currentView.end()
150
119
  }
151
120
  }
@@ -165,12 +134,12 @@ function newView(
165
134
  startClocks = clocksNow()
166
135
  }
167
136
  var id = UUID()
168
- var timings = {}
169
137
  var customTimings = {}
170
138
  var documentVersion = 0
171
139
  var endClocks
172
140
  var location = shallowClone(initialLocation)
173
141
 
142
+ var sessionIsActive = true
174
143
  var name
175
144
  var service
176
145
  var version
@@ -210,6 +179,15 @@ function newView(
210
179
  var setLoadEvent = _trackViewMetrics.setLoadEvent
211
180
  var stopViewMetricsTracking = _trackViewMetrics.stop
212
181
  var viewMetrics = _trackViewMetrics.viewMetrics
182
+
183
+ var _trackInitialViewTimings =
184
+ loadingType === ViewLoadingType.INITIAL_LOAD
185
+ ? trackInitialViewTimings(lifeCycle, setLoadEvent, scheduleViewUpdate)
186
+ : { scheduleStop: noop, timings: {} }
187
+ var scheduleStopInitialViewTimingsTracking =
188
+ _trackInitialViewTimings.scheduleStop
189
+ var timings = _trackInitialViewTimings.timings
190
+
213
191
  var _trackViewEventCounts = trackViewEventCounts(
214
192
  lifeCycle,
215
193
  id,
@@ -217,10 +195,18 @@ function newView(
217
195
  )
218
196
  var scheduleStopEventCountsTracking = _trackViewEventCounts.scheduleStop
219
197
  var eventCounts = _trackViewEventCounts.eventCounts
198
+
199
+ // Session keep alive
200
+ var keepAliveIntervalId = setInterval(
201
+ triggerViewUpdate,
202
+ SESSION_KEEP_ALIVE_INTERVAL
203
+ )
220
204
  // Initial view update
221
205
  triggerViewUpdate()
222
206
 
223
207
  function triggerViewUpdate() {
208
+ cancelScheduleViewUpdate()
209
+
224
210
  documentVersion += 1
225
211
  var currentEnd =
226
212
  endClocks === undefined ? timeStampNow() : endClocks.timeStamp
@@ -240,6 +226,7 @@ function newView(
240
226
  timings: timings,
241
227
  duration: elapsed(startClocks.timeStamp, currentEnd),
242
228
  isActive: endClocks === undefined,
229
+ sessionIsActive: sessionIsActive,
243
230
  eventCounts: eventCounts
244
231
  },
245
232
  viewMetrics
@@ -252,31 +239,36 @@ function newView(
252
239
  service: service,
253
240
  version: version,
254
241
  scheduleUpdate: scheduleViewUpdate,
255
- end: function (clocks) {
256
- if (typeof clocks === 'undefined') {
257
- clocks = clocksNow()
242
+ end: function (options) {
243
+ if (endClocks) {
244
+ // view already ended
245
+ return
258
246
  }
259
- endClocks = clocks
247
+ endClocks = isNullUndefinedDefaultValue(
248
+ options && options.endClocks,
249
+ clocksNow()
250
+ )
251
+ sessionIsActive = isNullUndefinedDefaultValue(
252
+ options && options.sessionIsActive,
253
+ true
254
+ )
260
255
  lifeCycle.notify(LifeCycleEventType.VIEW_ENDED, { endClocks: endClocks })
256
+ clearInterval(keepAliveIntervalId)
261
257
  stopViewMetricsTracking()
262
- scheduleStopEventCountsTracking
263
- },
264
- triggerUpdate: function () {
265
- // cancel any pending view updates execution
266
- cancelScheduleViewUpdate()
258
+ scheduleStopInitialViewTimingsTracking()
259
+ scheduleStopEventCountsTracking()
267
260
  triggerViewUpdate()
268
261
  },
269
- updateTimings: function (newTimings) {
270
- timings = newTimings
271
- if (newTimings.loadEvent !== undefined) {
272
- setLoadEvent(newTimings.loadEvent)
273
- }
274
- },
262
+
275
263
  addTiming: function (name, time) {
264
+ if (endClocks) {
265
+ return
266
+ }
276
267
  var relativeTime = looksLikeRelativeTime(time)
277
268
  ? time
278
269
  : elapsed(startClocks.timeStamp, time)
279
270
  customTimings[sanitizeTiming(name)] = relativeTime
271
+ scheduleViewUpdate()
280
272
  }
281
273
  }
282
274
  }
@@ -127,7 +127,8 @@ function processViewUpdate(view, foregroundContexts, recorderApi) {
127
127
  )
128
128
  },
129
129
  session: {
130
- has_replay: replayStats ? true : undefined
130
+ has_replay: replayStats ? true : undefined,
131
+ is_active: view.sessionIsActive ? undefined : false
131
132
  }
132
133
  }
133
134
  if (!isEmptyObject(view.customTimings)) {
@@ -52,7 +52,9 @@ export function startRumSessionManager(configuration, lifeCycle) {
52
52
  plan: plan,
53
53
  sessionReplayAllowed: plan === RumSessionPlan.WITH_SESSION_REPLAY
54
54
  }
55
- }
55
+ },
56
+ expire: sessionManager.expire,
57
+ expireObservable: sessionManager.expireObservable
56
58
  }
57
59
  }
58
60
 
@@ -86,7 +86,7 @@ export function findTraceComment(document) {
86
86
 
87
87
  function getTraceCommentFromNode(node) {
88
88
  if (node && isCommentNode(node)) {
89
- var match = node.data.match(/^\s*DATADOG;(.*?)\s*$/)
89
+ var match = node.data.match(/^\s*GUANCE;(.*?)\s*$/)
90
90
  if (match) {
91
91
  return match[1]
92
92
  }
@@ -5,7 +5,9 @@ import {
5
5
  LifeCycleEventType,
6
6
  some,
7
7
  matchList,
8
- instrumentMethodAndCallOriginal
8
+ instrumentMethodAndCallOriginal,
9
+ setTimeout,
10
+ clearTimeout
9
11
  } from '@cloudcare/browser-core'
10
12
 
11
13
  // Delay to wait for a page activity to validate the tracking process
@@ -75,10 +77,11 @@ export function doWaitPageActivityEnd(
75
77
  }, PAGE_ACTIVITY_VALIDATION_DELAY)
76
78
 
77
79
  var maxDurationTimeoutId =
78
- maxDuration &&
79
- setTimeout(function () {
80
- return complete({ hadActivity: true, end: timeStampNow() })
81
- }, maxDuration)
80
+ maxDuration !== undefined
81
+ ? setTimeout(function () {
82
+ return complete({ hadActivity: true, end: timeStampNow() })
83
+ }, maxDuration)
84
+ : undefined
82
85
 
83
86
  var pageActivitySubscription = pageActivityObservable.subscribe(function (
84
87
  data
@@ -2,16 +2,23 @@ import {
2
2
  Batch,
3
3
  createHttpRequest,
4
4
  LifeCycleEventType,
5
- RumEventType
5
+ RumEventType,
6
+ createFlushController
6
7
  } from '@cloudcare/browser-core'
7
8
 
8
9
  export function startRumBatch(
9
10
  configuration,
10
11
  lifeCycle,
11
12
  reportError,
12
- pageExitObservable
13
+ pageExitObservable,
14
+ sessionExpireObservable
13
15
  ) {
14
- var batch = makeRumBatch(configuration, reportError, pageExitObservable)
16
+ var batch = makeRumBatch(
17
+ configuration,
18
+ reportError,
19
+ pageExitObservable,
20
+ sessionExpireObservable
21
+ )
15
22
 
16
23
  lifeCycle.subscribe(
17
24
  LifeCycleEventType.RUM_EVENT_COLLECTED,
@@ -25,24 +32,40 @@ export function startRumBatch(
25
32
  )
26
33
  }
27
34
 
28
- function makeRumBatch(configuration, reportError, pageExitObservable) {
29
- var primaryBatch = createRumBatch(configuration.datakitUrl)
30
- function createRumBatch(endpointUrl, unloadCallback) {
31
- return new Batch(
35
+ function makeRumBatch(
36
+ configuration,
37
+ reportError,
38
+ pageExitObservable,
39
+ sessionExpireObservable
40
+ ) {
41
+ var rumBatch = createRumBatch(configuration.datakitUrl)
42
+ var primaryBatch = rumBatch.batch
43
+ var primaryFlushController = rumBatch.flushController
44
+ function createRumBatch(endpointUrl) {
45
+ var flushController = createFlushController({
46
+ messagesLimit: configuration.batchMessagesLimit,
47
+ bytesLimit: configuration.batchBytesLimit,
48
+ durationLimit: configuration.flushTimeout,
49
+ pageExitObservable: pageExitObservable,
50
+ sessionExpireObservable: sessionExpireObservable
51
+ })
52
+ var batch = new Batch(
32
53
  createHttpRequest(
33
54
  endpointUrl,
34
55
  configuration.batchBytesLimit,
35
56
  reportError
36
57
  ),
37
- configuration.batchMessagesLimit,
38
- configuration.batchBytesLimit,
39
- configuration.messageBytesLimit,
40
- configuration.flushTimeout,
41
- pageExitObservable
58
+ flushController,
59
+ configuration.messageBytesLimit
42
60
  )
61
+ return {
62
+ batch: batch,
63
+ flushController: flushController
64
+ }
43
65
  }
44
66
 
45
67
  return {
68
+ flushObservable: primaryFlushController.flushObservable,
46
69
  add: function (message) {
47
70
  primaryBatch.add(message)
48
71
  },