Repository navigation
fix(observe): detect methods by first parameter only - #2055
Open
zichen0116 wants to merge 1 commit into
Open
zichen0116 wants to merge 1 commit into
zichen0116 wants to merge 1 commit into
Conversation
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
@observe(capture_input=True)silently drops the first positional argument of a free function whenever any parameter is namedselforcls— including keyword-only ones:The function itself still receives the argument and returns the correct value; only the traced input is wrong. Both sync and async functions are affected.
Root cause
LangfuseDecorator._is_methodinlangfuse/_client/observe.pytreated a function as a method if"self"or"cls"appeared anywhere in the signature:_get_input_from_func_argsthen stripsfunc_args[0]as the implicit receiver — which doesn't exist for free functions.Fix
Only the first parameter indicates an unbound instance/class method, so
_is_methodnow checks just that:Genuine instance methods (
def m(self, ...)) and unbound classmethods (def m(cls, ...)) keep their existing behavior; bound methods never reach this code withself/clsvisible (inspect.signaturealready drops the bound argument), so there is no behavior change there.Verification
main(argscaptured as()) and passes with this fix for both sync and async paths.tests/unit/test_observe.py:clskeeps its first positional arg (sync + async),self,cls,selfis not treated as a method.tests/unit/test_observe.py: 20/20 passed.ruff check,ruff format --check, andmypyare clean on the changed files.Closes #18859


Confidence Score: 5/5
The PR appears safe to merge.Summary
Fixes
@observedropping the first argument of free functions that have a later parameter namedselforcls.No actionable issues found. Tests were not run during this review.
Reviews (1) · Last reviewed commit: "fix(observe): detect methods by first pa..." · Reviewed by Greptile