Skip to content

Commit 96a591b

Browse files
DominikB2014andrewshie-sentry
authored andcommitted
ref(insights): pass in search to http sample panel charts (#92503)
Same as #92337 but for web vitals sample charts Additionally change to the above: 1. made some changes so that the the `yAxis` is named in a way is correctly picked up by the widget when generating the explore url. 2. Add a `groupBy` prop to the insight chart to propagate that to explore.
1 parent 2bba3fc commit 96a591b

File tree

5 files changed

+37
-5
lines changed

5 files changed

+37
-5
lines changed

static/app/views/insights/common/components/insightsTimeSeriesWidget.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import type {DiscoverSeries} from 'sentry/views/insights/common/queries/useDisco
4040
import {convertSeriesToTimeseries} from 'sentry/views/insights/common/utils/convertSeriesToTimeseries';
4141
import {useInsightsEap} from 'sentry/views/insights/common/utils/useEap';
4242
import {INGESTION_DELAY} from 'sentry/views/insights/settings';
43+
import {type SpanFields} from 'sentry/views/insights/types';
4344

4445
export interface InsightsTimeSeriesWidgetProps
4546
extends WidgetTitleProps,
@@ -50,6 +51,7 @@ export interface InsightsTimeSeriesWidgetProps
5051
visualizationType: 'line' | 'area' | 'bar';
5152
aliases?: Record<string, string>;
5253
description?: React.ReactNode;
54+
groupBy?: SpanFields[];
5355
height?: string | number;
5456
interactiveTitle?: () => React.ReactNode;
5557
legendSelection?: LegendSelection | undefined;
@@ -191,6 +193,7 @@ export function InsightsTimeSeriesWidget(props: InsightsTimeSeriesWidgetProps) {
191193
<OpenInExploreButton
192194
chartType={chartType}
193195
yAxes={yAxisArray}
196+
groupBy={props.groupBy}
194197
title={props.title}
195198
search={props.search}
196199
/>

static/app/views/insights/common/components/openInExploreButton.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ import useOrganization from 'sentry/utils/useOrganization';
55
import {Mode} from 'sentry/views/explore/contexts/pageParamsContext/mode';
66
import {getExploreUrl} from 'sentry/views/explore/utils';
77
import type {ChartType} from 'sentry/views/insights/common/components/chart';
8+
import {type SpanFields} from 'sentry/views/insights/types';
89

910
type Props = {
1011
chartType: ChartType;
1112
yAxes: string[];
13+
groupBy?: SpanFields[];
1214
search?: MutableSearch;
1315
title?: string;
1416
};
1517

16-
export function OpenInExploreButton({yAxes, title, search, chartType}: Props) {
18+
export function OpenInExploreButton({yAxes, title, search, chartType, groupBy}: Props) {
1719
const organization = useOrganization();
1820

1921
const url = getExploreUrl({
@@ -28,7 +30,7 @@ export function OpenInExploreButton({yAxes, title, search, chartType}: Props) {
2830
title: title ?? yAxes[0],
2931
query: search?.formatString(),
3032
sort: undefined,
31-
groupBy: undefined,
33+
groupBy,
3234
});
3335

3436
return (

static/app/views/insights/http/components/charts/responseCodeCountChart.tsx

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,45 @@
11
import {t} from 'sentry/locale';
2+
import {type MutableSearch} from 'sentry/utils/tokenizeSearch';
23
// TODO(release-drawer): Only used in httpSamplesPanel, should be easy to move data fetching in here
34
// eslint-disable-next-line no-restricted-imports
45
import {InsightsLineChartWidget} from 'sentry/views/insights/common/components/insightsLineChartWidget';
56
import type {DiscoverSeries} from 'sentry/views/insights/common/queries/useDiscoverSeries';
7+
import {type SpanFields} from 'sentry/views/insights/types';
68

79
interface Props {
10+
groupBy: SpanFields[];
811
isLoading: boolean;
12+
search: MutableSearch;
913
series: DiscoverSeries[];
1014
error?: Error | null;
1115
}
1216

13-
export function ResponseCodeCountChart({series, isLoading, error}: Props) {
17+
export function ResponseCodeCountChart({
18+
series,
19+
isLoading,
20+
error,
21+
search,
22+
groupBy,
23+
}: Props) {
1424
// TODO: Temporary hack. `DiscoverSeries` meta field and the series name don't
1525
// match. This is annoying to work around, and will become irrelevant soon
1626
// enough. For now, just specify the correct meta for these series since
1727
// they're known and simple
28+
29+
const yAxis = 'count()';
30+
31+
const fieldAliases: Record<string, string> = {};
1832
const seriesWithMeta: DiscoverSeries[] = series.map(discoverSeries => {
33+
const newSeriesName = `${yAxis} ${discoverSeries.seriesName}`;
34+
35+
fieldAliases[newSeriesName] = discoverSeries.seriesName;
36+
1937
const transformedSeries: DiscoverSeries = {
2038
...discoverSeries,
39+
seriesName: newSeriesName,
2140
meta: {
2241
fields: {
23-
[discoverSeries.seriesName]: 'integer',
42+
[newSeriesName]: 'integer',
2443
},
2544
units: {},
2645
},
@@ -31,10 +50,13 @@ export function ResponseCodeCountChart({series, isLoading, error}: Props) {
3150

3251
return (
3352
<InsightsLineChartWidget
53+
search={search}
54+
groupBy={groupBy}
3455
title={t('Top 5 Response Codes')}
3556
series={seriesWithMeta}
3657
isLoading={isLoading}
3758
error={error ?? null}
59+
aliases={fieldAliases}
3860
/>
3961
);
4062
}

static/app/views/insights/http/components/httpSamplesPanel.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import decodeResponseCodeClass from 'sentry/views/insights/http/utils/queryParam
5858
import {InsightsSpanTagProvider} from 'sentry/views/insights/pages/insightsSpanTagProvider';
5959
import {
6060
ModuleName,
61+
SpanFields,
6162
SpanFunction,
6263
SpanIndexedField,
6364
SpanMetricsField,
@@ -211,7 +212,7 @@ export function HTTPSamplesPanel() {
211212
} = useTopNSpanMetricsSeries(
212213
{
213214
search,
214-
fields: ['span.status_code', 'count()'],
215+
fields: [SpanFields.RESPONSE_CODE, 'count()'],
215216
yAxis: ['count()'],
216217
topN: 5,
217218
sort: {
@@ -418,6 +419,7 @@ export function HTTPSamplesPanel() {
418419
<ModuleLayout.Full>
419420
<InsightsLineChartWidget
420421
showLegend="never"
422+
search={search}
421423
title={getDurationChartTitle('http')}
422424
isLoading={isDurationDataFetching}
423425
error={durationError}
@@ -432,6 +434,8 @@ export function HTTPSamplesPanel() {
432434
<Fragment>
433435
<ModuleLayout.Full>
434436
<ResponseCodeCountChart
437+
search={search}
438+
groupBy={[SpanFields.RESPONSE_CODE]}
435439
series={Object.values(responseCodeData).filter(Boolean)}
436440
isLoading={isResponseCodeDataLoading}
437441
error={responseCodeError}

static/app/views/insights/types.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export enum SpanFields {
9191
SPAN_OP = 'span.op',
9292
RELEASE = 'release',
9393
PROJECT_ID = 'project.id',
94+
RESPONSE_CODE = 'span.status_code',
9495
}
9596

9697
type WebVitalsMeasurements =

0 commit comments

Comments
 (0)