feat: Add IgnoreTransactions option to filter transactions by name#5377
Open
Adham-Kiwan wants to merge 2 commits into
Open
feat: Add IgnoreTransactions option to filter transactions by name#5377Adham-Kiwan wants to merge 2 commits into
Adham-Kiwan wants to merge 2 commits into
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>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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.)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.BeforeSend), consistent with the equivalentBeforeSendTransactiondrop path.BindableSentryOptions— added theList<string>?surrogate +ApplyTomapping for AOT-safe configuration binding, as required by theBindableProperties_MatchOptionsPropertiesguard.One choice worth a maintainer's eye: I classified ignored transactions under
DiscardReason.BeforeSendin client reports (since it's functionally the built-in equivalent of aBeforeSendTransactiondrop). Happy to change this if you'd prefer a different reason or no client report at all.Tests
Added to
SentryClientTests:CaptureTransaction_MatchesIgnoreTransactions_Dropped— substring match is dropped, and the discard is recorded for both the transaction and its spans.CaptureTransaction_MatchesIgnoreTransactionsRegex_Dropped— regex match is dropped.CaptureTransaction_DoesNotMatchIgnoreTransactions_Sent— a non-matching transaction is still sent.Updated the
ApiApprovalTestssnapshots for the new public member (net8.0/net9.0/net10.0/net4.8).Verified locally on net10.0: the three new tests,
ApiApprovalTests, andBindableProperties_MatchOptionsPropertiesall pass (5/5). I also confirmed the tests fail if the filtering logic is removed.