77
88import json
99import logging
10+ from collections .abc import Mapping
1011from typing import Any , Optional
1112
1213from opentelemetry .context import Context
13- from opentelemetry .sdk .trace import ReadableSpan , Span , SpanProcessor
14+ from opentelemetry .sdk .trace import Span , SpanProcessor
15+ from opentelemetry .util .types import AttributeValue
1416
1517logger = logging .getLogger (__name__ )
1618
@@ -25,14 +27,14 @@ def on_start(self, span: Span, parent_context: Optional[Context] = None) -> None
2527 """Called when span starts - no action needed."""
2628 pass
2729
28- def on_end (self , span : ReadableSpan ) -> None :
30+ def on_end (self , span : Span ) -> None :
2931 """Normalize tool call attributes before span is consumed by exporters/terminal."""
3032 if not span ._attributes :
3133 return
3234
3335 try :
3436 # Get the mutable internal attributes dict
35- attrs : dict = span ._attributes # type: ignore[attr-defined]
37+ attrs : Mapping [ str , AttributeValue ] = span ._attributes
3638
3739 if attrs .get ("openinference.span.kind" , None ) == "TOOL" :
3840 # Normalize tool call attributes
@@ -46,7 +48,7 @@ def on_end(self, span: ReadableSpan) -> None:
4648 if logger .isEnabledFor (logging .DEBUG ):
4749 logger .debug (
4850 f"Normalized { key } in span '{ span .name } ': "
49- f"{ original [:50 ]} ... → { normalized [:50 ]} ..."
51+ f"{ str ( original ) [:50 ]} ... → { str ( normalized ) [:50 ]} ..."
5052 )
5153
5254 except Exception as e :
0 commit comments