0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-12-14 19:23:53 +01:00

opentracing: use a consistent name for background processes (#10135)

... otherwise we tend to get a namespace clash between the bg process and the
functions that it calls.
This commit is contained in:
Richard van der Hoff 2021-06-07 17:57:49 +01:00 committed by GitHub
parent beb251e3ee
commit b2557cbf42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 2 deletions

1
changelog.d/10135.misc Normal file
View file

@ -0,0 +1 @@
OpenTracing: use a consistent name for background processes.

View file

@ -337,6 +337,7 @@ def ensure_active_span(message, ret=None):
@contextlib.contextmanager @contextlib.contextmanager
def noop_context_manager(*args, **kwargs): def noop_context_manager(*args, **kwargs):
"""Does exactly what it says on the tin""" """Does exactly what it says on the tin"""
# TODO: replace with contextlib.nullcontext once we drop support for Python 3.6
yield yield

View file

@ -204,11 +204,12 @@ def run_as_background_process(desc: str, func, *args, bg_start_span=True, **kwar
with BackgroundProcessLoggingContext(desc, count) as context: with BackgroundProcessLoggingContext(desc, count) as context:
try: try:
ctx = noop_context_manager()
if bg_start_span: if bg_start_span:
ctx = start_active_span( ctx = start_active_span(
desc, tags={SynapseTags.REQUEST_ID: str(context)} f"bgproc.{desc}", tags={SynapseTags.REQUEST_ID: str(context)}
) )
else:
ctx = noop_context_manager()
with ctx: with ctx:
return await maybe_awaitable(func(*args, **kwargs)) return await maybe_awaitable(func(*args, **kwargs))
except Exception: except Exception: