Structured Logging
Structured logging records an event as named fields with defined meanings and types, such as run_id, stage, status, and row_count. A JSON object per line is one possible encoding; the structure lets a collector filter by a field without extracting it from prose.
Choose identifiers and count meanings explicitly. A run ID identifies an attempt, while a batch ID can persist across retries. A candidate row count does not mean those rows committed. Record publication evidence separately and keep field names stable so queries survive wording changes.
Python logging separates loggers, handlers, and formatters. Applications can add context and serialize an approved event to JSON. Passing extra fields alone does not automatically create JSON output; the configured formatting and destination decide what is emitted.
JSON encoding does not remove secrets or personal data. Select permitted fields and handle exception details carefully. A log emitted by a process can also be lost before collection. Use durable destination state to resolve ambiguous commits instead of treating a success message as the transaction itself.
A useful event might pair run_id=run-18 with batch_id=delivery-42 and status=already_committed. Another attempt has a new run ID but keeps that batch ID, allowing queries to group retries without merging unrelated deliveries. Define whether a count is null, absent, or zero; use a stable type, and add a schema version when incompatible field changes are necessary.
See Python ETL Engineering for Production for a command-line example.
Further reading
Discover more from Insightful Data Lab
Subscribe to get the latest posts sent to your email.
