I want to propose a change to add logging to redirects that happen directly from routes.
Right now when a redirect happens in a route, it’s not clear from the log that an actual redirect happened. I was trying to find where a redirect originated and it took me some time to realize this.
For example with this route:
get :moo, to: "rails/welcome#index"
The logs only shows a line for the initial GET and then the GET for the redirected page.
Started GET "/" for 127.0.0.1 at 2021-10-21 13:09:51 +0200
Started GET "/moo" for 127.0.0.1 at 2021-10-21 13:09:51 +0200
Processing by Rails::WelcomeController#index as */*
...
While a redirect generated in a controller shows a lot more info:
Started GET "/redirect" for 127.0.0.1 at 2021-10-21 13:11:33 +0200
Processing by RegularController#redirect as */*
Redirected to http://localhost:3000/moo
Completed 302 Found in 0ms (ActiveRecord: 0.0ms | Allocations: 414)
Started GET "/moo" for 127.0.0.1 at 2021-10-21 13:11:33 +0200
Processing by Rails::WelcomeController#index as */*
...
I want to add some instrumentation to ActionDispatch::Routing::Redirect
and create a similar log output for redirects from a route.
I’ve already got a working solution ready in a branch on Github.
With these changes a redirect from a route would look like this in the logs:
Started GET "/" for 127.0.0.1 at 2021-10-21 13:14:49 +0200
Redirected to http://localhost:3000/moo
Completed 301 Moved Permanently in 0ms
Started GET "/moo" for 127.0.0.1 at 2021-10-21 13:14:49 +0200
Processing by Rails::WelcomeController#index as */*
...
Curious to hear if this is something you think is worth adding, if there is positive feedback I’d like to create a PR.