Braj Kishore
JourneyVaultML FoundationsAI PM GuideAgenticNewsWork With MeMentorshipPulseNow
Say hi

Hiring · Building · Investing

Have a system — or a team —that needs to scale?

info@avyxon.ai

Usually replies within a day · track record here

JourneyVaultML FoundationsAI PM GuideAgenticNewsWork With MeMentorshipPulseNow
LinkedInXYouTubeSubstackInstagramThreadsFacebookDiscordGitHubTopmate
© 2026 Braj Kishore · Bengaluru, INThink Big · Start Small · Scale Fast
Agentic engineering
Lesson 18Working

Observability and tracing

An ordinary service gives you one request, one trace, and a deterministic path through it. An agent gives you a tree of model calls that took a different shape than it did yesterday. Almost everything you know about monitoring still applies — but the unit of observation has moved.

Here is the situation this lesson is for. A customer says the agent did something wrong three days ago. Your dashboard says latency and error rate were normal. Both are true, and neither helps, because the run failed while every individual step succeeded.

That is the shift. In a normal service the interesting failure is a bad response. In an agent it is usually a bad sequence — a tool called twice, a policy read and then ignored, a run that stopped one step early. None of those is visible in an aggregate, and all of them are obvious in a trace.

Interactive · one run, as a trace

A trace is a tree, and the shape is the diagnosis

The refund run from lesson 04, drawn as spans. Select any bar for the attributes it carries and why they matter. Durations are illustrative; the shape and the token counts are not.

invoke_agentchatexecute_tool
execute_toolissue_refund → blocked
gen_ai.tool.name = issue_refunderror.type = policy_ceiling_exceededoutcome = blocked

The guard fires. error.type is one of the few attributes here that is Stable rather than Development, and setting it is what turns a blocked run into something you can alert on rather than something you notice in a spreadsheet.

GenAI semantic conventions repositoryOpenTelemetry

There is a standard, and it is not finished

You do not have to invent a schema. OpenTelemetry’s GenAI semantic conventions define the vocabulary: operations named chat, execute_tool, invoke_agent, embeddings and create_agent, with gen_ai.operation.name and gen_ai.provider.name required on every span.

Now the honest part, and say it out loud in an interview rather than being caught by it. The whole GenAI convention set is still badged Development, not Stable. It was recently moved out of the main conventions repository into its own. Field names will change under you.

Adopt it anyway. A moving shared standard costs you renames. A private schema costs you every integration, every vendor migration, and every engineer who has to learn your vocabulary instead of the industry’s.

One more thing worth knowing. The attribute error.type is Stable, because it comes from the general conventions rather than the GenAI ones. So the field you most want to alert on is the one least likely to move.

Semantic conventions for generative AI client spansOpenTelemetry

Keep the token fields split

The conventions define fourteen separate token-usage attributes. That looks like pedantry until you try to produce a cost number.

Input and output are the obvious two. The ones that matter are cache_read.input_tokens, cache_write.input_tokens and reasoning.output_tokens. Cache reads are billed at a tenth of base input. So a trace that sums input tokens into one number cannot produce a cost figure you would put in front of a CFO.

There is a second payoff. Plot input tokens per turn across a run and you have drawn the square law from the economics lesson — with your own data, not a model of it. A team that records the split can show that curve; a team that does not is arguing from theory.

span.py
from opentelemetry import trace

tracer = trace.get_tracer("agent")


def run(user_message, tools, handlers):
    # One span wrapping the whole trajectory. Everything else nests inside it,
    # which is what makes "did this RUN succeed?" an answerable question.
    with tracer.start_as_current_span("invoke_agent") as root:
        root.set_attribute("gen_ai.operation.name", "invoke_agent")
        root.set_attribute("gen_ai.agent.name", "refund_agent")
        root.set_attribute("gen_ai.conversation.id", conversation_id)

        for turn in range(MAX_TURNS):
            with tracer.start_as_current_span("chat") as span:
                span.set_attribute("gen_ai.operation.name", "chat")
                span.set_attribute("gen_ai.provider.name", "anthropic")
                response = client.messages.create(...)

                # Four fields, not one total. The cache split is what makes
                # the cost figure trustworthy.
                u = response.usage
                span.set_attribute("gen_ai.usage.input_tokens", u.input_tokens)
                span.set_attribute("gen_ai.usage.output_tokens", u.output_tokens)
                span.set_attribute(
                    "gen_ai.usage.cache_read.input_tokens",
                    getattr(u, "cache_read_input_tokens", 0),
                )
                span.set_attribute(
                    "gen_ai.usage.cache_write.input_tokens",
                    getattr(u, "cache_creation_input_tokens", 0),
                )

            if response.stop_reason != "tool_use":
                root.set_attribute("outcome", "answered")
                return response

            for block in tool_use_blocks(response):
                with tracer.start_as_current_span("execute_tool") as span:
                    span.set_attribute("gen_ai.operation.name", "execute_tool")
                    span.set_attribute("gen_ai.tool.name", block.name)
                    span.set_attribute("gen_ai.tool.call.id", block.id)
                    result = execute(block, handlers)
                    if result.startswith("ERROR"):
                        # Stable attribute, unlike most of the gen_ai.* set.
                        span.set_attribute("error.type", classify(result))

        root.set_attribute("outcome", "capped")
        raise RuntimeError(f"no answer in {MAX_TURNS} turns")
