Skip to content

Commit 0b494d3

Browse files
DominikB2014andrewshie-sentry
authored andcommitted
ref(insights): remove any fields that are already returned as default in useSpanSamples (#89513)
The `useSpanSamples` hook returns a few fields by default, it also takes a prop `additionalFields` which allows you to return a few extra fields. The PR ensures that you cannot pass in fields that is returned by default into `additionalFields` This will make the eap migration a bit easier. In eap the `transaction.id` field is now called `transaction.span_id`, so it will be easier to migrate if we don't have to update `transaction.id` everywhere.
1 parent c69c3c9 commit 0b494d3

File tree

10 files changed

+42
-64
lines changed

10 files changed

+42
-64
lines changed

static/app/views/insights/common/queries/useSpanSamples.tsx

+16-15
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {SpanIndexedField, SpanMetricsField} from 'sentry/views/insights/types';
1919

2020
const {SPAN_SELF_TIME, SPAN_GROUP} = SpanIndexedField;
2121

22-
type Options<Fields> = {
22+
type Options<Fields extends NonDefaultSpanSampleFields[]> = {
2323
groupId: string;
2424
transactionName: string;
2525
additionalFields?: Fields;
@@ -42,7 +42,20 @@ export type SpanSample = Pick<
4242
| SpanIndexedField.TRACE
4343
>;
4444

45-
export const useSpanSamples = <Fields extends SpanIndexedProperty[]>(
45+
export type DefaultSpanSampleFields =
46+
| SpanIndexedField.PROJECT
47+
| SpanIndexedField.TRANSACTION_ID
48+
| SpanIndexedField.TIMESTAMP
49+
| SpanIndexedField.SPAN_ID
50+
| SpanIndexedField.PROFILE_ID
51+
| SpanIndexedField.SPAN_SELF_TIME;
52+
53+
export type NonDefaultSpanSampleFields = Exclude<
54+
SpanIndexedProperty,
55+
DefaultSpanSampleFields
56+
>;
57+
58+
export const useSpanSamples = <Fields extends NonDefaultSpanSampleFields[]>(
4659
options: Options<Fields>
4760
) => {
4861
const organization = useOrganization();
@@ -103,19 +116,7 @@ export const useSpanSamples = <Fields extends SpanIndexedProperty[]>(
103116
);
104117

105118
return useApiQuery<{
106-
data: Array<
107-
Pick<
108-
SpanIndexedResponse,
109-
| Fields[number]
110-
// These fields are returned by default
111-
| SpanIndexedField.PROJECT
112-
| SpanIndexedField.TRANSACTION_ID
113-
| SpanIndexedField.TIMESTAMP
114-
| SpanIndexedField.SPAN_ID
115-
| SpanIndexedField.PROFILE_ID
116-
| SpanIndexedField.SPAN_SELF_TIME
117-
>
118-
>;
119+
data: Array<Pick<SpanIndexedResponse, Fields[number] | DefaultSpanSampleFields>>;
119120
meta: EventsMetaType;
120121
}>(
121122
[

static/app/views/insights/common/views/spanSummaryPage/sampleList/durationChart/index.tsx

+6-7
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,22 @@ import Chart, {ChartType} from 'sentry/views/insights/common/components/chart';
1515
import ChartPanel from 'sentry/views/insights/common/components/chartPanel';
1616
import {useSpanMetrics} from 'sentry/views/insights/common/queries/useDiscover';
1717
import {useSpanMetricsSeries} from 'sentry/views/insights/common/queries/useDiscoverSeries';
18-
import type {SpanSample} from 'sentry/views/insights/common/queries/useSpanSamples';
18+
import type {
19+
NonDefaultSpanSampleFields,
20+
SpanSample,
21+
} from 'sentry/views/insights/common/queries/useSpanSamples';
1922
import {useSpanSamples} from 'sentry/views/insights/common/queries/useSpanSamples';
2023
import {AverageValueMarkLine} from 'sentry/views/insights/common/utils/averageValueMarkLine';
2124
import {useSampleScatterPlotSeries} from 'sentry/views/insights/common/views/spanSummaryPage/sampleList/durationChart/useSampleScatterPlotSeries';
22-
import type {
23-
SpanIndexedProperty,
24-
SpanMetricsQueryFilters,
25-
SubregionCode,
26-
} from 'sentry/views/insights/types';
25+
import type {SpanMetricsQueryFilters, SubregionCode} from 'sentry/views/insights/types';
2726
import {SpanMetricsField} from 'sentry/views/insights/types';
2827

2928
const {SPAN_SELF_TIME, SPAN_OP} = SpanMetricsField;
3029

3130
type Props = {
3231
groupId: string;
3332
transactionName: string;
34-
additionalFields?: SpanIndexedProperty[];
33+
additionalFields?: NonDefaultSpanSampleFields[];
3534
additionalFilters?: Record<string, string>;
3635
highlightedSpanId?: string;
3736
onClickSample?: (sample: SpanSample) => void;

static/app/views/insights/common/views/spanSummaryPage/sampleList/index.tsx

+2-5
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ import decodeSubregions from 'sentry/views/insights/browser/resources/utils/quer
2222
import {SampleDrawerBody} from 'sentry/views/insights/common/components/sampleDrawerBody';
2323
import {SampleDrawerHeaderTransaction} from 'sentry/views/insights/common/components/sampleDrawerHeaderTransaction';
2424
import {DEFAULT_COLUMN_ORDER} from 'sentry/views/insights/common/components/samplesTable/spanSamplesTable';
25+
import type {NonDefaultSpanSampleFields} from 'sentry/views/insights/common/queries/useSpanSamples';
2526
import DurationChart from 'sentry/views/insights/common/views/spanSummaryPage/sampleList/durationChart';
2627
import SampleInfo from 'sentry/views/insights/common/views/spanSummaryPage/sampleList/sampleInfo';
2728
import SampleTable from 'sentry/views/insights/common/views/spanSummaryPage/sampleList/sampleTable/sampleTable';
2829
import {useDomainViewFilters} from 'sentry/views/insights/pages/useFilters';
2930
import {
3031
ModuleName,
3132
SpanIndexedField,
32-
type SpanIndexedProperty,
3333
SpanMetricsField,
3434
} from 'sentry/views/insights/types';
3535
import {getTransactionSummaryBaseUrl} from 'sentry/views/performance/transactionSummary/utils';
@@ -108,10 +108,7 @@ export function SampleList({groupId, moduleName, transactionRoute, referrer}: Pr
108108

109109
let columnOrder = DEFAULT_COLUMN_ORDER;
110110

111-
const additionalFields: SpanIndexedProperty[] = [
112-
SpanIndexedField.TRACE,
113-
SpanIndexedField.TRANSACTION_ID,
114-
];
111+
const additionalFields: NonDefaultSpanSampleFields[] = [SpanIndexedField.TRACE];
115112

116113
if (moduleName === ModuleName.RESOURCE) {
117114
additionalFields?.push(SpanIndexedField.HTTP_RESPONSE_CONTENT_LENGTH);

static/app/views/insights/common/views/spanSummaryPage/sampleList/sampleTable/sampleTable.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ import useOrganization from 'sentry/utils/useOrganization';
1212
import type {SamplesTableColumnHeader} from 'sentry/views/insights/common/components/samplesTable/spanSamplesTable';
1313
import {SpanSamplesTable} from 'sentry/views/insights/common/components/samplesTable/spanSamplesTable';
1414
import {useSpanMetrics} from 'sentry/views/insights/common/queries/useDiscover';
15-
import type {SpanSample} from 'sentry/views/insights/common/queries/useSpanSamples';
15+
import type {
16+
NonDefaultSpanSampleFields,
17+
SpanSample,
18+
} from 'sentry/views/insights/common/queries/useSpanSamples';
1619
import {useSpanSamples} from 'sentry/views/insights/common/queries/useSpanSamples';
1720
import {useTransactions} from 'sentry/views/insights/common/queries/useTransactions';
1821
import type {
1922
ModuleName,
20-
SpanIndexedProperty,
2123
SpanMetricsQueryFilters,
2224
SubregionCode,
2325
} from 'sentry/views/insights/types';
@@ -32,7 +34,7 @@ type Props = {
3234
groupId: string;
3335
moduleName: ModuleName;
3436
transactionName: string;
35-
additionalFields?: SpanIndexedProperty[];
37+
additionalFields?: NonDefaultSpanSampleFields[];
3638
additionalFilters?: Record<string, string>;
3739
columnOrder?: SamplesTableColumnHeader[];
3840
highlightedSpanId?: string;

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

+1-6
Original file line numberDiff line numberDiff line change
@@ -416,12 +416,7 @@ describe('HTTPSamplesPanel', () => {
416416
query:
417417
'span.module:http span.op:http.client span.domain:"\\*.sentry.dev" transaction:/api/0/users',
418418
project: [],
419-
additionalFields: [
420-
'trace',
421-
'transaction.id',
422-
'span.description',
423-
'span.status_code',
424-
],
419+
additionalFields: ['trace', 'span.description', 'span.status_code'],
425420
lowerBound: 0,
426421
firstBound: expect.closeTo(333.3333),
427422
secondBound: expect.closeTo(666.6666),

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

-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ export function HTTPSamplesPanel() {
233233
search,
234234
fields: [
235235
SpanIndexedField.TRACE,
236-
SpanIndexedField.TRANSACTION_ID,
237236
SpanIndexedField.SPAN_DESCRIPTION,
238237
SpanIndexedField.RESPONSE_CODE,
239238
],

static/app/views/insights/http/queries/useSpanSamples.spec.tsx

+4-10
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {QueryClientProvider} from 'sentry/utils/queryClient';
88
import {MutableSearch} from 'sentry/utils/tokenizeSearch';
99
import {useLocation} from 'sentry/utils/useLocation';
1010
import usePageFilters from 'sentry/utils/usePageFilters';
11+
import type {NonDefaultSpanSampleFields} from 'sentry/views/insights/common/queries/useSpanSamples';
1112
import {useSpanSamples} from 'sentry/views/insights/http/queries/useSpanSamples';
12-
import {SpanIndexedField, type SpanIndexedProperty} from 'sentry/views/insights/types';
1313
import {OrganizationContext} from 'sentry/views/organizationContext';
1414

1515
jest.mock('sentry/utils/usePageFilters');
@@ -69,10 +69,7 @@ describe('useSpanSamples', () => {
6969
{
7070
wrapper: Wrapper,
7171
initialProps: {
72-
fields: [
73-
SpanIndexedField.TRANSACTION_ID,
74-
SpanIndexedField.SPAN_ID,
75-
] as SpanIndexedProperty[],
72+
fields: [] satisfies NonDefaultSpanSampleFields[],
7673
enabled: false,
7774
},
7875
}
@@ -122,10 +119,7 @@ describe('useSpanSamples', () => {
122119
'span.group': '221aa7ebd216',
123120
release: '0.0.1',
124121
},
125-
fields: [
126-
SpanIndexedField.TRANSACTION_ID,
127-
SpanIndexedField.SPAN_ID,
128-
] as SpanIndexedProperty[],
122+
fields: [] satisfies NonDefaultSpanSampleFields[],
129123
referrer: 'api-spec',
130124
},
131125
}
@@ -138,7 +132,7 @@ describe('useSpanSamples', () => {
138132
expect.objectContaining({
139133
method: 'GET',
140134
query: {
141-
additionalFields: ['transaction.id', 'span_id'],
135+
additionalFields: [],
142136
project: [],
143137
query: `span.group:221aa7ebd216 release:0.0.1`,
144138
referrer: 'api-spec',

static/app/views/insights/http/queries/useSpanSamples.tsx

+8-14
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ import {useApiQuery} from 'sentry/utils/queryClient';
66
import type {MutableSearch} from 'sentry/utils/tokenizeSearch';
77
import useOrganization from 'sentry/utils/useOrganization';
88
import usePageFilters from 'sentry/utils/usePageFilters';
9-
import {getDateConditions} from 'sentry/views/insights/common/utils/getDateConditions';
109
import type {
11-
SpanIndexedField,
12-
SpanIndexedProperty,
13-
SpanIndexedResponse,
14-
} from 'sentry/views/insights/types';
15-
16-
import {useInsightsEap} from '../../common/utils/useEap';
10+
DefaultSpanSampleFields,
11+
NonDefaultSpanSampleFields,
12+
} from 'sentry/views/insights/common/queries/useSpanSamples';
13+
import {getDateConditions} from 'sentry/views/insights/common/utils/getDateConditions';
14+
import {useInsightsEap} from 'sentry/views/insights/common/utils/useEap';
15+
import type {SpanIndexedResponse} from 'sentry/views/insights/types';
1716

1817
interface UseSpanSamplesOptions<Fields> {
1918
enabled?: boolean;
@@ -24,7 +23,7 @@ interface UseSpanSamplesOptions<Fields> {
2423
search?: MutableSearch;
2524
}
2625

27-
export const useSpanSamples = <Fields extends SpanIndexedProperty[]>(
26+
export const useSpanSamples = <Fields extends NonDefaultSpanSampleFields[]>(
2827
options: UseSpanSamplesOptions<Fields> = {}
2928
) => {
3029
const {
@@ -55,12 +54,7 @@ export const useSpanSamples = <Fields extends SpanIndexedProperty[]>(
5554
SpanIndexedResponse,
5655
| Fields[number]
5756
// These fields are returned by default
58-
| SpanIndexedField.PROJECT
59-
| SpanIndexedField.TRANSACTION_ID
60-
| SpanIndexedField.TIMESTAMP
61-
| SpanIndexedField.SPAN_ID
62-
| SpanIndexedField.PROFILE_ID
63-
| SpanIndexedField.SPAN_SELF_TIME
57+
| DefaultSpanSampleFields
6458
>
6559
>;
6660
meta: EventsMetaType;

static/app/views/insights/queues/components/messageSpanSamplesPanel.spec.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ describe('messageSpanSamplesPanel', () => {
189189
query: expect.objectContaining({
190190
additionalFields: [
191191
'trace',
192-
'transaction.id',
193192
'span.description',
194193
'measurements.messaging.message.body.size',
195194
'measurements.messaging.message.receive.latency',
@@ -285,7 +284,6 @@ describe('messageSpanSamplesPanel', () => {
285284
query: expect.objectContaining({
286285
additionalFields: [
287286
'trace',
288-
'transaction.id',
289287
'span.description',
290288
'measurements.messaging.message.body.size',
291289
'measurements.messaging.message.receive.latency',

static/app/views/insights/queues/components/messageSpanSamplesPanel.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ export function MessageSpanSamplesPanel() {
188188
enabled: isPanelOpen && durationAxisMax > 0,
189189
fields: [
190190
SpanIndexedField.TRACE,
191-
SpanIndexedField.TRANSACTION_ID,
192191
SpanIndexedField.SPAN_DESCRIPTION,
193192
SpanIndexedField.MESSAGING_MESSAGE_BODY_SIZE,
194193
SpanIndexedField.MESSAGING_MESSAGE_RECEIVE_LATENCY,

0 commit comments

Comments
 (0)