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: Traces explorer cleanup (#9506)

Aditya Singh4837ddb60111
diff --git a/frontend/src/components/Graph/utils.ts b/frontend/src/components/Graph/utils.ts
index b21f205b72..3910db5ac5 100644
--- a/frontend/src/components/Graph/utils.ts
+++ b/frontend/src/components/Graph/utils.ts
@@ -149,6 +149,7 @@ export const getGraphOptions = (
scales: {
x: {
stacked: isStacked,
+ offset: false,
grid: {
display: true,
color: getGridColor(),
diff --git a/frontend/src/components/QueryBuilderV2/QueryBuilderV2.styles.scss b/frontend/src/components/QueryBuilderV2/QueryBuilderV2.styles.scss
index 078030738d..e4d47bd86c 100644
--- a/frontend/src/components/QueryBuilderV2/QueryBuilderV2.styles.scss
+++ b/frontend/src/components/QueryBuilderV2/QueryBuilderV2.styles.scss
@@ -300,6 +300,10 @@
}
}
.qb-trace-operator-button-container {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+
&-text {
display: flex;
align-items: center;
diff --git a/frontend/src/components/QueryBuilderV2/QueryV2/QueryFooter/QueryFooter.tsx b/frontend/src/components/QueryBuilderV2/QueryV2/QueryFooter/QueryFooter.tsx
index 31c8f4720c..3f50471623 100644
--- a/frontend/src/components/QueryBuilderV2/QueryV2/QueryFooter/QueryFooter.tsx
+++ b/frontend/src/components/QueryBuilderV2/QueryV2/QueryFooter/QueryFooter.tsx
@@ -2,8 +2,74 @@ import './QueryFooter.styles.scss';
/* eslint-disable react/require-default-props */
import { Button, Tooltip, Typography } from 'antd';
+import WarningPopover from 'components/WarningPopover/WarningPopover';
+import { PANEL_TYPES } from 'constants/queryBuilder';
+import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
import { DraftingCompass, Plus, Sigma } from 'lucide-react';
import BetaTag from 'periscope/components/BetaTag/BetaTag';
+import { useMemo } from 'react';
+
+function TraceOperatorSection({
+ addTraceOperator,
+}: {
+ addTraceOperator?: () => void;
+}): JSX.Element {
+ const { currentQuery, panelType } = useQueryBuilder();
+
+ const showTraceOperatorWarning = useMemo(() => {
+ const isListViewPanel =
+ panelType === PANEL_TYPES.LIST || panelType === PANEL_TYPES.TRACE;
+ const hasMultipleQueries = currentQuery.builder.queryData.length > 1;
+ const hasTraceOperator =
+ currentQuery.builder.queryTraceOperator &&
+ currentQuery.builder.queryTraceOperator.length > 0;
+ return isListViewPanel && hasMultipleQueries && !hasTraceOperator;
+ }, [
+ currentQuery?.builder?.queryData,
+ currentQuery?.builder?.queryTraceOperator,
+ panelType,
+ ]);
+
+ const traceOperatorWarning = useMemo(() => {
+ if (currentQuery.builder.queryData.length === 0) return '';
+ const firstQuery = currentQuery.builder.queryData[0];
+ return `Currently, you are only seeing results from query ${firstQuery.queryName}. Add a trace operator to combine results of multiple queries.`;
+ }, [currentQuery]);
+ return (
+ <div className="qb-trace-operator-button-container">
+ <Tooltip
+ title={
+ <div style={{ textAlign: 'center' }}>
+ Add Trace Matching
+ <Typography.Link
+ href="https://signoz.io/docs/userguide/query-builder-v5/#multi-query-analysis-trace-operators"
+ target="_blank"
+ style={{ textDecoration: 'underline' }}
+ >
+ {' '}
+ <br />
+ Learn more
+ </Typography.Link>
+ </div>
+ }
+ >
+ <Button
+ className="add-trace-operator-button periscope-btn"
+ icon={<DraftingCompass size={16} />}
+ onClick={(): void => addTraceOperator?.()}
+ >
+ <div className="qb-trace-operator-button-container-text">
+ Add Trace Matching
+ <BetaTag />
+ </div>
+ </Button>
+ </Tooltip>
+ {showTraceOperatorWarning && (
+ <WarningPopover message={traceOperatorWarning} />
+ )}
+ </div>
+ );
+}
export default function QueryFooter({
addNewBuilderQuery,
@@ -60,35 +126,7 @@ export default function QueryFooter({
</div>
)}
{showAddTraceOperator && (
- <div className="qb-trace-operator-button-container">
- <Tooltip
- title={
- <div style={{ textAlign: 'center' }}>
- Add Trace Matching
- <Typography.Link
- href="https://signoz.io/docs/userguide/query-builder-v5/#multi-query-analysis-trace-operators"
- target="_blank"
- style={{ textDecoration: 'underline' }}
- >
- {' '}
- <br />
- Learn more
- </Typography.Link>
- </div>
- }
- >
- <Button
- className="add-trace-operator-button periscope-btn "
- icon={<DraftingCompass size={16} />}
- onClick={(): void => addTraceOperator?.()}
- >
- <div className="qb-trace-operator-button-container-text">
- Add Trace Matching
- <BetaTag />
- </div>
- </Button>
- </Tooltip>
- </div>
+ <TraceOperatorSection addTraceOperator={addTraceOperator} />
)}
</div>
</div>
diff --git a/frontend/src/components/WarningPopover/WarningPopover.tsx b/frontend/src/components/WarningPopover/WarningPopover.tsx
index 472ecd74f3..afd3aebeaa 100644
--- a/frontend/src/components/WarningPopover/WarningPopover.tsx
+++ b/frontend/src/components/WarningPopover/WarningPopover.tsx
@@ -7,7 +7,7 @@ import ErrorIcon from 'assets/Error';
import OverlayScrollbar from 'components/OverlayScrollbar/OverlayScrollbar';
import { BookOpenText, ChevronsDown, TriangleAlert } from 'lucide-react';
import KeyValueLabel from 'periscope/components/KeyValueLabel';
-import { ReactNode } from 'react';
+import { ReactNode, useMemo } from 'react';
import { Warning } from 'types/api';
interface WarningContentProps {
@@ -106,19 +106,51 @@ export function WarningContent({ warning }: WarningContentProps): JSX.Element {
);
}
+function PopoverMessage({
+ message,
+}: {
+ message: string | ReactNode;
+}): JSX.Element {
+ return (
+ <section className="warning-content">
+ <section className="warning-content__summary-section">
+ <header className="warning-content__summary">
+ <div className="warning-content__summary-left">
+ <div className="warning-content__summary-text">
+ <p className="warning-content__warning-message">{message}</p>
+ </div>
+ </div>
+ </header>
+ </section>
+ </section>
+ );
+}
+
interface WarningPopoverProps extends PopoverProps {
children?: ReactNode;
- warningData: Warning;
+ warningData?: Warning;
+ message?: string | ReactNode;
}
function WarningPopover({
children,
warningData,
+ message = '',
...popoverProps
}: WarningPopoverProps): JSX.Element {
+ const content = useMemo(() => {
+ if (message) {
+ return <PopoverMessage message={message} />;
+ }
+ if (warningData) {
+ return <WarningContent warning={warningData} />;
+ }
+ return null;
+ }, [message, warningData]);
+
return (
<Popover
- content={<WarningContent warning={warningData} />}
+ content={content}
overlayStyle={{ padding: 0, maxWidth: '600px' }}
overlayInnerStyle={{ padding: 0 }}
autoAdjustOverflow
@@ -137,6 +169,8 @@ function WarningPopover({
WarningPopover.defaultProps = {
children: undefined,
+ warningData: null,
+ message: null,
};
export default WarningPopover;
diff --git a/frontend/src/container/LogsExplorerViews/index.tsx b/frontend/src/container/LogsExplorerViews/index.tsx
index 6798577b2d..cafb02fdca 100644
--- a/frontend/src/container/LogsExplorerViews/index.tsx
+++ b/frontend/src/container/LogsExplorerViews/index.tsx
@@ -8,11 +8,7 @@ import { ENTITY_VERSION_V5 } from 'constants/app';
import { LOCALSTORAGE } from 'constants/localStorage';
import { AVAILABLE_EXPORT_PANEL_TYPES } from 'constants/panelTypes';
import { QueryParams } from 'constants/query';
-import {
- initialFilters,
- initialQueriesMap,
- PANEL_TYPES,
-} from 'constants/queryBuilder';
+import { initialFilters, PANEL_TYPES } from 'constants/queryBuilder';
import { DEFAULT_PER_PAGE_VALUE } from 'container/Controls/config';
import ExplorerOptionWrapper from 'container/ExplorerOptions/ExplorerOptionWrapper';
import { ChangeViewFunctionType } from 'container/ExplorerOptions/types';
@@ -101,12 +97,7 @@ function LogsExplorerViewsContainer({
const currentMinTimeRef = useRef<number>(minTime);
// Context
- const {
- currentQuery,
- stagedQuery,
- panelType,
- updateAllQueriesOperators,
- } = useQueryBuilder();
+ const { stagedQuery, panelType } = useQueryBuilder();
const selectedPanelType = panelType || PANEL_TYPES.LIST;
@@ -136,13 +127,8 @@ function LogsExplorerViewsContainer({
}, [stagedQuery, activeLogId]);
const exportDefaultQuery = useMemo(
- () =>
- updateAllQueriesOperators(
- currentQuery || initialQueriesMap.logs,
- selectedPanelType,
- DataSource.LOGS,
- ),
- [currentQuery, selectedPanelType, updateAllQueriesOperators],
+ () => getExportQueryData(requestData, selectedPanelType),
+ [selectedPanelType, requestData],
);
const {
@@ -279,9 +265,7 @@ function LogsExplorerViewsContainer({
const widgetId = v4();
- const query = getExportQueryData(requestData, selectedPanelType);
-
- if (!query) return;
+ if (!exportDefaultQuery) return;
logEvent('Logs Explorer: Add to dashboard successful', {
panelType: selectedPanelType,
@@ -290,7 +274,7 @@ function LogsExplorerViewsContainer({
});
const dashboardEditView = generateExportToDashboardLink({
- query,
+ query: exportDefaultQuery,
panelType: panelTypeParam,
dashboardId: dashboard.id,
widgetId,
@@ -298,7 +282,7 @@ function LogsExplorerViewsContainer({
safeNavigate(dashboardEditView);
},
- [safeNavigate, requestData, selectedPanelType],
+ [safeNavigate, exportDefaultQuery, selectedPanelType],
);
useEffect(() => {
diff --git a/frontend/src/container/TimeSeriesView/index.tsx b/frontend/src/container/TimeSeriesView/index.tsx
index 59c5857238..9c6eb02d8e 100644
--- a/frontend/src/container/TimeSeriesView/index.tsx
+++ b/frontend/src/container/TimeSeriesView/index.tsx
@@ -5,7 +5,13 @@ import { initialQueriesMap, PANEL_TYPES } from 'constants/queryBuilder';
import { REACT_QUERY_KEY } from 'constants/reactQueryKeys';
import { useGetQueryRange } from 'hooks/queryBuilder/useGetQueryRange';
import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
-import { Dispatch, SetStateAction, useEffect, useMemo } from 'react';
+import {
+ Dispatch,
+ MutableRefObject,
+ SetStateAction,
+ useEffect,
+ useMemo,
+} from 'react';
import { useSelector } from 'react-redux';
import { AppState } from 'store/reducers';
import { Warning } from 'types/api';
@@ -21,6 +27,7 @@ function TimeSeriesViewContainer({
isFilterApplied,
setWarning,
setIsLoadingQueries,
+ queryKeyRef,
}: TimeSeriesViewProps): JSX.Element {
const { stagedQuery, currentQuery, panelType } = useQueryBuilder();
@@ -48,6 +55,22 @@ function TimeSeriesViewContainer({
return isValid.every(Boolean);
}, [currentQuery]);
+ const queryKey = useMemo(
+ () => [
+ REACT_QUERY_KEY.GET_QUERY_RANGE,
+ globalSelectedTime,
+ maxTime,
+ minTime,
+ stagedQuery,
+ ],
+ [globalSelectedTime, maxTime, minTime, stagedQuery],
+ );
+
+ if (queryKeyRef) {
+ // eslint-disable-next-line no-param-reassign
+ queryKeyRef.current = queryKey;
+ }
+
const { data, isLoading, isFetching, isError, error } = useGetQueryRange(
{
query: stagedQuery || initialQueriesMap[dataSource],
@@ -61,13 +84,7 @@ function TimeSeriesViewContainer({
// ENTITY_VERSION_V4,
ENTITY_VERSION_V5,
{
- queryKey: [
- REACT_QUERY_KEY.GET_QUERY_RANGE,
- globalSelectedTime,
- maxTime,
- minTime,
- stagedQuery,
- ],
+ queryKey,
enabled: !!stagedQuery && panelType === PANEL_TYPES.TIME_SERIES,
},
);
@@ -111,10 +128,12 @@ interface TimeSeriesViewProps {
isFilterApplied: boolean;
setWarning: Dispatch<SetStateAction<Warning | undefined>>;
setIsLoadingQueries: Dispatch<SetStateAction<boolean>>;
+ queryKeyRef?: MutableRefObject<any>;
}
TimeSeriesViewContainer.defaultProps = {
dataSource: DataSource.TRACES,
+ queryKeyRef: undefined,
};
export default TimeSeriesViewContainer;
diff --git a/frontend/src/container/TracesExplorer/ListView/index.tsx b/frontend/src/container/TracesExplorer/ListView/index.tsx
index efc55c4b86..0e8609a6c0 100644
--- a/frontend/src/container/TracesExplorer/ListView/index.tsx
+++ b/frontend/src/container/TracesExplorer/ListView/index.tsx
@@ -14,6 +14,7 @@ import NoLogs from 'container/NoLogs/NoLogs';
import { useOptionsMenu } from 'container/OptionsMenu';
import { CustomTimeType } from 'container/TopNav/DateTimeSelectionV2/config';
import TraceExplorerControls from 'container/TracesExplorer/Controls';
+import { getListViewQuery } from 'container/TracesExplorer/explorerUtils';
import { useGetQueryRange } from 'hooks/queryBuilder/useGetQueryRange';
import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
import { Pagination } from 'hooks/queryPagination';
@@ -22,12 +23,12 @@ import useDragColumns from 'hooks/useDragColumns';
import { getDraggedColumns } from 'hooks/useDragColumns/utils';
import useUrlQueryData from 'hooks/useUrlQueryData';
import { RowData } from 'lib/query/createTableColumnsFromQuery';
-import { cloneDeep } from 'lodash-es';
import { ArrowUp10, Minus } from 'lucide-react';
import { useTimezone } from 'providers/Timezone';
import {
Dispatch,
memo,
+ MutableRefObject,
SetStateAction,
useCallback,
useEffect,
@@ -50,12 +51,14 @@ interface ListViewProps {
isFilterApplied: boolean;
setWarning: Dispatch<SetStateAction<Warning | undefined>>;
setIsLoadingQueries: Dispatch<SetStateAction<boolean>>;
+ queryKeyRef?: MutableRefObject<any>;
}
function ListView({
isFilterApplied,
setWarning,
setIsLoadingQueries,
+ queryKeyRef,
}: ListViewProps): JSX.Element {
const {
stagedQuery,
@@ -92,35 +95,10 @@ function ListView({
const paginationConfig =
paginationQueryData ?? getDefaultPaginationConfig(PER_PAGE_OPTIONS);
- const requestQuery = useMemo(() => {
- const query = stagedQuery
- ? cloneDeep(stagedQuery)
- : cloneDeep(initialQueriesMap.traces);
-
- if (query.builder.queryData[0]) {
- query.builder.queryData[0].orderBy = [
- {
- columnName: orderBy.split(':')[0],
- order: orderBy.split(':')[1] as 'asc' | 'desc',
- },
- ];
- }
-
- // add order by to trace operator
- if (
- query.builder.queryTraceOperator &&
- query.builder.queryTraceOperator.length > 0
- ) {
- query.builder.queryTraceOperator[0].orderBy = [
- {
- columnName: orderBy.split(':')[0],
- order: orderBy.split(':')[1] as 'asc' | 'desc',
- },
- ];
- }
-
- return query;
- }, [stagedQuery, orderBy]);
+ const requestQuery = useMemo(
+ () => getListViewQuery(stagedQuery || initialQueriesMap.traces, orderBy),
+ [stagedQuery, orderBy],
+ );
const queryKey = useMemo(
() => [
@@ -146,6 +124,11 @@ function ListView({
],
);
+ if (queryKeyRef) {
+ // eslint-disable-next-line no-param-reassign
+ queryKeyRef.current = queryKey;
+ }
+
const { data, isFetching, isLoading, isError, error } = useGetQueryRange(
{
query: requestQuery,
@@ -293,4 +276,8 @@ function ListView({
);
}
+ListView.defaultProps = {
+ queryKeyRef: undefined,
+};
+
export default memo(ListView);
diff --git a/frontend/src/container/TracesExplorer/TableView/index.tsx b/frontend/src/container/TracesExplorer/TableView/index.tsx
index 2737bb5c0f..66bdbb2edf 100644
--- a/frontend/src/container/TracesExplorer/TableView/index.tsx
+++ b/frontend/src/container/TracesExplorer/TableView/index.tsx
@@ -6,7 +6,14 @@ import { REACT_QUERY_KEY } from 'constants/reactQueryKeys';
import { QueryTable } from 'container/QueryTable';
import { useGetQueryRange } from 'hooks/queryBuilder/useGetQueryRange';
import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
-import { Dispatch, memo, SetStateAction, useEffect, useMemo } from 'react';
+import {
+ Dispatch,
+ memo,
+ MutableRefObject,
+ SetStateAction,
+ useEffect,
+ useMemo,
+} from 'react';
import { useSelector } from 'react-redux';
import { AppState } from 'store/reducers';
import { Warning } from 'types/api';
@@ -17,9 +24,11 @@ import { GlobalReducer } from 'types/reducer/globalTime';
function TableView({
setWarning,
setIsLoadingQueries,
+ queryKeyRef,
}: {
setWarning: Dispatch<SetStateAction<Warning | undefined>>;
setIsLoadingQueries: Dispatch<SetStateAction<boolean>>;
+ queryKeyRef?: MutableRefObject<any>;
}): JSX.Element {
const { stagedQuery, panelType } = useQueryBuilder();
@@ -28,6 +37,22 @@ function TableView({
GlobalReducer
>((state) => state.globalTime);
+ const queryKey = useMemo(
+ () => [
+ REACT_QUERY_KEY.GET_QUERY_RANGE,
+ globalSelectedTime,
+ maxTime,
+ minTime,
+ stagedQuery,
+ ],
+ [globalSelectedTime, maxTime, minTime, stagedQuery],
+ );
+
+ if (queryKeyRef) {
+ // eslint-disable-next-line no-param-reassign
+ queryKeyRef.current = queryKey;
+ }
+
const { data, isLoading, isFetching, isError, error } = useGetQueryRange(
{
query: stagedQuery || initialQueriesMap.traces,
@@ -40,13 +65,7 @@ function TableView({
},
ENTITY_VERSION_V5,
{
- queryKey: [
- REACT_QUERY_KEY.GET_QUERY_RANGE,
- globalSelectedTime,
- maxTime,
- minTime,
- stagedQuery,
- ],
+ queryKey,
enabled: !!stagedQuery && panelType === PANEL_TYPES.TABLE,
},
);
@@ -89,4 +108,8 @@ function TableView({
);
}
+TableView.defaultProps = {
+ queryKeyRef: undefined,
+};
+
export default memo(TableView);
diff --git a/frontend/src/container/TracesExplorer/TracesView/index.tsx b/frontend/src/container/TracesExplorer/TracesView/index.tsx
index b92a626cfe..b7551623d5 100644
--- a/frontend/src/container/TracesExplorer/TracesView/index.tsx
+++ b/frontend/src/container/TracesExplorer/TracesView/index.tsx
@@ -1,7 +1,7 @@
+/* eslint-disable sonarjs/cognitive-complexity */
import { Typography } from 'antd';
import logEvent from 'api/common/logEvent';
import ErrorInPlace from 'components/ErrorInPlace/ErrorInPlace';
-import ListViewOrderBy from 'components/OrderBy/ListViewOrderBy';
import { ResizeTable } from 'components/ResizeTable';
import { ENTITY_VERSION_V5 } from 'constants/app';
import { QueryParams } from 'constants/query';
@@ -9,19 +9,18 @@ import { initialQueriesMap, PANEL_TYPES } from 'constants/queryBuilder';
import { REACT_QUERY_KEY } from 'constants/reactQueryKeys';
import EmptyLogsSearch from 'container/EmptyLogsSearch/EmptyLogsSearch';
import NoLogs from 'container/NoLogs/NoLogs';
+import { getListViewQuery } from 'container/TracesExplorer/explorerUtils';
import { useGetQueryRange } from 'hooks/queryBuilder/useGetQueryRange';
import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
import { Pagination } from 'hooks/queryPagination';
import useUrlQueryData from 'hooks/useUrlQueryData';
-import { ArrowUp10, Minus } from 'lucide-react';
import {
Dispatch,
memo,
+ MutableRefObject,
SetStateAction,
- useCallback,
useEffect,
useMemo,
- useState,
} from 'react';
import { useSelector } from 'react-redux';
import { AppState } from 'store/reducers';
@@ -30,7 +29,6 @@ import APIError from 'types/api/error';
import { DataSource } from 'types/common/queryBuilder';
import { GlobalReducer } from 'types/reducer/globalTime';
import DOCLINKS from 'utils/docLinks';
-import { transformBuilderQueryFields } from 'utils/queryTransformers';
import TraceExplorerControls from '../Controls';
import { TracesLoading } from '../TraceLoading/TraceLoading';
@@ -41,15 +39,16 @@ interface TracesViewProps {
isFilterApplied: boolean;
setWarning: Dispatch<SetStateAction<Warning | undefined>>;
setIsLoadingQueries: Dispatch<SetStateAction<boolean>>;
+ queryKeyRef?: MutableRefObject<any>;
}
function TracesView({
isFilterApplied,
setWarning,
setIsLoadingQueries,
+ queryKeyRef,
}: TracesViewProps): JSX.Element {
const { stagedQuery, panelType } = useQueryBuilder();
- const [orderBy, setOrderBy] = useState<string>('timestamp:desc');
const { selectedTime: globalSelectedTime, maxTime, minTime } = useSelector<
AppState,
@@ -61,21 +60,34 @@ function TracesView({
);
const transformedQuery = useMemo(
- () =>
- transformBuilderQueryFields(stagedQuery || initialQueriesMap.traces, {
- orderBy: [
- {
- columnName: orderBy.split(':')[0],
- order: orderBy.split(':')[1] as 'asc' | 'desc',
- },
- ],
- }),
- [stagedQuery, orderBy],
+ () => getListViewQuery(stagedQuery || initialQueriesMap.traces),
+ [stagedQuery],
);
- const handleOrderChange = useCallback((value: string) => {
- setOrderBy(value);
- }, []);
+ const queryKey = useMemo(
+ () => [
+ REACT_QUERY_KEY.GET_QUERY_RANGE,
+ globalSelectedTime,
+ maxTime,
+ minTime,
+ stagedQuery,
+ panelType,
+ paginationQueryData,
+ ],
+ [
+ globalSelectedTime,
+ maxTime,
+ minTime,
+ stagedQuery,
+ panelType,
+ paginationQueryData,
+ ],
+ );
+
+ if (queryKeyRef) {
+ // eslint-disable-next-line no-param-reassign
+ queryKeyRef.current = queryKey;
+ }
const { data, isLoading, isFetching, isError, error } = useGetQueryRange(
{
@@ -92,16 +104,7 @@ function TracesView({
},
ENTITY_VERSION_V5,
{
- queryKey: [
- REACT_QUERY_KEY.GET_QUERY_RANGE,
- globalSelectedTime,
- maxTime,
- minTime,
- stagedQuery,
- panelType,
- paginationQueryData,
- orderBy,
- ],
+ queryKey,
enabled: !!stagedQuery && panelType === PANEL_TYPES.TRACE,
},
);
@@ -148,18 +151,6 @@ function TracesView({
</Typography>
<div className="trace-explorer-controls">
- <div className="order-by-container">
- <div className="order-by-label">
- Order by <Minus size={14} /> <ArrowUp10 size={14} />
- </div>
-
- <ListViewOrderBy
- value={orderBy}
- onChange={handleOrderChange}
- dataSource={DataSource.TRACES}
- />
- </div>
-
<TraceExplorerControls
isLoading={isLoading}
totalCount={responseData?.length || 0}
@@ -203,4 +194,8 @@ function TracesView({
);
}
+TracesView.defaultProps = {
+ queryKeyRef: undefined,
+};
+
export default memo(TracesView);
diff --git a/frontend/src/container/TracesExplorer/explorerUtils.ts b/frontend/src/container/TracesExplorer/explorerUtils.ts
new file mode 100644
index 0000000000..bdf0f29e6c
--- /dev/null
+++ b/frontend/src/container/TracesExplorer/explorerUtils.ts
@@ -0,0 +1,75 @@
+import { initialQueriesMap, PANEL_TYPES } from 'constants/queryBuilder';
+import { OptionsQuery } from 'container/OptionsMenu/types';
+import { cloneDeep, set } from 'lodash-es';
+import { OrderByPayload, Query } from 'types/api/queryBuilder/queryBuilderData';
+
+export const getListViewQuery = (
+ stagedQuery: Query,
+ orderBy?: string,
+): Query => {
+ const query = stagedQuery
+ ? cloneDeep(stagedQuery)
+ : cloneDeep(initialQueriesMap.traces);
+
+ const orderByPayload: OrderByPayload[] = orderBy
+ ? [
+ {
+ columnName: orderBy.split(':')[0],
+ order: orderBy.split(':')[1] as 'asc' | 'desc',
+ },
+ ]
+ : [];
+
+ for (let i = 0; i < query.builder.queryData.length; i++) {
+ const queryData = query.builder.queryData[i];
+ queryData.groupBy = [];
+ queryData.having = {
+ expression: '',
+ };
+ queryData.orderBy = orderByPayload;
+ }
+
+ if (
+ query.builder.queryTraceOperator &&
+ query.builder.queryTraceOperator.length > 0
+ ) {
+ for (let i = 0; i < query.builder.queryTraceOperator.length; i++) {
+ const queryTraceOperator = query.builder.queryTraceOperator[i];
+ queryTraceOperator.groupBy = [];
+ queryTraceOperator.having = {
+ expression: '',
+ };
+ queryTraceOperator.orderBy = orderByPayload;
+ }
+ }
+
+ return query;
+};
+
+export const getQueryByPanelType = (
+ stagedQuery: Query,
+ panelType: PANEL_TYPES,
+): Query => {
+ if (panelType === PANEL_TYPES.LIST || panelType === PANEL_TYPES.TRACE) {
+ return getListViewQuery(stagedQuery);
+ }
+ return stagedQuery;
+};
+
+export const getExportQueryData = (
+ query: Query,
+ panelType: PANEL_TYPES,
+ options: OptionsQuery,
+): Query => {
+ if (panelType === PANEL_TYPES.LIST) {
+ const updatedQuery = cloneDeep(query);
+ set(
+ updatedQuery,
+ 'builder.queryData[0].selectColumns',
+ options.selectColumns,
+ );
+
+ return updatedQuery;
+ }
+ return query;
+};
diff --git a/frontend/src/pages/TracesExplorer/constants.ts b/frontend/src/pages/TracesExplorer/constants.ts
new file mode 100644
index 0000000000..6cb2f1bb9e
--- /dev/null
+++ b/frontend/src/pages/TracesExplorer/constants.ts
@@ -0,0 +1,36 @@
+export const TOOLBAR_VIEWS = {
+ list: {
+ name: 'list',
+ label: 'List',
+ show: true,
+ key: 'list',
+ },
+ timeseries: {
+ name: 'timeseries',
+ label: 'Timeseries',
+ disabled: false,
+ show: true,
+ key: 'timeseries',
+ },
+ trace: {
+ name: 'trace',
+ label: 'Trace',
+ disabled: false,
+ show: true,
+ key: 'trace',
+ },
+ table: {
+ name: 'table',
+ label: 'Table',
+ disabled: false,
+ show: true,
+ key: 'table',
+ },
+ clickhouse: {
+ name: 'clickhouse',
+ label: 'Clickhouse',
+ disabled: false,
+ show: false,
+ key: 'clickhouse',
+ },
+};
diff --git a/frontend/src/pages/TracesExplorer/index.tsx b/frontend/src/pages/TracesExplorer/index.tsx
index 19052f1380..49e5a0c759 100644
--- a/frontend/src/pages/TracesExplorer/index.tsx
+++ b/frontend/src/pages/TracesExplorer/index.tsx
@@ -1,7 +1,6 @@
import './TracesExplorer.styles.scss';
import * as Sentry from '@sentry/react';
-import { Callout } from '@signozhq/callout';
import { Card } from 'antd';
import logEvent from 'api/common/logEvent';
import cx from 'classnames';
@@ -13,12 +12,15 @@ import { LOCALSTORAGE } from 'constants/localStorage';
import { AVAILABLE_EXPORT_PANEL_TYPES } from 'constants/panelTypes';
import { initialQueriesMap, PANEL_TYPES } from 'constants/queryBuilder';
import ExplorerOptionWrapper from 'container/ExplorerOptions/ExplorerOptionWrapper';
-import ExportPanel from 'container/ExportPanel';
import { useOptionsMenu } from 'container/OptionsMenu';
import LeftToolbarActions from 'container/QueryBuilder/components/ToolbarActions/LeftToolbarActions';
import RightToolbarActions from 'container/QueryBuilder/components/ToolbarActions/RightToolbarActions';
import TimeSeriesView from 'container/TimeSeriesView';
import Toolbar from 'container/Toolbar/Toolbar';
+import {
+ getExportQueryData,
+ getQueryByPanelType,
+} from 'container/TracesExplorer/explorerUtils';
import ListView from 'container/TracesExplorer/ListView';
import { defaultSelectedColumns } from 'container/TracesExplorer/ListView/configs';
import QuerySection from 'container/TracesExplorer/QuerySection';
@@ -27,36 +29,35 @@ import TracesView from 'container/TracesExplorer/TracesView';
import { useGetPanelTypesQueryParam } from 'hooks/queryBuilder/useGetPanelTypesQueryParam';
import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
import { useShareBuilderUrl } from 'hooks/queryBuilder/useShareBuilderUrl';
-import { useHandleExplorerTabChange } from 'hooks/useHandleExplorerTabChange';
+import {
+ ICurrentQueryData,
+ useHandleExplorerTabChange,
+} from 'hooks/useHandleExplorerTabChange';
import { useSafeNavigate } from 'hooks/useSafeNavigate';
-import { cloneDeep, isEmpty, set } from 'lodash-es';
+import { isEmpty } from 'lodash-es';
import ErrorBoundaryFallback from 'pages/ErrorBoundaryFallback/ErrorBoundaryFallback';
import { ExplorerViews } from 'pages/LogsExplorer/utils';
+import { TOOLBAR_VIEWS } from 'pages/TracesExplorer/constants';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useSearchParams } from 'react-router-dom-v5-compat';
import { Warning } from 'types/api';
import { Dashboard } from 'types/api/dashboard/getAll';
-import {
- IBuilderTraceOperator,
- Query,
-} from 'types/api/queryBuilder/queryBuilderData';
+import { Query } from 'types/api/queryBuilder/queryBuilderData';
import { DataSource } from 'types/common/queryBuilder';
import { generateExportToDashboardLink } from 'utils/dashboard/generateExportToDashboardLink';
import {
- getExplorerViewForPanelType,
+ explorerViewToPanelType,
getExplorerViewFromUrl,
} from 'utils/explorerUtils';
import { v4 } from 'uuid';
function TracesExplorer(): JSX.Element {
const {
- currentQuery,
panelType,
updateAllQueriesOperators,
handleRunQuery,
stagedQuery,
handleSetConfig,
- updateQueriesData,
} = useQueryBuilder();
const { options } = useOptionsMenu({
@@ -69,6 +70,7 @@ function TracesExplorer(): JSX.Element {
});
const [searchParams] = useSearchParams();
+ const listQueryKeyRef = useRef<any>();
// Get panel type from URL
const panelTypesFromUrl = useGetPanelTypesQueryParam(PANEL_TYPES.LIST);
@@ -78,103 +80,45 @@ function TracesExplorer(): JSX.Element {
getExplorerViewFromUrl(searchParams, panelTypesFromUrl),
);
- const { handleExplorerTabChange } = useHandleExplorerTabChange();
- const { safeNavigate } = useSafeNavigate();
-
- // Update selected view when panel type from URL changes
- useEffect(() => {
- if (panelTypesFromUrl) {
- const newView = getExplorerViewForPanelType(panelTypesFromUrl);
- if (newView && newView !== selectedView) {
- setSelectedView(newView);
- }
- }
- }, [panelTypesFromUrl, selectedView]);
-
- const [shouldReset, setShouldReset] = useState(false);
+ const [warning, setWarning] = useState<Warning | undefined>(undefined);
+ const [isOpen, setOpen] = useState<boolean>(true);
- const [defaultQuery, setDefaultQuery] = useState<Query>(() =>
- updateAllQueriesOperators(
- initialQueriesMap.traces,
- PANEL_TYPES.LIST,
- DataSource.TRACES,
- ),
+ const defaultQuery = useMemo(
+ (): Query =>
+ updateAllQueriesOperators(
+ initialQueriesMap.traces,
+ PANEL_TYPES.LIST,
+ DataSource.TRACES,
+ ),
+ [updateAllQueriesOperators],
);
- const handleChangeSelectedView = useCallback(
- (view: ExplorerViews): void => {
- if (selectedView === ExplorerViews.LIST) {
- handleSetConfig(PANEL_TYPES.LIST, DataSource.TRACES);
- }
-
- if (
- (selectedView === ExplorerViews.TRACE ||
- selectedView === ExplorerViews.LIST) &&
- stagedQuery?.builder?.queryTraceOperator &&
- stagedQuery.builder.queryTraceOperator.length > 0
- ) {
- // remove order by from trace operator
- set(stagedQuery, 'builder.queryTraceOperator[0].orderBy', []);
- }
-
- if (view === ExplorerViews.LIST || view === ExplorerViews.TRACE) {
- // loop through all the queries and remove the group by
-
- const updateQuery = updateQueriesData(
- currentQuery,
- 'queryData',
- (item) => ({ ...item, groupBy: [], orderBy: [] }),
- );
-
- setDefaultQuery(updateQuery);
+ const { handleExplorerTabChange } = useHandleExplorerTabChange();
+ const { safeNavigate } = useSafeNavigate();
- setShouldReset(true);
- }
+ const handleChangeSelectedView = useCallback(
+ (view: ExplorerViews, querySearchParameters?: ICurrentQueryData): void => {
+ handleSetConfig(explorerViewToPanelType[view], DataSource.TRACES);
setSelectedView(view);
handleExplorerTabChange(
- view === ExplorerViews.TIMESERIES ? PANEL_TYPES.TIME_SERIES : view,
+ explorerViewToPanelType[view],
+ querySearchParameters,
);
},
- [
- selectedView,
- currentQuery,
- stagedQuery,
- handleExplorerTabChange,
- handleSetConfig,
- updateQueriesData,
- ],
+ [handleExplorerTabChange, handleSetConfig],
);
- const listQuery = useMemo(() => {
- if (!stagedQuery || stagedQuery.builder.queryData.length < 1) return null;
-
- return stagedQuery.builder.queryData.find((item) => !item.disabled) || null;
- }, [stagedQuery]);
-
const exportDefaultQuery = useMemo(
() =>
- updateAllQueriesOperators(
- currentQuery || initialQueriesMap.traces,
- PANEL_TYPES.TIME_SERIES,
- DataSource.TRACES,
+ getQueryByPanelType(
+ stagedQuery || initialQueriesMap.traces,
+ panelType || PANEL_TYPES.LIST,
),
- [currentQuery, updateAllQueriesOperators],
+ [stagedQuery, panelType],
);
- const getUpdatedQueryForExport = useCallback((): Query => {
- const updatedQuery = cloneDeep(currentQuery);
-
- set(
- updatedQuery,
- 'builder.queryData[0].selectColumns',
- options.selectColumns,
- );
-
- return updatedQuery;
- }, [currentQuery, options.selectColumns]);
-
const handleExport = useCallback(
(dashboard: Dashboard | null, isNewDashboard?: boolean): void => {
if (!dashboard || !panelType) return;
@@ -185,10 +129,11 @@ function TracesExplorer(): JSX.Element {
const widgetId = v4();
- const query =
- panelType === PANEL_TYPES.LIST
- ? getUpdatedQueryForExport()
- : exportDefaultQuery;
+ const query = getExportQueryData(
+ exportDefaultQuery,
+ panelTypeParam,
+ options,
+ );
logEvent('Traces Explorer: Add to dashboard successful', {
panelType,
@@ -205,56 +150,11 @@ function TracesExplorer(): JSX.Element {
safeNavigate(dashboardEditView);
},
- [exportDefaultQuery, panelType, safeNavigate, getUpdatedQueryForExport],
- );
-
- useShareBuilderUrl({ defaultValue: defaultQuery, forceReset: shouldReset });
-
- const hasMultipleQueries = useMemo(
- () => currentQuery?.builder?.queryData?.length > 1,
- [currentQuery],
+ [exportDefaultQuery, panelType, safeNavigate, options],
);
- const traceOperator = useMemo((): IBuilderTraceOperator | undefined => {
- if (
- currentQuery.builder.queryTraceOperator &&
- currentQuery.builder.queryTraceOperator.length > 0
- ) {
- return currentQuery.builder.queryTraceOperator[0];
- }
-
- return undefined;
- }, [currentQuery.builder.queryTraceOperator]);
-
- const showTraceOperatorCallout = useMemo(
- () =>
- (selectedView === ExplorerViews.LIST ||
- selectedView === ExplorerViews.TRACE) &&
- hasMultipleQueries &&
- !traceOperator,
- [selectedView, hasMultipleQueries, traceOperator],
- );
-
- const traceOperatorCalloutDescription = useMemo(() => {
- if (currentQuery.builder.queryData.length === 0) return '';
- const firstQuery = currentQuery.builder.queryData[0];
- return `Please use a Trace Operator to combine results of multiple span queries. Else you'd only see the results from query "${firstQuery.queryName}"`;
- }, [currentQuery]);
-
- useEffect(() => {
- if (shouldReset) {
- setShouldReset(false);
- setDefaultQuery(
- updateAllQueriesOperators(
- initialQueriesMap.traces,
- PANEL_TYPES.LIST,
- DataSource.TRACES,
- ),
- );
- }
- }, [shouldReset, updateAllQueriesOperators]);
+ useShareBuilderUrl({ defaultValue: defaultQuery });
- const [isOpen, setOpen] = useState<boolean>(true);
const logEventCalledRef = useRef(false);
useEffect(() => {
@@ -264,51 +164,13 @@ function TracesExplorer(): JSX.Element {
}
}, []);
- const toolbarViews = useMemo(
- () => ({
- list: {
- name: 'list',
- label: 'List',
- show: true,
- key: 'list',
- },
- timeseries: {
- name: 'timeseries',
- label: 'Timeseries',
- disabled: false,
- show: true,
- key: 'timeseries',
- },
- trace: {
- name: 'trace',
- label: 'Trace',
- disabled: false,
- show: true,
- key: 'trace',
- },
- table: {
- name: 'table',
- label: 'Table',
- disabled: false,
- show: true,
- key: 'table',
- },
- clickhouse: {
- name: 'clickhouse',
- label: 'Clickhouse',
- disabled: false,
- show: false,
- key: 'clickhouse',
- },
- }),
- [],
- );
-
- const isFilterApplied = useMemo(() => !isEmpty(listQuery?.filters?.items), [
- listQuery,
- ]);
-
- const [warning, setWarning] = useState<Warning | undefined>(undefined);
+ const isFilterApplied = useMemo(() => {
+ // if any of the non-disabled queries has filters applied, return true
+ const result = stagedQuery?.builder?.queryData?.filter(
+ (item) => !isEmpty(item.filters?.items) && !item.disabled,
+ );
+ return !!result?.length;
+ }, [stagedQuery]);
return (
<Sentry.ErrorBoundary fallback={<ErrorBoundaryFallback />}>
@@ -335,7 +197,7 @@ function TracesExplorer(): JSX.Element {
<LeftToolbarActions
showFilter={isOpen}
handleFilterVisibilityChange={(): void => setOpen(!isOpen)}
- items={toolbarViews}
+ items={TOOLBAR_VIEWS}
selectedView={selectedView}
onChangeSelectedView={handleChangeSelectedView}
/>
@@ -347,6 +209,7 @@ function TracesExplorer(): JSX.Element {
<RightToolbarActions
onStageRunQuery={(): void => handleRunQuery()}
isLoadingQueries={isLoadingQueries}
+ listQueryKeyRef={listQueryKeyRef}
/>
}
/>
@@ -358,29 +221,13 @@ function TracesExplorer(): JSX.Element {
</ExplorerCard>
<div className="traces-explorer-views">
- <div className="traces-explorer-export-panel">
- <ExportPanel
- query={exportDefaultQuery}
- isLoading={false}
- onExport={handleExport}
- />
- </div>
-
- {showTraceOperatorCallout && (
- <Callout
- type="info"
- size="small"
- showIcon
- description={traceOperatorCalloutDescription}
- />
- )}
-
{selectedView === ExplorerViews.LIST && (
<div className="trace-explorer-list-view">
<ListView
isFilterApplied={isFilterApplied}
setWarning={setWarning}
setIsLoadingQueries={setIsLoadingQueries}
+ queryKeyRef={listQueryKeyRef}
/>
</div>
)}
@@ -391,6 +238,7 @@ function TracesExplorer(): JSX.Element {
isFilterApplied={isFilterApplied}
setWarning={setWarning}
setIsLoadingQueries={setIsLoadingQueries}
+ queryKeyRef={listQueryKeyRef}
/>
</div>
)}
@@ -402,6 +250,7 @@ function TracesExplorer(): JSX.Element {
isFilterApplied={isFilterApplied}
setWarning={setWarning}
setIsLoadingQueries={setIsLoadingQueries}
+ queryKeyRef={listQueryKeyRef}
/>
</div>
)}
@@ -411,6 +260,7 @@ function TracesExplorer(): JSX.Element {
<TableView
setWarning={setWarning}
setIsLoadingQueries={setIsLoadingQueries}
+ queryKeyRef={listQueryKeyRef}
/>
</div>
)}
@@ -421,6 +271,7 @@ function TracesExplorer(): JSX.Element {
query={exportDefaultQuery}
sourcepage={DataSource.TRACES}
onExport={handleExport}
+ handleChangeSelectedView={handleChangeSelectedView}
/>
</div>
</div>
diff --git a/frontend/src/utils/queryTransformers.ts b/frontend/src/utils/queryTransformers.ts
deleted file mode 100644
index 16f318c8a2..0000000000
--- a/frontend/src/utils/queryTransformers.ts
+++ /dev/null
@@ -1,28 +0,0 @@
-import { cloneDeep } from 'lodash-es';
-import { IBuilderQuery, Query } from 'types/api/queryBuilder/queryBuilderData';
-
-/**
- * Transforms a query by modifying specific fields in the builder queries
- * @param query - The original query object
- * @param fieldOverrides - Partial object containing fields to override in each builder query
- * @returns A new query object with the modified fields
- */
-export const transformBuilderQueryFields = (
- query: Query,
- fieldOverrides: Partial<IBuilderQuery>,
-): Query => {
- // Create a deep copy of the query
- const transformedQuery: Query = cloneDeep(query);
-
- // Update the specified fields for each query in the builder
- if (transformedQuery.builder?.queryData) {
- transformedQuery.builder.queryData = transformedQuery.builder.queryData.map(
- (queryItem) => ({
- ...queryItem,
- ...fieldOverrides,
- }),
- );
- }
-
- return transformedQuery;
-};