Skip to content

Commit

Permalink
fix(@opentelemetry/exporter-jaeger): fixed issue #1757 (#1758)
Browse files Browse the repository at this point in the history
Co-authored-by: Bartlomiej Obecny <[email protected]>
  • Loading branch information
debagger and obecny authored Dec 17, 2020
1 parent c5cbc49 commit 14818da
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/opentelemetry-exporter-jaeger/src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}

Expand Down
76 changes: 75 additions & 1 deletion packages/opentelemetry-exporter-jaeger/test/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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'
);
});
});
});

0 comments on commit 14818da

Please sign in to comment.