@cloudcare/browser-rum 3.1.13 → 3.1.15

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 (67) hide show
  1. package/bundle/dataflux-rum.js +1 -1
  2. package/cjs/boot/buildEnv.js +1 -1
  3. package/cjs/domain/configuration.js +1 -0
  4. package/cjs/domain/configuration.js.map +1 -1
  5. package/cjs/domain/contexts/pageStateHistory.js +14 -9
  6. package/cjs/domain/contexts/pageStateHistory.js.map +1 -1
  7. package/cjs/domain/contexts/urlContexts.js +6 -3
  8. package/cjs/domain/contexts/urlContexts.js.map +1 -1
  9. package/cjs/domain/replay/deflate/deflateWorker.js +1 -1
  10. package/cjs/domain/rumEventsCollection/actions/actionCollection.js +3 -2
  11. package/cjs/domain/rumEventsCollection/actions/actionCollection.js.map +1 -1
  12. package/cjs/domain/rumEventsCollection/actions/getSelectorsFromElement.js +17 -0
  13. package/cjs/domain/rumEventsCollection/actions/getSelectorsFromElement.js.map +1 -1
  14. package/cjs/domain/rumEventsCollection/error/errorCollection.js +2 -1
  15. package/cjs/domain/rumEventsCollection/error/errorCollection.js.map +1 -1
  16. package/cjs/domain/rumEventsCollection/resource/matchRequestTiming.js +8 -4
  17. package/cjs/domain/rumEventsCollection/resource/matchRequestTiming.js.map +1 -1
  18. package/cjs/domain/rumEventsCollection/resource/resourceUtils.js +42 -40
  19. package/cjs/domain/rumEventsCollection/resource/resourceUtils.js.map +1 -1
  20. package/cjs/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +40 -17
  21. package/cjs/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
  22. package/cjs/domain/rumEventsCollection/view/trackInteractionToNextPaint.js +18 -19
  23. package/cjs/domain/rumEventsCollection/view/trackInteractionToNextPaint.js.map +1 -1
  24. package/cjs/domain/rumEventsCollection/view/viewCollection.js +1 -4
  25. package/cjs/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
  26. package/cjs/domain/tracing/tracer.js +16 -1
  27. package/cjs/domain/tracing/tracer.js.map +1 -1
  28. package/esm/boot/buildEnv.js +1 -1
  29. package/esm/domain/configuration.js +2 -1
  30. package/esm/domain/configuration.js.map +1 -1
  31. package/esm/domain/contexts/pageStateHistory.js +14 -9
  32. package/esm/domain/contexts/pageStateHistory.js.map +1 -1
  33. package/esm/domain/contexts/urlContexts.js +6 -3
  34. package/esm/domain/contexts/urlContexts.js.map +1 -1
  35. package/esm/domain/replay/deflate/deflateWorker.js +1 -1
  36. package/esm/domain/rumEventsCollection/actions/actionCollection.js +4 -3
  37. package/esm/domain/rumEventsCollection/actions/actionCollection.js.map +1 -1
  38. package/esm/domain/rumEventsCollection/actions/getSelectorsFromElement.js +17 -0
  39. package/esm/domain/rumEventsCollection/actions/getSelectorsFromElement.js.map +1 -1
  40. package/esm/domain/rumEventsCollection/error/errorCollection.js +2 -1
  41. package/esm/domain/rumEventsCollection/error/errorCollection.js.map +1 -1
  42. package/esm/domain/rumEventsCollection/resource/matchRequestTiming.js +10 -7
  43. package/esm/domain/rumEventsCollection/resource/matchRequestTiming.js.map +1 -1
  44. package/esm/domain/rumEventsCollection/resource/resourceUtils.js +41 -39
  45. package/esm/domain/rumEventsCollection/resource/resourceUtils.js.map +1 -1
  46. package/esm/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +40 -17
  47. package/esm/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
  48. package/esm/domain/rumEventsCollection/view/trackInteractionToNextPaint.js +18 -19
  49. package/esm/domain/rumEventsCollection/view/trackInteractionToNextPaint.js.map +1 -1
  50. package/esm/domain/rumEventsCollection/view/viewCollection.js +1 -4
  51. package/esm/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
  52. package/esm/domain/tracing/tracer.js +16 -1
  53. package/esm/domain/tracing/tracer.js.map +1 -1
  54. package/package.json +4 -4
  55. package/src/domain/configuration.js +7 -1
  56. package/src/domain/contexts/pageStateHistory.js +22 -12
  57. package/src/domain/contexts/urlContexts.js +13 -7
  58. package/src/domain/rumEventsCollection/actions/actionCollection.js +8 -3
  59. package/src/domain/rumEventsCollection/actions/getSelectorsFromElement.js +18 -0
  60. package/src/domain/rumEventsCollection/error/errorCollection.js +3 -1
  61. package/src/domain/rumEventsCollection/resource/matchRequestTiming.js +10 -6
  62. package/src/domain/rumEventsCollection/resource/resourceUtils.js +59 -57
  63. package/src/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +37 -22
  64. package/src/domain/rumEventsCollection/view/trackInteractionToNextPaint.js +18 -18
  65. package/src/domain/rumEventsCollection/view/viewCollection.js +2 -5
  66. package/src/domain/tracing/tracer.js +17 -1
  67. package/types/index.d.ts +8 -3
