Production
Monitoring
Production is watched from three angles, and each tool answers a different question: Grafana tells you something is wrong, Sentry tells you what broke, and Langfuse tells you what the AI did.
Metrics: Prometheus and Grafana
They run in the Docker stack and answer: how is the system doing?
- Collection: the API exposes request metrics, and Prometheus collects them every five seconds. Metrics are labelled by route, not by raw URL, so the number of series stays small.
- Dashboard: Grafana shows request rate, 5xx error percentage, requests in progress, whether Prometheus can reach the API, latency percentiles, requests by route and status, and the API's CPU and memory.
- Access: Grafana is public behind its login. Prometheus is not exposed.
Errors: Sentry
Hosted by Sentry. It answers: what broke, and where in the code?
- The API reports unexpected server errors with the stack trace, and similar errors are grouped into one issue.
- No personal data is sent, and no performance tracing.
- The error response includes a reference that matches the event in Sentry.
- Events carry an environment tag, which separates production, development and evaluation.
AI traces: Langfuse
Hosted by Langfuse. It answers: what did the AI do? Where Prometheus counts requests, Langfuse looks inside each answer.
- One trace per chat turn: a trace is the full record of one turn. It holds the question, the streamed answer, and the user and chat it belongs to.
- Spans: a trace is made of spans, the individual steps inside it. Each span has its own input and its own output. The classifier, router, SQL agent and generator each appear as a span, with their model calls inside.
- AI metrics on every trace, filterable in Langfuse:
- the pipeline path the turn took
- time to first token and total time
- input and output tokens, and the cost in dollars
- how many pieces were consulted and how many were cited
- the reason, when the SQL step failed
- the prompt versions used
- Automatic evaluators: Langfuse offers evaluators that score traces by
themselves. In this project they are set up for the classifier, the agent that
decides whether a question is about pottery.
- A blind judge: a model reads the question and the earlier conversation, without the classifier's answer, and decides whether the question is about pottery. It runs on a sample of the traffic.
- Three detectors: simple rules check every classification decision and flag the suspicious ones: a refused follow-up question, an accepted request to change entries, and a refused question about the user's own data. A flag is a suspicion to review, not a verdict.
- Review loop: unlike the other monitoring tools, Langfuse lets you score
what it records, automatically and by hand.
- Review: a person looks at the traces where the judge and the classifier disagree, or where a detector fired, and decides who was right. A person can also score a trace by hand.
- Misalignment: when the human verdict differs from the automatic score, either the classifier or the evaluator is wrong, and both are worth fixing.
- Next cycle: a confirmed miss becomes a new example in the classifier's evaluation, which then checks the next version. Only human-confirmed verdicts become examples, never the judge's scores.
- How the evaluators were built and checked is described in Evaluation.
- Environment tag: it keeps production traffic apart from development and evaluation runs.
Access
Sentry and Langfuse are hosted outside the server. The server sends data to them, so nothing needs to be exposed. You open their web interfaces.