-
Notifications
You must be signed in to change notification settings - Fork 5
Add trace_id to Logs for Enhanced Traceability #265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅ 📢 Thoughts on this report? Let us know! |
95722dd to
862b3dd
Compare
WalkthroughThe changes integrate request correlation IDs throughout the backend. Middleware is added to propagate correlation IDs per request, logging is enhanced to include the correlation ID in each log entry, and traces now always record the request ID in their metadata. The required dependency is also added to the project configuration. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant FastAPI App
participant CorrelationIdMiddleware
participant Logger
participant Langfuse
Client->>FastAPI App: HTTP Request
FastAPI App->>CorrelationIdMiddleware: Process request
CorrelationIdMiddleware->>FastAPI App: Attach correlation ID to context
FastAPI App->>Logger: Log event (includes correlation ID)
FastAPI App->>Langfuse: start_trace(metadata)
Langfuse->>Langfuse: Add request_id from correlation ID to metadata
Langfuse->>Langfuse: Record trace with metadata
FastAPI App-->>Client: HTTP Response
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (4)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🔇 Additional comments (8)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved
Summary
This PR enhances platform logging by including a trace_id (via correlation_id) in all log entries, improving request traceability across services.
Target issue is #251
The CorrelationIdMiddleware from the asgi-correlation-id package is used to automatically assign and manage a unique trace ID (also called a correlation ID) for each incoming HTTP request in a FastAPI (or any ASGI) application.
Incoming Request:
Storage:
Logging:
Checklist
Before submitting a pull request, please ensure that you mark these task.
fastapi run --reload app/main.pyordocker compose upin the repository root and test.Summary by CodeRabbit
New Features
Chores