@cloudcare/browser-rum 3.3.14 → 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.
- package/README.md +60 -0
- package/README.zh.md +48 -0
- package/bundle/dataflux-rum.js +1 -1
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/boot/perStartRum.js +3 -0
- package/cjs/boot/perStartRum.js.map +1 -1
- package/cjs/boot/recorderApi.js +72 -56
- package/cjs/boot/recorderApi.js.map +1 -1
- package/cjs/boot/rumPublicApi.js +35 -3
- package/cjs/boot/rumPublicApi.js.map +1 -1
- package/cjs/boot/startRecording.js +4 -4
- package/cjs/boot/startRecording.js.map +1 -1
- package/cjs/constants.js +8 -8
- package/cjs/constants.js.map +1 -1
- package/cjs/domain/assembly.js +14 -1
- package/cjs/domain/assembly.js.map +1 -1
- package/cjs/domain/configuration.js +62 -0
- package/cjs/domain/configuration.js.map +1 -1
- package/cjs/domain/deflate/deflateWorker.js +1 -1
- package/cjs/domain/encoderStreamId.js +2 -1
- package/cjs/domain/encoderStreamId.js.map +1 -1
- package/cjs/domain/replay/record/canvasEncodeWorker.js +1 -1
- package/cjs/domain/replay/record/record.js +2 -3
- package/cjs/domain/replay/record/record.js.map +1 -1
- package/cjs/domain/replay/record/serializationUtils.js +8 -15
- package/cjs/domain/replay/record/serializationUtils.js.map +1 -1
- package/cjs/domain/replay/record/serialize.js +14 -6
- package/cjs/domain/replay/record/serialize.js.map +1 -1
- package/cjs/domain/requestCollection.js +3 -1
- package/cjs/domain/requestCollection.js.map +1 -1
- package/cjs/domain/rumEventsCollection/error/errorCollection.js +6 -8
- package/cjs/domain/rumEventsCollection/error/errorCollection.js.map +1 -1
- package/cjs/domain/rumEventsCollection/resource/resourceCollection.js +5 -0
- package/cjs/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
- package/cjs/domain/rumSessionManager.js +3 -3
- package/cjs/domain/rumSessionManager.js.map +1 -1
- package/cjs/domain/tracing/tracer.js +5 -1
- package/cjs/domain/tracing/tracer.js.map +1 -1
- package/cjs/domain/visitorId/index.js +417 -0
- package/cjs/domain/visitorId/index.js.map +1 -0
- package/cjs/index.js +7 -0
- package/cjs/index.js.map +1 -1
- package/cjs/transport/startRumBatch.js +44 -3
- package/cjs/transport/startRumBatch.js.map +1 -1
- package/esm/boot/buildEnv.js +1 -1
- package/esm/boot/perStartRum.js +3 -0
- package/esm/boot/perStartRum.js.map +1 -1
- package/esm/boot/recorderApi.js +72 -56
- package/esm/boot/recorderApi.js.map +1 -1
- package/esm/boot/rumPublicApi.js +36 -4
- package/esm/boot/rumPublicApi.js.map +1 -1
- package/esm/boot/startRecording.js +4 -4
- package/esm/boot/startRecording.js.map +1 -1
- package/esm/constants.js +1 -8
- package/esm/constants.js.map +1 -1
- package/esm/domain/assembly.js +15 -2
- package/esm/domain/assembly.js.map +1 -1
- package/esm/domain/configuration.js +62 -1
- package/esm/domain/configuration.js.map +1 -1
- package/esm/domain/deflate/deflateWorker.js +1 -1
- package/esm/domain/encoderStreamId.js +2 -1
- package/esm/domain/encoderStreamId.js.map +1 -1
- package/esm/domain/replay/record/canvasEncodeWorker.js +1 -1
- package/esm/domain/replay/record/record.js +1 -2
- package/esm/domain/replay/record/record.js.map +1 -1
- package/esm/domain/replay/record/serializationUtils.js +8 -15
- package/esm/domain/replay/record/serializationUtils.js.map +1 -1
- package/esm/domain/replay/record/serialize.js +13 -5
- package/esm/domain/replay/record/serialize.js.map +1 -1
- package/esm/domain/requestCollection.js +4 -2
- package/esm/domain/requestCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/error/errorCollection.js +6 -8
- package/esm/domain/rumEventsCollection/error/errorCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/resourceCollection.js +5 -0
- package/esm/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
- package/esm/domain/rumSessionManager.js +3 -3
- package/esm/domain/rumSessionManager.js.map +1 -1
- package/esm/domain/tracing/tracer.js +6 -2
- package/esm/domain/tracing/tracer.js.map +1 -1
- package/esm/domain/visitorId/index.js +406 -0
- package/esm/domain/visitorId/index.js.map +1 -0
- package/esm/index.js +1 -0
- package/esm/index.js.map +1 -1
- package/esm/transport/startRumBatch.js +45 -4
- package/esm/transport/startRumBatch.js.map +1 -1
- package/package.json +4 -4
- package/src/boot/perStartRum.js +4 -0
- package/src/boot/recorderApi.js +73 -59
- package/src/boot/rumPublicApi.js +38 -4
- package/src/boot/startRecording.js +7 -3
- package/src/constants.js +1 -8
- package/src/domain/assembly.js +28 -2
- package/src/domain/configuration.js +154 -0
- package/src/domain/encoderStreamId.js +2 -2
- package/src/domain/replay/record/record.js +1 -2
- package/src/domain/replay/record/serializationUtils.js +10 -24
- package/src/domain/replay/record/serialize.js +25 -5
- package/src/domain/requestCollection.js +4 -1
- package/src/domain/rumEventsCollection/error/errorCollection.js +10 -8
- package/src/domain/rumEventsCollection/resource/resourceCollection.js +3 -0
- package/src/domain/rumSessionManager.js +8 -7
- package/src/domain/tracing/tracer.js +15 -2
- package/src/domain/visitorId/index.js +571 -0
- package/src/index.js +1 -0
- package/src/transport/startRumBatch.js +61 -3
- package/types/index.d.ts +23 -1
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudcare/browser-rum",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.16",
|
|
4
4
|
"main": "cjs/index.js",
|
|
5
5
|
"module": "esm/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@cloudcare/browser-core": "3.3.
|
|
9
|
-
"@cloudcare/browser-worker": "3.3.
|
|
8
|
+
"@cloudcare/browser-core": "3.3.16",
|
|
9
|
+
"@cloudcare/browser-worker": "3.3.16"
|
|
10
10
|
},
|
|
11
11
|
"description": "Guance Browser SDK RUM Package",
|
|
12
12
|
"browserSdkCapabilities": {
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"author": "dataflux",
|
|
42
42
|
"license": "MIT",
|
|
43
43
|
"homepage": "https://github.com/GuanceCloud/datakit-js/README.md",
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "c6d2dbe27df774f31227c9ee1631f981d5d8d5de"
|
|
45
45
|
}
|
package/src/boot/perStartRum.js
CHANGED
|
@@ -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.'
|
package/src/boot/recorderApi.js
CHANGED
|
@@ -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
|
|
76
|
-
notifyRecordingState(false)
|
|
96
|
+
keepRecordingIntentAfterFailure(state.$rOptions)
|
|
77
97
|
}
|
|
78
98
|
}
|
|
79
99
|
|
|
80
100
|
var startStrategy = function (options) {
|
|
81
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
(
|
|
281
|
-
state.$rStatus === RecorderStatus.Started) &&
|
|
299
|
+
isRecordingInProgress() &&
|
|
282
300
|
state.$rToken === recordingToken
|
|
283
301
|
) {
|
|
284
|
-
|
|
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
|
-
|
|
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
|
-
|
|
354
|
+
keepRecordingIntentAfterFailure(options)
|
|
340
355
|
}
|
|
341
356
|
if (
|
|
342
357
|
cachedDeflateEncoder === deflateEncoder &&
|
|
343
358
|
!(
|
|
344
|
-
(
|
|
345
|
-
state.$rStatus === RecorderStatus.Started) &&
|
|
359
|
+
isRecordingInProgress() &&
|
|
346
360
|
state.$rToken !== recordingToken
|
|
347
361
|
)
|
|
348
362
|
) {
|
package/src/boot/rumPublicApi.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
230
|
+
return getGlobalContext()
|
|
201
231
|
}),
|
|
202
232
|
getGlobalContext: monitor(function () {
|
|
203
|
-
return
|
|
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)
|
|
@@ -238,14 +238,18 @@ export function startRecording(
|
|
|
238
238
|
if (isRecordErrorSessionReplay) {
|
|
239
239
|
var sessionStateUpdateSubscription =
|
|
240
240
|
sessionManager.sessionStateUpdateObservable.subscribe(
|
|
241
|
-
({
|
|
242
|
-
if (
|
|
241
|
+
({ newState }) => {
|
|
242
|
+
if (
|
|
243
|
+
isRecordErrorSessionReplay &&
|
|
244
|
+
(newState.hasError || newState.forcedSession)
|
|
245
|
+
) {
|
|
243
246
|
isRecordErrorSessionReplay = false
|
|
244
247
|
replayTimeAnchorsEnabled = true
|
|
245
248
|
unlockSegment()
|
|
246
249
|
// Error-only recordings do not need periodic anchor-only
|
|
247
250
|
// segments while their buffer is locked. Establish the live
|
|
248
|
-
// timeline immediately when
|
|
251
|
+
// timeline immediately when an error or forced session
|
|
252
|
+
// unlocks it.
|
|
249
253
|
emitReplayTimeAnchor()
|
|
250
254
|
}
|
|
251
255
|
}
|
package/src/constants.js
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export var NodePrivacyLevel = {
|
|
3
|
-
IGNORE: 'ignore',
|
|
4
|
-
HIDDEN: 'hidden',
|
|
5
|
-
ALLOW: DefaultPrivacyLevel.ALLOW,
|
|
6
|
-
MASK: DefaultPrivacyLevel.MASK,
|
|
7
|
-
MASK_USER_INPUT: DefaultPrivacyLevel.MASK_USER_INPUT
|
|
8
|
-
}
|
|
1
|
+
export { NodePrivacyLevel } from '@cloudcare/browser-core'
|
|
9
2
|
|
|
10
3
|
export var PRIVACY_ATTR_NAME = 'data-gc-privacy'
|
|
11
4
|
|
package/src/domain/assembly.js
CHANGED
|
@@ -12,7 +12,8 @@ import {
|
|
|
12
12
|
limitModification,
|
|
13
13
|
display,
|
|
14
14
|
assign,
|
|
15
|
-
round
|
|
15
|
+
round,
|
|
16
|
+
WeakSet
|
|
16
17
|
} from '@cloudcare/browser-core'
|
|
17
18
|
var SessionType = {
|
|
18
19
|
SYNTHETICS: 'synthetics',
|
|
@@ -93,6 +94,9 @@ export function startRumAssembly(
|
|
|
93
94
|
reportError
|
|
94
95
|
)
|
|
95
96
|
var pendingRawEvents = createBoundedBuffer()
|
|
97
|
+
// Context objects belong to the existing View history. Weak references do
|
|
98
|
+
// not retain ended Views or require a second history of every collected ID.
|
|
99
|
+
var collectedViews = new WeakSet()
|
|
96
100
|
var resolvedDeviceInfo
|
|
97
101
|
getDeviceInfoImp(function (deviceInfo) {
|
|
98
102
|
resolvedDeviceInfo = deviceInfo
|
|
@@ -188,8 +192,20 @@ export function startRumAssembly(
|
|
|
188
192
|
{},
|
|
189
193
|
commonContext.context,
|
|
190
194
|
viewContext.context,
|
|
191
|
-
customerContext
|
|
195
|
+
customerContext,
|
|
196
|
+
rawRumEvent.context
|
|
192
197
|
)
|
|
198
|
+
if (configuration.visitorId && configuration.visitorId.enabled) {
|
|
199
|
+
var visitorId =
|
|
200
|
+
(rawRumEvent.type === RumEventType.RESOURCE &&
|
|
201
|
+
rawRumEvent.context &&
|
|
202
|
+
rawRumEvent.context.visitor_id) ||
|
|
203
|
+
commonContext.visitorId ||
|
|
204
|
+
(savedCommonContext && getCommonContext().visitorId)
|
|
205
|
+
if (visitorId) {
|
|
206
|
+
context.visitor_id = visitorId
|
|
207
|
+
}
|
|
208
|
+
}
|
|
193
209
|
if (!isEmptyObject(context)) {
|
|
194
210
|
serverRumEvent.context = context
|
|
195
211
|
}
|
|
@@ -236,6 +252,16 @@ export function startRumAssembly(
|
|
|
236
252
|
LifeCycleEventType.RUM_EVENT_COLLECTED,
|
|
237
253
|
serverRumEvent
|
|
238
254
|
)
|
|
255
|
+
if (
|
|
256
|
+
serverRumEvent.type === RumEventType.VIEW &&
|
|
257
|
+
!collectedViews.has(viewContext)
|
|
258
|
+
) {
|
|
259
|
+
collectedViews.add(viewContext)
|
|
260
|
+
lifeCycle.notify(
|
|
261
|
+
LifeCycleEventType.RUM_VIEW_FIRST_COLLECTED,
|
|
262
|
+
serverRumEvent
|
|
263
|
+
)
|
|
264
|
+
}
|
|
239
265
|
}
|
|
240
266
|
}
|
|
241
267
|
}
|
|
@@ -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')
|
|
@@ -253,6 +321,7 @@ export function validateAndBuildRumConfiguration(initConfiguration) {
|
|
|
253
321
|
allowTraceHeaderWithoutSession:
|
|
254
322
|
!!initConfiguration.allowTraceHeaderWithoutSession,
|
|
255
323
|
allowedTracingUrls: allowedTracingUrls,
|
|
324
|
+
visitorId: visitorId,
|
|
256
325
|
injectTraceHeader:
|
|
257
326
|
initConfiguration.injectTraceHeader &&
|
|
258
327
|
catchUserErrors(
|
|
@@ -364,6 +433,91 @@ export function validateAndBuildRumConfiguration(initConfiguration) {
|
|
|
364
433
|
)
|
|
365
434
|
}
|
|
366
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
|
+
|
|
367
521
|
/**
|
|
368
522
|
* Handles allowedTracingUrls and processes legacy allowedTracingOrigins
|
|
369
523
|
*/
|
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
getSerializedNodeApproxBytes,
|
|
30
30
|
SERIALIZATION_MAX_NODE_COUNT,
|
|
31
31
|
SERIALIZATION_MAX_APPROX_BYTES,
|
|
32
|
+
FULL_SNAPSHOT_SERIALIZATION_MAX_APPROX_BYTES,
|
|
32
33
|
} from './serialize'
|
|
33
34
|
import { initInputObserver, initObservers } from './observers'
|
|
34
35
|
|
|
@@ -85,8 +86,6 @@ var FULL_SNAPSHOT_SYNCHRONOUS_FINALIZATION_BUDGET_MS = 12
|
|
|
85
86
|
// record must still fit below the segment layer's 4 MiB pending-raw budget.
|
|
86
87
|
var FULL_SNAPSHOT_SERIALIZATION_MAX_NODE_COUNT =
|
|
87
88
|
SERIALIZATION_MAX_NODE_COUNT * 4
|
|
88
|
-
var FULL_SNAPSHOT_SERIALIZATION_MAX_APPROX_BYTES =
|
|
89
|
-
SERIALIZATION_MAX_APPROX_BYTES * 4 - 64 * 1024
|
|
90
89
|
var FULL_SNAPSHOT_MAX_RESTART_COUNT = 3
|
|
91
90
|
var FULL_SNAPSHOT_MAX_TOTAL_DURATION_MS = 1000
|
|
92
91
|
var FULL_SNAPSHOT_MAX_WALL_DURATION_MS = 30000
|