-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Document IsFromUnhandledException/IsFromTerminalException API (.NET) #18676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jamescrosswell
merged 5 commits into
master
from
jamescrosswell/document-unhandled-exception-api-5348
Jul 10, 2026
+46
−4
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d7b2fd6
Document IsFromUnhandledException/IsFromTerminalException API
jamescrosswell 6bf39ed
Tweaked wording
jamescrosswell 89f33ca
Add open statements to F# before-send example
jamescrosswell 7d406aa
docs(dotnet): Rename F# before-send parameter to sentryEvent
jamescrosswell df71fda
Merge branch 'master' into jamescrosswell/document-unhandled-exceptio…
jamescrosswell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,48 @@ The SDK supports the <PlatformIdentifier name="before-send" /> callback method. | |
|
|
||
| Note also that breadcrumbs can be filtered, as discussed in [our Breadcrumbs documentation](/product/issues/issue-details/breadcrumbs/). | ||
|
|
||
| #### Filtering by Unhandled or Terminal Exceptions | ||
|
|
||
| When filtering events in <PlatformIdentifier name="before-send" />, you may want to treat unhandled exceptions differently from handled ones. For example, you might drop noisy exceptions (like network timeouts) if these were handled, but capture them if they crashed your app. | ||
|
|
||
| The SDK provides two extension methods on `SentryEvent` to enable this: | ||
|
|
||
| - `IsFromUnhandledException()` returns `true` when the event came from an exception that wasn't caught by your application code, but was instead captured through an unhandled exception hook (such as `AppDomain.UnhandledException`, ASP.NET Core middleware, or another integration). | ||
| - `IsFromTerminalException()` returns `true` only when the unhandled exception caused the application to crash. Some integrations capture unhandled exceptions that don't terminate the process (for example, unobserved task exceptions) and mark them as non-terminal. | ||
|
|
||
| ```csharp | ||
| options.SetBeforeSend((sentryEvent, hint) => | ||
| { | ||
| // Always send unhandled exceptions, even if they'd be filtered below | ||
| if (sentryEvent.IsFromUnhandledException()) | ||
| { | ||
| return sentryEvent; | ||
| } | ||
|
|
||
| // Drop noisy handled exceptions | ||
| if (sentryEvent.Exception is HttpRequestException) | ||
| { | ||
| return null; // Don't send this event to Sentry | ||
| } | ||
|
|
||
| return sentryEvent; | ||
| }); | ||
| ``` | ||
|
|
||
| ```fsharp | ||
| open Sentry | ||
| open System.Net.Http | ||
|
Comment on lines
+54
to
+55
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TIL: F# has no implicit usings / opens |
||
|
|
||
| options.SetBeforeSend(fun sentryEvent hint -> | ||
|
jamescrosswell marked this conversation as resolved.
|
||
| if sentryEvent.IsFromUnhandledException() then | ||
| sentryEvent // Always send unhandled exceptions, even if filtered below | ||
| elif (sentryEvent.Exception :? HttpRequestException) then | ||
| null // Drop noisy handled exceptions | ||
| else | ||
| sentryEvent | ||
| ) | ||
| ``` | ||
|
|
||
|
sentry[bot] marked this conversation as resolved.
|
||
| ### Using <PlatformIdentifier name="add-exception-filter" /> and <PlatformIdentifier name="add-exception-filter-for-type" /> | ||
|
|
||
| The SDK also allows you to provide your own, custom exception filters. These have to inherit from <PlatformIdentifier name="IExceptionFilter" /> | ||
|
|
||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: The C# code example uses
HttpRequestExceptionbut is missing the requiredusing System.Net.Http;directive, which will cause compilation errors for some users copying the code.Severity: LOW
Suggested Fix
Add the
using System.Net.Http;directive at the top of the C# code block to ensure the example compiles correctly for all users, regardless of their project's implicit using settings.Prompt for AI Agent