Skip to content

feat: Provide the exception in the Hint passed to BeforeBreadcrumb - #5523

Draft
jamescrosswell wants to merge 1 commit into
mainfrom
breadcrumb-exception-hint
Draft

feat: Provide the exception in the Hint passed to BeforeBreadcrumb#5523
jamescrosswell wants to merge 1 commit into
mainfrom
breadcrumb-exception-hint

Conversation

@jamescrosswell

Copy link
Copy Markdown
Collaborator

Summary

When a breadcrumb is created from an exception, the exception itself is now provided in the SentryHint passed to the SetBeforeBreadcrumb callback, under a new HintTypes.Exception key.

This mirrors the Java SDK, which puts the originating logging event into the Hint it passes to beforeBreadcrumb (see TypeCheckHint, e.g. logback:loggingEvent). Until now .NET only ever passed an empty hint for these, so a BeforeBreadcrumb callback could only filter exception breadcrumbs by string-matching the message.

options.SetBeforeBreadcrumb((breadcrumb, hint) =>
    hint.Items.TryGetValue(HintTypes.Exception, out var exception) && exception is MyException
        ? null       // drop it
        : breadcrumb);

Covered sites:

  • Hub.AddBreadcrumbForException — the automatic Exception breadcrumb left on the scope for every captured exception event.
  • Sentry.Extensions.Logging, Sentry.Serilog, Sentry.NLog and Sentry.Log4Net — breadcrumbs those integrations create for log entries that carry an exception (i.e. below MinimumEventLevel, where they don't defer to the Hub's breadcrumb).

Notes for review

  • HubExtensions gains 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.
  • The Net4_8 API 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 IExceptionFilter just dropped. That needs a separate change to AddBreadcrumbForException so it respects SentryOptions.ExceptionFilters.

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

codecov Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.79%. Comparing base (fd638f0) to head (2f8d0ed).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant