r/OpenTelemetry • u/BroadlySociable • 5d 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.
6
u/Big_Ball_Paul 5d ago
Span links
3
u/s5n_n5n Contributor 5d 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/Alarming-Chart-1771 5d ago
Span links are the right call imo, a parent span sitting open for 3 hours just wrecks your latency charts
1
u/itssimon86 3d ago
Agree with the others, span links are the way to go.
I'd also put gen_ai.conversation.id on every root span though since that makes it easier to query.
1
u/strawgate 5d ago edited 5d 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 5d ago
Check this out! https://docs.braintrust.dev/observe/view-logs#group-related-traces