feat: Provide the exception in the Hint passed to BeforeBreadcrumb - #5523
Draft
jamescrosswell wants to merge 1 commit into
Draft
feat: Provide the exception in the Hint passed to BeforeBreadcrumb#5523jamescrosswell wants to merge 1 commit into
jamescrosswell wants to merge 1 commit 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.75% 74.79% +0.04%
==========================================
Files 515 515
Lines 18884 18903 +19
Branches 3688 3690 +2
==========================================
+ Hits 14116 14139 +23
+ Misses 3884 3883 -1
+ Partials 884 881 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
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.