More Sophisticated Issue Tracking in ELK Environments Part 3: Actively Utilizing Multi Thread Context
Key point
This solves the problem of log accumulation in batch APIs and asynchronous logic by introducing Multi Thread Context.
Details
Existing Thread Context-based issue tracking is useful for tracing a single request, but it has limitations in batch APIs or asynchronous logic. In particular, for batch APIs, when a single thread iterates through numerous tasks, logs keep accumulating in the debug field of the MDC (Thread-Local log metadata store), making it difficult to identify specific issues.
To solve this problem, a strategy of assigning a new Thread Context to each task is used. A new thread is created via the onNewContext function, and by performing the task within that thread, the MDC and Sentry contexts are kept in an initialized state, separating the logs.
The key point of this approach is not parallel processing, but separating the logs of each task independently. Therefore, after performing the task in a new thread, Future.get() is called to complete the task synchronously, thereby securing cleanly separated logs for each individual task as intended.
This summary was generated automatically by AI. Check the original for the author's claims and context. Copyright belongs to the original author.
Our guide explains how the AI works. Report summary errors, attribution issues, or removal requests via Contact.