@cloudcare/browser-rum 3.1.14 → 3.1.16

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 (72) hide show
  1. package/LICENSE +2 -2
  2. package/bundle/dataflux-rum.js +1 -1
  3. package/cjs/boot/buildEnv.js +1 -1
  4. package/cjs/domain/configuration.js +1 -0
  5. package/cjs/domain/configuration.js.map +1 -1
  6. package/cjs/domain/contexts/pageStateHistory.js +14 -9
  7. package/cjs/domain/contexts/pageStateHistory.js.map +1 -1
  8. package/cjs/domain/contexts/urlContexts.js +6 -3
  9. package/cjs/domain/contexts/urlContexts.js.map +1 -1
  10. package/cjs/domain/replay/deflate/deflateWorker.js +1 -1
  11. package/cjs/domain/replay/record/mutationBatch.js +11 -2
  12. package/cjs/domain/replay/record/mutationBatch.js.map +1 -1
  13. package/cjs/domain/rumEventsCollection/actions/actionCollection.js +3 -2
  14. package/cjs/domain/rumEventsCollection/actions/actionCollection.js.map +1 -1
  15. package/cjs/domain/rumEventsCollection/actions/getSelectorsFromElement.js +17 -0
  16. package/cjs/domain/rumEventsCollection/actions/getSelectorsFromElement.js.map +1 -1
  17. package/cjs/domain/rumEventsCollection/error/errorCollection.js +2 -1
  18. package/cjs/domain/rumEventsCollection/error/errorCollection.js.map +1 -1
  19. package/cjs/domain/rumEventsCollection/resource/matchRequestTiming.js +8 -4
  20. package/cjs/domain/rumEventsCollection/resource/matchRequestTiming.js.map +1 -1
  21. package/cjs/domain/rumEventsCollection/resource/resourceUtils.js +43 -41
  22. package/cjs/domain/rumEventsCollection/resource/resourceUtils.js.map +1 -1
  23. package/cjs/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +58 -48
  24. package/cjs/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
  25. package/cjs/domain/rumEventsCollection/view/trackInteractionToNextPaint.js +18 -19
  26. package/cjs/domain/rumEventsCollection/view/trackInteractionToNextPaint.js.map +1 -1
  27. package/cjs/domain/rumEventsCollection/view/viewCollection.js +1 -4
  28. package/cjs/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
  29. package/cjs/domain/tracing/tracer.js +12 -1
  30. package/cjs/domain/tracing/tracer.js.map +1 -1
  31. package/esm/boot/buildEnv.js +1 -1
  32. package/esm/domain/configuration.js +2 -1
  33. package/esm/domain/configuration.js.map +1 -1
  34. package/esm/domain/contexts/pageStateHistory.js +14 -9
  35. package/esm/domain/contexts/pageStateHistory.js.map +1 -1
  36. package/esm/domain/contexts/urlContexts.js +6 -3
  37. package/esm/domain/contexts/urlContexts.js.map +1 -1
  38. package/esm/domain/replay/deflate/deflateWorker.js +1 -1
  39. package/esm/domain/replay/record/mutationBatch.js +10 -3
  40. package/esm/domain/replay/record/mutationBatch.js.map +1 -1
  41. package/esm/domain/rumEventsCollection/actions/actionCollection.js +4 -3
  42. package/esm/domain/rumEventsCollection/actions/actionCollection.js.map +1 -1
  43. package/esm/domain/rumEventsCollection/actions/getSelectorsFromElement.js +17 -0
  44. package/esm/domain/rumEventsCollection/actions/getSelectorsFromElement.js.map +1 -1
  45. package/esm/domain/rumEventsCollection/error/errorCollection.js +2 -1
  46. package/esm/domain/rumEventsCollection/error/errorCollection.js.map +1 -1
  47. package/esm/domain/rumEventsCollection/resource/matchRequestTiming.js +10 -7
  48. package/esm/domain/rumEventsCollection/resource/matchRequestTiming.js.map +1 -1
  49. package/esm/domain/rumEventsCollection/resource/resourceUtils.js +42 -40
  50. package/esm/domain/rumEventsCollection/resource/resourceUtils.js.map +1 -1
  51. package/esm/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +56 -48
  52. package/esm/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
  53. package/esm/domain/rumEventsCollection/view/trackInteractionToNextPaint.js +18 -19
  54. package/esm/domain/rumEventsCollection/view/trackInteractionToNextPaint.js.map +1 -1
  55. package/esm/domain/rumEventsCollection/view/viewCollection.js +1 -4
  56. package/esm/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
  57. package/esm/domain/tracing/tracer.js +12 -1
  58. package/esm/domain/tracing/tracer.js.map +1 -1
  59. package/package.json +4 -4
  60. package/src/domain/configuration.js +7 -1
  61. package/src/domain/contexts/pageStateHistory.js +22 -12
  62. package/src/domain/contexts/urlContexts.js +13 -7
  63. package/src/domain/replay/record/mutationBatch.js +10 -5
  64. package/src/domain/rumEventsCollection/actions/actionCollection.js +8 -3
  65. package/src/domain/rumEventsCollection/actions/getSelectorsFromElement.js +18 -0
  66. package/src/domain/rumEventsCollection/error/errorCollection.js +3 -1
  67. package/src/domain/rumEventsCollection/resource/matchRequestTiming.js +10 -6
  68. package/src/domain/rumEventsCollection/resource/resourceUtils.js +60 -58
  69. package/src/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +55 -56
  70. package/src/domain/rumEventsCollection/view/trackInteractionToNextPaint.js +18 -18
  71. package/src/domain/rumEventsCollection/view/viewCollection.js +2 -5
  72. package/src/domain/tracing/tracer.js +12 -1
