การสังเกตระบบด้วยการบันทึกล็อกแบบมีโครงสร้างและการติดตามร่องรอย
ดูว่าฟังก์ชันของคุณทำอะไรอยู่จริง เรียนรู้การบันทึกล็อก JSON แบบมีโครงสร้าง การติดตามร่องรอยแบบกระจายด้วย AWS X-Ray และเมตริกแบบกำหนดเอง เพื่อการสังเกตระบบระดับใช้งานจริง
การสังเกตระบบด้วยการบันทึกล็อกแบบมีโครงสร้างและการติดตามร่องรอย เป็นบทเรียน Serverless Backend with AWS Lambda & API Gateway ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน 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
เรียนรู้ Serverless Backend with AWS Lambda & API Gateway ด้วย AI tutor — ฟรี
เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป
- คอร์ส
- 12
- บทเรียน
- 48
คำถามที่พบบ่อย
บทเรียน “การสังเกตระบบด้วยการบันทึกล็อกแบบมีโครงสร้างและการติดตามร่องรอย” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “การสังเกตระบบด้วยการบันทึกล็อกแบบมีโครงสร้างและการติดตามร่องรอย” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส 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 ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Serverless Backend with AWS Lambda & API Gateway หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Serverless Backend with AWS Lambda & API Gateway บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน
บทเรียน “การสังเกตระบบด้วยการบันทึกล็อกแบบมีโครงสร้างและการติดตามร่องรอย” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Serverless Backend with AWS Lambda & API Gateway นี้ได้ไหม
ได้ บทเรียน Serverless Backend with AWS Lambda & API Gateway ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- การเริ่มต้นแบบเย็นและกลยุทธ์การอุ่นเครื่อง
- เทคนิคการเพิ่มประสิทธิภาพค่าใช้จ่าย
- การจัดการข้อผิดพลาดและการลองใหม่
- การสังเกตระบบด้วยการบันทึกล็อกแบบมีโครงสร้างและการติดตามร่องรอย