Fix server_name
in logging context for multiple Synapse instances in one process
#18868
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.
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
Prior art
Previously, we exposed
server_name
by providing a static loggingMetadataFilter
that injected the values:synapse/synapse/config/logger.py
Line 216 in 205d9e4
While this can work fine for the normal case of one Synapse instance per Python process, this configures things globally and isn't compatible when we try to start multiple Synapse instances because each subsequent tenant will overwrite the previous tenant.
What does this PR do?
We remove the
MetadataFilter
and replace it by tracking theserver_name
in theLoggingContext
and expose it with our existingLoggingContextFilter
that we already use to expose information about therequest
.This means that the
server_name
value follows wherever we log as expected even when we have multiple Synapse instances running in the same process.Todo
unknown_server_from_sentinel_context
LoggingContext
in aContextVar
#18871Pull Request Checklist
EventStore
toEventWorkerStore
.".code blocks
.