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:
+1
-1
@@ -768,7 +768,7 @@ class VoiceSession:
|
||||
if message.get("role") == "user"
|
||||
)
|
||||
retrieval_query = f"{retrieval_query} {user_text}".strip()
|
||||
with trace_span("knowledge_base_search"):
|
||||
async with time_span("knowledge_base_search"):
|
||||
kb_hits = (
|
||||
knowledge_base.search(
|
||||
retrieval_query,
|
||||
|
||||
+14
-2
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user