Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

feat: add pinning functionality for span attributes (#8769)

Shaheer Kochai3999a64c6445
diff --git a/frontend/src/constants/localStorage.ts b/frontend/src/constants/localStorage.ts
index 8e6a4ae937..123a3901c2 100644
--- a/frontend/src/constants/localStorage.ts
+++ b/frontend/src/constants/localStorage.ts
@@ -32,6 +32,7 @@ export enum LOCALSTORAGE {
BANNER_DISMISSED = 'BANNER_DISMISSED',
QUICK_FILTERS_SETTINGS_ANNOUNCEMENT = 'QUICK_FILTERS_SETTINGS_ANNOUNCEMENT',
FUNNEL_STEPS = 'FUNNEL_STEPS',
+ SPAN_DETAILS_PINNED_ATTRIBUTES = 'SPAN_DETAILS_PINNED_ATTRIBUTES',
LAST_USED_CUSTOM_TIME_RANGES = 'LAST_USED_CUSTOM_TIME_RANGES',
SHOW_FREQUENCY_CHART = 'SHOW_FREQUENCY_CHART',
}
diff --git a/frontend/src/constants/userPreferences.ts b/frontend/src/constants/userPreferences.ts
index 682acd085a..fdec6cc39e 100644
--- a/frontend/src/constants/userPreferences.ts
+++ b/frontend/src/constants/userPreferences.ts
@@ -2,4 +2,5 @@ export const USER_PREFERENCES = {
SIDENAV_PINNED: 'sidenav_pinned',
NAV_SHORTCUTS: 'nav_shortcuts',
LAST_SEEN_CHANGELOG_VERSION: 'last_seen_changelog_version',
+ SPAN_DETAILS_PINNED_ATTRIBUTES: 'span_details_pinned_attributes',
};
diff --git a/frontend/src/container/SpanDetailsDrawer/Attributes/AttributeActions.tsx b/frontend/src/container/SpanDetailsDrawer/Attributes/AttributeActions.tsx
index e173910696..f382bd8115 100644
--- a/frontend/src/container/SpanDetailsDrawer/Attributes/AttributeActions.tsx
+++ b/frontend/src/container/SpanDetailsDrawer/Attributes/AttributeActions.tsx
@@ -2,7 +2,13 @@ import { Button, Popover, Spin, Tooltip } from 'antd';
import GroupByIcon from 'assets/CustomIcons/GroupByIcon';
import { OPERATORS } from 'constants/antlrQueryConstants';
import { useTraceActions } from 'hooks/trace/useTraceActions';
-import { ArrowDownToDot, ArrowUpFromDot, Copy, Ellipsis } from 'lucide-react';
+import {
+ ArrowDownToDot,
+ ArrowUpFromDot,
+ Copy,
+ Ellipsis,
+ Pin,
+} from 'lucide-react';
import { useCallback, useMemo, useState } from 'react';
interface AttributeRecord {
@@ -12,10 +18,14 @@ interface AttributeRecord {
interface AttributeActionsProps {
record: AttributeRecord;
+ isPinned?: boolean;
+ onTogglePin: (fieldKey: string) => void;
}
export default function AttributeActions({
record,
+ isPinned,
+ onTogglePin,
}: AttributeActionsProps): JSX.Element {
const [isOpen, setIsOpen] = useState<boolean>(false);
const [isFilterInLoading, setIsFilterInLoading] = useState<boolean>(false);
@@ -79,6 +89,10 @@ export default function AttributeActions({
setIsOpen(false);
}, [onCopyFieldValue, textToCopy]);
+ const handleTogglePin = useCallback((): void => {
+ onTogglePin(record.field);
+ }, [onTogglePin, record.field]);
+
const moreActionsContent = (
<div className="attribute-actions-menu">
<Button
@@ -111,6 +125,14 @@ export default function AttributeActions({
return (
<div className="action-btn">
+ <Tooltip title={isPinned ? 'Unpin attribute' : 'Pin attribute'}>
+ <Button
+ className={`filter-btn periscope-btn ${isPinned ? 'pinned' : ''}`}
+ aria-label={isPinned ? 'Unpin attribute' : 'Pin attribute'}
+ icon={<Pin size={14} fill={isPinned ? 'currentColor' : 'none'} />}
+ onClick={handleTogglePin}
+ />
+ </Tooltip>
<Tooltip title="Filter for value">
<Button
className="filter-btn periscope-btn"
@@ -158,3 +180,7 @@ export default function AttributeActions({
</div>
);
}
+
+AttributeActions.defaultProps = {
+ isPinned: false,
+};
diff --git a/frontend/src/container/SpanDetailsDrawer/Attributes/Attributes.styles.scss b/frontend/src/container/SpanDetailsDrawer/Attributes/Attributes.styles.scss
index abd920e82b..059c6cabdc 100644
--- a/frontend/src/container/SpanDetailsDrawer/Attributes/Attributes.styles.scss
+++ b/frontend/src/container/SpanDetailsDrawer/Attributes/Attributes.styles.scss
@@ -32,6 +32,17 @@
}
}
+ .item-key-wrapper {
+ display: flex;
+ align-items: center;
+ gap: 6px;
+
+ .pin-icon {
+ color: var(--bg-robin-400);
+ flex-shrink: 0;
+ }
+ }
+
.item-key {
color: var(--bg-vanilla-100);
font-family: Inter;
diff --git a/frontend/src/container/SpanDetailsDrawer/Attributes/Attributes.tsx b/frontend/src/container/SpanDetailsDrawer/Attributes/Attributes.tsx
index 24475f69c7..9ff49bcac5 100644
--- a/frontend/src/container/SpanDetailsDrawer/Attributes/Attributes.tsx
+++ b/frontend/src/container/SpanDetailsDrawer/Attributes/Attributes.tsx
@@ -4,12 +4,19 @@ import { Input, Tooltip, Typography } from 'antd';
import cx from 'classnames';
import CopyClipboardHOC from 'components/Logs/CopyClipboardHOC';
import { flattenObject } from 'container/LogDetailedView/utils';
-import { useMemo, useState } from 'react';
+import { usePinnedAttributes } from 'hooks/spanDetails/usePinnedAttributes';
+import { Pin } from 'lucide-react';
+import { useCallback, useMemo, useState } from 'react';
import { Span } from 'types/api/trace/getTraceV2';
import NoData from '../NoData/NoData';
import AttributeActions from './AttributeActions';
+interface AttributeRecord {
+ field: string;
+ value: string;
+}
+
interface IAttributesProps {
span: Span;
isSearchVisible: boolean;
@@ -24,11 +31,38 @@ function Attributes(props: IAttributesProps): JSX.Element {
[span],
);
- const datasource = Object.keys(flattenSpanData)
- .filter((attribute) =>
- attribute.toLowerCase().includes(fieldSearchInput.toLowerCase()),
- )
- .map((key) => ({ field: key, value: flattenSpanData[key] }));
+ const availableAttributes = useMemo(() => Object.keys(flattenSpanData), [
+ flattenSpanData,
+ ]);
+
+ const { pinnedAttributes, togglePin } = usePinnedAttributes(
+ availableAttributes,
+ );
+
+ const sortPinnedAttributes = useCallback(
+ (data: AttributeRecord[]): AttributeRecord[] =>
+ data.sort((a, b) => {
+ const aIsPinned = pinnedAttributes[a.field];
+ const bIsPinned = pinnedAttributes[b.field];
+
+ if (aIsPinned && !bIsPinned) return -1;
+ if (!aIsPinned && bIsPinned) return 1;
+
+ // Within same pinning status, maintain alphabetical order
+ return a.field.localeCompare(b.field);
+ }),
+ [pinnedAttributes],
+ );
+
+ const datasource = useMemo(() => {
+ const filtered = Object.keys(flattenSpanData)
+ .filter((attribute) =>
+ attribute.toLowerCase().includes(fieldSearchInput.toLowerCase()),
+ )
+ .map((key) => ({ field: key, value: flattenSpanData[key] }));
+
+ return sortPinnedAttributes(filtered);
+ }, [flattenSpanData, fieldSearchInput, sortPinnedAttributes]);
return (
<div className="attributes-corner">
@@ -49,19 +83,31 @@ function Attributes(props: IAttributesProps): JSX.Element {
className={cx('attributes-container', isSearchVisible ? 'border-top' : '')}
>
{datasource.map((item) => (
- <div className="item" key={`${item.field} + ${item.value}`}>
- <Typography.Text className="item-key" ellipsis>
- {item.field}
- </Typography.Text>
+ <div
+ className={cx('item', { pinned: pinnedAttributes[item.field] })}
+ key={`${item.field} + ${item.value}`}
+ >
+ <div className="item-key-wrapper">
+ <Typography.Text className="item-key" ellipsis>
+ {item.field}
+ </Typography.Text>
+ {pinnedAttributes[item.field] && (
+ <Pin size={14} className="pin-icon" fill="currentColor" />
+ )}
+ </div>
<div className="value-wrapper">
<Tooltip title={item.value}>
<CopyClipboardHOC entityKey={item.value} textToCopy={item.value}>
<Typography.Text className="item-value" ellipsis>
{item.value}
- </Typography.Text>
+ </Typography.Text>{' '}
</CopyClipboardHOC>
</Tooltip>
- <AttributeActions record={item} />
+ <AttributeActions
+ record={item}
+ isPinned={pinnedAttributes[item.field]}
+ onTogglePin={togglePin}
+ />
</div>
</div>
))}
diff --git a/frontend/src/container/SpanDetailsDrawer/__tests__/AttributeActions.userflow.test.tsx b/frontend/src/container/SpanDetailsDrawer/__tests__/AttributeActions.userflow.test.tsx
index a6e7e9e8c1..8bdb9fef6b 100644
--- a/frontend/src/container/SpanDetailsDrawer/__tests__/AttributeActions.userflow.test.tsx
+++ b/frontend/src/container/SpanDetailsDrawer/__tests__/AttributeActions.userflow.test.tsx
@@ -2,6 +2,8 @@
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import ROUTES from 'constants/routes';
+import { AppProvider } from 'providers/App/App';
+import MockQueryClientProvider from 'providers/test/MockQueryClientProvider';
import { MemoryRouter, Route } from 'react-router-dom';
import { Span } from 'types/api/trace/getTraceV2';
@@ -109,23 +111,26 @@ const createMockSpan = (): Span => ({
subTreeNodeCount: 0,
level: 0,
});
-
const renderSpanDetailsDrawer = (span: Span = createMockSpan()): any => {
const user = userEvent.setup();
const component = render(
- <MemoryRouter>
- <Route>
- <SpanDetailsDrawer
- isSpanDetailsDocked={false}
- setIsSpanDetailsDocked={jest.fn()}
- selectedSpan={span}
- traceID={span.traceId}
- traceStartTime={span.timestamp}
- traceEndTime={span.timestamp + span.durationNano}
- />
- </Route>
- </MemoryRouter>,
+ <MockQueryClientProvider>
+ <AppProvider>
+ <MemoryRouter>
+ <Route>
+ <SpanDetailsDrawer
+ isSpanDetailsDocked={false}
+ setIsSpanDetailsDocked={jest.fn()}
+ selectedSpan={span}
+ traceID={span.traceId}
+ traceStartTime={span.timestamp}
+ traceEndTime={span.timestamp + span.durationNano}
+ />
+ </Route>
+ </MemoryRouter>{' '}
+ </AppProvider>
+ </MockQueryClientProvider>,
);
return { ...component, user };
diff --git a/frontend/src/hooks/spanDetails/usePinnedAttributes.ts b/frontend/src/hooks/spanDetails/usePinnedAttributes.ts
new file mode 100644
index 0000000000..c56d9d150d
--- /dev/null
+++ b/frontend/src/hooks/spanDetails/usePinnedAttributes.ts
@@ -0,0 +1,124 @@
+import setLocalStorageApi from 'api/browser/localstorage/set';
+import updateUserPreference from 'api/v1/user/preferences/name/update';
+import { AxiosError } from 'axios';
+import { LOCALSTORAGE } from 'constants/localStorage';
+import { USER_PREFERENCES } from 'constants/userPreferences';
+import { useNotifications } from 'hooks/useNotifications';
+import { useAppContext } from 'providers/App/App';
+import { useCallback, useEffect, useMemo, useState } from 'react';
+import { useMutation } from 'react-query';
+import { UserPreference } from 'types/api/preferences/preference';
+import { showErrorNotification } from 'utils/error';
+
+import { useLocalStorage } from '../useLocalStorage';
+
+interface UsePinnedAttributesReturn {
+ pinnedAttributes: Record<string, boolean>;
+ togglePin: (attributeKey: string) => void;
+ isPinned: (attributeKey: string) => boolean;
+}
+
+/**
+ * Hook for managing pinned span attributes with backend persistence.
+ * Falls back to localStorage during initial load and handles migration.
+ *
+ * @param availableAttributes - Object keys of the current span's flattened attributes
+ * @returns Object with pinned state, toggle function, and check function
+ */
+export function usePinnedAttributes(
+ availableAttributes: string[],
+): UsePinnedAttributesReturn {
+ const { userPreferences, updateUserPreferenceInContext } = useAppContext();
+ const { notifications } = useNotifications();
+ // API mutation for updating preferences
+ const { mutate: updateUserPreferenceMutation } = useMutation(
+ updateUserPreference,
+ {
+ onError: (error) => {
+ showErrorNotification(notifications, error as AxiosError);
+ },
+ },
+ );
+
+ // Local state for optimistic updates
+ const [pinnedKeys, setPinnedKeys] = useState<string[]>([]);
+
+ // Get localStorage fallback for initial load
+ const [localStoragePinnedKeys] = useLocalStorage<string[]>(
+ LOCALSTORAGE.SPAN_DETAILS_PINNED_ATTRIBUTES,
+ [],
+ );
+
+ // Initialize from user preferences when loaded
+ useEffect(() => {
+ if (userPreferences !== null) {
+ const preference = userPreferences.find(
+ (pref) => pref.name === USER_PREFERENCES.SPAN_DETAILS_PINNED_ATTRIBUTES,
+ );
+
+ if (preference?.value) {
+ // use backend data
+ setPinnedKeys(preference.value as string[]);
+ } else if (localStoragePinnedKeys.length > 0) {
+ // use local storage data
+ setPinnedKeys(localStoragePinnedKeys);
+ }
+ }
+ }, [userPreferences, localStoragePinnedKeys]);
+
+ // Create pinned attributes state from stored keys, filtering by available attributes
+ const pinnedAttributes = useMemo(
+ (): Record<string, boolean> =>
+ pinnedKeys.reduce((acc, key) => {
+ // Only include if the attribute exists in the current span
+ if (availableAttributes.includes(key)) {
+ acc[key] = true;
+ }
+ return acc;
+ }, {} as Record<string, boolean>),
+ [pinnedKeys, availableAttributes],
+ );
+
+ // Toggle pin state for an attribute
+ const togglePin = useCallback(
+ (attributeKey: string): void => {
+ const currentlyPinned = pinnedKeys.includes(attributeKey);
+ const newPinnedKeys = currentlyPinned
+ ? pinnedKeys.filter((key) => key !== attributeKey)
+ : [...pinnedKeys, attributeKey];
+
+ // Optimistically update local state for instant UI feedback
+ setPinnedKeys(newPinnedKeys);
+
+ updateUserPreferenceInContext({
+ name: USER_PREFERENCES.SPAN_DETAILS_PINNED_ATTRIBUTES,
+ value: newPinnedKeys,
+ } as UserPreference);
+
+ // Save to localStorage immediately for offline resilience
+ setLocalStorageApi(
+ LOCALSTORAGE.SPAN_DETAILS_PINNED_ATTRIBUTES,
+ JSON.stringify(newPinnedKeys),
+ );
+
+ // Make the API call in the background
+ updateUserPreferenceMutation({
+ name: USER_PREFERENCES.SPAN_DETAILS_PINNED_ATTRIBUTES,
+ value: newPinnedKeys,
+ });
+ },
+ [pinnedKeys, updateUserPreferenceInContext, updateUserPreferenceMutation],
+ );
+
+ // Check if an attribute is pinned
+ const isPinned = useCallback(
+ (attributeKey: string): boolean => pinnedAttributes[attributeKey] === true,
+ [pinnedAttributes],
+ );
+
+ return {
+ pinnedAttributes,
+ togglePin,
+ isPinned,
+ };
+}
diff --git a/pkg/types/preferencetypes/name.go b/pkg/types/preferencetypes/name.go
index 00e1852afe..2760ee40c8 100644
--- a/pkg/types/preferencetypes/name.go
+++ b/pkg/types/preferencetypes/name.go
@@ -19,6 +19,7 @@ var (
NameSidenavPinned = Name{valuer.NewString("sidenav_pinned")}
NameNavShortcuts = Name{valuer.NewString("nav_shortcuts")}
NameLastSeenChangelogVersion = Name{valuer.NewString("last_seen_changelog_version")}
+ NameSpanDetailsPinnedAttributes = Name{valuer.NewString("span_details_pinned_attributes")}
)
type Name struct{ valuer.String }
@@ -37,6 +38,7 @@ func NewName(name string) (Name, error) {
NameSidenavPinned.StringValue(),
NameNavShortcuts.StringValue(),
NameLastSeenChangelogVersion.StringValue(),
+ NameSpanDetailsPinnedAttributes.StringValue(),
},
name,
)
diff --git a/pkg/types/preferencetypes/preference.go b/pkg/types/preferencetypes/preference.go
index fafa5b6d8c..42d1f11d8c 100644
--- a/pkg/types/preferencetypes/preference.go
+++ b/pkg/types/preferencetypes/preference.go
@@ -154,6 +154,15 @@ func NewAvailablePreference() map[Name]Preference {
AllowedValues: []string{},
Value: MustNewValue("", ValueTypeString),
},
+ NameSpanDetailsPinnedAttributes: {
+ Name: NameSpanDetailsPinnedAttributes,
+ Description: "List of pinned attributes in span details drawer.",
+ ValueType: ValueTypeArray,
+ DefaultValue: MustNewValue([]any{}, ValueTypeArray),
+ AllowedScopes: []Scope{ScopeUser},
+ AllowedValues: []string{},
+ Value: MustNewValue([]any{}, ValueTypeArray),
+ },
}
}