Dodawanie logowania i metryk
Zobaczy Pan/Pani, co robi aplikacja.
Dodawanie logowania i metryk to bezpłatna lekcja Vibe Coding na CoddyKit. To lekcja 3 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Vibe Coding, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Vibe Coding zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
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.
Często zadawane pytania
Czy lekcja „Dodawanie logowania i metryk” jest bezpłatna?
Tak — pełny tekst „Dodawanie logowania i metryk” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Vibe Coding, przejdź na CoddyKit PRO. Kurs Vibe Coding zawiera 4 lekcji w sumie.
Co nauczysz się w „Dodawanie logowania i metryk”?
Zobaczy Pan/Pani, co robi aplikacja. Ćwiczysz Vibe Coding z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć Vibe Coding?
Nie wymagamy żadnego doświadczenia. Vibe Coding w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 3 z 4.
Ile czasu zajmuje lekcja „Dodawanie logowania i metryk”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji Vibe Coding?
Tak. Każda lekcja Vibe Coding zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Od prototypu do produktu
- Optymalizacja wydajności za pomocą promptu
- Dodawanie logowania i metryk
- Reagowanie na incydenty