Skip to content

Commit 2d15c2b

Browse files
authored
fix(n1-api-call): Properly parse sanitized span descriptions (#46195)
This is an FE aspect of #46187. For N+1 API Call performance issues, we need to parse the URLs and extract the query parameters. With newer SDK versions, the query parameters might be in a separate key in span data called `http.query`, rather than being appended to the description or the `url` key in span data.
1 parent 8ad22e7 commit 2d15c2b

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

static/app/components/events/interfaces/performance/spanEvidenceKeyValueList.spec.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,10 @@ describe('SpanEvidenceKeyValueList', () => {
385385
extractSpanURLString({
386386
span_id: 'a',
387387
data: {
388-
url: 'http://service.io',
388+
url: 'http://service.io?id=2543',
389389
},
390390
})?.toString()
391-
).toEqual('http://service.io/');
391+
).toEqual('http://service.io/?id=2543');
392392
});
393393

394394
it('Pulls out a relative URL if a base is provided', () => {
@@ -405,6 +405,19 @@ describe('SpanEvidenceKeyValueList', () => {
405405
).toEqual('http://service.io/item');
406406
});
407407

408+
it('Fetches the query string from the span data if available', () => {
409+
expect(
410+
extractSpanURLString({
411+
span_id: 'a',
412+
description: 'GET http://service.io/item',
413+
data: {
414+
url: 'http://service.io/item',
415+
'http.query': 'id=153',
416+
},
417+
})?.toString()
418+
).toEqual('http://service.io/item?id=153');
419+
});
420+
408421
it('Falls back to span description if URL is faulty', () => {
409422
expect(
410423
extractSpanURLString({

static/app/components/events/interfaces/performance/spanEvidenceKeyValueList.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,13 +477,23 @@ function formatChangingQueryParameters(spans: Span[], baseURL?: string): string[
477477
return pairs;
478478
}
479479

480+
/** Parses the span data and pulls out the URL. Accounts for different SDKs and
481+
different versions of SDKs formatting and parsing the URL contents
482+
differently. Mirror of `get_url_from_span`. Ideally, this should not exist,
483+
and instead it should use the data provided by the backend */
480484
export const extractSpanURLString = (span: Span, baseURL?: string): URL | null => {
481485
let URLString;
482486

483487
URLString = span?.data?.url;
484488
if (URLString) {
485489
try {
486-
return new URL(span?.data?.url, baseURL);
490+
let url = span?.data?.url ?? '';
491+
const query = span?.data?.['http.query'];
492+
if (query) {
493+
url += `?${query}`;
494+
}
495+
496+
return new URL(url, baseURL);
487497
} catch (e) {
488498
// Ignore error
489499
}

0 commit comments

Comments
 (0)