@@ -1419,6 +1419,7 @@ def _get_feature_flag_result(
14191419 flag_result = None
14201420 flag_details = None
14211421 request_id = None
1422+ evaluated_at = None
14221423
14231424 flag_value = self ._locally_evaluate_flag (
14241425 key , distinct_id , groups , person_properties , group_properties
@@ -1443,13 +1444,15 @@ def _get_feature_flag_result(
14431444 )
14441445 elif not only_evaluate_locally :
14451446 try :
1446- flag_details , request_id = self ._get_feature_flag_details_from_server (
1447- key ,
1448- distinct_id ,
1449- groups ,
1450- person_properties ,
1451- group_properties ,
1452- disable_geoip ,
1447+ flag_details , request_id , evaluated_at = (
1448+ self ._get_feature_flag_details_from_server (
1449+ key ,
1450+ distinct_id ,
1451+ groups ,
1452+ person_properties ,
1453+ group_properties ,
1454+ disable_geoip ,
1455+ )
14531456 )
14541457 flag_result = FeatureFlagResult .from_flag_details (
14551458 flag_details , override_match_value
@@ -1488,6 +1491,7 @@ def _get_feature_flag_result(
14881491 groups ,
14891492 disable_geoip ,
14901493 request_id ,
1494+ evaluated_at ,
14911495 flag_details ,
14921496 )
14931497
@@ -1691,9 +1695,9 @@ def _get_feature_flag_details_from_server(
16911695 person_properties : dict [str , str ],
16921696 group_properties : dict [str , str ],
16931697 disable_geoip : Optional [bool ],
1694- ) -> tuple [Optional [FeatureFlag ], Optional [str ]]:
1698+ ) -> tuple [Optional [FeatureFlag ], Optional [str ], Optional [ int ] ]:
16951699 """
1696- Calls /flags and returns the flag details and request id
1700+ Calls /flags and returns the flag details, request id, and evaluated at timestamp
16971701 """
16981702 resp_data = self .get_flags_decision (
16991703 distinct_id ,
@@ -1704,9 +1708,10 @@ def _get_feature_flag_details_from_server(
17041708 flag_keys_to_evaluate = [key ],
17051709 )
17061710 request_id = resp_data .get ("requestId" )
1711+ evaluated_at = resp_data .get ("evaluatedAt" )
17071712 flags = resp_data .get ("flags" )
17081713 flag_details = flags .get (key ) if flags else None
1709- return flag_details , request_id
1714+ return flag_details , request_id , evaluated_at
17101715
17111716 def _capture_feature_flag_called (
17121717 self ,
@@ -1718,6 +1723,7 @@ def _capture_feature_flag_called(
17181723 groups : Dict [str , str ],
17191724 disable_geoip : Optional [bool ],
17201725 request_id : Optional [str ],
1726+ evaluated_at : Optional [int ],
17211727 flag_details : Optional [FeatureFlag ],
17221728 ):
17231729 feature_flag_reported_key = (
@@ -1741,6 +1747,8 @@ def _capture_feature_flag_called(
17411747
17421748 if request_id :
17431749 properties ["$feature_flag_request_id" ] = request_id
1750+ if evaluated_at :
1751+ properties ["$feature_flag_evaluated_at" ] = evaluated_at
17441752 if isinstance (flag_details , FeatureFlag ):
17451753 if flag_details .reason and flag_details .reason .description :
17461754 properties ["$feature_flag_reason" ] = flag_details .reason .description
0 commit comments