-
Notifications
You must be signed in to change notification settings - Fork 142
/
startRumBatch.ts
59 lines (54 loc) · 1.87 KB
/
startRumBatch.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import type {
Context,
TelemetryEvent,
Observable,
RawError,
PageExitEvent,
DeflateEncoder,
} from '@datadog/browser-core'
import {
DeflateEncoderStreamId,
combine,
isTelemetryReplicationAllowed,
startBatchWithReplica,
} from '@datadog/browser-core'
import type { RumConfiguration } from '../domain/configuration'
import type { LifeCycle } from '../domain/lifeCycle'
import { LifeCycleEventType } from '../domain/lifeCycle'
import { RumEventType } from '../rawRumEvent.types'
import type { RumEvent } from '../rumEvent.types'
export function startRumBatch(
configuration: RumConfiguration,
lifeCycle: LifeCycle,
telemetryEventObservable: Observable<TelemetryEvent & Context>,
reportError: (error: RawError) => void,
pageExitObservable: Observable<PageExitEvent>,
sessionExpireObservable: Observable<void>,
createDeflateEncoder?: (streamId: DeflateEncoderStreamId) => DeflateEncoder
) {
const replica = configuration.replica
const batch = startBatchWithReplica(
configuration,
{
endpoint: configuration.rumEndpointBuilder,
encoder: createDeflateEncoder && createDeflateEncoder(DeflateEncoderStreamId.RUM),
},
replica && {
endpoint: replica.rumEndpointBuilder,
transformMessage: (message) => combine(message, { application: { id: replica.applicationId } }),
encoder: createDeflateEncoder && createDeflateEncoder(DeflateEncoderStreamId.RUM_REPLICA),
},
reportError,
pageExitObservable,
sessionExpireObservable
)
lifeCycle.subscribe(LifeCycleEventType.RUM_EVENT_COLLECTED, (serverRumEvent: RumEvent & Context) => {
if (serverRumEvent.type === RumEventType.VIEW) {
batch.upsert(serverRumEvent, serverRumEvent.view.id)
} else {
batch.add(serverRumEvent)
}
})
telemetryEventObservable.subscribe((event) => batch.add(event, isTelemetryReplicationAllowed(configuration)))
return batch
}