Add structured error logging with request context - #204
Open
Armolas wants to merge 1 commit into
Open
Conversation
Adds logRequestError() as the single place every 5xx/4xx error is logged, carrying correlation id, method, path, user id, client IP, and a full stack trace on first occurrence. Repeat occurrences of the same error on the same route within a 5-minute window (Redis-backed, fails open if Redis is unreachable) collapse into a lightweight line with a running count instead of repeating the full payload. Request bodies are logged at debug level through a new redaction helper so credentials/tokens never reach the logs. handleError/handleOnChainError now take req so they can build this context, and AuthController's private handleError duplicate (which logged with less context than the shared one) is removed in favor of it.
|
@Armolas Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Adds logRequestError() as the single place every 5xx/4xx error is logged, carrying correlation id, method, path, user id, client IP, and a full stack trace on first occurrence.
Description
Every error that flows through
handleError()/handleOnChainError()or Express's global error handler now logs through a single structuredlogRequestError(req, error, statusCode)utility. Each log line carriesreqId(correlation id),method,path,userId, clientip, andstatusCode, with the full stack trace attached on the first occurrence of a given error+route. Repeats of the same error on the same route within a 5-minute window (tracked via a Redis counter, matching the existing rate-limiter/cache patterns in this codebase, and failing open if Redis is unreachable) collapse into a lightweight "duplicate suppressed" line carrying the running count instead of repeating the full payload every time. Request bodies are logged atdebuglevel through a newredactSensitiveFields()helper so passwords/tokens/secrets never reach the logs. 5xx errors log aterrorlevel, 4xx atwarn.handleError/handleOnChainErrorinutils/helpers.tsnow takereqso they can build this context — every controller call site was updated.AuthControllerhad its own privatehandleErrorduplicate that logged with less context than the shared one (and duplicated a manuallogger.errorcall in every catch block); it's been removed in favor of the shared, fully-contextualized path. Added a properExpress.Request.usertype augmentation andLOG_LEVEL/ERROR_DEDUP_WINDOW_MSto the typed env config along the way.Fixes #122
Type of change
Checklist: