Skip to content

Session Lifecycle Logs

Session is the most core business entity. Every state change produces structured logs. These logs allow you to trace the complete session lifecycle.

EventTriggerKey Fields
[OpenSession]New Session createduser, session
[OpenSession] session not closed, skippingAttempt to open an existing unclosed Sessionsession, status
[CloseSession]Session closeduser, session
[CloseSession] session already closedDuplicate close of an already closed Sessionsession
[UpdateSession]Session properties updateduser, session
[CompactSession]Context compression triggereduser, session
[CompactSession] enqueuedCompression task enqueuedsession, has_custom_instruction
[ForkSession] startSession fork starteduser, old_session, old_message, limit
EventTriggerKey Fields
[SendMessage]User sends a messageuser, device, content_len, session_id, client_id
[StopTurn]User interrupts a Turnuser, session
[GetSession]Query Session detailsuser, session
[ListSessions]List Sessionsuser, count, has_next
[MessageList]Query message listuser, session, count, has_next

View all Session operations for a specific user

Section titled “View all Session operations for a specific user”
{service="server"} | json user="user" | msg=~"\\[(Open|Close|Update|Compact|Fork)Session\\]" | user="user-123"
{service="server"} | json session="session", session_id="session_id" | msg=~"\\[(Open|Close|Update|Compact|Fork)Session\\]|\\[SendMessage\\]|\\[StopTurn\\]" | session="abc-def-123"
{service="server"} | json | msg="[CloseSession]"
sum(count_over_time({service="server"} | json | msg="[SendMessage]"[1m]))

View users with the highest message volume

Section titled “View users with the highest message volume”
topk(10, count by (user) ({service="server"} | json user="user" | msg="[SendMessage]"))
{service="server"} | json | msg=~"\\[SendMessage\\].*failed"
{service="server"} | json session="session" | msg=~"\\[CompactSession\\]"
{service="server"} | json | msg=~"\\[ForkSession\\]"
{service="server"} | json session="session" | msg="[CloseSession] session already closed"

Extract the content_len field to observe message sizes:

{service="server"} | json content_len="content_len" | msg="[SendMessage]"

Troubleshoot Session open failures (existing unclosed Session)

Section titled “Troubleshoot Session open failures (existing unclosed Session)”
{service="server"} | json session="session", status="status" | msg="[OpenSession] session not closed, skipping"

Every log entry automatically includes trace_id, which can be used to trace across services:

{service="server"} | json trace_id="trace_id", session_id="session_id" | msg="[SendMessage]" | session_id="abc-def-123"

After obtaining the trace_id, view the full call chain in Grafana Tempo.

Session-related operations are automatically recorded via RPC middleware:

MetricDescription
rtc_turn_totalTotal Turn count by work_kind and status
rtc_turn_duration_secondsTurn execution duration distribution
# Session message send rate per minute
sum(rate(rtc_turn_total[5m])) by (status)
# Turn execution latency P95
histogram_quantile(0.95, sum(rate(rtc_turn_duration_seconds_bucket[5m])) by (le))