Repository navigation
feat(search): trace-level AND scope across spans (#3004) #3154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
05d85c4
66a65e1
b3cfe62
847b8fc
08c2269
77a6f8f
16a92a3
79dca70
916499e
74d2a6c
9cc2dad
eccbf4d
6682dac
320f9b1
e2c5d86
69c5d65
a6cb1fa
a80c4a2
989fbd9
6c9dccc
63f1116
a9fedab
afdabd9
86a8027
90c2442
9d2df50
66e5410
a48e323
8aa2c35
5f4ddba
06711f4
0fd3c03
d0cf978
ea67a50
c7ac108
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| --- | ||
| '@hyperdx/common-utils': minor | ||
| '@hyperdx/app': minor | ||
| --- | ||
|
|
||
| Add a trace-level scope for search so multi-predicate `AND` can match across the | ||
| spans of a trace, not only within a single span. | ||
|
|
||
| Search gains a **Span | Trace** scope control. **Span** (the default) is | ||
| unchanged: every predicate must hold in the same span. **Trace** matches traces | ||
| where the predicates are satisfied by different spans of the same trace. Under | ||
| the hood each predicate is rewritten into its own | ||
| `TraceId IN (SELECT TraceId FROM <source> WHERE <predicate> AND <time>)` and the | ||
| parts are `AND`-composed, with the time filter pushed into every subquery. | ||
|
|
||
| Trace scope is fail-closed: it is offered only for trace sources that expose a | ||
| trace-id expression, and it resets to Span when the source is switched, so | ||
| existing searches and saved queries are unaffected. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import mongoose from 'mongoose'; | ||
|
|
||
| import { SavedSearch } from '@/models/savedSearch'; | ||
|
|
||
| // Mongoose strict mode silently drops paths the schema does not declare, so | ||
| // these build documents in memory (no DB) to pin that searchScope survives. | ||
| describe('SavedSearch model searchScope', () => { | ||
| const base = { | ||
| team: new mongoose.Types.ObjectId(), | ||
| source: new mongoose.Types.ObjectId(), | ||
| name: 'trace search', | ||
| where: 'ServiceName:frontend', | ||
| }; | ||
|
|
||
| it('keeps a Trace scope', () => { | ||
| const doc = new SavedSearch({ ...base, searchScope: 'trace' }); | ||
| expect(doc.searchScope).toBe('trace'); | ||
| expect(doc.validateSync()).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('leaves the scope unset for legacy saved searches', () => { | ||
| const doc = new SavedSearch(base); | ||
| expect(doc.searchScope).toBeUndefined(); | ||
| expect(doc.validateSync()).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('rejects an unknown scope', () => { | ||
| const doc = new SavedSearch({ ...base, searchScope: 'session' }); | ||
| expect(doc.validateSync()?.errors.searchScope).toBeDefined(); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ import { | |
| } from '@hyperdx/common-utils/dist/clickhouse'; | ||
| import { tcFromSource } from '@hyperdx/common-utils/dist/core/metadata'; | ||
| import { buildSearchChartConfig } from '@hyperdx/common-utils/dist/core/searchChartConfig'; | ||
| import { resolveTraceScope } from '@hyperdx/common-utils/dist/core/traceScope'; | ||
| import { | ||
| aliasMapToWithClauses, | ||
| getReferencedWithClauses, | ||
|
|
@@ -48,12 +49,15 @@ import { | |
| Filter, | ||
| isPersistableUserId, | ||
| isTraceSource, | ||
| SearchScope, | ||
| SearchScopeSchema, | ||
| SourceKind, | ||
| TSource, | ||
| } from '@hyperdx/common-utils/dist/types'; | ||
| import { | ||
| ActionIcon, | ||
| Anchor, | ||
| Badge, | ||
| Box, | ||
| Breadcrumbs, | ||
| Button, | ||
|
|
@@ -144,6 +148,12 @@ import { | |
| useUpdateSavedSearch, | ||
| } from '@/savedSearch'; | ||
| import { useSearchPageFilterState } from '@/searchFilters'; | ||
| import { | ||
| resolveSearchScope, | ||
| SEARCH_SCOPE_PARAM, | ||
| TRACE_SCOPE_LABEL, | ||
| TRACE_ZERO_EMPTY_DESCRIPTION, | ||
| } from '@/searchScope'; | ||
| import { getEventBody, useSource, useSources } from '@/source'; | ||
| import { | ||
| parseRelativeTimeQuery, | ||
|
|
@@ -213,11 +223,12 @@ const LIVE_TAIL_REFRESH_FREQUENCY_OPTIONS = [ | |
| const DEFAULT_REFRESH_FREQUENCY = 10000; | ||
|
|
||
| const ALLOWED_SOURCE_KINDS = [SourceKind.Log, SourceKind.Trace]; | ||
| const SearchConfigSchema = z.object({ | ||
| export const SearchConfigSchema = z.object({ | ||
| select: z.string(), | ||
| source: z.string(), | ||
| where: z.string(), | ||
| whereLanguage: z.enum(['sql', 'lucene']), | ||
| searchScope: SearchScopeSchema.default('span'), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 major — Search scope isn't saved with saved searches, and a stale
Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 major — Saved searches and alerts silently drop trace scope
Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond |
||
| orderBy: z.string(), | ||
| filters: z.array( | ||
| z.union([ | ||
|
|
@@ -583,6 +594,7 @@ function SaveSearchModalComponent({ | |
| source: searchedConfig.source ?? '', | ||
| orderBy: searchedConfig.orderBy ?? '', | ||
| filters: searchedConfig.filters ?? [], | ||
| searchScope: resolveSearchScope(searchedConfig.searchScope), | ||
| tags: tags, | ||
| }, | ||
| { | ||
|
|
@@ -611,6 +623,7 @@ function SaveSearchModalComponent({ | |
| source: searchedConfig.source ?? '', | ||
| orderBy: searchedConfig.orderBy ?? '', | ||
| filters: searchedConfig.filters ?? [], | ||
| searchScope: resolveSearchScope(searchedConfig.searchScope), | ||
| tags: tags, | ||
| }); | ||
|
|
||
|
|
@@ -833,7 +846,15 @@ function useLiveUpdate({ | |
| * and returns a chart config. | ||
| */ | ||
| function useSearchedConfigToChartConfig( | ||
| { select, source, whereLanguage, where, filters, orderBy }: SearchConfig, | ||
| { | ||
| select, | ||
| source, | ||
| whereLanguage, | ||
| searchScope, | ||
| where, | ||
| filters, | ||
| orderBy, | ||
| }: SearchConfig, | ||
| defaultSearchConfig?: Partial<SearchConfig>, | ||
| ) { | ||
| const { data: sourceObj, isLoading } = useSource({ | ||
|
|
@@ -850,6 +871,7 @@ function useSearchedConfigToChartConfig( | |
| const chartConfig = buildSearchChartConfig(sourceObj, { | ||
| where, | ||
| whereLanguage, | ||
| searchScope: resolveSearchScope(searchScope), | ||
| filters, | ||
| select: select || defaultSearchConfig?.select || null, | ||
| displayType: DisplayType.Search, | ||
|
|
@@ -870,6 +892,7 @@ function useSearchedConfigToChartConfig( | |
| defaultSearchConfig, | ||
| where, | ||
| whereLanguage, | ||
| searchScope, | ||
| defaultOrderBy, | ||
| orderBy, | ||
| ]); | ||
|
|
@@ -951,6 +974,7 @@ const queryStateMap = { | |
| where: parseAsStringEncoded, | ||
| select: parseAsStringEncoded, | ||
| whereLanguage: parseAsStringEnum<'sql' | 'lucene'>(['sql', 'lucene']), | ||
| searchScope: SEARCH_SCOPE_PARAM, | ||
| filters: parseAsJsonEncoded<Filter[]>(), | ||
| orderBy: parseAsStringEncoded, | ||
| }; | ||
|
|
@@ -1268,6 +1292,7 @@ function DBSearchPageContent() { | |
| where: searchedConfig.where || '', | ||
| whereLanguage: | ||
| searchedConfig.whereLanguage ?? getStoredLanguage() ?? 'lucene', | ||
| searchScope: resolveSearchScope(searchedConfig.searchScope), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new Include the resolved scope in that reset. |
||
| // When source is provided in the URL or in the saved search, don't | ||
| // fallback to the default source. | ||
| source: | ||
|
|
@@ -1354,6 +1379,7 @@ function DBSearchPageContent() { | |
| source: searchedConfig?.source ?? undefined, | ||
| filters: searchedConfig?.filters ?? [], | ||
| orderBy: searchedConfig?.orderBy ?? '', | ||
| searchScope: resolveSearchScope(searchedConfig?.searchScope), | ||
| }); | ||
| } | ||
| }, [searchedConfig, reset, prevSearched]); | ||
|
|
@@ -1384,6 +1410,7 @@ function DBSearchPageContent() { | |
| whereLanguage: savedSearch.whereLanguage as 'sql' | 'lucene', | ||
| filters: savedSearch.filters ?? [], | ||
| orderBy: savedSearch.orderBy ?? '', | ||
| searchScope: resolveSearchScope(savedSearch.searchScope), | ||
| }); | ||
| return; | ||
| } | ||
|
|
@@ -1454,11 +1481,20 @@ function DBSearchPageContent() { | |
| onSearch(displayedTimeInputValue); | ||
| } | ||
| handleSubmit( | ||
| ({ select, where, whereLanguage, source, filters, orderBy }) => { | ||
| ({ | ||
| select, | ||
| where, | ||
| whereLanguage, | ||
| searchScope, | ||
| source, | ||
| filters, | ||
| orderBy, | ||
| }) => { | ||
| setSearchedConfig({ | ||
| select, | ||
| where, | ||
| whereLanguage, | ||
| searchScope, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Save and restore the scope, and pass it to the alert query builder. |
||
| source, | ||
| filters, | ||
| orderBy, | ||
|
|
@@ -1751,6 +1787,7 @@ function DBSearchPageContent() { | |
| where: searchedConfig.where ?? '', | ||
| whereLanguage: | ||
| searchedConfig.whereLanguage ?? getStoredLanguage() ?? 'lucene', | ||
| searchScope: resolveSearchScope(searchedConfig.searchScope), | ||
| filters: searchedConfig.filters ?? [], | ||
| orderBy: searchedConfig.orderBy ?? '', | ||
| }), | ||
|
|
@@ -1761,6 +1798,7 @@ function DBSearchPageContent() { | |
| searchedConfig.select, | ||
| searchedConfig.where, | ||
| searchedConfig.whereLanguage, | ||
| searchedConfig.searchScope, | ||
| ], | ||
| ); | ||
|
|
||
|
|
@@ -1775,8 +1813,24 @@ function DBSearchPageContent() { | |
| : null; | ||
| return { hasQueryError, queryError }; | ||
| }, [_queryErrors]); | ||
| const executedSearchScope = resolveSearchScope(searchedConfig.searchScope); | ||
| // Reflect what the query actually did: trace scope only takes effect on a | ||
| // trace source that exposes a trace-id expression. The badge/copy key off | ||
| // this so they never claim Trace when the rewrite silently fell back to span | ||
| // (e.g. scope left at trace while the sidebar was collapsed on a log source). | ||
| const traceScopeActive = | ||
| executedSearchScope === 'trace' && | ||
| searchedSource != null && | ||
| resolveTraceScope(searchedSource).applicable; | ||
| const inputWhere = useWatch({ name: 'where', control }); | ||
| const inputWhereLanguage = useWatch({ name: 'whereLanguage', control }); | ||
| const inputSearchScope = useWatch({ name: 'searchScope', control }); | ||
| const onSearchScopeChange = useCallback( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 minor — Clicking Trace/Span does not re-run the search, unlike the other sidebar controls
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond |
||
| (scope: SearchScope) => { | ||
| setValue('searchScope', scope, { shouldDirty: true }); | ||
| }, | ||
| [setValue], | ||
| ); | ||
| // query suggestion for 'where' if error | ||
| const whereSuggestions = useSqlSuggestions({ | ||
| input: inputWhere, | ||
|
|
@@ -2950,6 +3004,8 @@ function DBSearchPageContent() { | |
| displayedColumns={displayedColumns} | ||
| onCollapse={isCompact ? undefined : collapseFilters} | ||
| fill={isCompact} | ||
| searchScope={resolveSearchScope(inputSearchScope)} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 minor — The scope control only exists inside the filter sidebar, so with the sidebar collapsed users can't see or change an active Trace scope
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond |
||
| onSearchScopeChange={onSearchScopeChange} | ||
| {...searchFilters} | ||
| /> | ||
| </ErrorBoundary> | ||
|
|
@@ -3105,6 +3161,16 @@ function DBSearchPageContent() { | |
| } | ||
| /> | ||
| <Group gap="sm" align="center"> | ||
| {traceScopeActive && ( | ||
| <Badge | ||
| variant="light" | ||
| color="blue" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 minor — Scope badge uses the raw Mantine palette ( The semantic-design-tokens convention says not to use raw Mantine color props for app chrome, and the Click UI convention prefers click-ui Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond |
||
| radius="sm" | ||
| aria-label={TRACE_SCOPE_LABEL} | ||
| > | ||
| {TRACE_SCOPE_LABEL} | ||
| </Badge> | ||
| )} | ||
| {traceChartsSource != null && ( | ||
| <SegmentedControl | ||
| size="xs" | ||
|
|
@@ -3348,6 +3414,11 @@ function DBSearchPageContent() { | |
| selectionResetKey={selectionResetKey} | ||
| onSelectedRowsChange={onSelectedRowsChange} | ||
| onResolvedColumnsChange={onResolvedColumnsChange} | ||
| noResultsMessage={ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 major —
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 critical —
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 critical —
Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond |
||
| traceScopeActive | ||
| ? TRACE_ZERO_EMPTY_DESCRIPTION | ||
| : undefined | ||
| } | ||
|
Comment on lines
+3417
to
+3421
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new trace-specific zero-result path passes custom text into the table's inline no-results branch. The repository requires all empty and no-data states to use the shared Context Used: CLAUDE.md (source) Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||
| /> | ||
| )} | ||
| </Box> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
External saved search drops scope
Low Severity
toExternalJSONand the MCP save payload never includesearchScope, even though the Mongoose model andSavedSearchSchemanow persist it. MCP get/save and any othertoExternalJSONconsumer omit the field, so a Trace saved search round-trips as Span through those APIs.Reviewed by Cursor Bugbot for commit c7ac108. Configure here.