Skip to content
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

Allow filtering trace details with search #7600

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

adamint
Copy link
Member

@adamint adamint commented Feb 13, 2025

Description

Adds a search button to the filter detail page that filters out spans based on the following rule:

A span is visible if any of these are true:

  • at least one of its children is visible
  • its id contains the filter
  • its resource name contains the filter
  • its display summary contains the filter
  • its uninstrumented peer contains the filter

(no filter)
image

(filter)
image

Fixes #4439

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?

@adamint adamint requested review from Copilot, JamesNK and drewnoakes and removed request for Copilot February 13, 2025 19:11
[
viewModel.Span.SpanId,
GetResourceName(viewModel.Span.Source),
SpanWaterfallViewModel.GetDisplaySummary(viewModel.Span),
Copy link
Member

Choose a reason for hiding this comment

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

Update GetDisplaySummary on the VM to save the summary in a string so it isn't recreated when searched for and displayed on the page. e.g.

public static string GetDisplaySummary(OtlpSpan span)
{
    return _cachedDisplaySummary ??= BuildDisplaySummary(span);
}

...

@@ -169,6 +207,11 @@ private void UpdateDetailViewData()
return;
}

private async Task HandleAfterFilterBindAsync()
{
await InvokeAsync(_dataGrid.SafeRefreshDataAsync);
Copy link
Member

Choose a reason for hiding this comment

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

When you search on the resources and structured logs page, if there are open details then they're closed.

I can't remember exactly why we did that, but this page should also close details (if open) to be consistent.

@@ -93,6 +94,43 @@ private ValueTask<GridItemsProviderResult<SpanWaterfallViewModel>> GetData(GridI
Items = page.ToList(),
TotalItemCount = visibleSpanWaterfallViewModels.Count
});

// Return spans where any child span matches the filter.
List<SpanWaterfallViewModel> GetFilteredSpanWaterfalls(List<SpanWaterfallViewModel> viewModels)
Copy link
Member

Choose a reason for hiding this comment

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

Could you split this method out from the page, maybe put it on SpanWaterfallViewModel, and then write some unit tests for each scenario you mentioned on the page.

// Return spans where any child span matches the filter.
List<SpanWaterfallViewModel> GetFilteredSpanWaterfalls(List<SpanWaterfallViewModel> viewModels)
{
var viewModelsToFilterMatch = new Dictionary<SpanWaterfallViewModel, bool>();
Copy link
Member

Choose a reason for hiding this comment

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

Is this a perf optimization to avoid filtering a span multiple times when there are children? Could you add a comment.

}

matchesFilter = span.Children.Any(AnyChildMatchFilter) || Filter(_filter, span);
viewModelsToFilterMatch.Add(span, matchesFilter);
Copy link
Member

@JamesNK JamesNK Feb 14, 2025

Choose a reason for hiding this comment

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

Be defensive against a span show getting into the list multiple times to avoid a "key already exists" error.

Suggested change
viewModelsToFilterMatch.Add(span, matchesFilter);
viewModelsToFilterMatch.Add[span] = matchesFilter;

return matchesFilter;
}

bool Filter(string filter, SpanWaterfallViewModel viewModel)
Copy link
Member

Choose a reason for hiding this comment

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

Could this be static?

@davidfowl
Copy link
Member

IS this a 9.1 bug?

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.

Ability to filter/search for individual spans for a specific trace in dashboard
3 participants