diff options
author | Erik Johnston <erik@matrix.org> | 2020-10-19 12:26:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-19 12:26:26 +0100 |
commit | 1fcdbeb3ab66c20fd559f3a8e169b8185b19d067 (patch) | |
tree | 80efa7d4edbef6cead186ecd0575296e1472594f | |
parent | Replace DeferredCache with LruCache where possible (#8563) (diff) | |
download | synapse-1fcdbeb3ab66c20fd559f3a8e169b8185b19d067.tar.xz |
Start an opentracing span for background processes. (#8567)
This should reduce the number of `There was no active span` errors we see. Fixes #8510.
Diffstat (limited to '')
-rw-r--r-- | changelog.d/8567.bugfix | 1 | ||||
-rw-r--r-- | synapse/metrics/background_process_metrics.py | 11 |
2 files changed, 7 insertions, 5 deletions
diff --git a/changelog.d/8567.bugfix b/changelog.d/8567.bugfix new file mode 100644 index 0000000000..4d835df6fd --- /dev/null +++ b/changelog.d/8567.bugfix @@ -0,0 +1 @@ +Fix increase in the number of `There was no active span...` errors logged when using OpenTracing. diff --git a/synapse/metrics/background_process_metrics.py b/synapse/metrics/background_process_metrics.py index 5b73463504..ea5f1c7b62 100644 --- a/synapse/metrics/background_process_metrics.py +++ b/synapse/metrics/background_process_metrics.py @@ -24,6 +24,7 @@ from prometheus_client.core import REGISTRY, Counter, Gauge 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 @@ -197,14 +198,14 @@ def run_as_background_process(desc: str, func, *args, **kwargs): 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, |