Skip to content

Commit d59bf54

Browse files
committed
fix(pipecat): close spans on terminal frames
1 parent 97875a9 commit d59bf54

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

‎py/src/braintrust/integrations/pipecat/test_pipecat.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ async def test_setup_pipecat_traces_real_pipeline_frames(memory_logger):
310310

311311
@worker.event_handler("on_pipeline_started")
312312
async def on_pipeline_started(_worker, _frame):
313-
await worker.queue_frames([LLMContextFrame(context), EndFrame()])
313+
await worker.queue_frames([LLMContextFrame(context), EndFrame(reason="pipeline complete")])
314314

315315
runner = WorkerRunner(**_worker_runner_kwargs())
316316
await runner.add_workers(worker)
@@ -320,6 +320,8 @@ async def on_pipeline_started(_worker, _frame):
320320
pipeline_span = _single_span(logs, "pipecat_pipeline")
321321
assert _span_type(pipeline_span) == "task"
322322
assert pipeline_span.get("metrics", {}).get("end") is not None
323+
assert pipeline_span["metadata"]["terminal_frame"] == "EndFrame"
324+
assert pipeline_span["metadata"]["reason"] == "pipeline complete"
323325

324326
llm_span = _single_span(logs, "pipecat_llm_response")
325327
assert _span_type(llm_span) == "task"

‎py/src/braintrust/integrations/pipecat/tracing.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,12 @@ async def on_pipeline_started(self) -> None:
121121
self._ensure_pipeline_span()
122122

123123
async def on_process_frame(self, data: Any) -> None:
124-
if self._uses_native_frame_deduplication:
124+
frame = getattr(data, "frame", None)
125+
processor = getattr(data, "processor", None)
126+
is_terminal_at_sink = type(frame).__name__ in _TERMINAL_FRAME_TYPES and _is_pipeline_sink_processor(processor)
127+
if self._uses_native_frame_deduplication and not is_terminal_at_sink:
125128
return
126-
await self._handle_frame(getattr(data, "frame", None), processor=getattr(data, "processor", None))
129+
await self._handle_frame(frame, processor=processor)
127130

128131
async def on_push_frame(self, data: Any) -> None:
129132
await self._handle_frame(getattr(data, "frame", None), processor=getattr(data, "source", None))

0 commit comments

Comments
 (0)