API Observability & Structured Logging
Design logs, metrics and traces that help you debug services without exposing secrets or user data.
Educational reference drafted for the Nullwire archive. This is not a claim of completed training or original research; verify examples and customise before presenting it as finished work.
Objective
Make a service explain what happened during a request, while treating telemetry as sensitive data.
Three useful signals
Logs describe discrete events. Metrics quantify behaviour over time. Traces show the path of an operation across components.
A useful HTTP service might track request counts, error rates, latency distributions and dependencies. High-cardinality labels such as raw user IDs can cause operational and privacy problems.
Structured logging
Prefer fields with explicit meanings rather than a sentence that must be parsed later.
{
"timestamp": "2026-01-01T00:00:00Z",
"level": "info",
"event": "http_request",
"route": "/api/health",
"status": 200,
"duration_ms": 12,
"request_id": "demo-001"
}
This is illustrative, not a real production event. Avoid logging passwords, session cookies, access tokens or raw request bodies without a specific, reviewed need.
Basic reliability indicators
- Latency: How long requests take, ideally as distributions rather than averages alone.
- Traffic: Number of requests arriving.
- Errors: Failures by route and class.
- Saturation: A constrained resource approaching its limit.
Troubleshooting exercise
Design a small, local API. Make one request succeed and one fail. Confirm that both have a correlation ID and that logs give enough context to explain the failure.
Failure-mode thinking
If logging fails, should the service continue? Could verbose debug logs exhaust storage? What is the retention policy? These are design decisions, not afterthoughts.
Related: Python CLI Engineering.