Performance

Serverless observability with AWS Lambda Powertools

Structured logs, custom metrics, and tracing for AWS Lambda with Powertools for TypeScript — plus the dashboards and alarms that help.

  • 3 min read
  • Updated December 2, 2026

In a serverless system, a single user action can cross API Gateway, several Lambda functions, a queue, a workflow, and a database. When something goes wrong, you need to follow that path quickly. This guide shows how to get there with AWS Lambda Powertools for TypeScript, Amazon CloudWatch, and AWS X-Ray — and which dashboards and alarms actually help during incidents.

The three signals

  • Logs tell you what happened in one invocation, in detail.
  • Metrics tell you how the system behaves in aggregate: rates, errors, latency, business counts.
  • Traces tell you how a request moved across services and where time went.

Powertools provides a utility for each — Logger, Metrics, and Tracer — designed for Lambda's execution model.

Structured logging with Logger

Plain console.log strings are hard to search and aggregate. Structured JSON logs with consistent keys make CloudWatch Logs Insights queries trivial.

import { Logger } from "@aws-lambda-powertools/logger";

const logger = new Logger({ serviceName: "orders" });

export const handler = async (event: OrderEvent, context: Context) => {
  logger.addContext(context);
  logger.appendKeys({ tenantId: event.tenantId, orderId: event.orderId });
  logger.info("Processing order");
  // ...
};

Good practices:

  • Add request context (function name, request id, cold start flag) to every line.
  • Append business identifiers — tenant, order, user — so you can answer "what happened to this customer's order?".
  • Propagate a correlation id from the first request through events and queues, and log it everywhere.
  • Set the log level per environment with an environment variable; keep DEBUG off in production, or sample it for a small percentage of requests.
  • Never log secrets, tokens, or full payloads with personal data.

Then queries like this become one line:

fields @timestamp, level, message, orderId
| filter tenantId = "t-123" and level = "ERROR"
| sort @timestamp desc

Metrics with the Embedded Metric Format

Powertools Metrics writes custom metrics as structured log lines in CloudWatch's Embedded Metric Format (EMF). CloudWatch extracts them asynchronously, so publishing a metric adds no API call and no latency to the invocation.

import { Metrics, MetricUnit } from "@aws-lambda-powertools/metrics";

const metrics = new Metrics({ namespace: "Shop", serviceName: "orders" });

metrics.addMetric("OrderPlaced", MetricUnit.Count, 1);
metrics.addMetric("OrderValue", MetricUnit.NoUnit, order.total);
metrics.publishStoredMetrics();

Track two kinds of metrics:

  • Technical: errors, throttles, duration, iterator age, queue depth — mostly provided by AWS already.
  • Business: orders placed, sign-ups, payments failed, documents processed. These detect problems the technical metrics miss ("no errors, but no orders either").

Be careful with dimensions: each unique combination creates a separate metric and cost. Use high-cardinality values such as user ids in logs, not as metric dimensions.

Tracing with Tracer and X-Ray

Enable active tracing on functions and API Gateway, and use Powertools Tracer to capture AWS SDK calls and add annotations:

import { Tracer } from "@aws-lambda-powertools/tracer";
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";

const tracer = new Tracer({ serviceName: "orders" });
const dynamo = tracer.captureAWSv3Client(new DynamoDBClient({}));

tracer.putAnnotation("tenantId", event.tenantId);

The X-Ray service map shows how services connect and where latency and errors concentrate. Annotations make traces searchable ("all slow traces for tenant t-123"). For asynchronous flows, carry the trace and correlation ids in message attributes so the path stays connected.

If your organization already uses OpenTelemetry or a third-party observability platform, the AWS Distro for OpenTelemetry Lambda layer or the vendor's extension can export the same signals.

Built-in metrics you should already watch

Before adding anything custom, make sure you look at what AWS publishes:

  • Lambda: Errors, Throttles, Duration (p99, not just average), ConcurrentExecutions, and IteratorAge for stream consumers.
  • SQS: ApproximateAgeOfOldestMessage and ApproximateNumberOfMessagesVisible, especially on dead-letter queues.
  • API Gateway: 5XXError, 4XXError, Latency, and IntegrationLatency.
  • DynamoDB: throttled requests and consumed capacity.
  • Step Functions: failed, timed-out, and aborted executions.

Alarms that matter

Too many alarms train people to ignore them. Alarm on symptoms users feel and on work that silently stops:

  • API error rate and p99 latency above your target for several minutes.
  • Any message in a dead-letter queue.
  • Age of the oldest message in a work queue growing beyond what the business tolerates.
  • Failed workflow executions for critical processes.
  • A business metric dropping to zero when it never should (anomaly detection helps here).

Composite alarms and metric math (for example, errors divided by invocations) reduce noise. Every alarm should link to a short runbook: what it means, how to check, and how to mitigate.

Dashboards

Build one dashboard per service or workload with the same layout: traffic, errors, latency, saturation (concurrency, queue depth), and the key business metric. Consistency matters more than completeness — during an incident, nobody wants to learn a new dashboard.

Beyond the three signals

Powertools also includes utilities that improve reliability and debuggability:

  • Idempotency for safe retries of handlers with side effects.
  • Batch processing for partial failures in SQS, Kinesis, and DynamoDB Streams.
  • Parameters for cached access to SSM, Secrets Manager, and AppConfig.
  • Parser / validation integrations for typed, validated events.

Summary

Use structured logs with business context, publish business metrics through EMF, trace across services, watch the metrics AWS already provides, and alarm on user-facing symptoms with runbooks attached. Our performance and reliability service sets this up end to end for existing systems.

Services

Related services

How we can help you put this guide into practice.

Guides

More guides

Keep reading.

Let's make your serverless workload simpler, safer, and cheaper.

Start with a free 30-minute intro call with a serverless engineer.

Book a consultation