Skip to content

fix: report each cause's own type and message when its backtrace is shared or missing - #3221

Open
clucas wants to merge 2 commits into
getsentry:masterfrom
clucas:fix/cause-identity-shared-backtrace
Open

clucas wants to merge 2 commits into
getsentry:masterfrom
clucas:fix/cause-identity-shared-backtrace

Conversation

@clucas

@clucas clucas commented Nov 18, 2026 •

Copy link
Copy Markdown

Description

ExceptionInterface.build skips the stacktrace of a cause whose backtrace object was already processed, or that has no backtrace. That dedupe is correct (it was the fix for #514). But the else branch built the entry from exception, the outermost error, instead of the current cause e. So the event showed the outer exception's type, module and message in place of that cause.

A common real-world chain is a PG::UniqueViolation that ActiveRecord translates into ActiveRecord::RecordNotUnique (with set_backtrace(original.backtrace)), wrapped again by a gRPC interceptor. Sentry shows:

GRPC::Internal → GRPC::Internal → PG::UniqueViolation

instead of

GRPC::Internal → ActiveRecord::RecordNotUnique → PG::UniqueViolation

This is a regression from #1296. Before that refactor, every entry took type, value and module from e, and only the duplicate stacktrace was omitted.

The fix builds the entry from e. The shared stacktrace is still sent only once, and the entry keeps the same mechanism.

Tests

Two cases in spec/sentry/client_spec.rb, with their exceptions built by new helpers in spec/spec_helper.rb next to build_exception_with_two_causes:

  • A three-level chain where the middle cause shares the inner cause's backtrace object. The types are ArgumentError, TypeError, RuntimeError, the middle value contains its own message (not the outer one), and only the middle stacktrace is omitted.
  • A cause with no backtrace. The entry has the cause's type, module and message, and no stacktrace.

Both fail on master (["ArgumentError", "RuntimeError", "RuntimeError"] and ["RuntimeError", "RuntimeError"]) and pass with the fix. The two-level shared-backtrace case did not show the bug, because the deduplicated entry there is the outer exception itself.

🤖 Generated with Claude Code

@clucas
clucas requested review from a team and solnic as code owners November 18, 2026 15:45
clucas added a commit to clucas/sentry-ruby that referenced this pull request Nov 18, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@clucas
clucas force-pushed the fix/cause-identity-shared-backtrace branch from d2a2bf4 to 5d3efc8 Compare November 18, 2026 15:48
@dingsdax dingsdax added the Junior: repro Junior reproduces this bug and drafts a fix label Nov 18, 2026
…hared 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 getsentry#3220

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@clucas
clucas force-pushed the fix/cause-identity-shared-backtrace branch from 5d3efc8 to 13087e0 Compare November 18, 2026 16:21
@dingsdax dingsdax added Junior: repro Junior reproduces this bug and drafts a fix and removed Junior: repro Junior reproduces this bug and drafts a fix labels Nov 18, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chained exception reports the outer exception's type and message for a cause with a shared or missing backtrace

2 participants