Add logging of per-context variables to logging system and network stack #1507
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change adds a per-thread logging context to the logging system, which can be set by the user and will then be logged from all threads and tasks created with that context.
This is useful to correlate requests from the client to any network requests made based on that request.
The logging formatter must be set up by including a
MessageFormatter::ElementType::ContextValue
with the 'format' set to the context key to use:The log context must then be created and set up once manually from the top-most thread:
The log context is stored for each thread, so whenever a new thread or task is created, this context must somehow be copied into the thread-local storage of that new thread.
For
ThreadPoolTaskScheduler
, the current log context is captured for the new task lambda and made active when the task is activated.For
NetworkCurl
, the current log context is captured inside theRequestHandle
on creation and subsequently made active whenever this request is processed.Resolves: OLPEDGE-2893