Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/shy-badgers-wander.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"posthog": patch
"posthog-android": patch
---

Stop sending `$sdk_debug_replay_*` and `$sdk_debug_session_start` on events while session replay is intentionally off (disabled in config, stopped by the app, or turned off remotely). `$recording_status` is still sent as `disabled`. Sampled-out and trigger-pending sessions are unchanged.
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@
"$lib": "posthog-android",
"$lib_version": "<sdk-version>",
"$recording_status": "disabled",
"$sdk_debug_replay_event_trigger_status": "trigger_disabled",
"$sdk_debug_replay_linked_flag_trigger_status": "trigger_disabled",
"$sdk_debug_replay_internal_buffer_length": 0,
"$sdk_debug_pending_queue_size": "<pending-queue-size>",
"$set": {
"plan": "pro"
Expand Down Expand Up @@ -94,11 +91,6 @@
"$lib": "posthog-android",
"$lib_version": "<sdk-version>",
"$recording_status": "disabled",
"$sdk_debug_replay_event_trigger_status": "trigger_disabled",
"$sdk_debug_replay_linked_flag_trigger_status": "trigger_disabled",
"$sdk_debug_replay_capture_mode": "screenshot",
"$sdk_debug_replay_internal_buffer_length": 0,
"$sdk_debug_session_start": 1700000000123,
"$sdk_debug_pending_queue_size": "<pending-queue-size>",
"$set": {
"email": "person@example.com"
Expand Down Expand Up @@ -141,9 +133,6 @@
"$lib": "posthog-android",
"$lib_version": "<sdk-version>",
"$recording_status": "disabled",
"$sdk_debug_replay_event_trigger_status": "trigger_disabled",
"$sdk_debug_replay_linked_flag_trigger_status": "trigger_disabled",
"$sdk_debug_replay_internal_buffer_length": 0,
"$sdk_debug_pending_queue_size": "<pending-queue-size>",
"$group_type": "company",
"$group_key": "posthog",
Expand Down Expand Up @@ -186,9 +175,6 @@
"$lib": "posthog-android",
"$lib_version": "<sdk-version>",
"$recording_status": "disabled",
"$sdk_debug_replay_event_trigger_status": "trigger_disabled",
"$sdk_debug_replay_linked_flag_trigger_status": "trigger_disabled",
"$sdk_debug_replay_internal_buffer_length": 0,
"$sdk_debug_pending_queue_size": "<pending-queue-size>",
"$groups": {
"company": "posthog"
Expand Down Expand Up @@ -234,9 +220,6 @@
"$lib": "posthog-android",
"$lib_version": "<sdk-version>",
"$recording_status": "disabled",
"$sdk_debug_replay_event_trigger_status": "trigger_disabled",
"$sdk_debug_replay_linked_flag_trigger_status": "trigger_disabled",
"$sdk_debug_replay_internal_buffer_length": 0,
"$sdk_debug_pending_queue_size": "<pending-queue-size>",
"$groups": {
"company": "posthog"
Expand Down
14 changes: 12 additions & 2 deletions posthog/src/main/java/com/posthog/PostHog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1042,11 +1042,12 @@ public class PostHog private constructor(
if (timestamp != null && managerStart > 0 && timestamp.time < managerStart) {
return props
}
val claimed = claimReplayDebugBundle()
val replayOff = isSessionReplayIntentionallyOff()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1/design] Agree on the reduced wire shape before releasing it

IMPORTANT · REQUIRED acceptance decision · intentional wire change, not a second recorder defect

Initialize the client without a replay integration and capture the first eligible event, such as sdk.screen("Home"). On base the event carries $sdk_debug_session_start; on head it does not. The current replay-debug spec expects the fallback session-start key when available and capture mode where provided. It separately requires config-derived diagnostics after stop or uninstall. The equivalent base/head probe verified the session-start removal, and the batch fixture records the intended wire change. Running more tests cannot resolve which contract should govern the release.

sdk-specs#232 proposes the reduced shape but is still open. It also says a successful mobile response missing sessionRecording is not remote-off. Android’s decoder already treated omission as false for recording; this PR newly makes omission suppress event diagnostics too. The executed probe verified suppression for both omitted and explicit false, while an enabled-object response retained diagnostics on both revisions. The current backend producer always writes the field, so this is a compatibility decision for omitted-field responses, not evidence of a current Cloud failure. The proposed spec also calls for gating the raw wrapper map; the React Native Android bridge reads PostHogReplayIntegration.debugProperties() directly and is not gated by this change.

Consider landing the spec change first or explicitly sequencing the two releases. Record whether omission should preserve diagnostics, including after a previously known remote-off result, and whether the native bridge is in scope or owned by a separate change. If omission should preserve diagnostics, distinguish field presence for this diagnostic gate without changing existing recording eligibility. Once agreed, pin the distinction with separate omitted, explicit-false, quota, and valid-object response assertions; verify the native bridge separately if the agreed contract covers it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed on the order, I'll hold this until sdk-specs#232 lands so the release doesn't go out ahead of the spec.

On the two open bits:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correction on the RN bridge bit: #232 keeps the wrapper-map requirement and marks Android partial, rather than amending the scenario. A follow-up adds a gated internal accessor and moves the RN bridge to it.

The status already follows the running recorder here (!handler.isActive() in PostHog.kt), and #232 now makes that the rule for every SDK. The missing-key allowance is in the spec text too. #232 is approved at 9b0ba3a, so this one goes in right after it merges.

val claimed = !replayOff && claimReplayDebugBundle()
// Guarded separately from the session and queue keys below: those come from the session
// manager and the queue, not from replay, so a handler that throws must not suppress them.
try {
val replayProps = readReplayDebugProperties()
val replayProps = if (replayOff) mapOf("\$recording_status" to "disabled") else readReplayDebugProperties()
if (claimed) {
props.putAll(replayProps)
} else {
Expand Down Expand Up @@ -3310,6 +3311,15 @@ public class PostHog private constructor(
return config?.sessionReplay == true
}

// Not off while sampled out, awaiting remote config, or waiting on a trigger: those keys explain
// why replay isn't recording. A running recorder is never off: a flags reload can restart it after
// an explicit stop, and a remote off stops it only after the app's flags callback has run.
private fun isSessionReplayIntentionallyOff(): Boolean {
val handler = sessionReplayHandler ?: return true
return !handler.isActive() &&
(!sessionReplayWanted || remoteConfig?.isSessionRecordingRemotelyDisabled() == true)
}

// this is used in cases where we know the session is already active
// so we spare another locker
private fun isSessionReplayFlagEnabled(): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ public class PostHogRemoteConfig(
@Volatile
private var sessionRecordingMinimumDurationMs: Long? = null

// The last /config said replay is off (sessionRecording false, or mobile recordings quota limited).
// Kept across clear(), like the cached session replay config.
@Volatile
private var sessionRecordingRemotelyDisabled = false

init {
preloadSessionRecordingConfig()
preloadSurveys()
Expand Down Expand Up @@ -355,8 +360,10 @@ public class PostHogRemoteConfig(
Learn more about billing limits at https://posthog.com/docs/billing/limits-alerts""",
)
processSessionRecordingConfig(false)
sessionRecordingRemotelyDisabled = true
} else {
processSessionRecordingConfig(it.sessionRecording)
sessionRecordingRemotelyDisabled = it.sessionRecording == false
Comment thread
ioannisj marked this conversation as resolved.
Resolved
}
processSurveys(it.surveys)
processErrorTrackingConfig(it.errorTracking)
Expand Down Expand Up @@ -1472,6 +1479,8 @@ public class PostHogRemoteConfig(
*/
public fun hasRemoteConfigFetched(): Boolean = remoteConfigHasFetched.get()

internal fun isSessionRecordingRemotelyDisabled(): Boolean = sessionRecordingRemotelyDisabled

/**
* Makes a sampling decision for session recording based on the sample rate
* from remote config and the given session ID.
Expand Down
Loading
Loading