From 9d4e7c331f6fce0ab07e40f0a95b354628adf867 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Wed, 1 Oct 2025 15:17:56 +0100 Subject: [PATCH 1/2] Provide a default value for `server_name` This is a backwards-compatibility patch for modules that imported LoggingContext from within Synapse. See https://github.com/matrix-org/synapse-s3-storage-provider/issues/133 --- synapse/logging/context.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/synapse/logging/context.py b/synapse/logging/context.py index 119d3be7bf4..9566d87e9fe 100644 --- a/synapse/logging/context.py +++ b/synapse/logging/context.py @@ -285,7 +285,11 @@ class LoggingContext: Args: name: Name for the context for logging. server_name: The name of the server this context is associated with - (`config.server.server_name` or `hs.hostname`) + (`config.server.server_name` or `hs.hostname`). + + If not provided, this will be set to "SERVER_NAME_NOT_PROVIDED". + This is a backwards-compatibility patch for + https://github.com/matrix-org/synapse-s3-storage-provider/issues/133. parent_context (LoggingContext|None): The parent of the new context request: Synapse Request Context object. Useful to associate all the logs happening to a given request. @@ -309,7 +313,7 @@ def __init__( self, *, name: str, - server_name: str, + server_name: str = "SERVER_NAME_NOT_PROVIDED", parent_context: "Optional[LoggingContext]" = None, request: Optional[ContextRequest] = None, ) -> None: From bce22241e841b98feab3b03a65eb77cdcb2eadb5 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Wed, 1 Oct 2025 15:20:23 +0100 Subject: [PATCH 2/2] re-use newsfile text from #18868 --- changelog.d/19003.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/19003.misc diff --git a/changelog.d/19003.misc b/changelog.d/19003.misc new file mode 100644 index 00000000000..0eb4399406f --- /dev/null +++ b/changelog.d/19003.misc @@ -0,0 +1 @@ +Fix `server_name` in logging context for multiple Synapse instances in one process. \ No newline at end of file