Skip to content

feat(core): Add ignoreSpans option #17078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open

feat(core): Add ignoreSpans option #17078

wants to merge 4 commits into from

Conversation

mydea
Copy link
Member

@mydea mydea commented Jul 18, 2025

This adds a new ignoreSpans option to all SDKs. This can be used as follows:

Sentry.init({
  ignoreSpans: ['partial match', /regex/, { name: 'span name', op: 'http.client' }]
});

this will drop spans before they are sent. Eventual child spans in the same envelope will be re-parented, if possible.

Closes #16820

@mydea mydea self-assigned this Jul 18, 2025
Copy link
Contributor

github-actions bot commented Jul 18, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 23.97 kB +0.88% +209 B 🔺
@sentry/browser - with treeshaking flags 22.55 kB +0.9% +200 B 🔺
@sentry/browser (incl. Tracing) 39.65 kB +0.61% +238 B 🔺
@sentry/browser (incl. Tracing, Replay) 77.81 kB +0.36% +276 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 67.64 kB +0.37% +244 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 82.5 kB +0.32% +259 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 94.59 kB +0.25% +234 B 🔺
@sentry/browser (incl. Feedback) 40.65 kB +0.5% +200 B 🔺
@sentry/browser (incl. sendFeedback) 28.65 kB +0.73% +205 B 🔺
@sentry/browser (incl. FeedbackAsync) 33.55 kB +0.63% +209 B 🔺
@sentry/react 25.7 kB +0.79% +201 B 🔺
@sentry/react (incl. Tracing) 41.6 kB +0.52% +215 B 🔺
@sentry/vue 28.43 kB +0.85% +239 B 🔺
@sentry/vue (incl. Tracing) 41.46 kB +0.61% +251 B 🔺
@sentry/svelte 24 kB +0.88% +209 B 🔺
CDN Bundle 25.48 kB +0.8% +200 B 🔺
CDN Bundle (incl. Tracing) 39.54 kB +0.65% +255 B 🔺
CDN Bundle (incl. Tracing, Replay) 75.62 kB +0.3% +221 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 81.07 kB +0.29% +233 B 🔺
CDN Bundle - uncompressed 74.5 kB +0.87% +641 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 117.07 kB +0.67% +776 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 231.39 kB +0.35% +787 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 244.2 kB +0.33% +787 B 🔺
@sentry/nextjs (client) 43.67 kB +0.54% +231 B 🔺
@sentry/sveltekit (client) 40.1 kB +0.66% +260 B 🔺
@sentry/node-core 47.68 kB +0.42% +199 B 🔺
@sentry/node 146.02 kB +0.16% +229 B 🔺
@sentry/node - without tracing 91.77 kB +0.21% +189 B 🔺
@sentry/aws-serverless 103.22 kB +0.18% +184 B 🔺

View base workflow run

@mydea mydea requested review from bcoe, Lms24 and s1gr1d July 18, 2025 10:55
@mydea mydea marked this pull request as ready for review July 18, 2025 10:55
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Had some suggestions for types and performance

Copy link
Member

@bcoe bcoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, excited to see this 👏

Should we refactor similar functions like ignoreResourceSpans and ignorePerformanceApiSpans to just alias ignoreSpans?

@amccloud
Copy link

@mydea, perfect timing. I was about to try to use beforeSendSpan. Do you have a prerelease with this or plan to merge it soon?

@Lms24
Copy link
Member

Lms24 commented Jul 30, 2025

Hey @amccloud thx for expressing interest! I just made some optimizations to this PR. We'll merge this soon. Expect it to be released later this week or starting next week.

Update: sorry, but we actually need to wait for next week to merge this.

cursor[bot]

This comment was marked as outdated.

@Lms24
Copy link
Member

Lms24 commented Jul 30, 2025

Should we refactor similar functions like ignoreResourceSpans and ignorePerformanceApiSpans to just alias ignoreSpans?

@bcoe I think it's easier and more bundle-size efficient to keep the options separate for now. Worth noting though that users can set ignoreSpans in a way that will also apply to resource or performance API spans.

}

const nameMatches = pattern.name ? isMatchingPattern(span.description, pattern.name) : true;
const opMatches = pattern.op ? span.op && isMatchingPattern(span.op, pattern.op) : true;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Span Ignoring Fails for Empty Operations

The shouldIgnoreSpan function fails to correctly evaluate ignoreSpans patterns for spans with an empty op value. The condition span.op && isMatchingPattern(span.op, pattern.op) short-circuits when span.op is an empty string (""), as empty strings are falsy. This prevents isMatchingPattern from being called, causing spans with empty op values to not be ignored even when pattern.op is configured to match them (e.g., /^$/). The check should explicitly distinguish empty strings from undefined (e.g., span.op != null) to ensure proper pattern matching.

Locations (1)
Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ignoreSpans option
4 participants