Skip to content

Commit 889a2ec

Browse files
committed
Update _send_telemetry.py
1 parent 91ac325 commit 889a2ec

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

featuremanagement/azuremonitor/_send_telemetry.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
EVALUATION_EVENT_VERSION = "1.1.0"
3838

39-
4039
def track_event(event_name: str, user: str, event_properties: Optional[Dict[str, Optional[str]]] = None) -> None:
4140
"""
4241
Tracks an event with the specified name and properties.
@@ -117,22 +116,25 @@ def attach_targeting_info(targeting_id: str) -> None:
117116
118117
:param str targeting_id: The targeting ID to attach.
119118
"""
119+
if not HAS_AZURE_MONITOR_EVENTS_EXTENSION:
120+
return
120121
context.attach(baggage.set_baggage(MICROSOFT_TARGETING_ID, targeting_id))
121122
trace.get_current_span().set_attribute(TARGETING_ID, targeting_id)
122123

123124

124-
class TargetingSpanProcessor(SpanProcessor):
125-
"""
126-
A custom SpanProcessor that attaches the targeting ID to the span and baggage when a new span is started.
127-
"""
128-
129-
def on_start(self, span: Span, parent_context: Optional[Context] = None) -> None:
125+
if HAS_AZURE_MONITOR_EVENTS_EXTENSION:
126+
class TargetingSpanProcessor(SpanProcessor):
130127
"""
131-
Attaches the targeting ID to the span and baggage when a new span is started.
132-
133-
:param Span span: The span that was started.
134-
:param parent_context: The parent context of the span.
128+
A custom SpanProcessor that attaches the targeting ID to the span and baggage when a new span is started.
135129
"""
136-
target_baggage = baggage.get_baggage(MICROSOFT_TARGETING_ID, parent_context)
137-
if target_baggage is not None and isinstance(target_baggage, str):
138-
span.set_attribute(TARGETING_ID, target_baggage)
130+
131+
def on_start(self, span: Span, parent_context: Optional[Context] = None) -> None:
132+
"""
133+
Attaches the targeting ID to the span and baggage when a new span is started.
134+
135+
:param Span span: The span that was started.
136+
:param parent_context: The parent context of the span.
137+
"""
138+
target_baggage = baggage.get_baggage(MICROSOFT_TARGETING_ID, parent_context)
139+
if target_baggage is not None and isinstance(target_baggage, str):
140+
span.set_attribute(TARGETING_ID, target_baggage)

0 commit comments

Comments
 (0)