feat: session replay minimum recording duration#482
Conversation
|
This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the |
|
This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the |
# Conflicts: # posthog-android/api/posthog-android.api # posthog-android/src/main/java/com/posthog/android/replay/PostHogReplayIntegration.kt # posthog/src/main/java/com/posthog/internal/PostHogRemoteConfig.kt
posthog-android Compliance ReportDate: 2026-05-06 08:39:58 UTC
|
| Test | Status | Duration |
|---|---|---|
| Request Payload.Request With Person Properties Device Id | ❌ | 251ms |
| Request Payload.Flags Request Uses V2 Query Param | ❌ | 24ms |
| Request Payload.Flags Request Hits Flags Path Not Decide | ❌ | 26ms |
| Request Payload.Flags Request Omits Authorization Header | ❌ | 28ms |
| Request Payload.Token In Flags Body Matches Init | ❌ | 18ms |
| Request Payload.Groups Round Trip | ❌ | 18ms |
| Request Payload.Groups Default To Empty Object | ❌ | 18ms |
| Request Payload.Person Properties Distinct Id Auto Populated When Caller Omits It | ❌ | 16ms |
| Request Payload.Disable Geoip False Propagates As Geoip Disable False | ❌ | 18ms |
| Request Payload.Disable Geoip Omitted Defaults To False | ❌ | 17ms |
| Request Payload.Flag Keys To Evaluate Contains Only Requested Key | ❌ | 18ms |
| Request Lifecycle.No Flags Request On Init Alone | ❌ | 14ms |
| Request Lifecycle.No Flags Request On Normal Capture | ❌ | 2053ms |
| Request Lifecycle.Two Flag Calls Produce Two Remote Requests | ❌ | 15ms |
| Request Lifecycle.Mock Response Value Is Returned To Caller | ❌ | 14ms |
| Side Effect Events.Get Feature Flag Captures Feature Flag Called Event | ❌ | 13ms |
Failures
request_payload.request_with_person_properties_device_id
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_payload.flags_request_uses_v2_query_param
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_payload.flags_request_hits_flags_path_not_decide
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_payload.flags_request_omits_authorization_header
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_payload.token_in_flags_body_matches_init
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_payload.groups_round_trip
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_payload.groups_default_to_empty_object
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_payload.person_properties_distinct_id_auto_populated_when_caller_omits_it
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_payload.disable_geoip_false_propagates_as_geoip_disable_false
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_payload.disable_geoip_omitted_defaults_to_false
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_payload.flag_keys_to_evaluate_contains_only_requested_key
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_lifecycle.no_flags_request_on_init_alone
Expected 0 /flags requests, got 1
request_lifecycle.no_flags_request_on_normal_capture
Expected 0 /flags requests, got 1
request_lifecycle.two_flag_calls_produce_two_remote_requests
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_lifecycle.mock_response_value_is_returned_to_caller
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
side_effect_events.get_feature_flag_captures_feature_flag_called_event
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
dustinbyrne
left a comment
There was a problem hiding this comment.
Got through some of this but I have to step away. I'll circle back when I can if nobody else gets to it first!
| * [PostHogReplayBufferDelegate]. When [PostHogReplayBufferDelegate.isBuffering] | ||
| * is true, snapshots are routed to the buffer and `flush()` calls are suppressed. | ||
| */ | ||
| public class PostHogReplayQueue internal constructor( |
There was a problem hiding this comment.
Can this be internal? Does it need to be public?
There was a problem hiding this comment.
Fixed and made this internal. It ended up public because PostHogReplayIntegration is already a public class, and PostHogReplayQueue was used in a public method when implementing PostHogReplayBufferDelegate.
PostHogReplayIntegration should be internal as well though? I checked hybrid SDKs, and it seems that this class is not used there directly. So, unless I'm missing something (cc @marandaneto), I would also change replay integration to internal since I think we exposed it publicly accidentally
| if (bufferDelegate?.isBuffering == true) { | ||
| bufferQueue.add(event) | ||
| config.logger.log("Buffered replay event '${event.event}'. Buffer depth: ${bufferQueue.depth}") | ||
| bufferDelegate?.onReplayBufferSnapshot(this) | ||
| } else { | ||
| innerQueue.add(event) | ||
| } |
There was a problem hiding this comment.
This is a synchronous write to disk. Perhaps this queue should be constructed with an ExecutorService similar to PostHogQueue and serialize buffer writes through it to avoid blocking the calling thread?
There was a problem hiding this comment.
unless the caller is guaranteed to be within an ExecutorService already, then i'd add a comment to make that clear
There was a problem hiding this comment.
Updated PostHogReplayQueue to take the replay ExecutorService and serialize buffered disk writes through it, similar to PostHogQueue. The buffering state is also rechecked inside the executor before writing, so events won’t be incorrectly buffered if the minimum-duration threshold flips while the task is queued.
| // Reset minimum duration buffering state for the new session | ||
| resetBufferingState() |
There was a problem hiding this comment.
start is only called once globally afaik, so it seems like this call would be better off in onSessionIdChanged?
There was a problem hiding this comment.
Right, we were not resetting buffer onSessionIdChanged. We now track current session id and reset when the session actually changes
|
@turnipdabeets pls review! |
# Conflicts: # posthog-android/src/main/java/com/posthog/android/replay/PostHogReplayIntegration.kt # posthog-android/src/test/java/com/posthog/android/replay/PostHogReplayIntegrationTest.kt
turnipdabeets
left a comment
There was a problem hiding this comment.
LGTM, it might be worth adding a few more tests though. Seems like iOS has happy-path migration coverage (PostHogQueue target, file move, ordering, concurrent writes during migration) that this PR doesn't.
💡 Motivation and Context
Adds support for the minimumDurationMilliseconds remote config setting for session replay and follows the implementation as described in PostHog/posthog-ios#548
💚 How did you test it?
📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset file