Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/google/adk/plugins/auto_tracing_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,17 @@ def _rebind(
if getattr(fn, auto_tracing_helpers.WRAPPED_ATTR, False):
return
try:
setattr(
owner,
name,
auto_tracing_helpers.build_tracing_wrapper(
fn, self._tracer, self._caps
),
wrapper = auto_tracing_helpers.build_tracing_wrapper(
fn, self._tracer, self._caps
)
# inspect.getmembers unwraps staticmethod to a plain function.
# Reapply the descriptor so instance access does not bind self.
raw = getattr(owner, "__dict__", {}).get(name)
if isinstance(raw, staticmethod):
wrapper = staticmethod(wrapper)
elif isinstance(raw, classmethod):
wrapper = classmethod(wrapper)
setattr(owner, name, wrapper)
except (AttributeError, TypeError) as exc:
logger.info(
"AutoTracingPlugin: cannot rebind %s.%s: %s",
Expand Down
21 changes: 20 additions & 1 deletion tests/unittests/plugins/test_auto_tracing_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,20 @@ async def _async_method(unused_self, x: int) -> int:

_method.__module__ = _FIXTURE_MODULE_NAME
_async_method.__module__ = _FIXTURE_MODULE_NAME
cls = type("C", (), {"method": _method, "async_method": _async_method})

def _static(a, b=None):
return ("static", a, b)

_static.__module__ = _FIXTURE_MODULE_NAME
cls = type(
"C",
(),
{
"method": _method,
"async_method": _async_method,
"static": staticmethod(_static),
},
)
cls.__module__ = _FIXTURE_MODULE_NAME

module.sync_fn = _sync_fn
Expand Down Expand Up @@ -145,6 +158,12 @@ def _instrument(
return plugin


def test_staticmethod_does_not_bind_instance(fixture):
_instrument(fixture.tracer)
assert fixture.module.C.static(a=1) == ("static", 1, None)
assert fixture.module.C().static(a=1) == ("static", 1, None)


@pytest.mark.parametrize(
"run_fn,expected_substr",
[
Expand Down