Repository navigation
Description
Issue Description
When an exception chain contains a cause whose backtrace is shared with an exception already processed, or a cause with no backtrace, the event reports that cause with the outermost exception's type, module and message instead of its own.
This is common with Rails: ActiveRecord translates PG::UniqueViolation into ActiveRecord::RecordNotUnique and copies the original backtrace with set_backtrace. When that error is wrapped again (for example by a gRPC interceptor raising GRPC::Internal), Sentry shows:
GRPC::Internal → GRPC::Internal → PG::UniqueViolation
instead of
GRPC::Internal → ActiveRecord::RecordNotUnique → PG::UniqueViolation
The cause is in Sentry::ExceptionInterface.build (sentry-ruby/lib/sentry/interfaces/exception.rb). The else branch, taken when a backtrace was already processed or is nil, builds the entry from exception (the outermost error) instead of the current cause e:
exceptions = exceptions.map do |e|
if e.backtrace && !processed_backtrace_ids.include?(e.backtrace.object_id)
processed_backtrace_ids << e.backtrace.object_id
SingleExceptionInterface.build_with_stacktrace(exception: e, ...)
else
SingleExceptionInterface.new(exception: exception, mechanism: mechanism) # should be `e`
end
endThis looks like a regression from #1296 (Feb 2021, "Refactor event interface construction"). Before that refactor, Event#add_exception_interface set type, value and module from e for every entry, and only skipped the duplicate stacktrace (the dedupe that fixed #514).
Reproduction Steps
inner = begin
raise ArgumentError, "inner message"
rescue ArgumentError => e
e
end
middle = begin
raise TypeError, "middle message", inner.backtrace, cause: inner # shares inner's backtrace object
rescue TypeError => e
e
end
outer = begin
raise RuntimeError, "outer message", cause: middle
rescue RuntimeError => e
e
end
Sentry.capture_exception(outer)A stackless cause shows the same problem:
begin
raise RuntimeError, "outer message", cause: Errno::ENOENT.new("cause message")
rescue RuntimeError => e
Sentry.capture_exception(e)
endExpected Behavior
exception.values types are ["ArgumentError", "TypeError", "RuntimeError"]. The middle entry carries the middle cause's own message (its detailed_message, for example middle message (TypeError) on Ruby 4.0.6). Its stacktrace stays omitted, because it is the same as the inner one.
For the stackless cause: ["Errno::ENOENT", "RuntimeError"], with module Errno and the cause's own message (for example No such file or directory - cause message (Errno::ENOENT) on Ruby 4.0.6).
Actual Behavior
exception.values types are ["ArgumentError", "RuntimeError", "RuntimeError"]. The middle entry carries the outer exception's type, module and message (outer message (RuntimeError)).
For the stackless cause: ["RuntimeError", "RuntimeError"].
Ruby Version
Observed on Ruby 4.0.6. I have not run other Ruby versions. The faulty branch is visible in the source and runs whenever a cause's backtrace was already processed or is nil. The shared-backtrace reproduction above depends on the middle exception holding the same Array object as the inner one.
SDK Version
7.2.0; also present on master at 1636faa (7.3.0)
Integration and Its Version
sentry-rails 7.2.0, sentry-sidekiq 7.2.0 (not required to reproduce)
Sentry Config
Default configuration.
I have a fix with regression specs ready and will open a PR.
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsWaiting for: Product Owner
Activity
fix: report each cause's own type and message when its backtrace is s…
linear-code commentedon Nov 18, 2026
RUBY-250
fix: report each cause's own type and message when its backtrace is s…
sentry-junior commentedon Nov 18, 2026
Junior stopped: an open PR already fixes this issue, #3221. This says nothing about the bug.