Add Correlation ID to request logs#1261
Merged
aaronburtle merged 30 commits intomainfrom Feb 27, 2023
Merged
Conversation
Aniruddh25
reviewed
Feb 25, 2023
Aniruddh25
approved these changes
Feb 25, 2023
Collaborator
Aniruddh25
left a comment
There was a problem hiding this comment.
Looks good, thanks for pushing this in as well!
Just wanting to see how the logs will now look like.
Contributor
seantleonard
left a comment
There was a problem hiding this comment.
nit: not sure if you ruled this out: you can reduce or possibly eliminate the need to modify method signatures just for logging purposes by injecting IHttpContextAccessor in class constructors.
seantleonard
approved these changes
Feb 27, 2023
Contributor
seantleonard
left a comment
There was a problem hiding this comment.
thank you for addressing comments!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why make this change?
Closes #1206
To assist in debugging we attach a correlation ID to any logs that are generated during a request. Since many requests may be made, having a way to identify the logs to a specific request will be important to assist in the debugging process.
What is this change?
Where possible we get the correlation ID from the http context. This correlation id is
guidwhich we translate into a string and attach to the beginning of anything that we write to the logs for a given request. If no correlation id is available, we simply do not include a correlation id in the log. This would arise in the case where we have code shared between the setting up of our service and the processing of requests. To determine the difference, we look at if the http context, or the guid itself is null. In either of those cases, we do not include the correlation id in the logs.An example of this correlation ID can be seen here:

How was this tested?
Manually run to verify logs, and the test suite was run against the changes as well.
Sample Request(s)
Any valid request will display correlation ID in the request logs.