Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/agents/tracing/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
from .traces import NoOpTrace, Trace, TraceImpl


def _safe_debug(message: str) -> None:
"""Best-effort debug logging that tolerates closed streams during shutdown."""
try:
logger.debug(message)
except Exception:
# Avoid noisy shutdown errors when the underlying stream is already closed.
return


class SynchronousMultiTracingProcessor(TracingProcessor):
"""
Forwards all calls to a list of TracingProcessors, in order of registration.
Expand Down Expand Up @@ -83,7 +92,7 @@ def shutdown(self) -> None:
Called when the application stops.
"""
for processor in self._processors:
logger.debug(f"Shutting down trace processor {processor}")
_safe_debug(f"Shutting down trace processor {processor}")
try:
processor.shutdown()
except Exception as e:
Expand Down Expand Up @@ -306,7 +315,7 @@ def shutdown(self) -> None:
return

try:
logger.debug("Shutting down trace provider")
_safe_debug("Shutting down trace provider")
self._multi_processor.shutdown()
except Exception as e:
logger.error(f"Error shutting down trace provider: {e}")