getsentry / sentry-dotnet

Sentry SDK for .NET
https://docs.sentry.io/platforms/dotnet
MIT License
566 stars 203 forks source link

Filter out health check transactions #3317

Open TomRoelofsWhyellow opened 3 weeks ago

TomRoelofsWhyellow commented 3 weeks ago

Package

Sentry.AspNetCore

.NET Flavor

.NET

.NET Version

6.0.0

OS

Any (not platform specific)

SDK Version

4.4.0

Self-Hosted Sentry Version

No response

Steps to Reproduce

  1. Enable inbound filter for filtering out health check transactions
  2. Create a health check endpoint (e.g. /healthcheck/database)
  3. Assure that the health check is unhealthy
  4. Perform a health check call to the endpoint

Expected Result

According to the docs (https://docs.sentry.io/product/data-management-settings/filtering/#transactions-coming-from-health-check), the health check transaction should be filtered out.

Number of other things I've tried:

  1. Add SetBeforeSendTransaction and SetBeforeSend. Tried to filter on Transaction Name/Tags.

options.SetBeforeSendTransaction((sentryTransaction, _) => { return sentryTransaction.Name.Contains("healthcheck") ? null : sentryTransaction; });

  1. Add TracesSampler

options.TracesSampler = samplingContext => { return samplingContext.TransactionContext.Name.Contains("healthcheck") ? 0 : 1; };

When I check the logs, it says the events/transactions are dropped, but I'm still receiving them in Sentry. image

Actual Result

The health check is not filtered out.

bitsandfoxes commented 3 weeks ago

So it looks like our docs are ahead of our implementation! I don't find anything related to heathcheck in our SDK. We're going to put that on our To-Do.

TomRoelofsWhyellow commented 3 weeks ago

Are there any options to filter them out? This is depleting my performance units within a few days, because I have multiple health endpoints.

bitsandfoxes commented 3 weeks ago

You should definitely be able to filter those. The automatically created transaction's name should be in the format {method} {route} e.g. GET /pets/{id}. Can you confirm this? Returning null drops the event. The only way I see your filter not work would be if the SDK fails to extract the route from the route template.

TomRoelofsWhyellow commented 2 weeks ago

Yes, the format is indeed {method} {route}. I debugged the BeforeSend/BeforeSendTransaction/TracesSampler filters and the routes do get extracted correctly.

I've noticed that even after dropping a transaction, still some tracing information is sent to Sentry. Does this count towards my performance units limit?

bitsandfoxes commented 2 weeks ago

With the transaction dropped we update the client report. You can see that here: https://github.com/getsentry/sentry-dotnet/blob/7213a8cb8550381e88156119e98f69ff79b231da/src/Sentry/SentryClient.cs#L172-L178 This does not count towards your quota.

TomRoelofsWhyellow commented 2 weeks ago

Okay, I'll check if the filters are working once I have performance units again.