Skip to content

Commit

Permalink
Public method takeSessionReplayFullSnapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
amortemousque committed Nov 16, 2023
1 parent f2f10b4 commit 33526f4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/rum-core/src/boot/rumPublicApi.ts
Expand Up @@ -52,6 +52,7 @@ type StartRumResult = ReturnType<typeof startRum>
export interface RecorderApi {
start: () => void
stop: () => void
takeFullSnapshot: () => void
onRumStart: (
lifeCycle: LifeCycle,
configuration: RumConfiguration,
Expand Down Expand Up @@ -126,6 +127,8 @@ export function makeRumPublicApi(
bufferApiCalls.add(() => recorderStopStrategy())
}

let recorderTakeFullSnapshotStrategy: typeof recorderApi.takeFullSnapshot = () => {}

let addFeatureFlagEvaluationStrategy: StartRumResult['addFeatureFlagEvaluation'] = (key: string, value: any) => {
bufferApiCalls.add(() => addFeatureFlagEvaluationStrategy(key, value))
}
Expand Down Expand Up @@ -230,6 +233,7 @@ export function makeRumPublicApi(
recorderApi.getSessionReplayLink(configuration, startRumResults.session, startRumResults.viewContexts)
recorderStartStrategy = recorderApi.start
recorderStopStrategy = recorderApi.stop
recorderTakeFullSnapshotStrategy = recorderApi.takeFullSnapshot
;({
startView: startViewStrategy,
addAction: addActionStrategy,
Expand Down Expand Up @@ -324,6 +328,7 @@ export function makeRumPublicApi(

startSessionReplayRecording: monitor(() => recorderStartStrategy()),
stopSessionReplayRecording: monitor(() => recorderStopStrategy()),
takeSessionReplayFullSnapshot: monitor(() => recorderTakeFullSnapshotStrategy()),

/**
* This feature is currently in beta. For more information see the full [feature flag tracking guide](https://docs.datadoghq.com/real_user_monitoring/feature_flag_tracking/).
Expand Down
1 change: 1 addition & 0 deletions packages/rum-core/test/noopRecorderApi.ts
Expand Up @@ -4,6 +4,7 @@ import { noop } from '@datadog/browser-core'
export const noopRecorderApi: RecorderApi = {
start: noop,
stop: noop,
takeFullSnapshot: noop,
isRecording: () => false,
onRumStart: noop,
getReplayStats: () => undefined,
Expand Down
1 change: 1 addition & 0 deletions packages/rum-slim/src/entries/main.ts
Expand Up @@ -30,6 +30,7 @@ export { DefaultPrivacyLevel } from '@datadog/browser-core'
export const datadogRum = makeRumPublicApi(startRum, {
start: noop,
stop: noop,
takeFullSnapshot: noop,
onRumStart: noop,
isRecording: () => false,
getReplayStats: () => undefined,
Expand Down
7 changes: 6 additions & 1 deletion packages/rum/src/boot/recorderApi.ts
Expand Up @@ -56,6 +56,7 @@ export function makeRecorderApi(
return {
start: noop,
stop: noop,
takeFullSnapshot: noop,
getReplayStats: () => undefined,
onRumStart: noop,
isRecording: () => false,
Expand All @@ -73,9 +74,12 @@ export function makeRecorderApi(
let stopStrategy = () => {
state = { status: RecorderStatus.Stopped }
}

let takeFullSnapshotStrategy = noop
return {
start: () => startStrategy(),
stop: () => stopStrategy(),
takeFullSnapshot: () => takeFullSnapshotStrategy(),
getSessionReplayLink: (configuration, sessionManager, viewContexts) =>
getSessionReplayLink(configuration, sessionManager, viewContexts, state.status !== RecorderStatus.Stopped),
onRumStart: (
Expand Down Expand Up @@ -137,13 +141,14 @@ export function makeRecorderApi(
}
}

const { stop: stopRecording } = startRecordingImpl(
const { stop: stopRecording, takeSubsequentFullSnapshot } = startRecordingImpl(
lifeCycle,
configuration,
sessionManager,
viewContexts,
createDeflateEncoder(configuration, worker, DeflateEncoderStreamId.REPLAY)
)
takeFullSnapshotStrategy = takeSubsequentFullSnapshot
state = {
status: RecorderStatus.Started,
stopRecording,
Expand Down
1 change: 1 addition & 0 deletions packages/rum/src/boot/startRecording.ts
Expand Up @@ -95,6 +95,7 @@ export function startRecording(
)

return {
takeSubsequentFullSnapshot,
stop: () => {
unsubscribeViewEnded()
unsubscribeViewCreated()
Expand Down

0 comments on commit 33526f4

Please sign in to comment.