Skip to content

Commit

Permalink
remaps http status tag to meet ddog convention for otel(#4384)
Browse files Browse the repository at this point in the history
  • Loading branch information
zarirhamza authored and ida613 committed Jun 10, 2024
1 parent 431950a commit 321451c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/dd-trace/src/opentelemetry/span.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,19 @@ class Span {
}

setAttribute (key, value) {
if (key === 'http.response.status_code') {
this._ddSpan.setTag('http.status_code', value.toString())
}

this._ddSpan.setTag(key, value)
return this
}

setAttributes (attributes) {
if ('http.response.status_code' in attributes) {
attributes['http.status_code'] = attributes['http.response.status_code'].toString()
}

this._ddSpan.addTags(attributes)
return this
}
Expand Down
20 changes: 20 additions & 0 deletions packages/dd-trace/test/opentelemetry/span.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,26 @@ describe('OTel Span', () => {
expect(_tags).to.have.property('baz', 'buz')
})

describe('should remap http.response.status_code', () => {
it('should remap when setting attributes', () => {
const span = makeSpan('name')

const { _tags } = span._ddSpan.context()

span.setAttributes({ 'http.response.status_code': 200 })
expect(_tags).to.have.property('http.status_code', '200')
})

it('should remap when setting singular attribute', () => {
const span = makeSpan('name')

const { _tags } = span._ddSpan.context()

span.setAttribute('http.response.status_code', 200)
expect(_tags).to.have.property('http.status_code', '200')
})
})

it('should set span links', () => {
const span = makeSpan('name')
const span2 = makeSpan('name2')
Expand Down

0 comments on commit 321451c

Please sign in to comment.