From 432805344d006b2fec7d4a6d0f629c740f9df3a2 Mon Sep 17 00:00:00 2001 From: Ji Zhang Date: Fri, 8 Jun 2018 10:25:09 +0800 Subject: [PATCH] fail the span if error tag is true - following opentracing standard, error tag should be true if the span has failed - discard the tag in meta since the backend relies on the error flag --- src/format.js | 5 +++++ test/format.spec.js | 28 +++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/format.js b/src/format.js index 9661925c21b..1c5d7adcd20 100644 --- a/src/format.js +++ b/src/format.js @@ -43,6 +43,11 @@ function extractTags (trace, tags) { case 'resource.name': trace[map[tag]] = String(tags[tag]) break + case 'error': + if (tags[tag]) { + trace.error = 1 + } + break case 'error.type': case 'error.msg': case 'error.stack': diff --git a/test/format.spec.js b/test/format.spec.js index 3fc52241a70..1d64b7891e5 100644 --- a/test/format.spec.js +++ b/test/format.spec.js @@ -86,7 +86,33 @@ describe('format', () => { expect(trace.meta['error.stack']).to.equal(span._error.stack) }) - it('should set the error flag when there is an error tag', () => { + describe('when there is an `error` tag ', () => { + it('should set the error flag when error tag is true', () => { + span._tags['error'] = true + + trace = format(span) + + expect(trace.error).to.equal(1) + }) + + it('should not set the error flag when error is false', () => { + span._tags['error'] = false + + trace = format(span) + + expect(trace.error).to.equal(0) + }) + + it('should not extract error to meta', () => { + span._tags['error'] = true + + trace = format(span) + + expect(trace.meta['error']).to.be.undefined + }) + }) + + it('should set the error flag when there is an error-related tag', () => { span._tags['error.type'] = 'Error' span._tags['error.msg'] = 'boom' span._tags['error.stack'] = ''