Skip to content

Common Log Query Patterns

In addition to module-specific queries, day-to-day troubleshooting typically filters by general dimensions such as log level, Trace ID, and Session ID. This document provides ready-to-reuse query templates.

All logs are in JSON format (zap JSON encoding). Key fields:

FieldDescriptionExample
levelLog levelinfo, warn, error, debug, fatal
timeISO8601 timestamp2026-09-22T05:33:26.910Z
msgEvent name[turnagent] turn.end, [RPC] ->
trace_idOpenTelemetry Trace ID (auto-injected)463b28fa9fd2b71c0c6355247e80f045
span_idOpenTelemetry Span ID (auto-injected)531f76a1dc491cce
{service="server"} | json | level="warn"
{service="server"} | json | level="error"
{service="server"} | json | level="fatal"
{service="server"} | json | level=~"warn|error"
sum(count_over_time({service="server"} | json | level="error"[1m]))
topk(10,
count by (msg) ({service="server"} | json msg="msg" | level="error")
)

View error logs from the last 5 minutes (with details)

Section titled “View error logs from the last 5 minutes (with details)”
{service="server"} | json | level="error"

Set the time range to now-5m in Grafana Explore.

Every log entry automatically contains trace_id and span_id (from the OpenTelemetry context), enabling full end-to-end tracing of a single request.

{service="server"} | json trace_id="trace_id" | trace_id="463b28fa9fd2b71c0c6355247e80f045"

Extract Trace ID from error logs, then trace the full chain

Section titled “Extract Trace ID from error logs, then trace the full chain”
  1. First, find the error:
{service="server"} | json trace_id="trace_id", msg="msg" | level="error"
  1. After obtaining the trace_id, query the full chain:
{service="server"} | json trace_id="trace_id" | trace_id="<value from above>"

The same trace_id is shared across multiple services. Searching for a trace_id in Grafana Tempo reveals the complete cross-service call chain (HTTP -> RPC -> Agent -> LLM).

Trace the full logs for a specific RPC request

Section titled “Trace the full logs for a specific RPC request”

Start from the RPC logs and extract the trace_id:

{service="server"} | json trace_id="trace_id", method="method" | msg="[RPC] ->" | method="v1.rtc.submit_result"

Then use the extracted trace_id to query the full chain:

{service="server"} | json trace_id="trace_id" | trace_id="e6518062ef5d54ff05961e2a48d3e3c0"

session_id is the core correlation field on the business dimension.

{service="server"} | json session_id="session_id" | session_id="01a0c796-1ecc-72c9-80b9-b214e6ef6d68"
{service="server"} | json session_id="session_id" | level="error" | session_id="01a0c796-1ecc-72c9-80b9-b214e6ef6d68"

View all warn/error logs for a specific Session

Section titled “View all warn/error logs for a specific Session”
{service="server"} | json session_id="session_id" | level=~"warn|error" | session_id="01a0c796-1ecc-72c9-80b9-b214e6ef6d68"
topk(10,
count by (session_id) ({service="server"} | json session_id="session_id" | level="error")
)

turn_id is used to trace the full execution chain of a single Turn.

{service="server"} | json turn_id="turn_id" | turn_id="01a0c79c-adbb-73ae-818d-9c2b5b95cb5f"

View execution duration for a specific Turn

Section titled “View execution duration for a specific Turn”
{service="server"} | json turn_id="turn_id", duration_ms="duration_ms" | msg="[turnagent] turn.end" | turn_id="01a0c79c-adbb-73ae-818d-9c2b5b95cb5f"
{service="server"} | json user="user" | user="01a09047-0f11-7c36-8e08-74e6726fbbd3"
{service="server"} | json user="user" | level="error" | user="01a09047-0f11-7c36-8e08-74e6726fbbd3"

Find logs containing a specific keyword within a time range

Section titled “Find logs containing a specific keyword within a time range”
{service="server"} |= "timeout" | json

Find logs containing a specific error message

Section titled “Find logs containing a specific error message”
{service="server"} |= "connection refused" | json | level="error"
{service="server"} | json | level="warn" | msg !~ "non-fatal|best effort"

Troubleshoot user issues: by Session + time + level

Section titled “Troubleshoot user issues: by Session + time + level”
{service="server"} | json session_id="session_id", msg="msg" | level=~"warn|error" | session_id="<session-id>"

Troubleshoot tool call failures: by Session + keyword

Section titled “Troubleshoot tool call failures: by Session + keyword”
{service="server"} | json session_id="session_id" | level="warn" | msg=~"tool\\.call_failed|script.*failed" | session_id="<session-id>"
Section titled “Troubleshoot LLM anomalies: by Session + token-related”
{service="server"} | json session_id="session_id" | msg=~"llm\\.complete|llm\\.http\\.error|token_callback" | session_id="<session-id>"

Troubleshoot RTC end-to-end: trace from Trace ID

Section titled “Troubleshoot RTC end-to-end: trace from Trace ID”
{service="server"} | json trace_id="trace_id", msg="msg" | trace_id="<trace-id>" | line_format "{{.msg}} | {{.level}}"

Global health overview: errors from the last 15 minutes grouped by module

Section titled “Global health overview: errors from the last 15 minutes grouped by module”
sum by (msg) (count_over_time({service="server"} | json msg="msg" | level="error"[15m]))

Use line_format in Grafana Explore to simplify output:

{service="server"} | json | level="error" | line_format "{{.time}} [{{.level}}] {{.msg}} | session={{.session_id}} | error={{.error}}"
{service="server"}
| json
| label_format level="{{.level}}"
| level="error"

In Grafana, you can click directly on the trace_id field in a Loki log entry to jump to Tempo and view the full distributed tracing chain.

In the development environment, logs are also written to logs/debug.log (console format, more readable):

终端窗口
# Tail error logs in real time
tail -f logs/debug.log | grep '"level":"error"'
# Filter by session_id
tail -f logs/debug.log | grep '<session-id>'
# Filter by trace_id
tail -f logs/debug.log | grep '<trace-id>'
# Filter by keyword
tail -f logs/debug.log | grep 'timeout\|failed\|error'

Full LLM request/response logs are in logs/llm-payload.log:

终端窗口
# View LLM request errors
tail -f logs/llm-payload.log | grep 'llm.http.error'
# View requests for a specific URL
tail -f logs/llm-payload.log | grep 'api.anthropic.com'