@cloudcare/browser-rum 3.1.18 → 3.1.20

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 (151) hide show
  1. package/bundle/dataflux-rum.js +1 -1
  2. package/cjs/boot/buildEnv.js +1 -1
  3. package/cjs/boot/rum.js +11 -10
  4. package/cjs/boot/rum.js.map +1 -1
  5. package/cjs/domain/assembly.js.map +1 -1
  6. package/cjs/domain/contexts/pageStateHistory.js +4 -1
  7. package/cjs/domain/contexts/pageStateHistory.js.map +1 -1
  8. package/cjs/domain/contexts/urlContexts.js +6 -7
  9. package/cjs/domain/contexts/urlContexts.js.map +1 -1
  10. package/cjs/domain/contexts/viewContexts.js +9 -1
  11. package/cjs/domain/contexts/viewContexts.js.map +1 -1
  12. package/cjs/domain/locationChangeObservable.js +6 -4
  13. package/cjs/domain/locationChangeObservable.js.map +1 -1
  14. package/cjs/domain/performanceCollection.js +40 -90
  15. package/cjs/domain/performanceCollection.js.map +1 -1
  16. package/cjs/domain/performanceObservable.js +113 -0
  17. package/cjs/domain/performanceObservable.js.map +1 -0
  18. package/cjs/domain/performanceUtils.js +20 -0
  19. package/cjs/domain/performanceUtils.js.map +1 -0
  20. package/cjs/domain/replay/deflate/deflateWorker.js +1 -1
  21. package/cjs/domain/replay/record/observers.js +58 -54
  22. package/cjs/domain/replay/record/observers.js.map +1 -1
  23. package/cjs/domain/requestCollection.js +6 -2
  24. package/cjs/domain/requestCollection.js.map +1 -1
  25. package/cjs/domain/rumEventsCollection/actions/trackClickActions.js +3 -1
  26. package/cjs/domain/rumEventsCollection/actions/trackClickActions.js.map +1 -1
  27. package/cjs/domain/rumEventsCollection/longTask/longTaskCollection.js +5 -7
  28. package/cjs/domain/rumEventsCollection/longTask/longTaskCollection.js.map +1 -1
  29. package/cjs/domain/rumEventsCollection/resource/{matchRequestTiming.js → matchRequestResourceEntry.js} +4 -4
  30. package/cjs/domain/rumEventsCollection/resource/matchRequestResourceEntry.js.map +1 -0
  31. package/cjs/domain/rumEventsCollection/resource/resourceCollection.js +64 -66
  32. package/cjs/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
  33. package/cjs/domain/rumEventsCollection/resource/resourceUtils.js +18 -14
  34. package/cjs/domain/rumEventsCollection/resource/resourceUtils.js.map +1 -1
  35. package/cjs/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js +41 -0
  36. package/cjs/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js.map +1 -0
  37. package/cjs/domain/rumEventsCollection/view/trackCommonViewMetrics.js +1 -1
  38. package/cjs/domain/rumEventsCollection/view/trackCommonViewMetrics.js.map +1 -1
  39. package/cjs/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +8 -5
  40. package/cjs/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
  41. package/cjs/domain/rumEventsCollection/view/trackFirstContentfulPaint.js +2 -1
  42. package/cjs/domain/rumEventsCollection/view/trackFirstContentfulPaint.js.map +1 -1
  43. package/cjs/domain/rumEventsCollection/view/trackFirstInput.js +2 -1
  44. package/cjs/domain/rumEventsCollection/view/trackFirstInput.js.map +1 -1
  45. package/cjs/domain/rumEventsCollection/view/trackInitialViewTimings.js +1 -1
  46. package/cjs/domain/rumEventsCollection/view/trackInitialViewTimings.js.map +1 -1
  47. package/cjs/domain/rumEventsCollection/view/trackInteractionToNextPaint.js +3 -19
  48. package/cjs/domain/rumEventsCollection/view/trackInteractionToNextPaint.js.map +1 -1
  49. package/cjs/domain/rumEventsCollection/view/trackLargestContentfulPaint.js +2 -1
  50. package/cjs/domain/rumEventsCollection/view/trackLargestContentfulPaint.js.map +1 -1
  51. package/cjs/domain/rumEventsCollection/view/trackNavigationTimings.js +49 -25
  52. package/cjs/domain/rumEventsCollection/view/trackNavigationTimings.js.map +1 -1
  53. package/cjs/domain/rumEventsCollection/view/trackViewEventCounts.js +1 -22
  54. package/cjs/domain/rumEventsCollection/view/trackViewEventCounts.js.map +1 -1
  55. package/cjs/domain/rumEventsCollection/view/trackViews.js +1 -1
  56. package/cjs/domain/rumEventsCollection/view/trackViews.js.map +1 -1
  57. package/cjs/domain/rumEventsCollection/view/viewCollection.js +1 -0
  58. package/cjs/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
  59. package/cjs/domain/waitPageActivityEnd.js +6 -5
  60. package/cjs/domain/waitPageActivityEnd.js.map +1 -1
  61. package/esm/boot/buildEnv.js +1 -1
  62. package/esm/boot/rum.js +11 -10
  63. package/esm/boot/rum.js.map +1 -1
  64. package/esm/domain/assembly.js.map +1 -1
  65. package/esm/domain/contexts/pageStateHistory.js +5 -2
  66. package/esm/domain/contexts/pageStateHistory.js.map +1 -1
  67. package/esm/domain/contexts/urlContexts.js +7 -8
  68. package/esm/domain/contexts/urlContexts.js.map +1 -1
  69. package/esm/domain/contexts/viewContexts.js +10 -2
  70. package/esm/domain/contexts/viewContexts.js.map +1 -1
  71. package/esm/domain/locationChangeObservable.js +7 -5
  72. package/esm/domain/locationChangeObservable.js.map +1 -1
  73. package/esm/domain/performanceCollection.js +41 -89
  74. package/esm/domain/performanceCollection.js.map +1 -1
  75. package/esm/domain/performanceObservable.js +105 -0
  76. package/esm/domain/performanceObservable.js.map +1 -0
  77. package/esm/domain/performanceUtils.js +14 -0
  78. package/esm/domain/performanceUtils.js.map +1 -0
  79. package/esm/domain/replay/deflate/deflateWorker.js +1 -1
  80. package/esm/domain/replay/record/observers.js +59 -55
  81. package/esm/domain/replay/record/observers.js.map +1 -1
  82. package/esm/domain/requestCollection.js +6 -2
  83. package/esm/domain/requestCollection.js.map +1 -1
  84. package/esm/domain/rumEventsCollection/actions/trackClickActions.js +4 -2
  85. package/esm/domain/rumEventsCollection/actions/trackClickActions.js.map +1 -1
  86. package/esm/domain/rumEventsCollection/longTask/longTaskCollection.js +6 -8
  87. package/esm/domain/rumEventsCollection/longTask/longTaskCollection.js.map +1 -1
  88. package/esm/domain/rumEventsCollection/resource/{matchRequestTiming.js → matchRequestResourceEntry.js} +5 -5
  89. package/esm/domain/rumEventsCollection/resource/matchRequestResourceEntry.js.map +1 -0
  90. package/esm/domain/rumEventsCollection/resource/resourceCollection.js +66 -68
  91. package/esm/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
  92. package/esm/domain/rumEventsCollection/resource/resourceUtils.js +12 -9
  93. package/esm/domain/rumEventsCollection/resource/resourceUtils.js.map +1 -1
  94. package/esm/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js +35 -0
  95. package/esm/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js.map +1 -0
  96. package/esm/domain/rumEventsCollection/view/trackCommonViewMetrics.js +1 -1
  97. package/esm/domain/rumEventsCollection/view/trackCommonViewMetrics.js.map +1 -1
  98. package/esm/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +9 -7
  99. package/esm/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
  100. package/esm/domain/rumEventsCollection/view/trackFirstContentfulPaint.js +2 -1
  101. package/esm/domain/rumEventsCollection/view/trackFirstContentfulPaint.js.map +1 -1
  102. package/esm/domain/rumEventsCollection/view/trackFirstInput.js +2 -2
  103. package/esm/domain/rumEventsCollection/view/trackFirstInput.js.map +1 -1
  104. package/esm/domain/rumEventsCollection/view/trackInitialViewTimings.js +1 -1
  105. package/esm/domain/rumEventsCollection/view/trackInitialViewTimings.js.map +1 -1
  106. package/esm/domain/rumEventsCollection/view/trackInteractionToNextPaint.js +2 -19
  107. package/esm/domain/rumEventsCollection/view/trackInteractionToNextPaint.js.map +1 -1
  108. package/esm/domain/rumEventsCollection/view/trackLargestContentfulPaint.js +2 -2
  109. package/esm/domain/rumEventsCollection/view/trackLargestContentfulPaint.js.map +1 -1
  110. package/esm/domain/rumEventsCollection/view/trackNavigationTimings.js +50 -26
  111. package/esm/domain/rumEventsCollection/view/trackNavigationTimings.js.map +1 -1
  112. package/esm/domain/rumEventsCollection/view/trackViewEventCounts.js +1 -21
  113. package/esm/domain/rumEventsCollection/view/trackViewEventCounts.js.map +1 -1
  114. package/esm/domain/rumEventsCollection/view/trackViews.js +1 -1
  115. package/esm/domain/rumEventsCollection/view/trackViews.js.map +1 -1
  116. package/esm/domain/rumEventsCollection/view/viewCollection.js +1 -0
  117. package/esm/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
  118. package/esm/domain/waitPageActivityEnd.js +7 -7
  119. package/esm/domain/waitPageActivityEnd.js.map +1 -1
  120. package/package.json +4 -4
  121. package/src/boot/rum.js +18 -9
  122. package/src/domain/assembly.js +0 -1
  123. package/src/domain/contexts/pageStateHistory.js +5 -5
  124. package/src/domain/contexts/urlContexts.js +11 -15
  125. package/src/domain/contexts/viewContexts.js +10 -3
  126. package/src/domain/locationChangeObservable.js +17 -7
  127. package/src/domain/performanceCollection.js +55 -138
  128. package/src/domain/performanceObservable.js +148 -0
  129. package/src/domain/performanceUtils.js +16 -0
  130. package/src/domain/replay/record/observers.js +39 -35
  131. package/src/domain/requestCollection.js +6 -2
  132. package/src/domain/rumEventsCollection/actions/trackClickActions.js +4 -2
  133. package/src/domain/rumEventsCollection/longTask/longTaskCollection.js +7 -8
  134. package/src/domain/rumEventsCollection/resource/{matchRequestTiming.js → matchRequestResourceEntry.js} +10 -4
  135. package/src/domain/rumEventsCollection/resource/resourceCollection.js +74 -117
  136. package/src/domain/rumEventsCollection/resource/resourceUtils.js +13 -11
  137. package/src/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js +45 -0
  138. package/src/domain/rumEventsCollection/view/trackCommonViewMetrics.js +2 -1
  139. package/src/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +24 -7
  140. package/src/domain/rumEventsCollection/view/trackFirstContentfulPaint.js +2 -1
  141. package/src/domain/rumEventsCollection/view/trackFirstInput.js +2 -2
  142. package/src/domain/rumEventsCollection/view/trackInitialViewTimings.js +1 -1
  143. package/src/domain/rumEventsCollection/view/trackInteractionToNextPaint.js +7 -19
  144. package/src/domain/rumEventsCollection/view/trackLargestContentfulPaint.js +3 -2
  145. package/src/domain/rumEventsCollection/view/trackNavigationTimings.js +65 -32
  146. package/src/domain/rumEventsCollection/view/trackViewEventCounts.js +1 -24
  147. package/src/domain/rumEventsCollection/view/trackViews.js +1 -1
  148. package/src/domain/rumEventsCollection/view/viewCollection.js +4 -0
  149. package/src/domain/waitPageActivityEnd.js +16 -17
  150. package/cjs/domain/rumEventsCollection/resource/matchRequestTiming.js.map +0 -1
  151. package/esm/domain/rumEventsCollection/resource/matchRequestTiming.js.map +0 -1
