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

Commit

Permalink
Start an opentracing span for background processes. (#8567)
Browse files Browse the repository at this point in the history
This should reduce the number of `There was no active span` errors we
see.

Fixes #8510.
  • Loading branch information
erikjohnston authored Oct 19, 2020
1 parent 97647b3 commit 1fcdbeb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog.d/8567.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix increase in the number of `There was no active span...` errors logged when using OpenTracing.
11 changes: 6 additions & 5 deletions synapse/metrics/background_process_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from twisted.internet import defer

from synapse.logging.context import LoggingContext, PreserveLoggingContext
from synapse.logging.opentracing import start_active_span

if TYPE_CHECKING:
import resource
Expand Down Expand Up @@ -197,14 +198,14 @@ async def run():

with BackgroundProcessLoggingContext(desc) as context:
context.request = "%s-%i" % (desc, count)

try:
result = func(*args, **kwargs)
with start_active_span(desc, tags={"request_id": context.request}):
result = func(*args, **kwargs)

if inspect.isawaitable(result):
result = await result
if inspect.isawaitable(result):
result = await result

return result
return result
except Exception:
logger.exception(
"Background process '%s' threw an exception", desc,
Expand Down

0 comments on commit 1fcdbeb

Please sign in to comment.