The whole integration, roughly. A context manager around the loop for the root span, one span per model call, one per tool. The four usage fields are the only part people routinely get wrong, by adding them up first.
Prompt cachingAnthropic docs

The awkward trade

Everything above is metadata. It tells you what happened and what it cost, and it contains nothing anyone said.

The attributes that tell you why are different. gen_ai.input.messages, gen_ai.output.messages, gen_ai.system_instructions and gen_ai.tool.definitions are all marked Opt-In. Each carries the same plain warning: this attribute is likely to contain sensitive information including user and PII data.

Interactive · what you record decides what you can ask

The most useful field is the one you are least allowed to keep

Switch attributes on and off. The questions on the right answer themselves — and the four that cost nothing in privacy terms are already on by default in the conventions.

Questions you can answer · 4 of 7
  • What did this run cost?
  • Is our cache hit rate falling?
  • Which tool fails most often?
  • Is the agent repeating itself?
  • Why did it not use the refund tool?
  • Did last week's prompt change cause this?
  • Why did it tell the customer that?

Everything on is PII-free. This is the set worth having on day one: it answers every cost and reliability question without storing a word anyone said. What it cannot tell you is why — and that is the trade the next four fields make.

The sentence worth having ready: the most useful field for debugging an agent is the one you are least allowed to store. Turning it on is often right. Drifting into it because it was a config flag is not. That is how a company ends up with a second copy of its customer conversations in a vendor system nobody wrote a retention policy for.

This is also why the failure taxonomy in lesson 16 could exist at all. Those categories were produced by people hand-annotating trajectories. No aggregate metric would have surfaced “the agent repeated work it had already done” as a distinct, countable thing.

Why Do Multi-Agent LLM Systems Fail?arXiv 2503.13657

From sampling to reading everything

Once you have traces, a second option opens that traditional monitoring never had. You can have a model read them.

Nubank describe the shift plainly: moving from a tiny sample of surveys to a 100% audit of conversations let them iterate on variants daily. That is the real prize. Not a dashboard — a feedback loop that runs at the speed you ship rather than the speed customers reply to surveys.

The catch is the one from the evaluation lesson. An auditor is a model, and a model judging a model has to be validated against human labels before you believe its numbers. Skip that and you have automated the production of confident numbers with no relationship to quality.

What to actually run

You do not need to build any of the viewing layer, and at most sizes you should not.

🇩🇪🇪🇺 Germany · European Union

Langfuse — the open-source shape of an LLM observability platform

MIT
licence, except its ee folders
~34k
GitHub stars
Jan 2026
became part of ClickHouse

Langfuse is an open-source LLM engineering platform built in the EU, self-hostable, and OpenTelemetry-compatible. It bundles the three things teams keep rebuilding separately: tracing, evaluation — LLM-as-a-judge, code evaluators, user feedback, manual labelling — and versioned prompt management.

Two reasons it belongs in this lesson rather than a tools list. First, self-hosting is the answer to most of the privacy trade above: if the content never leaves your infrastructure, the calculation changes. Second, its acquisition by ClickHouse in January 2026 is a useful reminder for anyone doing vendor due diligence — an open-source licence is what protects you when a tool you depend on changes owner, and MIT with carve-outs is worth reading carefully before you assume it covers what you need.

Langfuselangfuse on GitHub

What to run at your size

Two of the five controls below are honest skips at seed, and one stays a skip all the way through. The third is the one that catches teams out. Recording message content is right at seed and becomes a governed decision later — the opposite of how most controls age.

