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.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
fix: make trace details attributes search visible by default (#9247)
Shaheer Kochaidb5c102f14b4
diff --git a/frontend/src/container/SpanDetailsDrawer/Attributes/Attributes.tsx b/frontend/src/container/SpanDetailsDrawer/Attributes/Attributes.tsxindex e6a909d022..069f61e0b5 100644--- a/frontend/src/container/SpanDetailsDrawer/Attributes/Attributes.tsx+++ b/frontend/src/container/SpanDetailsDrawer/Attributes/Attributes.tsx@@ -20,10 +20,11 @@ interface AttributeRecord {interface IAttributesProps {span: Span;isSearchVisible: boolean;+ shouldFocusOnToggle?: boolean;}function Attributes(props: IAttributesProps): JSX.Element {- const { span, isSearchVisible } = props;+ const { span, isSearchVisible, shouldFocusOnToggle } = props;const [fieldSearchInput, setFieldSearchInput] = useState<string>('');const flattenSpanData: Record<string, string> = useMemo(@@ -69,7 +70,7 @@ function Attributes(props: IAttributesProps): JSX.Element {{isSearchVisible &&(datasource.length > 0 || fieldSearchInput.length > 0) && (<Input- autoFocus+ autoFocus={shouldFocusOnToggle}placeholder="Search for attribute..."className="search-input"value={fieldSearchInput}@@ -118,4 +119,8 @@ function Attributes(props: IAttributesProps): JSX.Element {);}+Attributes.defaultProps = {+ shouldFocusOnToggle: false,+};+export default Attributes;diff --git a/frontend/src/container/SpanDetailsDrawer/Events/Events.tsx b/frontend/src/container/SpanDetailsDrawer/Events/Events.tsxindex fa1b598a60..ed2bd9ae08 100644--- a/frontend/src/container/SpanDetailsDrawer/Events/Events.tsx+++ b/frontend/src/container/SpanDetailsDrawer/Events/Events.tsx@@ -41,7 +41,7 @@ function EventsTable(props: IEventsTableProps): JSX.Element {</div>)}<div className="events-container">- {isSearchVisible && (+ {isSearchVisible && events.length > 0 && (<InputautoFocusplaceholder="Search for events..."diff --git a/frontend/src/container/SpanDetailsDrawer/SpanDetailsDrawer.tsx b/frontend/src/container/SpanDetailsDrawer/SpanDetailsDrawer.tsxindex 3aa37d4ca6..182a98326c 100644--- a/frontend/src/container/SpanDetailsDrawer/SpanDetailsDrawer.tsx+++ b/frontend/src/container/SpanDetailsDrawer/SpanDetailsDrawer.tsx@@ -35,7 +35,10 @@ function SpanDetailsDrawer(props: ISpanDetailsDrawerProps): JSX.Element {traceEndTime,} = props;- const [isSearchVisible, setIsSearchVisible] = useState<boolean>(false);+ const [isSearchVisible, setIsSearchVisible] = useState<boolean>(true);+ const [shouldAutoFocusSearch, setShouldAutoFocusSearch] = useState<boolean>(+ false,+ );const [isRelatedSignalsOpen, setIsRelatedSignalsOpen] = useState<boolean>(false,);@@ -73,7 +76,13 @@ function SpanDetailsDrawer(props: ISpanDetailsDrawerProps): JSX.Element {</Button>),key: 'attributes',- children: <Attributes span={span} isSearchVisible={isSearchVisible} />,+ children: (+ <Attributes+ span={span}+ isSearchVisible={isSearchVisible}+ shouldFocusOnToggle={shouldAutoFocusSearch}+ />+ ),},{label: (@@ -246,7 +255,16 @@ function SpanDetailsDrawer(props: ISpanDetailsDrawerProps): JSX.Element {size={14}className="search-icon"cursor="pointer"- onClick={(): void => setIsSearchVisible((prev) => !prev)}+ onClick={(): void => {+ setIsSearchVisible((prev) => {+ const newValue = !prev;+ // Only set toggle flag when search becomes visible+ if (newValue) {+ setShouldAutoFocusSearch(true);+ }+ return newValue;+ });+ }}/>}/>diff --git a/frontend/src/container/SpanDetailsDrawer/__tests__/SpanDetailsDrawer.test.tsx b/frontend/src/container/SpanDetailsDrawer/__tests__/SpanDetailsDrawer.test.tsxindex be73fefcac..9ddcf82b8e 100644--- a/frontend/src/container/SpanDetailsDrawer/__tests__/SpanDetailsDrawer.test.tsx+++ b/frontend/src/container/SpanDetailsDrawer/__tests__/SpanDetailsDrawer.test.tsx@@ -3,7 +3,13 @@ import ROUTES from 'constants/routes';import { GetMetricQueryRange } from 'lib/dashboard/getQueryResults';import { server } from 'mocks-server/server';import { QueryBuilderContext } from 'providers/QueryBuilder';-import { fireEvent, render, screen, waitFor } from 'tests/test-utils';+import {+ fireEvent,+ render,+ screen,+ userEvent,+ waitFor,+} from 'tests/test-utils';import SpanDetailsDrawer from '../SpanDetailsDrawer';import {@@ -25,6 +31,12 @@ jest.mock('react-router-dom', () => ({}),}));+jest.mock('@signozhq/button', () => ({+ Button: ({ children }: { children: React.ReactNode }): JSX.Element => (+ <div>{children}</div>+ ),+}));+const mockSafeNavigate = jest.fn();jest.mock('hooks/useSafeNavigate', () => ({useSafeNavigate: (): any => ({@@ -156,6 +168,54 @@ jest.mock('providers/preferences/context/PreferenceContextProvider', () => ({),}));+// Mock QueryBuilder context value+const mockQueryBuilderContextValue = {+ currentQuery: {+ builder: {+ queryData: [+ {+ dataSource: 'logs',+ queryName: 'A',+ filter: { expression: "trace_id = 'test-trace-id'" },+ },+ ],+ },+ },+ stagedQuery: {+ builder: {+ queryData: [+ {+ dataSource: 'logs',+ queryName: 'A',+ filter: { expression: "trace_id = 'test-trace-id'" },+ },+ ],+ },+ },+ updateAllQueriesOperators: mockUpdateAllQueriesOperators,+ panelType: 'list',+ redirectWithQuery: jest.fn(),+ handleRunQuery: jest.fn(),+ handleStageQuery: jest.fn(),+ resetQuery: jest.fn(),+};++const renderSpanDetailsDrawer = (props = {}): void => {+ render(+ <QueryBuilderContext.Provider value={mockQueryBuilderContextValue as any}>+ <SpanDetailsDrawer+ isSpanDetailsDocked={false}+ setIsSpanDetailsDocked={jest.fn()}+ selectedSpan={mockSpan}+ traceStartTime={1640995200000} // 2022-01-01 00:00:00 in milliseconds+ traceEndTime={1640995260000} // 2022-01-01 00:01:00 in milliseconds+ // eslint-disable-next-line react/jsx-props-no-spreading+ {...props}+ />+ </QueryBuilderContext.Provider>,+ );+};+describe('SpanDetailsDrawer', () => {let apiCallHistory: any[] = [];@@ -197,54 +257,6 @@ describe('SpanDetailsDrawer', () => {server.resetHandlers();});- // Mock QueryBuilder context value- const mockQueryBuilderContextValue = {- currentQuery: {- builder: {- queryData: [- {- dataSource: 'logs',- queryName: 'A',- filter: { expression: "trace_id = 'test-trace-id'" },- },- ],- },- },- stagedQuery: {- builder: {- queryData: [- {- dataSource: 'logs',- queryName: 'A',- filter: { expression: "trace_id = 'test-trace-id'" },- },- ],- },- },- updateAllQueriesOperators: mockUpdateAllQueriesOperators,- panelType: 'list',- redirectWithQuery: jest.fn(),- handleRunQuery: jest.fn(),- handleStageQuery: jest.fn(),- resetQuery: jest.fn(),- };-- const renderSpanDetailsDrawer = (props = {}): void => {- render(- <QueryBuilderContext.Provider value={mockQueryBuilderContextValue as any}>- <SpanDetailsDrawer- isSpanDetailsDocked={false}- setIsSpanDetailsDocked={jest.fn()}- selectedSpan={mockSpan}- traceStartTime={1640995200000} // 2022-01-01 00:00:00 in milliseconds- traceEndTime={1640995260000} // 2022-01-01 00:01:00 in milliseconds- // eslint-disable-next-line react/jsx-props-no-spreading- {...props}- />- </QueryBuilderContext.Provider>,- );- };-it('should display logs tab in right sidebar when span is selected', async () => {renderSpanDetailsDrawer();@@ -507,3 +519,104 @@ describe('SpanDetailsDrawer', () => {expect(contextLogBefore).not.toHaveAttribute('title');});});++describe('SpanDetailsDrawer - Search Visibility User Flows', () => {+ const SEARCH_PLACEHOLDER = 'Search for attribute...';++ beforeEach(() => {+ jest.clearAllMocks();+ mockSafeNavigate.mockClear();+ mockWindowOpen.mockClear();+ mockUpdateAllQueriesOperators.mockClear();++ (GetMetricQueryRange as jest.Mock).mockImplementation(() =>+ Promise.resolve(mockEmptyLogsResponse),+ );+ });++ afterEach(() => {+ server.resetHandlers();+ });++ // Journey 1: Default Search Visibility++ it('should display search visible by default when user opens span details', () => {+ renderSpanDetailsDrawer();++ // User sees search input in the Attributes tab by default+ const searchInput = screen.getByPlaceholderText(SEARCH_PLACEHOLDER);+ expect(searchInput).toBeInTheDocument();+ expect(searchInput).toBeVisible();+ });++ it('should filter attributes when user types in search', async () => {+ const user = userEvent.setup({ pointerEventsCheck: 0 });++ renderSpanDetailsDrawer();++ // User sees all attributes initially+ expect(screen.getByText('http.method')).toBeInTheDocument();+ expect(screen.getByText('http.url')).toBeInTheDocument();+ expect(screen.getByText('http.status_code')).toBeInTheDocument();++ // User types "method" in search+ const searchInput = screen.getByPlaceholderText(SEARCH_PLACEHOLDER);+ await user.type(searchInput, 'method');++ // User sees only matching attributes+ await waitFor(() => {+ expect(screen.getByText('http.method')).toBeInTheDocument();+ expect(screen.queryByText('http.url')).not.toBeInTheDocument();+ expect(screen.queryByText('http.status_code')).not.toBeInTheDocument();+ });+ });++ // Journey 2: Search Toggle & Focus Management++ it('should hide search when user clicks search icon', () => {+ renderSpanDetailsDrawer();++ // User sees search initially+ expect(screen.getByPlaceholderText(SEARCH_PLACEHOLDER)).toBeInTheDocument();++ // User clicks search icon to hide search+ const tabBar = screen.getByRole('tablist');+ const searchIcon = tabBar.querySelector('.search-icon');+ if (searchIcon) {+ fireEvent.click(searchIcon);+ }++ // Search is now hidden+ expect(+ screen.queryByPlaceholderText(SEARCH_PLACEHOLDER),+ ).not.toBeInTheDocument();+ });++ it('should show and focus search when user clicks search icon again', () => {+ renderSpanDetailsDrawer();++ // User clicks search icon to hide+ const tabBar = screen.getByRole('tablist');+ const searchIcon = tabBar.querySelector('.search-icon');+ if (searchIcon) {+ fireEvent.click(searchIcon);+ }++ // Search is hidden+ expect(+ screen.queryByPlaceholderText(SEARCH_PLACEHOLDER),+ ).not.toBeInTheDocument();++ // User clicks search icon again to show+ if (searchIcon) {+ fireEvent.click(searchIcon);+ }++ // Search appears and receives focus+ const searchInput = screen.getByPlaceholderText(+ SEARCH_PLACEHOLDER,+ ) as HTMLInputElement;+ expect(searchInput).toBeInTheDocument();+ expect(searchInput).toHaveFocus();+ });+});