Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Action and controller are lost when an error is handled by ActionDispatch::ShowExceptions #200

Open
fsateler opened this issue Dec 10, 2021 · 0 comments

Comments

@fsateler
Copy link

When ActionDispatch::ShowExceptions captures an error, it renders the appropriate error page and then sets the correct exit status. To do this, it reuses the rack env (wrapped in a Request), and resets the path_info to /#{status} and runs that request with an exceptions_app. This may[1] result in the controller and action being overriden, since the exceptions_app will parse the path info and route to a different controller/action. This results in the wrong labels being added to the prometheus metrics.

[1] At least, when an exception app is configured with config.exceptions_app = routes.

We have worked around this locally by re-parsing the path when setting the labels:

  def default_labels(env, result)
    labels = super
    if labels[:controller] == "errors"
      params = begin
        Rails.application.routes.recognize_path(env["REQUEST_PATH"])
      rescue ActionController::RoutingError
        nil # Si no podemos parsear no reemplazamos nomas
      end
      if params
        labels[:controller] = params[:controller]
        labels[:action] = params[:action]
      end
    end
    labels
  end

I don't know how to cleanly fix this. This only works for us because we know the "errors" controller is only used for error routing.

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

No branches or pull requests

1 participant