Class: Alplus::Railtie

Inherits:
Rails::Railtie
  • Object
show all
Defined in:
lib/alplus/railtie.rb

Overview

Installs Alplus::RackMiddleware and auto-detects the app root from Rails config, so a Rails app gets automatic unhandled-exception capture with zero explicit wiring beyond setting the ingest key (issue #14 story 2/12).

Middleware position matters, and there are TWO exception renderers to get inside of, not one:

* `ActionDispatch::ShowExceptions` (outer) renders the public error
page in production.
* `ActionDispatch::DebugExceptions` (inner, closer to the app) renders
the developer error page in development — and, crucially, it does
NOT re-raise. In development it rescues the exception and returns the
debug page, so any middleware OUTSIDE it never sees the exception.

Inserting after ShowExceptions (the original fix) works in production — there DebugExceptions re-raises and our middleware, sitting between the two, catches the re-raised exception. But in DEVELOPMENT DebugExceptions swallows first, so unhandled web errors were lost (verified against a real Rails 8 app, 2026-08-17).

insert_after ActionDispatch::DebugExceptions places RackMiddleware inside BOTH renderers — the innermost exception boundary, matching Sentry::Rails::CaptureExceptions. The app's exception now reaches our rescue/re-raise before either renderer runs, in every environment.