diff --git a/packages/rum/src/boot/startRecording.ts b/packages/rum/src/boot/startRecording.ts index 14d8507743..64782b1389 100644 --- a/packages/rum/src/boot/startRecording.ts +++ b/packages/rum/src/boot/startRecording.ts @@ -1,5 +1,12 @@ import type { RawError, HttpRequest, DeflateEncoder } from '@datadog/browser-core' -import { timeStampNow, createHttpRequest, addTelemetryDebug, canUseEventBridge, noop } from '@datadog/browser-core' +import { + timeStampNow, + createHttpRequest, + addTelemetryDebug, + canUseEventBridge, + noop, + sendToExtension, +} from '@datadog/browser-core' import type { LifeCycle, ViewContexts, @@ -48,19 +55,34 @@ export function startRecording( ;({ addRecord } = startRecordBridge(viewContexts)) } + const addRecordAndSendToExtension = (record: BrowserRecord) => { + addRecord(record) + sendToExtension('record', { + record, + segment: { + start: Infinity, + end: -Infinity, + creation_reason: 'init', + records_count: 0, + has_full_snapshot: false, + source: 'browser' as const, + }, + }) + } + const { stop: stopRecording, takeSubsequentFullSnapshot, flushMutations, } = record({ - emit: addRecord, + emit: addRecordAndSendToExtension, configuration, lifeCycle, }) const { unsubscribe: unsubscribeViewEnded } = lifeCycle.subscribe(LifeCycleEventType.VIEW_ENDED, () => { flushMutations() - addRecord({ + addRecordAndSendToExtension({ timestamp: timeStampNow(), type: RecordType.ViewEnd, }) diff --git a/packages/rum/src/domain/segmentCollection/segment.ts b/packages/rum/src/domain/segmentCollection/segment.ts index 395bb3b432..af6f309515 100644 --- a/packages/rum/src/domain/segmentCollection/segment.ts +++ b/packages/rum/src/domain/segmentCollection/segment.ts @@ -1,5 +1,5 @@ import type { Encoder, EncoderResult } from '@datadog/browser-core' -import { assign, sendToExtension } from '@datadog/browser-core' +import { assign } from '@datadog/browser-core' import type { BrowserRecord, BrowserSegmentMetadata, CreationReason, SegmentContext } from '../../types' import { RecordType } from '../../types' import * as replayStats from '../replayStats' @@ -41,7 +41,6 @@ export class Segment { this.metadata.records_count += 1 this.metadata.has_full_snapshot ||= record.type === RecordType.FullSnapshot - sendToExtension('record', { record, segment: this.metadata }) replayStats.addRecord(this.metadata.view.id) const prefix = this.encoder.isEmpty ? '{"records":[' : ','