Repository navigation
Support @logfire.instrument above @classmethod and @staticmethod - #2807
Closed
astroknot-sheep wants to merge 1 commit into
Closed
astroknot-sheep wants to merge 1 commit into
astroknot-sheep wants to merge 1 commit into
Conversation
PR overviewNo security issues were found in this pull request. Reviews
|
Contributor
There was a problem hiding this comment.
1 issue found across 5 files
Confidence score: 5/5
tests/test_logfire.pyonly covers the configured form above@staticmethod, so regressions in the bare-descriptor path could go undetected. Add a bare@logfire.instrumentcase and assert the call and span.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="tests/test_logfire.py">
<violation number="1" location="tests/test_logfire.py:1467">
P2: This regression test does not cover bare `@logfire.instrument` above `@staticmethod`; it only covers the configured form. Add a bare staticmethod case and assert its call and span so the separate bare-descriptor path is protected.</violation>
</file>
Reply to a comment to ask cubic a question or push back. It learns from your replies.
View guided diff | Re-trigger cubic
| def template_classmethod(cls, a: int) -> str: | ||
| return f'{cls.__name__} {a}' | ||
|
|
||
| @logfire.instrument('staticmethod {a}') |
Contributor
There was a problem hiding this comment.
P2: This regression test does not cover bare @logfire.instrument above @staticmethod; it only covers the configured form. Add a bare staticmethod case and assert its call and span so the separate bare-descriptor path is protected.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At tests/test_logfire.py, line 1467:
<comment>This regression test does not cover bare `@logfire.instrument` above `@staticmethod`; it only covers the configured form. Add a bare staticmethod case and assert its call and span so the separate bare-descriptor path is protected.</comment>
<file context>
@@ -1452,6 +1452,86 @@ def __repr__(self):
+ def template_classmethod(cls, a: int) -> str:
+ return f'{cls.__name__} {a}'
+
+ @logfire.instrument('staticmethod {a}')
+ @staticmethod
+ def template_staticmethod(a: int) -> int:
</file context>
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||||||||
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.
@logfire.instrumentbreaks when it's put above@classmethodor@staticmethodinstead of below:The wrapper is a plain function, so the classmethod/staticmethod binding gets lost. With this change,
instrumentinstruments the underlying__func__and wraps the result in the same descriptor type again.Logfire.instrumentalso treats aclassmethodobject as the decorated function for the bare@logfire.instrumentform (astaticmethodis already callable). I made the same small change in thelogfire-apishim, because the bare form above@classmethodbreaks there too.Tests: added
test_instrument_above_classmethod_and_staticmethod, and a shim case intest_runtime. Both fail on main and pass now.tests/test_logfire.py,tests/test_logfire_api.pyandtests/test_auto_trace.pypass locally. The one exception istest_runtime[with_logfire], which fails the same way on main for me because of a local google-genai import error. ruff and pyright are clean.I used an AI assistant while working on this; I reproduced the issue, reviewed the change and ran the tests myself.