Interactive · calibrate to your stage

What to actually do about this, at your size

Nearly all guidance on this topic is written for one company size and then read by everyone. Pick yours — the list re-sorts, and what you should deliberately not build drops to the bottom.

  • A root span per runNon-negotiable

    One span wrapping the whole trajectory, with a conversation or run id every child carries.

    At this stage · Now with the run id propagated to your application logs too, so a support ticket can be joined to a trajectory.

  • Split token accountingDo it

    Record input, output, cache-read and cache-write tokens as separate fields rather than one total.

    At this stage · Now on a dashboard beside latency. A falling cache hit rate is the most common cause of a cost line that moves without anyone shipping anything.

  • Message content in tracesCheap version

    Recording the actual prompts, replies and tool results alongside the metadata.

    At this stage · Sample it, redact obvious identifiers, and set a short retention. This is the stage where the volume stops being readable and the data starts being regulated.

  • An LLM auditor over tracesSkip it

    A model grading a sample — or all — of your completed runs against written criteria.

    At this stage · Still skip. Build the human-labelled set first — that is the thing an auditor has to be validated against, and it is the part with no shortcut.

  • A bespoke trace viewerSkip it

    Your own UI for reading trajectories, rather than an off-the-shelf platform.

    At this stage · Still skip. Langfuse and its peers are open source and self-hostable; building a worse one is a quarter you do not get back.

2 of 5 deliberately skipped at this stage. Knowing which controls you are choosing not to build, and being able to say why, is a stronger signal than having built all of them.

What to remember

  1. 1
    The run is the unit, not the request

    An agent usually fails while every step succeeds. Wrap the whole trajectory in a root span with a run id, or you can count model calls but cannot answer how many runs finished.

  2. 2
    Adopt the standard even though it is unfinished

    OpenTelemetry's GenAI conventions are badged Development and field names will move. A private schema costs more: every integration, every migration, and every engineer learning your vocabulary instead of the industry's.

  3. 3
    Never sum the token fields

    Cache reads are billed at a tenth of base input, so a single input-token total cannot produce a cost figure you would defend. Keep input, output, cache-read and cache-write apart from day one.

  4. 4
    Decide about message content deliberately

    The attributes that explain why something happened are opt-in and flagged as likely to contain PII. Recording them is often right. Drifting into it because it was a config flag is how you end up with an unpoliced second copy of customer conversations.

Sources

Every source in this lesson

Primary sources wherever one exists. Where a claim is contested or vendor-reported, the lesson says so at the point it is made.

Paper
  • Why Do Multi-Agent LLM Systems Fail?arXiv 2503.13657

    The failure taxonomy was built by hand-annotating traces. That is the argument for keeping them: the categories that let you fix an agent are only visible in the sequence of steps, never in an aggregate.

Read
  • Building AI agents for 131 million customersNubank engineering

    Defines a trace as the full interaction chain of LLM messages, customer inputs and tool calls. The line worth carrying: “By moving from a tiny sample of surveys to a 100% audit of conversations, we can iterate on variants daily.”

Code
  • Langfuselangfuse on GitHub

    MIT-licensed except its ee folders, around 34,000 stars, self-hostable, and OpenTelemetry-compatible. Built in the EU and part of ClickHouse since January 2026. Useful as the reference shape for what an LLM observability platform actually does: tracing, evaluation, prompt management.

Docs
  • Semantic conventions for generative AI client spansOpenTelemetry

    The shared vocabulary, and still badged Development rather than Stable. Defines the operations — chat, embeddings, execute_tool, invoke_agent, create_agent — and makes gen_ai.operation.name and gen_ai.provider.name required on every span.

  • GenAI semantic conventions repositoryOpenTelemetry

    The conventions were moved out of the main semantic-conventions repo into their own home, which is itself a signal about how fast this area is still changing. Covers spans, metrics and events for GenAI clients and for MCP.

  • Semantic conventions for GenAI metricsOpenTelemetry

    Four client metrics worth having on a dashboard before anything bespoke: gen_ai.client.operation.duration, gen_ai.client.token.usage, and for streaming, time_to_first_chunk and time_per_output_chunk.

  • Prompt cachingAnthropic docs

    Why the cache_read and cache_write token fields are separate lines rather than pedantry: cache reads are billed at 0.1x base input, so a trace that collapses them into one number cannot produce a cost figure you can trust.

Lesson 17
Production
Lesson 19
How inference actually works