Skip to content
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

feat(.NET): Added Exception Filters #10846

Merged
merged 3 commits into from
Aug 4, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion docs/platforms/dotnet/common/configuration/filtering.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ We also offer [Inbound Filters](/concepts/data-management/filtering/) to filter

## Filtering Error Events

Configure your SDK to filter error events by using the <PlatformIdentifier name="before-send" /> callback method and configuring, enabling, or disabling integrations.
To prevent certain errors from being reported to Sentry, use the <PlatformIdentifier name="before-send" /> or <PlatformIdentifier name="add-exception-filter" /> configuration options, which allowes you to evaluate whether to send an error or now. Alternatively, you can also control the behaviour by enabling, or disabling integrations.
bitsandfoxes marked this conversation as resolved.
Show resolved Hide resolved

### Using <PlatformIdentifier name="before-send" />

Expand All @@ -22,6 +22,32 @@ All Sentry SDKs support the <PlatformIdentifier name="before-send" /> callback m

Note also that breadcrumbs can be filtered, as discussed in [our Breadcrumbs documentation](/product/error-monitoring/breadcrumbs/).

### 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" />

```csharp
public class MyExceptionFilter : IExceptionFilter
{
public bool Filter(Exception ex)
{
// TODO: Add your filtering logic
}
}
```

and can then be provided to the options during initialization.

```csharp
options.AddExceptionFilter(new MyExceptionFilter());
```

Exception types provided via <PlatformIdentifier name="add-exception-filter-for-type" /> automatically get filtered and prevented from being set to Sentry.

```csharp
options.AddExceptionFilterForType<MyCustomException>();
```

## Filtering Transaction Events

To prevent certain transactions from being reported to Sentry, use the <PlatformIdentifier name="traces-sampler" /> or <PlatformIdentifier name="before-send-transaction" /> configuration option, which allows you to provide a function to evaluate the current transaction and drop it if it's not one you want.
Expand Down
Loading