Skip to content

Commit

Permalink
feat: Add option to search only logs or spans (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestii authored May 1, 2024
1 parent ebd3f25 commit 2488882
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changeset/rich-scissors-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@hyperdx/api': minor
'@hyperdx/app': minor
---

Allow to filter search results by event type (log or span)
2 changes: 2 additions & 0 deletions packages/api/src/clickhouse/searchQueryParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
69 changes: 69 additions & 0 deletions packages/app/src/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -750,6 +788,36 @@ function SearchPage() {
/>
<div className="d-flex flex-column flex-grow-1 bg-hdx-dark h-100">
<div className="bg-body pb-3 pt-3 d-flex px-3 align-items-center">
<div className={styles.eventTypeSwitch}>
<div
className={cx(styles.eventTypeSwitchItem, {
[styles.eventTypeSwitchItemActive]:
searchedTypes.includes('log'),
})}
onClick={() => handleToggleType('log')}
>
{searchedTypes.includes('log') ? (
<i className="bi bi-check" />
) : (
<i />
)}
Logs
</div>
<div
className={cx(styles.eventTypeSwitchItem, {
[styles.eventTypeSwitchItemActive]:
searchedTypes.includes('span'),
})}
onClick={() => handleToggleType('span')}
>
{searchedTypes.includes('span') ? (
<i className="bi bi-check" />
) : (
<i />
)}
Spans
</div>
</div>
<form onSubmit={onSearchSubmit} className="d-flex flex-grow-1">
<SearchInput
inputRef={searchInput}
Expand Down Expand Up @@ -786,6 +854,7 @@ function SearchPage() {
}}
/>
</form>

<SearchPageActionBar
key={`${savedSearchId}`}
onClickConfigAlert={onClickConfigAlert}
Expand Down
41 changes: 41 additions & 0 deletions packages/app/styles/SearchPage.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
@import './variables';

.eventTypeSwitch {
border-radius: 4px;
border: 1px solid $slate-900;
height: 36px;
margin-right: 8px;
display: flex;
flex-direction: column;
}

.eventTypeSwitchItem {
border-bottom: 1px solid $slate-900;
font-size: 9px;
text-transform: uppercase;
letter-spacing: 0.8px;
flex: 1;
border-bottom: 1px solid $slate-700;
display: flex;
padding: 0 6px 0 4px;
align-items: center;
cursor: pointer;
color: $slate-300;
i {
width: 14px;
}
&:last-child {
border-bottom: none;
}
&:hover {
background-color: $slate-800;
}
&:active {
background-color: #000;
}
}

.eventTypeSwitchItemActive {
color: #fff;
background-color: $slate-950;
}

0 comments on commit 2488882

Please sign in to comment.