Skip to content

feat: session replay minimum recording duration#482

Merged
ioannisj merged 21 commits intomainfrom
feat/min_session_duration
May 6, 2026
Merged

feat: session replay minimum recording duration#482
ioannisj merged 21 commits intomainfrom
feat/min_session_duration

Conversation

@ioannisj
Copy link
Copy Markdown
Contributor

@ioannisj ioannisj commented Apr 9, 2026

💡 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

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran pnpm changeset to generate a changeset file
  • Added the "release" label to the PR to indicate we're publishing new versions for the affected packages

@github-actions
Copy link
Copy Markdown
Contributor

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 stale label – otherwise this will be closed in another week.

@github-actions github-actions Bot added the stale label Apr 17, 2026
@ioannisj ioannisj removed the stale label Apr 21, 2026
@github-actions
Copy link
Copy Markdown
Contributor

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 stale label – otherwise this will be closed in another week.

@github-actions github-actions Bot added the stale label Apr 29, 2026
@ioannisj ioannisj removed the stale label Apr 29, 2026
# 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
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 29, 2026

posthog-android Compliance Report

Date: 2026-05-06 08:39:58 UTC
Duration: 2775ms

⚠️ Some Tests Failed

0/16 tests passed, 16 failed


Feature_Flags Tests

⚠️ 0/16 tests passed, 16 failed

View Details
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'

@ioannisj ioannisj marked this pull request as ready for review April 29, 2026 14:27
@ioannisj ioannisj requested a review from a team as a code owner April 29, 2026 14:27
@ioannisj ioannisj requested review from a team, TueHaulund, fasyy612, ksvat and nicowaltz and removed request for a team April 29, 2026 14:27
Copy link
Copy Markdown
Contributor

@dustinbyrne dustinbyrne left a comment

Choose a reason for hiding this comment

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

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(
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.

Can this be internal? Does it need to be public?

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.

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

Comment on lines +55 to +61
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)
}
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.

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

unless the caller is guaranteed to be within an ExecutorService already, then i'd add a comment to make that clear

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.

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.

Comment on lines +1627 to +1628
// Reset minimum duration buffering state for the new session
resetBufferingState()
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.

start is only called once globally afaik, so it seems like this call would be better off in onSessionIdChanged?

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.

Right, we were not resetting buffer onSessionIdChanged. We now track current session id and reset when the session actually changes

@dustinbyrne dustinbyrne requested a review from a team April 29, 2026 22:01
@marandaneto
Copy link
Copy Markdown
Member

@turnipdabeets pls review!

@marandaneto marandaneto requested a review from turnipdabeets May 5, 2026 09:19
ioannisj added 4 commits May 5, 2026 21:06
# Conflicts:
#	posthog-android/src/main/java/com/posthog/android/replay/PostHogReplayIntegration.kt
#	posthog-android/src/test/java/com/posthog/android/replay/PostHogReplayIntegrationTest.kt
Copy link
Copy Markdown
Contributor

@turnipdabeets turnipdabeets left a comment

Choose a reason for hiding this comment

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

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.

@ioannisj ioannisj merged commit 006f5d0 into main May 6, 2026
14 checks passed
@ioannisj ioannisj deleted the feat/min_session_duration branch May 6, 2026 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants