agentleFS
krzysztofsurdykrzysztofsurdy/code-virtuoso/skills/ai/llm-observability/SKILL.md

llm-observability

Skill36 starsChanged 6 days agoMITView on GitHub

Instrument LLM apps and agents with OpenTelemetry GenAI traces, token and cost attribution, sampling, and PII-safe capture. Use when adding tracing, debugging agent runs, or cutting LLM cost and latency.

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use percentiles for latency and per-run totals for cost.

    line 66
  2. Distinctive:

    Run the eval suite with the same instrumentation, tagged as an eval run with a case id, so offline and production data share one shape.

    line 113

≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

LLM observability

An LLM app fails in ways that logs and error rates do not show. The request returns 200, the answer is wrong, the agent looped nine times, and the bill doubled. To see these you need a trace of every model call and tool call, token counts on each, and a way to connect the trace to quality checks. This skill covers how to record that data, what to measure, and what to keep out of it.

Core Principles

PrincipleMeaning
Trace the whole runOne trace per user request or agent run, with a span per model call and per tool call. A flat log of prompts cannot show where a run went wrong.
Concepts over attribute namesThe OpenTelemetry GenAI conventions are still in Development status and names change. Learn the shape, then take exact names from the current spec.
Tokens are the source of truth for costRecord input, output, cached, and reasoning tokens on every call. Compute money later from a versioned price table.
Measure before optimizingCache hit ratio, time to first token, and step count are numbers you read from traces. Do not tune on a guess.
Content is opt-inPrompts and completions hold user data. Capture them only on purpose, with redaction, retention, and access rules.
Keep the interesting tracesSample so that errors, slow runs, costly runs, and bad-feedback runs are always kept.
Close the loopProduction traces feed error analysis and the eval datasets. See llm-evals.

What a trace looks like

invoke_agent support-bot                     (one user request)
  chat model-x                               (model call 1: plans, picks a tool)
  execute_tool search_orders                 (tool call)
  chat model-x                               (model call 2: reads result)
  execute_tool issue_refund                  (tool call)
  chat model-x                               (model call 3: final answer)

Span types to emit:

SpanCoversKey data
Workflow or agent runOne request through one agent or pipelineAgent name, conversation id, step count, stop reason, total tokens
Model callOne request to a modelProvider, requested and actual model, token counts (input, output, cached read and write, reasoning), finish reason, parameters, error type
Tool callOne tool executionTool name, call id, duration, error. Arguments and results are content, so opt-in
Retrieval, embedding, guardrailSupporting stepsDuration, counts, index or model used

Parent-child links matter. A tool span nested under the agent span lets you see which step was slow or failed. Put the application's own fields on the run span: feature name, prompt version, release version, a hashed user or tenant id, experiment arm.

Details on the OpenTelemetry conventions and the metrics they define: otel-genai.

Standards status

  • The OpenTelemetry GenAI semantic conventions have Development status. They are not stable. Operation names, attribute names, and metric names have changed and can change again.
  • They now live in the open-telemetry/semantic-conventions-genai repository. The older pages on opentelemetry.io say they moved.
  • Pin your instrumentation library version. Read its changelog before upgrading. Isolate GenAI attribute names in one module or collector config so a rename is a one-place change.
  • Your backend may map several conventions (GenAI, OpenInference, vendor-specific). Check that token and cost fields land where you expect after you send a test trace.

What to measure

QuestionMeasureFrom
How much does a feature cost?Tokens by type, times the price table, grouped by feature and prompt versionModel call spans
Is caching working?Cache hit ratio, cache write shareCached token counts
Is it slow for the user?Time to first token, total duration, p50 and p95Streaming timestamps, span duration
Is an agent wandering?Steps per run, tool calls per run, repeated identical tool calls, stop reasonAgent span and children
Which tool is the problem?Tool duration and error rate per toolTool spans
Did a change hurt quality?Eval scores and user feedback per prompt versionScores attached to traces
Are we hitting limits?Rate-limit errors, retries, queue timeError type, retry count

Use percentiles for latency and per-run totals for cost. A mean hides the 5 percent of runs that loop and cost ten times the average. Details: cost-and-latency.

Cost and latency levers

Prompt caching and batching are the two big levers. Both are measurable from traces.

LeverWhen it helpsHow to measure
Prompt cachingLarge stable prefix (system prompt, tool definitions, documents) reused across requestsCache hit ratio: cached read tokens divided by all input tokens, per prompt version
Batch APIWork that can wait: evals, backfills, bulk classificationShare of tokens sent by batch, turnaround time, expiry and failure rate
Smaller model for easy stepsRouting, extraction, classificationCost and eval score per step, before and after
Shorter contextLong histories and big tool resultsInput tokens per call over a run
Fewer stepsAgents that retry or re-readSteps per run

Provider price multipliers and rules differ by model and change over time. Read the current provider docs for the model in use, see cost-and-latency.

Sampling

Head sampling decides when the trace starts and cannot know whether the run will fail or be slow. Tail sampling decides after the trace is complete. For LLM apps use tail sampling in a collector: keep every trace with an error, high latency, high cost, a human flag, or negative feedback, and a random slice of the rest as a baseline. Compute rates and cost totals from metrics that see all traffic, so sampling does not skew them. See privacy-and-sampling.

Privacy

  • Message content, system prompts, tool arguments, and tool results are sensitive. The conventions mark message content as opt-in. Leave it off by default and turn it on per environment.
  • Redact before data leaves your process or at a collector you control: emails, phone numbers, names, account numbers, secrets, tokens.
  • Hash user identifiers. Never use a raw email as a trace attribute.
  • Set retention shorter for content than for metadata. Restrict who can open traces.
  • Remember the backend is a data processor. Pick its region and contract to match your data rules.

Full checklist in privacy-and-sampling. For wider security concerns, use security.

Backends

Most LLM observability tools accept OTLP, so you can instrument once and choose a backend later, or send to two through a collector.

BackendOTLP support
LangfuseOTLP over HTTP, JSON or protobuf. No gRPC. Basic auth with project keys
LangSmithOTLP endpoint. API key in headers. Maps GenAI conventions and several vendor formats
PhoenixOTLP. Built around OpenInference instrumentation. Self-hostable
BraintrustOTLP over HTTP with bearer auth and a project header

Endpoints, headers, and regions change. Copy them from each vendor's current docs. Details and the eval loop: backends-and-eval-loop.

Linking traces to evals

  1. Give every production trace a stable id and a release and prompt version.
  2. Sample traces for human review and add confirmed failures to the regression dataset, with the trace id as the source.
  3. Run the eval suite with the same instrumentation, tagged as an eval run with a case id, so offline and production data share one shape.
  4. Attach scores (human labels, judge verdicts, user feedback) to traces and filter by them.
  5. Compare prompt versions on the same metrics: cost, latency, steps, score.

Quality checklist

  • One trace per request, a span per model call and tool call, parent links correct
  • Input, output, cached, and reasoning tokens recorded on each model call
  • Cost computed from a versioned price table, grouped by feature and prompt version
  • Time to first token and total latency tracked as percentiles
  • Agent runs record step count, tool call count, and stop reason, with a step limit
  • Message content capture is off by default, redaction runs before export
  • User ids hashed, retention and access rules written down
  • Tail sampling keeps errors, slow, costly, and flagged traces
  • GenAI attribute names confined to one place, instrumentation version pinned
  • Test trace sent to the backend and the token and cost fields checked
  • Production traces feed the eval dataset on a schedule

Reference Files

ReferenceContents
otel-genaiThe GenAI convention model: operations, span hierarchy, attributes by concept, metrics, status and how to cope with change
cost-and-latencyCost attribution, price tables, caching and batching measurement, latency and agent-loop metrics
privacy-and-samplingContent capture, redaction, retention, head and tail sampling for LLM traces
backends-and-eval-loopOTLP backends, collector setup, mapping checks, connecting traces to eval datasets

Integration with Other Skills

SituationRecommended Skill
Reading traces to find failures and build gradersllm-evals
General latency and bottleneck diagnosisperformance
Treating PII, secrets, and access controlsecurity
Instrumenting a Vercel AI SDK appvercel-ai-sdk
A slow or looping agent run to diagnosedebugging
Confirming instrumentation works before shippingverification-before-completion

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.