mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-06-29 03:14:19 +00:00
Small cleanup of console logs
This commit is contained in:
parent
cb9e9048e7
commit
084ec337af
3 changed files with 16 additions and 8 deletions
|
@ -217,7 +217,7 @@ class TracingMiddleware:
|
||||||
|
|
||||||
async def __call__(self, scope, receive, send):
|
async def __call__(self, scope, receive, send):
|
||||||
path = scope["path"]
|
path = scope["path"]
|
||||||
await start_trace(path, {"location": "server"})
|
await start_trace(path, {"__location__": "server"})
|
||||||
try:
|
try:
|
||||||
return await self.app(scope, receive, send)
|
return await self.app(scope, receive, send)
|
||||||
finally:
|
finally:
|
||||||
|
|
|
@ -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"
|
"async_generator" if is_async_gen else "async" if is_async else "sync"
|
||||||
)
|
)
|
||||||
span_attributes = {
|
span_attributes = {
|
||||||
"class": class_name,
|
"__autotraced__": True,
|
||||||
"method": method_name,
|
"__class__": class_name,
|
||||||
"type": span_type,
|
"__method__": method_name,
|
||||||
"args": serialize_value(args),
|
"__type__": span_type,
|
||||||
|
"__args__": serialize_value(args),
|
||||||
}
|
}
|
||||||
|
|
||||||
return class_name, method_name, span_attributes
|
return class_name, method_name, span_attributes
|
||||||
|
@ -103,7 +104,7 @@ def trace_protocol(cls: Type[T]) -> Type[T]:
|
||||||
result = method(self, *args, **kwargs)
|
result = method(self, *args, **kwargs)
|
||||||
span.set_attribute("output", serialize_value(result))
|
span.set_attribute("output", serialize_value(result))
|
||||||
return result
|
return result
|
||||||
except Exception as e:
|
except Exception as _e:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
if is_async_gen:
|
if is_async_gen:
|
||||||
|
|
|
@ -29,6 +29,9 @@ class ConsoleSpanProcessor(SpanProcessor):
|
||||||
|
|
||||||
def on_start(self, span: ReadableSpan, parent_context=None) -> None:
|
def on_start(self, span: ReadableSpan, parent_context=None) -> None:
|
||||||
"""Called when a span starts."""
|
"""Called when a span starts."""
|
||||||
|
if span.attributes and span.attributes.get("__autotraced__"):
|
||||||
|
return
|
||||||
|
|
||||||
timestamp = datetime.utcfromtimestamp(span.start_time / 1e9).strftime(
|
timestamp = datetime.utcfromtimestamp(span.start_time / 1e9).strftime(
|
||||||
"%H:%M:%S.%f"
|
"%H:%M:%S.%f"
|
||||||
)[:-3]
|
)[:-3]
|
||||||
|
@ -41,6 +44,9 @@ class ConsoleSpanProcessor(SpanProcessor):
|
||||||
|
|
||||||
def on_end(self, span: ReadableSpan) -> None:
|
def on_end(self, span: ReadableSpan) -> None:
|
||||||
"""Called when a span ends."""
|
"""Called when a span ends."""
|
||||||
|
if span.attributes and span.attributes.get("__autotraced__"):
|
||||||
|
return
|
||||||
|
|
||||||
timestamp = datetime.utcfromtimestamp(span.end_time / 1e9).strftime(
|
timestamp = datetime.utcfromtimestamp(span.end_time / 1e9).strftime(
|
||||||
"%H:%M:%S.%f"
|
"%H:%M:%S.%f"
|
||||||
)[:-3]
|
)[:-3]
|
||||||
|
@ -71,8 +77,7 @@ class ConsoleSpanProcessor(SpanProcessor):
|
||||||
# Print attributes indented
|
# Print attributes indented
|
||||||
if span.attributes:
|
if span.attributes:
|
||||||
for key, value in span.attributes.items():
|
for key, value in span.attributes.items():
|
||||||
# Skip internal attributes; also rename these internal attributes to have underscores
|
if key.startswith("__"):
|
||||||
if key in ("class", "method", "type", "__root__", "__ttl__"):
|
|
||||||
continue
|
continue
|
||||||
print(f" {COLORS['dim']}{key}: {value}{COLORS['reset']}")
|
print(f" {COLORS['dim']}{key}: {value}{COLORS['reset']}")
|
||||||
|
|
||||||
|
@ -87,6 +92,8 @@ class ConsoleSpanProcessor(SpanProcessor):
|
||||||
)
|
)
|
||||||
if event.attributes:
|
if event.attributes:
|
||||||
for key, value in event.attributes.items():
|
for key, value in event.attributes.items():
|
||||||
|
if key.startswith("__"):
|
||||||
|
continue
|
||||||
print(f" {COLORS['dim']}{key}: {value}{COLORS['reset']}")
|
print(f" {COLORS['dim']}{key}: {value}{COLORS['reset']}")
|
||||||
|
|
||||||
def shutdown(self) -> None:
|
def shutdown(self) -> None:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue