Skip to content

Commit

Permalink
update span.addTags() to accept error objects (#486)
Browse files Browse the repository at this point in the history
  • Loading branch information
rochdev authored Mar 14, 2019
1 parent 1d62725 commit 74e59d6
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ function extractTags (trace, span) {
}

function extractError (trace, span) {
const error = span._error
const error = span.context()._tags['error']

if (error) {
if (error instanceof Error) {
trace.meta['error.msg'] = error.message
trace.meta['error.type'] = error.name
trace.meta['error.stack'] = error.stack
Expand Down
2 changes: 1 addition & 1 deletion src/opentracing/span.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class DatadogSpan extends Span {
_addTags (keyValuePairs) {
try {
Object.keys(keyValuePairs).forEach(key => {
this._spanContext._tags[key] = String(keyValuePairs[key])
this._spanContext._tags[key] = keyValuePairs[key]
})
} catch (e) {
log.error(e)
Expand Down
9 changes: 5 additions & 4 deletions test/format.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,14 @@ describe('format', () => {
})

it('should extract errors', () => {
span._error = new Error('boom')
const error = new Error('boom')

spanContext._tags['error'] = error
trace = format(span)

expect(trace.meta['error.msg']).to.equal('boom')
expect(trace.meta['error.type']).to.equal('Error')
expect(trace.meta['error.stack']).to.equal(span._error.stack)
expect(trace.meta['error.msg']).to.equal(error.message)
expect(trace.meta['error.type']).to.equal(error.name)
expect(trace.meta['error.stack']).to.equal(error.stack)
})

it('should extract the origin', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/opentracing/span.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ describe('Span', () => {
expect(span.context()._tags).to.have.property('foo', 'bar')
})

it('should ensure tags are strings', () => {
it('should store the original values', () => {
span = new Span(tracer, recorder, sampler, prioritySampler, { operationName: 'operation' })
span.addTags({ foo: 123 })

expect(span.context()._tags).to.have.property('foo', '123')
expect(span.context()._tags).to.have.property('foo', 123)
})

it('should handle errors', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/plugins/util/web.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ describe('plugins/util/web', () => {
res.end()

expect(span.context()._tags).to.include({
[ERROR]: 'true'
[ERROR]: true
})
})

Expand All @@ -310,7 +310,7 @@ describe('plugins/util/web', () => {
res.end()

expect(span.context()._tags).to.include({
[ERROR]: 'true'
[ERROR]: true
})
})

Expand Down
6 changes: 3 additions & 3 deletions test/tracer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ describe('Tracer', () => {

it('should support analytics', () => {
tracer.trace('name', { analytics: true }, span => {
expect(span.context()._tags).to.have.property(ANALYTICS_SAMPLE_RATE, '1')
expect(span.context()._tags).to.have.property(ANALYTICS_SAMPLE_RATE, 1)
})

tracer.trace('name', { analytics: false }, span => {
expect(span.context()._tags).to.have.property(ANALYTICS_SAMPLE_RATE, '0')
expect(span.context()._tags).to.have.property(ANALYTICS_SAMPLE_RATE, 0)
})

tracer.trace('name', { analytics: 0.5 }, span => {
expect(span.context()._tags).to.have.property(ANALYTICS_SAMPLE_RATE, '0.5')
expect(span.context()._tags).to.have.property(ANALYTICS_SAMPLE_RATE, 0.5)
})

tracer.trace('name', { analytics: 2 }, span => {
Expand Down

0 comments on commit 74e59d6

Please sign in to comment.