Skip to content

Commit

Permalink
fix(node): fill in span data from http request options object
Browse files Browse the repository at this point in the history
  • Loading branch information
vlad-zhukov committed Sep 25, 2023
1 parent 618e992 commit 6c4c1d1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/node/src/integrations/utils/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,16 @@ export function normalizeRequestArgs(
requestOptions = urlToOptions(requestArgs[0]);
} else {
requestOptions = requestArgs[0];

if (!requestOptions.pathname || !requestOptions.search) {
const parsed = new URL(
requestOptions.path || '',
`${requestOptions.protocol || 'http:'}//${requestOptions.hostname}`,
);
requestOptions.pathname = parsed.pathname;
requestOptions.search = parsed.search;
requestOptions.hash = parsed.hash;
}
}

// if the options were given separately from the URL, fold them in
Expand Down
19 changes: 19 additions & 0 deletions packages/node/test/integrations/http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,25 @@ describe('tracing', () => {
expect(spans[1].data['http.fragment']).toEqual('learn-more');
});

it('fills in span data from http.RequestOptions object', () => {
nock('http://dogs.are.great').get('/spaniel?tail=wag&cute=true#learn-more').reply(200);

const transaction = createTransactionOnScope();
const spans = (transaction as unknown as Span).spanRecorder?.spans as Span[];

http.request({ method: 'GET', host: 'dogs.are.great', path: '/spaniel?tail=wag&cute=true#learn-more' });

expect(spans.length).toEqual(2);

// our span is at index 1 because the transaction itself is at index 0
expect(spans[1].description).toEqual('GET http://dogs.are.great/spaniel');
expect(spans[1].op).toEqual('http.client');
expect(spans[1].data['http.method']).toEqual('GET');
expect(spans[1].data.url).toEqual('http://dogs.are.great/spaniel');
expect(spans[1].data['http.query']).toEqual('tail=wag&cute=true');
expect(spans[1].data['http.fragment']).toEqual('learn-more');
});

it.each([
['user:pwd', '[Filtered]:[Filtered]@'],
['user:', '[Filtered]:@'],
Expand Down

0 comments on commit 6c4c1d1

Please sign in to comment.