feat: Add IgnoreTransactions option to filter transactions by name - #5377
#5377feat: Add IgnoreTransactions option to filter transactions by name#5377jamescrosswell merged 6 commits intogetsentry:maingetsentry/sentry-dotnet:mainfrom Adham-Kiwan:feat/ignore-transactionsAdham-Kiwan/sentry-dotnet:feat/ignore-transactionsCopy head branch name to clipboard
Conversation
Adds a first-class `SentryOptions.IgnoreTransactions` option, a list of substrings or regular expressions. A transaction whose name matches any entry is dropped in `SentryClient.CaptureTransaction` before the BeforeSendTransaction callback, mirroring the `ignoreTransactions` option in the JavaScript and Python SDKs. Previously this could only be achieved by writing a BeforeSendTransaction callback. The new option follows the same shape and matching semantics as the existing `TagFilters`/`TracePropagationTargets` options (StringOrRegex + MatchesSubstringOrRegex), and is wired into BindableSentryOptions for AOT-safe configuration binding. Fixes getsentry#2306 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Expand the IgnoreTransactions doc comment to state that matching transactions are dropped before the BeforeSendTransaction callback runs (so that callback is not invoked for them), matching the JavaScript and Python SDKs. Add a test asserting BeforeSendTransaction is not invoked for an ignored transaction, to pin that ordering. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Yes — the ordering is intentional and matches the JavaScript and Python SDKs, where I've updated the |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit c2d7ae2. Configure here.
IgnoreTransactions is a built-in filter, so its client-report discards should be attributed to EventProcessor (as the exception filter path already does, and as the JS inbound filters do), rather than BeforeSend. BeforeSend is reserved for the user's BeforeSendTransaction callback, which does not run for an ignored transaction, so attributing the drop to it would mislead drop-rate debugging. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Good catch — fixed in 1499ffc.
|
Move the IgnoreTransactions filter to run after the IsSampled check, so a transaction that is sampled out (e.g. via trace propagation) is still attributed to sampling (SampleRate) in client reports even if its name also matches an ignore pattern, rather than being misattributed to the filter (EventProcessor). Sampling is the earlier, primary drop reason; IgnoreTransactions only applies to transactions that would otherwise be sent. Reuses the already-computed span count. Adds a regression test asserting a sampled-out, ignore-matching transaction is recorded under SampleRate. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Confirmed and fixed in 1a525c7 — this was a real (telemetry-only) issue. The Added |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5377 +/- ##
=======================================
Coverage 74.25% 74.25%
=======================================
Files 509 509
Lines 18412 18420 +8
Branches 3604 3606 +2
=======================================
+ Hits 13671 13677 +6
- Misses 3868 3869 +1
- Partials 873 874 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| { | ||
| _options.ClientReportRecorder.RecordDiscardedEvent(DiscardReason.EventProcessor, DataCategory.Transaction); | ||
| _options.ClientReportRecorder.RecordDiscardedEvent(DiscardReason.EventProcessor, DataCategory.Span, spanCount); | ||
| _options.LogInfo("Transaction dropped by IgnoreTransactions option."); |
There was a problem hiding this comment.
Arguably this could be LogDebug but we can tweak that in a follow up if anyone is really unhappy with it.
jamescrosswell
left a comment
There was a problem hiding this comment.
Awesome - thanks for the PR @Adham-Kiwan ! Very much appreciated 🙏🏻
Summary
Adds a first-class
SentryOptions.IgnoreTransactionsoption: a list of substrings or regular expressions. A transaction whose name matches any entry is dropped before it is sent, mirroringignoreTransactionsin the JavaScript and Python SDKs.Previously this required writing a
BeforeSendTransactioncallback (as noted by the maintainers in the issue). The new option gives parity with the other SDKs and the same shape as the existingTagFilters/TracePropagationTargetsoptions.Fixes #2306
(The
ignoreErrorshalf of that issue is intentionally out of scope — it was marked "won't do" there, since exception filters already cover it.)Changelog Entry
Add
IgnoreTransactionsoption to filter out transactions by name, matching substrings or regular expressions against the transaction name (#5377)Implementation
SentryOptions.IgnoreTransactions—IList<StringOrRegex>, defaulting to empty (opt-in), matching theTagFilterspattern.SentryClient.CaptureTransaction— drops a transaction whoseNamematches, using the existingMatchesSubstringOrRegexhelper, right after the required-field validation and beforeBeforeSendTransaction. Discards are recorded against the client report recorder (DiscardReason.EventProcessor)BindableSentryOptions— added theList<string>?surrogate +ApplyTomapping for AOT-safe configuration binding, as required by theBindableProperties_MatchOptionsPropertiesguard.