From 13087e076b303920fc21dd7171553aaad8a0df0c Mon Sep 17 00:00:00 2001 From: Christophe Lucas <12145+clucas@users.noreply.github.com> Date: Wed, 18 Nov 2026 07:45:22 -0800 Subject: [PATCH 1/2] fix: report each cause's own type and message when its backtrace is shared or missing ExceptionInterface.build skips the stacktrace of a cause whose backtrace was already processed, or that has none, but it built that entry from the outermost exception instead of the cause. The event then showed the outer type, module and message in place of the cause, for example GRPC::Internal -> GRPC::Internal -> PG::UniqueViolation when ActiveRecord copies PG's backtrace into RecordNotUnique. Build the entry from the cause itself. The shared stacktrace is still sent only once. Fixes #3220 Co-Authored-By: Claude Opus 5.5 --- .../lib/sentry/interfaces/exception.rb | 2 +- sentry-ruby/spec/sentry/client_spec.rb | 24 +++++++++++++++++++ sentry-ruby/spec/spec_helper.rb | 24 +++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/sentry-ruby/lib/sentry/interfaces/exception.rb b/sentry-ruby/lib/sentry/interfaces/exception.rb index 79b4210f0..33ca12e9d 100644 --- a/sentry-ruby/lib/sentry/interfaces/exception.rb +++ b/sentry-ruby/lib/sentry/interfaces/exception.rb @@ -41,7 +41,7 @@ def self.build(exception:, stacktrace_builder:, mechanism:, data_collection:) data_collection: data_collection ) else - SingleExceptionInterface.new(exception: exception, mechanism: mechanism) + SingleExceptionInterface.new(exception: e, mechanism: mechanism) end end diff --git a/sentry-ruby/spec/sentry/client_spec.rb b/sentry-ruby/spec/sentry/client_spec.rb index 01a8e9ac8..81fe9c78e 100644 --- a/sentry-ruby/spec/sentry/client_spec.rb +++ b/sentry-ruby/spec/sentry/client_spec.rb @@ -485,6 +485,30 @@ module ExcTag; end end end + context 'when a cause shares its backtrace with its own cause' do + let(:exception) { build_exception_with_shared_backtrace_cause } + + it 'captures the type and message of each cause' do + expect(hash[:exception][:values].map { |value| value[:type] }).to eq(["ArgumentError", "TypeError", "RuntimeError"]) + expect(hash[:exception][:values][1][:value]).to match("exception b") + end + + it 'captures the shared stacktrace once' do + expect(hash[:exception][:values][0][:stacktrace]).not_to be_nil + expect(hash[:exception][:values][1][:stacktrace]).to be_nil + end + end + + context 'when a cause has no backtrace' do + let(:exception) { build_exception_with_stackless_cause } + + it 'captures the type and message of the cause' do + expect(hash[:exception][:values][0][:type]).to eq("Errno::ENOENT") + expect(hash[:exception][:values][0][:module]).to eq("Errno") + expect(hash[:exception][:values][0][:value]).to match("exception a") + end + end + context 'when the exception has a recursive cause' do let(:exception) { build_exception_with_recursive_cause } diff --git a/sentry-ruby/spec/spec_helper.rb b/sentry-ruby/spec/spec_helper.rb index c1863c7e5..6b051edb7 100644 --- a/sentry-ruby/spec/spec_helper.rb +++ b/sentry-ruby/spec/spec_helper.rb @@ -172,6 +172,30 @@ def build_exception_with_two_causes e end +def build_exception_with_shared_backtrace_cause + inner = begin + raise ArgumentError, "exception a" + rescue ArgumentError => e + e + end + + begin + begin + raise TypeError, "exception b", inner.backtrace, cause: inner + rescue TypeError + raise "exception c" + end + rescue RuntimeError => e + e + end +end + +def build_exception_with_stackless_cause + raise "exception b", cause: Errno::ENOENT.new("exception a") +rescue RuntimeError => e + e +end + def build_exception_with_recursive_cause backtrace = [] From 9027b002f1f5147b62a04464a349ac40293dd657 Mon Sep 17 00:00:00 2001 From: Christophe Lucas Date: Wed, 18 Nov 2026 10:58:30 -0800 Subject: [PATCH 2/2] test: build the shared-backtrace fixture without the four-argument raise JRuby rejects raise with a class, a message, a backtrace and cause:, so the fixture failed before reaching the assertions. Set the backtrace on the exception, then raise it with its cause. --- sentry-ruby/spec/spec_helper.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sentry-ruby/spec/spec_helper.rb b/sentry-ruby/spec/spec_helper.rb index 6b051edb7..20e055928 100644 --- a/sentry-ruby/spec/spec_helper.rb +++ b/sentry-ruby/spec/spec_helper.rb @@ -181,7 +181,9 @@ def build_exception_with_shared_backtrace_cause begin begin - raise TypeError, "exception b", inner.backtrace, cause: inner + middle = TypeError.new("exception b") + middle.set_backtrace(inner.backtrace) + raise middle, cause: inner rescue TypeError raise "exception c" end