fix(@opentelemetry/exporter-jaeger): fixed issue #1757 (#1758)

Co-authored-by: Bartlomiej Obecny <bobecny@gmail.com>
This commit is contained in:
Mikhail Sokolov 2020-12-17 18:50:09 +05:00 committed by GitHub
parent c5cbc495f6
commit 14818da153
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 77 additions and 3 deletions

View File

@ -55,9 +55,9 @@ export function spanToThrift(span: ReadableSpan): ThriftSpan {
if (span.status.message) {
tags.push({ key: 'status.message', value: span.status.message });
}
// Ensure that if Status.Code is not OK, that we set the "error" tag on the
// Ensure that if Status.Code is ERROR, that we set the "error" tag on the
// Jaeger span.
if (span.status.code !== StatusCode.OK) {
if (span.status.code === StatusCode.ERROR) {
tags.push({ key: 'error', value: true });
}

View File

@ -21,7 +21,7 @@ import { Resource } from '@opentelemetry/resources';
import * as api from '@opentelemetry/api';
import { ThriftUtils, Utils, ThriftReferenceType } from '../src/types';
import { hrTimeToMicroseconds } from '@opentelemetry/core';
import { TraceFlags } from '@opentelemetry/api';
import { StatusCode, TraceFlags } from '@opentelemetry/api';
describe('transform', () => {
const spanContext = {
@ -302,5 +302,79 @@ describe('transform', () => {
'0000000000000000'
);
});
it('should set error flag only if span.status.code is ERROR', () => {
const readableSpan: ReadableSpan = {
name: 'my-span',
kind: api.SpanKind.INTERNAL,
spanContext,
startTime: [1566156729, 709],
endTime: [1566156731, 709],
ended: true,
status: {
code: api.StatusCode.OK,
},
attributes: {
testBool: true,
testString: 'test',
testNum: 3.142,
},
links: [
{
context: {
traceId: 'a4cda95b652f4a1592b449d5929fda1b',
spanId: '3e0c63257de34c92',
},
attributes: {
testBool: true,
testString: 'test',
testNum: 3.142,
},
},
],
events: [
{
name: 'something happened',
attributes: {
error: true,
},
time: [1566156729, 809],
},
],
duration: [32, 800000000],
resource: new Resource({
service: 'ui',
version: 1,
cost: 112.12,
}),
instrumentationLibrary: {
name: 'default',
version: '0.0.1',
},
};
let thriftSpan = spanToThrift(readableSpan);
assert.strictEqual(
thriftSpan.tags.find(tag => tag.key === 'error'),
undefined,
'If span status OK, no error tag'
);
readableSpan.status.code = StatusCode.UNSET;
thriftSpan = spanToThrift(readableSpan);
assert.strictEqual(
thriftSpan.tags.find(tag => tag.key === 'error'),
undefined,
'If span status USET, no error tag'
);
readableSpan.status.code = StatusCode.ERROR;
thriftSpan = spanToThrift(readableSpan);
const errorTag = thriftSpan.tags.find(tag => tag.key === 'error');
assert.strictEqual(
errorTag?.vBool,
true,
'If span status ERROR, error tag must be true'
);
});
});
});