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

Start an opentracing span for background processes. #8567

Merged
merged 3 commits into from
Oct 19, 2020
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/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