Skip to content

feat(frontend): filter trace tree to key spans#4404

Open
mmabrouk wants to merge 1 commit into
mainfrom
feat/trace-key-spans-filter
Open

feat(frontend): filter trace tree to key spans#4404
mmabrouk wants to merge 1 commit into
mainfrom
feat/trace-key-spans-filter

Conversation

@mmabrouk
Copy link
Copy Markdown
Member

@mmabrouk mmabrouk commented May 22, 2026

Summary

Trace trees from agent frameworks (LangChain, n8n, and similar) are full of structural wrapper spans (RunnableSequence, RunnableMap, RunnableLambda, ChatPromptTemplate) that bury the spans you actually care about. This adds a visibility filter to the trace drawer that collapses the tree down to its key spans, the same idea as LangSmith's "Most relevant" view.

Key spans is now the default. A span counts as key when it does real work (LLM, chat, agent, tool, or retrieval), when its name marks it as meaningful (output parsers), or when it ended in an error. The root span is always kept. Wrapper ancestors are removed and the key spans they contained are promoted up to the nearest kept ancestor, so a noisy root -> RunnableSequence -> ChatOpenAI collapses to root -> ChatOpenAI.

The settings popover (the existing cog in the tree toolbar) gains a "Visibility" section with "All spans" and "Key spans". When key spans hides something, a notice appears right after the tree: "N spans hidden by key spans" with a "Show all" shortcut.

How the filter is defined

The point of this design is that the definition of a key span will change over time, so the rules live in one place and are easy to edit. See TraceTree/assets/spanVisibility.ts:

  • KEY_SPAN_TYPES: the span categories treated as real work.
  • KEY_SPAN_NAME_PATTERNS: name patterns that rescue a meaningful span whose type is a generic wrapper (output parsers report as chain).
  • keySpanRules: an array of {id, description, test} predicates. A span is key if any rule matches. Add or remove a rule without touching the traversal.

filterKeySpans does the pruning and returns the new tree plus a hidden count. It never mutates the input.

Also in this PR

Two pre-existing layout bugs in the trace drawer are fixed. The splitter dividers (left tree pane and right side panel) stopped short of the bottom on tall screens because of hardcoded h-[calc(100%-48px)] and h-[87vh] heights and a Spin wrapper that did not fill its container. They now use flexbox height (flex-1 min-h-0).

Notes

  • The filter runs on already-ingested spans, so it works for any framework, not only LangChain.
  • TraceTreeSettings is shared with the session drawer tree. The visibility section is gated behind a showVisibility prop, so sessions are unaffected.
  • One connector-line edge case in the shared CustomTreeComponent remains (a kept span that is the last sibling and has kept children can show a short trailing line). It predates this PR and is out of scope. Happy to fix it separately.

Test plan

  • Open a trace from a LangChain or n8n agent. Confirm the tree shows the root plus the LLM and output-parser spans, with wrappers hidden and the hidden-count notice present.
  • Toggle "All spans" and confirm the full tree returns. Toggle back to "Key spans".
  • Click "Show all" in the notice and confirm it switches to all spans.
  • Confirm a trace with no key spans shows just the root plus the notice.
  • Operate the visibility options with the keyboard (Tab, then Enter or Space).
  • On a tall screen, confirm both splitter dividers reach the bottom of the drawer.
  • Open the session drawer tree and confirm its settings popover has no visibility section and behaves as before.
CleanShot.2026-05-22.at.18.19.02.mp4

@vercel
Copy link
Copy Markdown

vercel Bot commented May 22, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agenta-documentation Ready Ready Preview, Comment May 24, 2026 3:24pm

Request Review

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. Feature Request New feature or request Frontend labels May 22, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 22, 2026

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Span visibility filter: toggle between viewing all spans or only key spans; banner shows number hidden with a "Show all" action.
    • Visibility controls added to trace display settings.
  • Improvements

    • Trace drawer and content layout updated for more reliable responsive/full-height behavior during loading and normal use.
    • Settings UI refined for clearer display toggles and keyboard interaction.

Walkthrough

This PR implements key-span visibility filtering for trace trees. Users can toggle between viewing all spans or only "key" spans (defined by type, name pattern, or error status) via a new settings option. The feature adds filtering logic, updates the settings state type, refines the settings UI, integrates filtering into the tree display with a hidden-count banner, and adjusts wrapper component layouts.

Changes

Key Spans Visibility Filtering

