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.

Add attribute action in common col of span details drawer (#10017)

Aditya Singh6a6907682891
diff --git a/frontend/src/container/SpanDetailsDrawer/Attributes/AttributeActions.tsx b/frontend/src/container/SpanDetailsDrawer/Attributes/AttributeActions.tsx
index 1df6367189..a04e35a0ec 100644
--- a/frontend/src/container/SpanDetailsDrawer/Attributes/AttributeActions.tsx
+++ b/frontend/src/container/SpanDetailsDrawer/Attributes/AttributeActions.tsx
@@ -20,13 +20,17 @@ interface AttributeRecord {
interface AttributeActionsProps {
record: AttributeRecord;
isPinned?: boolean;
- onTogglePin: (fieldKey: string) => void;
+ onTogglePin?: (fieldKey: string) => void;
+ showPinned?: boolean;
+ showCopyOptions?: boolean;
}
export default function AttributeActions({
record,
isPinned,
onTogglePin,
+ showPinned = true,
+ showCopyOptions = true,
}: AttributeActionsProps): JSX.Element {
const [isOpen, setIsOpen] = useState<boolean>(false);
const [isFilterInLoading, setIsFilterInLoading] = useState<boolean>(false);
@@ -91,7 +95,7 @@ export default function AttributeActions({
}, [onCopyFieldValue, textToCopy]);
const handleTogglePin = useCallback((): void => {
- onTogglePin(record.field);
+ onTogglePin?.(record.field);
}, [onTogglePin, record.field]);
const moreActionsContent = (
@@ -105,35 +109,41 @@ export default function AttributeActions({
>
Group By Attribute
</Button>
- <Button
- type="text"
- icon={<Copy size={14} />}
- onClick={handleCopyFieldName}
- block
- >
- Copy Field Name
- </Button>
- <Button
- type="text"
- icon={<Copy size={14} />}
- onClick={handleCopyFieldValue}
- block
- >
- Copy Field Value
- </Button>
+ {showCopyOptions && (
+ <>
+ <Button
+ type="text"
+ icon={<Copy size={14} />}
+ onClick={handleCopyFieldName}
+ block
+ >
+ Copy Field Name
+ </Button>
+ <Button
+ type="text"
+ icon={<Copy size={14} />}
+ onClick={handleCopyFieldValue}
+ block
+ >
+ Copy Field Value
+ </Button>
+ </>
+ )}
</div>
);
return (
<div className={cx('action-btn', { 'action-btn--is-open': isOpen })}>
- <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>
+ {showPinned && (
+ <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"
@@ -184,4 +194,7 @@ export default function AttributeActions({
AttributeActions.defaultProps = {
isPinned: false,
+ showPinned: true,
+ showCopyOptions: true,
+ onTogglePin: undefined,
};
diff --git a/frontend/src/container/SpanDetailsDrawer/SpanDetailsDrawer.styles.scss b/frontend/src/container/SpanDetailsDrawer/SpanDetailsDrawer.styles.scss
index fd15757621..b772a54cef 100644
--- a/frontend/src/container/SpanDetailsDrawer/SpanDetailsDrawer.styles.scss
+++ b/frontend/src/container/SpanDetailsDrawer/SpanDetailsDrawer.styles.scss
@@ -47,15 +47,56 @@
.description {
display: flex;
flex-direction: column;
- gap: 16px;
- padding: 10px 12px;
+ padding: 10px 0px;
.item {
+ padding: 8px 12px;
&,
.attribute-container {
display: flex;
flex-direction: column;
gap: 8px;
+ position: relative; // ensure absolutely-positioned children anchor to the row
+ }
+
+ // Show attribute actions on hover for hardcoded rows
+ .attribute-actions-wrapper {
+ display: none;
+ gap: 8px;
+ position: absolute;
+ right: 8px;
+ top: 50%;
+ transform: translateY(-50%);
+ border-radius: 4px;
+ padding: 2px;
+
+ // style the action button group
+ .action-btn {
+ display: flex;
+ gap: 4px;
+ }
+ .filter-btn {
+ display: flex;
+ align-items: center;
+ border: none;
+ box-shadow: none;
+ border-radius: 2px;
+ background: var(--bg-slate-400);
+ padding: 4px;
+ gap: 3px;
+ height: 24px;
+ width: 24px;
+
+ &:hover {
+ background: var(--bg-slate-300);
+ }
+ }
+ }
+ &:hover {
+ background-color: var(--bg-slate-500);
+ .attribute-actions-wrapper {
+ display: flex;
+ }
}
.span-name-wrapper {
@@ -646,6 +687,29 @@
.description {
.item {
+ .attribute-actions-wrapper {
+ display: none;
+ gap: 8px;
+ position: absolute;
+ right: 8px;
+ top: 50%;
+ transform: translateY(-50%);
+ border-radius: 4px;
+ padding: 2px;
+
+ .filter-btn {
+ background: var(--bg-vanilla-200);
+ &:hover {
+ background: var(--bg-vanilla-100);
+ }
+ }
+ }
+ &:hover {
+ background-color: var(--bg-vanilla-300);
+ .attribute-actions-wrapper {
+ display: flex;
+ }
+ }
.span-name-wrapper {
.span-percentile-value-container {
&.span-percentile-value-container-open {
diff --git a/frontend/src/container/SpanDetailsDrawer/SpanDetailsDrawer.tsx b/frontend/src/container/SpanDetailsDrawer/SpanDetailsDrawer.tsx
index 01e0698fec..8036831aa3 100644
--- a/frontend/src/container/SpanDetailsDrawer/SpanDetailsDrawer.tsx
+++ b/frontend/src/container/SpanDetailsDrawer/SpanDetailsDrawer.tsx
@@ -21,6 +21,7 @@ import { DATE_TIME_FORMATS } from 'constants/dateTimeFormats';
import { REACT_QUERY_KEY } from 'constants/reactQueryKeys';
import { themeColors } from 'constants/theme';
import { USER_PREFERENCES } from 'constants/userPreferences';
+import AttributeActions from 'container/SpanDetailsDrawer/Attributes/AttributeActions';
import dayjs from 'dayjs';
import useClickOutside from 'hooks/useClickOutside';
import { generateColor } from 'lib/uPlotLib/utils/generateColor';
@@ -103,6 +104,10 @@ interface IResourceAttribute {
const DEFAULT_RESOURCE_ATTRIBUTES = {
serviceName: 'service.name',
name: 'name',
+ spanId: 'span_id',
+ spanKind: 'kind_string',
+ statusCodeString: 'status_code_string',
+ statusMessage: 'status_message',
};
// eslint-disable-next-line sonarjs/cognitive-complexity
@@ -835,6 +840,16 @@ function SpanDetailsDrawer(props: ISpanDetailsDrawerProps): JSX.Element {
{selectedSpan.spanId}
</Typography.Text>
</div>
+ <div className="attribute-actions-wrapper">
+ <AttributeActions
+ record={{
+ field: DEFAULT_RESOURCE_ATTRIBUTES.spanId,
+ value: selectedSpan.spanId,
+ }}
+ showPinned={false}
+ showCopyOptions={false}
+ />
+ </div>
</div>
<div className="item">
<Typography.Text className="attribute-key">start time</Typography.Text>
@@ -863,6 +878,16 @@ function SpanDetailsDrawer(props: ISpanDetailsDrawerProps): JSX.Element {
</Typography.Text>
</Tooltip>
</div>
+ <div className="attribute-actions-wrapper">
+ <AttributeActions
+ record={{
+ field: DEFAULT_RESOURCE_ATTRIBUTES.serviceName,
+ value: selectedSpan.serviceName,
+ }}
+ showPinned={false}
+ showCopyOptions={false}
+ />
+ </div>
</div>
</div>
<div className="item">
@@ -872,6 +897,16 @@ function SpanDetailsDrawer(props: ISpanDetailsDrawerProps): JSX.Element {
{selectedSpan.spanKind}
</Typography.Text>
</div>
+ <div className="attribute-actions-wrapper">
+ <AttributeActions
+ record={{
+ field: DEFAULT_RESOURCE_ATTRIBUTES.spanKind,
+ value: selectedSpan.spanKind,
+ }}
+ showPinned={false}
+ showCopyOptions={false}
+ />
+ </div>
</div>
<div className="item">
<Typography.Text className="attribute-key">
@@ -882,6 +917,16 @@ function SpanDetailsDrawer(props: ISpanDetailsDrawerProps): JSX.Element {
{selectedSpan.statusCodeString}
</Typography.Text>
</div>
+ <div className="attribute-actions-wrapper">
+ <AttributeActions
+ record={{
+ field: DEFAULT_RESOURCE_ATTRIBUTES.statusCodeString,
+ value: selectedSpan.statusCodeString,
+ }}
+ showPinned={false}
+ showCopyOptions={false}
+ />
+ </div>
</div>
{selectedSpan.statusMessage && (
@@ -891,6 +936,16 @@ function SpanDetailsDrawer(props: ISpanDetailsDrawerProps): JSX.Element {
attributeValue={selectedSpan.statusMessage}
onExpand={showStatusMessageModal}
/>
+ <div className="attribute-actions-wrapper">
+ <AttributeActions
+ record={{
+ field: DEFAULT_RESOURCE_ATTRIBUTES.statusMessage,
+ value: selectedSpan.statusMessage,
+ }}
+ showPinned={false}
+ showCopyOptions={false}
+ />
+ </div>
</div>
)}
<div className="item">
diff --git a/frontend/src/container/SpanDetailsDrawer/__tests__/AttributeActions.unit.test.tsx b/frontend/src/container/SpanDetailsDrawer/__tests__/AttributeActions.unit.test.tsx
new file mode 100644
index 0000000000..ecf8aa19a1
--- /dev/null
+++ b/frontend/src/container/SpanDetailsDrawer/__tests__/AttributeActions.unit.test.tsx
@@ -0,0 +1,247 @@
+/* eslint-disable sonarjs/no-duplicate-string */
+import {
+ fireEvent,
+ render,
+ screen,
+ userEvent,
+ waitFor,
+} from 'tests/test-utils';
+
+import AttributeActions from '../Attributes/AttributeActions';
+
+// Mock only Popover from antd to simplify hover/open behavior while keeping other components real
+jest.mock('antd', () => {
+ const actual = jest.requireActual('antd');
+ const MockPopover = ({
+ content,
+ children,
+ open,
+ onOpenChange,
+ ...rest
+ }: any): JSX.Element => (
+ <div
+ data-testid="mock-popover-wrapper"
+ onMouseEnter={(): void => onOpenChange?.(true)}
+ {...rest}
+ >
+ {children}
+ {open ? <div data-testid="mock-popover-content">{content}</div> : null}
+ </div>
+ );
+ return { ...actual, Popover: MockPopover };
+});
+
+// Mock getAggregateKeys API used inside useTraceActions to resolve autocomplete keys
+jest.mock('api/queryBuilder/getAttributeKeys', () => ({
+ getAggregateKeys: jest.fn().mockResolvedValue({
+ payload: {
+ attributeKeys: [
+ {
+ key: 'http.method',
+ dataType: 'string',
+ type: 'tag',
+ isColumn: true,
+ },
+ ],
+ },
+ }),
+}));
+
+const record = { field: 'http.method', value: 'GET' };
+
+describe('AttributeActions (unit)', () => {
+ beforeEach(() => {
+ jest.clearAllMocks();
+ });
+
+ it('renders core action buttons (pin, filter in/out, more)', async () => {
+ render(<AttributeActions record={record} isPinned={false} />);
+
+ expect(
+ screen.getByRole('button', { name: 'Pin attribute' }),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByRole('button', { name: 'Filter for value' }),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByRole('button', { name: 'Filter out value' }),
+ ).toBeInTheDocument();
+ // more actions (ellipsis) button
+ expect(
+ document.querySelector('.lucide-ellipsis')?.closest('button'),
+ ).toBeInTheDocument();
+ });
+
+ it('applies "Filter for" and calls redirectWithQueryBuilderData with correct query', async () => {
+ const redirectWithQueryBuilderData = jest.fn();
+ const currentQuery = {
+ builder: {
+ queryData: [
+ {
+ aggregateOperator: 'count',
+ aggregateAttribute: { key: 'signoz_span_duration' },
+ filters: { items: [], op: 'AND' },
+ filter: { expression: '' },
+ groupBy: [],
+ },
+ ],
+ },
+ } as any;
+
+ render(<AttributeActions record={record} />, undefined, {
+ queryBuilderOverrides: { currentQuery, redirectWithQueryBuilderData },
+ });
+
+ const filterForBtn = screen.getByRole('button', { name: 'Filter for value' });
+
+ await userEvent.click(filterForBtn);
+ await waitFor(() => {
+ expect(redirectWithQueryBuilderData).toHaveBeenCalledWith(
+ expect.objectContaining({
+ builder: expect.objectContaining({
+ queryData: expect.arrayContaining([
+ expect.objectContaining({
+ filters: expect.objectContaining({
+ items: expect.arrayContaining([
+ expect.objectContaining({
+ key: expect.objectContaining({ key: 'http.method' }),
+ op: '=',
+ value: 'GET',
+ }),
+ ]),
+ }),
+ }),
+ ]),
+ }),
+ }),
+ {},
+ expect.any(String),
+ );
+ });
+ });
+
+ it('applies "Filter out" and calls redirectWithQueryBuilderData with correct query', async () => {
+ const redirectWithQueryBuilderData = jest.fn();
+ const currentQuery = {
+ builder: {
+ queryData: [
+ {
+ aggregateOperator: 'count',
+ aggregateAttribute: { key: 'signoz_span_duration' },
+ filters: { items: [], op: 'AND' },
+ filter: { expression: '' },
+ groupBy: [],
+ },
+ ],
+ },
+ } as any;
+
+ render(<AttributeActions record={record} />, undefined, {
+ queryBuilderOverrides: { currentQuery, redirectWithQueryBuilderData },
+ });
+
+ const filterOutBtn = screen.getByRole('button', { name: 'Filter out value' });
+
+ await userEvent.click(filterOutBtn);
+ await waitFor(() => {
+ expect(redirectWithQueryBuilderData).toHaveBeenCalledWith(
+ expect.objectContaining({
+ builder: expect.objectContaining({
+ queryData: expect.arrayContaining([
+ expect.objectContaining({
+ filters: expect.objectContaining({
+ items: expect.arrayContaining([
+ expect.objectContaining({
+ key: expect.objectContaining({ key: 'http.method' }),
+ op: '!=',
+ value: 'GET',
+ }),
+ ]),
+ }),
+ }),
+ ]),
+ }),
+ }),
+ {},
+ expect.any(String),
+ );
+ });
+ });
+
+ it('opens more actions on hover and calls Group By handler; closes after click', async () => {
+ const redirectWithQueryBuilderData = jest.fn();
+ const currentQuery = {
+ builder: {
+ queryData: [
+ {
+ aggregateOperator: 'count',
+ aggregateAttribute: { key: 'signoz_span_duration' },
+ filters: { items: [], op: 'AND' },
+ filter: { expression: '' },
+ groupBy: [],
+ },
+ ],
+ },
+ } as any;
+ render(<AttributeActions record={record} />, undefined, {
+ queryBuilderOverrides: { currentQuery, redirectWithQueryBuilderData },
+ });
+
+ const ellipsisBtn = document
+ .querySelector('.lucide-ellipsis')
+ ?.closest('button') as HTMLElement;
+ expect(ellipsisBtn).toBeInTheDocument();
+
+ // hover to trigger Popover open via mock
+ fireEvent.mouseEnter(ellipsisBtn.parentElement as Element);
+
+ // content appears
+ await waitFor(() =>
+ expect(screen.getByText('Group By Attribute')).toBeInTheDocument(),
+ );
+
+ await userEvent.click(screen.getByText('Group By Attribute'));
+ await waitFor(() => {
+ expect(redirectWithQueryBuilderData).toHaveBeenCalledWith(
+ expect.objectContaining({
+ builder: expect.objectContaining({
+ queryData: expect.arrayContaining([
+ expect.objectContaining({
+ groupBy: expect.arrayContaining([
+ expect.objectContaining({ key: 'http.method' }),
+ ]),
+ }),
+ ]),
+ }),
+ }),
+ {},
+ expect.any(String),
+ );
+ });
+
+ // After clicking group by, popover should close
+ await waitFor(() =>
+ expect(screen.queryByTestId('mock-popover-content')).not.toBeInTheDocument(),
+ );
+ });
+
+ it('hides pin button when showPinned=false', async () => {
+ render(<AttributeActions record={record} showPinned={false} />);
+ expect(
+ screen.queryByRole('button', { name: /pin attribute/i }),
+ ).not.toBeInTheDocument();
+ });
+
+ it('hides copy options when showCopyOptions=false', async () => {
+ render(<AttributeActions record={record} showCopyOptions={false} />);
+ const ellipsisBtn = document
+ .querySelector('.lucide-ellipsis')
+ ?.closest('button') as HTMLElement;
+ fireEvent.mouseEnter(ellipsisBtn.parentElement as Element);
+
+ await waitFor(() =>
+ expect(screen.queryByText('Copy Field Name')).not.toBeInTheDocument(),
+ );
+ expect(screen.queryByText('Copy Field Value')).not.toBeInTheDocument();
+ });
+});