2525
2626EVENT_NAME = "FeatureEvaluation"
2727
28+ EVALUATION_EVENT_VERSION = "1.0.0"
29+
2830
2931def track_event (event_name : str , user : str , event_properties : Optional [Dict [str , Optional [str ]]] = None ) -> None :
3032 """
@@ -51,17 +53,49 @@ def publish_telemetry(evaluation_event: EvaluationEvent) -> None:
5153 """
5254 if not HAS_AZURE_MONITOR_EVENTS_EXTENSION :
5355 return
54- event = {}
55- if evaluation_event .feature :
56- event [FEATURE_NAME ] = evaluation_event .feature .name
56+ event : Dict [str , Optional [str ]] = {}
57+ if not evaluation_event .feature :
58+ return
59+ event [FEATURE_NAME ] = evaluation_event .feature .name
5760 event [ENABLED ] = str (evaluation_event .enabled )
61+ event ["Version" ] = EVALUATION_EVENT_VERSION
5862
63+ # VariantAllocationPercentage
5964 if evaluation_event .reason and evaluation_event .reason != VariantAssignmentReason .NONE :
6065 if evaluation_event .variant :
6166 event [VARIANT ] = evaluation_event .variant .name
6267 event [REASON ] = evaluation_event .reason .value
6368
64- if evaluation_event .feature and evaluation_event .feature .telemetry :
69+ if evaluation_event .reason == VariantAssignmentReason .DEFAULT_WHEN_ENABLED :
70+ allocation_percentage = 0
71+
72+ if evaluation_event .feature .allocation and evaluation_event .feature .allocation .percentile :
73+ for allocation in evaluation_event .feature .allocation .percentile :
74+ if (
75+ evaluation_event .variant
76+ and allocation .variant == evaluation_event .variant .name
77+ and allocation .percentile_to
78+ ):
79+ allocation_percentage += allocation .percentile_to - allocation .percentile_from
80+
81+ event ["VariantAssignmentPercentage" ] = str (100 - allocation_percentage )
82+ elif evaluation_event .reason == VariantAssignmentReason .PERCENTILE :
83+ if evaluation_event .feature .allocation and evaluation_event .feature .allocation .percentile :
84+ allocation_percentage = 0
85+ for allocation in evaluation_event .feature .allocation .percentile :
86+ if (
87+ evaluation_event .variant
88+ and allocation .variant == evaluation_event .variant .name
89+ and allocation .percentile_to
90+ ):
91+ allocation_percentage += allocation .percentile_to - allocation .percentile_from
92+ event ["VariantAssignmentPercentage" ] = str (allocation_percentage )
93+
94+ # DefaultWhenEnabled
95+ if evaluation_event .feature .allocation and evaluation_event .feature .allocation .default_when_enabled :
96+ event ["DefaultWhenEnabled" ] = evaluation_event .feature .allocation .default_when_enabled
97+
98+ if evaluation_event .feature .telemetry :
6599 for metadata_key , metadata_value in evaluation_event .feature .telemetry .metadata .items ():
66100 if metadata_key not in event :
67101 event [metadata_key ] = metadata_value
0 commit comments