Chapter 14: Logging and Light Observability
14.8 Light observability vocabulary
Why: the problem
Suppose Hotstar streams a cricket final to millions of people. The team must answer three questions all night. Is it slow or failing right now? Where is it failing? Why is it failing? No single tool answers all three. Metrics are numbers over time, like errors per minute. They answer "is something wrong now?". Traces follow one request across services with timings. They answer "where is it slow?". Logs are detailed events. They answer "why?". Together they are called observability, the three pillars. Words like SLI, SLO, golden signals and OpenTelemetry appear in every DevOps interview. In this lesson we make each one real with a small runnable example.
What we will build
You will turn a log into a metric with a CloudWatch metric filter, expose a Prometheus metric from Python, send one trace with OpenTelemetry to the console, and write the four golden signals for a real service.
What: every term in plain English
- Observability — How well you can understand what a system is doing from its outputs.
- Logs — Detailed events with time and text. They tell why.
- Metrics — Numbers over time, like CPU percent or requests per second. They tell what and when.
- Traces — The path of one request through services, with time per step (spans). They tell where.
- Golden signals — Latency, traffic, errors, saturation. Google SRE book.
- SLI — Service level indicator. A measured number, like 99.95 percent of requests OK.
- SLO — Service level objective. The target, like 99.9 percent OK over 30 days.
- OpenTelemetry (OTel) — The open standard and SDKs for logs, metrics and traces.
How: step by step
-
Create a metric filter
aws logs put-metric-filter --log-group-name /loglab/checkout --filter-name errors --filter-pattern "ERROR" --metric-transformations metricName=CheckoutErrors,metricNamespace=LogLab,metricValue=1What it does: Every ERROR line adds 1 to a metric.
Output
(no output) -
Send test errors
for i in 1 2 3; do aws logs put-log-events --log-group-name /loglab/checkout --log-stream-name s1 --log-events timestamp=$(date +%s000),message="ERROR pay failed $i"; sleep 1; doneWhat it does: Three error events.
Output
"nextSequenceToken": ... -
Read the metric
aws cloudwatch get-metric-statistics --namespace LogLab --metric-name CheckoutErrors --start-time $(date -u -d "-10 min" +%FT%TZ) --end-time $(date -u +%FT%TZ) --period 300 --statistics SumWhat it does: The log became a number.
Output
"Sum": 3.0 -
Run the Prometheus example
pip install -q prometheus-client && python metrics.pyWhat it does: Starts a metrics page on port 8000.
Output
serving metrics on :8000 -
Read metrics
curl -s localhost:8000/metrics | grep orders_totalWhat it does: Prometheus text format.
Output
orders_total{status="ok"} 7.0 -
Run the trace example
pip install -q opentelemetry-sdk && python trace_demo.pyWhat it does: Prints spans to the console.
Output
"name": "charge-card" ...
Example 1: Prometheus metrics from Python: the golden signals
Stack. Python, prometheus-client
Goal. Prometheus metrics from Python: the golden signals.
metrics.py
import random, time
from prometheus_client import Counter, Histogram, start_http_server
ORDERS = Counter("orders_total", "Orders handled", ["status"])
LATENCY = Histogram("order_seconds", "Order latency in seconds")
start_http_server(8000)
print("serving metrics on :8000")
while True:
with LATENCY.time():
time.sleep(random.uniform(0.05, 0.3))
ORDERS.labels(status="error" if random.random() > 0.9 else "ok").inc()
What each line does
Counter— A number that only goes up: traffic and errors.labels(status=...)— Split one metric by a small set of values.Histogram— Buckets of timings: latency and percentiles like p95.start_http_server(8000)— Prometheus scrapes http://host:8000/metrics.LATENCY.time()— Measures how long the block took.
Green output
$ curl -s localhost:8000/metrics | grep -E "orders_total|order_seconds_count"
orders_total{status="ok"} 41.0
orders_total{status="error"} 5.0
order_seconds_count 46.0
Expected result. Traffic is 46, errors 5, latency is in the histogram. Saturation comes from CPU and memory metrics.
Example 2: One trace with OpenTelemetry
Stack. Python, OpenTelemetry SDK
Goal. One trace with OpenTelemetry.
trace_demo.py
import time
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor, ConsoleSpanExporter
provider = TracerProvider()
provider.add_span_processor(SimpleSpanProcessor(ConsoleSpanExporter()))
trace.set_tracer_provider(provider)
tracer = trace.get_tracer("checkout")
with tracer.start_as_current_span("checkout") as root:
root.set_attribute("order.id", "991")
with tracer.start_as_current_span("check-stock"):
time.sleep(0.05)
with tracer.start_as_current_span("charge-card"):
time.sleep(0.4)
What each line does
TracerProvider— The OTel engine that makes spans.ConsoleSpanExporter— Print spans on screen. In real life export to Jaeger, Tempo or X-Ray.start_as_current_span— One step of work with start and end time.Nested with blocks— Child spans. They share the same trace id.set_attribute— Extra data, like the order id.
Green output
{
"name": "charge-card",
"context": { "trace_id": "0x6f1c2a9e4b7d4c1e9a3f2d8e1b7c5a90", "span_id": "0x1a2b..." },
"parent_id": "0x9c8d...",
"start_time": "2026-10-25T06:00:00.051Z",
"end_time": "2026-10-25T06:00:00.452Z"
}
Expected result. charge-card took 400 ms of the 450 ms total. The trace shows where time goes.
Example 3: Write SLI and SLO for a real service
Stack. SRE practice, CloudWatch Logs Insights
Goal. Write SLI and SLO for a real service.
slo.md
Service: Zomato-like checkout API
Golden signals
- Latency: p95 of POST /pay under 800 ms
- Traffic: requests per second on /pay
- Errors: percent of /pay responses with status 5xx
- Saturation: DB connection pool used percent, CPU percent
SLI: good requests / all requests, good = status below 500 and under 800 ms
SLO: 99.9 percent good over 30 days
Error budget: 0.1 percent = about 43 minutes of bad time per 30 days
Logs Insights to measure the SLI
filter path = "/pay"
| stats sum(status >= 500 or ms > 800) as bad, count(*) as total by bin(1h)
| sort bin(1h) desc
What each line does
p95— 95 percent of requests are faster than this.SLI— What we measure.SLO— The target we promise ourselves.Error budget— How much failure is allowed. If spent, slow down releases.stats sum(...) as bad— Counts bad requests per hour from logs.
Green output
bin(1h) bad total
2026-10-25 10:00 14 52100
2026-10-25 09:00 3 49800
Expected result. 14 of 52100 is 99.97 percent good. Within the 99.9 SLO.
Verify: did it work?
-
Check the metric filter
aws logs describe-metric-filters --log-group-name /loglab/checkout --query "metricFilters[].filterName"What it does: Your filter exists.
Output
[ "errors" ] -
Check Prometheus page
curl -s -o /dev/null -w "%{http_code}" localhost:8000/metricsWhat it does: Should be 200.
Output
200
When it is red 1
get-metric-statistics returns "Datapoints": []
Cause. Wrong time range, or events were sent before the filter existed.
Fix, step by step
- Metric filters count only new events after creation.
- Send new ERROR events.
- Use a wider time range and --period 60.
When it is red 2
OSError: [Errno 98] Address already in use (port 8000)
Cause. Another program uses port 8000.
Fix, step by step
- Stop it, or use start_http_server(8001).
- Curl the new port.
When it is red 3
ModuleNotFoundError: No module named 'opentelemetry'
Cause. SDK not installed in this Python.
Fix, step by step
- pip install opentelemetry-sdk
- Check: python -c "import opentelemetry"
- Run again.
Cleanup
-
Delete the metric filter
aws logs delete-metric-filter --log-group-name /loglab/checkout --filter-name errors ; pkill -f metrics.pyWhat it does: Removes the lab filter.
Output
(no output)
Ravindra Bagale's Tip
Metrics say something went wrong, traces say where, and logs say why. All three together are observability.
Metrics सांगतात काहीतरी चुकलं, traces सांगतात कुठे, आणि logs सांगतात का. तिन्ही मिळून observability.
Metrics बताते हैं कुछ गलत हुआ, traces बताते हैं कहाँ, और logs बताते हैं क्यों. तीनों मिलकर observability.
Practice tasks
Easy Name tools per pillar
Why: Interviews ask this.
What to do: Write one tool per pillar.
- Metrics: Prometheus or CloudWatch. Traces: Jaeger or X-Ray. Logs: Loki or CloudWatch Logs.
Check: Three correct pairs.
Medium Alarm on the log metric
Why: Numbers become alerts.
What to do: Create a CloudWatch alarm on CheckoutErrors Sum >= 5 in 5 minutes.
- aws cloudwatch put-metric-alarm ...
Check: Alarm goes to ALARM after 5 errors.
Hard Trace id in logs
Why: Link logs and traces.
What to do: Print the current OTel trace id in your log lines.
- trace.get_current_span().get_span_context().trace_id
Check: Log line and trace share the same id.
Easy Say observability in two lines
Why: If you can say it simply, you understand it. Juniors and interviewers both want the short version first.
What to do: Write two short lines about observability for a fresher who knows only Linux, Git and Docker basics.
- Write the problem it solves.
- Write the one command or config line you use for it.
- Read it aloud to a friend.
Check: A fresher understands it without asking a question.
Easy Keep a throwaway log lab
Why: Practice needs a lab you can break. If it gets messy, you delete the containers and start again.
What to do: Run a small app in Docker that prints logs every second.
- docker run -d --name ticker busybox sh -c "while true; do date; sleep 1; done"
- docker logs -f ticker
- Press Ctrl+C, then docker rm -f ticker.
Check: You see one new time line every second.
Medium Do it on a second stack
Why: Logging ideas must work for Python, Node.js and Java. Only the library changes.
What to do: Repeat this lesson with a different language than the one you used first.
- If you used Python, use Node.js or Spring Boot now.
- Keep the same field names: time, level, msg, request_id.
- Compare the two outputs side by side.
Check: Both apps print the same fields in the same shape.
Medium Break it on purpose
Why: You must know the red error by face. In a real outage there is no time to read slowly.
What to do: Cause one error from the "When it is red" part of this lesson and fix it.
- Follow the error section.
- Copy the exact message into your notes.
- Write the fix in one line.
Check: You fixed it using only the steps, without searching the web.
Medium Write a one-page runbook
Why: At 2 a.m. nobody remembers log commands. A short page saves the on-call person.
What to do: Write a one-page runbook for this lesson.
- Title, when to use, exact commands, how to check, how to undo.
Check: A teammate can follow it alone.
Hard Explain it like an interview
Why: Interviewers want real stories, not definitions.
What to do: Record a 60 second answer about this lesson.
- Say the problem, the command you ran, the log line you found and the fix.
Check: Your answer has a real command and a real log line.
Hard Draw the flow top to bottom
Why: A drawing shows where a log line is born and where it ends up.
What to do: Draw this lesson as boxes from top to bottom.
- Start at the user click, go through the app, the log driver or agent, and end at the place you search.
Check: Each box matches a real command or file in this lesson.
Homework: try at home
Try at home
At home, write the four golden signals and one SLO for a service you know, like a college results website on results day.
Recap
- Observability has three pillars: logs, metrics, traces.
- Metric filters turn log lines into numbers.
- Golden signals: latency, traffic, errors, saturation.
- SLI is measured, SLO is the target, error budget is the gap.
- OpenTelemetry is the common standard.
FAQ
Is monitoring the same as observability?
Monitoring watches known problems. Observability helps with new unknown ones too.
Do small teams need traces?
Start with logs and metrics. Add traces when you have many services.
What is APM?
Application performance monitoring tools like Datadog or New Relic that combine the pillars.
Who sets the SLO?
Product and engineering together, based on what users need.
Is 100 percent a good SLO?
No. It blocks all change. Pick a realistic target.
Interview questions
-
What are the three pillars of observability?
Logs for detail, metrics for numbers over time, traces for request paths across services.
-
Explain the four golden signals.
Latency, traffic, errors and saturation, the key health views of any service.
-
What is an SLO and error budget?
SLO is the reliability target; error budget is allowed unreliability, used to balance releases and stability.
-
How do you create a metric from logs in AWS?
A CloudWatch Logs metric filter with a pattern and a metric transformation.
-
What is OpenTelemetry?
A CNCF standard with APIs, SDKs and a collector to produce and export telemetry to any backend.
Quick quiz
Q1. Which pillar tells why?
Logs.
Q2. Which pillar tells where it is slow?
Traces.
Q3. Name the four golden signals.
Latency, traffic, errors, saturation.
Q4. SLI vs SLO?
SLI is the measured number; SLO is the target.
Q5. What is OpenTelemetry?
An open standard and SDKs for logs, metrics and traces.
Did you understand? Let us try it once more.
Revision card
Interview card
Comparison card