Skip to content

Commit 970e3c7

Browse files
feat(assisted-query): Pass metric context and use dedicated feature flag
Pass the exact metric name, type, and unit to the Seer agent via the options dict so it can skip the metric.name discovery step. Gate the metrics AI search bar behind gen-ai-explore-metrics-search instead of the shared gen-ai-search-agent-translate flag. - Add options prop to AskSeerPollingComboBox and useAskSeerPolling - Wire traceMetric from Filter through to MetricsTabSeerComboBox - Send metric_context in both polling and mutation API requests - Switch feature flag checks to gen-ai-explore-metrics-search Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f09ab0b commit 970e3c7

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

static/app/components/searchQueryBuilder/askSeerCombobox/askSeerPollingComboBox.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ interface AskSeerPollingComboBoxProps<T extends QueryTokensProps> extends Omit<
111111
* If provided, the component will fall back to AskSeerComboBox on start failure.
112112
*/
113113
fallbackMutationOptions?: UseMutationOptions<any, Error, string>;
114+
/**
115+
* Optional key-value options to pass to the search agent start endpoint.
116+
* Used for strategy-specific context (e.g., metric name/type/unit for Metrics).
117+
*/
118+
options?: Record<string, unknown>;
114119
/**
115120
* Transform the final response from the polling API to the expected format.
116121
* This allows customization of how the response is converted to query items.
@@ -126,6 +131,7 @@ export function AskSeerPollingComboBox<T extends QueryTokensProps>({
126131
strategy,
127132
transformResponse,
128133
fallbackMutationOptions,
134+
options: extraOptions,
129135
...props
130136
}: AskSeerPollingComboBoxProps<T>) {
131137
const buttonRef = useRef<HTMLButtonElement>(null);
@@ -167,6 +173,7 @@ export function AskSeerPollingComboBox<T extends QueryTokensProps>({
167173
} = useAskSeerPolling<T>({
168174
projectIds,
169175
strategy,
176+
options: extraOptions,
170177
onError: error => {
171178
addErrorMessage(t('Failed to process AI query: %(error)s', {error: error.message}));
172179
trackAnalytics('ai_query.error', {

static/app/components/searchQueryBuilder/askSeerCombobox/useAskSeerPolling.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ interface UseAskSeerPollingOptions<T extends QueryTokensProps> {
6060
strategy: string;
6161
onError?: (error: Error) => void;
6262
onSuccess?: (result: T) => void;
63+
options?: Record<string, unknown>;
6364
}
6465

6566
/**
@@ -117,6 +118,7 @@ export function useAskSeerPolling<T extends QueryTokensProps>(
117118
natural_language_query: query,
118119
project_ids: options.projectIds,
119120
strategy: options.strategy,
121+
...(options.options ? {options: options.options} : {}),
120122
},
121123
}
122124
)) as AskSeerStartResponse;

static/app/views/explore/metrics/metricToolbar/filter.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,18 @@ interface FilterProps {
3636
}
3737

3838
interface MetricsSearchBarProps {
39+
traceMetric: TraceMetric;
3940
tracesItemSearchQueryBuilderProps: TraceItemSearchQueryBuilderProps;
4041
}
4142

42-
function MetricsSearchBar({tracesItemSearchQueryBuilderProps}: MetricsSearchBarProps) {
43+
function MetricsSearchBar({
44+
tracesItemSearchQueryBuilderProps,
45+
traceMetric,
46+
}: MetricsSearchBarProps) {
4347
const {displayAskSeer} = useSearchQueryBuilder();
4448

4549
if (displayAskSeer) {
46-
return <MetricsTabSeerComboBox />;
50+
return <MetricsTabSeerComboBox traceMetric={traceMetric} />;
4751
}
4852

4953
return <TraceItemSearchQueryBuilder {...tracesItemSearchQueryBuilderProps} />;
@@ -55,7 +59,7 @@ export function Filter({traceMetric}: FilterProps) {
5559
const organization = useOrganization();
5660

5761
const hasTranslateEndpoint = organization.features.includes(
58-
'gen-ai-search-agent-translate'
62+
'gen-ai-explore-metrics-search'
5963
);
6064

6165
const traceMetricFilter = createTraceMetricFilter(traceMetric);
@@ -172,6 +176,7 @@ export function Filter({traceMetric}: FilterProps) {
172176
>
173177
<MetricsSearchBar
174178
tracesItemSearchQueryBuilderProps={tracesItemSearchQueryBuilderProps}
179+
traceMetric={traceMetric}
175180
/>
176181
</SearchQueryBuilderProvider>
177182
);

static/app/views/explore/metrics/metricsTabSeerComboBox.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {useLocation} from 'sentry/utils/useLocation';
1616
import {useNavigate} from 'sentry/utils/useNavigate';
1717
import {useOrganization} from 'sentry/utils/useOrganization';
1818
import {useProjects} from 'sentry/utils/useProjects';
19+
import type {TraceMetric} from 'sentry/views/explore/metrics/metricQuery';
1920
import type {WritableAggregateField} from 'sentry/views/explore/queryParams/aggregateField';
2021
import {
2122
useQueryParams,
@@ -26,6 +27,10 @@ import {Mode} from 'sentry/views/explore/queryParams/mode';
2627
import {isVisualize} from 'sentry/views/explore/queryParams/visualize';
2728
import type {ChartType} from 'sentry/views/insights/common/components/chart';
2829

30+
interface MetricsTabSeerComboBoxProps {
31+
traceMetric: TraceMetric;
32+
}
33+
2934
interface Visualization {
3035
chartType: ChartType;
3136
yAxes: string[];
@@ -59,7 +64,7 @@ interface MetricsAskSeerTranslateResponse {
5964
unsupported_reason: string | null;
6065
}
6166

62-
export function MetricsTabSeerComboBox() {
67+
export function MetricsTabSeerComboBox({traceMetric}: MetricsTabSeerComboBoxProps) {
6368
const navigate = useNavigate();
6469
const location = useLocation();
6570
const {projects} = useProjects();
@@ -125,6 +130,13 @@ export function MetricsTabSeerComboBox() {
125130
project_ids: selectedProjects,
126131
strategy: 'Metrics',
127132
user_email: user?.email,
133+
options: {
134+
metric_context: {
135+
metric_name: traceMetric.name,
136+
metric_type: traceMetric.type,
137+
metric_unit: traceMetric.unit ?? 'none',
138+
},
139+
},
128140
},
129141
});
130142

@@ -281,7 +293,7 @@ export function MetricsTabSeerComboBox() {
281293
);
282294

283295
const usePollingEndpoint = organization.features.includes(
284-
'gen-ai-search-agent-translate'
296+
'gen-ai-explore-metrics-search'
285297
);
286298

287299
// Get selected project IDs for the polling variant
@@ -345,6 +357,13 @@ export function MetricsTabSeerComboBox() {
345357
initialQuery={initialSeerQuery}
346358
projectIds={selectedProjectIds}
347359
strategy="Metrics"
360+
options={{
361+
metric_context: {
362+
metric_name: traceMetric.name,
363+
metric_type: traceMetric.type,
364+
metric_unit: traceMetric.unit ?? 'none',
365+
},
366+
}}
348367
applySeerSearchQuery={applySeerSearchQuery}
349368
transformResponse={transformResponse}
350369
analyticsSource="metrics"

0 commit comments

Comments
 (0)