|
36 | 36 |
|
37 | 37 | EVALUATION_EVENT_VERSION = "1.1.0" |
38 | 38 |
|
39 | | - |
40 | 39 | def track_event(event_name: str, user: str, event_properties: Optional[Dict[str, Optional[str]]] = None) -> None: |
41 | 40 | """ |
42 | 41 | Tracks an event with the specified name and properties. |
@@ -117,22 +116,25 @@ def attach_targeting_info(targeting_id: str) -> None: |
117 | 116 |
|
118 | 117 | :param str targeting_id: The targeting ID to attach. |
119 | 118 | """ |
| 119 | + if not HAS_AZURE_MONITOR_EVENTS_EXTENSION: |
| 120 | + return |
120 | 121 | context.attach(baggage.set_baggage(MICROSOFT_TARGETING_ID, targeting_id)) |
121 | 122 | trace.get_current_span().set_attribute(TARGETING_ID, targeting_id) |
122 | 123 |
|
123 | 124 |
|
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): |
130 | 127 | """ |
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. |
135 | 129 | """ |
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