{"slug": "traceburn-a-local-profiler-that-found-69-avoidable-agent-spend", "title": "Traceburn, a local profiler that found 69% avoidable agent spend", "summary": "Developer Tommy Tran released Traceburn, a local-first tracer and efficiency profiler for AI agents, which identified 69% avoidable spend in a test run by suggesting prompt caching. The open-source tool, built on OpenAI and Anthropic SDKs, provides cost flamegraphs, waste reports, and deterministic replay without telemetry.", "body_md": "I wrote a small support ticket triage agent: five tickets, one tool call each, a roughly 4,700 token static policy prompt sent fresh on every call, model claude-haiku-4-5. Running it uncached cost $0.0539. traceburn's waste report looked at the trace, noticed that same 4,700 token prefix going out uncached on all 10 calls, and estimated that about 82 percent of that spend was avoidable. So I added exactly the one cache_control block it suggested and reran the same five tickets: $0.0167.\n\nThat's a 69 percent measured saving. The tool's estimate landed within 18 percent of what actually happened, close enough to trust as a first signal, not close enough to treat as gospel. That's roughly how I want a cost estimator to behave.\n\nPrices change and models get repriced, so do not take my word for it: the reproduction is a few\ncents and a couple of minutes, at\n[examples/cache_before_after.py](https://github.com/TommyTranX/traceburn/blob/main/examples/cache_before_after.py).\nMeasured 2026-07-05.\n\nThat's the whole pitch in one run. traceburn is a local-first tracer and efficiency profiler for AI agents, built on top of the openai and anthropic Python SDKs: a cost and latency flamegraph, a waste report that quantifies avoidable spend instead of just gesturing at it, deterministic replay of recorded calls, and run diffs, all backed by one SQLite file on disk. No account, no server to stand up for basic use, no telemetry leaving your machine.\n\nCore tracer, stdlib only, zero dependencies:\n\n```\npip install traceburn\n```\n\nTracer plus the local web viewer (adds starlette and uvicorn):\n\n```\npip install \"traceburn[ui]\"\n```\n\nRequires Python 3.10 or later.\n\nPatch the SDKs at the top of your agent:\n\n``` python\nimport traceburn\ntraceburn.install()\n\n# your existing openai / anthropic code, unchanged\n```\n\nEvery sync call, async call, streaming response, tool call, and prompt cache hit on either SDK now\ngets recorded as a span. Traces live in one SQLite file, `./.traceburn/traces.db`\n\nby default; set\nthe `TRACEBURN_DB`\n\nenvironment variable if you want it somewhere else. If you'd rather not touch\nthe source at all, wrap the run instead:\n\n```\nTRACEBURN=1 python your_agent.py\n```\n\nThen look at what happened:\n\n```\ntraceburn ui             # opens the web viewer at 127.0.0.1:8765\ntraceburn ls              # list recorded traces\ntraceburn show <id>       # inspect one trace\ntraceburn waste <id>      # run the waste report on one trace\ntraceburn diff <a> <b>    # compare two traces span by span\n```\n\nNo API keys and nothing to configure: `python examples/offline_demo.py`\n\nrecords a simulated agent\nrun with realistic token counts, including one deliberate duplicate call, so you can see a real\ntrace, a real flamegraph, and a real waste finding inside a minute.\n\n**Trace.** `traceburn.install()`\n\npatches both SDKs so every call becomes a span with tokens,\nlatency, and cost attached, no code changes required past that one line. Want manual control\ninstead, or you're using a framework outside the two supported SDKs? The explicit API, `@trace`\n\n,\n`span()`\n\n, and `session()`\n\n, works by hand with anything.\n\n**Flamegraph.** Spans render as a flamegraph you can size two ways: by wall-clock time or by\ndollars spent, with self-time kept separate from time spent in children, so a slow parent span\ndoesn't hide which child call actually burned the seconds or the money.\n\n**Waste report.** Heuristics look for duplicate calls, unused cache opportunities, bloated\nprompts, model overkill, and retry loops. Each finding ships with a confidence level and, where the\nnumbers support it, a dollar figure. More on this below.\n\n**Replay.** `traceburn.analyze.replay.replay()`\n\nplays recorded provider responses back through the\nreal SDK types, so your agent code runs again exactly as before with zero tokens spent. That's\nuseful for tests and for debugging without burning a budget. Streaming calls aren't replayable\nyet; replay currently only serves non-streaming recordings.\n\n**Diff.** `traceburn diff <a> <b>`\n\nlines up two traces span by span and reports the delta in\ntokens, cost, and latency, alongside text diffs of the prompts and responses that changed between\nthe runs. Good for answering \"did that prompt tweak actually help.\"\n\n`traceburn ui`\n\nstarts a small, read-only Starlette API in front of a vendored single-page app: no\nbuild step, no CDN, everything ships in the package. It gives you the trace tree, the flamegraph,\na waterfall timeline, the waste report, and the run diff view.\n\nIt binds to 127.0.0.1 only and checks the request's host header against DNS rebinding, but it has no authentication of any kind. That's a deliberate tradeoff: the viewer isn't meant to be reachable from anywhere but your own machine.\n\nToday, that means the raw `openai`\n\nand `anthropic`\n\nPython SDKs, patched automatically by\n`traceburn.install()`\n\n. If you're on something else, the explicit `span()`\n\n/ `trace()`\n\n/ `session()`\n\nAPI works with any framework right now, by hand, since it doesn't care what's making the call.\nLangChain, LlamaIndex, and anything already emitting OpenTelemetry GenAI spans aren't instrumented\nautomatically yet. That's real, planned work for v0.2, not something already built and just\nundocumented, and it's covered in the roadmap below.\n\nThe rules live in `traceburn/analyze/waste/`\n\nand are documented in full at\n[docs/waste-rules.md](https://github.com/TommyTranX/traceburn/blob/main/docs/waste-rules.md). Five\nkinds of waste get checked for: duplicates (exact and near-duplicate repeated calls), cache (a\nstable prompt prefix resent without ever hitting a provider cache), context_bloat (duplicate\nblocks inside one prompt, or a huge prompt for a tiny output), model_overkill (a frontier-priced\nmodel spent on trivial short calls, phrased as a suggestion and kept at low confidence on purpose),\nand loops (retry storms, repeated identical tool calls, or a runaway step count). Every finding\nalso carries a confidence level: high, medium, low, or info.\n\nTwo principles govern all of them. A wrong finding does more damage than a missed one, so the rules are tuned for precision over recall and would rather stay quiet than guess. And no dollar figure is ever printed without observed tokens behind it and a price in the pricing table to multiply against; everything the tool prints is labeled an estimate, because it is one.\n\ntraceburn makes no network calls of its own and sends no telemetry anywhere. The only traffic on\nthe wire is your own calls to your own model provider, exactly as they'd happen without traceburn\ninstalled. A test,\n[tests/test_no_network.py](https://github.com/TommyTranX/traceburn/blob/main/tests/test_no_network.py),\nblocks all socket access at the interpreter level and then runs the recorder, the store, every\nanalyzer, and the CLI against that blockade, to prove the point rather than just assert it. Auth\nheaders are never recorded in a trace, so an API key cannot end up sitting in a stored span.\n\nInstrumentation currently covers only the `openai`\n\nand `anthropic`\n\nPython SDKs. Within those,\n`parse()`\n\nconvenience methods and `with_raw_response`\n\ncalls pass through untraced rather than being\nrecorded incorrectly, and multi-choice requests (`n > 1`\n\n) only record the first choice.\n\nCost figures come from a dated public pricing table\n([pricing.json](https://github.com/TommyTranX/traceburn/blob/main/src/traceburn/pricing.json)) and\ndon't model long-context pricing tiers or regional surcharges. Token counts prefer whatever the\nprovider itself reports as usage; anything estimated is flagged as estimated rather than presented\nas measured.\n\nThe waste rules are heuristics tuned for precision over recall, which means they'll miss real waste sooner than they'll invent fake waste, and every finding states its own confidence so you can judge it accordingly. Streaming calls aren't replayable yet; only non-streaming recordings are.\n\nThe web viewer is read-only, bound to 127.0.0.1 only, and has no authentication.\n\n- OpenTelemetry GenAI span ingest plus OTLP export. This is also the path for capturing LangChain and LlamaIndex traces, since it rides on their existing OTel instrumentation rather than requiring bespoke adapters for each.\n- A pytest plugin built on replay, for deterministic, token-free agent tests.\n- litellm instrumentation.\n- More waste rules.\n\n[Langfuse](https://github.com/langfuse/langfuse) is a full open-source LLM platform: tracing,\nevals, and prompt management, backed by Postgres and ClickHouse and meant to run as a server.\n\n[Arize Phoenix](https://github.com/Arize-ai/phoenix) is the closest neighbor here. It runs locally\nagainst SQLite with no account needed, and it's strong on tracing and evals, but it runs as a\nserver process with a fairly large dependency set, and it doesn't focus on waste detection, a\ncost-weighted flamegraph, deterministic replay, or run diffs.\n\nMLflow has been adding GenAI tracing, trace comparison, and efficiency scoring to its tracking\nserver; see [mlflow/mlflow](https://github.com/mlflow/mlflow).\n\n[LangSmith](https://smith.langchain.com) is LangChain's hosted, proprietary platform.\n[OpenLLMetry](https://github.com/traceloop/openllmetry) takes a different approach: it instruments\nyour code and exports OpenTelemetry spans to whatever backend you choose to point it at, rather\nthan shipping a backend of its own.\n\n[AgentSight](https://github.com/eunomia-bpf/agentsight) renders token flamegraphs of coding agents\nfrom the system side using eBPF, a genuinely different vantage point, though it's Linux only.\n\nHelicone ([Helicone/helicone](https://github.com/Helicone/helicone)), OpenLIT\n([openlit/openlit](https://github.com/openlit/openlit)), Braintrust\n([braintrust.dev](https://braintrust.dev)), and Logfire\n([pydantic.dev/logfire](https://pydantic.dev/logfire)) each pair instrumentation with a server or a\ncloud backend of their own.\n\ntraceburn's own position is narrower than most of the above: strictly local, one file, no account and no server needed for basic use, framework-agnostic at the SDK level, and built around efficiency first, meaning the waste report, the dollar-weighted flamegraph, replay, and diff all live together in one small package. It's meant to sit next to whatever observability stack you already run, not replace it.\n\nThere are two extension points, each documented and each meant to be roughly an afternoon of work:\nan [instrumentation adapter](https://github.com/TommyTranX/traceburn/blob/main/docs/instrumentation.md)\nfor a new SDK or framework, and a\n[waste rule](https://github.com/TommyTranX/traceburn/blob/main/docs/waste-rules.md) for a new\npattern of avoidable spend. The full guide is at\n[CONTRIBUTING.md](https://github.com/TommyTranX/traceburn/blob/main/CONTRIBUTING.md).\n\nA citation file is included at\n[CITATION.cff](https://github.com/TommyTranX/traceburn/blob/main/CITATION.cff).\n\nMIT. Full text at\n[LICENSE](https://github.com/TommyTranX/traceburn/blob/main/LICENSE).\n\nWritten by Tommy Tran.", "url": "https://wpnews.pro/news/traceburn-a-local-profiler-that-found-69-avoidable-agent-spend", "canonical_source": "https://github.com/TommyTranX/traceburn", "published_at": "2026-07-08 03:59:14+00:00", "updated_at": "2026-07-08 04:29:55.373217+00:00", "lang": "en", "topics": ["ai-agents", "developer-tools", "ai-infrastructure"], "entities": ["Traceburn", "Tommy Tran", "OpenAI", "Anthropic", "Claude Haiku"], "alternates": {"html": "https://wpnews.pro/news/traceburn-a-local-profiler-that-found-69-avoidable-agent-spend", "markdown": "https://wpnews.pro/news/traceburn-a-local-profiler-that-found-69-avoidable-agent-spend.md", "text": "https://wpnews.pro/news/traceburn-a-local-profiler-that-found-69-avoidable-agent-spend.txt", "jsonld": "https://wpnews.pro/news/traceburn-a-local-profiler-that-found-69-avoidable-agent-spend.jsonld"}}