0Pricing
Serverless Backend with AWS Lambda & API Gateway · Lesson

Observability with Structured Logging and Tracing

See what your functions are really doing. Learn structured JSON logging, distributed tracing with AWS X-Ray, and custom metrics for production-grade observability.

Observability with Structured Logging and Tracing is a free Serverless Backend with AWS Lambda & API Gateway lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Serverless Backend with AWS Lambda & API Gateway learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

The Three Pillars of Observability

Observability rests on logs, metrics, and traces. Together they answer what happened, how much, and where the time went across your serverless system.

Why Structured Logging?

Plain text logs are hard to search. Structured (JSON) logs let CloudWatch Logs Insights filter and aggregate by field, turning logs into queryable data.

Writing a Structured Log

Emit JSON with consistent fields so you can query by request, level, and custom attributes.

console.log(JSON.stringify({
  level: "INFO",
  requestId: context.awsRequestId,
  action: "createOrder",
  orderId: 42
}));

Correlation IDs

Pass a correlation ID through every service and log it everywhere. This lets you trace a single user request across multiple functions and queues.

Querying with Logs Insights

CloudWatch Logs Insights runs SQL-like queries over structured logs.

fields @timestamp, action, orderId
| filter level = "ERROR"
| sort @timestamp desc
| limit 20

Distributed Tracing with X-Ray

AWS X-Ray records a trace as a request flows through Lambda, API Gateway, DynamoDB, and more, showing a timeline of every segment.

Enabling X-Ray

Turn on active tracing for the function, then instrument the SDK so downstream calls become subsegments.

const AWSXRay = require("aws-xray-sdk-core");
const AWS = AWSXRay.captureAWS(require("aws-sdk"));

Custom Subsegments

Wrap your own logic in a subsegment to measure how long a specific block takes inside the trace.

const seg = AWSXRay.getSegment().addNewSubsegment("validate");
validate(input);
seg.close();

Custom Metrics with EMF

The Embedded Metric Format lets you emit metrics inside a structured log line. CloudWatch extracts them automatically — no extra API call.

Setting Alarms

Create CloudWatch alarms on error rate, p99 latency, and DLQ depth. Alarms turn passive metrics into proactive alerts before users notice.

Avoiding Log Noise

Log with intent:

  • Use levels (DEBUG/INFO/ERROR) and a log-level env var
  • Never log secrets or full PII
  • Sample high-volume traces to control cost

Quick Check

Test your observability knowledge.

Recap

You learned production observability:

  • Logs, metrics, and traces are the three pillars
  • Use structured JSON logs and correlation IDs
  • X-Ray gives distributed traces across services
  • Emit custom metrics with EMF and alarm on them

Frequently asked questions

Is the “Observability with Structured Logging and Tracing” lesson free?

Yes — the full text of “Observability with Structured Logging and Tracing” is free to read here on the web, and the Serverless Backend with AWS Lambda & API Gateway course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Serverless Backend with AWS Lambda & API Gateway course, upgrade to CoddyKit PRO.

What will I learn in “Observability with Structured Logging and Tracing”?

See what your functions are really doing. Learn structured JSON logging, distributed tracing with AWS X-Ray, and custom metrics for production-grade observability. You practise Serverless Backend with AWS Lambda & API Gateway with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Serverless Backend with AWS Lambda & API Gateway?

No prior experience is required. Serverless Backend with AWS Lambda & API Gateway on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Observability with Structured Logging and Tracing” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Serverless Backend with AWS Lambda & API Gateway lesson?

Yes. Every Serverless Backend with AWS Lambda & API Gateway lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Cold Starts and Warm-up Strategies
  2. Cost Optimization Techniques
  3. Error Handling and Retries
  4. Observability with Structured Logging and Tracing
← Back to Serverless Backend with AWS Lambda & API Gateway