Skip to content
Draft
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
5 changes: 5 additions & 0 deletions .sampo/changesets/release-id-on-minimized-flag-called.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
posthog: patch
---

A minimized `$feature_flag_called` event keeps `$release_id`. The release id the SDK reads once from `POSTHOG_RELEASE_ID` was stamped on the event and then stripped by the minimal-event allowlist, so flag calls could not be broken down by release. It is static, low-cardinality runtime identity, like the `$lib` and `$os` values the allowlist already keeps.
2 changes: 2 additions & 0 deletions posthog/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,8 @@ def wrapper(self, *args, **kwargs):
"$os_distro",
"$python_runtime",
"$python_version",
# Deploy identity: one value per process, set once at construction.
"$release_id",
}
)

Expand Down
14 changes: 14 additions & 0 deletions posthog/test/test_feature_flag_called_minimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
to the full legacy shape.
"""

import os
import unittest
from unittest import mock

from parameterized import parameterized

from posthog.capture_event import _to_v1_event
from posthog.client import _MINIMAL_FLAG_CALLED_EVENT_PROPERTIES, Client
from posthog.release_id import RELEASE_ID_ENV_VAR
from posthog.request import GetResponse
from posthog.test.capture_helpers import record_sync_capture_sends
from posthog.test.test_utils import FAKE_TEST_API_KEY
Expand Down Expand Up @@ -139,6 +141,18 @@ def test_gated_non_experiment_flag_sends_exactly_the_allowlist(self, patch_flags
self.assertEqual(properties["$feature_flag_request_id"], "req-1")
self.assertEqual(properties["$feature_flag_evaluated_at"], 1640995200000)

@mock.patch("posthog.client.flags")
def test_gated_non_experiment_flag_keeps_the_release_id(self, patch_flags):
patch_flags.return_value = _flags_response(has_experiment=False, gate=True)
with mock.patch.dict(os.environ, {RELEASE_ID_ENV_VAR: "rel-abc123"}):
client, captured = self._make_client()

client.get_feature_flag_result("person-flag", "some-distinct-id")

properties = self._flag_called_properties(captured)
self.assertEqual(properties["$release_id"], "rel-abc123")
self.assertLessEqual(set(properties), _MINIMAL_FLAG_CALLED_EVENT_PROPERTIES)

@mock.patch("posthog.client.flags")
def test_gated_non_experiment_flag_with_groups_keeps_group_context(
self, patch_flags
Expand Down
20 changes: 18 additions & 2 deletions posthog/test/test_release_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,25 @@ def test_release_id_is_read_once_at_client_init(self) -> None:
client.capture("python test event", distinct_id="user-1")
self.assertEqual(events[0]["properties"]["$release_id"], "at-init")

def test_minimal_flag_called_events_keep_their_strict_allowlist(self) -> None:
def test_minimal_flag_called_events_keep_the_release_id(self) -> None:
client, events = self._client("0198c1a2-release")
client._enqueue(
{
"event": "$feature_flag_called",
"distinct_id": "user-1",
"timestamp": None,
"properties": {"$feature_flag": "my-flag", "dropped": "value"},
},
None,
property_allowlist=_MINIMAL_FLAG_CALLED_EVENT_PROPERTIES,
)
properties = events[0]["properties"]
self.assertEqual(properties["$feature_flag"], "my-flag")
self.assertEqual(properties["$release_id"], "0198c1a2-release")
self.assertNotIn("dropped", properties)

def test_minimal_flag_called_events_omit_an_unset_release_id(self) -> None:
client, events = self._client(None)
client._enqueue(
{
"event": "$feature_flag_called",
Expand All @@ -144,7 +161,6 @@ def test_minimal_flag_called_events_keep_their_strict_allowlist(self) -> None:
None,
property_allowlist=_MINIMAL_FLAG_CALLED_EVENT_PROPERTIES,
)
self.assertEqual(events[0]["properties"]["$feature_flag"], "my-flag")
self.assertNotIn("$release_id", events[0]["properties"])


Expand Down
Loading