@cloudcare/browser-rum 3.3.15 → 3.3.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 (71) hide show
  1. package/README.md +12 -0
  2. package/README.zh.md +13 -0
  3. package/bundle/dataflux-rum.js +1 -1
  4. package/cjs/boot/buildEnv.js +1 -1
  5. package/cjs/boot/startRecording.js +4 -4
  6. package/cjs/boot/startRecording.js.map +1 -1
  7. package/cjs/constants.js +8 -8
  8. package/cjs/constants.js.map +1 -1
  9. package/cjs/domain/assembly.js +7 -0
  10. package/cjs/domain/assembly.js.map +1 -1
  11. package/cjs/domain/deflate/deflateWorker.js +1 -1
  12. package/cjs/domain/encoderStreamId.js +2 -1
  13. package/cjs/domain/encoderStreamId.js.map +1 -1
  14. package/cjs/domain/replay/record/canvasEncodeWorker.js +1 -1
  15. package/cjs/domain/replay/record/record.js +2 -3
  16. package/cjs/domain/replay/record/record.js.map +1 -1
  17. package/cjs/domain/replay/record/serializationUtils.js +8 -15
  18. package/cjs/domain/replay/record/serializationUtils.js.map +1 -1
  19. package/cjs/domain/replay/record/serialize.js +14 -6
  20. package/cjs/domain/replay/record/serialize.js.map +1 -1
  21. package/cjs/domain/rumEventsCollection/error/errorCollection.js +6 -8
  22. package/cjs/domain/rumEventsCollection/error/errorCollection.js.map +1 -1
  23. package/cjs/domain/rumSessionManager.js +3 -3
  24. package/cjs/domain/rumSessionManager.js.map +1 -1
  25. package/cjs/domain/visitorId/index.js +38 -0
  26. package/cjs/domain/visitorId/index.js.map +1 -1
  27. package/cjs/index.js +7 -0
  28. package/cjs/index.js.map +1 -1
  29. package/cjs/transport/startRumBatch.js +44 -3
  30. package/cjs/transport/startRumBatch.js.map +1 -1
  31. package/esm/boot/buildEnv.js +1 -1
  32. package/esm/boot/startRecording.js +4 -4
  33. package/esm/boot/startRecording.js.map +1 -1
  34. package/esm/constants.js +1 -8
  35. package/esm/constants.js.map +1 -1
  36. package/esm/domain/assembly.js +8 -1
  37. package/esm/domain/assembly.js.map +1 -1
  38. package/esm/domain/deflate/deflateWorker.js +1 -1
  39. package/esm/domain/encoderStreamId.js +2 -1
  40. package/esm/domain/encoderStreamId.js.map +1 -1
  41. package/esm/domain/replay/record/canvasEncodeWorker.js +1 -1
  42. package/esm/domain/replay/record/record.js +1 -2
  43. package/esm/domain/replay/record/record.js.map +1 -1
  44. package/esm/domain/replay/record/serializationUtils.js +8 -15
  45. package/esm/domain/replay/record/serializationUtils.js.map +1 -1
  46. package/esm/domain/replay/record/serialize.js +13 -5
  47. package/esm/domain/replay/record/serialize.js.map +1 -1
  48. package/esm/domain/rumEventsCollection/error/errorCollection.js +6 -8
  49. package/esm/domain/rumEventsCollection/error/errorCollection.js.map +1 -1
  50. package/esm/domain/rumSessionManager.js +3 -3
  51. package/esm/domain/rumSessionManager.js.map +1 -1
  52. package/esm/domain/visitorId/index.js +39 -1
  53. package/esm/domain/visitorId/index.js.map +1 -1
  54. package/esm/index.js +1 -0
  55. package/esm/index.js.map +1 -1
  56. package/esm/transport/startRumBatch.js +45 -4
  57. package/esm/transport/startRumBatch.js.map +1 -1
  58. package/package.json +4 -4
  59. package/src/boot/startRecording.js +7 -3
  60. package/src/constants.js +1 -8
  61. package/src/domain/assembly.js +15 -1
  62. package/src/domain/encoderStreamId.js +2 -2
  63. package/src/domain/replay/record/record.js +1 -2
  64. package/src/domain/replay/record/serializationUtils.js +10 -24
  65. package/src/domain/replay/record/serialize.js +25 -5
  66. package/src/domain/rumEventsCollection/error/errorCollection.js +10 -8
  67. package/src/domain/rumSessionManager.js +8 -7
  68. package/src/domain/visitorId/index.js +49 -0
  69. package/src/index.js +1 -0
  70. package/src/transport/startRumBatch.js +61 -3
  71. package/types/index.d.ts +22 -2
@@ -1,6 +1,8 @@
1
1
  import {
2
2
  createIdentityEncoder,
3
+ createHttpRequest,
3
4
  LifeCycleEventType,
5
+ Observable,
4
6
  RumEventType,
5
7
  startBatchWithReplica
6
8
  } from '@cloudcare/browser-core'
