How to keep API logs searchable later: attach an ID to each request to group records of the same request(qiita.com)
Writing language: KoreanRead in the original language
Plain summary
- If you attach a unique number (requestId) to each request in the records a server writes, you can avoid the problem of being unable to tell, from timestamps alone, which of the concurrently handled requests failed. This is a design example written on Qiita by the Japanese developer masashige0904.
- Each log entry is written as one line of JSON, with searchable values such as the event name, request ID and failure category kept as separate fields. Multi-line error records may be split into several events depending on how they are collected, it is said.
- The article proposes a policy of not logging passwords, authentication tokens, emails, request bodies, and raw exception text or SQL whose safety has not been verified, and creating a common logging gateway so this rule can be checked in one place.
- In AWS CloudWatch Logs Insights, filtering by requestId and sorting in chronological order lets you follow the start and failure of a single request. The article states that its search result table is a hypothetical example, not run on AWS, and that retention periods and fees must be checked separately.
Found on
Qiita ↗ / Published by source
Have you run into something like this? Tell us in a line or two what you did. You do not need to know the product.