33import os
44import sys
55from datetime import datetime , timedelta
6- from typing import Any , Callable , Dict , Optional , Union
6+ from typing import Any , Dict , Optional , Union
77from typing_extensions import Unpack
88from uuid import uuid4
99
@@ -1381,6 +1381,7 @@ def _get_feature_flag_result(
13811381 flag_result = None
13821382 flag_details = None
13831383 request_id = None
1384+ evaluated_at = None
13841385
13851386 flag_value = self ._locally_evaluate_flag (
13861387 key , distinct_id , groups , person_properties , group_properties
@@ -1405,13 +1406,15 @@ def _get_feature_flag_result(
14051406 )
14061407 elif not only_evaluate_locally :
14071408 try :
1408- flag_details , request_id = self ._get_feature_flag_details_from_server (
1409- key ,
1410- distinct_id ,
1411- groups ,
1412- person_properties ,
1413- group_properties ,
1414- disable_geoip ,
1409+ flag_details , request_id , evaluated_at = (
1410+ self ._get_feature_flag_details_from_server (
1411+ key ,
1412+ distinct_id ,
1413+ groups ,
1414+ person_properties ,
1415+ group_properties ,
1416+ disable_geoip ,
1417+ )
14151418 )
14161419 flag_result = FeatureFlagResult .from_flag_details (
14171420 flag_details , override_match_value
@@ -1450,6 +1453,7 @@ def _get_feature_flag_result(
14501453 groups ,
14511454 disable_geoip ,
14521455 request_id ,
1456+ evaluated_at ,
14531457 flag_details ,
14541458 )
14551459
@@ -1653,9 +1657,9 @@ def _get_feature_flag_details_from_server(
16531657 person_properties : dict [str , str ],
16541658 group_properties : dict [str , str ],
16551659 disable_geoip : Optional [bool ],
1656- ) -> tuple [Optional [FeatureFlag ], Optional [str ]]:
1660+ ) -> tuple [Optional [FeatureFlag ], Optional [str ], Optional [ int ] ]:
16571661 """
1658- Calls /flags and returns the flag details and request id
1662+ Calls /flags and returns the flag details, request id, and evaluated at timestamp
16591663 """
16601664 resp_data = self .get_flags_decision (
16611665 distinct_id ,
@@ -1666,9 +1670,10 @@ def _get_feature_flag_details_from_server(
16661670 flag_keys_to_evaluate = [key ],
16671671 )
16681672 request_id = resp_data .get ("requestId" )
1673+ evaluated_at = resp_data .get ("evaluatedAt" )
16691674 flags = resp_data .get ("flags" )
16701675 flag_details = flags .get (key ) if flags else None
1671- return flag_details , request_id
1676+ return flag_details , request_id , evaluated_at
16721677
16731678 def _capture_feature_flag_called (
16741679 self ,
@@ -1680,6 +1685,7 @@ def _capture_feature_flag_called(
16801685 groups : Dict [str , str ],
16811686 disable_geoip : Optional [bool ],
16821687 request_id : Optional [str ],
1688+ evaluated_at : Optional [int ],
16831689 flag_details : Optional [FeatureFlag ],
16841690 ):
16851691 feature_flag_reported_key = (
@@ -1703,6 +1709,8 @@ def _capture_feature_flag_called(
17031709
17041710 if request_id :
17051711 properties ["$feature_flag_request_id" ] = request_id
1712+ if evaluated_at :
1713+ properties ["$feature_flag_evaluated_at" ] = evaluated_at
17061714 if isinstance (flag_details , FeatureFlag ):
17071715 if flag_details .reason and flag_details .reason .description :
17081716 properties ["$feature_flag_reason" ] = flag_details .reason .description
0 commit comments