Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: report reason for recording start #1452

Merged
merged 10 commits into from
Oct 15, 2024
15 changes: 14 additions & 1 deletion src/extensions/replay/sessionrecording.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,10 @@ export class SessionRecording {
if (makeDecision) {
const randomNumber = Math.random()
shouldSample = randomNumber < currentSampleRate
this._reportStarted('sampling', {
sampleRate: currentSampleRate,
randomNumber,
})
} else {
shouldSample = storedIsSampled
}
Expand Down Expand Up @@ -539,6 +543,7 @@ export class SessionRecording {
const tag = 'linked flag matched'
logger.info(LOGGER_PREFIX + ' ' + tag, payload)
this._tryAddCustomEvent(tag, payload)
this._reportStarted('linked_flag_match', payload)
}
this._linkedFlagSeen = linkedFlagMatches
})
Expand Down Expand Up @@ -711,7 +716,7 @@ export class SessionRecording {
}

// We only want to extend the session if it is an interactive event.
const { windowId, sessionId } = this.sessionManager.checkAndGetSessionAndWindowId(
const { windowId, sessionId, changeReason } = this.sessionManager.checkAndGetSessionAndWindowId(
!isUserInteraction,
event.timestamp
)
Expand All @@ -725,6 +730,7 @@ export class SessionRecording {
if (sessionIdChanged || windowIdChanged) {
this.stopRecording()
this.startIfEnabledOrStop()
this._reportStarted('session_id_change', { changeReason })
} else if (returningFromIdle) {
this._scheduleFullSnapshot()
}
Expand Down Expand Up @@ -1099,5 +1105,12 @@ export class SessionRecording {
* */
public overrideLinkedFlag() {
this._linkedFlagSeen = true
this._reportStarted('linked flag override')
}

private _reportStarted(reason: string, properties?: Properties) {
if (this.instance.config.session_recording.report_recording_started) {
this.instance.capture('$session_recording_started', { ...(properties || {}), reason })
}
}
}
6 changes: 6 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,12 @@ export interface SessionRecordingOptions {
Default is 5 minutes.
*/
session_idle_threshold_ms?: number
/*
Sends an event whenever a recording starts, with the reason the recording started.
Useful, for example, when using ingestion controls
to have a signal in batch exports to know which sessions have recordings
*/
report_recording_started?: boolean
}

export type SessionIdChangedCallback = (
Expand Down
Loading