Skip to content

Request lines for an app's error pages log the error page's path, and some errors log two request lines #28

Closed

Description

@ndbroadbent

With config.exceptions_app = routes (an app's own error pages, such as an ErrorsController), Rails' ShowExceptions renders the error page by sending the request through the routes again as GET /<status>. The error page's controller then logs a request line of its own:

  • An error raised inside a controller action logs two request lines: the action's (its method and path, the error's status) and the error page's (GET /500, GET /422).
  • An error raised before the action's line is logged logs only the error page's line, with the wrong method and path. For example, ActionController::BadRequest for a query Rack can't parse is raised while Rails builds the action's instrumentation payload, so the only line is GET /400 instead of the request's own method and path.

Rails keeps the original method and path in the request's action_dispatch.original_request_method and action_dispatch.original_path headers.

LogStruct should:

  1. log the error page's line with the original method and path, and
  2. log one request line per request: skip the error page's line when the failed action already logged one.

To reproduce: a Rails app with config.exceptions_app = routes, match "/500", to: "errors#internal_server_error", via: :all, and an action that raises, requested with action_dispatch.show_exceptions on. The log has the action's line and a second GET /500 line.

Activity

  1. ndbroadbent commented on Oct 18, 2026

    @ndbroadbent
    MemberAuthor

    Fixed in 0.2.1 (changelog, #43). With config.exceptions_app = routes, a request whose action raises has one request line, the action's: the error page's controller no longer logs a second GET /500 line. When the error comes before any action (a routing error) or after it (in a middleware), the error page's line is logged with the request's own method and path, from action_dispatch.original_request_method and action_dispatch.original_path.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions