How do you instrument an application with a Prometheus client library? [Intermediate]
Answer
To instrument an application, I add a Prometheus client library, define a small set of well-named counters, gauges, and histograms, expose a /metrics endpoint, and ensure labels are bounded and useful.
Technical explanation
Start with service RED metrics: request count, error count, and request duration histogram.
Add domain metrics only when they drive SLOs, capacity planning, or operational debugging.
Protect cardinality by using route templates, status classes, dependency names, and environment labels rather than IDs.
Hands-on example
Python Flask sketch:
from prometheus_client import Counter, Histogram, generate_latest
REQ = Counter('http_requests_total','Requests',['route','method','status'])
LAT = Histogram('http_request_duration_seconds','Latency',['route'])
@app.get('/metrics')
def metrics(): return generate_latest(), 200, {'Content-Type':'text/plain'}
Check how well your resume matches the role with our free resume checker— match score, ATS check, and the skills you're missing.
More Observability interview questions
- What is observability, and how is it different from traditional monitoring? [Basic]
- What are the three pillars of observability (metrics, logs, traces)? [Basic]
- What is the difference between monitoring and observability in practice? [Basic]
- What are the four golden signals of monitoring? [Basic]
- What is the difference between the USE method and the RED method? [Basic]
- When would you use the USE method versus the RED method? [Basic]
- What is an SLI, an SLO, and an SLA, and how do they relate? [Basic]
- How do you choose good SLIs for a service? [Basic]