Do not do opentracing wrapping if tracing is disabled

This shows up in profiles as wasted CPU time.
This commit is contained in:
Kegan Dougal
2026-03-19 13:45:28 +00:00
parent 5354ed1306
commit cce8520efb
2 changed files with 11 additions and 4 deletions
+9
View File
@@ -943,6 +943,10 @@ def _custom_sync_async_decorator(
async def _wrapper(
*args: P.args, **kwargs: P.kwargs
) -> Any: # Return type is RInner
# Short-circuit: if opentracing was disabled after decoration time
# (init_tracer sets opentracing=None), skip all wrapping overhead.
if opentracing is None:
return await func(*args, **kwargs) # type: ignore[unreachable]
# type-ignore: func() returns R, but mypy doesn't know that R is
# Awaitable here.
with wrapping_logic(func, *args, **kwargs): # type: ignore[arg-type]
@@ -953,6 +957,11 @@ def _custom_sync_async_decorator(
# `@defer.inlineCallbacks` or that return a `Deferred` or other `Awaitable`.
@wraps(func)
def _wrapper(*args: P.args, **kwargs: P.kwargs) -> Any:
# Short-circuit: if opentracing was disabled after decoration time
# (init_tracer sets opentracing=None), skip all wrapping overhead.
if opentracing is None:
return func(*args, **kwargs) # type: ignore[unreachable]
scope = wrapping_logic(func, *args, **kwargs)
scope.__enter__()
+2 -4
View File
@@ -455,9 +455,7 @@ class DeferredCacheListDescriptor(_CacheDescriptorBase):
cache_entry.error_bulk(cache, missing, f)
args_to_call = dict(arg_dict)
args_to_call[list_name] = {
cache_key_to_arg(key) for key in missing
}
args_to_call[list_name] = {cache_key_to_arg(key) for key in missing}
# dispatch the call, and attach the two handlers
missing_d = defer.maybeDeferred(
@@ -710,4 +708,4 @@ def _get_cache_key_gen(
pos += 1
else:
if inc:
yield param_defaults[nm]
yield param_defaults[nm]