feat: propagate logging context through contracts service#528
Merged
Conversation
|
@egwujiohaifesinachiperpetual-max is attempting to deploy a commit to the 1nonly's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@egwujiohaifesinachiperpetual-max 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.
This pr closes #447
Implemented full propagation of a structured logging context throughout the contracts service and all related API routes. This adds a LoggingContext object (containing requestId and optional commitmentId) that is threaded through every service call, making logs for a given operation easily correlatable.
What’s new
src/lib/backend/services/contracts.ts
Introduced LoggingContext interface.
Updated all service method signatures to accept an optional LoggingContext.
Added requestId handling to every log statement inside the contracts service.
API route handlers (src/app/api/...)
Extract requestId from the incoming request (via existing header convention) and build a LoggingContext.
Pass this context down to the contracts service methods.
Updated settle, status, history, and other routes to log with the context.
src/lib/backend/logger.ts
Enhanced logInfo, logError, etc., to include the requestId field in the JSON output.
src/lib/backend/redact.ts
Ensured any sensitive fields inside the logging context are redacted before emission.
Tests
Added/updated unit tests verifying that the LoggingContext is correctly threaded and that logs contain the expected requestId.
Documentation
Updated docs/backend-performance-guidelines.md (and related docs) to describe the new LoggingContext pattern and how to use it.
Benefits
Observability: All logs belonging to a single request now share the same requestId, simplifying tracing in logs and monitoring tools.
Debugging: Easier to pinpoint which logs belong to a particular commitment operation.
Security: Sensitive fields are automatically redacted before being written.
Maintainability: Centralised context handling reduces duplicated code across services.
Checklist
Code compiles (npm run build succeeds).
All existing tests pass; new coverage > 95 % for the modified modules.
Documentation updated to reflect the new logging pattern.
Branch pushed to origin/feature/contracts-log-context-propagation.