2525VARIANT = "Variant"
2626REASON = "VariantAssignmentReason"
2727
28- DefaultWhenEnabled = "DefaultWhenEnabled"
28+ DEFAULT_WHEN_ENABLED = "DefaultWhenEnabled"
2929VERSION = "Version"
3030VARIANT_ASSIGNMENT_PERCENTAGE = "VariantAssignmentPercentage"
31- Microsoft_TargetingId = "Microsoft.TargetingId"
31+ MICROSOFT_TARGETING_ID = "Microsoft.TargetingId"
3232SPAN = "Span"
3333
3434EVENT_NAME = "FeatureEvaluation"
@@ -100,7 +100,7 @@ def publish_telemetry(evaluation_event: EvaluationEvent) -> None:
100100
101101 # DefaultWhenEnabled
102102 if feature .allocation and feature .allocation .default_when_enabled :
103- event [DefaultWhenEnabled ] = feature .allocation .default_when_enabled
103+ event [DEFAULT_WHEN_ENABLED ] = feature .allocation .default_when_enabled
104104
105105 if feature .telemetry :
106106 for metadata_key , metadata_value in feature .telemetry .metadata .items ():
@@ -110,10 +110,26 @@ def publish_telemetry(evaluation_event: EvaluationEvent) -> None:
110110 track_event (EVENT_NAME , evaluation_event .user , event_properties = event )
111111
112112def attach_targeting_info (targeting_id : str ):
113- context .attach (baggage .set_baggage (Microsoft_TargetingId , targeting_id ))
113+ """
114+ Attaches the targeting ID to the current span and baggage.
115+
116+ :param str targeting_id: The targeting ID to attach.
117+ """
118+ context .attach (baggage .set_baggage (MICROSOFT_TARGETING_ID , targeting_id ))
114119 trace .get_current_span ().set_attribute (TARGETING_ID , targeting_id )
115120
121+ """
122+ This class is a custom SpanProcessor that attaches the targeting ID to the span and baggage when a new span is started.
123+ """
116124class TargetingSpanProcessor (SpanProcessor ):
125+
117126 def on_start (self , span : Span , parent_context = None ):
118- if (baggage .get_baggage (Microsoft_TargetingId , parent_context ) != None ):
119- span .set_attribute (TARGETING_ID , baggage .get_baggage (Microsoft_TargetingId , parent_context ))
127+ """
128+ Attaches the targeting ID to the span and baggage when a new span is started.
129+
130+ :param Span span: The span that was started.
131+ :param parent_context: The parent context of the span.
132+ """
133+ target_baggage = baggage .get_baggage (MICROSOFT_TARGETING_ID , parent_context )
134+ if (target_baggage != None ):
135+ span .set_attribute (TARGETING_ID , target_baggage )
0 commit comments