feat: Provide the exception in the Hint passed to BeforeBreadcrumb - #5523
Open
jamescrosswell wants to merge 4 commits into
Open
feat: Provide the exception in the Hint passed to BeforeBreadcrumb#5523jamescrosswell wants to merge 4 commits into
jamescrosswell wants to merge 4 commits into
Conversation
Breadcrumbs created from an exception now carry that exception in the SentryHint passed to the BeforeBreadcrumb callback, under the new HintTypes.Exception key. This mirrors the Java SDK, which puts the originating log event into the Hint it passes to beforeBreadcrumb. Covers the automatic "Exception" breadcrumb the Hub leaves for captured exception events, as well as the breadcrumbs created by the Microsoft.Extensions.Logging, Serilog, NLog and log4net integrations. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5523 +/- ##
==========================================
+ Coverage 74.67% 74.72% +0.04%
==========================================
Files 515 515
Lines 18909 18930 +21
Branches 3691 3692 +1
==========================================
+ Hits 14120 14145 +25
+ Misses 3904 3902 -2
+ Partials 885 883 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
jamescrosswell
commented
Aug 31, 2026
jamescrosswell
commented
Aug 31, 2026
Addresses review feedback: the `exception is null ? null : new SentryHint(...)` pattern repeated at each logging integration call site is now an internal `ToHint()` extension on SentryExceptionExtensions. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 1462662. Configure here.
Append already resolves the exception as `ExceptionObject ?? MessageObject as Exception`, but the breadcrumb path only looked at ExceptionObject, so `logger.Warn(ex)` produced a breadcrumb with no exception in its hint. Pass the resolved exception through instead. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Closes #5514
Summary
When a breadcrumb is created from an exception, the exception itself is now provided in the
SentryHintpassed to theSetBeforeBreadcrumbcallback, under a newHintTypes.Exceptionkey.This mirrors the Java SDK, which puts the originating logging event into the
Hintit passes tobeforeBreadcrumb(seeTypeCheckHint, e.g.logback:loggingEvent). Until now .NET only ever passed an empty hint for these, so aBeforeBreadcrumbcallback could only filter exception breadcrumbs by string-matching the message.Covered sites:
Hub.AddBreadcrumbForException— the automaticExceptionbreadcrumb left on the scope for every captured exception event.Sentry.Extensions.Logging,Sentry.Serilog,Sentry.NLogandSentry.Log4Net— breadcrumbs those integrations create for log entries that carry an exception (i.e. belowMinimumEventLevel, where they don't defer to the Hub's breadcrumb).Notes for review
HubExtensionsgains a hint-carrying overload of the[EditorBrowsable(Never)]AddBreadcrumb(clock, …)method that the logging integrations use. It's a new overload rather than an added optional parameter, to avoid a binary-breaking change and overload ambiguity at existing call sites.Net4_8API approval snapshot was hand-edited, since that TFM can't be built on macOS. The other three regenerated normally.Relates to #5514. It does not close that issue: this gives users a way to filter exception breadcrumbs by type, but the SDK still leaves a breadcrumb for an exception that its own
IExceptionFilterjust dropped. That needs a separate change toAddBreadcrumbForExceptionso it respectsSentryOptions.ExceptionFilters.