With `register_error_subscriber`, view errors are reported twice: the wrapper by the middleware, and its cause by the error subscriber
メンテナーはふだん 2 日以内に返信
評価
- 難易度
- 4/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 57/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 領域
- backend, observability
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Ruby
- スター
- 990
- フォーク
- 552
- 平均マージ
- 2日 16時間
- マージ済み PR(30日)
- 29
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
getsentry/sentry-ruby のほかの issue
-
Bug Ruby
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
getsentry/sentry-ruby#3211 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
Events dropped client-side for size are only logged at debug level and not recorded as lost対応中かも @sentry-junior が今日担当しました。 オープンBug Junior: repro Ruby
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
getsentry/sentry-ruby#3209 · コメント 2 件 · リアクション 1 件 ·
メンテナーはふだん 2 日以内に返信
-
with_child_span drops spans when blocks exit via break, return, or throw対応中かも @itsrayeedscodespace が 1 日前に担当しました。 オープンBug Ruby Traces Waiting for: Product Owner
難易度 2/5 1〜3時間 初心者へのやさしさ 38/100
getsentry/sentry-ruby#3206 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
Let apps choose how the client IP on events is determined対応中かも @sl0thentr0py が 11 日前に担当しました。 オープンImprovement Ruby
getsentry/sentry-ruby#3180 · コメント 2 件 · リアクション 1 件 · 担当者 1 名 ·
メンテナーはふだん 2 日以内に返信
-
breaking change Next Major
難易度 2/5 1〜3時間 初心者へのやさしさ 58/100
getsentry/sentry-ruby#3176 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
getsentry/sentry-ruby の issue をすべて見る
似ている issue
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
internetee/registry#2984 ·
メンテナーはふだん 6 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
ecosyste-ms/issues#862 ·
メンテナーはふだん 1 日以内に返信
-
Redis Lua error `@user_script:52: ERR value is not an integer or out of range` when `window_size` is configured対応中かも @mimosa が今日担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
riscv/riscv-unified-db#2829 ·
メンテナーはふだん 1 日以内に返信
-
⛓️ Security Difficulty: Easy Good First Issue Help Wanted ruby Type: Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
rubyforgood/casa#7404 ·
メンテナーはふだん 1 日以内に返信