summary refs log tree commit diff
path: root/synapse/logging
diff options
context:
space:
mode:
authorAndrew Morgan <andrew@amorgan.xyz>2021-04-22 11:23:34 +0100
committerAndrew Morgan <andrew@amorgan.xyz>2021-04-22 11:23:34 +0100
commit0f2629ebc6610971557df5810a9b34d7f07c0077 (patch)
treea6d5910c45102451ed01360b43c75a54e6add399 /synapse/logging
parentMerge branch 'release-v1.32.1' of github.com:matrix-org/synapse (diff)
parentA regression can't be introduced twice (diff)
downloadsynapse-0f2629ebc6610971557df5810a9b34d7f07c0077.tar.xz
Merge tag 'v1.32.2'
Synapse 1.32.2 (2021-04-22)
===========================

This release includes a fix for a regression introduced in 1.32.0.

Bugfixes
--------

- Fix a regression in Synapse 1.32.0 and 1.32.1 which caused `LoggingContext` errors in plugins. ([\#9857](https://github.com/matrix-org/synapse/issues/9857))
Diffstat (limited to 'synapse/logging')
-rw-r--r--synapse/logging/context.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/synapse/logging/context.py b/synapse/logging/context.py
index dbd7d3a33a..7fc11a9ac2 100644
--- a/synapse/logging/context.py
+++ b/synapse/logging/context.py
@@ -258,7 +258,8 @@ class LoggingContext:
           child to the parent
 
     Args:
-        name (str): Name for the context for debugging.
+        name: Name for the context for logging. If this is omitted, it is
+           inherited from the parent context.
         parent_context (LoggingContext|None): The parent of the new context
     """
 
@@ -277,12 +278,11 @@ class LoggingContext:
 
     def __init__(
         self,
-        name: str,
+        name: Optional[str] = None,
         parent_context: "Optional[LoggingContext]" = None,
         request: Optional[ContextRequest] = None,
     ) -> None:
         self.previous_context = current_context()
-        self.name = name
 
         # track the resources used by this context so far
         self._resource_usage = ContextResourceUsage()
@@ -314,6 +314,15 @@ class LoggingContext:
             # the request param overrides the request from the parent context
             self.request = request
 
+        # if we don't have a `name`, but do have a parent context, use its name.
+        if self.parent_context and name is None:
+            name = str(self.parent_context)
+        if name is None:
+            raise ValueError(
+                "LoggingContext must be given either a name or a parent context"
+            )
+        self.name = name
+
     def __str__(self) -> str:
         return self.name