mirror of
https://github.com/SigNoz/signoz.git
synced 2026-11-16 05:11:07 +00:00
Compare commits
3 Commits
feat/input
...
keystone-p
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2edb9c1bfb | ||
|
|
f7220ae79c | ||
|
|
e010c4fa03 |
@@ -3,6 +3,7 @@ import { AxiosError, AxiosHeaders } from 'axios';
|
||||
|
||||
import {
|
||||
hasNoAppFrames,
|
||||
isInjectedScriptError,
|
||||
isExpectedRequestFailure,
|
||||
isExternalIntegrationError,
|
||||
SENTRY_IGNORE_ERRORS,
|
||||
@@ -129,6 +130,24 @@ describe('hasNoAppFrames', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('isInjectedScriptError', () => {
|
||||
it('drops an error thrown from eval code behind the Sentry wrapper', () => {
|
||||
expect(
|
||||
isInjectedScriptError(eventWithFrames(APP_BUNDLE, '<anonymous>')),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('keeps an error thrown from our bundle', () => {
|
||||
expect(
|
||||
isInjectedScriptError(eventWithFrames('<anonymous>', APP_BUNDLE)),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('keeps an error without a stack trace', () => {
|
||||
expect(isInjectedScriptError({ type: undefined })).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('SENTRY_IGNORE_ERRORS', () => {
|
||||
it('ignores the bundled PostHog recorder load failure', () => {
|
||||
expect(
|
||||
|
||||
@@ -42,6 +42,7 @@ import {
|
||||
hasNoAppFrames,
|
||||
isExpectedRequestFailure,
|
||||
isExternalIntegrationError,
|
||||
isInjectedScriptError,
|
||||
SENTRY_IGNORE_ERRORS,
|
||||
} from './sentryFilters';
|
||||
|
||||
@@ -355,7 +356,7 @@ function App(): JSX.Element {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isExternalIntegrationError(event)) {
|
||||
if (isExternalIntegrationError(event) || isInjectedScriptError(event)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,15 @@ export function hasNoAppFrames(event: ErrorEvent): boolean {
|
||||
);
|
||||
}
|
||||
|
||||
// The throwing frame is the last one. Sentry's own timer wrapper is bundled
|
||||
// with the app, so only the top frame shows the code came from an eval.
|
||||
export function isInjectedScriptError(event: ErrorEvent): boolean {
|
||||
return (event.exception?.values ?? []).some((exception) => {
|
||||
const frames = exception.stacktrace?.frames ?? [];
|
||||
return frames[frames.length - 1]?.filename === '<anonymous>';
|
||||
});
|
||||
}
|
||||
|
||||
// PostHog's lazy recorder, the Pylon widget and Appcues.
|
||||
const EXTERNAL_SCRIPT_URLS = [
|
||||
/^https?:\/\/[^/]+\.posthog\.com\//,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/* eslint-disable import/no-extraneous-dependencies */
|
||||
/* eslint-disable sonarjs/cognitive-complexity */
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { useQuery } from 'react-query';
|
||||
import {
|
||||
autocompletion,
|
||||
closeCompletion,
|
||||
@@ -24,14 +23,16 @@ import CodeMirror, {
|
||||
ViewUpdate,
|
||||
} from '@uiw/react-codemirror';
|
||||
import { Button, Popover, Tooltip } from 'antd';
|
||||
import { getKeySuggestions } from 'api/querySuggestions/getKeySuggestions';
|
||||
import { QueryBuilderKeys } from 'constants/queryBuilder';
|
||||
import { TelemetrytypesFieldDataTypeDTO } from 'api/generated/services/sigNoz.schemas';
|
||||
import { tracesAggregateOperatorOptions } from 'constants/queryBuilderOperators';
|
||||
import { useFieldKeysSuggestion } from 'hooks/querySuggestions/useFieldKeysSuggestion';
|
||||
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 {
|
||||
DATA_SOURCE_TO_SIGNAL,
|
||||
TracesAggregatorOperator,
|
||||
} from 'types/common/queryBuilder';
|
||||
|
||||
import { useQueryBuilderV2Context } from '../../QueryBuilderV2Context';
|
||||
|
||||
@@ -41,6 +42,12 @@ const chipDecoration = Decoration.mark({
|
||||
class: 'chip-decorator',
|
||||
});
|
||||
|
||||
const OPERATORS_WITHOUT_DATA_TYPE: string[] = [
|
||||
TracesAggregatorOperator.COUNT,
|
||||
TracesAggregatorOperator.COUNT_DISTINCT,
|
||||
TracesAggregatorOperator.RATE,
|
||||
];
|
||||
|
||||
const operatorArgMeta: Record<
|
||||
string,
|
||||
{ acceptsArgs: boolean; multiple: boolean }
|
||||
@@ -310,31 +317,19 @@ function QueryAggregationSelect({
|
||||
// Find function context for fetching suggestions
|
||||
const functionContextForFetch = getFunctionContextAtCursor(input, cursorPos);
|
||||
|
||||
const { data: aggregateAttributeData, isLoading: isLoadingFields } = useQuery(
|
||||
[
|
||||
QueryBuilderKeys.GET_AGGREGATE_ATTRIBUTE,
|
||||
functionContextForFetch,
|
||||
queryData.dataSource,
|
||||
],
|
||||
() => {
|
||||
const operatorsWithoutDataType: (string | undefined)[] = [
|
||||
TracesAggregatorOperator.COUNT,
|
||||
TracesAggregatorOperator.COUNT_DISTINCT,
|
||||
TracesAggregatorOperator.RATE,
|
||||
];
|
||||
|
||||
const fieldDataType: FieldDataType | undefined =
|
||||
functionContextForFetch &&
|
||||
operatorsWithoutDataType.includes(functionContextForFetch)
|
||||
? undefined
|
||||
: 'number';
|
||||
|
||||
return getKeySuggestions({
|
||||
signal: queryData.dataSource,
|
||||
searchText: '',
|
||||
fieldDataType,
|
||||
});
|
||||
const numericKeysOnly = !(
|
||||
functionContextForFetch &&
|
||||
OPERATORS_WITHOUT_DATA_TYPE.includes(functionContextForFetch)
|
||||
);
|
||||
const { data: fieldKeys, isLoading: isLoadingFields } = useFieldKeysSuggestion(
|
||||
{
|
||||
signal: DATA_SOURCE_TO_SIGNAL[queryData.dataSource],
|
||||
searchText: '',
|
||||
fieldDataType: numericKeysOnly
|
||||
? TelemetrytypesFieldDataTypeDTO.number
|
||||
: undefined,
|
||||
},
|
||||
queryData.builderQueryType,
|
||||
{
|
||||
enabled:
|
||||
!!functionContextForFetch &&
|
||||
@@ -427,48 +422,42 @@ function QueryAggregationSelect({
|
||||
}),
|
||||
);
|
||||
|
||||
// Memoize field suggestions from API (no filtering here)
|
||||
// Memoize field suggestions from API (no search filtering here)
|
||||
const fieldSuggestions = useMemo(
|
||||
() =>
|
||||
Object.keys(aggregateAttributeData?.data.data.keys || {}).flatMap((key) => {
|
||||
const attributeKeys = aggregateAttributeData?.data.data.keys[key];
|
||||
if (!attributeKeys) {
|
||||
return [];
|
||||
}
|
||||
(fieldKeys ?? []).map((key) => ({
|
||||
// The backend reads trace.-prefixed columns as per-trace aggregates.
|
||||
label: key.fieldContext === 'trace' ? `trace.${key.name}` : key.name,
|
||||
type: 'variable',
|
||||
info: key.fieldDataType,
|
||||
apply: (
|
||||
view: EditorView,
|
||||
completion: Completion,
|
||||
from: number,
|
||||
to: number,
|
||||
): void => {
|
||||
const text = view.state.sliceDoc(0, from);
|
||||
const funcName = getFunctionContextAtCursor(text, from);
|
||||
const multiple = funcName ? operatorArgMeta[funcName]?.multiple : false;
|
||||
|
||||
return attributeKeys.map((attributeKey) => ({
|
||||
label: attributeKey.name,
|
||||
type: 'variable',
|
||||
info: attributeKey.fieldDataType,
|
||||
apply: (
|
||||
view: EditorView,
|
||||
completion: Completion,
|
||||
from: number,
|
||||
to: number,
|
||||
): void => {
|
||||
const text = view.state.sliceDoc(0, from);
|
||||
const funcName = getFunctionContextAtCursor(text, from);
|
||||
const multiple = funcName ? operatorArgMeta[funcName]?.multiple : false;
|
||||
// Insert the selected key followed by either a comma or closing parenthesis
|
||||
const insertText = multiple
|
||||
? `${completion.label},`
|
||||
: `${completion.label}) `;
|
||||
const cursorPos = from + insertText.length; // Use insertText.length instead of hardcoded values
|
||||
|
||||
// Insert the selected key followed by either a comma or closing parenthesis
|
||||
const insertText = multiple
|
||||
? `${completion.label},`
|
||||
: `${completion.label}) `;
|
||||
const cursorPos = from + insertText.length; // Use insertText.length instead of hardcoded values
|
||||
view.dispatch({
|
||||
changes: { from, to, insert: insertText },
|
||||
selection: { anchor: cursorPos },
|
||||
});
|
||||
|
||||
view.dispatch({
|
||||
changes: { from, to, insert: insertText },
|
||||
selection: { anchor: cursorPos },
|
||||
});
|
||||
|
||||
// Trigger next suggestions after a small delay
|
||||
setTimeout(() => {
|
||||
safeStartCompletion();
|
||||
}, 50);
|
||||
},
|
||||
}));
|
||||
}) || [],
|
||||
[aggregateAttributeData, safeStartCompletion],
|
||||
// Trigger next suggestions after a small delay
|
||||
setTimeout(() => {
|
||||
safeStartCompletion();
|
||||
}, 50);
|
||||
},
|
||||
})),
|
||||
[fieldKeys, safeStartCompletion],
|
||||
);
|
||||
|
||||
const aggregatorAutocomplete = useMemo(
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
import {
|
||||
GetAIObservabilityFieldsKeys200,
|
||||
GetFieldsKeys200,
|
||||
TelemetrytypesFieldContextDTO,
|
||||
TelemetrytypesFieldDataTypeDTO,
|
||||
TelemetrytypesSignalDTO,
|
||||
TelemetrytypesTelemetryFieldKeyDTO,
|
||||
} from 'api/generated/services/sigNoz.schemas';
|
||||
import { ENVIRONMENT } from 'constants/env';
|
||||
import { initialQueriesMap } from 'constants/queryBuilder';
|
||||
import { rest, server } from 'mocks-server/server';
|
||||
import { render, screen, userEvent, waitFor } from 'tests/test-utils';
|
||||
import type { IBuilderQuery } from 'types/api/queryBuilder/queryBuilderData';
|
||||
|
||||
import { QueryBuilderV2Provider } from '../../QueryBuilderV2Context';
|
||||
import QueryAggregationSelect from '../QueryAggregation/QueryAggregationSelect';
|
||||
import { mockCodeMirrorDomApis } from './codemirrorDomMocks';
|
||||
|
||||
const EDITOR_TEST_ID = 'query-aggregation-editor';
|
||||
// CodeMirror's suggestion popup is slow to open under a parallel jest run.
|
||||
const SUGGESTIONS_TIMEOUT_MS = 5000;
|
||||
const TEST_TIMEOUT_MS = 15000;
|
||||
|
||||
const fieldKey = (
|
||||
name: string,
|
||||
fieldContext: TelemetrytypesFieldContextDTO,
|
||||
fieldDataType: TelemetrytypesFieldDataTypeDTO,
|
||||
): TelemetrytypesTelemetryFieldKeyDTO => ({
|
||||
name,
|
||||
fieldContext,
|
||||
fieldDataType,
|
||||
signal: TelemetrytypesSignalDTO.traces,
|
||||
});
|
||||
|
||||
const durationNano = fieldKey(
|
||||
'duration_nano',
|
||||
TelemetrytypesFieldContextDTO.span,
|
||||
TelemetrytypesFieldDataTypeDTO.float64,
|
||||
);
|
||||
|
||||
const serviceName = fieldKey(
|
||||
'service.name',
|
||||
TelemetrytypesFieldContextDTO.resource,
|
||||
TelemetrytypesFieldDataTypeDTO.string,
|
||||
);
|
||||
|
||||
const totalTokens = fieldKey(
|
||||
'total_tokens',
|
||||
TelemetrytypesFieldContextDTO.trace,
|
||||
TelemetrytypesFieldDataTypeDTO.float64,
|
||||
);
|
||||
|
||||
const aiKeysResponse = (
|
||||
keys: TelemetrytypesTelemetryFieldKeyDTO[],
|
||||
): GetAIObservabilityFieldsKeys200 => ({
|
||||
status: 'success',
|
||||
data: {
|
||||
complete: true,
|
||||
keys: Object.fromEntries(keys.map((key) => [key.name, [key]])),
|
||||
},
|
||||
});
|
||||
|
||||
// Assumes the AI endpoint's number filter also returns the float64 trace aggregates.
|
||||
const aiKeysFor = (
|
||||
params: URLSearchParams,
|
||||
): TelemetrytypesTelemetryFieldKeyDTO[] =>
|
||||
params.get('fieldDataType') === TelemetrytypesFieldDataTypeDTO.number
|
||||
? [durationNano, totalTokens]
|
||||
: [durationNano, serviceName, totalTokens];
|
||||
|
||||
const keysResponse: GetFieldsKeys200 = {
|
||||
status: 'success',
|
||||
data: { complete: true, keys: { duration_nano: [durationNano] } },
|
||||
};
|
||||
|
||||
const aiQuery: IBuilderQuery = {
|
||||
...(initialQueriesMap.traces.builder.queryData[0] as IBuilderQuery),
|
||||
builderQueryType: 'builder_ai_query',
|
||||
aggregations: [],
|
||||
};
|
||||
|
||||
const aiKeysRequests: URLSearchParams[] = [];
|
||||
const keysRequests: URLSearchParams[] = [];
|
||||
|
||||
beforeAll(() => {
|
||||
mockCodeMirrorDomApis();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
aiKeysRequests.length = 0;
|
||||
keysRequests.length = 0;
|
||||
server.use(
|
||||
rest.get(
|
||||
`${ENVIRONMENT.baseURL}/api/v1/ai_observability/fields/keys`,
|
||||
(req, res, ctx) => {
|
||||
aiKeysRequests.push(req.url.searchParams);
|
||||
return res(
|
||||
ctx.status(200),
|
||||
ctx.json(aiKeysResponse(aiKeysFor(req.url.searchParams))),
|
||||
);
|
||||
},
|
||||
),
|
||||
rest.get(`${ENVIRONMENT.baseURL}/api/v1/fields/keys`, (req, res, ctx) => {
|
||||
keysRequests.push(req.url.searchParams);
|
||||
return res(ctx.status(200), ctx.json(keysResponse));
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
async function enterAggregation(text: string): Promise<void> {
|
||||
const user = userEvent.setup({ pointerEventsCheck: 0 });
|
||||
render(
|
||||
<QueryBuilderV2Provider>
|
||||
<QueryAggregationSelect queryData={aiQuery} />
|
||||
</QueryBuilderV2Provider>,
|
||||
);
|
||||
|
||||
const content = (
|
||||
await screen.findByTestId(EDITOR_TEST_ID)
|
||||
).querySelector<HTMLElement>('.cm-content');
|
||||
if (!content) {
|
||||
throw new Error('CodeMirror content element not rendered');
|
||||
}
|
||||
await user.click(content);
|
||||
// Typed keys drop under load: a re-render's dispatch discards DOM input CodeMirror hasn't read yet.
|
||||
await user.paste(text);
|
||||
await user.keyboard('{Control>} {/Control}');
|
||||
}
|
||||
|
||||
function suggestionLabels(): string[] {
|
||||
return Array.from(
|
||||
screen.getByTestId(EDITOR_TEST_ID).querySelectorAll('.cm-completionLabel'),
|
||||
(label) => label.textContent ?? '',
|
||||
).sort();
|
||||
}
|
||||
|
||||
describe('QueryAggregationSelect field suggestions for an AI query', () => {
|
||||
it.each([
|
||||
{
|
||||
aggregation: 'avg(',
|
||||
fieldDataType: TelemetrytypesFieldDataTypeDTO.number,
|
||||
labels: ['duration_nano', 'trace.total_tokens'],
|
||||
},
|
||||
{
|
||||
aggregation: 'count_distinct(',
|
||||
fieldDataType: null,
|
||||
labels: ['duration_nano', 'service.name', 'trace.total_tokens'],
|
||||
},
|
||||
])(
|
||||
'suggests keys from the AI keys endpoint, with trace aggregates as trace.<name>, for $aggregation',
|
||||
async ({ aggregation, fieldDataType, labels }) => {
|
||||
await enterAggregation(aggregation);
|
||||
|
||||
await waitFor(() => expect(suggestionLabels()).toStrictEqual(labels), {
|
||||
timeout: SUGGESTIONS_TIMEOUT_MS,
|
||||
});
|
||||
expect(keysRequests).toHaveLength(0);
|
||||
expect(
|
||||
aiKeysRequests.map((params) => ({
|
||||
signal: params.get('signal'),
|
||||
fieldDataType: params.get('fieldDataType'),
|
||||
fieldContext: params.get('fieldContext'),
|
||||
})),
|
||||
).toStrictEqual([{ signal: 'traces', fieldDataType, fieldContext: null }]);
|
||||
},
|
||||
TEST_TIMEOUT_MS,
|
||||
);
|
||||
});
|
||||
6
tests/uv.lock
generated
6
tests/uv.lock
generated
@@ -86,11 +86,11 @@ wheels = [
|
||||
|
||||
[[package]]
|
||||
name = "certifi"
|
||||
version = "2026.7.22"
|
||||
version = "2026.10.19"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/a3/c2/24167ea9858356b47a87a50d39908bfdb72ceeefe0041586e704e5376b3a/certifi-2026.7.22.tar.gz", hash = "sha256:741e2c3b351ddf169a738da9f2c048608ff7f2c5cc02f1ebc6b118bb090d5d55", size = 138112, upload-time = "2026-07-22T03:35:12.644Z" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/a6/bd/1436c50cc46699de0230fbaacc1d1de7bfec413176099949e9d5112e88f2/certifi-2026.10.19.tar.gz", hash = "sha256:035c1e85572b141bf1c3a3eff0e33a8eb74917522f2559075ff8d2fea780a1ae", size = 137598, upload-time = "2026-10-20T02:24:16.604Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/0b/a7/71ac2cff56fec219ed242bb11b8efb69fcc4bec75db06fb7bfe35de520e6/certifi-2026.7.22-py3-none-any.whl", hash = "sha256:62f22742b58a1a33014a2b6b706588a8d7e2a88ae7bd1a6ebe8c992928483775", size = 136983, upload-time = "2026-07-22T03:35:11.276Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/c4/51/29046e48f693c54e5b7412216d447a1d8362c9653148d98c02cdf65fa733/certifi-2026.10.19-py3-none-any.whl", hash = "sha256:42d35340cc5b9ba78e818ddbff0c5b1c2b779de448a340fd1b989f5fa8670e1b", size = 136464, upload-time = "2026-10-20T02:24:15.072Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
Reference in New Issue
Block a user