Install any skill in seconds. Free to start, no credit card required.
Get Started Free →jpoindexter/llm-observability-and-cost
Reference-grade guide to production LLM observability and cost attribution — distributed traces and spans for multi-step agents, OpenTelemetry GenAI semantic conventions, the metrics/percentiles that matter, drift detection with online evals, and per-feature/tenant/user cost attribution via span metadata. Real tooling (LangSmith, Langfuse, Phoenix, Helicone, OTel), tables, do/don't, and the failure modes that leave you blind.
Passed 19 of 22 test cases with the skill, and 16 of 22 without it.
3 fixed16 passed either way3 still failing0 broke
Tokens, turns and time describe resource use, not a dollar price.
One of 3 test cases the skill fixed. Same model, same prompt, with and without the skill.
We noticed that Feature A has a low average cost per LLM call ($0.01), but it frequently fails and retries up to 5 times before giving up. What unit metric should we compute to reflect the true financial efficiency of Feature A?
| Checked | Without skill | With skill |
|---|---|---|
| Computes cost per successful outcome by joining span cost with call success evaluation | Missed | Passed |
The instructions your model reads when the skill loads.
You cannot debug, optimize, or cost what you cannot see. Traditional APM assumes deterministic, cheap, fast functions. LLM systems break all three assumptions: the same input yields different outputs, a single user request fans out into a dozen model and tool calls, every call costs real money proportional to tokens, and output quality silently drifts as models, prompts, and data change underneath you. Observability for LLM systems is therefore a first-class engineering discipline, not a dashboard you bolt on later — it is the only way to answer "why did this request fail," "which feature is burning our budget," and "did quality regress after the deploy."
How to use this skill: instrument every LLM call as a span inside a request-level trace (§2), attach the metadata tags that make cost and quality attributable (§5), emit the metrics in §3, watch for drift in §4, and debug from traces in §6. Treat the failure modes in §9 as a pre-ship checklist.
Concretely, what blindness costs you. A support agent starts giving wrong answers after a Tuesday deploy. Without traces: you know error rate is flat (it didn't error, it answered confidently and wrongly), you can't reproduce the complaint (different output every run), you can't tell if it was the prompt edit, a model snapshot rollover, or stale retrieval, and you have no idea the bad path is also the most expensive one because it retries internally. With traces + tags + online evals: the faithfulness eval dropped at 14:02, every failing trace shows an empty retrieval span, the prompt-version stamp points at the deploy, and the cost-by-feature chart already flagged the spike. Same incident, minutes vs. days.
The discipline in one line: capture every call with enough structure (trace shape) and enough metadata (tags) that you can later ask why it failed and what it cost — broken down by the dimensions your business cares about.
A trace is one end-to-end request (a user turn, an API call, a scheduled job). A span is one unit of work inside it. Model the request as a tree of nested spans so latency, cost, and errors roll up naturally.
trace: chat-request (user=u_42, tenant=acme, feature=support-copilot, session=s_9)
├─ span: agent.plan (llm) 120 tok in / 40 out 180ms
├─ span: retrieval.search (vector) k=8, 0.85 top score 45ms
├─ span: tool.get_order_status (tool) args={id:...} ok 210ms
├─ span: agent.synthesize (llm) 1340 tok in / 280 out 1.9s
│ └─ span: subagent.summarize (llm) 900 tok in / 120 out 900ms
└─ span: guardrail.check (eval) pass 30ms
Capture on every span: model + version, prompt (messages/template + resolved variables), response/completion, token counts (input / output / cached separately — cached reads are priced lower), latency (TTFT and total), computed cost, tool args + results, error type, and the metadata block (§5). For retrieval spans also capture the query, the k documents returned, and their scores; for tool spans, the raw arguments and return value.
Nesting & correlation. Propagate a single trace_id across the whole agent run and parent each span to its caller. When a sub-agent or a separate service is invoked, pass the trace context through (HTTP header / message field) so the child spans attach to the same trace. Without this you get orphaned fragments and cannot follow one request.
Instrumentation pattern. Wrap each unit of work in a span context — a decorator/with block — that opens the span, records inputs, runs the call, records outputs + usage + cost on the way out, and closes it. The pattern:
test cases passed, vs 16 / 22 without
More skills from the same source and nearby in the registry, with their headline benchmark lift.