Skip to content

Commit c4310a7

Browse files
DominikB2014cursoragent
authored andcommitted
ref(insights): replace useSpansIndexed with useSpans (#95470)
Eap with insights is fully GA, so we can replace usages of `useSpansIndexed` with `useSpans`. I did some work to remove `SpanIndexedField` usage, but will complete the rest in a followup PR
1 parent 89cfc40 commit c4310a7

File tree

16 files changed

+211
-177
lines changed

16 files changed

+211
-177
lines changed

static/app/views/insights/browser/webVitals/queries/useSpanSamplesWebVitalsQuery.tsx

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ import {
88
} from 'sentry/views/insights/browser/webVitals/types';
99
import type {BrowserType} from 'sentry/views/insights/browser/webVitals/utils/queryParameterDecoders/browserType';
1010
import {useWebVitalsSort} from 'sentry/views/insights/browser/webVitals/utils/useWebVitalsSort';
11-
import {useSpansIndexed} from 'sentry/views/insights/common/queries/useDiscover';
12-
import {SpanIndexedField, type SubregionCode} from 'sentry/views/insights/types';
11+
import {useSpans} from 'sentry/views/insights/common/queries/useDiscover';
12+
import {
13+
SpanFields,
14+
SpanIndexedField,
15+
type SubregionCode,
16+
} from 'sentry/views/insights/types';
1317

1418
export const INTERACTION_SPANS_FILTER =
1519
'span.op:[ui.interaction.click,ui.interaction.hover,ui.interaction.drag,ui.interaction.press]';
@@ -95,30 +99,31 @@ export function useSpanSamplesWebVitalsQuery({
9599
break;
96100
}
97101

98-
const {data, isPending, ...rest} = useSpansIndexed(
102+
const {data, isPending, ...rest} = useSpans(
99103
{
100104
search: `${mutableSearch.formatString()} ${filter}`,
101105
sorts: [sort],
102106
fields: [
103107
...(field && ratioField ? [field, ratioField] : []),
104-
SpanIndexedField.TOTAL_SCORE,
105-
SpanIndexedField.TRACE,
106-
SpanIndexedField.PROFILE_ID,
107-
SpanIndexedField.PROFILEID,
108-
SpanIndexedField.REPLAY_ID,
109-
SpanIndexedField.REPLAYID,
110-
SpanIndexedField.USER_EMAIL,
111-
SpanIndexedField.USER_USERNAME,
112-
SpanIndexedField.USER_ID,
113-
SpanIndexedField.USER_IP,
114-
SpanIndexedField.PROJECT,
115-
SpanIndexedField.SPAN_DESCRIPTION,
116-
SpanIndexedField.TIMESTAMP,
117-
SpanIndexedField.SPAN_SELF_TIME,
118-
SpanIndexedField.TRANSACTION,
119-
SpanIndexedField.SPAN_OP,
120-
SpanIndexedField.LCP_ELEMENT,
121-
SpanIndexedField.CLS_SOURCE,
108+
SpanFields.TOTAL_SCORE,
109+
SpanFields.TRACE,
110+
SpanFields.PROFILE_ID,
111+
SpanFields.PROFILEID,
112+
SpanFields.REPLAY_ID,
113+
SpanFields.REPLAYID,
114+
SpanFields.USER_EMAIL,
115+
SpanFields.USER_USERNAME,
116+
SpanFields.USER_ID,
117+
SpanFields.USER_IP,
118+
SpanFields.PROJECT,
119+
SpanFields.SPAN_DESCRIPTION,
120+
SpanFields.TIMESTAMP,
121+
SpanFields.SPAN_SELF_TIME,
122+
SpanFields.TRANSACTION,
123+
SpanFields.SPAN_OP,
124+
SpanFields.LCP_ELEMENT,
125+
SpanFields.CLS_SOURCE,
126+
SpanFields.ID,
122127
],
123128
enabled,
124129
limit,

static/app/views/insights/browser/webVitals/views/pageOverview.spec.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {render, waitFor} from 'sentry-test/reactTestingLibrary';
55

66
import {useLocation} from 'sentry/utils/useLocation';
77
import usePageFilters from 'sentry/utils/usePageFilters';
8+
import {SAMPLING_MODE} from 'sentry/views/explore/hooks/useProgressiveQuery';
89
import PageOverview from 'sentry/views/insights/browser/webVitals/views/pageOverview';
910

1011
jest.mock('sentry/utils/useLocation');
@@ -139,7 +140,8 @@ describe('PageOverview', function () {
139140
'/organizations/org-slug/events/',
140141
expect.objectContaining({
141142
query: expect.objectContaining({
142-
dataset: 'spansIndexed',
143+
dataset: 'spans',
144+
sampling: SAMPLING_MODE.NORMAL,
143145
field: [
144146
'measurements.inp',
145147
'measurements.score.ratio.inp',
@@ -161,6 +163,7 @@ describe('PageOverview', function () {
161163
'span.op',
162164
'lcp.element',
163165
'cls.source.1',
166+
'id',
164167
],
165168
query:
166169
'has:message !span.description:<unknown> transaction:/ span.op:[ui.interaction.click,ui.interaction.hover,ui.interaction.drag,ui.interaction.press] ',
@@ -195,7 +198,8 @@ describe('PageOverview', function () {
195198
'/organizations/org-slug/events/',
196199
expect.objectContaining({
197200
query: expect.objectContaining({
198-
dataset: 'spansIndexed',
201+
dataset: 'spans',
202+
sampling: SAMPLING_MODE.NORMAL,
199203
field: [
200204
'measurements.inp',
201205
'measurements.score.ratio.inp',
@@ -217,6 +221,7 @@ describe('PageOverview', function () {
217221
'span.op',
218222
'lcp.element',
219223
'cls.source.1',
224+
'id',
220225
],
221226
query:
222227
'has:message !span.description:<unknown> transaction:"/page-with-a-\\*/" span.op:[ui.interaction.click,ui.interaction.hover,ui.interaction.drag,ui.interaction.press] ',

static/app/views/insights/cache/components/samplePanel.tsx

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import {
3333
useDiscoverOrEap,
3434
useSpanMetrics,
3535
useSpans,
36-
useSpansIndexed,
3736
} from 'sentry/views/insights/common/queries/useDiscover';
3837
import {
3938
DataTitles,
@@ -129,31 +128,32 @@ export function CacheSamplePanel() {
129128
const sampleFilters: SpanIndexedQueryFilters = {
130129
...BASE_FILTERS,
131130
transaction: query.transaction,
132-
project_id: query.project,
131+
['project.id']: query.project,
133132
};
134133

135134
const useIndexedCacheSpans = (
136135
isCacheHit: SpanIndexedResponse['cache.hit'],
137136
limit: number
138137
) =>
139-
useSpansIndexed(
138+
useSpans(
140139
{
141140
search: MutableSearch.fromQueryObject({
142141
...sampleFilters,
143142
...new MutableSearch(query.spanSearchQuery).filters,
144143
'cache.hit': isCacheHit,
145144
}),
146145
fields: [
147-
SpanIndexedField.PROJECT,
148-
SpanIndexedField.TRACE,
149-
SpanIndexedField.TRANSACTION_SPAN_ID,
150-
SpanIndexedField.SPAN_ID,
151-
SpanIndexedField.TIMESTAMP,
152-
SpanIndexedField.SPAN_DESCRIPTION,
153-
SpanIndexedField.CACHE_HIT,
154-
SpanIndexedField.SPAN_OP,
155-
SpanIndexedField.CACHE_ITEM_SIZE,
156-
SpanIndexedField.TRACE,
146+
SpanFields.ID,
147+
SpanFields.PROJECT,
148+
SpanFields.TRACE,
149+
SpanFields.TRANSACTION_SPAN_ID,
150+
SpanFields.SPAN_ID,
151+
SpanFields.TIMESTAMP,
152+
SpanFields.SPAN_DESCRIPTION,
153+
SpanFields.CACHE_HIT,
154+
SpanFields.SPAN_OP,
155+
SpanFields.CACHE_ITEM_SIZE,
156+
SpanFields.TRACE,
157157
],
158158
sorts: [SPAN_SAMPLES_SORT],
159159
limit,
@@ -211,6 +211,10 @@ export function CacheSamplePanel() {
211211
const transactionDurationsMap = keyBy(transactionData, 'id');
212212
return cacheSamples.map(span => ({
213213
...span,
214+
'cache.hit':
215+
span['cache.hit'] === undefined
216+
? ''
217+
: (`${span['cache.hit']}` as 'true' | 'false' | ''),
214218
'transaction.duration':
215219
transactionDurationsMap[span[SpanIndexedField.TRANSACTION_SPAN_ID]]?.[
216220
'span.duration'

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import {SQLishFormatter} from 'sentry/utils/sqlish/SQLishFormatter';
1111
import {MutableSearch} from 'sentry/utils/tokenizeSearch';
1212
import {useLocation} from 'sentry/utils/useLocation';
1313
import {useNavigate} from 'sentry/utils/useNavigate';
14-
import {useSpansIndexed} from 'sentry/views/insights/common/queries/useDiscover';
14+
import {useSpans} from 'sentry/views/insights/common/queries/useDiscover';
1515
import {useModuleURL} from 'sentry/views/insights/common/utils/useModuleURL';
1616
import {prettyPrintJsonString} from 'sentry/views/insights/database/utils/jsonUtils';
17-
import {ModuleName, SpanIndexedField} from 'sentry/views/insights/types';
17+
import {ModuleName, SpanFields} from 'sentry/views/insights/types';
1818

1919
const formatter = new SQLishFormatter();
2020

@@ -31,15 +31,15 @@ export function FullSpanDescription({
3131
filters = {},
3232
moduleName,
3333
}: Props) {
34-
const {data: indexedSpans, isFetching: areIndexedSpansLoading} = useSpansIndexed(
34+
const {data: indexedSpans, isFetching: areIndexedSpansLoading} = useSpans(
3535
{
3636
search: MutableSearch.fromQueryObject({'span.group': group, ...filters}),
3737
limit: 1,
3838
fields: [
39-
SpanIndexedField.PROJECT_ID,
40-
SpanIndexedField.TRANSACTION_ID,
41-
SpanIndexedField.SPAN_DESCRIPTION,
42-
SpanIndexedField.DB_SYSTEM,
39+
SpanFields.PROJECT_ID,
40+
SpanFields.TRANSACTION_SPAN_ID,
41+
SpanFields.SPAN_DESCRIPTION,
42+
SpanFields.DB_SYSTEM,
4343
],
4444
},
4545
'api.starfish.span-description'

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {useNavigate} from 'sentry/utils/useNavigate';
1212
import useOrganization from 'sentry/utils/useOrganization';
1313
import useProjects from 'sentry/utils/useProjects';
1414
import {useRelease} from 'sentry/utils/useRelease';
15-
import {useSpansIndexed} from 'sentry/views/insights/common/queries/useDiscover';
15+
import {useSpans} from 'sentry/views/insights/common/queries/useDiscover';
1616
import {
1717
MissingFrame,
1818
StackTraceMiniFrame,
@@ -23,11 +23,11 @@ import {
2323
prettyPrintJsonString,
2424
} from 'sentry/views/insights/database/utils/jsonUtils';
2525
import type {SpanIndexedFieldTypes} from 'sentry/views/insights/types';
26-
import {SpanIndexedField} from 'sentry/views/insights/types';
26+
import {SpanFields} from 'sentry/views/insights/types';
2727

2828
interface Props {
29-
groupId: SpanIndexedFieldTypes[SpanIndexedField.SPAN_GROUP];
30-
op: SpanIndexedFieldTypes[SpanIndexedField.SPAN_OP];
29+
groupId: SpanIndexedFieldTypes[SpanFields.SPAN_GROUP];
30+
op: SpanIndexedFieldTypes[SpanFields.SPAN_OP];
3131
preliminaryDescription?: string;
3232
}
3333

@@ -52,29 +52,29 @@ export function DatabaseSpanDescription({
5252
const {projects} = useProjects();
5353
const organization = useOrganization();
5454

55-
const {data: indexedSpans, isFetching: areIndexedSpansLoading} = useSpansIndexed(
55+
const {data: indexedSpans, isFetching: areIndexedSpansLoading} = useSpans(
5656
{
5757
search: MutableSearch.fromQueryObject({'span.group': groupId}),
5858
limit: 1,
5959
fields: [
60-
SpanIndexedField.PROJECT_ID,
61-
SpanIndexedField.SPAN_DESCRIPTION,
62-
SpanIndexedField.DB_SYSTEM,
63-
SpanIndexedField.CODE_FILEPATH,
64-
SpanIndexedField.CODE_LINENO,
65-
SpanIndexedField.CODE_FUNCTION,
66-
SpanIndexedField.SDK_NAME,
67-
SpanIndexedField.SDK_VERSION,
68-
SpanIndexedField.RELEASE,
69-
SpanIndexedField.PLATFORM,
60+
SpanFields.PROJECT_ID,
61+
SpanFields.SPAN_DESCRIPTION,
62+
SpanFields.DB_SYSTEM,
63+
SpanFields.CODE_FILEPATH,
64+
SpanFields.CODE_LINENO,
65+
SpanFields.CODE_FUNCTION,
66+
SpanFields.SDK_NAME,
67+
SpanFields.SDK_VERSION,
68+
SpanFields.RELEASE,
69+
SpanFields.PLATFORM,
7070
],
71-
sorts: [{field: SpanIndexedField.CODE_FILEPATH, kind: 'desc'}],
71+
sorts: [{field: SpanFields.CODE_FILEPATH, kind: 'desc'}],
7272
},
7373
'api.starfish.span-description'
7474
);
7575
const indexedSpan = indexedSpans?.[0];
7676

77-
const project = projects.find(p => p.id === indexedSpan?.project_id?.toString());
77+
const project = projects.find(p => p.id === indexedSpan?.['project.id']?.toString());
7878

7979
const {data: release} = useRelease({
8080
orgSlug: organization.slug,
@@ -157,7 +157,7 @@ export function DatabaseSpanDescription({
157157
<Fragment>
158158
{codeFilepath ? (
159159
<StackTraceMiniFrame
160-
projectId={indexedSpan?.project_id?.toString()}
160+
projectId={indexedSpan?.['project.id']?.toString()}
161161
event={event}
162162
frame={{
163163
filename: codeFilepath,

static/app/views/insights/common/queries/useDiscover.spec.tsx

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,10 @@ import {QueryClientProvider} from 'sentry/utils/queryClient';
1010
import {MutableSearch} from 'sentry/utils/tokenizeSearch';
1111
import {useLocation} from 'sentry/utils/useLocation';
1212
import usePageFilters from 'sentry/utils/usePageFilters';
13-
import {
14-
useSpanMetrics,
15-
useSpansIndexed,
16-
} from 'sentry/views/insights/common/queries/useDiscover';
17-
import {
18-
SpanIndexedField,
19-
type SpanIndexedProperty,
20-
type SpanMetricsProperty,
21-
} from 'sentry/views/insights/types';
13+
import {SAMPLING_MODE} from 'sentry/views/explore/hooks/useProgressiveQuery';
14+
import {useSpanMetrics, useSpans} from 'sentry/views/insights/common/queries/useDiscover';
15+
import type {EAPSpanProperty, SpanMetricsProperty} from 'sentry/views/insights/types';
16+
import {SpanFields} from 'sentry/views/insights/types';
2217
import {OrganizationContext} from 'sentry/views/organizationContext';
2318

2419
jest.mock('sentry/utils/useLocation');
@@ -178,11 +173,11 @@ describe('useDiscover', () => {
178173
});
179174

180175
const {result} = renderHook(
181-
({fields, enabled}) => useSpansIndexed({fields, enabled}, 'referrer'),
176+
({fields, enabled}) => useSpans({fields, enabled}, 'referrer'),
182177
{
183178
wrapper: Wrapper,
184179
initialProps: {
185-
fields: [SpanIndexedField.SPAN_DESCRIPTION] as SpanIndexedProperty[],
180+
fields: [SpanFields.SPAN_DESCRIPTION] as EAPSpanProperty[],
186181
enabled: false,
187182
},
188183
}
@@ -216,7 +211,7 @@ describe('useDiscover', () => {
216211

217212
const {result} = renderHook(
218213
({filters, fields, sorts, limit, cursor, referrer}) =>
219-
useSpansIndexed(
214+
useSpans(
220215
{
221216
search: MutableSearch.fromQueryObject(filters),
222217
fields,
@@ -236,10 +231,10 @@ describe('useDiscover', () => {
236231
release: '0.0.1',
237232
},
238233
fields: [
239-
SpanIndexedField.SPAN_OP,
240-
SpanIndexedField.SPAN_GROUP,
241-
SpanIndexedField.SPAN_DESCRIPTION,
242-
] as SpanIndexedProperty[],
234+
SpanFields.SPAN_OP,
235+
SpanFields.SPAN_GROUP,
236+
SpanFields.SPAN_DESCRIPTION,
237+
] as EAPSpanProperty[],
243238
sorts: [{field: 'span.group', kind: 'desc' as const}],
244239
limit: 10,
245240
referrer: 'api-spec',
@@ -255,7 +250,8 @@ describe('useDiscover', () => {
255250
expect.objectContaining({
256251
method: 'GET',
257252
query: {
258-
dataset: 'spansIndexed',
253+
dataset: 'spans',
254+
sampling: SAMPLING_MODE.NORMAL,
259255
environment: [],
260256
field: ['span.op', 'span.group', 'span.description'],
261257
per_page: 10,

static/app/views/insights/common/queries/useDiscover.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ import type {
1414
EAPSpanResponse,
1515
MetricsProperty,
1616
MetricsResponse,
17-
SpanIndexedField,
18-
SpanIndexedProperty,
19-
SpanIndexedResponse,
2017
SpanMetricsProperty,
2118
SpanMetricsResponse,
2219
} from 'sentry/views/insights/types';
@@ -47,19 +44,6 @@ interface UseDiscoverOptions<Fields> {
4744
// The default sampling mode for eap queries
4845
export const DEFAULT_SAMPLING_MODE: SamplingMode = 'NORMAL';
4946

50-
export const useSpansIndexed = <Fields extends SpanIndexedProperty[]>(
51-
options: UseDiscoverOptions<Fields> = {},
52-
referrer: string
53-
) => {
54-
const useEap = useInsightsEap();
55-
// Indexed spans dataset always returns an `id`
56-
return useDiscover<Fields | [SpanIndexedField.ID], SpanIndexedResponse>(
57-
options,
58-
useEap ? DiscoverDatasets.SPANS_EAP_RPC : DiscoverDatasets.SPANS_INDEXED,
59-
referrer
60-
);
61-
};
62-
6347
export const useSpans = <Fields extends EAPSpanProperty[]>(
6448
options: UseDiscoverOptions<Fields> = {},
6549
referrer: string

0 commit comments

Comments
 (0)