Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
9 changes: 9 additions & 0 deletions posthog/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,15 @@ def get_feature_flag_payload(
)


def get_decrypted_feature_flag_payload(
flag_id,
):
return _proxy(
"get_decrypted_feature_flag_payload",
flag_id=flag_id,
)


def get_all_flags_and_payloads(
distinct_id,
groups={},
Expand Down
29 changes: 28 additions & 1 deletion posthog/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from posthog.exception_utils import exc_info_from_error, exceptions_from_error_tuple, handle_in_app
from posthog.feature_flags import InconclusiveMatchError, match_feature_flag_properties
from posthog.poller import Poller
from posthog.request import DEFAULT_HOST, APIError, batch_post, decide, determine_server_host, get
from posthog.request import DEFAULT_HOST, APIError, batch_post, decide, remote_config, determine_server_host, get
from posthog.utils import SizeLimitedDict, clean, guess_timezone, remove_trailing_slash
from posthog.version import VERSION

Expand Down Expand Up @@ -205,6 +205,16 @@ def get_decide(self, distinct_id, groups=None, person_properties=None, group_pro
resp_data = decide(self.api_key, self.host, timeout=self.feature_flags_request_timeout_seconds, **request_data)

return resp_data

def get_remote_config_payload(self, flag_id):
resp_data = remote_config(
self.personal_api_key,
self.host,
flag_id,
timeout=self.feature_flags_request_timeout_seconds,
)

return resp_data

def capture(
self,
Expand Down Expand Up @@ -809,6 +819,23 @@ def get_feature_flag_payload(
self.distinct_ids_feature_flags_reported[distinct_id].add(feature_flag_reported_key)

return payload

def get_decrypted_feature_flag_payload(self, flag_id):
if self.disabled:
return None

if self.personal_api_key is None:
self.log.warning(
"[FEATURE FLAGS] You have to specify a personal_api_key to fetch decrypted feature flag payloads."
)
return None

try:
return self.get_remote_config_payload(flag_id)
except Exception as e:
self.log.exception(
f"[FEATURE FLAGS] Unable to get decrypted feature flag payload: {e}"
)

def _compute_payload_locally(self, key, match_value):
payload = None
Expand Down
3 changes: 3 additions & 0 deletions posthog/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ def decide(api_key: str, host: Optional[str] = None, gzip: bool = False, timeout
res = post(api_key, host, "/decide/?v=3", gzip, timeout, **kwargs)
return _process_response(res, success_message="Feature flags decided successfully")

def remote_config(api_key: str, host: Optional[str] = None, flag_id: str = "", timeout: int = 15) -> Any:
res = get(api_key, host, f"/api/projects/@current/feature_flags/{flag_id}/remote_config/", timeout)
return _process_response(res, success_message="Feature flags decided successfully")
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Success message should be specific to remote config, e.g. 'Remote config fetched successfully' instead of reusing 'Feature flags decided successfully'

Copy link
Contributor

Choose a reason for hiding this comment

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

i agree with greptile here


def batch_post(
api_key: str, host: Optional[str] = None, gzip: bool = False, timeout: int = 15, **kwargs
Expand Down
Loading