Skip to content

Commit 14a2f80

Browse files
authored
feat(flags): Add more details such as version, id, and reason to $feature_flag_called events (#207)
* Flesh out Decide response types * Ensure we normalize get_decide In a back compat manner. * Populate feature_flags_by_key when setting feature_flags Since `self.feature_flags_by_key` is derived from `self.feature_flags`, and we often set the latter in unit tests, but forget to set the former, our tests can be wonky. This ensures that when we set `self.feature_flags`, we always set `self. feature_flags_by_key` * Annotate types * Lookup local flag by key Fixes #121 * Refactor local flag evaluation into its own method * Include extra details in `$feature_flag_called` events * Fix up type annotations, tests, and formatting * Update lib to decide v4 * Bump version and add changelog
1 parent 2779ad1 commit 14a2f80

12 files changed

+850
-126
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 3.22.0 – 2025-03-26
2+
3+
1. Add more information to `$feature_flag_called` events.
4+
2. Support for the `/decide?v=3` endpoint which contains more information about feature flags.
5+
16
## 3.21.0 – 2025-03-17
27

38
1. Support serializing dataclasses.
@@ -194,6 +199,7 @@
194199

195200
1. Update type hints for module variables to work with newer versions of mypy
196201

202+
197203
## 3.3.3 - 2024-01-26
198204

199205
1. Remove new relative date operators, combine into regular date operators

posthog/__init__.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from posthog.client import Client
66
from posthog.exception_capture import Integrations # noqa: F401
7+
from posthog.types import FeatureFlag, FlagsAndPayloads
78
from posthog.version import VERSION
89

910
__version__ = VERSION
@@ -403,7 +404,7 @@ def get_feature_flag(
403404
only_evaluate_locally=False, # type: bool
404405
send_feature_flag_events=True, # type: bool
405406
disable_geoip=None, # type: Optional[bool]
406-
):
407+
) -> Optional[FeatureFlag]:
407408
"""
408409
Get feature flag variant for users. Used with experiments.
409410
Example:
@@ -446,7 +447,7 @@ def get_all_flags(
446447
group_properties={}, # type: dict
447448
only_evaluate_locally=False, # type: bool
448449
disable_geoip=None, # type: Optional[bool]
449-
):
450+
) -> Optional[dict[str, FeatureFlag]]:
450451
"""
451452
Get all flags for a given user.
452453
Example:
@@ -477,7 +478,7 @@ def get_feature_flag_payload(
477478
only_evaluate_locally=False,
478479
send_feature_flag_events=True,
479480
disable_geoip=None, # type: Optional[bool]
480-
):
481+
) -> Optional[str]:
481482
return _proxy(
482483
"get_feature_flag_payload",
483484
key=key,
@@ -519,7 +520,7 @@ def get_all_flags_and_payloads(
519520
group_properties={},
520521
only_evaluate_locally=False,
521522
disable_geoip=None, # type: Optional[bool]
522-
):
523+
) -> FlagsAndPayloads:
523524
return _proxy(
524525
"get_all_flags_and_payloads",
525526
distinct_id=distinct_id,

0 commit comments

Comments
 (0)