Skip to content

ref: Add span filtering to span first (15)#5633

Open
sentrivana wants to merge 100 commits intomasterfrom
ivana/span-first-15-ignore-spans
Open

ref: Add span filtering to span first (15)#5633
sentrivana wants to merge 100 commits intomasterfrom
ivana/span-first-15-ignore-spans

Conversation

@sentrivana
Copy link
Contributor

@sentrivana sentrivana commented Mar 11, 2026

In span first, we're introducing a new span filtering init option called ignore_spans which allows to ignore spans at start time based on name and attributes.

  • Spans ignored this way emit a new ignored client report (set via NoOpStreamedSpan.unsampled_reason).
  • If a segment matches one of the rules in ignore_spans, the whole span tree will be ignored. The implementation achieves this by allowing NoOpStreamedSpans to be set on the scope in this one single case, so that their children can easily determine their segment was dropped.
  • If a segment is not ignored but one of its children spans (regardless of depth) is, ONLY that one span will be ignored, not its whole subtree.

Spec: https://develop.sentry.dev/sdk/telemetry/spans/filtering/#filter-with-ignorespans

@sentrivana sentrivana changed the title ref: Add span filtering to span first ref: Add span filtering to span first (15) Mar 11, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 11, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


This PR will not appear in the changelog.


🤖 This preview updates automatically when you update the PR.

1 similar comment
@github-actions
Copy link
Contributor

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


This PR will not appear in the changelog.


🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 11, 2026

Codecov Results 📊

13 passed | Total: 13 | Pass Rate: 100% | Execution Time: 7.30s

All tests are passing successfully.

❌ Patch coverage is 8.57%. Project has 14043 uncovered lines.

Files with missing lines (4)
File Patch % Lines
tracing_utils.py 39.48% ⚠️ 423 Missing and 28 partials
scope.py 68.55% ⚠️ 267 Missing and 66 partials
_types.py 66.67% ⚠️ 10 Missing
consts.py 99.43% ⚠️ 2 Missing

Generated by Codecov Action

@sentrivana sentrivana marked this pull request as ready for review March 11, 2026 10:34
@sentrivana sentrivana requested a review from a team as a code owner March 11, 2026 10:34
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

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.

Base automatically changed from ivana/span-first-14-custom-sampling-context to master March 11, 2026 12:18
Copy link
Contributor

@alexander-alderman-webb alexander-alderman-webb left a comment

Choose a reason for hiding this comment

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

looks good, see one non-blocking suggestion

Comment on lines +366 to +370
IgnoreSpansContext = TypedDict(
"IgnoreSpansContext",
{"name": IgnoreSpansName, "attributes": Attributes},
total=False,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can have a proper IgnoreSpansContext class?

I think creating a dedicated IgnoreSpansContext would give us more control in the future, as we can add new parameters with default arguments, etc ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you give me an example what that could look like? Would we require users to wrap their ignore_spans rules in the class, too?

Copy link
Contributor

@alexander-alderman-webb alexander-alderman-webb Mar 11, 2026

Choose a reason for hiding this comment

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

Yes, re-reading my comment that's super vague 😅 .
The idea would be to funnel everything through

class IgnoreSpansConfig:
	def __init__(self, rules: "list[IgnoreSpansContext]"):
		self.rules = rules + [
			IgnoreSpansContext(attributes = {"http.url": "https://api.openai.com/v1/traces"})
		]

class IgnoreSpansContext:
	def __init__(self, name: "IgnoreSpansName",  attributes: "Attributes"):
		self.name = name
		self.attributes = attributes

So the user would pass in

ignore_spans=IgnoreSpansConfig([IgnoreSpansContext(name="/health")])

There would still be dedicated options for common filtering cases like the trace_ignore_status_codes option. The class could let us cater for cases where we want to filter out some spans by default, but give the user an option to override it by controlling self.rules themselves?

Copy link
Contributor

Choose a reason for hiding this comment

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

Very rough idea. The motivation is that I found calls to https://api.openai.com/v1/traces clutter the trace view and it'd be nice to have the facility to globally disable them.

If there's another way to do this please let me know 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants