Adding Logging and Metrics
See what your app is doing.
Adding Logging and Metrics is a free Vibe Coding lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Vibe Coding learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
You Can't Fix What You Can't See
When a vibe-coded app misbehaves in production, you're blind unless you instrumented it. Logs, metrics, and traces are the three lenses that let you see inside a running system.
This lesson uses your AI assistant to add observability that answers real questions instead of producing noise.
Logs, Metrics, Traces
Each pillar answers a different question. Logs tell you what happened in one event. Metrics tell you how often and how much over time. Traces tell you how a single request moved across services.
Knowing which to reach for keeps your instrumentation focused and your bills sane.
Explain for my app which of logs, metrics, or traces best answers each question: 'why did this one checkout fail', 'is error rate rising', and 'which step makes this request slow'. Then recommend what to instrument first.Make Logs Structured
A wall of free-text print statements is unsearchable. Structured logs emit JSON with consistent fields, so you can filter by user, route, or status in seconds.
Ask the assistant to replace ad-hoc logging with a structured logger and a standard field schema.
Replace all console prints with a structured JSON logger. Every log line should include timestamp, level, request_id, route, and duration_ms where relevant. Show the logger setup and convert three existing log statements as examples.Correlate With Request IDs
A single user action can touch many log lines and several services. Without a shared identifier you can't tell which lines belong together.
Generate a request ID at the edge and thread it through every log and downstream call so one trace tells the whole story.
Add middleware that assigns a unique request_id to every incoming request, attaches it to all logs for that request, and forwards it as a header to downstream services. Show how I would later filter logs by a single request_id.Choose Log Levels Wisely
Logging everything at one level is the same as logging nothing useful. Levels let you stay quiet in normal operation and verbose when investigating.
Have the assistant assign sensible levels and make verbosity configurable per environment without a redeploy.
Audit our log statements and assign appropriate levels: debug for development detail, info for business events, warn for recoverable issues, error for failures. Make the active level configurable via an environment variable so production can run at info and drop to debug temporarily.Never Log Secrets
Logs are read by many people and often shipped to third-party tools. A password, token, or full credit-card number in a log line is a breach waiting to happen.
Ask the assistant to add redaction so sensitive fields are masked before anything is written.
Add automatic redaction to the logger so fields like password, token, authorization, and card_number are masked before output. Scan existing log calls for places that currently log full request bodies and fix them.Emit the Golden Signals
For metrics, start with the four golden signals: latency, traffic, errors, and saturation. They cover most of what you need to know about service health.
Let the assistant instrument these as counters and histograms you can graph and alert on.
Instrument the four golden signals for the HTTP layer: request latency as a histogram, request count by route and status, error rate, and a saturation gauge like active connections. Expose them on a /metrics endpoint in a format my monitoring stack can scrape.Track Business Metrics Too
System health is only half the picture. Signups, checkouts, and failed payments tell you whether the product is actually working for users.
Ask for custom metrics on the events that matter to the business so a silent revenue drop becomes visible immediately.
Add custom business metrics: a counter for completed checkouts, a counter for failed payments tagged by failure reason, and a gauge for active subscriptions. Make sure these are cheap to emit and won't slow the request path.Add Distributed Tracing
When a request fans out across services and a database, a trace shows the timeline of every span so you can see exactly where the time went.
Have the assistant wire up a tracing standard so spans propagate automatically across service boundaries.
Add OpenTelemetry tracing to the API and worker. Auto-instrument HTTP and database calls, propagate trace context across the queue, and export spans to our collector. Show me what a single checkout request's trace would look like.Build a Dashboard That Answers Questions
Raw metrics are useless until someone can read them at a glance. A good dashboard is organized around the questions you'll ask during an incident.
Ask the assistant to define panels for error rate, p95 latency, and the key business counters, with thresholds marked.
Design a dashboard layout for this service: panels for request rate, error rate, p95 and p99 latency, queue depth, and completed checkouts. For each panel, suggest a threshold line that would indicate trouble worth investigating.Signal, Not Noise
The goal of observability is fast answers, not data hoarding. Too many logs and metrics cost money and bury the signal you need.
Periodically prune what you never query, keep field names consistent, and make sure every metric maps to a question someone actually asks.
Quick Check
Test your understanding of logging and metrics.
Recap
Observability rests on three pillars: structured, correlated, redacted logs; the golden-signal and business metrics that surface trends; and distributed traces that show a request's full path.
Prompt your assistant to instrument each deliberately, build dashboards around real questions, and prune anything that produces noise instead of answers.
Frequently asked questions
Is the “Adding Logging and Metrics” lesson free?
Yes — the full text of “Adding Logging and Metrics” is free to read here on the web, and the Vibe Coding course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Vibe Coding course, upgrade to CoddyKit PRO.
What will I learn in “Adding Logging and Metrics”?
See what your app is doing. You practise Vibe Coding with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Vibe Coding?
No prior experience is required. Vibe Coding on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Adding Logging and Metrics” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Vibe Coding lesson?
Yes. Every Vibe Coding lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- From Prototype to Product
- Performance by Prompt
- Adding Logging and Metrics
- Responding to Incidents