Distributed Logging: ตอนที่ 1 ให้ Log รู้ว่าเกิดจาก Request เดียวกัน
Originally published at https://somprasongd.work/blog/go/distributed-logging-1 เคยไหม? เปิด log ไฟล์มาแล้วต้องกวาดตาดู Stack Trace วนเป็นชั่วโมง กว่าจะเจอว่า Error อันนี้มาจาก Request ไหน แล้วถ้าเจอ Request หนึ่งกระจายยิงหลาย Service ยิ่งวุ่นเข้าไปใหญ่ นี่คือที่มาของ Request ID หรือบางคนเรียกว่า Correlation ID — ตัวช่วยเล็ก ๆ ที่ทำให้ Distributed Logging เป็นเรื่องง่ายขึ้น บทความนี้จะพาไปดูวิธีทำ End-to-End Correlated Logging ตั้งแต่ Proxy ชั้นนอก (NGINX) จนถึง Backend (Go Fiber) และวิธีส่งต่อ ID นี้ไปทั้ง Layer: Handler → Service → Repository…