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(quick-filters): AI o11y quick filters (#12788)

Gaurav Tewari35973efd6560
diff --git a/frontend/src/components/QuickFilters/FilterRenderers/Checkbox/Checkbox.tsx b/frontend/src/components/QuickFilters/FilterRenderers/Checkbox/Checkbox.tsx
index 271a3918c6..21d0c073da 100644
--- a/frontend/src/components/QuickFilters/FilterRenderers/Checkbox/Checkbox.tsx
+++ b/frontend/src/components/QuickFilters/FilterRenderers/Checkbox/Checkbox.tsx
@@ -15,7 +15,7 @@ import { Query } from 'types/api/queryBuilder/queryBuilderData';
import CheckboxFilterHeader from './CheckboxFilterHeader';
import CheckboxValueRow from './CheckboxValueRow';
import LogsQuickFilterEmptyState from './LogsQuickFilterEmptyState';
-import useActiveQueryIndex from './useActiveQueryIndex';
+import useActiveQueryIndex from 'components/QuickFilters/hooks/useActiveQueryIndex';
import useCheckboxDisclosure from './useCheckboxDisclosure';
import useCheckboxFilterActions from './useCheckboxFilterActions';
import useCheckboxFilterState from './useCheckboxFilterState';
diff --git a/frontend/src/components/QuickFilters/FilterRenderers/Checkbox/v2/CheckboxFilterV2.testUtils.tsx b/frontend/src/components/QuickFilters/FilterRenderers/Checkbox/v2/CheckboxFilterV2.testUtils.tsx
index 5a787fcda4..a3ed683d93 100644
--- a/frontend/src/components/QuickFilters/FilterRenderers/Checkbox/v2/CheckboxFilterV2.testUtils.tsx
+++ b/frontend/src/components/QuickFilters/FilterRenderers/Checkbox/v2/CheckboxFilterV2.testUtils.tsx
@@ -56,6 +56,57 @@ export function mockFieldsValuesAPI(response: {
);
}
+/**
+ * Records every request the AI observability values endpoint receives, so a test
+ * can assert both the routing and the query params it was called with.
+ */
+export function mockAIObservabilityFieldsValuesAPI(response: {
+ relatedValues?: (string | null)[];
+ stringValues?: (string | null)[];
+ numberValues?: (number | null)[];
+}): { requests: URLSearchParams[] } {
+ const requests: URLSearchParams[] = [];
+
+ server.use(
+ rest.get(
+ 'http://localhost/api/v1/ai_observability/fields/values',
+ (req, res, ctx) => {
+ requests.push(req.url.searchParams);
+
+ return res(
+ ctx.status(200),
+ ctx.json({
+ status: 'success',
+ data: {
+ values: {
+ relatedValues: response.relatedValues ?? [],
+ stringValues: response.stringValues ?? [],
+ numberValues: response.numberValues ?? [],
+ },
+ },
+ }),
+ );
+ },
+ ),
+ );
+
+ return { requests };
+}
+
+/** Fails the test if the signal-wide values endpoint is hit at all. */
+export function forbidFieldsValuesAPI(): { called: boolean } {
+ const state = { called: false };
+
+ server.use(
+ rest.get('http://localhost/api/v1/fields/values', (_, res, ctx) => {
+ state.called = true;
+ return res(ctx.status(200), ctx.json({ status: 'success', data: {} }));
+ }),
+ );
+
+ return state;
+}
+
export function mockFieldsValuesAPILoading(): void {
server.use(
rest.get('http://localhost/api/v1/fields/values', (_, res, ctx) =>
diff --git a/frontend/src/components/QuickFilters/FilterRenderers/Checkbox/v2/CheckboxFilterV2.tsx b/frontend/src/components/QuickFilters/FilterRenderers/Checkbox/v2/CheckboxFilterV2.tsx
index e634a6577f..c8d2a1640f 100644
--- a/frontend/src/components/QuickFilters/FilterRenderers/Checkbox/v2/CheckboxFilterV2.tsx
+++ b/frontend/src/components/QuickFilters/FilterRenderers/Checkbox/v2/CheckboxFilterV2.tsx
@@ -16,7 +16,7 @@ import useDebouncedFn from 'hooks/useDebouncedFunction';
import { Query } from 'types/api/queryBuilder/queryBuilderData';
import { NON_SELECTED_OPERATORS } from '../checkboxFilterQuery';
-import useActiveQueryIndex from '../useActiveQueryIndex';
+import useActiveQueryIndex from 'components/QuickFilters/hooks/useActiveQueryIndex';
import useCheckboxDisclosure from '../useCheckboxDisclosure';
import useCheckboxFilterActions from '../useCheckboxFilterActions';
import useCheckboxFilterState from '../useCheckboxFilterState';
diff --git a/frontend/src/components/QuickFilters/FilterRenderers/Checkbox/v2/__tests__/CheckboxFilterV2.aiObservability.test.tsx b/frontend/src/components/QuickFilters/FilterRenderers/Checkbox/v2/__tests__/CheckboxFilterV2.aiObservability.test.tsx
new file mode 100644
index 0000000000..9d7b63205f
--- /dev/null
+++ b/frontend/src/components/QuickFilters/FilterRenderers/Checkbox/v2/__tests__/CheckboxFilterV2.aiObservability.test.tsx
@@ -0,0 +1,81 @@
+import { screen, waitFor } from '@testing-library/react';
+import { render } from 'tests/test-utils';
+
+import { QuickFiltersSource } from '../../../../types';
+
+import CheckboxFilterV2 from '../CheckboxFilterV2';
+import {
+ DEFAULT_FILTER,
+ DEFAULT_USE_FIELD_APIS,
+ forbidFieldsValuesAPI,
+ mockAIObservabilityFieldsValuesAPI,
+ mockFieldsValuesAPI,
+ setupServer,
+} from '../CheckboxFilterV2.testUtils';
+
+setupServer();
+
+describe('CheckboxFilterV2 - AI observability routing', () => {
+ it('reads values from the AI observability endpoint and never the signal-wide one', async () => {
+ const aiEndpoint = mockAIObservabilityFieldsValuesAPI({
+ stringValues: ['openai', 'anthropic'],
+ });
+ const fieldsEndpoint = forbidFieldsValuesAPI();
+
+ render(
+ <CheckboxFilterV2
+ filter={DEFAULT_FILTER}
+ source={QuickFiltersSource.AI_OBSERVABILITY}
+ useFieldApis={DEFAULT_USE_FIELD_APIS}
+ />,
+ );
+
+ await expect(screen.findByText('openai')).resolves.toBeInTheDocument();
+ expect(screen.getByText('anthropic')).toBeInTheDocument();
+ expect(fieldsEndpoint.called).toBe(false);
+ expect(aiEndpoint.requests).toHaveLength(1);
+ });
+
+ it('forwards the filter key and the time range to the AI observability endpoint', async () => {
+ const aiEndpoint = mockAIObservabilityFieldsValuesAPI({
+ stringValues: ['openai'],
+ });
+
+ render(
+ <CheckboxFilterV2
+ filter={DEFAULT_FILTER}
+ source={QuickFiltersSource.AI_OBSERVABILITY}
+ useFieldApis={DEFAULT_USE_FIELD_APIS}
+ />,
+ );
+
+ await screen.findByText('openai');
+
+ const params = aiEndpoint.requests[0];
+ expect(params.get('name')).toBe(DEFAULT_FILTER.attributeKey.key);
+ expect(params.get('startUnixMilli')).toBe(
+ String(DEFAULT_USE_FIELD_APIS.startUnixMilli),
+ );
+ expect(params.get('endUnixMilli')).toBe(
+ String(DEFAULT_USE_FIELD_APIS.endUnixMilli),
+ );
+ });
+
+ it('keeps non-AI sources on the signal-wide endpoint', async () => {
+ mockFieldsValuesAPI({ stringValues: ['production'] });
+ const aiEndpoint = mockAIObservabilityFieldsValuesAPI({
+ stringValues: ['should-not-be-used'],
+ });
+
+ render(
+ <CheckboxFilterV2
+ filter={DEFAULT_FILTER}
+ source={QuickFiltersSource.TRACES_EXPLORER}
+ useFieldApis={DEFAULT_USE_FIELD_APIS}
+ />,
+ );
+
+ await expect(screen.findByText('production')).resolves.toBeInTheDocument();
+ await waitFor(() => expect(aiEndpoint.requests).toHaveLength(0));
+ });
+});
diff --git a/frontend/src/components/QuickFilters/FilterRenderers/Checkbox/v2/useFieldValues.tsx b/frontend/src/components/QuickFilters/FilterRenderers/Checkbox/v2/useFieldValues.tsx
index e8a80adc83..f337649ca7 100644
--- a/frontend/src/components/QuickFilters/FilterRenderers/Checkbox/v2/useFieldValues.tsx
+++ b/frontend/src/components/QuickFilters/FilterRenderers/Checkbox/v2/useFieldValues.tsx
@@ -1,11 +1,12 @@
import { useMemo } from 'react';
-import { useGetFieldsValues } from 'api/generated/services/fields';
import { TelemetrytypesSourceDTO } from 'api/generated/services/sigNoz.schemas';
+import { FieldValuesConfig } from 'api/querySuggestions/types';
import {
IQuickFiltersConfig,
QuickFiltersSource,
} from 'components/QuickFilters/types';
-import { FIELD_API_CACHE_TIME } from 'constants/queryCacheTime';
+import { useFieldValuesSuggestion } from 'hooks/querySuggestions/useFieldValuesSuggestion';
+import { BuilderQueryType } from 'types/api/v5/queryRange';
import { DATA_SOURCE_TO_SIGNAL } from 'types/common/queryBuilder';
interface UseFieldValuesProps {
@@ -42,32 +43,43 @@ export function useFieldValues({
endUnixMilli,
enabled,
}: UseFieldValuesProps): UseFieldValuesReturn {
- const { data, isLoading, isFetching } = useGetFieldsValues(
- {
- signal: filter.dataSource
- ? DATA_SOURCE_TO_SIGNAL[filter.dataSource]
- : undefined,
- name: filter.attributeKey.key,
- searchText,
- existingQuery,
- metricNamespace,
- source: source ? QUICK_FILTERS_SOURCE_TO_SOURCE[source] : undefined,
- startUnixMilli,
- // This field does not affect the backend but I wanted to keep it here
- // in case we add the support in the future
- endUnixMilli,
- },
- {
- query: {
- enabled,
- cacheTime: FIELD_API_CACHE_TIME,
- keepPreviousData: true,
- },
- },
- );
+ const isAIObservability = source === QuickFiltersSource.AI_OBSERVABILITY;
+
+ const builderQueryType: BuilderQueryType | undefined = isAIObservability
+ ? 'builder_ai_query'
+ : undefined;
+
+ // The AI values endpoint is already gen_ai-scoped: no signal, no source.
+ const fieldValuesConfig: FieldValuesConfig = isAIObservability
+ ? {
+ name: filter.attributeKey.key,
+ searchText,
+ existingQuery,
+ startUnixMilli,
+ endUnixMilli,
+ }
+ : {
+ signal: filter.dataSource
+ ? DATA_SOURCE_TO_SIGNAL[filter.dataSource]
+ : undefined,
+ name: filter.attributeKey.key,
+ searchText,
+ existingQuery,
+ metricNamespace,
+ source: source ? QUICK_FILTERS_SOURCE_TO_SOURCE[source] : undefined,
+ startUnixMilli,
+ // This field does not affect the backend but I wanted to keep it here
+ // in case we add the support in the future
+ endUnixMilli,
+ };
+
+ const {
+ data: values,
+ isLoading,
+ isFetching,
+ } = useFieldValuesSuggestion(fieldValuesConfig, builderQueryType, { enabled });
const relatedValues: string[] = useMemo(() => {
- const values = data?.data?.values;
if (!values) {
return [];
}
@@ -78,10 +90,9 @@ export function useFieldValues({
value !== null && value !== undefined && value !== '',
) || []
);
- }, [data]);
+ }, [values]);
const allValues: string[] = useMemo(() => {
- const values = data?.data?.values;
if (!values) {
return [];
}
@@ -101,7 +112,7 @@ export function useFieldValues({
.map((value) => value.toString()) || [];
return [...stringValues, ...numberValues, ...boolValues];
- }, [data]);
+ }, [values]);
return { relatedValues, allValues, isLoading, isFetching };
}
diff --git a/frontend/src/components/QuickFilters/FilterRenderers/Duration/Duration.tsx b/frontend/src/components/QuickFilters/FilterRenderers/Duration/Duration.tsx
index d2357862df..4d0bc727b3 100644
--- a/frontend/src/components/QuickFilters/FilterRenderers/Duration/Duration.tsx
+++ b/frontend/src/components/QuickFilters/FilterRenderers/Duration/Duration.tsx
@@ -1,11 +1,11 @@
import { useCallback, useEffect, useMemo, useState } from 'react';
import { Collapse } from 'antd';
import { Undo2 } from '@signozhq/icons';
+import useActiveQueryIndex from 'components/QuickFilters/hooks/useActiveQueryIndex';
import {
IQuickFiltersConfig,
QuickFiltersSource,
} from 'components/QuickFilters/types';
-import { PANEL_TYPES } from 'constants/queryBuilder';
import { getMs } from 'container/Trace/Filters/Panel/PanelBody/Duration/util';
import { useGetCompositeQueryParam } from 'hooks/queryBuilder/useGetCompositeQueryParam';
import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
@@ -39,7 +39,7 @@ function Duration({
}: {
filter: IQuickFiltersConfig;
onFilterChange?: (query: Query) => void;
- source?: QuickFiltersSource;
+ source: QuickFiltersSource;
}): JSX.Element {
const [selectedFilters, setSelectedFilters] =
useState<
@@ -52,26 +52,11 @@ function Duration({
filter.defaultOpen ? 'durationNano' : '',
]);
- const {
- currentQuery,
- redirectWithQueryBuilderData,
- lastUsedQuery,
- panelType,
- } = useQueryBuilder();
+ const { currentQuery, redirectWithQueryBuilderData } = useQueryBuilder();
const compositeQuery = useGetCompositeQueryParam();
- const isListView = panelType === PANEL_TYPES.LIST;
- // In ListView mode, use index 0 for most sources; for TRACES_EXPLORER, use lastUsedQuery
- // Otherwise use lastUsedQuery for non-ListView modes
- const activeQueryIndex = useMemo(() => {
- if (isListView) {
- return source === QuickFiltersSource.TRACES_EXPLORER
- ? lastUsedQuery || 0
- : 0;
- }
- return lastUsedQuery || 0;
- }, [isListView, source, lastUsedQuery]);
+ const activeQueryIndex = useActiveQueryIndex(source);
// eslint-disable-next-line sonarjs/cognitive-complexity
const syncSelectedFilters = useMemo((): FilterType => {
diff --git a/frontend/src/components/QuickFilters/QuickFilters.tsx b/frontend/src/components/QuickFilters/QuickFilters.tsx
index 62043b8984..6ef0d2d0b4 100644
--- a/frontend/src/components/QuickFilters/QuickFilters.tsx
+++ b/frontend/src/components/QuickFilters/QuickFilters.tsx
@@ -35,6 +35,7 @@ import { isFunction } from 'lodash-es';
import { Query } from 'types/api/queryBuilder/queryBuilderData';
import Checkbox from './FilterRenderers/Checkbox/Checkbox';
+import useActiveQueryIndex from './hooks/useActiveQueryIndex';
import CheckboxV2 from './FilterRenderers/Checkbox/v2/CheckboxFilterV2';
import Duration from './FilterRenderers/Duration/Duration';
import Slider from './FilterRenderers/Slider/Slider';
@@ -113,14 +114,13 @@ export default function QuickFilters(props: IQuickFiltersProps): JSX.Element {
const shouldShowDropdownInListView =
isListView && source === QuickFiltersSource.TRACES_EXPLORER;
- const activeQueryIndex = useMemo(() => {
- if (isListView) {
- return source === QuickFiltersSource.TRACES_EXPLORER
- ? lastUsedQuery || 0
- : 0;
- }
- return lastUsedQuery || 0;
- }, [isListView, source, lastUsedQuery]);
+ // AI observability builds a single query in the row-level views, so there is
+ // no query for the selector to switch between.
+ const isAIObservabilityRowView =
+ source === QuickFiltersSource.AI_OBSERVABILITY &&
+ (isListView || panelType === PANEL_TYPES.TRACE);
+
+ const activeQueryIndex = useActiveQueryIndex(source);
// clear all the filters for the query which is in sync with filters
const handleReset = (): void => {
@@ -167,9 +167,10 @@ export default function QuickFilters(props: IQuickFiltersProps): JSX.Element {
currentQuery.builder.queryData?.[lastUsedQuery || 0]?.queryName;
// In ListView, always show the 0th query's name; otherwise use the active query's name
- const displayedQueryName = isListView
- ? showQueryName && currentQuery.builder.queryData?.[0]?.queryName
- : lastQueryName;
+ const displayedQueryName =
+ isListView || isAIObservabilityRowView
+ ? showQueryName && currentQuery.builder.queryData?.[0]?.queryName
+ : lastQueryName;
const handleQueryChange = (value: number): void => {
setLastUsedQuery(value);
@@ -182,7 +183,9 @@ export default function QuickFilters(props: IQuickFiltersProps): JSX.Element {
<Typography.Text className="text">
{displayedQueryName ? 'Filters for' : 'Filters'}
</Typography.Text>
- {queryOptions.length > 1 && (!isListView || shouldShowDropdownInListView) ? (
+ {queryOptions.length > 1 &&
+ !isAIObservabilityRowView &&
+ (!isListView || shouldShowDropdownInListView) ? (
<Combobox open={open} onOpenChange={setOpen}>
<ComboboxTrigger
placeholder="Select a query"
@@ -318,6 +321,7 @@ export default function QuickFilters(props: IQuickFiltersProps): JSX.Element {
return (
<Duration
key={filter.attributeKey.key}
+ source={source}
filter={filter}
onFilterChange={onFilterChange}
/>
diff --git a/frontend/src/components/QuickFilters/QuickFiltersSettings/OtherFilters.tsx b/frontend/src/components/QuickFilters/QuickFiltersSettings/OtherFilters.tsx
index 313673410d..b6f5174a0a 100644
--- a/frontend/src/components/QuickFilters/QuickFiltersSettings/OtherFilters.tsx
+++ b/frontend/src/components/QuickFilters/QuickFiltersSettings/OtherFilters.tsx
@@ -1,12 +1,14 @@
import { useMemo } from 'react';
import { Button, Skeleton } from 'antd';
-import { useGetFieldsKeys } from 'api/generated/services/fields';
import { TelemetrytypesSourceDTO } from 'api/generated/services/sigNoz.schemas';
+import { FieldKeysConfig } from 'api/querySuggestions/types';
import OverlayScrollbar from 'components/OverlayScrollbar/OverlayScrollbar';
import { SIGNAL_DATA_SOURCE_MAP } from 'components/QuickFilters/QuickFiltersSettings/constants';
import { SignalType } from 'components/QuickFilters/types';
import { buildCompositeKey } from 'container/OptionsMenu/utils';
+import { useFieldKeysSuggestion } from 'hooks/querySuggestions/useFieldKeysSuggestion';
import {
+ BuilderQueryType,
FieldContext,
FieldDataType,
TelemetryFieldKey,
@@ -41,23 +43,31 @@ function OtherFilters({
setAddedFilters: React.Dispatch<React.SetStateAction<TelemetryFieldKey[]>>;
}): JSX.Element {
const isMeterDataSource = signal === SignalType.METER_EXPLORER;
+ const isAIObservability = signal === SignalType.AI_OBSERVABILITY;
- const { data, isFetching } = useGetFieldsKeys(
- {
- searchText: inputValue,
- signal: signal
- ? DATA_SOURCE_TO_SIGNAL[SIGNAL_DATA_SOURCE_MAP[signal]]
- : undefined,
- source: isMeterDataSource ? TelemetrytypesSourceDTO.meter : undefined,
- },
- { query: { enabled: !!signal } },
+ const builderQueryType: BuilderQueryType | undefined = isAIObservability
+ ? 'builder_ai_query'
+ : undefined;
+
+ const fieldKeysConfig: FieldKeysConfig = isAIObservability
+ ? { searchText: inputValue }
+ : {
+ searchText: inputValue,
+ signal: signal
+ ? DATA_SOURCE_TO_SIGNAL[SIGNAL_DATA_SOURCE_MAP[signal]]
+ : undefined,
+ source: isMeterDataSource ? TelemetrytypesSourceDTO.meter : undefined,
+ };
+
+ const { data: fetchedKeys, isFetching } = useFieldKeysSuggestion(
+ fieldKeysConfig,
+ builderQueryType,
);
const otherFilters = useMemo<TelemetryFieldKey[]>(() => {
- const rawSuggestions = Object.values(data?.data?.keys ?? {}).flat();
// Normalize: synthesize the composite `key` once so downstream reads (dedupe,
// add, render) can trust it.
- const suggestions: TelemetryFieldKey[] = rawSuggestions.map((attr) => ({
+ const suggestions: TelemetryFieldKey[] = (fetchedKeys ?? []).map((attr) => ({
name: attr.name,
signal: attr.signal as TelemetryFieldKey['signal'],
fieldContext: attr.fieldContext as FieldContext,
@@ -71,7 +81,7 @@ function OtherFilters({
),
);
return suggestions.filter((attr) => !addedKeys.has(attr.key as string));
- }, [data, addedFilters]);
+ }, [fetchedKeys, addedFilters]);
const handleAddFilter = (filter: TelemetryFieldKey): void => {
setAddedFilters((prev) => [...prev, filter]);
diff --git a/frontend/src/components/QuickFilters/QuickFiltersSettings/__tests__/OtherFilters.test.tsx b/frontend/src/components/QuickFilters/QuickFiltersSettings/__tests__/OtherFilters.test.tsx
new file mode 100644
index 0000000000..3200f203fc
--- /dev/null
+++ b/frontend/src/components/QuickFilters/QuickFiltersSettings/__tests__/OtherFilters.test.tsx
@@ -0,0 +1,81 @@
+import { screen, waitFor } from '@testing-library/react';
+import { ENVIRONMENT } from 'constants/env';
+import { server } from 'mocks-server/server';
+import { rest } from 'msw';
+import { render } from 'tests/test-utils';
+
+import { SignalType } from '../../types';
+import OtherFilters from '../OtherFilters';
+
+const BASE_URL = ENVIRONMENT.baseURL;
+const FIELDS_KEYS_URL = `${BASE_URL}/api/v1/fields/keys`;
+const AI_KEYS_URL = `${BASE_URL}/api/v1/ai_observability/fields/keys`;
+
+function keysResponse(name: string): Record<string, unknown> {
+ return {
+ status: 'success',
+ data: {
+ complete: true,
+ keys: {
+ [name]: [{ name, fieldContext: 'attribute', fieldDataType: 'string' }],
+ },
+ },
+ };
+}
+
+describe('OtherFilters - AI observability keys', () => {
+ let fieldsKeysCalled: boolean;
+ let aiKeysParams: URLSearchParams | undefined;
+
+ beforeEach(() => {
+ fieldsKeysCalled = false;
+ aiKeysParams = undefined;
+
+ server.use(
+ rest.get(FIELDS_KEYS_URL, (_, res, ctx) => {
+ fieldsKeysCalled = true;
+ return res(ctx.status(200), ctx.json(keysResponse('http.route')));
+ }),
+ rest.get(AI_KEYS_URL, (req, res, ctx) => {
+ aiKeysParams = req.url.searchParams;
+ return res(ctx.status(200), ctx.json(keysResponse('gen_ai.request.model')));
+ }),
+ );
+ });
+
+ function renderOtherFilters(signal: SignalType): void {
+ render(
+ <OtherFilters
+ signal={signal}
+ inputValue=""
+ addedFilters={[]}
+ setAddedFilters={jest.fn()}
+ />,
+ );
+ }
+
+ it('reads AI observability keys from their own endpoint', async () => {
+ renderOtherFilters(SignalType.AI_OBSERVABILITY);
+
+ await expect(
+ screen.findByText('gen_ai.request.model'),
+ ).resolves.toBeInTheDocument();
+ expect(fieldsKeysCalled).toBe(false);
+ });
+
+ it('does not narrow the AI keys by fieldContext', async () => {
+ renderOtherFilters(SignalType.AI_OBSERVABILITY);
+
+ // A `trace` context would return only the computed per-trace aggregates,
+ // which cannot be filtered on.
+ await waitFor(() => expect(aiKeysParams).toBeDefined());
+ expect(aiKeysParams?.get('fieldContext')).toBeNull();
+ });
+
+ it('keeps other signals on the signal-wide keys endpoint', async () => {
+ renderOtherFilters(SignalType.TRACES);
+
+ await expect(screen.findByText('http.route')).resolves.toBeInTheDocument();
+ await waitFor(() => expect(aiKeysParams).toBeUndefined());
+ });
+});
diff --git a/frontend/src/components/QuickFilters/QuickFiltersSettings/constants.ts b/frontend/src/components/QuickFilters/QuickFiltersSettings/constants.ts
index 4f357fd2e6..4232dfd96b 100644
--- a/frontend/src/components/QuickFilters/QuickFiltersSettings/constants.ts
+++ b/frontend/src/components/QuickFilters/QuickFiltersSettings/constants.ts
@@ -7,4 +7,5 @@ export const SIGNAL_DATA_SOURCE_MAP = {
[SignalType.EXCEPTIONS]: DataSource.TRACES,
[SignalType.API_MONITORING]: DataSource.TRACES,
[SignalType.METER_EXPLORER]: DataSource.METRICS,
+ [SignalType.AI_OBSERVABILITY]: DataSource.TRACES,
};
diff --git a/frontend/src/components/QuickFilters/hooks/__tests__/useActiveQueryIndex.test.ts b/frontend/src/components/QuickFilters/hooks/__tests__/useActiveQueryIndex.test.ts
new file mode 100644
index 0000000000..f6d3510954
--- /dev/null
+++ b/frontend/src/components/QuickFilters/hooks/__tests__/useActiveQueryIndex.test.ts
@@ -0,0 +1,81 @@
+import { renderHook } from '@testing-library/react';
+import { PANEL_TYPES } from 'constants/queryBuilder';
+import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
+
+import { QuickFiltersSource } from '../../types';
+import useActiveQueryIndex from '../useActiveQueryIndex';
+
+jest.mock('hooks/queryBuilder/useQueryBuilder', () => ({
+ useQueryBuilder: jest.fn(),
+}));
+
+const LAST_USED_QUERY = 2;
+
+function mockQueryBuilder(panelType: PANEL_TYPES): void {
+ (useQueryBuilder as jest.Mock).mockReturnValue({
+ lastUsedQuery: LAST_USED_QUERY,
+ panelType,
+ });
+}
+
+describe('useActiveQueryIndex', () => {
+ describe('AI observability builds a single query in the row-level views', () => {
+ it.each([PANEL_TYPES.LIST, PANEL_TYPES.TRACE])(
+ 'drives the first query in %s',
+ (panelType) => {
+ mockQueryBuilder(panelType);
+
+ const { result } = renderHook(() =>
+ useActiveQueryIndex(QuickFiltersSource.AI_OBSERVABILITY),
+ );
+
+ expect(result.current).toBe(0);
+ },
+ );
+
+ it.each([PANEL_TYPES.TIME_SERIES, PANEL_TYPES.TABLE])(
+ 'follows the last used query in %s',
+ (panelType) => {
+ mockQueryBuilder(panelType);
+
+ const { result } = renderHook(() =>
+ useActiveQueryIndex(QuickFiltersSource.AI_OBSERVABILITY),
+ );
+
+ expect(result.current).toBe(LAST_USED_QUERY);
+ },
+ );
+ });
+
+ describe('other sources are unchanged', () => {
+ it('lets the traces explorer track the last used query in list view', () => {
+ mockQueryBuilder(PANEL_TYPES.LIST);
+
+ const { result } = renderHook(() =>
+ useActiveQueryIndex(QuickFiltersSource.TRACES_EXPLORER),
+ );
+
+ expect(result.current).toBe(LAST_USED_QUERY);
+ });
+
+ it('pins single-query sources to the first query in list view', () => {
+ mockQueryBuilder(PANEL_TYPES.LIST);
+
+ const { result } = renderHook(() =>
+ useActiveQueryIndex(QuickFiltersSource.INFRA_MONITORING),
+ );
+
+ expect(result.current).toBe(0);
+ });
+
+ it('tracks the last used query outside list view', () => {
+ mockQueryBuilder(PANEL_TYPES.TIME_SERIES);
+
+ const { result } = renderHook(() =>
+ useActiveQueryIndex(QuickFiltersSource.LOGS_EXPLORER),
+ );
+
+ expect(result.current).toBe(LAST_USED_QUERY);
+ });
+ });
+});
diff --git a/frontend/src/components/QuickFilters/FilterRenderers/Checkbox/useActiveQueryIndex.ts b/frontend/src/components/QuickFilters/hooks/useActiveQueryIndex.ts
similarity index 71%
rename from frontend/src/components/QuickFilters/FilterRenderers/Checkbox/useActiveQueryIndex.ts
rename to frontend/src/components/QuickFilters/hooks/useActiveQueryIndex.ts
index 9f9a9392da..dd581bb6a8 100644
--- a/frontend/src/components/QuickFilters/FilterRenderers/Checkbox/useActiveQueryIndex.ts
+++ b/frontend/src/components/QuickFilters/hooks/useActiveQueryIndex.ts
@@ -15,13 +15,21 @@ function useActiveQueryIndex(source: QuickFiltersSource): number {
const isListView = panelType === PANEL_TYPES.LIST;
return useMemo(() => {
+ // AI observability builds a single query in the row-level views, so its
+ // filters always drive the first one there.
+ if (source === QuickFiltersSource.AI_OBSERVABILITY) {
+ return isListView || panelType === PANEL_TYPES.TRACE
+ ? 0
+ : lastUsedQuery || 0;
+ }
+
if (isListView) {
return source === QuickFiltersSource.TRACES_EXPLORER
? lastUsedQuery || 0
: 0;
}
return lastUsedQuery || 0;
- }, [isListView, source, lastUsedQuery]);
+ }, [isListView, panelType, source, lastUsedQuery]);
}
export default useActiveQueryIndex;
diff --git a/frontend/src/components/QuickFilters/types.ts b/frontend/src/components/QuickFilters/types.ts
index 200c71f88f..b5022ab248 100644
--- a/frontend/src/components/QuickFilters/types.ts
+++ b/frontend/src/components/QuickFilters/types.ts
@@ -24,6 +24,7 @@ export enum SignalType {
API_MONITORING = 'api_monitoring',
EXCEPTIONS = 'exceptions',
METER_EXPLORER = 'meter',
+ AI_OBSERVABILITY = 'ai_observability',
}
/**
@@ -69,6 +70,7 @@ export enum QuickFiltersSource {
API_MONITORING = 'api-monitoring',
EXCEPTIONS = 'exceptions',
METER_EXPLORER = 'meter',
+ AI_OBSERVABILITY = 'ai-observability',
}
/**
diff --git a/frontend/src/constants/reactQueryKeys.ts b/frontend/src/constants/reactQueryKeys.ts
index c311d42a42..1503cb8461 100644
--- a/frontend/src/constants/reactQueryKeys.ts
+++ b/frontend/src/constants/reactQueryKeys.ts
@@ -109,6 +109,9 @@ export const REACT_QUERY_KEY = {
// Field Keys Suggestion Query Keys
FIELD_KEYS_SUGGESTION: 'FIELD_KEYS_SUGGESTION',
+ // Field Values Suggestion Query Keys
+ FIELD_VALUES_SUGGESTION: 'FIELD_VALUES_SUGGESTION',
+
// AI Assistant Query Keys
AI_ASSISTANT_EMPTY_STATE_CHIPS: 'AI_ASSISTANT_EMPTY_STATE_CHIPS',
} as const;
diff --git a/frontend/src/container/LLMObservability/Explorer/Explorer.tsx b/frontend/src/container/LLMObservability/Explorer/Explorer.tsx
index a97042f054..3ae78b4fea 100644
--- a/frontend/src/container/LLMObservability/Explorer/Explorer.tsx
+++ b/frontend/src/container/LLMObservability/Explorer/Explorer.tsx
@@ -8,6 +8,7 @@ import cx from 'classnames';
import ExplorerCard from 'components/ExplorerCard/ExplorerCard';
import QueryCancelledPlaceholder from 'components/QueryCancelledPlaceholder';
import QuickFilters from 'components/QuickFilters/QuickFilters';
+import { useSignalFieldApis } from 'components/QuickFilters/hooks/useSignalFieldApis';
import { QuickFiltersSource, SignalType } from 'components/QuickFilters/types';
import WarningPopover from 'components/WarningPopover/WarningPopover';
import { initialQueryAIWithType } from 'constants/queryBuilder';
@@ -94,6 +95,13 @@ function Explorer(): JSX.Element {
const [warning, setWarning] = useState<Warning | undefined>();
const [isOpen, setOpen] = useState<boolean>(true);
+ const { startUnixMilli, endUnixMilli } = useSignalFieldApis();
+ // existingQuery is left unset so related values auto-extract from the current query
+ const quickFiltersFieldApis = useMemo(
+ () => ({ startUnixMilli, endUnixMilli }),
+ [startUnixMilli, endUnixMilli],
+ );
+
const defaultQuery = useMemo(
(): Query =>
updateAllQueriesOperators(
@@ -187,8 +195,9 @@ function Explorer(): JSX.Element {
<Card className="filter" hidden={!isOpen}>
<QuickFilters
className="qf-traces-explorer"
- source={QuickFiltersSource.TRACES_EXPLORER}
- signal={SignalType.TRACES}
+ source={QuickFiltersSource.AI_OBSERVABILITY}
+ signal={SignalType.AI_OBSERVABILITY}
+ useFieldApis={quickFiltersFieldApis}
handleFilterVisibilityChange={(): void => {
setOpen(!isOpen);
}}
diff --git a/frontend/src/hooks/querySuggestions/useFieldValuesSuggestion.ts b/frontend/src/hooks/querySuggestions/useFieldValuesSuggestion.ts
new file mode 100644
index 0000000000..c56d38dafc
--- /dev/null
+++ b/frontend/src/hooks/querySuggestions/useFieldValuesSuggestion.ts
@@ -0,0 +1,61 @@
+import {
+ QueryKey,
+ useQuery,
+ UseQueryOptions,
+ UseQueryResult,
+} from 'react-query';
+import { ErrorType } from 'api/generatedAPIInstance';
+import {
+ RenderErrorResponseDTO,
+ TelemetrytypesTelemetryFieldValuesDTO,
+} from 'api/generated/services/sigNoz.schemas';
+import { getFieldValueSuggestions } from 'api/querySuggestions/getFieldValueSuggestions';
+import { FIELD_API_CACHE_TIME } from 'constants/queryCacheTime';
+import { REACT_QUERY_KEY } from 'constants/reactQueryKeys';
+import {
+ FieldValuesConfig,
+ FieldValuesResponse,
+} from 'api/querySuggestions/types';
+import { BuilderQueryType } from 'types/api/v5/queryRange';
+
+export type FieldValuesQueryOptions = UseQueryOptions<
+ FieldValuesResponse,
+ ErrorType<RenderErrorResponseDTO>,
+ TelemetrytypesTelemetryFieldValuesDTO
+> & { queryKey: QueryKey };
+
+const EMPTY_FIELD_VALUES: TelemetrytypesTelemetryFieldValuesDTO = {};
+
+export const toFieldValues = (
+ res: FieldValuesResponse | undefined,
+): TelemetrytypesTelemetryFieldValuesDTO =>
+ res?.data?.values ?? EMPTY_FIELD_VALUES;
+
+export const getFieldValuesQueryOptions = (
+ fieldValuesConfig: FieldValuesConfig,
+ builderQueryType?: BuilderQueryType,
+): FieldValuesQueryOptions => ({
+ queryKey: [
+ REACT_QUERY_KEY.FIELD_VALUES_SUGGESTION,
+ builderQueryType,
+ fieldValuesConfig,
+ ],
+ queryFn: ({ signal }): Promise<FieldValuesResponse> =>
+ getFieldValueSuggestions(fieldValuesConfig, builderQueryType, signal),
+ select: toFieldValues,
+ cacheTime: FIELD_API_CACHE_TIME,
+ keepPreviousData: true,
+});
+
+export const useFieldValuesSuggestion = (
+ fieldValuesConfig: FieldValuesConfig,
+ builderQueryType?: BuilderQueryType,
+ options?: Pick<FieldValuesQueryOptions, 'enabled'>,
+): UseQueryResult<
+ TelemetrytypesTelemetryFieldValuesDTO,
+ ErrorType<RenderErrorResponseDTO>
+> =>
+ useQuery({
+ ...getFieldValuesQueryOptions(fieldValuesConfig, builderQueryType),
+ ...options,
+ });