Write logs that make a failed request diagnosable
In this article (3 sections)
“Request failed” does not tell an operator which request, dependency, attempt or outcome needs attention. Structured fields make logs queryable and correlatable.
Check one error event
The engineering foundations lab creates a synthetic metadata-only record.
from engineering_cases import logging_case
result = logging_case()
assert result["required_present"] is True
assert result["forbidden_present"] == []
assert result["diagnosable"] is True
assert result["event"]["request_id"] == "R-7"Record timestamp, severity, stable event name, service/release, request/trace ID, dependency, attempt, outcome/error code and duration. Add tenant/user pseudonyms only when justified. Use consistent JSON fields rather than embedding everything in prose.
Never log authorization headers, passwords, tokens or raw bodies by default. Redact before export and test every sink. Separate a safe client error from an internal diagnostic record; both can share the correlation ID.
The FDE for Freshers course connects logging to deployed-service monitoring and handover.
Exercise
Emit structured records for success, timeout and invalid input. Query by request ID and prove seeded fake secrets never appear in the output file.
Continue learning
This article is part of the FDE engineering foundations sequence. Use the neighbouring tasks when you need the prerequisite or the next application.
- Review the prerequisite or neighbouring task in Read a stack trace and identify the failing contract.
- Continue with Git branches and pull requests for a student project.
Reference: Python logging documentation.
Pankit Kumar has 10 years in Data Science & AI, building and shipping production systems in regulated pharma and clinical environments. He is a freelance trainer at Boston Institute of Analytics, AnalytixLabs and Scaler, and has taught this material to thousands of working professionals.
This article is part of our FDE for Freshers programme — 6–7 months. Build your engineering foundations, then take AI from discovery to delivery.
Explore FDE for Freshers