Skip to content

Logging: Add request id to the app logs for easy log tracking #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2025
Merged

Conversation

vas3a
Copy link
Collaborator

@vas3a vas3a commented Jun 4, 2025

Prepends a nanoid as the requestId to each log so it's easier to track down all the requests for a specific request. eg:
image

@vas3a vas3a requested a review from kkartunov June 4, 2025 10:59
const asyncStorage = new AsyncLocalStorage<RequestMetadata>();

// Gets the RequestMetadada object associated with the current request
export function getStore(): RequestMetadata {
Copy link

Choose a reason for hiding this comment

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

high
correctness
The getStore function returns a RequestMetadata object with an empty requestId if the store is undefined. This could lead to logs with missing request IDs, which may defeat the purpose of tracking requests. Consider initializing with a new nanoid instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is happening only for "root"-level logging - and is expected - they are not part of any request.

@vas3a vas3a merged commit e628580 into dev Jun 5, 2025
1 check passed
@vas3a vas3a deleted the logger branch June 5, 2025 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant