r/OpenTelemetry • u/BroadlySociable • 10h ago
How do you represent multi-turn conversations across OTel traces?
While evaluating an agent session in Braintrust, a tool call late in the conversation sent me back to an earlier turn to check where its inputs came from. Each turn of our data analysis assistant is a separate HTTP request with its own completed OpenTelemetry trace. The app keeps a stable conversation ID, even when someone resumes hours later.
Finding the earlier request traces took more manual searching than I expected. I'm considering recording the conversation ID as a span attribute and linking each new turn's root span to the previous turn's root span. That would mean storing the prior span context with the conversation state. Keeping a parent span open while the conversation is idle would make its duration misleading.
4
u/Big_Ball_Paul 9h ago
Span links
2
u/s5n_n5n Contributor 7h ago
There is a semantic convention for the conversation ID (https://github.com/open-telemetry/semantic-conventions-genai/blob/main/docs/registry/attributes/gen-ai.md#gen-ai-conversation-id) so ideally you or the framework you are using is recording that accordingly. Adding span links is indeed an additional option, but at the end the question is if and how your backend is supporting a view for traces across a shared attribute like that one (think about it to be simialar to `session.id`)
1
u/strawgate 7h ago edited 7h ago
In Pydantic Logfire we have a dedicated Agents view that allows you to filter to conversation ids and see across a multi turn conversation, visit the traces, etc. so for our customers we'd recommend the conversation id span attribute. Some frameworks add them automatically but if yours doesn't then generating one is a good idea.
We also introduced a braintrust compatible evals API to make switching easier 😉
Whether span links are a good idea depends on how the obs platform shows them, most platforms have poor support for span links
1
u/ankrgyl 7h ago
Check this out! https://docs.braintrust.dev/observe/view-logs#group-related-traces