fix: update .gitignore to include logs directory and remove outdated waterfall.log

refactor: change trace span to async context manager in knowledge_base_search
refactor: enhance _run_sync_span for better trace handling and cleanup
This commit is contained in:
2026-09-27 17:04:41 +05:00
parent 59bffbed1a
commit 86a79b971e
5 changed files with 17 additions and 61 deletions
+14 -2
View File
@@ -106,12 +106,20 @@ async def time_span(span_name: str, **attributes: Any):
def _run_sync_span(span_name: str, func: Callable, *args: Any, **kwargs: Any) -> Any:
"""Synchronous span helper for trace execution."""
trace_id = _current_trace_id.get() or f"tr-{uuid.uuid4().hex[:8]}"
trace_id = _current_trace_id.get()
is_root = trace_id is None
if is_root:
trace_id = f"tr-{uuid.uuid4().hex[:8]}"
_current_trace_id.set(trace_id)
parent_span = _current_parent_span.get() or "ROOT"
span_id = f"sp-{uuid.uuid4().hex[:6]}"
depth = _current_depth.get()
t_parent = _current_parent_span.set(span_id)
t_depth = _current_depth.set(depth + 1)
indent = " │ " * depth + " ├─ " if depth > 0 else "┌─ "
logger.info(
"WATERFALL | %s %s [START] [trace_id=%s span_id=%s parent=%s]",
@@ -137,3 +145,7 @@ def _run_sync_span(span_name: str, func: Callable, *args: Any, **kwargs: Any) ->
span_id,
parent_span,
)
_current_parent_span.reset(t_parent)
_current_depth.reset(t_depth)
if is_root:
_current_trace_id.set(None)