fix(backend/copilot): add conversation_turn to Langfuse trace metadata

Add conversation_turn field to trace metadata with the correct turn number
based on user message count. This fixes the Langfuse observability issue where
SDK's num_turns always showed '1' when using --resume (which creates a new CLI
session each turn).

Now Langfuse traces will include:
- langsmith.metadata.num_turns: '1' (from SDK, represents current CLI session)
- metadata.conversation_turn: <actual turn> (from our code, represents conversation history)

This gives us accurate turn tracking for multi-turn conversation analysis.
This commit is contained in:
Zamil Majdy
2026-03-06 16:07:30 +07:00
parent c17f19317b
commit 8625a82495

View File

@@ -1075,7 +1075,10 @@ async def stream_chat_completion_sdk(
session_id=session_id,
trace_name="copilot-sdk",
tags=["sdk"],
metadata={"resume": str(use_resume)},
metadata={
"resume": str(use_resume),
"conversation_turn": turn,
},
)
_otel_ctx.__enter__()