Skip to content

Commit 0996a67

Browse files
committed
fix(opentelemetry): Do not overwrite http span name if kind is internal
1 parent 21830b1 commit 0996a67

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

packages/opentelemetry/src/utils/parseSpanDescription.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,14 @@ export function descriptionForHttpMethod(
163163
data['http.fragment'] = fragment;
164164
}
165165

166+
// If the span kind is neither client nor server, we use the original name
167+
// this infers that somebody manually started this span, in which case we don't want to overwrite the name
168+
const isClientOrServerKind = kind === SpanKind.CLIENT || kind === SpanKind.SERVER;
169+
166170
return {
167171
op: opParts.join('.'),
168-
description,
169-
source,
172+
description: isClientOrServerKind ? description : name,
173+
source: isClientOrServerKind ? source : 'custom',
170174
data,
171175
};
172176
}

packages/opentelemetry/test/utils/parseSpanDescription.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,25 @@ describe('descriptionForHttpMethod', () => {
231231
source: 'route',
232232
},
233233
],
234+
[
235+
'works with basic client GET with SpanKind.INTERNAL',
236+
'GET',
237+
{
238+
[SEMATTRS_HTTP_METHOD]: 'GET',
239+
[SEMATTRS_HTTP_URL]: 'https://www.example.com/my-path',
240+
[SEMATTRS_HTTP_TARGET]: '/my-path',
241+
},
242+
'test name',
243+
SpanKind.INTERNAL,
244+
{
245+
op: 'http',
246+
description: 'test name',
247+
data: {
248+
url: 'https://www.example.com/my-path',
249+
},
250+
source: 'custom',
251+
},
252+
],
234253
])('%s', (_, httpMethod, attributes, name, kind, expected) => {
235254
const actual = descriptionForHttpMethod({ attributes, kind, name }, httpMethod);
236255
expect(actual).toEqual(expected);

0 commit comments

Comments
 (0)