-
Notifications
You must be signed in to change notification settings - Fork 0
Log client host/port #65
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
WalkthroughThe changes update the logging functionality in the Changes
Sequence Diagram(s)sequenceDiagram
participant C as Client
participant LM as LoggingMiddleware
participant A as Application
participant L as Logger
C->>LM: Send request (includes client host & port)
LM->>L: Log "Received request" (with method, host, and path)
LM->>A: Pass request for processing
A-->>LM: Return response
LM->>L: Log "Processed request" (including client host details)
LM-->>C: Return response
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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.
Actionable comments posted: 0
🧹 Nitpick comments (3)
dnstapir/starlette.py (3)
19-26: Add null checks and consider privacy implications.While adding client information is useful for debugging, consider:
- Adding null checks as
request.clientmight be None in certain scenarios- Implementing IP address sanitization for privacy (e.g., truncating IPv6 or masking portions of IPv4)
logger.bind( - remote_host=request.client.host, - remote_port=request.client.port, + remote_host=request.client.host if request.client else None, + remote_port=request.client.port if request.client else None, method=request.method, path=request.url.path, ).info( - f"Processing {request.method} request from {request.client.host} to {request.url.path}", + f"Processing {request.method} request from {request.client.host if request.client else 'unknown'} to {request.url.path}", )
33-42: Extract common logging bindings to reduce duplication.The logging bindings are duplicated between the two logging statements. Consider extracting them to a helper method.
+ def _get_request_bindings(self, request: Request) -> dict: + return { + "remote_host": request.client.host if request.client else None, + "remote_port": request.client.port if request.client else None, + "method": request.method, + "path": request.url.path, + } async def dispatch(self, request: Request, call_next: Callable[[Request], Awaitable[Response]]) -> Response: logger = structlog.get_logger() request_id = str(uuid.uuid4()) with structlog.contextvars.bound_contextvars(request_id=request_id): - logger.bind( - remote_host=request.client.host, - remote_port=request.client.port, - method=request.method, - path=request.url.path, - ).info( + logger.bind(**self._get_request_bindings(request)).info( f"Processing {request.method} request from {request.client.host if request.client else 'unknown'} to {request.url.path}", ) # ... existing code ... - logger.bind( - remote_host=request.client.host, - remote_port=request.client.port, - method=request.method, - path=request.url.path, + logger.bind( + **self._get_request_bindings(request), status_code=response.status_code, elapsed=elapsed, ).info(
1-47:Details
❓ Verification inconclusive
Document logging changes and verify compliance with privacy regulations.
The addition of client host/port information to logs might have implications:
- Update documentation to reflect the new logging format
- Verify compliance with privacy regulations (GDPR, etc.) regarding IP address logging
- Consider impact on log aggregation/retention policies
Let's verify if there are any privacy-related documentation or policies in the codebase:
🏁 Script executed:
#!/bin/bash # Search for privacy-related documentation rg -i "privacy|gdpr|data protection|retention" --type mdLength of output: 58
Document logging changes and verify compliance
- The updated logging now includes client IP and port data, which may impact user privacy under GDPR and similar regulations.
- Our initial search did not return any privacy or data protection documentation—please confirm if existing internal policies address this logging approach.
- Update the documentation to explain the new logging format and assess how these changes affect your log aggregation and retention processes.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
dnstapir/starlette.py(2 hunks)pyproject.toml(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- pyproject.toml
Summary by CodeRabbit
New Features
Chores