Skip to content

Commit 43d0c0d

Browse files
committed
update tests
1 parent 9c9db48 commit 43d0c0d

File tree

2 files changed

+20
-106
lines changed

2 files changed

+20
-106
lines changed

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

Lines changed: 10 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {ProjectFixture} from 'sentry-fixture/project';
55
import {render, screen, waitForElementToBeRemoved} from 'sentry-test/reactTestingLibrary';
66
import {textWithMarkupMatcher} from 'sentry-test/utils';
77

8-
import {EntryType} from 'sentry/types/event';
98
import usePageFilters from 'sentry/utils/usePageFilters';
109
import {DatabaseSpanDescription} from 'sentry/views/insights/common/components/spanDescription';
1110

@@ -45,7 +44,7 @@ describe('DatabaseSpanDescription', function () {
4544
expect(screen.getByText('SELECT USERS FRO*')).toBeInTheDocument();
4645
});
4746

48-
it('shows full query if full event is available', async function () {
47+
it('shows full query from indexed span', async function () {
4948
MockApiClient.addMockResponse({
5049
url: `/organizations/${organization.slug}/events/`,
5150
body: {
@@ -54,24 +53,7 @@ describe('DatabaseSpanDescription', function () {
5453
'transaction.id': eventId,
5554
project: project.slug,
5655
span_id: spanId,
57-
},
58-
],
59-
},
60-
});
61-
62-
MockApiClient.addMockResponse({
63-
url: `/organizations/${organization.slug}/events/${project.slug}:${eventId}/`,
64-
body: {
65-
id: eventId,
66-
entries: [
67-
{
68-
type: EntryType.SPANS,
69-
data: [
70-
{
71-
span_id: spanId,
72-
description: 'SELECT users FROM my_table LIMIT 1;',
73-
},
74-
],
56+
'span.description': 'SELECT users FROM my_table LIMIT 1;',
7557
},
7658
],
7759
},
@@ -101,28 +83,9 @@ describe('DatabaseSpanDescription', function () {
10183
'transaction.id': eventId,
10284
project: project.slug,
10385
span_id: spanId,
104-
},
105-
],
106-
},
107-
});
108-
109-
MockApiClient.addMockResponse({
110-
url: `/organizations/${organization.slug}/events/${project.slug}:${eventId}/`,
111-
body: {
112-
id: eventId,
113-
entries: [
114-
{
115-
type: EntryType.SPANS,
116-
data: [
117-
{
118-
span_id: spanId,
119-
description: 'SELECT users FROM my_table LIMIT 1;',
120-
data: {
121-
'code.filepath': '/app/views/users.py',
122-
'code.lineno': 78,
123-
},
124-
},
125-
],
86+
'code.filepath': '/app/views/users.py',
87+
'code.lineno': 78,
88+
'span.description': 'SELECT users FROM my_table LIMIT 1;',
12689
},
12790
],
12891
},
@@ -147,37 +110,18 @@ describe('DatabaseSpanDescription', function () {
147110
});
148111

149112
it('correctly formats and displays MongoDB queries', async function () {
113+
const sampleMongoDBQuery = `{"a": "?", "insert": "documents"}`;
114+
150115
MockApiClient.addMockResponse({
151116
url: `/organizations/${organization.slug}/events/`,
152117
body: {
153118
data: [
154119
{
155-
'transaction.id': eventId,
120+
'transaction.span_id': eventId,
156121
project: project.slug,
157122
span_id: spanId,
158-
},
159-
],
160-
},
161-
});
162-
163-
const sampleMongoDBQuery = `{"a": "?", "insert": "documents"}`;
164-
165-
MockApiClient.addMockResponse({
166-
url: `/organizations/${organization.slug}/events/${project.slug}:${eventId}/`,
167-
body: {
168-
id: eventId,
169-
entries: [
170-
{
171-
type: EntryType.SPANS,
172-
data: [
173-
{
174-
span_id: spanId,
175-
description: sampleMongoDBQuery,
176-
data: {
177-
'db.system': 'mongodb',
178-
},
179-
},
180-
],
123+
'span.description': sampleMongoDBQuery,
124+
'db.system': 'mongodb',
181125
},
182126
],
183127
},

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

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import useOrganization from 'sentry/utils/useOrganization';
1313
import useProjects from 'sentry/utils/useProjects';
1414
import {useRelease} from 'sentry/utils/useRelease';
1515
import {useSpansIndexed} from 'sentry/views/insights/common/queries/useDiscover';
16-
import {useFullSpanFromTrace} from 'sentry/views/insights/common/queries/useFullSpanFromTrace';
17-
import {useInsightsEap} from 'sentry/views/insights/common/utils/useEap';
1816
import {
1917
MissingFrame,
2018
StackTraceMiniFrame,
@@ -51,7 +49,6 @@ export function DatabaseSpanDescription({
5149
}: Omit<Props, 'op'>) {
5250
const navigate = useNavigate();
5351
const location = useLocation();
54-
const useEap = useInsightsEap();
5552
const {projects} = useProjects();
5653
const organization = useOrganization();
5754

@@ -83,7 +80,7 @@ export function DatabaseSpanDescription({
8380
orgSlug: organization.slug,
8481
projectSlug: project?.slug ?? '',
8582
releaseVersion: indexedSpan?.release ?? '',
86-
enabled: useEap,
83+
enabled: indexedSpan?.release !== undefined,
8784
});
8885

8986
const sdk =
@@ -100,13 +97,6 @@ export function DatabaseSpanDescription({
10097
sdk,
10198
};
10299

103-
// NOTE: We only need this for `span.data`! If this info existed in indexed spans, we could skip it
104-
const {data: rawSpan, isFetching: isRawSpanLoading} = useFullSpanFromTrace(
105-
groupId,
106-
[INDEXED_SPAN_SORT],
107-
Boolean(indexedSpan) && !useEap
108-
);
109-
110100
// isExpanded is a query param that is meant to be accessed only when clicking on the
111101
// "View full query" button from the hover tooltip. It is removed from the query params
112102
// on the initial load so the value is not persisted through the link
@@ -121,39 +111,24 @@ export function DatabaseSpanDescription({
121111
// eslint-disable-next-line react-hooks/exhaustive-deps
122112
}, [navigate]);
123113

124-
const system = useEap ? indexedSpan?.['db.system'] : rawSpan?.data?.['db.system'];
125-
const codeFilepath = useEap
126-
? indexedSpan?.['code.filepath']
127-
: rawSpan?.data?.['code.filepath'];
128-
const codeLineno = useEap
129-
? indexedSpan?.['code.lineno']
130-
: rawSpan?.data?.['code.lineno'];
131-
const codeFunction = useEap
132-
? indexedSpan?.['code.function']
133-
: rawSpan?.data?.['code.function'];
114+
const system = indexedSpan?.['db.system'];
115+
const codeFilepath = indexedSpan?.['code.filepath'];
116+
const codeLineno = indexedSpan?.['code.lineno'];
117+
const codeFunction = indexedSpan?.['code.function'];
134118

135119
const formattedDescription = useMemo(() => {
136-
const description = useEap ? indexedSpan?.['span.description'] : rawSpan?.description;
137-
const rawDescription =
138-
description || indexedSpan?.['span.description'] || preliminaryDescription;
120+
const rawDescription = indexedSpan?.['span.description'] || preliminaryDescription;
139121

140122
if (system === SupportedDatabaseSystem.MONGODB) {
141123
let bestDescription = '';
142124

143-
if (
144-
rawSpan?.sentry_tags?.description &&
145-
isValidJson(rawSpan.sentry_tags.description)
146-
) {
147-
bestDescription = rawSpan.sentry_tags.description;
148-
} else if (preliminaryDescription && isValidJson(preliminaryDescription)) {
125+
if (preliminaryDescription && isValidJson(preliminaryDescription)) {
149126
bestDescription = preliminaryDescription;
150127
} else if (
151128
indexedSpan?.['span.description'] &&
152129
isValidJson(indexedSpan?.['span.description'])
153130
) {
154131
bestDescription = indexedSpan?.['span.description'];
155-
} else if (rawSpan?.description && isValidJson(rawSpan.description)) {
156-
bestDescription = rawSpan?.description;
157132
} else {
158133
return rawDescription ?? 'N/A';
159134
}
@@ -162,11 +137,11 @@ export function DatabaseSpanDescription({
162137
}
163138

164139
return formatter.toString(rawDescription ?? '');
165-
}, [preliminaryDescription, rawSpan, indexedSpan, system, useEap]);
140+
}, [preliminaryDescription, indexedSpan, system]);
166141

167142
return (
168143
<Frame>
169-
{areIndexedSpansLoading || isRawSpanLoading ? (
144+
{areIndexedSpansLoading ? (
170145
<WithPadding>
171146
<LoadingIndicator mini />
172147
</WithPadding>
@@ -178,7 +153,7 @@ export function DatabaseSpanDescription({
178153
</QueryClippedBox>
179154
)}
180155

181-
{!areIndexedSpansLoading && !isRawSpanLoading && (
156+
{!areIndexedSpansLoading && (
182157
<Fragment>
183158
{codeFilepath ? (
184159
<StackTraceMiniFrame
@@ -209,11 +184,6 @@ function QueryClippedBox(props: any) {
209184
return <StyledClippedBox {...props} />;
210185
}
211186

212-
const INDEXED_SPAN_SORT = {
213-
field: 'span.self_time',
214-
kind: 'desc' as const,
215-
};
216-
217187
export const Frame = styled('div')`
218188
border: solid 1px ${p => p.theme.border};
219189
border-radius: ${p => p.theme.borderRadius};

0 commit comments

Comments
 (0)