Skip to content

Add caller_location_filter for custom location key computation#101

Open
jdyoung73 wants to merge 1 commit into
charkost:mainfrom
jdyoung73:add-caller-location-filter
Open

Add caller_location_filter for custom location key computation#101
jdyoung73 wants to merge 1 commit into
charkost:mainfrom
jdyoung73:add-caller-location-filter

Conversation

@jdyoung73

@jdyoung73 jdyoung73 commented Apr 6, 2026

Copy link
Copy Markdown

Problem

Some gems produce different stack frames on the first (cold) vs subsequent (warm) calls to a method. For example, sorbet-runtime uses call_validation.rb on the cold path and call_validation_2_7.rb on the warm path, plus an extra _methods.rb frame during cold method compilation. Other observability or instrumentation gems may add extra frames on the first call to an instrumented method.

Since Prosopite groups queries by hashing the full caller_locations into a location_key, these differing frames cause identical N+1 queries to be split into separate groups. With exactly 2 queries through such a method, each gets a unique location key (count=1 each) and Prosopite sees no N+1. With 3+ queries the warm path accumulates count>=2, making detection intermittent rather than reliable.

Solution

Add an ignore_location_paths configuration option — an array of strings or regexes, consistent with the existing ignore_queries and allow_stack_paths APIs. Matching frames are excluded from the location key computation. The full unfiltered caller is still stored for notification display and allow_stack_paths matching.

Prosopite.ignore_location_paths = ['sorbet-runtime']

This is a minimal, non-breaking change:

  • 1 new attr_accessor
  • 1 new method (ignore_location_path?) matching the pattern of ignore_query?
  • 1 line added in subscribe
  • Defaults to [] (no filtering), preserving existing behavior
  • All existing tests pass unchanged

Test plan

  • Added test_ignore_location_paths — verifies N+1 detection works with string matching
  • Added test_ignore_location_paths_with_regex — verifies regex matching works
  • Added test_ignore_location_paths_nil_by_default — verifies default behavior is unchanged
  • All 59 tests pass

@jdyoung73 jdyoung73 force-pushed the add-caller-location-filter branch from de641a4 to 929322f Compare April 6, 2026 16:43
Some gems produce different stack frames on the first (cold) vs
subsequent (warm) calls to a method. For example, sorbet-runtime uses
call_validation.rb on the cold path and call_validation_2_7.rb on the
warm path. Other observability or instrumentation gems may add extra
frames on the first call to an instrumented method.

This causes Prosopite to compute different location keys and split
identical N+1 queries into separate groups that fall below the
min_n_queries threshold.

This adds an `ignore_location_paths` configuration option that accepts
an array of strings or regexes. Matching frames are excluded from the
location key computation. The full unfiltered caller is still stored
for notification display.

Example:

  Prosopite.ignore_location_paths = ['sorbet-runtime']

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jdyoung73 jdyoung73 force-pushed the add-caller-location-filter branch from 929322f to a258044 Compare April 7, 2026 15:02
@jdyoung73

Copy link
Copy Markdown
Author

Hi @charkost. When you get a chance, would you mind taking a look at this PR? We've been running into intermittent N+1 detection misses due to gems like sorbet-runtime producing different stack frames on cold vs warm calls, and this small addition would help a lot.

Happy to make any changes based on your feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant