feat(billing): add structured JSON access logs for /api/billing [b#003] - #1016
Merged
greatest0fallt1me merged 3 commits intoJul 29, 2026
Merged
Conversation
|
@Stanley471 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
|
Green across the board — merging. Thanks! |
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.
Closes #868
Description
This PR implements structured JSON access logging for all
/api/billingendpoints as part of the GrantFox FWC26 campaign ([b#003]).Every request processed by the
/api/billingrouter emits a structured JSON log entry containing request correlation IDs, latency metrics, HTTP status code, request/response byte counts, and actor/developer identity context on thebillingPino logger channel.Key Changes
1. Enhanced Billing Access Log Middleware (
src/middleware/billingAccessLog.ts)req-id: Canonical request correlation IDlatency&latencyMs: Request processing duration in milliseconds (3 decimal places)status&statusCode: HTTP status codesize&responseBytes: HTTP response body size in bytesrequestBytes: Request payload body size in bytesactor: Authenticated user ID (res.locals.authenticatedUser.id) or developer ID (req.params.developerId/req.body.developerId)requestBytes.finishandcloseresponse events.[REDACTED]) for sensitive log fields.2. Access Log Exports (
src/middleware/accessLog.ts)billingAccessLogMiddleware,createBillingAccessLogMiddleware,billingLogger, and associated types directly fromaccessLog.tsto provide a unified entry point for all access log middlewares.3. Route Integration (
src/routes/billing.ts)billingAccessLogMiddlewarefromaccessLog.jsat the root of the billing router to ensure 100% route coverage (/credits,/disputes,/deduct,/refund,/fee-abstraction,/forecast,/request/:requestId,/).4. Comprehensive Documentation (
docs/BILLING_ACCESS_LOGGING.md)5. Focused Test Coverage
src/middleware/billingAccessLog.test.ts): Verified log fields (req-id,latency,status,size,actor), developer fallback, and redaction logic.src/middleware/billingAccessLog.integration.test.ts): Validated end-to-end request/response lifecycle logging on Express routes.src/middleware/accessLog.test.ts): Tested re-exported billing access log middleware.Log Output Example
{ "level": 30, "time": 1785178800000, "channel": "billing", "correlationId": "req-98765", "requestId": "req-98765", "req-id": "req-98765", "method": "POST", "path": "/api/billing/deduct", "status": 200, "statusCode": 200, "ms": 12.345, "durationMs": 12.345, "latency": 12.345, "latencyMs": 12.345, "requestBytes": 128, "responseBytes": 84, "size": 84, "userId": "dev_user_001", "actor": "dev_user_001", "clientIp": "127.0.0.1", "apiId": "api_weather", "endpointId": "ep_forecast", "apiKeyId": "ak_12345", "amountUsdc": "0.05", "billingRequestId": "client_deduct_99", "msg": "billing request completed" }