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

Commit c302d93

Browse files
committed
Fix behaviour when tracing is not enabled
`start_active_span` always returns a truthy result, so we need to go further round the houses to get the span.
1 parent f71e964 commit c302d93

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Diff for: synapse/util/caches/response_cache.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
from synapse.logging.context import make_deferred_yieldable, run_in_background
2222
from synapse.logging.opentracing import (
23+
active_span,
2324
start_active_span,
2425
start_active_span_follows_from,
2526
)
@@ -225,11 +226,10 @@ async def handle_request(request):
225226
async def cb() -> RV:
226227
# NB it is important that we do not `await` before setting span_context!
227228
nonlocal span_context
228-
with start_active_span(
229-
f"ResponseCache[{self._name}].calculate"
230-
) as scope:
231-
if scope:
232-
span_context = scope.span.context
229+
with start_active_span(f"ResponseCache[{self._name}].calculate"):
230+
span = active_span()
231+
if span:
232+
span_context = span.context
233233
return await callback(*args, **kwargs)
234234

235235
d = run_in_background(cb)
@@ -244,8 +244,9 @@ async def cb() -> RV:
244244
"[%s]: using incomplete cached result for [%s]", self._name, key
245245
)
246246

247+
span_context = entry.opentracing_span_context
247248
with start_active_span_follows_from(
248249
f"ResponseCache[{self._name}].wait",
249-
contexts=[entry.opentracing_span_context],
250+
contexts=(span_context,) if span_context else (),
250251
):
251252
return await make_deferred_yieldable(result)

0 commit comments

Comments
 (0)