feat: add structured JSON access logs for /api/users with comprehensive test coverage - #732
Merged
greatest0fallt1me merged 3 commits intoJul 29, 2026
Conversation
- Add /api/tags and /api/referrals route detection to accessLog middleware so they emit tags_access_log and referrals_access_log entries - Enhance users access log test to assert all required fields: req-id, correlationId, method, path, statusCode, status, ip, durationMs, latency, size, and actor - Add Content-Length / size assertions to users access log tests - Add authenticated actor extraction test for req.user - Add referrals_access_log routing test for the new /api/referrals route - Update JSDoc to document all recognized access log names Closes Predictify-org#572
|
@PHADAR6 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! 🚀 |
Contributor
|
Merged into main via admin resolver (-X theirs). |
Contributor
|
All checks green — merging. Nice job! 🚀 |
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.
Overview
This PR enhances the existing
accessLogmiddleware to emit properly structured JSON access logs for/api/userswith all required fields (req-id,latency,status,size,actor). It also adds route detection for/api/tagsand/api/referralsso those endpoints emit their own named log entries. Comprehensive test coverage ensures every field is validated.Related Issue
Closes #572
Changes
🛡️ Middleware
src/middleware/accessLog.ts— added route detection for:/api/tags→tags_access_log(fixes pre-existing gap)/api/referrals→referrals_access_log(supports new route from Add per-endpoint audit log for /api/referrals mutations [b#053] #627)🧪 Test Coverage
tests/usersAccessLog.test.ts— enhanced to assert:req-id,correlationId,method,path,statusCode,status,ip,durationMs,latency,size,actorContent-Length/size— verifies correct parsing when header is set or absentreq.user.idis logged when presentreferrals_access_logrouting — verifies/api/referralsproduces correct log nameVerification Results
req-idfield present in every log entrydurationMsandlatencyalias both loggedstatusCodeandstatusalias both loggedsizefield, handles missing header gracefullyactorfield with user ID or "anonymous" fallbackcorrelationIdresolved from X-Correlation-Id → X-Request-Id → req.id → UUIDTimeline