構造化ログとトレーシングによる可観測性
関数が実際に行っている処理を把握します。構造化JSONログ、AWS X-Rayによる分散トレーシング、本番環境向けのカスタムメトリクスを使った可観測性を学びます。
「構造化ログとトレーシングによる可観測性」はCoddyKit上の無料Serverless Backend with AWS Lambda & API Gatewayレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはServerless Backend with AWS Lambda & API Gateway学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Serverless Backend with AWS Lambda & API Gatewayコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
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 20Distributed 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
よくある質問
「構造化ログとトレーシングによる可観測性」レッスンは無料ですか?
はい。「構造化ログとトレーシングによる可観測性」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Serverless Backend with AWS Lambda & API Gatewayコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Serverless Backend with AWS Lambda & API Gatewayコースには全4レッスンが含まれています。
「構造化ログとトレーシングによる可観測性」で何を学びますか?
関数が実際に行っている処理を把握します。構造化JSONログ、AWS X-Rayによる分散トレーシング、本番環境向けのカスタムメトリクスを使った可観測性を学びます。 ブラウザで直接実行するハンズオンコードでServerless Backend with AWS Lambda & API Gatewayを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Serverless Backend with AWS Lambda & API Gatewayを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのServerless Backend with AWS Lambda & API Gatewayは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「構造化ログとトレーシングによる可観測性」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このServerless Backend with AWS Lambda & API Gatewayレッスンでコードを書いて実行できますか?
はい。すべてのServerless Backend with AWS Lambda & API Gatewayレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- コールドスタートとウォームアップ戦略
- コスト最適化のテクニック
- エラー処理とリトライ
- 構造化ログとトレーシングによる可観測性