diff --git a/sentry-ruby/3166/Gemfile b/sentry-ruby/3166/Gemfile new file mode 100644 index 0000000..d864ddf --- /dev/null +++ b/sentry-ruby/3166/Gemfile @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gem "rails", "8.1.4" + +# Set SENTRY_RUBY_PATH to a local sentry-ruby checkout to test a fix branch. +if (path = ENV["SENTRY_RUBY_PATH"]) + gem "sentry-ruby", path: File.join(path, "sentry-ruby") + gem "sentry-rails", path: File.join(path, "sentry-rails") +else + gem "sentry-rails", "7.1.0" +end diff --git a/sentry-ruby/3166/Gemfile.lock b/sentry-ruby/3166/Gemfile.lock new file mode 100644 index 0000000..91a0970 --- /dev/null +++ b/sentry-ruby/3166/Gemfile.lock @@ -0,0 +1,308 @@ +GEM + remote: https://rubygems.org/ + specs: + action_text-trix (2.1.19) + railties + actioncable (8.1.4) + actionpack (= 8.1.4) + activesupport (= 8.1.4) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + zeitwerk (~> 2.6) + actionmailbox (8.1.4) + actionpack (= 8.1.4) + activejob (= 8.1.4) + activerecord (= 8.1.4) + activestorage (= 8.1.4) + activesupport (= 8.1.4) + mail (>= 2.8.0) + actionmailer (8.1.4) + actionpack (= 8.1.4) + actionview (= 8.1.4) + activejob (= 8.1.4) + activesupport (= 8.1.4) + mail (>= 2.8.0) + rails-dom-testing (~> 2.2) + actionpack (8.1.4) + actionview (= 8.1.4) + activesupport (= 8.1.4) + nokogiri (>= 1.8.5) + rack (>= 2.2.4) + rack-session (>= 1.0.1) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + useragent (~> 0.16) + actiontext (8.1.4) + action_text-trix (~> 2.1.15) + actionpack (= 8.1.4) + activerecord (= 8.1.4) + activestorage (= 8.1.4) + activesupport (= 8.1.4) + globalid (>= 0.6.0) + nokogiri (>= 1.8.5) + actionview (8.1.4) + activesupport (= 8.1.4) + builder (~> 3.1) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + activejob (8.1.4) + activesupport (= 8.1.4) + globalid (>= 0.3.6) + activemodel (8.1.4) + activesupport (= 8.1.4) + activerecord (8.1.4) + activemodel (= 8.1.4) + activesupport (= 8.1.4) + timeout (>= 0.4.0) + activestorage (8.1.4) + actionpack (= 8.1.4) + activejob (= 8.1.4) + activerecord (= 8.1.4) + activesupport (= 8.1.4) + marcel (~> 1.0) + activesupport (8.1.4) + base64 + bigdecimal + concurrent-ruby (~> 1.0, >= 1.3.1) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + json + logger (>= 1.4.2) + minitest (>= 5.1) + securerandom (>= 0.3) + tzinfo (~> 2.0, >= 2.0.5) + uri (>= 0.13.1) + base64 (0.3.0) + bigdecimal (4.1.3) + builder (3.3.0) + concurrent-ruby (1.3.8) + connection_pool (3.0.2) + crass (1.0.8) + date (3.6.0) + drb (2.2.3) + erb (6.0.7) + erubi (1.13.1) + globalid (1.4.0) + activesupport (>= 6.1) + i18n (1.15.2) + concurrent-ruby (~> 1.0) + io-console (0.9.5) + irb (1.18.0) + pp (>= 0.6.0) + prism (>= 1.3.0) + rdoc (>= 4.0.0) + reline (>= 0.4.2) + json (3.1.0) + logger (1.7.0) + loofah (2.25.3) + crass (~> 1.0.2) + nokogiri (>= 1.19.5) + mail (2.9.1) + logger + mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp + marcel (1.2.1) + mini_mime (1.1.5) + minitest (6.0.6) + drb (~> 2.0) + prism (~> 1.5) + net-imap (0.6.8) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.4.0) + timeout + net-smtp (0.5.2) + net-protocol + nio4r (2.7.5) + nokogiri (1.19.7-aarch64-linux-gnu) + racc (~> 1.4) + nokogiri (1.19.7-aarch64-linux-musl) + racc (~> 1.4) + nokogiri (1.19.7-arm-linux-gnu) + racc (~> 1.4) + nokogiri (1.19.7-arm-linux-musl) + racc (~> 1.4) + nokogiri (1.19.7-arm64-darwin) + racc (~> 1.4) + nokogiri (1.19.7-x86_64-darwin) + racc (~> 1.4) + nokogiri (1.19.7-x86_64-linux-gnu) + racc (~> 1.4) + nokogiri (1.19.7-x86_64-linux-musl) + racc (~> 1.4) + pp (0.6.4) + prettyprint + prettyprint (0.2.1) + prism (1.9.0) + racc (1.8.1) + rack (3.2.8) + rack-session (2.1.2) + base64 (>= 0.1.0) + rack (>= 3.0.0) + rack-test (2.3.0) + rack (>= 1.3) + rackup (2.3.1) + rack (>= 3) + rails (8.1.4) + actioncable (= 8.1.4) + actionmailbox (= 8.1.4) + actionmailer (= 8.1.4) + actionpack (= 8.1.4) + actiontext (= 8.1.4) + actionview (= 8.1.4) + activejob (= 8.1.4) + activemodel (= 8.1.4) + activerecord (= 8.1.4) + activestorage (= 8.1.4) + activesupport (= 8.1.4) + bundler (>= 1.15.0) + railties (= 8.1.4) + rails-dom-testing (2.3.0) + activesupport (>= 5.0.0) + minitest + nokogiri (>= 1.6) + rails-html-sanitizer (1.7.2) + loofah (~> 2.25, >= 2.25.3) + nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) + railties (8.1.4) + actionpack (= 8.1.4) + activesupport (= 8.1.4) + irb (~> 1.13) + rackup (>= 1.0.0) + rake (>= 12.2) + thor (~> 1.0, >= 1.2.2) + tsort (>= 0.2) + zeitwerk (~> 2.6) + rake (13.4.2) + rbs (4.2.0) + logger + prism (>= 1.6.0) + tsort + rdoc (8.1.0) + erb + prism (>= 1.6.0) + rbs (>= 4.0.0) + tsort + reline (0.7.0) + io-console (~> 0.5) + securerandom (0.4.1) + sentry-rails (7.1.0) + railties (>= 5.2.0) + sentry-ruby (~> 7.1.0) + sentry-ruby (7.1.0) + bigdecimal + concurrent-ruby (~> 1.0, >= 1.0.2) + logger + thor (1.5.0) + timeout (0.6.1) + tsort (0.2.0) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + uri (1.1.2) + useragent (0.16.11) + websocket-driver (0.8.2) + base64 + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + zeitwerk (2.8.3) + +PLATFORMS + aarch64-linux-gnu + aarch64-linux-musl + arm-linux-gnu + arm-linux-musl + arm64-darwin + x86_64-darwin + x86_64-linux-gnu + x86_64-linux-musl + +DEPENDENCIES + rails (= 8.1.4) + sentry-rails (= 7.1.0) + +CHECKSUMS + action_text-trix (2.1.19) sha256=7012f59421009cf284aa651294896414d653a61a2417c9b8714c8476d2f74009 + actioncable (8.1.4) sha256=cfcd72f8c861e01ccdc96d772ad8c5ad6ed0ea7c571aef81a794b6027eaa7f11 + actionmailbox (8.1.4) sha256=9c4525e577ebb671ce558f3ea78b8a634f64e56a0e6e8d105b28b873793a06eb + actionmailer (8.1.4) sha256=f82d95d6762ae46ea38f221d3363639266af4f8e56d50e2bd367558674baf093 + actionpack (8.1.4) sha256=245493cc51be195a7645e6fc184880fa7e5b32ff1a08e053ee31f58c76e30ea4 + actiontext (8.1.4) sha256=33ee99bea7da6af911fc7d98b17013a8e1ec62aa01b20b20e9a5366f40dbf644 + actionview (8.1.4) sha256=eff1efd07c4d969abad288322b423bcb67fdbab5e324c91ca37352b80f226076 + activejob (8.1.4) sha256=4ed5b2ed8d4cc5c8f5f09becfef8346f202a4884eee0c8c73cae5ac378824099 + activemodel (8.1.4) sha256=9a0906c127bd118aa5f06157db12b8f750da83dccee72db2f658547a0ae7a0e8 + activerecord (8.1.4) sha256=3b4957ea7f246c9231bd7faa909312eac03a9101aaf87977b6c52733ff00b04f + activestorage (8.1.4) sha256=f4956f3ec9ee63e5e0b332b57c877cb627f82b56f4cc902279310d2aa285c7a8 + activesupport (8.1.4) sha256=891dd3fe43c4fc8391934b237b1189bb1f661c932a84a840043db9d46a4e80df + base64 (0.3.0) sha256=27337aeabad6ffae05c265c450490628ef3ebd4b67be58257393227588f5a97b + bigdecimal (4.1.3) sha256=61ebe1e5e559bdc3cc6f2c0ee7f427321fc838f59611c294356eb04d6e21cf66 + builder (3.3.0) sha256=497918d2f9dca528fdca4b88d84e4ef4387256d984b8154e9d5d3fe5a9c8835f + bundler (4.0.23) sha256=407ba8a1d928f412847f819aa5f8b6aef7c59fb51feb517112af8a165487287b + concurrent-ruby (1.3.8) sha256=b2f1be836e968ccc78ccfce277ea79c72a88633f22306782c16ff23fb415d1e1 + connection_pool (3.0.2) sha256=33fff5ba71a12d2aa26cb72b1db8bba2a1a01823559fb01d29eb74c286e62e0a + crass (1.0.8) sha256=7a0145c7a2c59f8e7923b3a69ce819c444823a00a5127d805298fea13be24efe + date (3.6.0) sha256=18ac945c4e24ebd93534f8eab8c2fd8c5604b3e977105b3798d62a1e8d27b580 + drb (2.2.3) sha256=0b00d6fdb50995fe4a45dea13663493c841112e4068656854646f418fda13373 + erb (6.0.7) sha256=c5ca6dc25b0ef974a44dc8f59fe847577122483b1968a38dec305c60bf91ee92 + erubi (1.13.1) sha256=a082103b0885dbc5ecf1172fede897f9ebdb745a4b97a5e8dc63953db1ee4ad9 + globalid (1.4.0) sha256=037f12fbf1d9d7a014d501c2d5c77356fd4ddd96d7a7991d6700bba96706f427 + i18n (1.15.2) sha256=00f9eb62412fe593b2a65a97daa75300d37abb8f7202ec748e94b6d46a9dd1b5 + io-console (0.9.5) sha256=83dd9bbf4c4680416629245b39cd4212eb5f4d9a4ea91804870c1f6b846414d5 + irb (1.18.0) sha256=de9454a0703a54704b9811a5ef31a60c86949fbf4013fcf244fabc7c775248e3 + json (3.1.0) sha256=3ce7ccf8fde58960177a3a756c31f292a4c1e1dedee884547096a5b0604e3bd8 + logger (1.7.0) sha256=196edec7cc44b66cfb40f9755ce11b392f21f7967696af15d274dde7edff0203 + loofah (2.25.3) sha256=545f14eef0cc2a7de80df560530d593232b7c07e515c5c4e37532d9cb5b0185c + mail (2.9.1) sha256=06574eca475253d6c18145dd70af80d0eb970182d55053497c5f4d797ea160e8 + marcel (1.2.1) sha256=1678e9360e32f9eafa917c80029e2f6d10b2715c66a4b87b6d0da9b9cd1f859f + mini_mime (1.1.5) sha256=8681b7e2e4215f2a159f9400b5816d85e9d8c6c6b491e96a12797e798f8bccef + minitest (6.0.6) sha256=153ea36d1d987a62942382b61075745042a2b3123b1cd48f4c3675af9cc7d6f1 + net-imap (0.6.8) sha256=eb30bb62227b64a3af6b518b04b2375113d69f68f15de59b0193b07d98acf6d9 + net-pop (0.1.2) sha256=848b4e982013c15b2f0382792268763b748cce91c9e91e36b0f27ed26420dff3 + net-protocol (0.4.0) sha256=f9f90c8c6f64794a45160bf422177a336db12809de3beeeaa26b88fcd2e8c853 + net-smtp (0.5.2) sha256=35103cc04d6b2d94632f9928ede07483c24b70b9c0db1f231fea43909b678f3c + nio4r (2.7.5) sha256=6c90168e48fb5f8e768419c93abb94ba2b892a1d0602cb06eef16d8b7df1dca1 + nokogiri (1.19.7-aarch64-linux-gnu) sha256=8f5e15d299602456406e1f03a9f3456cceb33a0722811e818d2ee2214eb4c84a + nokogiri (1.19.7-aarch64-linux-musl) sha256=efe0c3602e6e54521bc21c681930ce5568e2d11203de17400710b2b3ca2e4cb4 + nokogiri (1.19.7-arm-linux-gnu) sha256=7fd1907125691aa89e838cc91161761c758b4e17bb32f0dd9b5515a82cc759af + nokogiri (1.19.7-arm-linux-musl) sha256=28d0ff0c87b6bb2e56580323a6fb049d5d4a02b94f0958fdd47e9ac146991c77 + nokogiri (1.19.7-arm64-darwin) sha256=f27d7f25f4873fbc3aa35a2cc2fb680c98555fec1925348da439d0869d541142 + nokogiri (1.19.7-x86_64-darwin) sha256=508e81e8c5f84aaa240dce981bf1c43faae60808726f0ce7024ee92effc5cafe + nokogiri (1.19.7-x86_64-linux-gnu) sha256=25865ccb462f714e712fdf8906fde07849cb6704a808e3d629d75baa5af5dd3b + nokogiri (1.19.7-x86_64-linux-musl) sha256=464d1f3dfb0d53cf54c0c6a7e23e8e91cf68ec3cafc2b27dc4a7682f2d9bf546 + pp (0.6.4) sha256=dfcb0fce700c41456265922884f9fe195d7fbb0674a3578e6c0f69588e82b570 + prettyprint (0.2.1) sha256=d555d57ea6d7cf001d4774b693546a6bd88bec1e778ddffb5c60b68ceec4b7d4 + prism (1.9.0) sha256=7b530c6a9f92c24300014919c9dcbc055bf4cdf51ec30aed099b06cd6674ef85 + racc (1.8.1) sha256=4a7f6929691dbec8b5209a0b373bc2614882b55fc5d2e447a21aaa691303d62f + rack (3.2.8) sha256=1fecc85e463ebc7a2a945fff829ffcd549babeb1556384796fad946c28dc4ec7 + rack-session (2.1.2) sha256=595434f8c0c3473ae7d7ac56ecda6cc6dfd9d37c0b2b5255330aa1576967ffe8 + rack-test (2.3.0) sha256=b118d177cc002c572fc1b6fd8d19c9ed5881a36e8d6f689f9e618f9f861241e8 + rackup (2.3.1) sha256=6c79c26753778e90983761d677a48937ee3192b3ffef6bc963c0950f94688868 + rails (8.1.4) sha256=5f3ecdf9a2a3b79b2e31b8fee3b64a00f7284d76e5631f87d0e58e665911a33b + rails-dom-testing (2.3.0) sha256=8acc7953a7b911ca44588bf08737bc16719f431a1cc3091a292bca7317925c1d + rails-html-sanitizer (1.7.2) sha256=a21ef45b7a6639fc8e2282473c547514cb86ae271616162a946bf89148fa2424 + railties (8.1.4) sha256=b5e7a8e8984e33114d68af62227971960aae1e6c02bd7c9d826ffad97fff583c + rake (13.4.2) sha256=cb825b2bd5f1f8e91ca37bddb4b9aaf345551b4731da62949be002fa89283701 + rbs (4.2.0) sha256=51f7b886dcc05bc09e10b901daa6a81829f6adc03101d6ca9ea4aac6103e0674 + rdoc (8.1.0) sha256=befc37880a5cfd36dcb176c748b5fd5ee39dd3536a75e81824e4972ce230f60a + reline (0.7.0) sha256=5b012d8e55dbf9d450f12bde2cf7d15ff546ae80b3f8f3b30e570d431815583d + securerandom (0.4.1) sha256=cc5193d414a4341b6e225f0cb4446aceca8e50d5e1888743fac16987638ea0b1 + sentry-rails (7.1.0) sha256=21e2092f8ab013ec384a4a3e406622a1c2a04d6638c697b8f922d9d46da634fa + sentry-ruby (7.1.0) sha256=bd6d2d022d879268526f62f0dccfb76aac99542bfce355e2b6a49cd1a81c0102 + thor (1.5.0) sha256=e3a9e55fe857e44859ce104a84675ab6e8cd59c650a49106a05f55f136425e73 + timeout (0.6.1) sha256=78f57368a7e7bbadec56971f78a3f5ecbcfb59b7fcbb0a3ed6ddc08a5094accb + tsort (0.2.0) sha256=9650a793f6859a43b6641671278f79cfead60ac714148aabe4e3f0060480089f + tzinfo (2.0.6) sha256=8daf828cc77bcf7d63b0e3bdb6caa47e2272dcfaf4fbfe46f8c3a9df087a829b + uri (1.1.2) sha256=89292e98eabbef6248b0a0ed5e7e398e152f83f17560023a6d94a7f492b169fb + useragent (0.16.11) sha256=700e6413ad4bb954bb63547fa098dddf7b0ebe75b40cc6f93b8d54255b173844 + websocket-driver (0.8.2) sha256=97c556b019bf3410b4961002ac501621e9322d3f8a7bc02161a09301cc4c4146 + websocket-extensions (0.1.5) sha256=1c6ba63092cda343eb53fc657110c71c754c56484aad42578495227d717a8241 + zeitwerk (2.8.3) sha256=2c85125a8467ce069e20123d1e709a08955c9d29c118c25b46b7b7fafdbb92e5 + +BUNDLED WITH + 4.0.23 diff --git a/sentry-ruby/3166/README.md b/sentry-ruby/3166/README.md new file mode 100644 index 0000000..71fb221 --- /dev/null +++ b/sentry-ruby/3166/README.md @@ -0,0 +1,72 @@ +# Reproduction for sentry-ruby#3166 + +**Issue:** https://github.com/getsentry/sentry-ruby/issues/3166 +**Proposed fix:** https://github.com/getsentry/sentry-ruby/pull/3167 + +## Description + +With `config.rails.register_error_subscriber = true`, an exception raised in a view is reported twice: + +1. `Sentry::Rails::CaptureExceptions` captures the `ActionView::Template::Error` and marks that object as captured. +2. `ActionDispatch::Executor` (or `ActionDispatch::Reloader` in development) reports `ExceptionWrapper#unwrapped_exception`, which is the wrapper's `cause`, to `Rails.error`. `Sentry::Rails::ErrorSubscriber` forwards it, and because the cause is a different object, `Hub#capture_exception` doesn't skip it. + +The two events have different types and stacks, so they group as separate issues. With reloading off (production), the second event has no request context. + +## Steps to Reproduce + +1. Install dependencies: + ```bash + bundle install + ``` + +2. Run the reproduction (production order, reloading off): + ```bash + bundle exec ruby repro.rb + ``` + +3. Run it with reloading on (development order): + ```bash + bundle exec ruby repro.rb reloading + ``` + +Events are captured in-process with `Sentry::DummyTransport`. To send them to a real project, `export SENTRY_DSN=...` first. + +To test a local sentry-ruby checkout (e.g. a fix branch) instead of the released gem: + +```bash +SENTRY_RUBY_PATH=/path/to/sentry-ruby BUNDLE_GEMFILE=Gemfile.local bundle exec ruby repro.rb +``` + +(Copy `Gemfile` to `Gemfile.local` first so the released `Gemfile.lock` stays untouched.) + +## Expected Behavior + +One event per view error, with request context. + +## Actual Behavior + +sentry-rails 7.1.0, reloading off: + +``` +events (2): + ActionView::Template::Error url="http://example.org/" + RuntimeError url=nil +BUG: expected 1 event, got 2 +``` + +Reloading on: + +``` +events (2): + RuntimeError url="http://example.org/" + ActionView::Template::Error url="http://example.org/" +BUG: expected 1 event, got 2 +``` + +Same on sentry-ruby master (`6a919396`, 7.2.0). With PR #3167 (`20dad7e6`), both modes produce one event with a request URL. + +## Environment + +- Ruby: 4.0 +- Rails: 8.1.4 +- sentry-ruby / sentry-rails: 7.1.0 diff --git a/sentry-ruby/3166/repro.rb b/sentry-ruby/3166/repro.rb new file mode 100644 index 0000000..a4395c2 --- /dev/null +++ b/sentry-ruby/3166/repro.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +# Reproduction for getsentry/sentry-ruby#3166 +# +# With `config.rails.register_error_subscriber = true`, a view error is reported twice: +# 1. Sentry::Rails::CaptureExceptions captures the ActionView::Template::Error (with request context) +# 2. Rails.error (via ActionDispatch::Executor / Reloader) reports its `cause`, which +# Sentry::Rails::ErrorSubscriber forwards as a second, separately grouped event +# +# Expected: one event per view error, with request context. +# Actual: two events; in production mode (reloading off) the second has no request URL. +# +# Usage: ruby repro.rb [reloading] # pass "reloading" to mimic development + +require "bundler/setup" +require "action_controller/railtie" +require "sentry-rails" + +RELOADING = ARGV.include?("reloading") +EVENTS = [] + +class ReproApp < Rails::Application + config.root = __dir__ + config.eager_load = false + config.enable_reloading = RELOADING + 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| + # Events never leave the process; set SENTRY_DSN to send them to a real project instead. + c.dsn = ENV.fetch("SENTRY_DSN", "https://key@o0.ingest.sentry.io/0") + c.transport.transport_class = Sentry::DummyTransport unless ENV["SENTRY_DSN"] + c.background_worker_threads = 0 + c.rails.register_error_subscriber = true + c.before_send = lambda do |event, hint| + EVENTS << "#{hint[:exception].class} url=#{event.request&.url.inspect}" + ENV["SENTRY_DSN"] ? event : nil + end +end + +class PagesController < ActionController::Base + def show = render(inline: "<%= raise 'boom' %>") +end + +ReproApp.initialize! +ReproApp.call(Rack::MockRequest.env_for("/")) + +puts "sentry-ruby #{Sentry::VERSION}, rails #{Rails.version}, reloading=#{RELOADING}" +puts "events (#{EVENTS.size}):" +EVENTS.each { |e| puts " #{e}" } +puts(EVENTS.size == 1 ? "OK: one event" : "BUG: expected 1 event, got #{EVENTS.size}")