Skip to content

Commit 48ad138

Browse files
authored
ref(node): Don't strip query strings or fragments from span descriptions (#2882)
Reverts the `span` half of #2857, which added the stripping.
1 parent a5af9c8 commit 48ad138

File tree

3 files changed

+39
-44
lines changed

3 files changed

+39
-44
lines changed

packages/node/src/integrations/http.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getCurrentHub } from '@sentry/core';
22
import { Integration, Span, Transaction } from '@sentry/types';
3-
import { fill, parseSemver, stripUrlQueryAndFragment } from '@sentry/utils';
3+
import { fill, parseSemver } from '@sentry/utils';
44
import * as http from 'http';
55
import * as https from 'https';
66

@@ -158,18 +158,18 @@ function addRequestBreadcrumb(event: string, url: string, req: http.IncomingMess
158158
/**
159159
* Assemble a URL to be used for breadcrumbs and spans.
160160
*
161-
* @param requestArgs URL string or object containing the component parts
161+
* @param url URL string or object containing the component parts
162162
* @returns Fully-formed URL
163163
*/
164-
export function extractUrl(requestArgs: string | http.ClientRequestArgs): string {
165-
if (typeof requestArgs === 'string') {
166-
return stripUrlQueryAndFragment(requestArgs);
164+
export function extractUrl(url: string | http.ClientRequestArgs): string {
165+
if (typeof url === 'string') {
166+
return url;
167167
}
168-
const protocol = requestArgs.protocol || '';
169-
const hostname = requestArgs.hostname || requestArgs.host || '';
168+
const protocol = url.protocol || '';
169+
const hostname = url.hostname || url.host || '';
170170
// Don't log standard :80 (http) and :443 (https) ports to reduce the noise
171-
const port = !requestArgs.port || requestArgs.port === 80 || requestArgs.port === 443 ? '' : `:${requestArgs.port}`;
172-
const path = requestArgs.path ? stripUrlQueryAndFragment(requestArgs.path) : '/';
171+
const port = !url.port || url.port === 80 || url.port === 443 ? '' : `:${url.port}`;
172+
const path = url.path ? url.path : '/';
173173

174174
// internal routes end up with too many slashes
175175
return `${protocol}//${hostname}${port}${path}`.replace('///', '/');

packages/node/test/integrations/http.test.ts

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,12 @@ describe('extractUrl()', () => {
1111
path: '/yay/',
1212
port: 1231,
1313
};
14-
const queryString = '?furry=yes&funny=very';
15-
const fragment = '#adoptnotbuy';
1614

1715
it('accepts a url string', () => {
1816
expect(extractUrl(urlString)).toBe(urlString);
1917
});
2018

2119
it('accepts a http.RequestOptions object and returns a string with everything in the right place', () => {
22-
expect(extractUrl(urlParts)).toBe('http://dogs.are.great:1231/yay/');
20+
expect(extractUrl(urlParts)).toBe(urlString);
2321
});
24-
25-
it('strips query string from url string', () => {
26-
const urlWithQueryString = `${urlString}${queryString}`;
27-
expect(extractUrl(urlWithQueryString)).toBe(urlString);
28-
});
29-
30-
it('strips query string from path in http.RequestOptions object', () => {
31-
const urlPartsWithQueryString = { ...urlParts, path: `${urlParts.path}${queryString}` };
32-
expect(extractUrl(urlPartsWithQueryString)).toBe(urlString);
33-
});
34-
35-
it('strips fragment from url string', () => {
36-
const urlWithFragment = `${urlString}${fragment}`;
37-
expect(extractUrl(urlWithFragment)).toBe(urlString);
38-
});
39-
40-
it('strips fragment from path in http.RequestOptions object', () => {
41-
const urlPartsWithFragment = { ...urlParts, path: `${urlParts.path}${fragment}` };
42-
expect(extractUrl(urlPartsWithFragment)).toBe(urlString);
43-
});
44-
45-
it('strips query string and fragment from url string', () => {
46-
const urlWithQueryStringAndFragment = `${urlString}${queryString}${fragment}`;
47-
expect(extractUrl(urlWithQueryStringAndFragment)).toBe(urlString);
48-
});
49-
50-
it('strips query string and fragment from path in http.RequestOptions object', () => {
51-
const urlPartsWithQueryStringAndFragment = { ...urlParts, path: `${urlParts.path}${queryString}${fragment}` };
52-
expect(extractUrl(urlPartsWithQueryStringAndFragment)).toBe(urlString);
53-
});
54-
}); // end describe('extractUrl()')
22+
});

packages/utils/test/misc.test.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { StackFrame } from '@sentry/types';
22

3-
import { addContextToFrame, getEventDescription, getGlobalObject, parseRetryAfterHeader } from '../src/misc';
3+
import {
4+
addContextToFrame,
5+
getEventDescription,
6+
getGlobalObject,
7+
parseRetryAfterHeader,
8+
stripUrlQueryAndFragment,
9+
} from '../src/misc';
410

511
describe('getEventDescription()', () => {
612
test('message event', () => {
@@ -210,3 +216,24 @@ describe('addContextToFrame', () => {
210216
expect(frame.post_context).toEqual([]);
211217
});
212218
});
219+
220+
describe('stripQueryStringAndFragment', () => {
221+
const urlString = 'http://dogs.are.great:1231/yay/';
222+
const queryString = '?furry=yes&funny=very';
223+
const fragment = '#adoptnotbuy';
224+
225+
it('strips query string from url', () => {
226+
const urlWithQueryString = `${urlString}${queryString}`;
227+
expect(stripUrlQueryAndFragment(urlWithQueryString)).toBe(urlString);
228+
});
229+
230+
it('strips fragment from url', () => {
231+
const urlWithFragment = `${urlString}${fragment}`;
232+
expect(stripUrlQueryAndFragment(urlWithFragment)).toBe(urlString);
233+
});
234+
235+
it('strips query string and fragment from url', () => {
236+
const urlWithQueryStringAndFragment = `${urlString}${queryString}${fragment}`;
237+
expect(stripUrlQueryAndFragment(urlWithQueryStringAndFragment)).toBe(urlString);
238+
});
239+
});

0 commit comments

Comments
 (0)