Skip to content

feat(trace-eap-waterfall): Sorting attributes. #91814

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

Merged
merged 1 commit into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import useOrganization from 'sentry/utils/useOrganization';
import {AttributesTree} from 'sentry/views/explore/components/traceItemAttributes/attributesTree';
import type {TraceRootEventQueryResults} from 'sentry/views/performance/newTraceDetails/traceApi/useTraceRootEvent';
import {isTraceItemDetailsResponse} from 'sentry/views/performance/newTraceDetails/traceApi/utils';
import {sortAttributes} from 'sentry/views/performance/newTraceDetails/traceDrawer/details/utils';
import {useHasTraceTabsUI} from 'sentry/views/performance/newTraceDetails/useHasTraceTabsUI';

type Props = {
Expand All @@ -35,7 +36,7 @@ export function TraceContextTags({rootEventResults}: Props) {
const eventDetails = rootEventResults.data!;
const rendered = isTraceItemDetailsResponse(eventDetails) ? (
<AttributesTree
attributes={eventDetails.attributes}
attributes={sortAttributes(eventDetails.attributes)}
rendererExtra={{
theme,
location,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ import {FoldSection} from 'sentry/views/issueDetails/streamline/foldSection';
import {InterimSection} from 'sentry/views/issueDetails/streamline/interimSection';
import {IssueList} from 'sentry/views/performance/newTraceDetails/traceDrawer/details/issues/issues';
import {TraceDrawerComponents} from 'sentry/views/performance/newTraceDetails/traceDrawer/details/styles';
import {getProfileMeta} from 'sentry/views/performance/newTraceDetails/traceDrawer/details/utils';
import {
getProfileMeta,
sortAttributes,
} from 'sentry/views/performance/newTraceDetails/traceDrawer/details/utils';
import type {TraceTreeNodeDetailsProps} from 'sentry/views/performance/newTraceDetails/traceDrawer/tabs/traceTreeNodeDetails';
import {isEAPSpanNode} from 'sentry/views/performance/newTraceDetails/traceGuards';
import type {TraceTree} from 'sentry/views/performance/newTraceDetails/traceModels/traceTree';
Expand Down Expand Up @@ -390,7 +393,7 @@ function EAPSpanNodeDetails({
>
<AttributesTree
columnCount={columnCount}
attributes={attributes}
attributes={sortAttributes(attributes)}
rendererExtra={{
theme,
location,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,20 @@ export function findSpanAttributeValue(
) {
return attributes.find(attribute => attribute.name === attributeName)?.value.toString();
}

// Sort attributes so that span.* attributes are at the beginning and
// the rest of the attributes are sorted alphabetically.
export function sortAttributes(attributes: TraceItemResponseAttribute[]) {
return [...attributes].sort((a, b) => {
const aIsSpan = a.name.startsWith('span.');
const bIsSpan = b.name.startsWith('span.');

if (aIsSpan && !bIsSpan) {
return -1;
}
if (!aIsSpan && bIsSpan) {
return 1;
}
return a.name.localeCompare(b.name);
Comment on lines +93 to +99
Copy link
Contributor

@DominikB2014 DominikB2014 May 16, 2025

Choose a reason for hiding this comment

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

Suggested change
if (aIsSpan && !bIsSpan) {
return -1;
}
if (!aIsSpan && bIsSpan) {
return 1;
}
return a.name.localeCompare(b.name);
return (bIsSpan - aIsSpan) || a.name.localeCompare(b.name);

I think this works, bit more concise, slightly harder to read

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah a lil bit harder to read imo 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Feel free to ignore, i like the readable one

});
}
Loading