@cloudcare/browser-rum 3.3.13 → 3.3.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 (96) hide show
  1. package/README.md +48 -0
  2. package/README.zh.md +35 -0
  3. package/bundle/dataflux-rum.js +1 -1
  4. package/cjs/boot/buildEnv.js +1 -1
  5. package/cjs/boot/perStartRum.js +3 -0
  6. package/cjs/boot/perStartRum.js.map +1 -1
  7. package/cjs/boot/recorderApi.js +72 -56
  8. package/cjs/boot/recorderApi.js.map +1 -1
  9. package/cjs/boot/rumPublicApi.js +35 -3
  10. package/cjs/boot/rumPublicApi.js.map +1 -1
  11. package/cjs/boot/startRecording.js +5 -2
  12. package/cjs/boot/startRecording.js.map +1 -1
  13. package/cjs/domain/assembly.js +7 -1
  14. package/cjs/domain/assembly.js.map +1 -1
  15. package/cjs/domain/configuration.js +63 -0
  16. package/cjs/domain/configuration.js.map +1 -1
  17. package/cjs/domain/deflate/deflateWorker.js +1 -1
  18. package/cjs/domain/privacy.js +278 -0
  19. package/cjs/domain/privacy.js.map +1 -0
  20. package/cjs/domain/replay/record/canvasEncodeWorker.js +1 -1
  21. package/cjs/domain/replay/record/privacy.js +11 -272
  22. package/cjs/domain/replay/record/privacy.js.map +1 -1
  23. package/cjs/domain/replay/record/record.js +10 -1
  24. package/cjs/domain/replay/record/record.js.map +1 -1
  25. package/cjs/domain/requestCollection.js +3 -1
  26. package/cjs/domain/requestCollection.js.map +1 -1
  27. package/cjs/domain/rumEventsCollection/actions/getActionNameFromElement.js +81 -19
  28. package/cjs/domain/rumEventsCollection/actions/getActionNameFromElement.js.map +1 -1
  29. package/cjs/domain/rumEventsCollection/actions/trackClickActions.js +11 -4
  30. package/cjs/domain/rumEventsCollection/actions/trackClickActions.js.map +1 -1
  31. package/cjs/domain/rumEventsCollection/resource/resourceCollection.js +5 -0
  32. package/cjs/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
  33. package/cjs/domain/rumEventsCollection/view/trackViews.js +16 -5
  34. package/cjs/domain/rumEventsCollection/view/trackViews.js.map +1 -1
  35. package/cjs/domain/rumSessionManager.js +2 -2
  36. package/cjs/domain/rumSessionManager.js.map +1 -1
  37. package/cjs/domain/tracing/tracer.js +5 -1
  38. package/cjs/domain/tracing/tracer.js.map +1 -1
  39. package/cjs/domain/visitorId/index.js +379 -0
  40. package/cjs/domain/visitorId/index.js.map +1 -0
  41. package/esm/boot/buildEnv.js +1 -1
  42. package/esm/boot/perStartRum.js +3 -0
  43. package/esm/boot/perStartRum.js.map +1 -1
  44. package/esm/boot/recorderApi.js +72 -56
  45. package/esm/boot/recorderApi.js.map +1 -1
  46. package/esm/boot/rumPublicApi.js +36 -4
  47. package/esm/boot/rumPublicApi.js.map +1 -1
  48. package/esm/boot/startRecording.js +5 -2
  49. package/esm/boot/startRecording.js.map +1 -1
  50. package/esm/domain/assembly.js +7 -1
  51. package/esm/domain/assembly.js.map +1 -1
  52. package/esm/domain/configuration.js +63 -1
  53. package/esm/domain/configuration.js.map +1 -1
  54. package/esm/domain/deflate/deflateWorker.js +1 -1
  55. package/esm/domain/privacy.js +266 -0
  56. package/esm/domain/privacy.js.map +1 -0
  57. package/esm/domain/replay/record/canvasEncodeWorker.js +1 -1
  58. package/esm/domain/replay/record/privacy.js +1 -266
  59. package/esm/domain/replay/record/privacy.js.map +1 -1
  60. package/esm/domain/replay/record/record.js +10 -1
  61. package/esm/domain/replay/record/record.js.map +1 -1
  62. package/esm/domain/requestCollection.js +4 -2
  63. package/esm/domain/requestCollection.js.map +1 -1
  64. package/esm/domain/rumEventsCollection/actions/getActionNameFromElement.js +80 -18
  65. package/esm/domain/rumEventsCollection/actions/getActionNameFromElement.js.map +1 -1
  66. package/esm/domain/rumEventsCollection/actions/trackClickActions.js +11 -4
  67. package/esm/domain/rumEventsCollection/actions/trackClickActions.js.map +1 -1
  68. package/esm/domain/rumEventsCollection/resource/resourceCollection.js +5 -0
  69. package/esm/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
  70. package/esm/domain/rumEventsCollection/view/trackViews.js +17 -6
  71. package/esm/domain/rumEventsCollection/view/trackViews.js.map +1 -1
  72. package/esm/domain/rumSessionManager.js +2 -2
  73. package/esm/domain/rumSessionManager.js.map +1 -1
  74. package/esm/domain/tracing/tracer.js +6 -2
  75. package/esm/domain/tracing/tracer.js.map +1 -1
  76. package/esm/domain/visitorId/index.js +368 -0
  77. package/esm/domain/visitorId/index.js.map +1 -0
  78. package/package.json +4 -4
  79. package/src/boot/perStartRum.js +4 -0
  80. package/src/boot/recorderApi.js +73 -59
  81. package/src/boot/rumPublicApi.js +38 -4
  82. package/src/boot/startRecording.js +11 -2
  83. package/src/domain/assembly.js +13 -1
  84. package/src/domain/configuration.js +158 -0
  85. package/src/domain/privacy.js +356 -0
  86. package/src/domain/replay/record/privacy.js +1 -356
  87. package/src/domain/replay/record/record.js +10 -1
  88. package/src/domain/requestCollection.js +4 -1
  89. package/src/domain/rumEventsCollection/actions/getActionNameFromElement.js +148 -21
  90. package/src/domain/rumEventsCollection/actions/trackClickActions.js +19 -5
  91. package/src/domain/rumEventsCollection/resource/resourceCollection.js +3 -0
  92. package/src/domain/rumEventsCollection/view/trackViews.js +33 -6
  93. package/src/domain/rumSessionManager.js +2 -2
  94. package/src/domain/tracing/tracer.js +15 -2
  95. package/src/domain/visitorId/index.js +522 -0
  96. package/types/index.d.ts +2 -0
