From 248888245cf77b5d12c697cce0de86985986cbbe Mon Sep 17 00:00:00 2001 From: Ernest Iliiasov Date: Wed, 1 May 2024 14:21:39 -0700 Subject: [PATCH] feat: Add option to search only logs or spans (#388) --- .changeset/rich-scissors-grin.md | 6 ++ .../api/src/clickhouse/searchQueryParser.ts | 2 + packages/app/src/SearchPage.tsx | 69 +++++++++++++++++++ packages/app/styles/SearchPage.module.scss | 41 +++++++++++ 4 files changed, 118 insertions(+) create mode 100644 .changeset/rich-scissors-grin.md create mode 100644 packages/app/styles/SearchPage.module.scss diff --git a/.changeset/rich-scissors-grin.md b/.changeset/rich-scissors-grin.md new file mode 100644 index 000000000..4e27c4458 --- /dev/null +++ b/.changeset/rich-scissors-grin.md @@ -0,0 +1,6 @@ +--- +'@hyperdx/api': minor +'@hyperdx/app': minor +--- + +Allow to filter search results by event type (log or span) diff --git a/packages/api/src/clickhouse/searchQueryParser.ts b/packages/api/src/clickhouse/searchQueryParser.ts index 5340d61e9..09d0a690b 100644 --- a/packages/api/src/clickhouse/searchQueryParser.ts +++ b/packages/api/src/clickhouse/searchQueryParser.ts @@ -42,6 +42,7 @@ const customColumnMap: { [level: string]: string } = { end_timestamp: 'end_timestamp', host: '_host', hyperdx_event_size: '_hyperdx_event_size', + hyperdx_event_type: 'type', hyperdx_platform: '_platform', level: 'severity_text', parent_span_id: 'parent_span_id', @@ -69,6 +70,7 @@ export const customColumnMapType: { host: 'string', hyperdx_event_size: 'number', hyperdx_platform: 'string', + hyperdx_event_type: 'string', level: 'string', parent_span_id: 'string', rum_session_id: 'string', diff --git a/packages/app/src/SearchPage.tsx b/packages/app/src/SearchPage.tsx index 1235d6f82..97a483c53 100644 --- a/packages/app/src/SearchPage.tsx +++ b/packages/app/src/SearchPage.tsx @@ -11,6 +11,7 @@ import dynamic from 'next/dynamic'; import Head from 'next/head'; import Link from 'next/link'; import { useRouter } from 'next/router'; +import cx from 'classnames'; import { clamp, format, sub } from 'date-fns'; import { formatInTimeZone } from 'date-fns-tz'; import { Button } from 'react-bootstrap'; @@ -49,6 +50,7 @@ import { useTimeQuery } from './timeQuery'; import { useDisplayedColumns } from './useDisplayedColumns'; import 'react-modern-drawer/dist/index.css'; +import styles from '../styles/SearchPage.module.scss'; const formatDate = ( date: Date, @@ -597,6 +599,42 @@ function SearchPage() { [setDisplayedSearchQuery], ); + const searchedTypes = useMemo(() => { + if (searchedQuery.includes('hyperdx_event_type:"span"')) { + return ['span']; + } else if (searchedQuery.includes('hyperdx_event_type:"log"')) { + return ['log']; + } + return ['log', 'span']; + }, [searchedQuery]); + + const handleToggleType = useCallback( + (type: 'log' | 'span') => { + let newQuery = displayedSearchQuery; + + if (displayedSearchQuery.includes(`hyperdx_event_type:"${type}"`)) { + return; // Do nothing if the query already contains the type + } + + newQuery = newQuery + .replaceAll('hyperdx_event_type:"log"', '') + .replaceAll('hyperdx_event_type:"span"', '') + .trim(); + + if (!displayedSearchQuery.includes('hyperdx_event_type:')) { + newQuery = + newQuery + + (newQuery.length ? ' ' : '') + + `hyperdx_event_type:"${type === 'log' ? 'span' : 'log'}"`; + } + + if (newQuery !== displayedSearchQuery) { + doSearch(newQuery, displayedTimeInputValue); + } + }, + [displayedSearchQuery, displayedTimeInputValue, doSearch], + ); + const chartsConfig = useMemo(() => { return { where: searchedQuery, @@ -750,6 +788,36 @@ function SearchPage() { />
+
+
handleToggleType('log')} + > + {searchedTypes.includes('log') ? ( + + ) : ( + + )} + Logs +
+
handleToggleType('span')} + > + {searchedTypes.includes('span') ? ( + + ) : ( + + )} + Spans +
+
+