Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,10 @@ describe('SpanEvidenceKeyValueList', () => {
extractSpanURLString({
span_id: 'a',
data: {
url: 'http://service.io',
url: 'http://service.io?id=2543',
},
})?.toString()
).toEqual('http://service.io/');
).toEqual('http://service.io/?id=2543');
});

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

it('Fetches the query string from the span data if available', () => {
expect(
extractSpanURLString({
span_id: 'a',
description: 'GET http://service.io/item',
data: {
url: 'http://service.io/item',
'http.query': 'id=153',
},
})?.toString()
).toEqual('http://service.io/item?id=153');
});

it('Falls back to span description if URL is faulty', () => {
expect(
extractSpanURLString({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,13 +477,23 @@ function formatChangingQueryParameters(spans: Span[], baseURL?: string): string[
return pairs;
}

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

URLString = span?.data?.url;
if (URLString) {
try {
return new URL(span?.data?.url, baseURL);
let url = span?.data?.url ?? '';
const query = span?.data?.['http.query'];
if (query) {
url += `?${query}`;
}

return new URL(url, baseURL);
} catch (e) {
// Ignore error
}
Expand Down