diff --git a/llama_stack/distribution/server/server.py b/llama_stack/distribution/server/server.py index 4ae1854df..43e9c0706 100644 --- a/llama_stack/distribution/server/server.py +++ b/llama_stack/distribution/server/server.py @@ -217,7 +217,7 @@ class TracingMiddleware: async def __call__(self, scope, receive, send): path = scope["path"] - await start_trace(path, {"location": "server"}) + await start_trace(path, {"__location__": "server"}) try: return await self.app(scope, receive, send) finally: diff --git a/llama_stack/distribution/tracing.py b/llama_stack/distribution/tracing.py index ff4fe2483..3fcce08e9 100644 --- a/llama_stack/distribution/tracing.py +++ b/llama_stack/distribution/tracing.py @@ -52,10 +52,11 @@ def trace_protocol(cls: Type[T]) -> Type[T]: "async_generator" if is_async_gen else "async" if is_async else "sync" ) span_attributes = { - "class": class_name, - "method": method_name, - "type": span_type, - "args": serialize_value(args), + "__autotraced__": True, + "__class__": class_name, + "__method__": method_name, + "__type__": span_type, + "__args__": serialize_value(args), } return class_name, method_name, span_attributes @@ -103,7 +104,7 @@ def trace_protocol(cls: Type[T]) -> Type[T]: result = method(self, *args, **kwargs) span.set_attribute("output", serialize_value(result)) return result - except Exception as e: + except Exception as _e: raise if is_async_gen: diff --git a/llama_stack/providers/inline/telemetry/meta_reference/console_span_processor.py b/llama_stack/providers/inline/telemetry/meta_reference/console_span_processor.py index 0a2989bd3..6c4d7e8d4 100644 --- a/llama_stack/providers/inline/telemetry/meta_reference/console_span_processor.py +++ b/llama_stack/providers/inline/telemetry/meta_reference/console_span_processor.py @@ -29,6 +29,9 @@ class ConsoleSpanProcessor(SpanProcessor): def on_start(self, span: ReadableSpan, parent_context=None) -> None: """Called when a span starts.""" + if span.attributes and span.attributes.get("__autotraced__"): + return + timestamp = datetime.utcfromtimestamp(span.start_time / 1e9).strftime( "%H:%M:%S.%f" )[:-3] @@ -41,6 +44,9 @@ class ConsoleSpanProcessor(SpanProcessor): def on_end(self, span: ReadableSpan) -> None: """Called when a span ends.""" + if span.attributes and span.attributes.get("__autotraced__"): + return + timestamp = datetime.utcfromtimestamp(span.end_time / 1e9).strftime( "%H:%M:%S.%f" )[:-3] @@ -71,8 +77,7 @@ class ConsoleSpanProcessor(SpanProcessor): # Print attributes indented if span.attributes: for key, value in span.attributes.items(): - # Skip internal attributes; also rename these internal attributes to have underscores - if key in ("class", "method", "type", "__root__", "__ttl__"): + if key.startswith("__"): continue print(f" {COLORS['dim']}{key}: {value}{COLORS['reset']}") @@ -87,6 +92,8 @@ class ConsoleSpanProcessor(SpanProcessor): ) if event.attributes: for key, value in event.attributes.items(): + if key.startswith("__"): + continue print(f" {COLORS['dim']}{key}: {value}{COLORS['reset']}") def shutdown(self) -> None: