Skip to content

feat: Add IgnoreTransactions option to filter transactions by name#5377

Open
Adham-Kiwan wants to merge 2 commits into
getsentry:mainfrom
Adham-Kiwan:feat/ignore-transactions
Open

feat: Add IgnoreTransactions option to filter transactions by name#5377
Adham-Kiwan wants to merge 2 commits into
getsentry:mainfrom
Adham-Kiwan:feat/ignore-transactions

Conversation

@Adham-Kiwan

Copy link
Copy Markdown

Summary

Adds a first-class SentryOptions.IgnoreTransactions option: a list of substrings or regular expressions. A transaction whose name matches any entry is dropped before it is sent, mirroring ignoreTransactions in the JavaScript and Python SDKs.

Previously this required writing a BeforeSendTransaction callback (as noted by the maintainers in the issue). The new option gives parity with the other SDKs and the same shape as the existing TagFilters / TracePropagationTargets options.

Fixes #2306

(The ignoreErrors half of that issue is intentionally out of scope — it was marked "won't do" there, since exception filters already cover it.)

Implementation

  • SentryOptions.IgnoreTransactionsIList<StringOrRegex>, defaulting to empty (opt-in), matching the TagFilters pattern.
  • SentryClient.CaptureTransaction — drops a transaction whose Name matches, using the existing MatchesSubstringOrRegex helper, right after the required-field validation and before BeforeSendTransaction. Discards are recorded against the client report recorder (DiscardReason.BeforeSend), consistent with the equivalent BeforeSendTransaction drop path.
  • BindableSentryOptions — added the List<string>? surrogate + ApplyTo mapping for AOT-safe configuration binding, as required by the BindableProperties_MatchOptionsProperties guard.

One choice worth a maintainer's eye: I classified ignored transactions under DiscardReason.BeforeSend in client reports (since it's functionally the built-in equivalent of a BeforeSendTransaction drop). 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 ApiApprovalTests snapshots for the new public member (net8.0/net9.0/net10.0/net4.8).

Verified locally on net10.0: the three new tests, ApiApprovalTests, and BindableProperties_MatchOptionsProperties all pass (5/5). I also confirmed the tests fail if the filtering logic is removed.

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>
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Jul 10, 2026
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ignoreTransactions

1 participant