Repository navigation
fix(telemetry): keep staticmethods static under trace_class - #1430
Open
ShivamSharma43 wants to merge 1 commit into
Open
ShivamSharma43 wants to merge 1 commit into
ShivamSharma43 wants to merge 1 commit into
Conversation
trace_class collects methods with inspect.getmembers(cls, inspect.isfunction), which unwraps a staticmethod into its plain function. The traced wrapper was then set back on the class as a plain function, so the method became an instance method: calling it on an instance passed self as the first argument and raised TypeError. Re-wrap the traced function in staticmethod when the class attribute is a staticmethod, including one inherited from a base class. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🧪 Code Coverage (vs
|
| Base | PR | Delta | |
|---|---|---|---|
| src/a2a/utils/telemetry.py | 90.70% | 91.04% | 🟢 +0.35% |
| Total | 93.53% | 93.53% | ⚪️ 0.00% |
Generated by coverage-comment.yml
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
trace_classturns a@staticmethodinto an instance method. It collects methods withinspect.getmembers(cls, inspect.isfunction), which returns the plain function behind a staticmethod. The traced wrapper is then set back on the class withsetattr, without thestaticmethodwrapper, so calling the method on an instance passesselfas its first argument:None of the SDK's own traced classes has a staticmethod today, but
trace_classis public and its docstring shows it applied to user classes.Fix
After building the traced wrapper, check the class attribute with
inspect.getattr_static. If it is astaticmethod, wrap the traced function instaticmethodagain before setting it. This also covers a staticmethod inherited from a base class, whichgetmembersreturns as well. Instance methods are unchanged, and classmethods stay untraced as before, becausegetmembersreturns them as bound methods.Tests
test_trace_class_keeps_staticmethod_staticdecorates a class with its own staticmethod and an inherited one. It calls them through an instance, through the class, and from another method, and it checks that both staystaticmethodobjects and are still traced. On main it fails with theTypeErrorabove. With the fix it passes.uv run pytest tests/utils/test_telemetry.py: 22 passedbash scripts/lint.sh: success. The 3 ruff diagnostics it prints are inclient_factory.pyandtransports/__init__.py, which this change does not touch.uv run pyteston Windows, Python 3.10, skippingtests/integration/cross_versionandtests/integration/push_notificationsbecause they needos.killpgand fork-based multiprocessing: 2549 passed, 207 skipped, 4 xfailed, 1 xpassed🤖 Generated with Claude Code