Repository navigation
Capture route names for Grape 4 - #635
Merged
Merged
Conversation
Grape 4 moved endpoint route metadata (method/path/api) off the public `options` Hash and onto the protected `Endpoint#config` object (Grape::Endpoint::Options). Reading the old `options[:method]`, `options[:for]`, and `options[:path]` keys under Grape 4 silently returns nil, so every request was named "Grape/Unknown" instead of the real endpoint name. Extract the name-building logic (duplicated between the alias-method and prepend instrumentation paths) into a shared GrapeEndpointNaming.name_for helper that reads from `config` when available (Grape 4) and falls back to the old `options` reads otherwise (Grape 3), preserving the existing name format and rescue-to-"Grape/Unknown" fallback behavior. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Testing the Grape 4 fix required a bundle install with a local --path for gems/instruments-ruby4.gemfile (no writable system gem dir in the sandbox); ignore the resulting vendor directory so it never gets picked up as repo content. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
json 3.0 (2026-09) removed the quirks_mode keyword that Grape 3's ActiveSupport JSON formatter still passes, breaking the Ruby 3.0 / gems/instruments.gemfile matrix cell on any JSON-rendering request. Pin to the maintained 2.x line until that cell moves off Grape 3.
Merged
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.
Summary
Grape 4 endpoints were all being reported as
Grape/Unknowninstead of their real route name (e.g.Grape/GET/WidgetAPI/widgets/:id), so every Grape transaction collapsed into one bucket in Scout.Fixes #634.
Root cause
The instrument built the transaction name from Grape 3 internals —
endpoint.options[:method],options[:for],options[:path]. Grape 4 moved that route metadata off the publicoptionsHash onto the (protected)Endpoint#config(Grape::Endpoint::Options), and renamedoptions[:for]→endpoint.api. Under Grape 4 thoseoptions[...]reads returnnil,.firstraises, and the rescue falls back toGrape/Unknown.Fix
Extract the name-building logic (previously duplicated across the alias-method and prepend wrappers) into a shared
GrapeEndpointNaming.name_forhelper that:http_methods/api/pathfromconfigon Grape 4, andoptions[...]reads on Grape 3,preserving the existing name format and the rescue-to-
Grape/Unknownfallback.Tests
Adds
test_endpoint_name_reflects_the_route, which drives a request through an endpoint and asserts the capturedControllerlayer name is the real route name (and specifically notGrape/Unknown). It fails on the old code and passes with the fix.CI: json pin
Separately, json 3.0 (released 2026-09) removed the
quirks_modekeyword that Grape 3's ActiveSupport JSON formatter still passes, which broke the Ruby 3.0 /gems/instruments.gemfilematrix cell on any JSON-rendering request (unrelated to this change, but it turns that cell red). Pinnedjson < 3in that gemfile to keep the Grape 3 cell green until it moves off Grape 3.Verification
Verified end-to-end against a real multi-endpoint Grape 4 app: booted it, hit
GET/POST/DELETEroutes (incl. path params and nested namespaces) over real HTTP, and confirmed the reported Scout checkin payload contained correct per-endpoint metrics and slow-transaction traces — each namedGrape/<METHOD>/<API>/<path>, noneGrape/Unknown.