@@ -15,10 +17,21 @@ export function startRumBatch(
15
17
  createEncoder
16
18
  ) {
17
19
  const rumEncoder = createEncoder(EncoderStreamId.RUM)
20
+ // Both batches share the same retry queue and bandwidth limits.
21
+ const request = createHttpRequest(
22
+ configuration.rumEndpoint,
23
+ configuration.batchBytesLimit,
24
+ configuration.retryMaxSize,
25
+ reportError
26
+ )
27
+ const flushRequestObservable = new Observable()
28
+ let initialViewBatch
29
+ let initialViewEncoder
18
30
  const batch = startBatchWithReplica(
19
31
  configuration,
20
32
  {
21
33
  endpoint: configuration.rumEndpoint,
34
+ request,
22
35
  encoder: rumEncoder,
23
36
  encoderFallback: rumEncoder.isAsync
24
37
  ? createIdentityEncoder
@@ -28,7 +41,7 @@ export function startRumBatch(
28
41
  pageExitObservable,
29
42
  sessionExpireObservable
30
43
  )
31
- lifeCycle.subscribe(
44
+ const rumEventSubscription = lifeCycle.subscribe(
32
45
  LifeCycleEventType.RUM_EVENT_COLLECTED,
33
46
  function (serverRumEvent) {
34
47
  if (serverRumEvent.type === RumEventType.VIEW) {
@@ -38,8 +51,53 @@ export function startRumBatch(
38
51
  }
39
52
  }
40
53
  )
41
- telemetryEventObservable.subscribe(function (event) {
54
+ const initialViewSubscription = lifeCycle.subscribe(
55
+ LifeCycleEventType.RUM_VIEW_FIRST_COLLECTED,
56
+ function (event) {
57
+ if (!initialViewBatch) {
58
+ initialViewEncoder = createEncoder(EncoderStreamId.RUM_INITIAL_VIEW)
59
+ initialViewBatch = startBatchWithReplica(
60
+ configuration,
61
+ {
62
+ request,
63
+ encoder: initialViewEncoder,
64
+ encoderFallback: initialViewEncoder.isAsync
65
+ ? createIdentityEncoder
66
+ : undefined,
67
+ flushRequestObservable
68
+ },
69
+ reportError,
70
+ // The regular batch already owns the exit copy. Do not promote an
71
+ // older first version from this encoder's journal on the same exit.
72
+ new Observable(),
73
+ sessionExpireObservable
74
+ )
75
+ }
76
+ // Send the first eligible version separately. The normal batch retains
77
+ // each View's latest version for its original deadline and exit beacon,
78
+ // including rapid routes whose first fetches have not completed yet.
79
+ initialViewBatch.upsert(event, event.view.id)
80
+ flushRequestObservable.notify('view_created')
81
+ }
82
+ )
83
+ const telemetrySubscription = telemetryEventObservable.subscribe(function (event) {
42
84
  batch.add(event)
43
85
  })
44
- return batch
86
+ return {
87
+ flushObservable: batch.flushObservable,
88
+ add: batch.add,
89
+ upsert: batch.upsert,
90
+ stop: function () {
91
+ rumEventSubscription.unsubscribe()
92
+ initialViewSubscription.unsubscribe()
93
+ telemetrySubscription.unsubscribe()
94
+ batch.stop()
95
+ if (initialViewBatch) {
96
+ initialViewBatch.stop()
97
+ if (initialViewEncoder.stop) {
98
+ initialViewEncoder.stop()
99
+ }
100
+ }
101
+ }
102
+ }
45
103
  }
package/types/index.d.ts CHANGED
@@ -1,9 +1,22 @@
1
1
  import type {
2
2
  RumInitConfiguration,
3
+ RumLegacyInitConfiguration,
3
4
  RumSiteInitConfiguration,
4
5
  Context,
5
6
  User
6
7
  } from '@cloudcare/browser-core'
8
+ export { TraceType } from '@cloudcare/browser-core'
9
+ export type {
10
+ Context,
11
+ User,
12
+ RumInitConfiguration,
13
+ RumLegacyInitConfiguration,
14
+ RumSiteInitConfiguration,
15
+ MatchOption,
16
+ OriginMatchOption,
17
+ TraceTypeValue,
18
+ TracingOption
19
+ } from '@cloudcare/browser-core'
7
20
  export interface InternalContext {
8
21
  application: {
9
22
  id: string
@@ -39,7 +52,8 @@ export interface StartSessionOptions {
39
52
  export interface StartSessionReplayRecordingOptions {
40
53
  /**
41
54
  * Forces the current session to be tracked, assigns a session ID when
42
- * necessary, and enables Session Replay recording.
55
+ * necessary, and enables Session Replay recording without waiting for an error.
56
+ * An existing error-only replay buffer is also released.
43
57
  */
44
58
  force?: boolean
45
59
  }
@@ -227,6 +241,7 @@ export interface RumPlugin {
227
241
 
228
242
  export type RumPluginInitConfiguration = (
229
243
  | RumInitConfiguration
244
+ | RumLegacyInitConfiguration
230
245
  | RumSiteInitConfiguration
231
246
  ) & {
232
247
  plugins?: RumPlugin[] | undefined
@@ -246,7 +261,7 @@ export declare const datafluxRum: {
246
261
  getGlobalContext: () => Context
247
262
  setGlobalContext: (context: any) => void
248
263
  clearGlobalContext: () => void
249
- /** Rotates the SDK-managed Visitor ID immediately. */
264
+ /** Rotates the Web-generated Visitor ID immediately. No-op while an allowed native bridge provides a valid Visitor ID; the App owns its rotation. */
250
265
  resetVisitorId: () => void
251
266
  getInternalContext: (
252
267
  startTime?: number | undefined
@@ -273,6 +288,11 @@ export declare const datafluxRum: {
273
288
  clearUser: () => void
274
289
  stopSession: () => void
275
290
  startSession: (options?: StartSessionOptions) => void
291
+ /**
292
+ * Forces the current session to be tracked without waiting for an error.
293
+ * Assigns an ID if needed and releases any existing error-only replay buffer.
294
+ * To start recording, call startSessionReplayRecording({ force: true }).
295
+ */
276
296
  setForcedSession: () => void
277
297
  startSessionReplayRecording: (
278
298
  options?: StartSessionReplayRecordingOptions