Skip to content

Commit

Permalink
feat(.NET): Added Exception Filters (#10846)
Browse files Browse the repository at this point in the history
  • Loading branch information
bitsandfoxes authored Aug 4, 2024
1 parent bab73d3 commit 1013f16
Showing 1 changed file with 27 additions and 1 deletion.
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 allows you to evaluate whether to send an error or now. Alternatively, you can also control the behaviour by enabling, or disabling integrations.

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

0 comments on commit 1013f16

Please sign in to comment.