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

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

Merged
merged 2 commits into from
Dec 17, 2020
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 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'
);
});
});
});