Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update span.addTags() to accept error objects #486

Merged
merged 2 commits into from
Mar 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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])
brettlangdon marked this conversation as resolved.
Show resolved Hide resolved
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