From 3cc737c315f0042b003c09ebcdc2f5efb4c7b035 Mon Sep 17 00:00:00 2001 From: rochdev Date: Wed, 13 Mar 2019 16:26:54 -0400 Subject: [PATCH 1/2] update span.addTags() to accept error objects --- src/format.js | 4 ++-- src/opentracing/span.js | 2 +- test/format.spec.js | 9 +++++---- test/opentracing/span.spec.js | 4 ++-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/format.js b/src/format.js index 6097677d506..e6449cfdc99 100644 --- a/src/format.js +++ b/src/format.js @@ -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 diff --git a/src/opentracing/span.js b/src/opentracing/span.js index 547abaabfbe..8fe47abf59c 100644 --- a/src/opentracing/span.js +++ b/src/opentracing/span.js @@ -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) diff --git a/test/format.spec.js b/test/format.spec.js index e790d05067e..2c5fdab6d47 100644 --- a/test/format.spec.js +++ b/test/format.spec.js @@ -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', () => { diff --git a/test/opentracing/span.spec.js b/test/opentracing/span.spec.js index 0af8d5d0f53..3a8bcd16c74 100644 --- a/test/opentracing/span.spec.js +++ b/test/opentracing/span.spec.js @@ -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', () => { From f323d3151f406744d28653de581d4c2b22823f11 Mon Sep 17 00:00:00 2001 From: rochdev Date: Wed, 13 Mar 2019 16:31:16 -0400 Subject: [PATCH 2/2] fix tests relying on string tags --- test/plugins/util/web.spec.js | 4 ++-- test/tracer.spec.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/plugins/util/web.spec.js b/test/plugins/util/web.spec.js index 1bc9d8358a6..51c117bbe72 100644 --- a/test/plugins/util/web.spec.js +++ b/test/plugins/util/web.spec.js @@ -300,7 +300,7 @@ describe('plugins/util/web', () => { res.end() expect(span.context()._tags).to.include({ - [ERROR]: 'true' + [ERROR]: true }) }) @@ -310,7 +310,7 @@ describe('plugins/util/web', () => { res.end() expect(span.context()._tags).to.include({ - [ERROR]: 'true' + [ERROR]: true }) }) diff --git a/test/tracer.spec.js b/test/tracer.spec.js index 2284b7af040..0ce1f8bd747 100644 --- a/test/tracer.spec.js +++ b/test/tracer.spec.js @@ -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 => {