← Home · Tutorial 16 · Production engineering

Tracking production agents

How to track what an agent did and how it performed: the options, and the same agent tracked with Python logging and with LangSmith.

Last reviewed 19 October 2026 · Written with AI assistance and reviewed by me

Where this comes from: Python's Logging HOWTO, LangSmith's guides on tracing your own code and tracing with OpenTelemetry, and the OpenTelemetry documentation. The examples are my own, and every snippet that does not call a service was run to produce the output shown.
Who this is for: anyone running an agent who needs to answer "what did it do, how long did it take, and what did it cost?". You will learn why tracking matters, what the options are, and how the same agent is tracked with free Python logging and with a tracing platform, LangSmith.

1What we are demystifying

Tracking and performance tracking, defined.

This page answers one question: how do you track what a production agent does, and how well it performs?

Tracking means a record of every step of every request: which model call, which tool, in what order, and what came back. Performance tracking adds the numbers to that record: how long each step took, how many tokens it used, and whether it failed.

2Why it matters

An agent answer is several steps.

A chatbot answer is one model call. An agent's answer is several: it may classify the question, call a tool, then call the model again with the result. When a user says "it was slow" or "it got it wrong", you need to know which of those steps did it.

When someone asksYou need to know
"Why was it slow?"Time per step, to find the one that dominated
"Why did this cost so much?"Tokens per model call
"Why did it say that?"Which route and tool it took, and what the tool returned
"Is it getting worse?"The same numbers across many requests, over time
Failures are often silent. An agent can return a well-formed wrong answer with no error raised. Without a record of the steps, there is nothing to look at except the code, and the code did not change.

3What you can use

Logging, platforms, cloud monitoring, OpenTelemetry.

OptionWhat it isCost and set-up
Python loggingBuilt into Python. Your code writes events to a screen, file or log serviceFree, already installed
A tracing platformA hosted product that records each request as a tree of timed steps and gives you a UI to search it. LangSmith, Langfuse, Arize and Braintrust are examplesAn account and an SDK. Free tiers with limits are common; check each one
Your cloud provider's monitoringLogs, metrics and traces inside the platform you already deploy onUsually billed by volume
OpenTelemetryAn open standard for producing this data, which many of the tools above can receiveFree and open source; you still need somewhere to send it

These are not exclusive. OpenTelemetry is a way of producing the data; the other three are places it can go. Many teams use logging and one other option side by side.

4Why compare these two

Basic and free versus a full platform.

This page compares Python logging and LangSmith tracing, because they sit at the two ends of the range.

  • Python logging is the most basic option: free, in every Python install, no account.
  • LangSmith is a full platform built for LLM apps: automatic step trees, token counts and a UI.

Most people start with one and wonder whether they need the other. Seeing the same agent tracked both ways answers that better than a feature list. LangSmith stands in for tracing platforms in general here. I chose it because its tracing for LangChain and LangGraph code is automatic, not because I have ranked it against the others.

5The example agent

Three steps, made-up numbers.

Here is the agent we will track. It answers "Where is my order?" in three steps: a model call to classify the question, a tool call to look up the order, and a model call to write the answer. There is no real model; each step returns fixed, made-up timings and token counts so the results are repeatable.

One request, three steps
classifymodel call
→
get_order_statustool call
→
answermodel call

6Tracked with Python logging

JSON lines, then a summary you write.

With logging, you decide what to record and write it yourself. One JSON line per step, each stamped with the same request id. (How the logger, levels and JSON formatter work is covered in Logging for AI apps.)

Python
import json, logging, sys
log = logging.getLogger("support_agent"); log.handlers = []
log.addHandler(logging.StreamHandler(sys.stdout)); log.setLevel(logging.INFO)

def step(request_id, name, ms, tokens=0):
    log.info(json.dumps({"request_id": request_id, "step": name, "ms": ms, "tokens": tokens}))

