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(drilldown): carry the field type through a breakout (#12309)
Abhi kumar9aeb9a82409b
diff --git a/frontend/src/components/FieldsSelector/OtherFields.tsx b/frontend/src/components/FieldsSelector/OtherFields.tsxindex cf3624657b..d30a91b9da 100644--- a/frontend/src/components/FieldsSelector/OtherFields.tsx+++ b/frontend/src/components/FieldsSelector/OtherFields.tsx@@ -8,7 +8,6 @@ import { buildCompositeKey } from 'container/OptionsMenu/utils';import { useGetQueryKeySuggestions } from 'hooks/querySuggestions/useGetQueryKeySuggestions';import {FieldContext,- FieldDataType,SignalType,TelemetryFieldKey,} from 'types/api/v5/queryRange';@@ -55,7 +54,7 @@ function OtherFields({key: buildCompositeKey(attr.name, attr.fieldContext as string),signal: attr.signal as SignalType,fieldContext: attr.fieldContext as FieldContext,- fieldDataType: attr.fieldDataType as FieldDataType,+ fieldDataType: attr.fieldDataType,}),);const addedIds = new Set(diff --git a/frontend/src/components/QueryBuilderV2/QueryV2/QueryAggregation/QueryAggregationSelect.tsx b/frontend/src/components/QueryBuilderV2/QueryV2/QueryAggregation/QueryAggregationSelect.tsxindex 2e6074cf92..9b3119a3cd 100644--- a/frontend/src/components/QueryBuilderV2/QueryV2/QueryAggregation/QueryAggregationSelect.tsx+++ b/frontend/src/components/QueryBuilderV2/QueryV2/QueryAggregation/QueryAggregationSelect.tsx@@ -25,12 +25,12 @@ import CodeMirror, {} from '@uiw/react-codemirror';import { Button, Popover, Tooltip } from 'antd';import { getKeySuggestions } from 'api/querySuggestions/getKeySuggestions';-import { QUERY_BUILDER_KEY_TYPES } from 'constants/antlrQueryConstants';import { QueryBuilderKeys } from 'constants/queryBuilder';import { tracesAggregateOperatorOptions } from 'constants/queryBuilderOperators';import { useIsDarkMode } from 'hooks/useDarkMode';import { Info, TriangleAlert } from '@signozhq/icons';import { IBuilderQuery } from 'types/api/queryBuilder/queryBuilderData';+import { FieldDataType } from 'types/api/v5/queryRange';import { TracesAggregatorOperator } from 'types/common/queryBuilder';import { useQueryBuilderV2Context } from '../../QueryBuilderV2Context';@@ -323,16 +323,16 @@ function QueryAggregationSelect({TracesAggregatorOperator.RATE,];- const fieldDataType =+ const fieldDataType: FieldDataType | undefined =functionContextForFetch &&operatorsWithoutDataType.includes(functionContextForFetch)? undefined- : QUERY_BUILDER_KEY_TYPES.NUMBER;+ : 'number';return getKeySuggestions({signal: queryData.dataSource,searchText: '',- fieldDataType: fieldDataType as QUERY_BUILDER_KEY_TYPES,+ fieldDataType,});},{diff --git a/frontend/src/container/OptionsMenu/useOptionsMenu.ts b/frontend/src/container/OptionsMenu/useOptionsMenu.tsindex 12f890b6b6..45b668650a 100644--- a/frontend/src/container/OptionsMenu/useOptionsMenu.ts+++ b/frontend/src/container/OptionsMenu/useOptionsMenu.ts@@ -113,7 +113,7 @@ const useOptionsMenu = ({(suggestion) => ({name: suggestion.name,signal: suggestion.signal as SignalType,- fieldDataType: suggestion.fieldDataType as FieldDataType,+ fieldDataType: suggestion.fieldDataType,fieldContext: suggestion.fieldContext as FieldContext,}),);@@ -192,7 +192,7 @@ const useOptionsMenu = ({name: e.name,signal: e.signal as SignalType,fieldContext: e.fieldContext as FieldContext,- fieldDataType: e.fieldDataType as FieldDataType,+ fieldDataType: e.fieldDataType,}));}if (dataSource === DataSource.TRACES) {diff --git a/frontend/src/container/QueryTable/Drilldown/BreakoutOptions.tsx b/frontend/src/container/QueryTable/Drilldown/BreakoutOptions.tsxindex 8e428c69f1..b706e37570 100644--- a/frontend/src/container/QueryTable/Drilldown/BreakoutOptions.tsx+++ b/frontend/src/container/QueryTable/Drilldown/BreakoutOptions.tsx@@ -4,11 +4,11 @@ import { Input } from '@signozhq/ui/input';import { Skeleton } from 'antd';import { getKeySuggestions } from 'api/querySuggestions/getKeySuggestions';import OverlayScrollbar from 'components/OverlayScrollbar/OverlayScrollbar';-import { QUERY_BUILDER_KEY_TYPES } from 'constants/antlrQueryConstants';import useDebounce from 'hooks/useDebounce';import { ContextMenu } from 'periscope/components/ContextMenu';import { BaseAutocompleteData } from 'types/api/queryBuilder/queryAutocompleteResponse';import { MetricAggregation } from 'types/api/v5/queryRange';+import { fieldDataTypeToDataType } from 'utils/fieldDataType';import { BreakoutOptionsProps } from './contextConfig';import { BreakoutAttributeType } from './types';@@ -80,7 +80,7 @@ function BreakoutOptions({keyArray.forEach((keyData) => {transformedOptions.push({key: keyData.name,- dataType: keyData.fieldDataType as QUERY_BUILDER_KEY_TYPES,+ dataType: fieldDataTypeToDataType(keyData.fieldDataType),type: '',});});diff --git a/frontend/src/container/QueryTable/Drilldown/__tests__/Breakout.test.tsx b/frontend/src/container/QueryTable/Drilldown/__tests__/Breakout.test.tsxindex 2013fc9d2e..a2fa4e47c9 100644--- a/frontend/src/container/QueryTable/Drilldown/__tests__/Breakout.test.tsx+++ b/frontend/src/container/QueryTable/Drilldown/__tests__/Breakout.test.tsx@@ -238,6 +238,10 @@ describe('TableDrilldown Breakout Functionality', () => {expect(aggregateQueryData.groupBy).toHaveLength(1);expect(aggregateQueryData.groupBy[0].key).toBe('deployment.environment');+ // The picked field's type travels with it — dropping it leaves the breakout query+ // untyped, so a drilldown on its result can't tell a number from a string.+ expect(aggregateQueryData.groupBy[0].dataType).toBe('string');+// Verify that orderBy has been cleared (as per getBreakoutQuery logic)expect(aggregateQueryData.orderBy).toStrictEqual([]);diff --git a/frontend/src/container/QueryTable/Drilldown/tableDrilldownUtils.tsx b/frontend/src/container/QueryTable/Drilldown/tableDrilldownUtils.tsxindex 129d3fb0e0..2eee79ce70 100644--- a/frontend/src/container/QueryTable/Drilldown/tableDrilldownUtils.tsx+++ b/frontend/src/container/QueryTable/Drilldown/tableDrilldownUtils.tsx@@ -1,6 +1,5 @@import { OPERATORS, PANEL_TYPES } from 'constants/queryBuilder';import cloneDeep from 'lodash-es/cloneDeep';-import { BaseAutocompleteData } from 'types/api/queryBuilder/queryAutocompleteResponse';import { IBuilderQuery, Query } from 'types/api/queryBuilder/queryBuilderData';import { addFilterToSelectedQuery, FilterData } from './drilldownUtils';@@ -89,7 +88,11 @@ export const getBreakoutQuery = (.filter((item: IBuilderQuery) => item.queryName === aggregateData.queryName).map((item: IBuilderQuery) => ({...item,- groupBy: [{ key: groupBy.key, type: groupBy.type } as BaseAutocompleteData],+ // The picked field's type travels with it: dropped, the breakout query goes out+ // untyped and a drilldown on its result can't tell a number from a string.+ groupBy: [+ { key: groupBy.key, dataType: groupBy.dataType, type: groupBy.type },+ ],orderBy: [],legend: item.legend && groupBy.key ? `{{${groupBy.key}}}` : '',}));diff --git a/frontend/src/container/QueryTable/Drilldown/types.ts b/frontend/src/container/QueryTable/Drilldown/types.tsindex c0c1e1a21b..db187f8039 100644--- a/frontend/src/container/QueryTable/Drilldown/types.ts+++ b/frontend/src/container/QueryTable/Drilldown/types.ts@@ -1,6 +1,8 @@import { ReactNode } from 'react';-import { QUERY_BUILDER_KEY_TYPES } from 'constants/antlrQueryConstants';-import { BaseAutocompleteData } from 'types/api/queryBuilder/queryAutocompleteResponse';+import {+ BaseAutocompleteData,+ DataTypes,+} from 'types/api/queryBuilder/queryAutocompleteResponse';import { IBuilderQuery } from 'types/api/queryBuilder/queryBuilderData';export type ContextMenuItem = ReactNode;@@ -31,7 +33,8 @@ export interface AggregateContextMenuConfig {export interface BreakoutAttributeType {key: string;- dataType: QUERY_BUILDER_KEY_TYPES;+ /** The picked field's type, in the vocabulary the group-by it becomes is read with. */+ dataType: DataTypes;type: string;}diff --git a/frontend/src/types/api/querySuggestions/types.ts b/frontend/src/types/api/querySuggestions/types.tsindex d9b7575d61..b5b16c0727 100644--- a/frontend/src/types/api/querySuggestions/types.ts+++ b/frontend/src/types/api/querySuggestions/types.ts@@ -1,4 +1,4 @@-import { QUERY_BUILDER_KEY_TYPES } from 'constants/antlrQueryConstants';+import { FieldDataType } from 'types/api/v5/queryRange';export interface QueryKeyDataSuggestionsProps {label: string;@@ -7,7 +7,12 @@ export interface QueryKeyDataSuggestionsProps {apply?: string;detail?: string;fieldContext?: 'resource' | 'scope' | 'attribute' | 'span';- fieldDataType?: QUERY_BUILDER_KEY_TYPES;+ /**+ * The field's type as the API reports it. Was declared as the antlr key-type enum+ * (`string | number | boolean`), which the endpoint never returns — every consumer cast it+ * back to `FieldDataType`.+ */+ fieldDataType?: FieldDataType;name: string;signal: 'traces' | 'logs' | 'metrics';}@@ -26,7 +31,7 @@ export interface QueryKeyRequestProps {signal: 'traces' | 'logs' | 'metrics';searchText: string;fieldContext?: 'resource' | 'scope' | 'attribute' | 'span';- fieldDataType?: QUERY_BUILDER_KEY_TYPES;+ fieldDataType?: FieldDataType;metricName?: string;metricNamespace?: string;signalSource?: 'meter' | '';diff --git a/frontend/src/utils/__tests__/fieldDataType.test.ts b/frontend/src/utils/__tests__/fieldDataType.test.tsnew file mode 100644index 0000000000..8966b25c49--- /dev/null+++ b/frontend/src/utils/__tests__/fieldDataType.test.ts@@ -0,0 +1,34 @@+import { DataTypes } from 'types/api/queryBuilder/queryAutocompleteResponse';+import type { FieldDataType } from 'types/api/v5/queryRange';++import { fieldDataTypeToDataType } from '../fieldDataType';++describe('fieldDataTypeToDataType', () => {+ it('maps the reported numeric spellings onto the query-builder numerics', () => {+ expect(fieldDataTypeToDataType('number')).toBe(DataTypes.Float64);+ expect(fieldDataTypeToDataType('int64')).toBe(DataTypes.Int64);+ expect(fieldDataTypeToDataType('float64')).toBe(DataTypes.Float64);+ });++ it('maps the list spellings onto the array types', () => {+ expect(fieldDataTypeToDataType('[]string')).toBe(DataTypes.ArrayString);+ expect(fieldDataTypeToDataType('[]bool')).toBe(DataTypes.ArrayBool);+ expect(fieldDataTypeToDataType('[]int64')).toBe(DataTypes.ArrayInt64);+ expect(fieldDataTypeToDataType('[]float64')).toBe(DataTypes.ArrayFloat64);+ expect(fieldDataTypeToDataType('[]number')).toBe(DataTypes.ArrayFloat64);+ });++ it('passes through the spellings the two vocabularies share', () => {+ expect(fieldDataTypeToDataType('string')).toBe(DataTypes.String);+ expect(fieldDataTypeToDataType('bool')).toBe(DataTypes.bool);+ });++ it('returns EMPTY for empty, missing and not-yet-known types', () => {+ expect(fieldDataTypeToDataType('')).toBe(DataTypes.EMPTY);+ expect(fieldDataTypeToDataType(undefined)).toBe(DataTypes.EMPTY);+ // The backend can store `[]json` / `[]dynamic`, which the API union doesn't list.+ expect(fieldDataTypeToDataType('[]json' as FieldDataType)).toBe(+ DataTypes.EMPTY,+ );+ });+});diff --git a/frontend/src/utils/fieldDataType.ts b/frontend/src/utils/fieldDataType.tsnew file mode 100644index 0000000000..7bfd1371aa--- /dev/null+++ b/frontend/src/utils/fieldDataType.ts@@ -0,0 +1,31 @@+import { DataTypes } from 'types/api/queryBuilder/queryAutocompleteResponse';+import type { FieldDataType } from 'types/api/v5/queryRange';++/**+ * The field metadata APIs and the query builder spell field types differently: the metadata+ * collapses the numerics to `number` and writes lists as `[]string`, while `DataTypes` — which+ * keys the operator and attribute-value lookups — uses `float64` and `array(string)`. Convert+ * where a reported type becomes a query-builder one, so those lookups can't miss.+ */+const TO_DATA_TYPE: Record<FieldDataType, DataTypes> = {+ '': DataTypes.EMPTY,+ string: DataTypes.String,+ bool: DataTypes.bool,+ int64: DataTypes.Int64,+ float64: DataTypes.Float64,+ number: DataTypes.Float64,+ '[]string': DataTypes.ArrayString,+ '[]bool': DataTypes.ArrayBool,+ '[]int64': DataTypes.ArrayInt64,+ '[]float64': DataTypes.ArrayFloat64,+ '[]number': DataTypes.ArrayFloat64,+};++/**+ * Exhaustive over `FieldDataType`, so a type added to the API union fails to compile here+ * rather than going missing at runtime. The fallback is for a spelling the union doesn't know+ * yet — the backend can store `[]json` and `[]dynamic` — not for any of the cases above.+ */+export const fieldDataTypeToDataType = (+ fieldDataType?: FieldDataType,+): DataTypes => TO_DATA_TYPE[fieldDataType ?? ''] ?? DataTypes.EMPTY;