Skip to content
Snippets Groups Projects
Unverified Commit 1fcdbeb3 authored by Erik Johnston's avatar Erik Johnston Committed by GitHub
Browse files

Start an opentracing span for background processes. (#8567)

This should reduce the number of `There was no active span` errors we
see.

Fixes #8510.
parent 97647b33
No related branches found
No related tags found
No related merge requests found
Fix increase in the number of `There was no active span...` errors logged when using OpenTracing.
...@@ -24,6 +24,7 @@ from prometheus_client.core import REGISTRY, Counter, Gauge ...@@ -24,6 +24,7 @@ from prometheus_client.core import REGISTRY, Counter, Gauge
from twisted.internet import defer from twisted.internet import defer
from synapse.logging.context import LoggingContext, PreserveLoggingContext from synapse.logging.context import LoggingContext, PreserveLoggingContext
from synapse.logging.opentracing import start_active_span
if TYPE_CHECKING: if TYPE_CHECKING:
import resource import resource
...@@ -197,14 +198,14 @@ def run_as_background_process(desc: str, func, *args, **kwargs): ...@@ -197,14 +198,14 @@ def run_as_background_process(desc: str, func, *args, **kwargs):
with BackgroundProcessLoggingContext(desc) as context: with BackgroundProcessLoggingContext(desc) as context:
context.request = "%s-%i" % (desc, count) context.request = "%s-%i" % (desc, count)
try: try:
result = func(*args, **kwargs) with start_active_span(desc, tags={"request_id": context.request}):
result = func(*args, **kwargs)
if inspect.isawaitable(result): if inspect.isawaitable(result):
result = await result result = await result
return result return result
except Exception: except Exception:
logger.exception( logger.exception(
"Background process '%s' threw an exception", desc, "Background process '%s' threw an exception", desc,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment