Skip to content

feat: propagate logging context through contracts service#528

Merged
1nonlypiece merged 4 commits into
Commitlabs-Org:masterfrom
egwujiohaifesinachiperpetual-max:feature/contracts-log-context-propagation
May 28, 2026
Merged

feat: propagate logging context through contracts service#528
1nonlypiece merged 4 commits into
Commitlabs-Org:masterfrom
egwujiohaifesinachiperpetual-max:feature/contracts-log-context-propagation

Conversation

@egwujiohaifesinachiperpetual-max
Copy link
Copy Markdown
Contributor

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.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 27, 2026

@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.

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 27, 2026

@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! 🚀

Learn more about application limits

@1nonlypiece 1nonlypiece merged commit 563139e into Commitlabs-Org:master May 28, 2026
1 check failed
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.

Backend - Add structured logging context propagation through the contracts service

2 participants