Skip to content

Commit

Permalink
Fix @tag_args for non-methods (#17604)
Browse files Browse the repository at this point in the history
The decorator assumed we were always wrapping function methods
  • Loading branch information
erikjohnston authored Aug 27, 2024
1 parent f1a1c7f commit b4d9540
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog.d/17604.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support to `@tag_args` for standalone functions.
14 changes: 7 additions & 7 deletions synapse/logging/opentracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit b4d9540

Please sign in to comment.