principletypescriptModerate
LLM observability requires tracing full prompt and response for debugging
Viewed 0 times
observabilitytracinglangsmithlangfuseheliconeprompt-loggingdebugging
Problem
When an LLM feature produces a bad output in production, debugging is impossible without knowing the exact prompt that was sent, the full response received, and the latency of each step. Standard application logs capture neither.
Solution
Use an LLM observability platform (LangSmith, Langfuse, Helicone, or Braintrust) that automatically captures full prompt/response traces with metadata. At minimum, log the full messages array, completion response, latency, token usage, model, and a trace ID that links to the user session.
Why
LLM bugs are prompt bugs. You cannot reproduce or fix a bad output without the exact prompt that caused it. Observability tools store this automatically and provide diff views across prompt versions.
Gotchas
- Full prompt logging raises privacy concerns — redact PII before logging or use a self-hosted solution
- Sampling traces in high-volume systems reduces cost but may miss rare failure modes
- Structured trace metadata (user_id, feature, version) is essential for filtering — log it on every trace
Code Snippets
Basic LLM call with structured observability logging
const traceId = crypto.randomUUID();
const start = Date.now();
const response = await openai.chat.completions.create({ model, messages });
logger.info('llm_trace', {
trace_id: traceId,
model,
messages,
response: response.choices[0].message,
latency_ms: Date.now() - start,
tokens: response.usage,
user_id: ctx.userId,
});Context
Operating LLM features in production with quality and debugging requirements
Revisions (0)
No revisions yet.