CLOUD CONCEPT

Structured Logging

Structured logging records application events as consistently named, machine-readable fields rather than relying only on free-form text messages.

Cloud Concepts Hub →

What is Structured Logging

Structured logs attach explicit context, such as severity, job identifiers, processing stages, and error codes, to each event. This makes distributed data pipelines easier to troubleshoot, query, monitor, and test without depending on fragile text parsing.

Structured logging treats each log entry as a record with defined fields and values. Instead of writing only “Job failed processing orders,” an application emits an event containing a timestamp, severity, event name, job identifier, dataset, processing stage, and error details. JSON is a common encoding, but the defining property is explicit structure, not a particular file format. A readable message can remain part of the record while separate fields provide reliable filtering and aggregation.

For example, a transformation task might emit {"severity":"ERROR","event":"record_validation_failed","job_id":"orders-daily","run_id":"run-123","stage":"transform","error_code":"INVALID_DATE","rejected_count":12}. An engineer can search for all validation failures, group failures by dataset, or compare rejection counts across runs without extracting values from changing message text. Numeric quantities should remain numbers rather than strings, and timestamps should use a consistent format and time zone, commonly UTC.

In cloud data engineering, workers often run across multiple containers, functions, or distributed processing executors. Each worker should emit logs through a standard logging library to a destination supported by its runtime, such as standard output or a collected log file. A logging agent or platform integration forwards those events to centralized storage and query tools. Collection alone does not create structured logs: the application must emit useful fields, and the ingestion path must preserve or correctly parse them.

Correlation is especially important for ingestion and transformation pipelines. Include a run identifier across orchestration, extraction, transformation, and loading, with task and attempt identifiers where retries occur. A request or trace identifier helps connect activity across services, but it does not automatically create a distributed trace. Avoid assuming that arrival order in a centralized log store represents execution order across workers. Timestamps, stage identifiers, and attempt numbers provide better context for reconstructing events.

Apply software engineering practices to logging itself. Keep shared logging configuration and field definitions in version control, use reusable logging helpers, and test that important success and failure paths produce the expected events. Tests should verify required fields, numeric types, severity choices, and redaction behavior rather than matching an entire formatted message. Evolve field names deliberately because dashboards, alerts, and operational queries can depend on them. Use a serializer instead of constructing JSON through string concatenation, which can break escaping or allow untrusted input to corrupt log records.

Log operational context rather than raw data payloads. Credentials, access tokens, personal information, and sensitive source records should be omitted or appropriately redacted before emission. Restrict access to logs and configure encryption and retention according to policy. For high-volume pipelines, logging every successful record can increase ingestion, indexing, and storage costs and expose unnecessary data. Prefer batch summaries and actionable errors, with controlled debug logging or sampling when appropriate.

Structured logging is not the same as monitoring, and JSON alone does not guarantee useful observability. Metrics summarize behavior over time, logs explain individual events, and traces describe execution paths. Derive alerts from meaningful log fields where appropriate, but avoid turning unique run identifiers into high-cardinality metric dimensions. Logging can also add serialization overhead or lose buffered events during failures; choose buffering and delivery behavior deliberately. For engineering scenarios, favor consistent contextual events and centralized analysis over scattered print statements, while recognizing that logs do not replace tests, data-quality checks, or durable processing checkpoints.

Key aspects of Structured Logging

Effective structured logging combines consistent event fields, correlation identifiers, tested conventions, secure handling, centralized analysis, and deliberate volume control.

Explicit event fields

Represent operational facts as named fields with consistent types, such as event, severity, run_id, and duration_ms. Preserve a human-readable message when useful, but do not make downstream queries depend on parsing it.

Cross-component correlation

Propagate run, task, request, and attempt identifiers through pipeline components. These fields help distinguish retries and connect failures across distributed workers.

Stable, tested conventions

Version logging helpers and field definitions alongside application code. Test important events for required fields, valid serialization, expected types, and sensitive-data exclusion.

Centralized querying and monitoring

Collect events in a shared system that preserves their structure and supports field-based queries. Use those fields to investigate failures, summarize outcomes, and configure targeted alerts.

Security and data minimization

Exclude secrets and avoid logging raw source records by default. Apply access controls, encryption, and retention policies to log destinations because operational metadata can also be sensitive.

Controlled volume and overhead

Choose severity levels, sampling, and batch summaries to keep logs useful and affordable. Account for serialization cost, buffering behavior, and possible event loss rather than assuming logging is free or guaranteed.

Cloud services for Structured Logging

Applications running in Lambda or Glue emit structured events with shared field conventions and correlation identifiers. CloudWatch Logs collects those events for operational queries and can support monitoring through metric filters and alarms. When broader search and dashboard requirements justify it, an ingestion pipeline can send selected events to OpenSearch Service. Logs can also be exported or delivered to S3 for retention and later analysis. Across these destinations, preserve field types, apply consistent access and retention policies, and avoid forwarding sensitive payloads or unnecessary debug events.

AWS Lambda image AWS Lambda

Lambda supports JSON-formatted logging through advanced logging controls for supported runtimes and logging methods, and application code can emit its own structured events. Include business context and pipeline identifiers alongside runtime request context, and configure the execution role to permit log delivery.

Open AWS Lambda →
AWS Glue image AWS Glue

Glue jobs publish operational logs to CloudWatch Logs, and job code can add application-level events describing validation outcomes, transformation stages, and batch counts. Use appropriate logging or serialization helpers when structured application fields are required; default runtime messages are not automatically a consistent application schema.

Open AWS Glue →
Amazon OpenSearch Service image Amazon OpenSearch Service

OpenSearch Service can index structured log events for field-based search, aggregations, and dashboards. Configure ingestion parsing and field mappings carefully, and control dynamic fields to avoid excessive mapping growth.

Open Amazon OpenSearch Service →
Amazon Simple Storage Service image Amazon S3

S3 can store exported or delivered structured logs for retention and later analysis. Time-based organization, compression, and lifecycle policies help manage storage and query costs; S3 itself does not supply the application's event schema.

Open Amazon S3 →