Skip to content

Commit 321451c

Browse files
zarirhamzaida613
authored andcommitted
remaps http status tag to meet ddog convention for otel(#4384)
1 parent 431950a commit 321451c

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

packages/dd-trace/src/opentelemetry/span.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,19 @@ class Span {
179179
}
180180

181181
setAttribute (key, value) {
182+
if (key === 'http.response.status_code') {
183+
this._ddSpan.setTag('http.status_code', value.toString())
184+
}
185+
182186
this._ddSpan.setTag(key, value)
183187
return this
184188
}
185189

186190
setAttributes (attributes) {
191+
if ('http.response.status_code' in attributes) {
192+
attributes['http.status_code'] = attributes['http.response.status_code'].toString()
193+
}
194+
187195
this._ddSpan.addTags(attributes)
188196
return this
189197
}

packages/dd-trace/test/opentelemetry/span.spec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,26 @@ describe('OTel Span', () => {
287287
expect(_tags).to.have.property('baz', 'buz')
288288
})
289289

290+
describe('should remap http.response.status_code', () => {
291+
it('should remap when setting attributes', () => {
292+
const span = makeSpan('name')
293+
294+
const { _tags } = span._ddSpan.context()
295+
296+
span.setAttributes({ 'http.response.status_code': 200 })
297+
expect(_tags).to.have.property('http.status_code', '200')
298+
})
299+
300+
it('should remap when setting singular attribute', () => {
301+
const span = makeSpan('name')
302+
303+
const { _tags } = span._ddSpan.context()
304+
305+
span.setAttribute('http.response.status_code', 200)
306+
expect(_tags).to.have.property('http.status_code', '200')
307+
})
308+
})
309+
290310
it('should set span links', () => {
291311
const span = makeSpan('name')
292312
const span2 = makeSpan('name2')

0 commit comments

Comments
 (0)