Add caller_location_filter for custom location key computation#101
Open
jdyoung73 wants to merge 1 commit into
Open
Add caller_location_filter for custom location key computation#101jdyoung73 wants to merge 1 commit into
jdyoung73 wants to merge 1 commit into
Conversation
de641a4 to
929322f
Compare
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>
929322f to
a258044
Compare
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. |
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
Some gems produce different stack frames on the first (cold) vs subsequent (warm) calls to a method. For example, sorbet-runtime uses
call_validation.rbon the cold path andcall_validation_2_7.rbon the warm path, plus an extra_methods.rbframe 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_locationsinto alocation_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_pathsconfiguration option — an array of strings or regexes, consistent with the existingignore_queriesandallow_stack_pathsAPIs. Matching frames are excluded from the location key computation. The full unfiltered caller is still stored for notification display andallow_stack_pathsmatching.This is a minimal, non-breaking change:
attr_accessorignore_location_path?) matching the pattern ofignore_query?subscribe[](no filtering), preserving existing behaviorTest plan
test_ignore_location_paths— verifies N+1 detection works with string matchingtest_ignore_location_paths_with_regex— verifies regex matching workstest_ignore_location_paths_nil_by_default— verifies default behavior is unchanged