Repository navigation
Description
What happens
A private method is never recorded, even when appmap.yml names it under functions. Reviews often turn on a private method: the check that decides who may see something is usually a private helper. Today the recording shows the SQL that helper runs but not the call itself, so a diagram has to point at the query instead of the code that made the decision.
Two places stop it:
lib/appmap/hook.rb:204builds the list of methods to hook frompublic_instance_methods(false) + protected_instance_methods(false). Private methods never enter the list.lib/appmap/hook/method.rb:87, indefining_class, looks for the owner withmethod_defined?(name, false), which is false for a private method. So even a private method that got into the list fails here.
Line 92 then calls Hook::LOG, which is not defined, so the run stops with NameError: uninitialized constant AppMap::Hook::LOG instead of printing the warning. That one is a bug on its own.
What I tried
A local patch on appmap 1.1.1, Ruby 4.0.10 (also confirmed the agent installs, loads and records on Ruby 4.0 without changes):
# hook.rb, after instance_methods is built
named_private = ENV.fetch("APPMAP_PRIVATE_METHODS", "").split(",")
unless named_private.empty?
instance_methods += cls.private_instance_methods(false).select { |m| named_private.include?("#{cls.name}##{m}") }
end
# hook/method.rb, defining_class
hook_class.ancestors.find { |cls| cls.method_defined?(hook_method.name, false) || cls.private_method_defined?(hook_method.name, false) }
# hook/method.rb, activate: keep the method private after wrapping it
was_private = hook_class.private_method_defined?(hook_method.name)
...
cls.send(:private, hook_method.name) if was_privateWith it, the two named private methods were recorded with their callers and the SQL under them, the methods stayed private (private_method_defined? is still true), and the test's result did not change.
The environment variable is only a stand-in. The real version should read the method names from functions in appmap.yml, and only hook private methods that are named there, so a whole package's private helpers are not recorded by default.
Asks
- Record a private method when
functionsnames it, keeping it private. - Fix
Hook::LOGindefining_classso a method that cannot be found prints a warning instead of raising.
Not done: a test, and the functions wiring. Tell me if you want a pull request with the patch above as a start.
Generated by Claude Code
Activity