Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Improve logging for logcontext leaks. #5288

Merged
merged 1 commit into from
May 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/5288.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve logging for logcontext leaks.
22 changes: 13 additions & 9 deletions synapse/util/logcontext.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ def __init__(self, name=None, parent_context=None, request=None):
self.request = request

def __str__(self):
if self.request:
return str(self.request)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want a request ID instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's what that is.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(the str() is just belt-and-braces)

return "%s@%x" % (self.name, id(self))

@classmethod
Expand Down Expand Up @@ -274,12 +276,10 @@ def __exit__(self, type, value, traceback):
current = self.set_current_context(self.previous_context)
if current is not self:
if current is self.sentinel:
logger.warn("Expected logging context %s has been lost", self)
logger.warning("Expected logging context %s was lost", self)
else:
logger.warn(
"Current logging context %s is not expected context %s",
current,
self
logger.warning(
"Expected logging context %s but found %s", self, current
)
self.previous_context = None
self.alive = False
Expand Down Expand Up @@ -433,10 +433,14 @@ def __exit__(self, type, value, traceback):
context = LoggingContext.set_current_context(self.current_context)

if context != self.new_context:
logger.warn(
"Unexpected logging context: %s is not %s",
context, self.new_context,
)
if context is LoggingContext.sentinel:
logger.warning("Expected logging context %s was lost", self.new_context)
else:
logger.warning(
"Expected logging context %s but found %s",
self.new_context,
context,
)

if self.current_context is not LoggingContext.sentinel:
if not self.current_context.alive:
Expand Down