Building My Own LLM Tracing Dashboard

How we built our own LLM tracing, and how you can build yours.

โ‰ˆ 5 min readLLM observabilityLangGraphAWS Bedrock

IN SHORT

  • The model already reports tokens and latency. Just save them.
  • Save traces in your own database, linked to the chat message.
  • One row per LLM call, one row per tool call.
  • Trace the guardrail and judge calls too. They also cost tokens.
We built an AI support assistant. After it went live, we needed answers. Why did it say this? Which tool failed? What did it cost? We first used a third-party tracing tool. But our data sat in two places, and the tool did not know our users or tenants. So we built our own. Here is how, step by step.

What do we want to see?

For every chat message, we want to answer five questions:
Question What to save
What did the user ask? The question
What did the model see? The exact prompt
What did it do? Every LLM call and tool call
What did it cost? Tokens and latency
Was it right? A quality score and user feedback
If you can answer these five, you have real visibility.

The design

Two tables do all the work:
  • llm_trace: one row per LLM call
  • tool_invocation: one row per tool call
Both are linked to the chat message.
LLM tracing design: user messages, LLM calls, tool calls and guardrails flowing into llm_trace and tool_invocation tables and one dashboard
Tracing design ยท 4 sources, 2 trace tables, 1 dashboard
Both tables live in the same database as the app, so the dashboard is just SQL.

Level 1: Trace one LLM call

Every model response already has token counts and latency. In LangChain, they are in usage_metadata and response_metadata. Save them. Do not count tokens yourself.
# after each LLM call, save one row:
model_name    = response.model_name
input_tokens  = response.usage.input_tokens
output_tokens = response.usage.output_tokens
latency_ms    = response.latency
raw           = the full response as JSON
Keep the full response as JSON. For reasoning models, it also saves the model’s thinking, with no extra work.

๐Ÿ’ก TIP

Latency can come as a number, or as a list when the response is streamed. Handle both.

Level 2: Trace one agent turn

An agent may call the LLM several times to answer one question. Add these calls up into one row for the turn. The chat history also holds all the old turns. So only use the messages after the last user message:
this_turn = messages after the last user message

for each AI message in this_turn:
    input_tokens  += its input tokens
    output_tokens += its output tokens

Level 3: Trace tools

Many wrong answers come from a tool, not the model. So save every tool call in tool_invocation: name, arguments, output, status and latency. The model does not report tool latency, so time it yourself:
start = time.time()
result = await run_tool(...)
latency_ms = (time.time() - start) * 1000

โš ๏ธ WATCH OUT

“Not found” is not a failure. Count a failure only when the tool could not do its job, like a network or API error. Otherwise your failure-rate chart looks worse than reality.

Level 4: Trace multi-step flows

Some flows run fixed steps, each with its own LLM call: understand, then generate, then verify, then answer. Save one row per step, with its exact prompt and output. Then you can see which step went wrong, or which one costs the most. To collect these calls without passing a trace object everywhere, use a Python ContextVar. It is a small store that belongs to the current request:
calls = ContextVar("llm_calls")

# at the start of the request
calls.set([])

# one helper for every LLM call
async def call_llm(prompt, step):
    response = await llm.ainvoke(prompt)
    calls.get().append((step, prompt, response))
    return response

# at the end of the request: save one row per recorded call
Every LLM call goes through this one helper, so no step is missed.

๐Ÿ’ก TIP

Prompts can be very long. Cap the text you store. We keep up to 60,000 characters per field.

Level 5: Trace guardrails

A guardrail check (is the question safe? what is the intent?) is an LLM call too. Trace it as its own row, and also save its decision on the chat message. Then, even when a message is blocked and the agent never runs, you can still see why it was blocked and what the check cost.

๐Ÿ’ก TIP

Also save the rewritten question. “What about the second one?” means nothing alone. The rewritten version explains many strange answers.

Level 6: Was the answer right?

Tokens tell you the cost, not the quality. For quality, a second model (an “LLM judge”) scores each answer. For example: is the answer supported by the documents we found? Save the score on the chat message. If it is below a threshold, flag the message so a person can review it.

๐Ÿ“ NOTE

The judge is an LLM call too. Save its tokens, or your totals will be too low.

Level 7: The dashboard

Everything is in your database, so the dashboard is simple SQL. Useful cards:
  • Total and average tokens
  • Response time trend
  • Tool calls and failure rate
  • Latency per tool
  • Blocked messages (guardrail)
  • Flagged answers (judge)
Add a conversation view too. Open one chat and see, for each answer, its tool calls, sources and scores. The charts show that something is wrong. The conversation view shows why.
LLM analytics dashboard showing user engagement, average response time, token usage and guardrail actions
Analytics page
Conversation view showing tool calls, sources and judge scores for each chatbot answer
Conversation view
Every row also has a tenant_id, so each client sees only their own usage.

Own tracing or a third-party tool?

Own tracing Third-party tool
Where data lives Your database The vendor’s cloud (some allow self-hosting)
Join with your business data Easy, same database Harder, separate system
Cost Your existing database Usually per trace or a subscription
Timeline view, replay, datasets No Usually yes
Setup Code to write and maintain Quick
Use a third-party tool for prototypes, or if you need replay and datasets. Build your own when you want traces next to your own data.

Start small

You do not need everything on day one. Build in this order:
1

Make one helper for all LLM calls. Save a row per call: model, input tokens, output tokens, latency, raw response.

2

Link each row to the chat message.

3

Add a tool table: name, arguments, output, status, latency.

4

Save the guardrail and judge results on the message.

5

Build the dashboard with SQL.

Steps 1 and 2 already give most of the value.

Final thoughts

Before this, “why did the bot say that?” was a guess. Now it is a query. We open the message and see the prompt, the tools and the cost.

You do not need a big platform for this. You need one helper around your LLM calls, and two tables to keep what it records.

BUILT INTO RESOLVR

See this tracing at work in Resolvr, our AI support engineer

Resolvr answers technical questions from your own product documentation, 24/7. Every answer is scored, and every conversation is logged. You see exactly where customers struggle.

70%

fewer routine tickets for human agents

15%

higher CSAT

24/7

global coverage, no extra headcount

Book a Discovery Call โ†’ Explore Resolvr
Share this postFacebookXLinkedInWhatsApp