Small cleanup of console logs

This commit is contained in:
Ashwin Bharambe 2024-12-06 09:35:33 -08:00
parent cb9e9048e7
commit 084ec337af
3 changed files with 16 additions and 8 deletions

View file

@ -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:

View file

@ -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:

View file

@ -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: