Skip to content

Commit b4d9540

Browse files
authored
Fix @tag_args for non-methods (#17604)
The decorator assumed we were always wrapping function methods
1 parent f1a1c7f commit b4d9540

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

changelog.d/17604.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add support to `@tag_args` for standalone functions.

synapse/logging/opentracing.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,13 +1032,13 @@ def tag_args(func: Callable[P, R]) -> Callable[P, R]:
10321032
def _wrapping_logic(
10331033
_func: Callable[P, R], *args: P.args, **kwargs: P.kwargs
10341034
) -> Generator[None, None, None]:
1035-
# We use `[1:]` to skip the `self` object reference and `start=1` to
1036-
# make the index line up with `argspec.args`.
1037-
#
1038-
# FIXME: We could update this to handle any type of function by ignoring the
1039-
# first argument only if it's named `self` or `cls`. This isn't fool-proof
1040-
# but handles the idiomatic cases.
1041-
for i, arg in enumerate(args[1:], start=1):
1035+
for i, arg in enumerate(args, start=0):
1036+
if argspec.args[i] in ("self", "cls"):
1037+
# Ignore `self` and `cls` values. Ideally we'd properly detect
1038+
# if we were wrapping a method, but that is really non-trivial
1039+
# and this is good enough.
1040+
continue
1041+
10421042
set_tag(SynapseTags.FUNC_ARG_PREFIX + argspec.args[i], str(arg))
10431043
set_tag(SynapseTags.FUNC_ARGS, str(args[len(argspec.args) :]))
10441044
set_tag(SynapseTags.FUNC_KWARGS, str(kwargs))

0 commit comments

Comments
 (0)