Cert EspressoLearn. Practise. Find your flow.

A LITTLE FOCUS.
A BIG NEXT STEP.

Your pace. Your space.
AWS · DVA-C03

Logging, metrics, tracing, and alerts

DVA-C03 · Lesson 22 of 24 · 3:02:38

YouTube loads only after you press play. This chapter opens at its timestamp in the full course. Watch on YouTube ↗

Learning with these videos? Subscribe for new courses and exam-style questions.

In this lesson

Prepare for the DVA-C03 exam (AWS Certified Developer – Associate). In this lesson: structured JSON logs and log levels, log retention, custom metrics with PutMetricData and the embedded metric format, alarms, composite alarms, and deployment notifications, tracing with X-Ray and OpenTelemetry, and health checks and probes for containers. Includes three original practice questions.

Study notes

The text of this lesson, to read at your own pace. Information as of November 2026.

On sale at nine

At AnyCompany Tickets, a big concert goes on sale at nine tomorrow morning. The team wants to count the tickets sold per minute, follow a slow request across services, and hear about trouble before the fans do. This lesson covers structured logs, custom metrics, alerts, tracing, and health checks.

Structured logging

Logs are only useful if you can query them. Structured logging writes each event as a JSON object, with the same keys every time: a level, a message, the request ID, and fields like the event ID or the action of the user. In Lambda, set the log format to JSON and choose an application log level, so that Lambda sends only the messages at that level or more severe, like warnings and errors in production. Never log secrets or card numbers, and set a retention period on each log group, because by default CloudWatch Logs keeps log data forever.

Custom metrics

AWS services publish their own metrics, but the number of tickets sold is a custom metric, which your code publishes. The first way is the PutMetricData API, called from the SDK with a namespace, a metric name, dimensions, and values, at the standard resolution of one minute or at a high resolution of one second. The second way is the embedded metric format: the function writes a JSON log line with a block that describes the metrics, and CloudWatch pulls them out of the log, asynchronously, with no API call in the code. With the embedded metric format, the function needs permission to write logs, not the PutMetricData permission. And keep dimensions to values with few variations, like the venue: a dimension like the request ID creates a new metric for every request.

Alerts

Metrics become alerts through CloudWatch alarms. A metric alarm compares a metric with a threshold over evaluation periods, and it goes to the ALARM state when enough data points breach, like three out of five; its other states are OK and insufficient data. Its actions can notify an SNS topic, which sends an email or calls a function, and a composite alarm combines several alarms to cut the noise. For quotas, Service Quotas lets you create an alarm on the usage of a quota, like concurrent executions, so that you hear about it before requests start to fail. And for deployment completions, an EventBridge rule matches the deployment state-change events of CodeDeploy, like success or failure, and sends them to SNS, while CodePipeline has notification rules for its own events.

Tracing

Tracing follows one request across services. In Lambda, turn on active tracing, and Lambda sends traces to X-Ray, which samples requests instead of tracing all of them; in a REST API, tracing is a setting of the stage. In the code, instrument the SDK clients so that each call becomes a subsegment, and add annotations, which are indexed for filter expressions, or metadata, which is not indexed. The X-Ray SDKs and daemon have been in maintenance mode since February twenty twenty-six, so new code uses OpenTelemetry, through the AWS Distro for OpenTelemetry, or ADOT, with its Lambda layers and auto-instrumentation for Java and Python. And a tracing header carries the trace ID and the sampling decision from one service to the next.

Health checks

Health checks tell the platform whether a workload can serve. An ECS container health check runs a command in the container, with an interval, a timeout, retries, and a start period, and when an essential container is unhealthy, the whole task is unhealthy. A load balancer checks a path on each target, like slash health, and stops routing to the targets that fail, and an Auto Scaling group can use these checks to replace instances, after a grace period. On EKS, a liveness probe restarts a container that is stuck, a readiness probe keeps traffic away from a pod until it can answer, and a startup probe gives a slow application time to start. And keep the liveness probe independent of external systems: if it tests a shared database, one database outage fails the probes of every pod.

Recap

Let's recap. Structured JSON logs, with log levels and a retention period, make application events easy to query. Custom metrics come from PutMetricData or from the embedded metric format, with dimensions that have few values. CloudWatch alarms notify SNS topics, including alarms on quota usage, and EventBridge rules report deployment completions. Traces come from active tracing and from OpenTelemetry through ADOT, with annotations to filter them. And health checks and probes let the platform replace, restart, or skip unhealthy workloads.

Quick checks for this lesson

The 3 questions of this lesson, as plain text. The button above runs them with shuffled choices and the reason behind every choice.

  1. In production, a Python function writes thousands of debug messages per minute through the standard logger, which makes its logs hard to search. The developer wants to keep only warnings and errors, without changing the code. What should the developer configure?

    • A metric filter on the log group
    • A shorter retention period for the log group
    • JSON log format, with the application log level at WARN
    • A subscription filter to another destination
    Show the answer

    JSON log format, with the application log level at WARN

    With the JSON log format, an application log level of WARN makes Lambda drop the messages below that level, with no change to the code. “A metric filter on the log group” would turn matching events into a metric, while every message is still stored. “A shorter retention period for the log group” would delete old logs sooner, while the debug messages keep arriving. And “A subscription filter to another destination” would copy the logs to another destination, with all their messages.

  2. A function must publish the number of tickets sold for each venue, without an extra API call that adds latency to each invocation. What should the developer use?

    • The embedded metric format, in a JSON log line
    • PutMetricData, called on every invocation
    • A dimension named after the request ID
    • X-Ray annotations named after the venue
    Show the answer

    The embedded metric format, in a JSON log line

    The function writes the metric in a log line, and CloudWatch pulls it out asynchronously, with no API call during the invocation. “PutMetricData, called on every invocation” would add a call to CloudWatch to every invocation. “A dimension named after the request ID” would create a separate metric for every request. And “X-Ray annotations named after the venue” would help filter traces, without producing a metric.

  3. A pod on EKS is sometimes busy for a minute with a heavy disk job. During that time, it is unable to answer requests, but it recovers on its own, and restarting it would not help. What should the developer configure?

    • A liveness probe that restarts the container
    • A composite alarm on the error rate
    • Active tracing for the requests
    • A readiness probe on the container
    Show the answer

    A readiness probe on the container

    A failed readiness probe takes the pod out of the service, so no requests reach it until it can answer again. “A liveness probe that restarts the container” would restart a container that recovers on its own, which the scenario rules out. “A composite alarm on the error rate” would alert people, while requests keep failing. And “Active tracing for the requests” would show the failed requests, without keeping traffic away.