- 
                Notifications
    You must be signed in to change notification settings 
- Fork 405
Be mindful of other logging context filters in 3rd-party code #19068
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
base: develop
Are you sure you want to change the base?
Be mindful of other logging context filters in 3rd-party code #19068
Conversation
01d945b    to
    0256915      
    Compare
  
    | def safe_set(attr: str, value: Any) -> None: | ||
| """ | ||
| Only write the attribute if it hasn't already been set or we actually have | ||
| a Synapse logcontext (indicating that this log record is relevant to | ||
| Synapse). | ||
| """ | ||
| if context is not SENTINEL_CONTEXT or not hasattr(record, attr): | ||
| setattr(record, attr, value) | 
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.
Is the abstraction worth it? Should I just inline the usage?
Originally, I thought I would have to use it more for all of the request attributes below but turns out we can do a little optimization to avoid it.
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.
Why not move setting the server_name under the request attribute? Then you'd only have one usage of safe_set, and then it'd be even more clear that it's not necessary.
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.
I'm not following 🙇
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.
No blocking comments - overall this looks good to me.
| def safe_set(attr: str, value: Any) -> None: | ||
| """ | ||
| Only write the attribute if it hasn't already been set or we actually have | ||
| a Synapse logcontext (indicating that this log record is relevant to | ||
| Synapse). | ||
| """ | ||
| if context is not SENTINEL_CONTEXT or not hasattr(record, attr): | ||
| setattr(record, attr, value) | 
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.
Why not move setting the server_name under the request attribute? Then you'd only have one usage of safe_set, and then it'd be even more clear that it's not necessary.
Be mindful that Synapse can be run alongside other code in the same Python process. We shouldn't overwrite fields on given log record unless we know it's relevant to Synapse.
(no clobber)
Background
As part of Element's plan to support a light form of vhosting (virtual host) (multiple instances of Synapse in the same Python process), we're currently diving into the details and implications of running multiple instances of Synapse in the same Python process.
"Per-tenant logging" tracked internally by https://github.com/element-hq/synapse-small-hosts/issues/48
Pull Request Checklist
EventStoretoEventWorkerStore.".code blocks.