@@ -101,6 +101,10 @@ export function createPreStartStrategy(
101
101
  return
102
102
  }
103
103
 
104
+ if (rumPublicApiOptions.onConfigurationReady) {
105
+ rumPublicApiOptions.onConfigurationReady(configuration)
106
+ }
107
+
104
108
  if (!eventBridgeAvailable && !configuration.sessionStoreStrategyType) {
105
109
  display.warn(
106
110
  'No storage available for session. We will not send any data.'
@@ -59,6 +59,7 @@ export function makeRecorderApi(startRecordingImpl, createDeflateWorkerImpl) {
59
59
  var state = {
60
60
  $rStatus: RecorderStatus.Stopped
61
61
  }
62
+ var retryOnView = false
62
63
  var nextRecordingToken = 0
63
64
  var unloadRecoveryGeneration = 0
64
65
  var replayDeflateWorkerController = createDeflateWorkerController()
@@ -66,22 +67,38 @@ export function makeRecorderApi(startRecordingImpl, createDeflateWorkerImpl) {
66
67
  return replayDeflateWorkerController.getStatus()
67
68
  }
68
69
 
70
+ function isRecordingInProgress() {
71
+ return state.$rStatus >= RecorderStatus.Starting
72
+ }
73
+
74
+ function keepRecordingIntent(options, shouldRetryOnView) {
75
+ retryOnView = shouldRetryOnView
76
+ state = {
77
+ $rStatus: RecorderStatus.IntentToStart,
78
+ $rOptions: options
79
+ }
80
+ notifyRecordingState(false)
81
+ }
82
+
83
+ function keepRecordingIntentAfterFailure(options) {
84
+ // `force` has already updated the current session before recorder startup.
85
+ // Reusing it while recovering would force the session again for every
86
+ // failed View instead of only retrying the recorder.
87
+ keepRecordingIntent(options && options.force ? undefined : options, true)
88
+ }
89
+
69
90
  function reconcileStoppedRecordingState() {
70
91
  if (
71
92
  state.$rStatus === RecorderStatus.Started &&
72
93
  state.$rIsStopped &&
73
94
  state.$rIsStopped()
74
95
  ) {
75
- state = { $rStatus: RecorderStatus.Stopped }
76
- notifyRecordingState(false)
96
+ keepRecordingIntentAfterFailure(state.$rOptions)
77
97
  }
78
98
  }
79
99
 
80
100
  var startStrategy = function (options) {
81
- state = {
82
- $rStatus: RecorderStatus.IntentToStart,
83
- $rOptions: options
84
- }
101
+ keepRecordingIntent(options)
85
102
  }
86
103
  var stopStrategy = function () {
87
104
  unloadRecoveryGeneration += 1
@@ -105,26 +122,17 @@ export function makeRecorderApi(startRecordingImpl, createDeflateWorkerImpl) {
105
122
  compressionWorker
106
123
  ) {
107
124
  lifeCycle.subscribe(LifeCycleEventType.SESSION_EXPIRED, function () {
108
- if (
109
- state.$rStatus === RecorderStatus.Starting ||
110
- state.$rStatus === RecorderStatus.Started
111
- ) {
125
+ if (isRecordingInProgress()) {
112
126
  var options = state.$rOptions
113
127
  stopStrategy()
114
- state = {
115
- $rStatus: RecorderStatus.IntentToStart,
116
- $rOptions: options
117
- }
128
+ keepRecordingIntent(options)
118
129
  }
119
130
  })
120
131
  lifeCycle.subscribe(
121
132
  LifeCycleEventType.PAGE_EXITED,
122
133
  function (pageExitEvent) {
123
134
  if (pageExitEvent.reason === PageExitReason.UNLOADING) {
124
- var shouldRecoverCanceledUnload =
125
- state.$rStatus === RecorderStatus.IntentToStart ||
126
- state.$rStatus === RecorderStatus.Starting ||
127
- state.$rStatus === RecorderStatus.Started
135
+ var shouldRecoverCanceledUnload = state.$rStatus
128
136
  var recoveryOptions =
129
137
  state.$rOptions && state.$rOptions.force
130
138
  ? undefined
@@ -152,6 +160,12 @@ export function makeRecorderApi(startRecordingImpl, createDeflateWorkerImpl) {
152
160
  startStrategy(state.$rOptions)
153
161
  }
154
162
  })
163
+ lifeCycle.subscribe(LifeCycleEventType.VIEW_CREATED, function () {
164
+ reconcileStoppedRecordingState()
165
+ if (state.$rStatus === RecorderStatus.IntentToStart && retryOnView) {
166
+ startStrategy(state.$rOptions)
167
+ }
168
+ })
155
169
  if (sessionManager.sessionStateUpdateObservable) {
156
170
  sessionManager.sessionStateUpdateObservable.subscribe(function ({
157
171
  previousState,
@@ -169,28 +183,41 @@ export function makeRecorderApi(startRecordingImpl, createDeflateWorkerImpl) {
169
183
  var cachedDeflateEncoder
170
184
  var replayWorker = compressionWorker
171
185
  var replayWorkerOwnership = compressionWorker ? 'shared' : 'none'
172
- function handleDeflateWorkerFailure() {
173
- var failedDeflateEncoder = cachedDeflateEncoder
174
- cachedDeflateEncoder = undefined
175
- stopStrategy()
176
- if (failedDeflateEncoder) {
177
- failedDeflateEncoder.stop()
178
- }
179
- if (replayWorkerOwnership === 'owned') {
180
- replayWorker = undefined
181
- replayWorkerOwnership = 'none'
182
- replayDeflateWorkerController.reset()
183
- } else if (replayWorkerOwnership === 'shared') {
184
- // The compression worker belongs to the RUM transport. A replay
185
- // stream failure must not terminate or reset that shared worker.
186
- // Detach replay from it so an explicit restart can fall back to an
187
- // isolated worker instead of remaining disabled for the whole page.
188
- replayWorker = undefined
189
- replayWorkerOwnership = 'none'
190
- }
191
- }
186
+ var activeDeflateFailure
192
187
  function getOrCreateDeflateEncoder() {
193
188
  if (!cachedDeflateEncoder) {
189
+ var handleDeflateWorkerFailure = function () {
190
+ if (activeDeflateFailure !== handleDeflateWorkerFailure) {
191
+ return
192
+ }
193
+ activeDeflateFailure = undefined
194
+ var shouldRetry = isRecordingInProgress()
195
+ var recoveryOptions = state.$rOptions
196
+ var failedDeflateEncoder = cachedDeflateEncoder
197
+ cachedDeflateEncoder = undefined
198
+ if (shouldRetry) {
199
+ stopStrategy()
200
+ }
201
+ if (failedDeflateEncoder) {
202
+ failedDeflateEncoder.stop()
203
+ }
204
+ if (replayWorkerOwnership === 'owned') {
205
+ replayWorker = undefined
206
+ replayWorkerOwnership = 'none'
207
+ replayDeflateWorkerController.reset()
208
+ } else if (replayWorkerOwnership === 'shared') {
209
+ // The compression worker belongs to the RUM transport. A replay
210
+ // stream failure must not terminate or reset that shared worker.
211
+ // Detach replay from it so a retry can fall back to an isolated
212
+ // worker instead of remaining disabled for the whole page.
213
+ replayWorker = undefined
214
+ replayWorkerOwnership = 'none'
215
+ }
216
+ if (shouldRetry) {
217
+ keepRecordingIntentAfterFailure(recoveryOptions)
218
+ }
219
+ }
220
+ activeDeflateFailure = handleDeflateWorkerFailure
194
221
  if (!replayWorker) {
195
222
  // Mark ownership before start(): worker creation can fail
196
223
  // synchronously and invoke the failure callback before start()
@@ -221,10 +248,7 @@ export function makeRecorderApi(startRecordingImpl, createDeflateWorkerImpl) {
221
248
  }
222
249
  startStrategy = function (options) {
223
250
  reconcileStoppedRecordingState()
224
- if (
225
- state.$rStatus === RecorderStatus.Starting ||
226
- state.$rStatus === RecorderStatus.Started
227
- ) {
251
+ if (isRecordingInProgress()) {
228
252
  if (options && options.force) {
229
253
  sessionManager.setForcedSession()
230
254
  }
@@ -239,10 +263,7 @@ export function makeRecorderApi(startRecordingImpl, createDeflateWorkerImpl) {
239
263
  }
240
264
  var session = sessionManager.findTrackedSession()
241
265
  if (!session || !session.sessionReplayAllowed) {
242
- state = {
243
- $rStatus: RecorderStatus.IntentToStart,
244
- $rOptions: options
245
- }
266
+ keepRecordingIntent(options)
246
267
  return
247
268
  }
248
269
 
@@ -262,9 +283,7 @@ export function makeRecorderApi(startRecordingImpl, createDeflateWorkerImpl) {
262
283
  }
263
284
  var deflateEncoder = getOrCreateDeflateEncoder()
264
285
  if (!deflateEncoder) {
265
- state = {
266
- $rStatus: RecorderStatus.Stopped
267
- }
286
+ keepRecordingIntentAfterFailure(options)
268
287
  return
269
288
  }
270
289
  try {
@@ -277,12 +296,10 @@ export function makeRecorderApi(startRecordingImpl, createDeflateWorkerImpl) {
277
296
  undefined,
278
297
  function () {
279
298
  if (
280
- (state.$rStatus === RecorderStatus.Starting ||
281
- state.$rStatus === RecorderStatus.Started) &&
299
+ isRecordingInProgress() &&
282
300
  state.$rToken === recordingToken
283
301
  ) {
284
- state = { $rStatus: RecorderStatus.Stopped }
285
- notifyRecordingState(false)
302
+ keepRecordingIntentAfterFailure(options)
286
303
  }
287
304
  }
288
305
  )
@@ -294,9 +311,7 @@ export function makeRecorderApi(startRecordingImpl, createDeflateWorkerImpl) {
294
311
  return
295
312
  }
296
313
  if (recordingImpl.isStopped && recordingImpl.isStopped()) {
297
- state = {
298
- $rStatus: RecorderStatus.Stopped
299
- }
314
+ keepRecordingIntentAfterFailure(options)
300
315
  return
301
316
  }
302
317
  state = {
@@ -336,13 +351,12 @@ export function makeRecorderApi(startRecordingImpl, createDeflateWorkerImpl) {
336
351
  state.$rStatus === RecorderStatus.Starting &&
337
352
  state.$rToken === recordingToken
338
353
  ) {
339
- state = { $rStatus: RecorderStatus.Stopped }
354
+ keepRecordingIntentAfterFailure(options)
340
355
  }
341
356
  if (
342
357
  cachedDeflateEncoder === deflateEncoder &&
343
358
  !(
344
- (state.$rStatus === RecorderStatus.Starting ||
345
- state.$rStatus === RecorderStatus.Started) &&
359
+ isRecordingInProgress() &&
346
360
  state.$rToken !== recordingToken
347
361
  )
348
362
  ) {
@@ -19,17 +19,23 @@ import {
19
19
  createCustomerDataTrackerManager,
20
20
  CustomerDataCompressionStatus,
21
21
  displayAlreadyInitializedError,
22
- getType
22
+ getType,
23
+ noop
23
24
  } from '@cloudcare/browser-core'
24
25
  import { buildCommonContext } from '../domain/contexts/commonContext'
25
26
  import { callPluginsMethod } from '../domain/plugins'
26
27
  import { createPreStartStrategy } from './perStartRum'
27
28
  import { createResourceTrackerManager } from '../domain/rumEventsCollection/resource/resourceTrackerManager'
29
+ import {
30
+ startVisitorId,
31
+ VISITOR_ID_CONTEXT_KEY
32
+ } from '../domain/visitorId'
28
33
  var RUM_STORAGE_KEY = 'rum'
29
34
  export function makeRumPublicApi(startRumImpl, recorderApi, options) {
30
35
  if (options === undefined) {
31
36
  options = {}
32
37
  }
38
+ var startVisitorIdImpl = options.startVisitorId || startVisitorId
33
39
  const customerDataTrackerManager = createCustomerDataTrackerManager(
34
40
  CustomerDataCompressionStatus.Unknown
35
41
  )
@@ -49,12 +55,32 @@ export function makeRumPublicApi(startRumImpl, recorderApi, options) {
49
55
  email: { type: 'string' }
50
56
  }
51
57
  })
58
+ var visitorId = {
59
+ getId: noop,
60
+ reset: noop,
61
+ stop: noop
62
+ }
63
+ function getGlobalContext() {
64
+ var context = globalContextManager.getContext()
65
+ var currentVisitorId = visitorId.getId()
66
+ if (currentVisitorId) {
67
+ context[VISITOR_ID_CONTEXT_KEY] = currentVisitorId
68
+ }
69
+ return context
70
+ }
52
71
  function getCommonContext() {
53
- return buildCommonContext(
72
+ var commonContext = buildCommonContext(
54
73
  globalContextManager,
55
74
  userContextManager,
56
75
  recorderApi
57
76
  )
77
+ var currentVisitorId = visitorId.getId()
78
+ if (currentVisitorId) {
79
+ commonContext.context[VISITOR_ID_CONTEXT_KEY] = currentVisitorId
80
+ // Keep the SDK value separate from customer fields in buffered snapshots.
81
+ commonContext.visitorId = currentVisitorId
82
+ }
83
+ return commonContext
58
84
  }
59
85
  let strategy
60
86
  function addPluginError(providedError) {
@@ -79,6 +105,10 @@ export function makeRumPublicApi(startRumImpl, recorderApi, options) {
79
105
  rum: publicApi,
80
106
  initConfiguration: initConfiguration
81
107
  })
108
+ },
109
+ onConfigurationReady: function (configuration) {
110
+ visitorId.stop()
111
+ visitorId = startVisitorIdImpl(configuration)
82
112
  }
83
113
  }),
84
114
  getCommonContext,
@@ -197,10 +227,10 @@ export function makeRumPublicApi(startRumImpl, recorderApi, options) {
197
227
 
198
228
  /** @deprecated: use getGlobalContext instead */
199
229
  getRumGlobalContext: monitor(function () {
200
- return globalContextManager.getContext()
230
+ return getGlobalContext()
201
231
  }),
202
232
  getGlobalContext: monitor(function () {
203
- return globalContextManager.getContext()
233
+ return getGlobalContext()
204
234
  }),
205
235
 
206
236
  /** @deprecated: use setGlobalContext instead */
@@ -216,6 +246,10 @@ export function makeRumPublicApi(startRumImpl, recorderApi, options) {
216
246
  clearGlobalContext: monitor(function () {
217
247
  return globalContextManager.clearContext()
218
248
  }),
249
+ resetVisitorId: monitor(function () {
250
+ visitorId.reset()
251
+ addTelemetryUsage({ feature: 'reset-visitor-id' })
252
+ }),
219
253
 
220
254
  getInitConfiguration: monitor(function () {
221
255
  return deepClone(strategy.initConfiguration)
@@ -56,7 +56,10 @@ export function startRecording(
56
56
  var finalReplayTimeAnchorRequested = false
57
57
  var hasSegmentCollection = false
58
58
  function emitFinalReplayTimeAnchor() {
59
- if (finalReplayTimeAnchorRequested) {
59
+ if (
60
+ finalReplayTimeAnchorRequested ||
61
+ document.visibilityState !== 'visible'
62
+ ) {
60
63
  return true
61
64
  }
62
65
  var admissionResult = emitReplayTimeAnchor()
@@ -361,7 +364,13 @@ export function startRecording(
361
364
  // mutations are never attached to the stale pre-overflow snapshot.
362
365
  _record.flushMutations()
363
366
  flushCanvasCommands()
364
- return emitReplayTimeAnchor()
367
+ if (
368
+ pageExitEvent.reason === PageExitReason.HIDDEN ||
369
+ document.visibilityState === 'visible'
370
+ ) {
371
+ return emitReplayTimeAnchor()
372
+ }
373
+ return
365
374
  }
366
375
  if (!flushScheduledFullSnapshot()) {
367
376
  // The segment is still writable in this hook. Give a paged raw/shadow
@@ -188,8 +188,20 @@ export function startRumAssembly(
188
188
  {},
189
189
  commonContext.context,
190
190
  viewContext.context,
191
- customerContext
191
+ customerContext,
192
+ rawRumEvent.context
192
193
  )
194
+ if (configuration.visitorId && configuration.visitorId.enabled) {
195
+ var visitorId =
196
+ (rawRumEvent.type === RumEventType.RESOURCE &&
197
+ rawRumEvent.context &&
198
+ rawRumEvent.context.visitor_id) ||
199
+ commonContext.visitorId ||
200
+ (savedCommonContext && getCommonContext().visitorId)
201
+ if (visitorId) {
202
+ context.visitor_id = visitorId
203
+ }
204
+ }
193
205
  if (!isEmptyObject(context)) {
194
206
  serverRumEvent.context = context
195
207
  }
@@ -14,11 +14,14 @@ import {
14
14
  getOrigin,
15
15
  each,
16
16
  isNumber,
17
+ isString,
18
+ getType,
17
19
  ExperimentalFeature
18
20
  } from '@cloudcare/browser-core'
19
21
  import { buildEnv } from '../boot/buildEnv'
20
22
  import { isTracingOption } from '../domain/tracing/tracer'
21
23
  import { validatePlugins } from './plugins'
24
+ import { DEFAULT_VISITOR_ID_TTL_HOURS } from './visitorId'
22
25
 
23
26
  var REPLAY_CANVAS_QUALITY_PRESETS = {
24
27
  low: {
@@ -61,6 +64,65 @@ var POSITIVE_REPLAY_CANVAS_OPTIONS = [
61
64
  ['replayCanvasAutoMaxPerRun', 'Auto Max Per Run']
62
65
  ]
63
66
 
67
+ var HTTP_HEADER_NAME_PATTERN = /^[!#$%&'*+\-.^_`|~0-9a-z]+$/
68
+ var FORBIDDEN_VISITOR_ID_HEADERS = [
69
+ 'b3',
70
+ 'traceparent',
71
+ 'tracestate',
72
+ 'uber-trace-id',
73
+ 'sw8',
74
+ 'x-gc-trace-id',
75
+ 'x-gc-span-id',
76
+ 'x-rum-resource-id'
77
+ ]
78
+ var FORBIDDEN_VISITOR_ID_HEADER_FRAGMENTS = [
79
+ 'authorization',
80
+ 'authentication',
81
+ 'api-key',
82
+ 'api_key',
83
+ 'apikey',
84
+ 'auth-token',
85
+ 'auth_token',
86
+ 'access-token',
87
+ 'access_token',
88
+ 'session-token',
89
+ 'session_token',
90
+ 'refresh-token',
91
+ 'refresh_token',
92
+ 'id-token',
93
+ 'id_token',
94
+ 'security-token',
95
+ 'security_token',
96
+ 'csrf',
97
+ 'xsrf',
98
+ 'jwt',
99
+ 'signature'
100
+ ]
101
+ var FORBIDDEN_REQUEST_HEADERS = [
102
+ 'accept-charset',
103
+ 'accept-encoding',
104
+ 'access-control-request-headers',
105
+ 'access-control-request-method',
106
+ 'authorization',
107
+ 'connection',
108
+ 'content-length',
109
+ 'cookie',
110
+ 'cookie2',
111
+ 'date',
112
+ 'dnt',
113
+ 'expect',
114
+ 'host',
115
+ 'keep-alive',
116
+ 'origin',
117
+ 'permissions-policy',
118
+ 'referer',
119
+ 'te',
120
+ 'trailer',
121
+ 'transfer-encoding',
122
+ 'upgrade',
123
+ 'via'
124
+ ]
125
+
64
126
  function getReplayCanvasQualityPreset(value) {
65
127
  return typeof value === 'string'
66
128
  ? REPLAY_CANVAS_QUALITY_PRESETS[value]
@@ -108,6 +170,12 @@ export function validateAndBuildRumConfiguration(initConfiguration) {
108
170
  if (!allowedTracingUrls) {
109
171
  return
110
172
  }
173
+ var visitorId = validateAndBuildVisitorIdConfiguration(
174
+ initConfiguration.visitorId
175
+ )
176
+ if (!visitorId) {
177
+ return
178
+ }
111
179
  // if (initConfiguration.allowedTracingOrigins !== undefined) {
112
180
  // if (!isArray(initConfiguration.allowedTracingOrigins)) {
113
181
  // display.error('Allowed Tracing Origins should be an array')
@@ -230,6 +298,10 @@ export function validateAndBuildRumConfiguration(initConfiguration) {
230
298
  {
231
299
  applicationId: initConfiguration.applicationId,
232
300
  actionNameAttribute: initConfiguration.actionNameAttribute,
301
+ enablePrivacyForActionName: isNullUndefinedDefaultValue(
302
+ initConfiguration.enablePrivacyForActionName,
303
+ false
304
+ ),
233
305
  sessionReplaySampleRate: isNullUndefinedDefaultValue(
234
306
  initConfiguration.sessionReplaySampleRate,
235
307
  100
@@ -249,6 +321,7 @@ export function validateAndBuildRumConfiguration(initConfiguration) {
249
321
  allowTraceHeaderWithoutSession:
250
322
  !!initConfiguration.allowTraceHeaderWithoutSession,
251
323
  allowedTracingUrls: allowedTracingUrls,
324
+ visitorId: visitorId,
252
325
  injectTraceHeader:
253
326
  initConfiguration.injectTraceHeader &&
254
327
  catchUserErrors(
@@ -360,6 +433,91 @@ export function validateAndBuildRumConfiguration(initConfiguration) {
360
433
  )
361
434
  }
362
435
 
436
+ export function validateAndBuildVisitorIdConfiguration(visitorId) {
437
+ if (visitorId === undefined) {
438
+ return { enabled: false }
439
+ }
440
+ if (getType(visitorId) !== 'object') {
441
+ display.error('Visitor ID configuration should be an object')
442
+ return
443
+ }
444
+ if (
445
+ visitorId.enabled !== undefined &&
446
+ typeof visitorId.enabled !== 'boolean'
447
+ ) {
448
+ display.error('Visitor ID enabled should be a boolean')
449
+ return
450
+ }
451
+ if (visitorId.enabled !== true) {
452
+ return { enabled: false }
453
+ }
454
+ if (!isValidVisitorIdHeader(visitorId.header)) {
455
+ display.error(
456
+ 'Visitor ID header should be a lowercase, writable HTTP header name and must not overlap authentication, CSRF, signature, tracing, or SDK resource tracking headers'
457
+ )
458
+ return
459
+ }
460
+ if (
461
+ !isArray(visitorId.match) ||
462
+ visitorId.match.length === 0 ||
463
+ visitorId.match.some(function (matchOption) {
464
+ return (
465
+ !isMatchOption(matchOption) ||
466
+ (isString(matchOption) && matchOption.length === 0)
467
+ )
468
+ })
469
+ ) {
470
+ display.error(
471
+ 'Visitor ID match should be a non-empty array of strings, RegExp values, or functions'
472
+ )
473
+ return
474
+ }
475
+ if (
476
+ visitorId.ttlHours !== undefined &&
477
+ (!isNumber(visitorId.ttlHours) ||
478
+ !isFinite(visitorId.ttlHours) ||
479
+ visitorId.ttlHours <= 0)
480
+ ) {
481
+ display.error('Visitor ID TTL should be a positive number of hours')
482
+ return
483
+ }
484
+
485
+ return {
486
+ enabled: true,
487
+ header: visitorId.header,
488
+ match: visitorId.match.slice(),
489
+ ttlHours: isNullUndefinedDefaultValue(
490
+ visitorId.ttlHours,
491
+ DEFAULT_VISITOR_ID_TTL_HOURS
492
+ )
493
+ }
494
+ }
495
+
496
+ function isValidVisitorIdHeader(header) {
497
+ if (
498
+ !isString(header) ||
499
+ header !== header.toLowerCase() ||
500
+ !HTTP_HEADER_NAME_PATTERN.test(header)
501
+ ) {
502
+ return false
503
+ }
504
+ if (
505
+ header.indexOf('proxy-') === 0 ||
506
+ header.indexOf('sec-') === 0 ||
507
+ header.indexOf('x-datadog-') === 0 ||
508
+ header.indexOf('x-b3-') === 0 ||
509
+ FORBIDDEN_VISITOR_ID_HEADER_FRAGMENTS.some(function (fragment) {
510
+ return header.indexOf(fragment) !== -1
511
+ })
512
+ ) {
513
+ return false
514
+ }
515
+ return (
516
+ FORBIDDEN_REQUEST_HEADERS.indexOf(header) === -1 &&
517
+ FORBIDDEN_VISITOR_ID_HEADERS.indexOf(header) === -1
518
+ )
519
+ }
520
+
363
521
  /**
364
522
  * Handles allowedTracingUrls and processes legacy allowedTracingOrigins
365
523
  */