@@ -221,24 +221,22 @@ export function isCacheHit(entry) {
221
221
 
222
222
  // · loadEventEnd:返回当前网页load事件的回调函数运行结束时的Unix毫秒时间戳。如果该事件还没有发生,返回0
223
223
  export function computePerformanceResourceDetails(entry) {
224
- var validEntry = toValidEntry(entry)
225
-
226
- if (!validEntry) {
224
+ if (!isValidEntry(entry)) {
227
225
  return undefined
228
226
  }
229
227
 
230
- var startTime = validEntry.startTime,
231
- fetchStart = validEntry.fetchStart,
232
- redirectStart = validEntry.redirectStart,
233
- redirectEnd = validEntry.redirectEnd,
234
- domainLookupStart = validEntry.domainLookupStart,
235
- domainLookupEnd = validEntry.domainLookupEnd,
236
- connectStart = validEntry.connectStart,
237
- secureConnectionStart = validEntry.secureConnectionStart,
238
- connectEnd = validEntry.connectEnd,
239
- requestStart = validEntry.requestStart,
240
- responseStart = validEntry.responseStart,
241
- responseEnd = validEntry.responseEnd
228
+ var startTime = entry.startTime,
229
+ fetchStart = entry.fetchStart,
230
+ redirectStart = entry.redirectStart,
231
+ redirectEnd = entry.redirectEnd,
232
+ domainLookupStart = entry.domainLookupStart,
233
+ domainLookupEnd = entry.domainLookupEnd,
234
+ connectStart = entry.connectStart,
235
+ secureConnectionStart = entry.secureConnectionStart,
236
+ connectEnd = entry.connectEnd,
237
+ requestStart = entry.requestStart,
238
+ responseStart = entry.responseStart,
239
+ responseEnd = entry.responseEnd
242
240
  var details = {
243
241
  firstbyte: msToNs(responseStart - domainLookupStart),
244
242
  trans: msToNs(responseEnd - responseStart),
@@ -284,7 +282,7 @@ export function computePerformanceResourceDetails(entry) {
284
282
  return details
285
283
  }
286
284
 
287
- export function toValidEntry(entry) {
285
+ export function isValidEntry(entry) {
288
286
  // Ensure timings are in the right order. On top of filtering out potential invalid
289
287
  // RumPerformanceResourceTiming, it will ignore entries from requests where timings cannot be
290
288
  // collected, for example cross origin requests without a "Timing-Allow-Origin" header allowing
@@ -302,47 +300,51 @@ export function toValidEntry(entry) {
302
300
  // page_trans float 内容传输时间 responseEnd - responseStart
303
301
  // page_dom float DOM解析耗时 domInteractive - responseEnd
304
302
  // page_resource_load_time float 资源加载时间 loadEventStart - domContentLoadedEventEnd
305
- if (
306
- !areInOrder(
307
- entry.startTime,
308
- entry.fetchStart,
309
- entry.domainLookupStart,
310
- entry.domainLookupEnd,
311
- entry.connectStart,
312
- entry.connectEnd,
313
- entry.requestStart,
314
- entry.responseStart,
315
- entry.responseEnd
316
- )
317
- ) {
318
- return undefined
319
- }
320
-
321
- if (!hasRedirection(entry)) {
322
- return entry
323
- }
324
-
325
- var redirectStart = entry.redirectStart
326
- var redirectEnd = entry.redirectEnd
327
- // Firefox doesn't provide redirect timings on cross origin requests.
328
- // Provide a default for those.
329
- if (redirectStart < entry.startTime) {
330
- redirectStart = entry.startTime
331
- }
332
- if (redirectEnd < entry.startTime) {
333
- redirectEnd = entry.fetchStart
334
- }
335
-
336
- // Make sure redirect timings are in order
337
- if (
338
- !areInOrder(entry.startTime, redirectStart, redirectEnd, entry.fetchStart)
339
- ) {
340
- return undefined
341
- }
342
- return extend({}, entry, {
343
- redirectEnd: redirectEnd,
344
- redirectStart: redirectStart
345
- })
303
+ var areCommonTimingsInOrder = areInOrder(
304
+ entry.startTime,
305
+ entry.fetchStart,
306
+ entry.domainLookupStart,
307
+ entry.domainLookupEnd,
308
+ entry.connectStart,
309
+ entry.connectEnd,
310
+ entry.requestStart,
311
+ entry.responseStart,
312
+ entry.responseEnd
313
+ )
314
+ var areRedirectionTimingsInOrder = hasRedirection(entry)
315
+ ? areInOrder(
316
+ entry.startTime,
317
+ entry.redirectStart,
318
+ entry.redirectEnd,
319
+ entry.fetchStart
320
+ )
321
+ : true
322
+ return areCommonTimingsInOrder && areRedirectionTimingsInOrder
323
+ // if (!hasRedirection(entry)) {
324
+ // return entry
325
+ // }
326
+
327
+ // var redirectStart = entry.redirectStart
328
+ // var redirectEnd = entry.redirectEnd
329
+ // // Firefox doesn't provide redirect timings on cross origin requests.
330
+ // // Provide a default for those.
331
+ // if (redirectStart < entry.startTime) {
332
+ // redirectStart = entry.startTime
333
+ // }
334
+ // if (redirectEnd < entry.startTime) {
335
+ // redirectEnd = entry.fetchStart
336
+ // }
337
+
338
+ // // Make sure redirect timings are in order
339
+ // if (
340
+ // !areInOrder(entry.startTime, redirectStart, redirectEnd, entry.fetchStart)
341
+ // ) {
342
+ // return undefined
343
+ // }
344
+ // return extend({}, entry, {
345
+ // redirectEnd: redirectEnd,
346
+ // redirectStart: redirectStart
347
+ // })
346
348
  // return {
347
349
  // ...entry,
348
350
  // redirectEnd,
@@ -32,48 +32,63 @@ 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
+ }
77
92
  function slidingSessionWindow() {
78
93
  var value = 0
79
94
  var startTime
@@ -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,21 @@ 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
+
156
+ var headers = tracer.makeTracingHeaders()
157
+ if (configuration.injectTraceHeader) {
158
+ var result = configuration.injectTraceHeader({
159
+ traceId: context.traceId,
160
+ spanId: context.spanId,
161
+ traceSampled: traceSampled
162
+ })
163
+ if (getType(result) === 'object') {
164
+ each(result, function (value, key) {
165
+ if (getType(value) === 'string') {
166
+ headers[key] = value
167
+ }
168
+ })
169
+ }
170
+ }
171
+ inject(headers)
156
172
  }
package/types/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type {
2
2
  RumInitConfiguration,
3
- InitConfiguration,
3
+ RumSiteInitConfiguration,
4
4
  Context,
5
5
  User
6
6
  } from '@cloudcare/browser-core'
@@ -27,7 +27,9 @@ export interface InternalContext {
27
27
  }
28
28
  }
29
29
  export declare const datafluxRum: {
30
- init: (initConfiguration: RumInitConfiguration) => void
30
+ init: (
31
+ initConfiguration: RumInitConfiguration | RumSiteInitConfiguration
32
+ ) => void
31
33
  setGlobalContextProperty: (key: any, value: any) => void
32
34
  addRumGlobalContext: (key: any, value: any) => void
33
35
  removeGlobalContextProperty: (key: any) => void
@@ -38,7 +40,10 @@ export declare const datafluxRum: {
38
40
  getInternalContext: (
39
41
  startTime?: number | undefined
40
42
  ) => InternalContext | undefined
41
- getInitConfiguration: () => InitConfiguration | undefined
43
+ getInitConfiguration: () =>
44
+ | RumInitConfiguration
45
+ | RumSiteInitConfiguration
46
+ | undefined
42
47
  addAction: (name: string, context?: object | undefined) => void
43
48
  addError: (error: unknown, context?: object | undefined) => void
44
49
  addTiming: (name: string, time?: number | undefined) => void