Skip to content

Commit b08ef8a

Browse files
committed
feat(node): Add http.method to node http spans
1 parent 646b54d commit b08ef8a

File tree

5 files changed

+18
-6
lines changed

5 files changed

+18
-6
lines changed

packages/node/src/integrations/http.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ function _createWrappedRequestMethodFactory(
189189

190190
const requestSpanData: SanitizedRequestData = {
191191
url: requestUrl,
192-
method: requestOptions.method || 'GET',
192+
'http.method': requestOptions.method || 'GET',
193193
};
194194
if (requestOptions.hash) {
195195
// strip leading "#"

packages/node/src/integrations/undici/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,20 @@ export class Undici implements Integration {
111111
const shouldCreateSpan = this._options.shouldCreateSpanForRequest(stringUrl);
112112

113113
if (shouldCreateSpan) {
114-
const data: Record<string, unknown> = {};
114+
const method = request.method || 'GET';
115+
const data: Record<string, unknown> = {
116+
'http.method': method,
117+
};
115118
const params = url.searchParams.toString();
116119
if (params) {
117120
data['http.query'] = `?${params}`;
118121
}
119122
if (url.hash) {
120123
data['http.fragment'] = url.hash;
121124
}
122-
123125
const span = activeSpan.startChild({
124126
op: 'http.client',
125-
description: `${request.method || 'GET'} ${stripUrlQueryAndFragment(stringUrl)}`,
127+
description: `${method} ${stripUrlQueryAndFragment(stringUrl)}`,
126128
data,
127129
});
128130
request.__sentry__ = span;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ describe('tracing', () => {
208208
// our span is at index 1 because the transaction itself is at index 0
209209
expect(spans[1].description).toEqual('GET http://dogs.are.great/spaniel');
210210
expect(spans[1].op).toEqual('http.client');
211-
expect(spans[1].data.method).toEqual('GET');
211+
expect(spans[1].data['http.method']).toEqual('GET');
212212
expect(spans[1].data.url).toEqual('http://dogs.are.great/spaniel');
213213
expect(spans[1].data['http.query']).toEqual('tail=wag&cute=true');
214214
expect(spans[1].data['http.fragment']).toEqual('learn-more');

packages/node/test/integrations/undici.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ conditionalTest({ min: 16 })('Undici integration', () => {
5656
{
5757
description: 'GET http://localhost:18099/',
5858
op: 'http.client',
59+
data: {
60+
'http.method': 'GET',
61+
},
5962
},
6063
],
6164
[
@@ -66,6 +69,7 @@ conditionalTest({ min: 16 })('Undici integration', () => {
6669
description: 'GET http://localhost:18099/',
6770
op: 'http.client',
6871
data: {
72+
'http.method': 'GET',
6973
'http.query': '?foo=bar',
7074
},
7175
},
@@ -76,6 +80,9 @@ conditionalTest({ min: 16 })('Undici integration', () => {
7680
{ method: 'POST' },
7781
{
7882
description: 'POST http://localhost:18099/',
83+
data: {
84+
'http.method': 'POST',
85+
},
7986
},
8087
],
8188
[
@@ -84,6 +91,9 @@ conditionalTest({ min: 16 })('Undici integration', () => {
8491
{ method: 'POST' },
8592
{
8693
description: 'POST http://localhost:18099/',
94+
data: {
95+
'http.method': 'POST',
96+
},
8797
},
8898
],
8999
[

packages/types/src/request.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export type QueryParams = string | { [key: string]: string } | Array<[string, st
1818
*/
1919
export type SanitizedRequestData = {
2020
url: string;
21-
method: string;
21+
'http.method': string;
2222
'http.fragment'?: string;
2323
'http.query'?: string;
2424
};

0 commit comments

Comments
 (0)