Skip to content

feat(eap): Sort trace item attributes by frequency#7833

Draft
volokluev wants to merge 1 commit intomasterfrom
feat/sort-attributes-by-frequency
Draft

feat(eap): Sort trace item attributes by frequency#7833
volokluev wants to merge 1 commit intomasterfrom
feat/sort-attributes-by-frequency

Conversation

@volokluev
Copy link
Member

Return attribute keys sorted by frequency (count) in descending order, with alphabetical ordering as a tiebreaker for attributes with the same frequency.

This change makes it easier for users to discover the most commonly used attributes in their traces by surfacing them first in the results.

Motivation

Previously, attributes were returned in alphabetical order only, which meant frequently-used, important attributes could be buried among less relevant ones. By sorting by frequency first, users can quickly identify which attributes are most prevalent in their data.

Changes

  • Modified the ClickHouse query to group by attribute key and count occurrences
  • Updated ORDER BY clause to sort by count DESC, then attr_key ASC as a tiebreaker
  • Updated result processing to handle the additional count column
  • Added two new tests to verify frequency-based sorting behavior:
    • test_sorted_by_frequency: Verifies alphabetical sorting when attributes have equal frequency
    • test_frequency_ordering_with_specific_attributes: Validates sorting with filtered results

Technical Details

The query now uses count() with GROUP BY attr_key instead of distinct(), which allows us to order by frequency. Non-stored attributes (like sentry.service) are assigned a very high count to ensure they appear first.

Refs EAP-432

🤖 Generated with Claude Code

Return attribute keys sorted by frequency (count) in descending order,
with alphabetical ordering as a tiebreaker. This makes it easier for
users to discover the most commonly used attributes in their traces.

Previously, attributes were returned in alphabetical order only, which
buried frequently-used attributes among less important ones.

Changes:
- Modified query to group by attribute key and count occurrences
- Updated ORDER BY to sort by count DESC, then attr_key ASC
- Added tests to verify frequency-based sorting behavior

Refs EAP-432
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@linear-code
Copy link

linear-code bot commented Mar 23, 2026

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.

1 participant