step("req-7f3a", "classify", 420, 101)
step("req-7f3a", "get_order_status", 210)
step("req-7f3a", "answer", 1350, 452)
Output (run to check)
{"request_id": "req-7f3a", "step": "classify", "ms": 420, "tokens": 101}
{"request_id": "req-7f3a", "step": "get_order_status", "ms": 210, "tokens": 0}
{"request_id": "req-7f3a", "step": "answer", "ms": 1350, "tokens": 452}
From three log lines to one answer
3 log linesone per step, shared request id
→
Query by request idyour log tool search, or a few lines of code
→
Summary1,980 ms total · 553 tokens · answer was slowest (68%)
What you get: a free, portable record that works anywhere, and full control over what goes in it. What you build yourself: the fields, and every view or summary, including the one in the diagram.

7Tracked with LangSmith

Decorators, and the trace they produce.

With LangSmith, you attach a small decorator, @traceable, to each function you want recorded. LangChain and LangGraph code is traced without it. Nothing else in the function changes.

Three functions, each decorated
classify()@traceable(run_type="llm")
get_order_status()@traceable(run_type="tool")
handle()@traceable — the parent

Set an API key and turn tracing on, and every call to handle becomes one trace: the parent, with the model and tool calls nested underneath. (Shape from LangSmith's docs; I have no account, so this was not run.)

What one request looks like as a trace
handle1,980 ms
→
classify420 ms · 101 tokens
get_order_status210 ms
answer1,350 ms · 452 tokens

The diagram uses this page's made-up numbers; it is a sketch of the shape, not a screenshot of LangSmith.

What you get: the tree, timings and a UI with no summary code to write, plus search across requests. What it costs: an account, an SDK dependency, and your data on a hosted service. At the time of writing LangSmith has a free single-user plan with a monthly trace limit; check the current pricing page.

8Side by side

Cost, set-up, views and fit.

Python loggingLangSmith tracing
CostFreeFree tier with limits, then paid
Set-upNothing to installAccount, API key, SDK
What it recordsWhat you writeEach marked function: inputs, outputs, timing
Steps of one requestLines sharing a request idA nested tree
Tokens per stepIf you log themShown for model runs
Viewing itYour log tool, or code you writeA UI built for agents
Where data goesWherever you send itA hosted service
Best forEvery app, from day oneDebugging multi-step requests one at a time
The short version: logging is the floor every app should have. A tracing platform is what you add when you keep asking "which step was it?" and reading log lines to answer.

9Use both, safely

One id across both, and what not to record.

Using both is common, and they work better together. Put the same id in your log lines and on the trace, as a tag or metadata, and you can move from a strange log line to its full trace and back. If you trace with OpenTelemetry, a small logging filter can copy the trace id onto every log record for you.

Either way, watch what you record. Platforms capture function inputs and outputs by default, and those often hold personal data. Do not log or trace API keys, passwords or payment details. Check what your platform stores, mask personal fields, and keep retention short for anything holding full text.

10Check yourself

Short questions, a try-it and one line to remember.

What is the difference between tracking and performance tracking?

Tracking records which steps ran and what they returned. Performance tracking adds time, tokens and failures for each step.

Why does an agent need more than a chatbot?

Each answer is several steps, so you need to know which step was slow, costly or wrong.

What do you have to build yourself with Python logging?

The fields, the timing and every summary or view, such as total time and slowest step per request.

When is a tracing platform worth adding?

When you regularly debug single requests across many steps and need the step tree and tokens per step without writing that code.

How do you use both together?

Put the same request or trace id in your logs and on the trace.

Try it: change the made-up timings so the tool call is slowest, and re-run the summary. Then add a fourth step, a retry of the tool, and make the summary report how many tool calls one request made.
One line to remember: "Logging gives you a record you build. A tracing platform gives you the tree, ready-made. Start with the first, add the second when the question keeps being 'which step?'"
Sources: Python Logging HOWTO; LangSmith tracing your own code and tracing with OpenTelemetry; LangChain pricing page for the free plan (checked October 2026); OpenTelemetry signals. Other platforms named are examples I have not tested. Products and plans change, so check the current docs. Independent notes, not affiliated with or endorsed by any company or course named here. Examples and wording are my own.