Domain 4 of 4 · Chapter 2 of 3

Code Observability

Unlock the complete study guide + 1,040 practice questions across 16 full exams.

Bundled into the existing AWS Certified Developer - Associate premium course — no separate purchase.

Included in this chapter:

  • Instrumentation is emitting telemetry, not reading it: the three-pillar model
  • Logs and metrics: structured logging, EMF, and PutMetricData
  • Traces: X-Ray SDK instrumentation, annotations vs. metadata
  • Alarms, and exam-pattern recognition: stem cue to signal

The three observability pillars on AWS: what to instrument when

PillarQuestion it answersAWS serviceHow code emits itReach for it when
LogsWhat exactly happened, in detail?Amazon CloudWatch Logs (+ Logs Insights)Structured JSON lines with a correlation ID; EMF for metric extractionYou need per-event detail to reconstruct a single request or failure
MetricsHow much / how often, over time?Amazon CloudWatch metricsPutMetricData API, or EMF from structured logs; dimensions slice the dataYou need aggregated trends, dashboards, and alarm thresholds
TracesWhere in the request path is the time going?AWS X-RayX-Ray SDK subsegments; annotations (indexed) vs metadata (context)You must follow one request end-to-end across multiple services

Decision tree

Follow one request end-to-end across services? Yes X-Ray subsegment + annotation (indexed, filterable) No Need an aggregated trend or alarm threshold? No, per-event detail Structured JSON log line + correlation ID to CloudWatch Logs Yes, custom metric On the Lambda request path (avoid a blocking call)? Yes (recommended) EMF (_aws log node) async; metric extracted from the log No / need control PutMetricData API synchronous; 1-second high-resolution Logs answer what happened; metrics answer how much over time; traces answer where the time went. Cardinality is the cost lever: never put unbounded values (raw user/request IDs) in a metric dimension.

Cheat sheet

  • Instrumentation emits telemetry; observability is the ability to ask new questions
  • Logs, metrics, and traces map to CloudWatch Logs, CloudWatch metrics, and X-Ray
  • Emit structured JSON logs so Logs Insights can query fields directly
  • Put a correlation ID on every log line to join one request's signals
  • EMF publishes a custom metric from a log line with no PutMetricData call
  • PutMetricData is the synchronous API for publishing a custom metric
  • Custom metrics are standard 1-minute resolution unless you set StorageResolution to 1
  • Keep metric dimensions low-cardinality; every unique combination is a billed metric
  • The X-Ray SDK captures downstream AWS SDK and HTTP calls as subsegments
  • Use X-Ray annotations for anything you filter on, metadata for bulky context
  • Distributed tracing needs the trace-context header propagated across every hop
  • CloudWatch ServiceLens / Application Signals correlates traces, metrics, and logs on one map
  • Alarm on a metric and publish to SNS to turn telemetry into a notification
  • New CloudWatch log groups never expire until you set a retention policy
  • X-Ray traces need Active tracing plus write permission, and API Gateway must be redeployed
  • X-Ray annotations follow strict key rules, cap at 50 per trace, and cannot go on Lambda's parent segment
  • Set awslogs-stream-prefix so ECS log streams trace back to a task and container
  • When EMF metrics never appear, check the AWS/Logs error metrics and the timestamp window
  • Use single_metric to emit EMF metrics that need different dimension sets in one invocation
  • Enable Container Insights enhanced observability for task- and container-level metrics
  • Use CloudWatch Application Insights to auto-correlate problems and fan out via EventBridge

Unlock with Premium — includes all practice exams and the complete study guide.

Also tested in

References

  1. Analyze log data with CloudWatch Logs Insights
  2. PutMetricData: Amazon CloudWatch API Reference
  3. Amazon CloudWatch concepts (metrics, dimensions, resolution)
  4. Embedding metrics within logs (CloudWatch embedded metric format)
  5. Using the embedded metric format client libraries
  6. Working with log groups and log streams
  7. Change log data retention in CloudWatch Logs
  8. AWS X-Ray SDK for Node.js
  9. AWS X-Ray concepts (segments, traces, annotations, tracing header)
  10. Use ServiceLens to monitor the health of your applications
  11. Application monitoring with CloudWatch Application Signals
  12. Using Amazon CloudWatch alarms