Skip to content

Commit cf7a490

Browse files
authored
feat(explore): Use processed autocomplete names (#81008)
The processed autocomplete names will map things lcp to `measurements.lcp` so we show them the way they used to be shown in other parts of sentry. Additionally, we'll get units back by doing this.
1 parent 1d63f1c commit cf7a490

File tree

17 files changed

+153
-96
lines changed

17 files changed

+153
-96
lines changed

static/app/components/performance/spanSearchQueryBuilder.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,12 @@ export function EAPSpanSearchQueryBuilder({
179179
SPANS_FILTER_KEY_SECTIONS.flatMap(section => section.children)
180180
);
181181
return [
182-
...SPANS_FILTER_KEY_SECTIONS,
182+
...SPANS_FILTER_KEY_SECTIONS.map(section => {
183+
return {
184+
...section,
185+
children: section.children.filter(key => stringTags.hasOwnProperty(key)),
186+
};
187+
}),
183188
{
184189
value: 'custom_fields',
185190
label: 'Custom Tags',

static/app/utils/discover/fieldRenderers.tsx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,6 @@ type SpecialFields = {
366366
replayId: SpecialField;
367367
'span.description': SpecialField;
368368
'span.status_code': SpecialField;
369-
span_id: SpecialField;
370369
team_key_transaction: SpecialField;
371370
'timestamp.to_day': SpecialField;
372371
'timestamp.to_hour': SpecialField;
@@ -482,17 +481,6 @@ const SPECIAL_FIELDS: SpecialFields = {
482481
return <Container>{getShortEventId(id)}</Container>;
483482
},
484483
},
485-
span_id: {
486-
sortField: 'span_id',
487-
renderFunc: data => {
488-
const spanId: string | unknown = data?.span_id;
489-
if (typeof spanId !== 'string') {
490-
return null;
491-
}
492-
493-
return <Container>{getShortEventId(spanId)}</Container>;
494-
},
495-
},
496484
'span.description': {
497485
sortField: 'span.description',
498486
renderFunc: data => {

static/app/utils/discover/fields.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,12 +1639,14 @@ export const COMBINED_DATASET_FILTER_KEY_SECTIONS: FilterKeySection[] = [
16391639
// will take in a project platform key, and output only the relevant filter key sections.
16401640
// This way, users will not be suggested mobile fields for a backend transaction, for example.
16411641

1642-
export const TYPED_TAG_KEY_RE = /tags\[(.*),(.*)\]/;
1642+
export const TYPED_TAG_KEY_RE = /tags\[([^\s]*),([^\s]*)\]/;
16431643

1644-
export function formatParsedFunction(func: ParsedFunction) {
1645-
const args = func.arguments.map(arg => {
1646-
const result = arg.match(TYPED_TAG_KEY_RE);
1647-
return result?.[1] ?? arg;
1648-
});
1644+
export function prettifyTagKey(key: string): string {
1645+
const result = key.match(TYPED_TAG_KEY_RE);
1646+
return result?.[1] ?? key;
1647+
}
1648+
1649+
export function prettifyParsedFunction(func: ParsedFunction) {
1650+
const args = func.arguments.map(prettifyTagKey);
16491651
return `${func.name}(${args.join(',')})`;
16501652
}

static/app/views/dashboards/widgetBuilder/widgetBuilder.spec.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2608,7 +2608,7 @@ describe('WidgetBuilder', function () {
26082608
body: [
26092609
{
26102610
key: 'plan',
2611-
name: 'Plan',
2611+
name: 'plan',
26122612
},
26132613
],
26142614
match: [
@@ -2621,12 +2621,12 @@ describe('WidgetBuilder', function () {
26212621
url: `/organizations/org-slug/spans/fields/`,
26222622
body: [
26232623
{
2624-
key: 'lcp.size',
2625-
name: 'Lcp.Size',
2624+
key: 'tags[lcp.size,number]',
2625+
name: 'lcp.size',
26262626
},
26272627
{
2628-
key: 'something.else',
2629-
name: 'Something.Else',
2628+
key: 'tags[something.else,number]',
2629+
name: 'something.else',
26302630
},
26312631
],
26322632
match: [

static/app/views/explore/charts/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import {space} from 'sentry/styles/space';
1414
import {dedupeArray} from 'sentry/utils/dedupeArray';
1515
import {
1616
aggregateOutputType,
17-
formatParsedFunction,
1817
parseFunction,
18+
prettifyParsedFunction,
1919
} from 'sentry/utils/discover/fields';
2020
import {MutableSearch} from 'sentry/utils/tokenizeSearch';
2121
import useOrganization from 'sentry/utils/useOrganization';
@@ -172,7 +172,7 @@ export function ExploreCharts({query, setError}: ExploreChartsProps) {
172172

173173
const formattedYAxes = dedupedYAxes.map(yaxis => {
174174
const func = parseFunction(yaxis);
175-
return func ? formatParsedFunction(func) : undefined;
175+
return func ? prettifyParsedFunction(func) : undefined;
176176
});
177177

178178
const {chartType, label, yAxes: visualizeYAxes} = visualize;

static/app/views/explore/contexts/spanTagsContext.tsx

Lines changed: 84 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ import {useApiQuery} from 'sentry/utils/queryClient';
99
import useOrganization from 'sentry/utils/useOrganization';
1010
import usePageFilters from 'sentry/utils/usePageFilters';
1111
import {SpanIndexedField} from 'sentry/views/insights/types';
12-
import {
13-
useSpanFieldStaticTags,
14-
useSpanFieldSupportedTags,
15-
} from 'sentry/views/performance/utils/useSpanFieldSupportedTags';
12+
import {useSpanFieldCustomTags} from 'sentry/views/performance/utils/useSpanFieldSupportedTags';
1613

1714
type TypedSpanTags = {
1815
number: TagCollection;
@@ -27,22 +24,9 @@ interface SpanTagsProviderProps {
2724
}
2825

2926
export function SpanTagsProvider({children, dataset}: SpanTagsProviderProps) {
30-
const numericSpanFields: Set<string> = useMemo(() => {
31-
return new Set([
32-
SpanIndexedField.SPAN_DURATION,
33-
SpanIndexedField.SPAN_SELF_TIME,
34-
SpanIndexedField.INP,
35-
SpanIndexedField.INP_SCORE,
36-
SpanIndexedField.INP_SCORE_WEIGHT,
37-
SpanIndexedField.TOTAL_SCORE,
38-
SpanIndexedField.CACHE_ITEM_SIZE,
39-
SpanIndexedField.MESSAGING_MESSAGE_BODY_SIZE,
40-
SpanIndexedField.MESSAGING_MESSAGE_RECEIVE_LATENCY,
41-
SpanIndexedField.MESSAGING_MESSAGE_RETRY_COUNT,
42-
]);
43-
}, []);
44-
45-
const supportedTags = useSpanFieldSupportedTags();
27+
const {data: indexedTags} = useSpanFieldCustomTags({
28+
enabled: dataset === DiscoverDatasets.SPANS_INDEXED,
29+
});
4630

4731
const numberTags: TagCollection = useTypedSpanTags({
4832
enabled: dataset === DiscoverDatasets.SPANS_EAP,
@@ -54,42 +38,92 @@ export function SpanTagsProvider({children, dataset}: SpanTagsProviderProps) {
5438
type: 'string',
5539
});
5640

57-
const staticTags = useSpanFieldStaticTags();
58-
5941
const allNumberTags = useMemo(() => {
42+
const measurements = [
43+
SpanIndexedField.SPAN_DURATION,
44+
SpanIndexedField.SPAN_SELF_TIME,
45+
].map(measurement => [
46+
measurement,
47+
{
48+
key: measurement,
49+
name: measurement,
50+
kind: FieldKind.MEASUREMENT,
51+
},
52+
]);
53+
6054
if (dataset === DiscoverDatasets.SPANS_INDEXED) {
61-
return {};
55+
return {
56+
...Object.fromEntries(measurements),
57+
};
6258
}
6359

6460
return {
6561
...numberTags,
66-
...Object.fromEntries(
67-
Object.entries(staticTags)
68-
.filter(([key, _]) => numericSpanFields.has(key))
69-
.map(([key, tag]) => [key, {...tag, kind: FieldKind.MEASUREMENT}])
70-
),
62+
...Object.fromEntries(measurements),
7163
};
72-
}, [dataset, numberTags, numericSpanFields, staticTags]);
64+
}, [dataset, numberTags]);
7365

7466
const allStringTags = useMemo(() => {
67+
const tags = [
68+
// NOTE: intentionally choose to not expose transaction id
69+
// as we're moving toward span ids
70+
71+
'id', // SpanIndexedField.SPAN_OP is actually `span_id`
72+
SpanIndexedField.BROWSER_NAME,
73+
SpanIndexedField.ENVIRONMENT,
74+
SpanIndexedField.ORIGIN_TRANSACTION,
75+
SpanIndexedField.PROJECT,
76+
SpanIndexedField.RAW_DOMAIN,
77+
SpanIndexedField.RELEASE,
78+
SpanIndexedField.SDK_NAME,
79+
SpanIndexedField.SDK_VERSION,
80+
SpanIndexedField.SPAN_ACTION,
81+
SpanIndexedField.SPAN_CATEGORY,
82+
SpanIndexedField.SPAN_DESCRIPTION,
83+
SpanIndexedField.SPAN_DOMAIN,
84+
SpanIndexedField.SPAN_GROUP,
85+
SpanIndexedField.SPAN_MODULE,
86+
SpanIndexedField.SPAN_OP,
87+
SpanIndexedField.SPAN_STATUS,
88+
SpanIndexedField.TIMESTAMP,
89+
SpanIndexedField.TRACE,
90+
SpanIndexedField.TRANSACTION,
91+
SpanIndexedField.TRANSACTION_METHOD,
92+
SpanIndexedField.TRANSACTION_OP,
93+
SpanIndexedField.USER,
94+
SpanIndexedField.USER_EMAIL,
95+
SpanIndexedField.USER_GEO_SUBREGION,
96+
SpanIndexedField.USER_ID,
97+
SpanIndexedField.USER_IP,
98+
SpanIndexedField.USER_USERNAME,
99+
].map(tag => [
100+
tag,
101+
{
102+
key: tag,
103+
name: tag,
104+
kind: FieldKind.TAG,
105+
},
106+
]);
107+
75108
if (dataset === DiscoverDatasets.SPANS_INDEXED) {
76-
return supportedTags.data;
109+
return {
110+
...indexedTags,
111+
...Object.fromEntries(tags),
112+
};
77113
}
78114

79115
return {
80116
...stringTags,
81-
...Object.fromEntries(
82-
Object.entries(staticTags)
83-
.filter(([key, _]) => !numericSpanFields.has(key))
84-
.map(([key, tag]) => [key, {...tag, kind: FieldKind.TAG}])
85-
),
117+
...Object.fromEntries(tags),
86118
};
87-
}, [dataset, supportedTags, stringTags, staticTags, numericSpanFields]);
119+
}, [dataset, indexedTags, stringTags]);
88120

89-
const tags = {
90-
number: allNumberTags,
91-
string: allStringTags,
92-
};
121+
const tags = useMemo(() => {
122+
return {
123+
number: allNumberTags,
124+
string: allStringTags,
125+
};
126+
}, [allNumberTags, allStringTags]);
93127

94128
return <SpanTagsContext.Provider value={tags}>{children}</SpanTagsContext.Provider>;
95129
}
@@ -131,6 +165,7 @@ function useTypedSpanTags({
131165
environment: selection.environments,
132166
...normalizeDateTimeParams(selection.datetime),
133167
dataset: 'spans',
168+
process: 1,
134169
type,
135170
},
136171
};
@@ -149,20 +184,22 @@ function useTypedSpanTags({
149184
// For now, skip all the sentry. prefixed tags as they
150185
// should be covered by the static tags that will be
151186
// merged with these results.
152-
if (tag.key.startsWith('sentry.')) {
187+
if (tag.key.startsWith('sentry.') || tag.key.startsWith('tags[sentry.')) {
153188
continue;
154189
}
155190

156191
// EAP spans contain tags with illegal characters
157-
if (!/^[a-zA-Z0-9_.:-]+$/.test(tag.key)) {
192+
// SnQL forbids `-` but is allowed in RPC. So add it back later
193+
if (
194+
!/^[a-zA-Z0-9_.:]+$/.test(tag.key) &&
195+
!/^tags\[[a-zA-Z0-9_.:]+,number\]$/.test(tag.key)
196+
) {
158197
continue;
159198
}
160199

161-
const key = type === 'number' ? `tags[${tag.key},number]` : tag.key;
162-
163-
allTags[key] = {
164-
key,
165-
name: tag.key,
200+
allTags[tag.key] = {
201+
key: tag.key,
202+
name: tag.name,
166203
kind: type === 'number' ? FieldKind.MEASUREMENT : FieldKind.TAG,
167204
};
168205
}

static/app/views/explore/hooks/useResultsMode.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('useResultMode', function () {
3939

4040
expect(resultMode).toEqual('samples'); // default
4141
expect(sampleFields).toEqual([
42-
'span_id',
42+
'id',
4343
'project',
4444
'span.op',
4545
'span.description',
@@ -56,7 +56,7 @@ describe('useResultMode', function () {
5656
expect(resultMode).toEqual('samples');
5757

5858
expect(sampleFields).toEqual([
59-
'span_id',
59+
'id',
6060
'project',
6161
'span.op',
6262
'span.description',

static/app/views/explore/hooks/useSampleFields.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('useSampleFields', function () {
1414
render(<TestPage />, {disableRouterMocks: true});
1515

1616
expect(sampleFields).toEqual([
17-
'span_id',
17+
'id',
1818
'project',
1919
'span.op',
2020
'span.description',
@@ -27,7 +27,7 @@ describe('useSampleFields', function () {
2727

2828
act(() => setSampleFields([]));
2929
expect(sampleFields).toEqual([
30-
'span_id',
30+
'id',
3131
'project',
3232
'span.op',
3333
'span.description',

static/app/views/explore/hooks/useSampleFields.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,7 @@ function useSampleFieldsImpl({
3131
return fields;
3232
}
3333

34-
return [
35-
'span_id',
36-
'project',
37-
'span.op',
38-
'span.description',
39-
'span.duration',
40-
'timestamp',
41-
];
34+
return ['id', 'project', 'span.op', 'span.description', 'span.duration', 'timestamp'];
4235
}, [location.query.field]);
4336

4437
const setSampleFields = useCallback(

static/app/views/explore/tables/aggregatesTable.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import EventView from 'sentry/utils/discover/eventView';
1515
import type {Sort} from 'sentry/utils/discover/fields';
1616
import {
1717
fieldAlignment,
18-
formatParsedFunction,
1918
getAggregateAlias,
2019
parseFunction,
20+
prettifyParsedFunction,
2121
} from 'sentry/utils/discover/fields';
2222
import {MutableSearch} from 'sentry/utils/tokenizeSearch';
2323
import useOrganization from 'sentry/utils/useOrganization';
@@ -147,7 +147,7 @@ export function AggregatesTable({setError}: AggregatesTableProps) {
147147

148148
const func = parseFunction(field);
149149
if (func) {
150-
label = formatParsedFunction(func);
150+
label = prettifyParsedFunction(func);
151151
}
152152

153153
const direction = sorts.find(s => s.field === field)?.kind;

0 commit comments

Comments
 (0)