With `register_error_subscriber`, view errors are reported twice: the wrapper by the middleware, and its cause by the error subscriber
I maintainer di solito rispondono entro 2 giorni
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 57/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Ambito
- backend, observability
Direzione di ricerca
Start in Hub#capture_exception and trace how captured markers and Sentry::Utils::ExceptionCauseChain handle exceptions and their causes. The report describes a reproduction using Rails 8.1.4 and sentry-rails 7.1.0; run it with reloading both off and on, then add focused coverage for each order. Done means one event per view error, retaining request context.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Issue Description
With config.rails.register_error_subscriber = true, every exception raised in a view becomes two Sentry issues.
Sentry::Rails::CaptureExceptionscaptures theActionView::Template::Errorand marks that object with@__sentry_captured.ActionDispatch::ExecutorreportsExceptionWrapper#unwrapped_exceptiontoRails.error. For a template error, that's the wrapper'scause.Sentry::Rails::ErrorSubscriberforwards that report. The cause isn't the marked object, soHub#capture_exceptiondoesn't skip it.
The two events have different types and stacks, so they group separately. When reloading is off, as in production, the executor reports outside the middleware's scope, so the second event also has no request URL or transaction. In development, ActionDispatch::Reloader reports the cause first, from inside the scope.
Related, from the other direction: #2931
Reproduction Steps
Below is a single-file app. enable_reloading = false matches production, and setting it to true shows the development order.
require "bundler/inline"
gemfile { source "https://rubygems.org"; gem "rails", "8.1.4"; gem "sentry-rails", "7.1.0" }
require "action_controller/railtie"
EVENTS = []
class ReproApp < Rails::Application
config.root = __dir__
config.eager_load = false
config.enable_reloading = false
config.consider_all_requests_local = false
config.hosts.clear
config.secret_key_base = "x" * 64
config.logger = Logger.new(nil)
routes.append { get "/" => "pages#show" }
end
Sentry.init do |c|
c.dsn = "https://[email protected]/0"
c.transport.transport_class = Sentry::DummyTransport
c.background_worker_threads = 0
c.rails.register_error_subscriber = true
c.before_send = ->(event, hint) { EVENTS << "#{hint[:exception].class} url=#{event.request&.url.inspect}"; nil }
end
class PagesController < ActionController::Base
def show = render(inline: "<%= raise 'boom' %>")
end
ReproApp.initialize!
ReproApp.call(Rack::MockRequest.env_for("/"))
p EVENTS
Output:
["ActionView::Template::Error url=\"http://example.org/\"", "RuntimeError url=nil"]
Expected Behavior
One event per view error, with request context.
Suggested fix
We tested this in the same app: it produced one event with request context, with reloading on and off. In Hub#capture_exception:
- skip capturing when any exception in the
causechain is already marked as captured; - mark the whole chain after capturing.
The event already includes the chain, via Sentry::Utils::ExceptionCauseChain, so a later capture of any part of it duplicates information Sentry already has.
Versions
Ruby 4.0.9, Rails 8.1.4, sentry-ruby / sentry-rails 7.1.0.
Workaround
Leave register_error_subscriber off and subscribe a Rails.error subscriber that forwards only handled: true reports.
- Lingua principale
- Ruby
- Stelle
- 990
- Fork
- 552
- Merge medio
- 2g 16h
- PR unite (30g)
- 29
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di getsentry/sentry-ruby
-
Bug Ruby
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
getsentry/sentry-ruby#3211 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
Events dropped client-side for size are only logged at debug level and not recorded as lostForse già presa @sentry-junior l’ha presa oggi. ApertaBug Junior: repro Ruby
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
getsentry/sentry-ruby#3209 · 2 commenti · 1 reazione ·
I maintainer di solito rispondono entro 2 giorni
-
with_child_span drops spans when blocks exit via break, return, or throwForse già presa @itsrayeedscodespace l’ha presa 1 giorno fa. ApertaBug Ruby Traces Waiting for: Product Owner
Difficoltà 2/5 1-3 ore Idoneità per principianti 38/100
getsentry/sentry-ruby#3206 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
Let apps choose how the client IP on events is determinedForse già presa @sl0thentr0py l’ha presa 11 giorni fa. ApertaImprovement Ruby
getsentry/sentry-ruby#3180 · 2 commenti · 1 reazione · 1 assegnatario ·
I maintainer di solito rispondono entro 2 giorni
-
breaking change Next Major
Difficoltà 2/5 1-3 ore Idoneità per principianti 58/100
getsentry/sentry-ruby#3176 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di getsentry/sentry-ruby
Issue simili
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
internetee/registry#2984 ·
I maintainer di solito rispondono entro 6 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
ecosyste-ms/issues#862 ·
I maintainer di solito rispondono entro 1 giorno
-
Redis Lua error `@user_script:52: ERR value is not an integer or out of range` when `window_size` is configuredForse già presa @mimosa l’ha presa oggi. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
riscv/riscv-unified-db#2829 ·
I maintainer di solito rispondono entro 1 giorno
-
⛓️ Security Difficulty: Easy Good First Issue Help Wanted ruby Type: Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
rubyforgood/casa#7404 ·
I maintainer di solito rispondono entro 1 giorno