Layer / File(s) Summary
Span Visibility Filtering Engine
web/oss/src/components/SharedDrawers/TraceDrawer/components/TraceTree/assets/spanVisibility.ts
Introduces SpanVisibilityMode type (all | key), UI options, and key-span criteria rules via types, regex patterns, and a rule-based evaluation system. Exports isKeySpan to test individual spans and filterKeySpans to recursively prune tree nodes while promoting surviving descendants, returning hidden count alongside the filtered tree.
Settings Type and State Contract
web/oss/src/components/SharedDrawers/TraceDrawer/components/TraceTreeSettings/types.ts
Defines unified TraceTreeSettingsState with latency, cost, tokens, and optional visibility field. Updates TraceTreeSettingsProps to reference this unified type instead of an inline object shape, aligning the prop contract with persisted state.
Settings UI with Visibility Option
web/oss/src/components/SharedDrawers/TraceDrawer/components/TraceTreeSettings/index.tsx
Refactors settings layout into a "Display" section with mapped toggles and adds a conditional "Visibility" section with radio-style selectable options, keyboard support, and a check indicator reflecting the current visibility mode.
TraceTree Display with Visibility Filtering
web/oss/src/components/SharedDrawers/TraceDrawer/components/TraceTree/index.tsx
Implements two-stage memoized filtering: first by text search to produce searchedTree, then by visibility mode to produce displayTree and hiddenCount. Passes showVisibility to settings, renders displayTree in the tree component, and displays a conditional banner with "Show all" button when spans are hidden.
Layout Refinements and State Alignment
web/oss/src/components/SharedDrawers/TraceDrawer/components/TraceContent/index.tsx, web/oss/src/components/SharedDrawers/TraceDrawer/components/TraceDrawerContent.tsx, web/oss/src/components/SharedDrawers/SessionDrawer/components/SessionTree/index.tsx
Updates TraceContent and TraceDrawerContent splitter height styling from fixed viewport values to flexible layout classes; types traceTreeSettings with TraceTreeSettingsState in SessionTree with comments documenting shared settings keys.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat(frontend): filter trace tree to key spans' clearly and concisely summarizes the main change: adding a visibility filter to collapse trace trees to key spans.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, explaining the feature, implementation approach, fixes to layout bugs, and the test plan.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/trace-key-spans-filter

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
web/oss/src/components/SharedDrawers/SessionDrawer/components/SessionTree/index.tsx (1)

15-15: ⚡ Quick win

Use @/oss/* alias for the shared settings type import.

Line 15 uses a deep relative import across modules; switch this to the alias path to keep imports stable and consistent.

Suggested change
-import {TraceTreeSettingsState} from "../../../TraceDrawer/components/TraceTreeSettings/types"
+import {TraceTreeSettingsState} from "`@/oss/components/SharedDrawers/TraceDrawer/components/TraceTreeSettings/types`"

As per coding guidelines, "Use @/oss/* path alias for shared utilities, helpers, types, hooks, and state that work the same in both EE and OSS" and "Never use relative paths for cross-package imports; use explicit path aliases instead".


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 733d8054-aa87-4867-9b61-82a659bd931c

📥 Commits

Reviewing files that changed from the base of the PR and between 3c9b1db and f452eff.

📒 Files selected for processing (7)
  • web/oss/src/components/SharedDrawers/SessionDrawer/components/SessionTree/index.tsx
  • web/oss/src/components/SharedDrawers/TraceDrawer/components/TraceContent/index.tsx
  • web/oss/src/components/SharedDrawers/TraceDrawer/components/TraceDrawerContent.tsx
  • web/oss/src/components/SharedDrawers/TraceDrawer/components/TraceTree/assets/spanVisibility.ts
  • web/oss/src/components/SharedDrawers/TraceDrawer/components/TraceTree/index.tsx
  • web/oss/src/components/SharedDrawers/TraceDrawer/components/TraceTreeSettings/index.tsx
  • web/oss/src/components/SharedDrawers/TraceDrawer/components/TraceTreeSettings/types.ts

@github-actions
Copy link
Copy Markdown
Contributor

Railway Preview Environment

Preview URL https://gateway-production-4e44.up.railway.app/w
Project agenta-oss-pr-4404
Image tag pr-4404-8b94edb
Status Deployed
Railway logs Open logs
Workflow logs View workflow run
Updated at 2026-05-22T16:31:18.875Z

@mmabrouk mmabrouk requested a review from ardaerzin May 24, 2026 12:58
Collapse the trace tree to the spans that carry signal (LLM, tool,
agent, retrieval, output parsers, and errors) and hide structural
wrappers such as RunnableSequence and RunnableLambda. Key spans is the
default view, with an "All spans" option in the tree settings popover
and a notice showing how many spans were hidden.

The filter rules live in spanVisibility.ts as editable span-type and
name-pattern definitions, so the definition of a key span can change
without touching the traversal logic.

Also fixes a pre-existing layout bug where the trace drawer splitter
dividers stopped short of the bottom on tall screens.
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
web/oss/src/components/SharedDrawers/TraceDrawer/components/TraceTree/index.tsx (1)

34-34: ⚡ Quick win

Type the settings parameter.

The settings parameter is typed as any. Use TraceTreeSettingsState for type safety (already imported on line 28).

🔧 Suggested fix
-export const TreeContent = ({value, settings}: {value: TraceSpanNode; settings: any}) => {
+export const TreeContent = ({value, settings}: {value: TraceSpanNode; settings: TraceTreeSettingsState}) => {

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d59f909c-0e68-431f-835d-704ed4bf5216

📥 Commits

Reviewing files that changed from the base of the PR and between f452eff and 414deb6.

📒 Files selected for processing (7)
  • web/oss/src/components/SharedDrawers/SessionDrawer/components/SessionTree/index.tsx
  • web/oss/src/components/SharedDrawers/TraceDrawer/components/TraceContent/index.tsx
  • web/oss/src/components/SharedDrawers/TraceDrawer/components/TraceDrawerContent.tsx
  • web/oss/src/components/SharedDrawers/TraceDrawer/components/TraceTree/assets/spanVisibility.ts
  • web/oss/src/components/SharedDrawers/TraceDrawer/components/TraceTree/index.tsx
  • web/oss/src/components/SharedDrawers/TraceDrawer/components/TraceTreeSettings/index.tsx
  • web/oss/src/components/SharedDrawers/TraceDrawer/components/TraceTreeSettings/types.ts

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

Labels

Feature Request New feature or request Frontend size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant