From 99ef84b850008e324bc0b1259213f92aa2b8392d Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 23 Aug 2024 14:21:25 +0100 Subject: [PATCH 1/2] Fix @tag_args for non-methods --- synapse/logging/opentracing.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/synapse/logging/opentracing.py b/synapse/logging/opentracing.py index 7a3c805cc5..e32b3f6781 100644 --- a/synapse/logging/opentracing.py +++ b/synapse/logging/opentracing.py @@ -1032,13 +1032,13 @@ def tag_args(func: Callable[P, R]) -> Callable[P, R]: def _wrapping_logic( _func: Callable[P, R], *args: P.args, **kwargs: P.kwargs ) -> Generator[None, None, None]: - # We use `[1:]` to skip the `self` object reference and `start=1` to - # make the index line up with `argspec.args`. - # - # FIXME: We could update this to handle any type of function by ignoring the - # first argument only if it's named `self` or `cls`. This isn't fool-proof - # but handles the idiomatic cases. - for i, arg in enumerate(args[1:], start=1): + for i, arg in enumerate(args, start=0): + if argspec.args[i] in ("self", "cls"): + # Ignore `self` and `cls` values. Ideally we'd properly detect + # if we were wrapping a method, but that is really non-trivial + # and this is good enough. + continue + set_tag(SynapseTags.FUNC_ARG_PREFIX + argspec.args[i], str(arg)) set_tag(SynapseTags.FUNC_ARGS, str(args[len(argspec.args) :])) set_tag(SynapseTags.FUNC_KWARGS, str(kwargs)) From 08da74b6d4d76367b9fc2db9d58ce463de2f1206 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 23 Aug 2024 14:22:21 +0100 Subject: [PATCH 2/2] Newsfile --- changelog.d/17604.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/17604.misc diff --git a/changelog.d/17604.misc b/changelog.d/17604.misc new file mode 100644 index 0000000000..96cb213bbd --- /dev/null +++ b/changelog.d/17604.misc @@ -0,0 +1 @@ +Add support to `@tag_args` for standalone functions.