Skip to content

Commit

Permalink
Move the sendToExtension for records
Browse files Browse the repository at this point in the history
  • Loading branch information
amortemousque committed Nov 15, 2023
1 parent 8d28a33 commit f2f10b4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
28 changes: 25 additions & 3 deletions packages/rum/src/boot/startRecording.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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,
})
Expand Down
3 changes: 1 addition & 2 deletions packages/rum/src/domain/segmentCollection/segment.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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":[' : ','
Expand Down

0 comments on commit f2f10b4

Please sign in to comment.