Skip to content

Commit 1a4f0b7

Browse files
committed
fix(tracing): Deep-copy spans before enqueuing to background queue
Processors like SGPAsyncTracingProcessor mutate span.data in-place via _add_source_to_span. With async background processing, this raced with the caller who holds a reference to the same span object. Deep-copying via model_copy(deep=True) decouples the two.
1 parent 84b3bca commit 1a4f0b7

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/agentex/lib/core/tracing/trace.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ async def start_span(
232232
)
233233

234234
if self.processors:
235-
self._span_queue.enqueue(SpanEventType.START, span, self.processors)
235+
self._span_queue.enqueue(SpanEventType.START, span.model_copy(deep=True), self.processors)
236236

237237
return span
238238

@@ -257,7 +257,7 @@ async def end_span(
257257
span.data = recursive_model_dump(span.data) if span.data else None
258258

259259
if self.processors:
260-
self._span_queue.enqueue(SpanEventType.END, span, self.processors)
260+
self._span_queue.enqueue(SpanEventType.END, span.model_copy(deep=True), self.processors)
261261

262262
return span
263263

0 commit comments

Comments
 (0)