Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(replay): let the direct blocks flag target a deployment (#129392)

Tue Haulund6b8138219c9f
diff --git a/posthog/session_recordings/recordings/replay_blocks_jwt.py b/posthog/session_recordings/recordings/replay_blocks_jwt.py
index 3c176d7bf9f5..81facc2bf957 100644
--- a/posthog/session_recordings/recordings/replay_blocks_jwt.py
+++ b/posthog/session_recordings/recordings/replay_blocks_jwt.py
@@ -2,6 +2,8 @@ import time
from datetime import UTC, datetime, timedelta
from typing import Literal
+from django.conf import settings
+
import posthoganalytics
from posthog.dataclasses import frozen
@@ -24,9 +26,16 @@ REPLAY_DIRECT_BLOCKS_FLAG = "replay-direct-blocks"
def is_direct_blocks_enabled(team_id: int) -> bool:
"""Gate for giving the player block urls. The player polls the listing for a live recording, so the check sends
no flag-called event."""
+ # All deployments share one flag project and team ids repeat across them, so conditions target a deployment by this.
+ person_properties = {"cloud_deployment": settings.CLOUD_DEPLOYMENT} if settings.CLOUD_DEPLOYMENT else {}
try:
return bool(
- posthoganalytics.feature_enabled(REPLAY_DIRECT_BLOCKS_FLAG, str(team_id), send_feature_flag_events=False)
+ posthoganalytics.feature_enabled(
+ REPLAY_DIRECT_BLOCKS_FLAG,
+ str(team_id),
+ person_properties=person_properties,
+ send_feature_flag_events=False,
+ )
)
except Exception:
return False
diff --git a/posthog/session_recordings/test/test_session_recording_snapshots_api_blob_v2.py b/posthog/session_recordings/test/test_session_recording_snapshots_api_blob_v2.py
index 15a4aab782e3..ea0aebab5807 100644
--- a/posthog/session_recordings/test/test_session_recording_snapshots_api_blob_v2.py
+++ b/posthog/session_recordings/test/test_session_recording_snapshots_api_blob_v2.py
@@ -158,7 +158,11 @@ class TestSessionRecordingSnapshotsAPI(APIBaseTest, ClickhouseTestMixin, QueryMa
("share_link", "share_link", True, True, False),
]
)
- @override_settings(REPLAY_PROXY_JWT_SECRET="replay-proxy-key", RECORDING_API_BLOCKS_JWT_SECRET="replay-blocks-key")
+ @override_settings(
+ REPLAY_PROXY_JWT_SECRET="replay-proxy-key",
+ RECORDING_API_BLOCKS_JWT_SECRET="replay-blocks-key",
+ CLOUD_DEPLOYMENT="DEV",
+ )
@patch(
"posthog.session_recordings.queries.session_replay_events.SessionReplayEvents.exists",
return_value=True,
@@ -257,6 +261,8 @@ class TestSessionRecordingSnapshotsAPI(APIBaseTest, ClickhouseTestMixin, QueryMa
else:
assert urls == [None, None]
assert body["block_token"] is None
+ for flag_call in mock_feature_enabled.call_args_list:
+ assert flag_call.kwargs["person_properties"] == {"cloud_deployment": "DEV"}
@parameterized.expand(
[