@@ -4,7 +4,7 @@ import {
4
4
  assign,
5
5
  getRelativeTime,
6
6
  ONE_MINUTE,
7
- ContextHistory,
7
+ createValueHistory,
8
8
  UUID,
9
9
  clocksNow,
10
10
  ONE_SECOND,
@@ -38,7 +38,9 @@ export function trackClickActions(
38
38
  domMutationObservable,
39
39
  configuration
40
40
  ) {
41
- var history = new ContextHistory(ACTION_CONTEXT_TIME_OUT_DELAY)
41
+ var history = new createValueHistory({
42
+ expireDelay: ACTION_CONTEXT_TIME_OUT_DELAY
43
+ })
42
44
  var stopObservable = new Observable()
43
45
  var currentClickChain
44
46
 
@@ -3,19 +3,17 @@ import {
3
3
  relativeToClocks,
4
4
  RumEventType,
5
5
  LifeCycleEventType,
6
- UUID
6
+ UUID,
7
+ RumLongTaskEntryType
7
8
  } from '@cloudcare/browser-core'
8
- export function startLongTaskCollection(lifeCycle, sessionManager) {
9
+ import { RumPerformanceEntryType } from '../../performanceObservable'
10
+ export function startLongTaskCollection(lifeCycle) {
9
11
  lifeCycle.subscribe(
10
12
  LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED,
11
13
  function (entries) {
12
14
  for (var i = 0; i < entries.length; i++) {
13
15
  var entry = entries[i]
14
- if (entry.entryType !== 'longtask') {
15
- return
16
- }
17
- var session = sessionManager.findTrackedSession(entry.startTime)
18
- if (!session) {
16
+ if (entry.entryType !== RumPerformanceEntryType.LONG_TASK) {
19
17
  break
20
18
  }
21
19
 
@@ -24,6 +22,7 @@ export function startLongTaskCollection(lifeCycle, sessionManager) {
24
22
  date: startClocks.timeStamp,
25
23
  long_task: {
26
24
  id: UUID(),
25
+ entryType: RumLongTaskEntryType.LONG_TASK,
27
26
  duration: toServerDuration(entry.duration)
28
27
  },
29
28
  type: RumEventType.LONG_TASK
@@ -31,7 +30,7 @@ export function startLongTaskCollection(lifeCycle, sessionManager) {
31
30
  lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
32
31
  rawRumEvent: rawRumEvent,
33
32
  startTime: startClocks.relative,
34
- domainContext: { performanceEntry: entry.toJSON() }
33
+ domainContext: { performanceEntry: entry }
35
34
  })
36
35
  }
37
36
  }
@@ -1,5 +1,8 @@
1
- import { isValidEntry } from './resourceUtils'
2
- import { map, filter, addDuration, WeakSet } from '@cloudcare/browser-core'
1
+ import {
2
+ hasValidResourceEntryDuration,
3
+ hasValidResourceEntryTimings
4
+ } from './resourceUtils'
5
+ import { filter, addDuration, WeakSet } from '@cloudcare/browser-core'
3
6
 
4
7
  var alreadyMatchedEntries = new WeakSet()
5
8
  /**
@@ -15,7 +18,7 @@ var alreadyMatchedEntries = new WeakSet()
15
18
  * - if two following timings match (OPTIONS request), return the timing for the actual request
16
19
  * - otherwise we can't decide, return undefined
17
20
  */
18
- export function matchRequestTiming(request) {
21
+ export function matchRequestResourceEntry(request) {
19
22
  if (!performance || !('getEntriesByName' in performance)) {
20
23
  return
21
24
  }
@@ -29,7 +32,10 @@ export function matchRequestTiming(request) {
29
32
  })
30
33
 
31
34
  candidates = filter(candidates, function (entry) {
32
- return isValidEntry(entry)
35
+ return (
36
+ hasValidResourceEntryDuration(entry) &&
37
+ hasValidResourceEntryTimings(entry)
38
+ )
33
39
  })
34
40
  candidates = filter(candidates, function (entry) {
35
41
  return isBetween(
@@ -10,93 +10,85 @@ import {
10
10
  ResourceType,
11
11
  RumEventType,
12
12
  LifeCycleEventType,
13
- toServerDuration,
14
- some,
15
- isNullUndefinedDefaultValue
13
+ toServerDuration
16
14
  } from '@cloudcare/browser-core'
17
- import { matchRequestTiming } from './matchRequestTiming'
15
+ import { matchRequestResourceEntry } from './matchRequestResourceEntry'
18
16
  import {
19
17
  computePerformanceResourceDetails,
20
- computePerformanceResourceDuration,
21
- computeResourceKind,
22
- computeSize,
23
- isRequestKind,
24
- is304,
25
- isCacheHit,
18
+ computeResourceEntryDuration,
19
+ computeResourceEntryType,
20
+ computeResourceEntrySize,
21
+ isResourceEntryRequestType,
26
22
  isResourceUrlLimit,
27
23
  isLongDataUrl,
28
24
  sanitizeDataUrl
29
25
  } from './resourceUtils'
30
- import { PageState } from '../../contexts/pageStateHistory.js'
26
+ import { PageState } from '../../contexts/pageStateHistory'
27
+ import {
28
+ createPerformanceObservable,
29
+ RumPerformanceEntryType
30
+ } from '../../performanceObservable'
31
+ import { retrieveInitialDocumentResourceTiming } from './retrieveInitialDocumentResourceTiming'
31
32
  export function startResourceCollection(
32
33
  lifeCycle,
33
34
  configuration,
34
- sessionManager,
35
- pageStateHistory
35
+ pageStateHistory,
36
+ retrieveInitialDocumentResourceTimingImpl
36
37
  ) {
38
+ if (typeof retrieveInitialDocumentResourceTimingImpl === 'undefined') {
39
+ retrieveInitialDocumentResourceTimingImpl =
40
+ retrieveInitialDocumentResourceTiming
41
+ }
37
42
  lifeCycle.subscribe(LifeCycleEventType.REQUEST_COMPLETED, function (request) {
38
- var rawEvent = processRequest(
39
- request,
40
- configuration,
41
- sessionManager,
42
- pageStateHistory
43
- )
43
+ var rawEvent = processRequest(request, pageStateHistory)
44
44
  if (rawEvent) {
45
45
  lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, rawEvent)
46
46
  }
47
47
  })
48
-
49
- lifeCycle.subscribe(
50
- LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED,
51
- function (entries) {
52
- for (var i = 0; i < entries.length; i++) {
53
- var entry = entries[i]
54
- if (
55
- entry.entryType === 'resource' &&
56
- !isRequestKind(entry) &&
57
- !isResourceUrlLimit(entry.name, configuration.resourceUrlLimit)
58
- ) {
59
- var rawEvent = processResourceEntry(
60
- entry,
61
- configuration,
62
- sessionManager,
63
- pageStateHistory
64
- )
65
- if (rawEvent) {
66
- lifeCycle.notify(
67
- LifeCycleEventType.RAW_RUM_EVENT_COLLECTED,
68
- rawEvent
69
- )
70
- }
48
+ var performanceResourceSubscription = createPerformanceObservable(
49
+ configuration,
50
+ {
51
+ type: RumPerformanceEntryType.RESOURCE,
52
+ buffered: true
53
+ }
54
+ ).subscribe(function (entries) {
55
+ for (var entry of entries) {
56
+ if (
57
+ !isResourceEntryRequestType(entry) &&
58
+ !isResourceUrlLimit(entry.name, configuration.resourceUrlLimit)
59
+ ) {
60
+ var rawEvent = processResourceEntry(entry, configuration)
61
+ if (rawEvent) {
62
+ lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, rawEvent)
71
63
  }
72
64
  }
73
65
  }
74
- )
66
+ })
67
+
68
+ retrieveInitialDocumentResourceTimingImpl(configuration, function (timing) {
69
+ var rawEvent = processResourceEntry(timing, configuration)
70
+ if (rawEvent) {
71
+ lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, rawEvent)
72
+ }
73
+ })
74
+ return {
75
+ stop: function () {
76
+ performanceResourceSubscription.unsubscribe()
77
+ }
78
+ }
75
79
  }
76
80
 
77
- function processRequest(
78
- request,
79
- configuration,
80
- sessionManager,
81
- pageStateHistory
82
- ) {
83
- var matchingTiming = matchRequestTiming(request)
81
+ function processRequest(request, pageStateHistory) {
82
+ var matchingTiming = matchRequestResourceEntry(request)
84
83
  var startClocks = matchingTiming
85
84
  ? relativeToClocks(matchingTiming.startTime)
86
85
  : request.startClocks
87
- var shouldIndex = shouldIndexResource(
88
- configuration,
89
- sessionManager,
90
- startClocks
91
- )
92
86
  var tracingInfo = computeRequestTracingInfo(request)
93
- if (!shouldIndex && !tracingInfo) {
94
- return
95
- }
87
+
96
88
  var type =
97
89
  request.type === RequestType.XHR ? ResourceType.XHR : ResourceType.FETCH
98
90
  var correspondingTimingOverrides = matchingTiming
99
- ? computePerformanceEntryMetrics(matchingTiming)
91
+ ? computeResourceEntryMetrics(matchingTiming)
100
92
  : undefined
101
93
 
102
94
  var duration = computeRequestDuration(
@@ -104,14 +96,7 @@ function processRequest(
104
96
  startClocks,
105
97
  request.duration
106
98
  )
107
- // var pageStateInfo = computePageStateInfo(
108
- // pageStateHistory,
109
- // startClocks,
110
- // isNullUndefinedDefaultValue(
111
- // matchingTiming && matchingTiming.duration,
112
- // request.duration
113
- // )
114
- // )
99
+
115
100
  var urlObj = urlParse(request.url).getParse()
116
101
  var resourceEvent = extend2Lev(
117
102
  {
@@ -145,44 +130,19 @@ function processRequest(
145
130
  response: request.response,
146
131
  requestInput: request.input,
147
132
  requestInit: request.init,
148
- error: request.error
133
+ error: request.error,
134
+ isAborted: request.isAborted,
135
+ handlingStack: request.handlingStack
149
136
  }
150
137
  }
151
138
  }
152
139
 
153
- function processResourceEntry(
154
- entry,
155
- configuration,
156
- sessionManager,
157
- pageStateHistory
158
- ) {
140
+ function processResourceEntry(entry, configuration) {
159
141
  var startClocks = relativeToClocks(entry.startTime)
160
- var shouldIndex = shouldIndexResource(
161
- configuration,
162
- sessionManager,
163
- startClocks
164
- )
165
- var tracingInfo = computeEntryTracingInfo(entry)
166
- if (!shouldIndex && !tracingInfo) {
167
- return
168
- }
169
- var type = computeResourceKind(entry)
170
- var entryMetrics = computePerformanceEntryMetrics(entry)
142
+ var tracingInfo = computeResourceEntryTracingInfo(entry)
143
+ var type = computeResourceEntryType(entry)
144
+ var entryMetrics = computeResourceEntryMetrics(entry)
171
145
  var urlObj = urlParse(entry.name).getParse()
172
- var statusCode = ''
173
- if (entry.responseStatus !== 0) {
174
- statusCode = entry.responseStatus
175
- } else if (is304(entry)) {
176
- statusCode = 304
177
- } else if (isCacheHit(entry)) {
178
- statusCode = 200
179
- }
180
- // var pageStateInfo = computePageStateInfo(
181
- // pageStateHistory,
182
- // startClocks,
183
- // entry.duration
184
- // )
185
-
186
146
  var resourceEvent = extend2Lev(
187
147
  {
188
148
  date: startClocks.timeStamp,
@@ -195,8 +155,8 @@ function processResourceEntry(
195
155
  urlPathGroup: replaceNumberCharByPath(urlObj.Path),
196
156
  urlQuery: getQueryParamsFromUrl(entry.name),
197
157
  method: 'GET',
198
- status: statusCode,
199
- statusGroup: getStatusGroup(statusCode)
158
+ status: discardZeroStatus(entry.responseStatus),
159
+ statusGroup: getStatusGroup(entry.responseStatus)
200
160
  },
201
161
  type: RumEventType.RESOURCE
202
162
  },
@@ -211,19 +171,16 @@ function processResourceEntry(
211
171
  }
212
172
  }
213
173
  }
214
- function shouldIndexResource(configuration, sessionManager, resourceStart) {
215
- return sessionManager.findTrackedSession(resourceStart.relative)
216
- }
217
174
 
218
- function computePerformanceEntryMetrics(timing) {
175
+ function computeResourceEntryMetrics(entry) {
219
176
  return {
220
177
  resource: extend2Lev(
221
178
  {},
222
179
  {
223
- duration: computePerformanceResourceDuration(timing)
180
+ duration: computeResourceEntryDuration(entry)
224
181
  },
225
- computeSize(timing),
226
- computePerformanceResourceDetails(timing)
182
+ computeResourceEntrySize(entry),
183
+ computePerformanceResourceDetails(entry)
227
184
  )
228
185
  }
229
186
  }
@@ -241,14 +198,7 @@ function computeRequestTracingInfo(request) {
241
198
  resource: { id: UUID() }
242
199
  }
243
200
  }
244
- // function computePageStateInfo(pageStateHistory, startClocks, duration) {
245
- // return {
246
- // _gc: {
247
- // page_states: pageStateHistory.findAll(startClocks.relative, duration),
248
- // page_was_discarded: String(document.wasDiscarded)
249
- // }
250
- // }
251
- // }
201
+
252
202
  function computeRequestDuration(pageStateHistory, startClocks, duration) {
253
203
  return !pageStateHistory.wasInPageStateDuringPeriod(
254
204
  PageState.FROZEN,
@@ -258,6 +208,13 @@ function computeRequestDuration(pageStateHistory, startClocks, duration) {
258
208
  ? toServerDuration(duration)
259
209
  : undefined
260
210
  }
261
- function computeEntryTracingInfo(entry) {
211
+ function computeResourceEntryTracingInfo(entry) {
262
212
  return entry.traceId ? { _gc: { traceId: entry.traceId } } : undefined
263
213
  }
214
+ /**
215
+ * The status is 0 for cross-origin resources without CORS headers, so the status is meaningless, and we shouldn't report it
216
+ * https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/responseStatus#cross-origin_response_status_codes
217
+ */
218
+ function discardZeroStatus(statusCode) {
219
+ return statusCode === 0 ? undefined : statusCode
220
+ }
@@ -75,8 +75,8 @@ var RESOURCE_TYPES = [
75
75
  ]
76
76
  ]
77
77
 
78
- export function computeResourceKind(timing) {
79
- var url = timing.name
78
+ export function computeResourceEntryType(entry) {
79
+ var url = entry.name
80
80
  if (!isValidUrl(url)) {
81
81
  return ResourceType.OTHER
82
82
  }
@@ -85,7 +85,8 @@ export function computeResourceKind(timing) {
85
85
  each(RESOURCE_TYPES, function (res) {
86
86
  var _type = res[0],
87
87
  isType = res[1]
88
- if (isType(timing.initiatorType, path)) {
88
+
89
+ if (isType(entry.initiatorType, path)) {
89
90
  type = _type
90
91
  return false
91
92
  }
@@ -102,10 +103,9 @@ function areInOrder() {
102
103
  return true
103
104
  }
104
105
 
105
- export function isRequestKind(timing) {
106
+ export function isResourceEntryRequestType(entry) {
106
107
  return (
107
- timing.initiatorType === 'xmlhttprequest' ||
108
- timing.initiatorType === 'fetch'
108
+ entry.initiatorType === 'xmlhttprequest' || entry.initiatorType === 'fetch'
109
109
  )
110
110
  }
111
111
  var HAS_MULTI_BYTES_CHARACTERS = /[^\u0000-\u007F]/
@@ -123,7 +123,7 @@ export function getStrSize(candidate) {
123
123
  export function isResourceUrlLimit(name, limitSize) {
124
124
  return getStrSize(name) > limitSize
125
125
  }
126
- export function computePerformanceResourceDuration(entry) {
126
+ export function computeResourceEntryDuration(entry) {
127
127
  // Safari duration is always 0 on timings blocked by cross origin policies.
128
128
  if (entry.duration === 0 && entry.startTime < entry.responseEnd) {
129
129
  return msToNs(entry.responseEnd - entry.startTime)
@@ -221,7 +221,7 @@ export function isCacheHit(entry) {
221
221
 
222
222
  // · loadEventEnd:返回当前网页load事件的回调函数运行结束时的Unix毫秒时间戳。如果该事件还没有发生,返回0
223
223
  export function computePerformanceResourceDetails(entry) {
224
- if (!isValidEntry(entry)) {
224
+ if (!hasValidResourceEntryTimings(entry)) {
225
225
  return undefined
226
226
  }
227
227
 
@@ -281,8 +281,10 @@ export function computePerformanceResourceDetails(entry) {
281
281
  }
282
282
  return details
283
283
  }
284
-
285
- export function isValidEntry(entry) {
284
+ export function hasValidResourceEntryDuration(entry) {
285
+ return entry.duration >= 0
286
+ }
287
+ export function hasValidResourceEntryTimings(entry) {
286
288
  // Ensure timings are in the right order. On top of filtering out potential invalid
287
289
  // RumPerformanceResourceTiming, it will ignore entries from requests where timings cannot be
288
290
  // collected, for example cross origin requests without a "Timing-Allow-Origin" header allowing
@@ -364,7 +366,7 @@ function formatTiming(origin, start, end) {
364
366
  }
365
367
  }
366
368
 
367
- export function computeSize(entry) {
369
+ export function computeResourceEntrySize(entry) {
368
370
  // Make sure a request actually occurred
369
371
  if (entry.startTime < entry.responseStart) {
370
372
  return {
@@ -0,0 +1,45 @@
1
+ import { runOnReadyState, assign } from '@cloudcare/browser-core'
2
+ import {
3
+ RumPerformanceEntryType,
4
+ supportPerformanceTimingEvent
5
+ } from '../../performanceObservable'
6
+ import { FAKE_INITIAL_DOCUMENT } from './resourceUtils'
7
+ import { computeRelativePerformanceTiming } from '../../performanceUtils'
8
+ export function retrieveInitialDocumentResourceTiming(configuration, callback) {
9
+ runOnReadyState('interactive', function () {
10
+ var timing
11
+ var forcedAttributes = {
12
+ entryType: RumPerformanceEntryType.RESOURCE,
13
+ initiatorType: FAKE_INITIAL_DOCUMENT,
14
+ toJSON: function () {
15
+ return assign({}, timing, { toJSON: undefined })
16
+ }
17
+ }
18
+ if (
19
+ supportPerformanceTimingEvent(RumPerformanceEntryType.NAVIGATION) &&
20
+ performance.getEntriesByType(RumPerformanceEntryType.NAVIGATION).length >
21
+ 0
22
+ ) {
23
+ var navigationEntry = performance.getEntriesByType(
24
+ RumPerformanceEntryType.NAVIGATION
25
+ )[0]
26
+ timing = assign(navigationEntry.toJSON(), forcedAttributes)
27
+ } else {
28
+ var relativePerformanceTiming = computeRelativePerformanceTiming()
29
+ timing = assign(
30
+ relativePerformanceTiming,
31
+ {
32
+ decodedBodySize: 0,
33
+ encodedBodySize: 0,
34
+ transferSize: 0,
35
+ renderBlockingStatus: 'non-blocking',
36
+ duration: relativePerformanceTiming.responseEnd,
37
+ name: window.location.href,
38
+ startTime: 0
39
+ },
40
+ forcedAttributes
41
+ )
42
+ }
43
+ callback(timing)
44
+ })
45
+ }
@@ -35,8 +35,9 @@ export function trackCommonViewMetrics(
35
35
  var stopScrollMetricsTracking = _trackScrollMetrics.stop
36
36
  var stopCLSTracking
37
37
  var _trackCumulativeLayoutShift = trackCumulativeLayoutShift(
38
- lifeCycle,
39
38
  configuration,
39
+ lifeCycle,
40
+ viewStart.relative,
40
41
  function (cumulativeLayoutShift) {
41
42
  commonViewMetrics.cumulativeLayoutShift = cumulativeLayoutShift
42
43
  scheduleViewUpdate()
@@ -4,11 +4,14 @@ import {
4
4
  round,
5
5
  ONE_SECOND,
6
6
  LifeCycleEventType,
7
- isElementNode
7
+ isElementNode,
8
+ elapsed
8
9
  } from '@cloudcare/browser-core'
9
- import { supportPerformanceTimingEvent } from '../../performanceCollection'
10
10
  import { getSelectorFromElement } from '../actions/getSelectorsFromElement'
11
-
11
+ import {
12
+ RumPerformanceEntryType,
13
+ supportPerformanceTimingEvent
14
+ } from '../../performanceObservable'
12
15
  /**
13
16
  * Track the cumulative layout shifts (CLS).
14
17
  * Layout shifts are grouped into session windows.
@@ -26,7 +29,12 @@ import { getSelectorFromElement } from '../actions/getSelectorsFromElement'
26
29
  * https://web.dev/evolving-cls/
27
30
  * Reference implementation: https://github.com/GoogleChrome/web-vitals/blob/master/src/getCLS.ts
28
31
  */
29
- export function trackCumulativeLayoutShift(lifeCycle, configuration, callback) {
32
+ export function trackCumulativeLayoutShift(
33
+ configuration,
34
+ lifeCycle,
35
+ viewStart,
36
+ callback
37
+ ) {
30
38
  if (!isLayoutShiftSupported()) {
31
39
  return {
32
40
  stop: noop
@@ -36,6 +44,7 @@ export function trackCumulativeLayoutShift(lifeCycle, configuration, callback) {
36
44
  var maxClsValue = 0
37
45
  // WeakRef is not supported in IE11 and Safari mobile, but so is the layout shift API, so this code won't be executed in these browsers
38
46
  var maxClsTarget
47
+ var maxClsStartTime
39
48
 
40
49
  // if no layout shift happen the value should be reported as 0
41
50
  callback({
@@ -47,13 +56,17 @@ export function trackCumulativeLayoutShift(lifeCycle, configuration, callback) {
47
56
  LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED,
48
57
  (entries) => {
49
58
  for (var entry of entries) {
50
- if (entry.entryType === 'layout-shift' && !entry.hadRecentInput) {
59
+ if (
60
+ entry.entryType === RumPerformanceEntryType.LAYOUT_SHIFT &&
61
+ !entry.hadRecentInput
62
+ ) {
51
63
  var _update = window.update(entry)
52
64
  var cumulatedValue = _update.cumulatedValue
53
65
  var isMaxValue = _update.isMaxValue
54
66
  if (isMaxValue) {
55
67
  var target = getTargetFromSource(entry.sources)
56
68
  maxClsTarget = target ? new WeakRef(target) : undefined
69
+ maxClsStartTime = elapsed(viewStart, entry.startTime)
57
70
  }
58
71
 
59
72
  if (cumulatedValue > maxClsValue) {
@@ -67,7 +80,8 @@ export function trackCumulativeLayoutShift(lifeCycle, configuration, callback) {
67
80
  getSelectorFromElement(
68
81
  target,
69
82
  configuration.actionNameAttribute
70
- )
83
+ ),
84
+ time: maxClsStartTime
71
85
  })
72
86
  }
73
87
  }
@@ -128,5 +142,8 @@ function slidingSessionWindow() {
128
142
  * Check whether `layout-shift` is supported by the browser.
129
143
  */
130
144
  export function isLayoutShiftSupported() {
131
- return supportPerformanceTimingEvent('layout-shift')
145
+ return (
146
+ supportPerformanceTimingEvent(RumPerformanceEntryType.LAYOUT_SHIFT) &&
147
+ 'WeakRef' in window
148
+ )
132
149
  }
@@ -1,4 +1,5 @@
1
1
  import { find, LifeCycleEventType, ONE_MINUTE } from '@cloudcare/browser-core'
2
+ import { RumPerformanceEntryType } from '../../performanceObservable'
2
3
  export var TIMING_MAXIMUM_DELAY = 10 * ONE_MINUTE
3
4
  export function trackFirstContentfulPaint(lifeCycle, firstHidden, callback) {
4
5
  var subscribe = lifeCycle.subscribe(
@@ -6,7 +7,7 @@ export function trackFirstContentfulPaint(lifeCycle, firstHidden, callback) {
6
7
  function (entries) {
7
8
  var fcpEntry = find(entries, function (entry) {
8
9
  return (
9
- entry.entryType === 'paint' &&
10
+ entry.entryType === RumPerformanceEntryType.PAINT &&
10
11
  entry.name === 'first-contentful-paint' &&
11
12
  entry.startTime < firstHidden.geTimeStamp() &&
12
13
  entry.startTime < TIMING_MAXIMUM_DELAY
@@ -5,7 +5,7 @@ import {
5
5
  isElementNode
6
6
  } from '@cloudcare/browser-core'
7
7
  import { getSelectorFromElement } from '../actions/getSelectorsFromElement'
8
-
8
+ import { RumPerformanceEntryType } from '../../performanceObservable'
9
9
  /**
10
10
  * Track the first input occurring during the initial View to return:
11
11
  * - First Input Delay
@@ -25,7 +25,7 @@ export function trackFirstInput(
25
25
  function (entries) {
26
26
  var firstInputEntry = find(entries, function (entry) {
27
27
  return (
28
- entry.entryType === 'first-input' &&
28
+ entry.entryType === RumPerformanceEntryType.FIRST_INPUT &&
29
29
  entry.startTime < firstHidden.geTimeStamp()
30
30
  )
31
31
  })
@@ -14,7 +14,7 @@ export function trackInitialViewMetrics(
14
14
  ) {
15
15
  var initialViewMetrics = {}
16
16
  var _trackNavigationTimings = trackNavigationTimings(
17
- lifeCycle,
17
+ configuration,
18
18
  function (navigationTimings) {
19
19
  setLoadEvent(navigationTimings.loadEvent)
20
20
  initialViewMetrics.navigationTimings = navigationTimings
@@ -7,13 +7,15 @@ import {
7
7
  elapsed,
8
8
  isElementNode
9
9
  } from '@cloudcare/browser-core'
10
- import { supportPerformanceTimingEvent } from '../../performanceCollection'
11
10
  import { getSelectorFromElement } from '../actions/getSelectorsFromElement'
12
11
  import {
13
12
  getInteractionCount,
14
13
  initInteractionCountPolyfill
15
14
  } from './interactionCountPolyfill'
16
-
15
+ import {
16
+ RumPerformanceEntryType,
17
+ supportPerformanceTimingEvent
18
+ } from '../../performanceObservable'
17
19
  // Arbitrary value to prevent unnecessary memory usage on views with lots of interactions.
18
20
  var MAX_INTERACTION_ENTRIES = 10
19
21
 
@@ -57,7 +59,8 @@ export function trackInteractionToNextPaint(
57
59
  function (entries) {
58
60
  for (var entry of entries) {
59
61
  if (
60
- (entry.entryType === 'event' || entry.entryType === 'first-input') &&
62
+ (entry.entryType === RumPerformanceEntryType.EVENT ||
63
+ entry.entryType === RumPerformanceEntryType.FIRST_INPUT) &&
61
64
  entry.interactionId &&
62
65
  entry.startTime >= viewStart &&
63
66
  entry.startTime <= viewEnd
@@ -72,22 +75,7 @@ export function trackInteractionToNextPaint(
72
75
  newInteraction.duration !== interactionToNextPaint
73
76
  ) {
74
77
  interactionToNextPaint = newInteraction.duration
75
- // if (interactionToNextPaint > 10 * ONE_MINUTE && !telemetryCollected) {
76
- // telemetryCollected = true
77
- // addTelemetryDebug('INP outlier', {
78
- // inp: interactionToNextPaint,
79
- // interaction: {
80
- // timeFromViewStart: elapsed(viewStart, newInteraction.startTime),
81
- // duration: newInteraction.duration,
82
- // startTime: newInteraction.startTime,
83
- // processingStart: newInteraction.processingStart,
84
- // processingEnd: newInteraction.processingEnd,
85
- // interactionId: newInteraction.interactionId,
86
- // name: newInteraction.name,
87
- // targetNodeName: newInteraction.target?.nodeName
88
- // }
89
- // })
90
- // }
78
+
91
79
  if (newInteraction.target && isElementNode(newInteraction.target)) {
92
80
  interactionToNextPaintTargetSelector = getSelectorFromElement(
93
81
  newInteraction.target,