Skip to content

Add Correlation ID to request logs#1261

Merged
aaronburtle merged 30 commits intomainfrom
dev/aaronburtle/CorrelationIDLogging
Feb 27, 2023
Merged

Add Correlation ID to request logs#1261
aaronburtle merged 30 commits intomainfrom
dev/aaronburtle/CorrelationIDLogging

Conversation

@aaronburtle
Copy link
Contributor

@aaronburtle aaronburtle commented Feb 24, 2023

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 guid which 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:
image

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.

@aaronburtle aaronburtle added this to the Open Sourcing Milestone milestone Feb 24, 2023
Copy link
Collaborator

@Aniruddh25 Aniruddh25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks for pushing this in as well!
Just wanting to see how the logs will now look like.

Copy link
Contributor

@seantleonard seantleonard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

@seantleonard seantleonard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for addressing comments!

@aaronburtle aaronburtle merged commit 23ecc6d into main Feb 27, 2023
@aaronburtle aaronburtle deleted the dev/aaronburtle/CorrelationIDLogging branch February 27, 2023 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Let's make this better

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Fix folder structure Log Correlation Id of each request with each log to enhance debuggability

3 participants