Skip to content

Record private methods named in appmap.yml functions (and fix Hook::LOG NameError) #369

Open

Description

@evlawler

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:

  1. lib/appmap/hook.rb:204 builds the list of methods to hook from public_instance_methods(false) + protected_instance_methods(false). Private methods never enter the list.
  2. lib/appmap/hook/method.rb:87, in defining_class, looks for the owner with method_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_private

With 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 functions names it, keeping it private.
  • Fix Hook::LOG in defining_class so 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

  1. added
    bug
    enhancement
    on Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugenhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions