Skip to content

feat(trace): add advanced span filters - #728

Merged
Abhijeet Prasad (AbhiPrasad) merged 1 commit into
mainfrom
abhi-feat-add-advanced-span-filters
Sep 10, 2026
Merged

feat(trace): add advanced span filters#728
Abhijeet Prasad (AbhiPrasad) merged 1 commit into
mainfrom
abhi-feat-add-advanced-span-filters

Conversation

@AbhiPrasad

@AbhiPrasad Abhijeet Prasad (AbhiPrasad) commented Sep 1, 2026

Copy link
Copy Markdown
Member

Add filters to trace.get_spans() so callers can select spans by type, name, error state, partial metadata, and duration without fetching the whole trace and filtering it themselves.

spans = await trace.get_spans(
    filters={
        "span_type": ["tool"],
        "name": ["search", "lookup"],
        "has_error": True,
        "metadata": {"model": "gpt-5"},
        "duration": {"min": 0.5, "max": 10},
    }
)

Filter dimensions combine with AND, and each name or span-type list matches any of its values. Metadata supports nested partial matching. Duration bounds are inclusive and measured in seconds. The existing top-level span_type argument remains supported without deprecation.

Filtering applies consistently to buffered spans, complete trace caches, and BTQL queries. Returned metadata candidates are checked locally to handle backend type coercion differences. Partial filtered results are kept out of the complete trace cache, and client-side validation stays limited to supported keys and input shapes.

Resolves https://linear.app/braintrustdata/issue/SDK-317/add-filters-on-traceget-spans-to-python-sdk

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-10T14:27:31.602628Z 478d6b1 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d95d83cc5c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".

Comment thread py/src/braintrust/trace.py Outdated
Comment thread py/src/braintrust/trace.py Outdated
@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) force-pushed the abhi-feat-add-advanced-span-filters branch from d95d83c to 17dce78 Compare September 2, 2026 15:20

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 17dce788f8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".

Comment thread py/src/braintrust/trace.py Outdated
@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) force-pushed the abhi-feat-add-advanced-span-filters branch 2 times, most recently from 1ce3164 to 10b2a3e Compare September 2, 2026 18:03

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 10b2a3ea7d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".

Comment thread py/src/braintrust/trace.py Outdated
Comment thread py/src/braintrust/trace.py Outdated
@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) force-pushed the abhi-feat-add-advanced-span-filters branch from 10b2a3e to 46a12e1 Compare September 3, 2026 13:50

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 46a12e12c6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".

Comment thread py/src/braintrust/trace.py Outdated
Add `filters` to `Trace.get_spans()` so callers can select spans by type,
name, error state, partial metadata, and duration without fetching the
whole trace and filtering it themselves.

```python
spans = await trace.get_spans(
    filters={
        "span_type": ["tool"],
        "name": ["search", "lookup"],
        "has_error": True,
        "metadata": {"model": "gpt-5"},
        "duration": {"min": 0.5, "max": 10},
    }
)
```

Combine filter dimensions with AND and match any value within each name
or span-type list. Duration bounds are inclusive and measured in seconds.
Keep the existing top-level `span_type` argument supported.

Apply consistent filtering to buffered spans, complete trace caches, and
BTQL queries. Check returned metadata candidates locally to handle backend
type coercion differences, and avoid caching partial filtered results as
complete traces. Keep client-side validation limited to supported keys
and input shapes.
@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) force-pushed the abhi-feat-add-advanced-span-filters branch from d74177d to 478d6b1 Compare September 10, 2026 14:22
@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) merged commit 2bb4c05 into main Sep 10, 2026
163 of 165 checks passed
@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) deleted the abhi-feat-add-advanced-span-filters branch September 10, 2026 15:07
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.

3 participants