Skip to content

Courses / GenAI & LLM / Module 11

Module 11: LLMOps and observability: tracing, cost, prompt versions

8 h · theory 2 · hands-on 3 · project 2 · revision 1

You will be able to

  • Trace every LLM call with inputs, outputs, cost and latency
  • Version prompts, datasets and models
  • Set alerts on quality and cost
  • Run A/B tests on prompts

Capstone increment: Langfuse (or Phoenix) tracing on every request, with a cost dashboard and an alert.

Job-description skills: LLMOps, MLflow, Observability · Lab tools: langfuse, arize-phoenix, mlflow

1. Trace every call

A trace records one request end to end as a tree of spans: parsing, retrieval, each model call, validation, retries. Each span carries inputs, outputs, latency, tokens, cost, model and prompt version. When someone says “the model got worse yesterday”, traces turn that into a query instead of an argument.

Langfuse and Arize Phoenix are open-source tracing tools built for LLM apps, and both can be self-hosted, which matters when prompts contain customer data. Both accept OpenTelemetry data, so you aren't locked in.

TracePOST /extractSpan: parse120 msSpan: promptextract@v7Span: LLM1.9 s, 2.1k tokSpan: validate1 retryCost₹ per documentLatencyp50 / p95Qualityscores + feedbackVersionsprompt, model, dataOne trace per requestWhat you can answer from traces
Without traces, ‘the model got worse’ is a guess. With them, it’s a query.
In production: Traces contain prompts, which contain personal data. Apply the same retention limits and access control to them as to your database (Module 12).

2. Version everything that changes behaviour

Four things change what your system does: code, prompts, models and data (golden sets, fine-tuning sets, retrieval indexes). Version all four and record the versions on every trace. Prompts can live in Git (simplest) or in a prompt registry such as Langfuse prompt management, which lets non-engineers edit them with history.

Pin model versions explicitly (a dated snapshot, not “latest”). Providers update aliases, and an unpinned model can change behaviour overnight without any change on your side.

3. What to monitor and alert on

Track per day and per version: request volume, error rate, p50 and p95 latency, tokens and cost per business unit (per document), and quality signals: validation failures, retries, review rate, user feedback, and online eval scores on a sample of traffic.

Alert on changes, not absolute thresholds you picked on day one: cost per document 30% above its weekly average, review rate jumping, a spike in validation failures after a deploy. Every alert needs an owner and a first step to take.

Common misconception: “Monitoring means uptime.” An LLM service can return 200 OK all day while answering badly. Quality signals matter as much as errors and latency.

4. A/B tests and staged rollouts

Offline evals tell you whether a change is safe to try; real traffic tells you whether it's better. Route a share of traffic to the new prompt or model, compare a business metric (documents accepted without review, answers marked helpful) and check the difference is larger than chance before switching everyone over.

For risky changes, roll out gradually (5%, 25%, 100%) with automatic rollback if the alerts fire. Keep the old prompt version one config change away.

5. Closing the loop

Observability feeds everything else: bad traces become golden-set cases (Module 8), reviewed corrections become fine-tuning data (Module 9), cost hotspots become routing rules (Module 10). Schedule a weekly review of the worst traces; it is the cheapest quality improvement process you will have.

Hands-on: coding window

The coding window and the full VS Code lab are available after you sign in.

Sign in to code

Labs

Lab 11.1: Self-host Langfuse

Run Langfuse with Docker Compose, instrument the capstone with the Langfuse SDK (or OpenTelemetry), and trace 50 extraction requests including retries.

Expected: Traces show nested spans with tokens, cost, latency and prompt version for every request.

Lab 11.2: Dashboard and alert (capstone increment)

Build a dashboard of cost per document, p95 latency and review rate per day and prompt version. Add one alert (for example, cost per document 30% over the weekly average) that posts to email or a chat channel.

Expected: A screenshot of the dashboard and a test that fires the alert from synthetic data.

Lab 11.3: Prompt A/B test

Serve two prompt versions 50/50 with a stable per-document assignment. After 400 documents, compute the difference in acceptance rate and its significance.

Expected: A decision (ship, keep testing, or drop) backed by the numbers.

Go deeper

Videos

Further reading

GitHub repositories

  • langfuse/langfuse: The self-hosting docker-compose file and the Python SDK decorators for tracing functions.
  • Arize-ai/phoenix: OpenTelemetry-based tracing and the built-in evals; compare its approach with Langfuse.
  • mlflow/mlflow: Tracking runs and the model registry: how to version fine-tuned models and their eval scores.

Checkpoint quiz

1. Your service returns 200 OK for every request, but users say answers got worse. What would have caught this?
2. Why pin a dated model version instead of a ‘latest’ alias?
3. What should every trace record so you can explain a quality change?
4. An A/B test shows v8 at 89.1% vs v7 at 86.0%. What else do you need before shipping?
5. Which alert is most useful?

Interview questions

  1. What would you put on the dashboard for an LLM service, and why?
  2. Quality dropped overnight and nobody deployed anything. How do you investigate?
  3. How do you version prompts, and who should be allowed to change them in production?
  4. How would you A/B test a new prompt safely?
  5. How do you handle personal data inside traces?

Ask the professor

Sign in to ask questions about this module.

Discussion

Community discussion appears here once giscus is configured (see README).