|
9 | 9 | from threading import Lock |
10 | 10 | from typing import TYPE_CHECKING, Any |
11 | 11 |
|
12 | | -from opentelemetry import baggage, context, trace |
| 12 | +from opentelemetry import context, trace |
13 | 13 | from opentelemetry.trace import ( |
14 | 14 | Span, |
15 | 15 | SpanKind, |
@@ -126,7 +126,6 @@ def __init__( |
126 | 126 | self._error_type: str | None = None |
127 | 127 | self._exception: Exception | None = None |
128 | 128 | self._context_token = None |
129 | | - self._baggage_tokens: list[object] = [] |
130 | 129 |
|
131 | 130 | if self._is_telemetry_enabled(): |
132 | 131 | tracer = self._get_tracer() |
@@ -242,29 +241,6 @@ def set_tag_maybe(self, name: str, value: Any) -> None: |
242 | 241 | if value is not None and self._span and self._is_telemetry_enabled(): |
243 | 242 | self._span.set_attribute(name, value) |
244 | 243 |
|
245 | | - def add_baggage(self, key: str, value: str) -> None: |
246 | | - """Add baggage to the current context. |
247 | | -
|
248 | | - .. warning:: |
249 | | - This method attaches a new context that cannot be detached. Prefer using |
250 | | - :class:`~microsoft_agents_a365.observability.core.middleware.baggage_builder.BaggageBuilder` |
251 | | - with its context-manager API (``with builder.build(): ...``) which properly |
252 | | - restores the previous context on exit. |
253 | | -
|
254 | | - Args: |
255 | | - key: The baggage key |
256 | | - value: The baggage value |
257 | | - """ |
258 | | - # Set baggage in the current context |
259 | | - if self._is_telemetry_enabled(): |
260 | | - # Set baggage on the current context |
261 | | - # This will be inherited by child spans created within this context |
262 | | - baggage_context = baggage.set_baggage(key, value) |
263 | | - # The context needs to be made current for child spans to inherit the baggage |
264 | | - token = context.attach(baggage_context) |
265 | | - # Store the token so it can be detached when the scope ends |
266 | | - self._baggage_tokens.append(token) |
267 | | - |
268 | 244 | def record_attributes(self, attributes: dict[str, Any] | list[tuple[str, Any]]) -> None: |
269 | 245 | """Record multiple attribute key/value pairs for telemetry tracking. |
270 | 246 |
|
@@ -303,11 +279,6 @@ def _end(self) -> None: |
303 | 279 | span_id = f"{self._span.context.span_id:016x}" if self._span.context else "unknown" |
304 | 280 | logger.info(f"Span ended: '{self._span.name}' ({span_id})") |
305 | 281 |
|
306 | | - # Detach any baggage tokens in reverse order |
307 | | - for token in reversed(self._baggage_tokens): |
308 | | - context.detach(token) |
309 | | - self._baggage_tokens.clear() |
310 | | - |
311 | 282 | # Convert custom end time to OTel-compatible format (nanoseconds since epoch) |
312 | 283 | otel_end_time = self._datetime_to_ns(self._custom_end_time) |
313 | 284 | if otel_end_time is not None: |
|
0 commit comments