@@ -32,95 +32,94 @@ export function trackCumulativeLayoutShift(lifeCycle, configuration, callback) {
32
32
  stop: noop
33
33
  }
34
34
  }
35
+
35
36
  var maxClsValue = 0
37
+ // 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
+ var maxClsTarget
39
+
40
+ // if no layout shift happen the value should be reported as 0
36
41
  callback({
37
42
  value: 0
38
43
  })
44
+
39
45
  var window = slidingSessionWindow()
40
46
  var _subscribe = lifeCycle.subscribe(
41
47
  LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED,
42
- function (entries) {
43
- for (var i = 0; i < entries.length; i++) {
44
- var entry = entries[i]
48
+ (entries) => {
49
+ for (var entry of entries) {
45
50
  if (entry.entryType === 'layout-shift' && !entry.hadRecentInput) {
46
- window.update(entry)
47
- if (window.value() > maxClsValue) {
48
- maxClsValue = window.value()
49
- var cls = round(maxClsValue, 4)
50
- var clsTarget = window.largestLayoutShiftTarget()
51
- var cslTargetSelector
52
- if (
53
- clsTarget &&
54
- // 检测目标是否在dom 中被删除
55
- clsTarget.isConnected
56
- ) {
57
- cslTargetSelector = getSelectorFromElement(
58
- clsTarget,
59
- configuration.actionNameAttribute
60
- )
61
- }
51
+ var _update = window.update(entry)
52
+ var cumulatedValue = _update.cumulatedValue
53
+ var isMaxValue = _update.isMaxValue
54
+ if (isMaxValue) {
55
+ var target = getTargetFromSource(entry.sources)
56
+ maxClsTarget = target ? new WeakRef(target) : undefined
57
+ }
58
+
59
+ if (cumulatedValue > maxClsValue) {
60
+ maxClsValue = cumulatedValue
61
+ var target = maxClsTarget && maxClsTarget.deref()
62
+
62
63
  callback({
63
- value: cls,
64
- targetSelector: cslTargetSelector
64
+ value: round(maxClsValue, 4),
65
+ targetSelector:
66
+ target &&
67
+ getSelectorFromElement(
68
+ target,
69
+ configuration.actionNameAttribute
70
+ )
65
71
  })
66
72
  }
67
73
  }
68
74
  }
69
75
  }
70
76
  )
77
+
71
78
  var stop = _subscribe.unsubscribe
72
79
  return {
73
80
  stop: stop
74
81
  }
75
82
  }
76
-
83
+ function getTargetFromSource(sources) {
84
+ if (!sources) {
85
+ return
86
+ }
87
+ var source = find(sources, function (source) {
88
+ return !!source.node && isElementNode(source.node)
89
+ })
90
+ return source && source.node
91
+ }
92
+ export var MAX_WINDOW_DURATION = 5 * ONE_SECOND
93
+ var MAX_UPDATE_GAP = ONE_SECOND
77
94
  function slidingSessionWindow() {
78
- var value = 0
95
+ var cumulatedValue = 0
79
96
  var startTime
80
97
  var endTime
81
- var largestLayoutShift = 0
82
- var largestLayoutShiftTarget
83
- var largestLayoutShiftTime
98
+ var maxValue = 0
84
99
  return {
85
100
  update: function (entry) {
86
101
  var shouldCreateNewWindow =
87
102
  startTime === undefined ||
88
- entry.startTime - endTime >= ONE_SECOND ||
89
- entry.startTime - startTime >= 5 * ONE_SECOND
103
+ entry.startTime - endTime >= MAX_UPDATE_GAP ||
104
+ entry.startTime - startTime >= 5 * MAX_WINDOW_DURATION
105
+ var isMaxValue
106
+
90
107
  if (shouldCreateNewWindow) {
91
108
  startTime = endTime = entry.startTime
92
- value = entry.value
93
- largestLayoutShift = 0
94
- largestLayoutShiftTarget = undefined
109
+ maxValue = cumulatedValue = entry.value
110
+ isMaxValue = true
95
111
  } else {
96
- value += entry.value
112
+ cumulatedValue += entry.value
97
113
  endTime = entry.startTime
98
- }
99
-
100
- if (entry.value > largestLayoutShift) {
101
- largestLayoutShift = entry.value
102
- largestLayoutShiftTime = entry.startTime
103
-
104
- if (entry.sources && entry.sources.length) {
105
- var findTarget = find(entry.sources, function (s) {
106
- return !!s.node && isElementNode(s.node)
107
- })
108
- if (findTarget) {
109
- largestLayoutShiftTarget = findTarget.node
110
- }
111
- } else {
112
- largestLayoutShiftTarget = undefined
114
+ isMaxValue = entry.value > maxValue
115
+ if (isMaxValue) {
116
+ maxValue = entry.value
113
117
  }
114
118
  }
115
- },
116
- value: function () {
117
- return value
118
- },
119
- largestLayoutShiftTarget: function () {
120
- return largestLayoutShiftTarget
121
- },
122
- largestLayoutShiftTime: function () {
123
- return largestLayoutShiftTime
119
+ return {
120
+ cumulatedValue: cumulatedValue,
121
+ isMaxValue: isMaxValue
122
+ }
124
123
  }
125
124
  }
126
125
  }
@@ -66,28 +66,28 @@ export function trackInteractionToNextPaint(
66
66
  }
67
67
  }
68
68
 
69
- var newInteraction = longestInteractions.estimateP98Duration()
69
+ var newInteraction = longestInteractions.estimateP98Interaction()
70
70
  if (
71
71
  newInteraction &&
72
72
  newInteraction.duration !== interactionToNextPaint
73
73
  ) {
74
74
  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
- }
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
+ // }
91
91
  if (newInteraction.target && isElementNode(newInteraction.target)) {
92
92
  interactionToNextPaintTargetSelector = getSelectorFromElement(
93
93
  newInteraction.target,
@@ -167,7 +167,7 @@ function trackLongestInteractions(getViewInteractionCount) {
167
167
  * Compute the p98 longest interaction.
168
168
  * For better performance the computation is based on 10 longest interactions and the interaction count of the current view.
169
169
  */
170
- estimateP98Duration: function () {
170
+ estimateP98Interaction: function () {
171
171
  var interactionIndex = Math.min(
172
172
  longestInteractions.length - 1,
173
173
  Math.floor(getViewInteractionCount() / 50)
@@ -6,7 +6,8 @@ import {
6
6
  RumEventType,
7
7
  LifeCycleEventType,
8
8
  extend2Lev,
9
- findByPath
9
+ findByPath,
10
+ discardNegativeDuration
10
11
  } from '@cloudcare/browser-core'
11
12
  import { trackViews } from './trackViews'
12
13
  export function startViewCollection(
@@ -230,7 +231,3 @@ function processViewUpdate(view, configuration, recorderApi, pageStateHistory) {
230
231
  }
231
232
  }
232
233
  }
233
-
234
- function discardNegativeDuration(duration) {
235
- return isNumber(duration) && duration < 0 ? undefined : duration
236
- }
@@ -152,5 +152,16 @@ export function injectHeadersIfTracingAllowed(
152
152
  context.traceId = tracer.getTraceId()
153
153
  context.spanId = tracer.getSpanId()
154
154
  context.traceSampled = traceSampled
155
- inject(tracer.makeTracingHeaders())
155
+ var headers = tracer.makeTracingHeaders()
156
+ if (configuration.injectTraceHeader) {
157
+ var result = configuration.injectTraceHeader(shallowClone(context))
158
+ if (getType(result) === 'object') {
159
+ each(result, function (value, key) {
160
+ if (getType(value) === 'string') {
161
+ headers[key] = value
162
+ }
163
+ })
164
+ }
165
+ }
166
+ inject(headers)
156
167
  }