LangfuseLangfuse Python SDK 4.15.4 · Python 3.10+
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
38 small wins to finish your pathNext lesson

Sessions: one conversation, many traces

A session groups traces that belong together, such as the turns of one chat. Each turn stays its own trace; the session_id ties them together.

Lesson 9 put one email in one trace. A chat is different: the customer writes, the desk answers, and minutes later the customer writes again. Langfuse's guidance is one trace per turn and one session per conversation, because you never know in advance when a conversation ends.

Examplechat.py, after the setup lines with propagate_attributes, and from desk import answer
conversation = ["Hello?", "Where is my order A17?", "Thanks. And B22?"]

for turn in conversation:
    with propagate_attributes(session_id="chat-0042", user_id="cust-42"):
        print(answer(turn))

langfuse.flush()
roots = [span for span in local_langfuse.SPANS if span["name"] == "answer-ticket"]
print(len({span["trace"] for span in roots}), "traces")
print({span["attributes"]["session.id"] for span in roots})
Example
python chat.py

The three turns made three traces, all with the same session id. In Langfuse's interface the session view replays the three turns in order, and scores can be attached to the whole session (lesson 24).

One conversation, three traces, one set of attributes
session chat-0042on every observation in each traceturn 1, one traceHello?turn 2, one traceWhere is my order A17?turn 3, one traceThanks. And B22?user_idcust-42session_idchat-0042tags and metadataorders, email, channel=emailenvironment, releasestaging, 2026.03.1trace idmade from the ticket numberlevelWARNING on a missing order
Hover or tap a piece to see what it is and which lesson built it.
Follow the conversation

Pick one to watch it run, step by step.

A session id is any US-ASCII string of at most 200 characters; a longer one is dropped. Use the id your chat system already has for the conversation, so a support agent can move between the two.

A session does not carry memory
Grouping turns into a session changes nothing about what the model sees. The stand-in answered each turn on its own; a real chat application still has to send the earlier messages itself.
Try it yourself
  • Give the third turn a different session id and print the set again.
  • Leave out session_id and print how many traces there are.
  • Wrap all three turns in one start_as_current_observation block and count the traces.

Every expert started right here.