Skip to content

Fix http.route tag not set on Rails 8.1+#5518

Merged
vpellan merged 4 commits intoDataDog:masterfrom
nhosoya:fix/http-route-tag-rails-8-1-v2
Apr 2, 2026
Merged

Fix http.route tag not set on Rails 8.1+#5518
vpellan merged 4 commits intoDataDog:masterfrom
nhosoya:fix/http-route-tag-rails-8-1-v2

Conversation

@nhosoya
Copy link
Copy Markdown
Contributor

@nhosoya nhosoya commented Mar 27, 2026

What does this PR do?

Adds a RecognizeRouter module that patches ActionDispatch::Journey::Router#recognize for Rails >= 8.1, and updates the version gate in Patcher#patch to use it. Also adds Rails 8.1 appraisals.

Motivation:

Rails 8.1 removed the private find_routes method by inlining its body directly into recognize (rails/rails@e533a32). As a result, the existing LazyRouter override of find_routes became a no-op on Rails 8.1+, and http.route was never set on the rack.request span.

Closes #5516

Change log entry

Additional Notes:

How to test the change?

BUNDLE_GEMFILE=gemfiles/ruby_3.4_rails81.gemfile bundle exec rspec \
  spec/datadog/tracing/contrib/action_pack/action_dispatch/journey/router_spec.rb

nhosoya and others added 2 commits March 27, 2026 16:07
Rails 8.1 inlined the body of `ActionDispatch::Journey::Router#find_routes`
directly into `recognize`, removing `find_routes` as a separate method.
The existing `LazyRouter` patch targets `find_routes`, so it silently had
no effect on Rails 8.1+, causing `http.route` to never be set on the
`rack.request` span.

Add a `RecognizeRouter` module that patches `recognize` instead, and
update the patcher's version gate to select it for ActionPack >= 8.1.

Two implementation details specific to Rails 8.1:
- Use delete_suffix instead of delete_suffix! as route.path.spec.to_s
  returns a frozen string.
- Capture SCRIPT_NAME before calling super, as recognize modifies
  req.script_name for mounted apps before yielding to the block.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions github-actions bot added integrations Involves tracing integrations tracing labels Mar 27, 2026
@nhosoya nhosoya marked this pull request as ready for review March 27, 2026 07:14
@nhosoya nhosoya requested review from a team as code owners March 27, 2026 07:14
@nhosoya nhosoya requested a review from mabdinur March 27, 2026 07:14
@mabdinur mabdinur mentioned this pull request Apr 1, 2026
@vpellan vpellan added the community Was opened by a community member label Apr 2, 2026
@vpellan
Copy link
Copy Markdown
Contributor

vpellan commented Apr 2, 2026

👋 Hey @nhosoya thank you very much for your contribution! We're going to merge this PR and it should be available in the next release!

@vpellan vpellan merged commit aa52327 into DataDog:master Apr 2, 2026
770 of 772 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community Was opened by a community member integrations Involves tracing integrations tracing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: http.route tag not set on rack.request span in Rails 8.1+ due to removal of ActionDispatch::Journey::Router#find_routes

3 participants