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

last_event_id not set on Rails custom 500 handling #1371

Closed
chrismdp opened this issue Mar 29, 2021 · 1 comment · Fixed by #1379
Closed

last_event_id not set on Rails custom 500 handling #1371

chrismdp opened this issue Mar 29, 2021 · 1 comment · Fixed by #1379
Assignees
Milestone

Comments

@chrismdp
Copy link

chrismdp commented Mar 29, 2021

I'm attempting to set up custom error messages so that I can capture information from our users when they hit an issue.

Minimal reproducible example:

  • Set config.exceptions_app = self.routes in config/application.rb
  • Add route: match "/500", to: "errors#internal_server_error", via: :all
  • Set up an error controller with action:
  def internal_server_error
    @sentry_event_id = Sentry.last_event_id
    render status: 500
  end

However, the event isn't being sent until after the action has been run, and therefore the last_event_id method has been called already, returning nil.

Log excerpt:

ActionView::SyntaxErrorInTemplate (Encountered a syntax error while rendering template: check - content_for :body_class app/views/devise/sessions/new.haml:24: syntax error, unexpected end, expecting end-of-input
Processing by ErrorsController#internal_server_error as HTML
  Rendering layout layouts/error.html.haml
  Rendering errors/internal_server_error.html.haml within layouts/error
  Rendered errors/internal_server_error.html.haml within layouts/error (Duration: 0.2ms | Allocations: 16)
  Rendered layouts/_error_tracking.html.haml (Duration: 2.6ms | Allocations: 2238)
  Rendered layout layouts/error.html.haml (Duration: 26.7ms | Allocations: 13990)
Completed 500 Internal Server Error in 8950ms (Views: 28.9ms | ActiveRecord: 0.0ms | Allocations: 31388)

Sending event 5d9cae89107d47299e9ab1f2801add4a to Sentry

Therefore I'm not able to pass the event ID to the Javascript via the view.

This appears to previously work (see #494), so I'm wondering if this is regression in later version of the gem? Or is there a better way of capturing the event id in this case?

  • ruby 2.6.6
  • rails 6.1.3.1
  • sentry-rails 4.3.3
  • sentry-ruby 4.3.1

Thanks!

@chrismdp
Copy link
Author

@st0012 thanks so much for fixing!

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

Successfully merging a pull request may close this issue.

3 participants