From f2f81409dca8b0e4b3303eff15632e91cb476313 Mon Sep 17 00:00:00 2001 From: ashtarkb Date: Sun, 28 Dec 2025 16:24:00 +0200 Subject: [PATCH] fix: move TraceContext.spans from class to instance attribute The spans list was defined as a class-level attribute, causing all TraceContext instances to share the same list. This led to trace corruption when handling concurrent requests, as spans from different requests would be mixed together. Moving spans initialization to __init__ ensures each TraceContext instance has its own isolated spans list. Fixes trace mixing bug in concurrent request handling. --- llama_stack/providers/utils/telemetry/tracing.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/llama_stack/providers/utils/telemetry/tracing.py b/llama_stack/providers/utils/telemetry/tracing.py index 62cceb13ea..de89af559a 100644 --- a/llama_stack/providers/utils/telemetry/tracing.py +++ b/llama_stack/providers/utils/telemetry/tracing.py @@ -155,11 +155,10 @@ def enqueue_event(event: Event) -> None: class TraceContext: - spans: list[Span] = [] - def __init__(self, logger: BackgroundLogger, trace_id: str): self.logger = logger self.trace_id = trace_id + self.spans: list[Span] = [] def push_span(self, name: str, attributes: dict[str, Any] = None) -> Span: current_span = self.get_current_span()