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: donot close suggestion on typing period (#11490)
Tushar Vats218f8269dd1f
diff --git a/frontend/src/utils/__tests__/queryContextUtils.test.ts b/frontend/src/utils/__tests__/queryContextUtils.test.tsindex be1dd1db09..24e77cf8eb 100644--- a/frontend/src/utils/__tests__/queryContextUtils.test.ts+++ b/frontend/src/utils/__tests__/queryContextUtils.test.ts@@ -3,6 +3,7 @@ import {extractQueryPairs,getCurrentQueryPair,getCurrentValueIndexAtCursor,+ getQueryContextAtCursor,} from '../queryContextUtils';describe('extractQueryPairs', () => {@@ -608,3 +609,42 @@ describe('getCurrentQueryPair', () => {expect(result).toStrictEqual(queryPairs[0]);});});++describe('getQueryContextAtCursor - trailing dot in key/value', () => {+ // A token ending with "." (e.g. "service.") is lexed as FREETEXT rather than+ // KEY, which previously collapsed the context to "nothing" and made the+ // suggestion dropdown render empty (appearing closed). These cases lock in+ // that a partial key/value still resolves to the correct context.+ it('keeps key context while typing a key that ends with a dot', () => {+ ['service.', 'k8s.', 'attribute.', 'k8s.pod.'].forEach((q) => {+ const ctx = getQueryContextAtCursor(q, q.length);+ expect(ctx.isInKey).toBe(true);+ expect(ctx.isInValue).toBe(false);+ expect(ctx.isInOperator).toBe(false);+ expect(ctx.keyToken).toBe(q);+ });+ });++ it('treats a new key after a conjunction as key context', () => {+ const q = 'a = b AND k8s.';+ const ctx = getQueryContextAtCursor(q, q.length);+ expect(ctx.isInKey).toBe(true);+ expect(ctx.isInValue).toBe(false);+ });++ it('keeps value context while typing a value that ends with a dot', () => {+ const q = 'service.name = foo.';+ const ctx = getQueryContextAtCursor(q, q.length);+ expect(ctx.isInValue).toBe(true);+ expect(ctx.isInKey).toBe(false);+ expect(ctx.keyToken).toBe('service.name');+ expect(ctx.operatorToken).toBe('=');+ });++ it('still resolves a complete dotted key to key context', () => {+ const q = 'k8s.namespace';+ const ctx = getQueryContextAtCursor(q, q.length);+ expect(ctx.isInKey).toBe(true);+ expect(ctx.keyToken).toBe('k8s.namespace');+ });+});diff --git a/frontend/src/utils/queryContextUtils.ts b/frontend/src/utils/queryContextUtils.tsindex 7479e80033..5555631f61 100644--- a/frontend/src/utils/queryContextUtils.ts+++ b/frontend/src/utils/queryContextUtils.ts@@ -766,6 +766,58 @@ export function getQueryContextAtCursor(}}+ // A token that ends with a '.' (e.g. "service." or "k8s.pod.") is lexed as+ // FREETEXT, not KEY, because the KEY rule requires a character after the dot.+ // While the user is mid-typing such a key/value the token stays FREETEXT, which+ // is otherwise unclassified and would collapse the context to "nothing" — making+ // the suggestion dropdown render empty (and appear closed). Classify the partial+ // token by the slot it occupies so suggestions keep flowing until the next+ // character turns it back into a valid KEY token.+ const partialToken = exactToken ?? lastTokenBeforeCursor;+ if (+ partialToken &&+ partialToken.channel === 0 &&+ partialToken.type === FilterQueryLexer.FREETEXT+ ) {+ // Closest meaningful token before the partial one determines the slot:+ // right after an operator we are typing a value, otherwise a key.+ const prevMeaningful =+ allTokens+ .filter(+ (t) =>+ t.channel === 0 &&+ t.type !== FilterQueryLexer.EOF &&+ t.stop < partialToken.start,+ )+ .pop() || null;++ const prevContext = prevMeaningful+ ? determineTokenContext(prevMeaningful, input)+ : null;+ const isValuePosition = !!prevContext?.isInOperator;++ return {+ tokenType: partialToken.type,+ text: partialToken.text,+ start: partialToken.start,+ stop: partialToken.stop,+ currentToken: partialToken.text,+ isInKey: !isValuePosition,+ isInNegation: false,+ isInOperator: false,+ isInValue: isValuePosition,+ isInFunction: false,+ isInConjunction: false,+ isInParenthesis: false,+ isInBracketList: false,+ keyToken: isValuePosition ? currentPair?.key || '' : partialToken.text,+ operatorToken: isValuePosition ? currentPair?.operator || '' : undefined,+ valueToken: isValuePosition ? partialToken.text : undefined,+ queryPairs,+ currentPair,+ };+ }+// If we don't have tokens yet, return default contextif (!previousToken && !nextToken && !exactToken && !lastTokenBeforeCursor) {return {