Skip to content

Commit ea450e2

Browse files
committed
fix(@opentelemetry/exporter-jaeger): fixed issue #1757
1 parent c478cc1 commit ea450e2

File tree

2 files changed

+77
-3
lines changed

2 files changed

+77
-3
lines changed

packages/opentelemetry-exporter-jaeger/src/transform.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ export function spanToThrift(span: ReadableSpan): ThriftSpan {
5555
if (span.status.message) {
5656
tags.push({ key: 'status.message', value: span.status.message });
5757
}
58-
// Ensure that if Status.Code is not OK, that we set the "error" tag on the
58+
// Ensure that if Status.Code is ERROR, that we set the "error" tag on the
5959
// Jaeger span.
60-
if (span.status.code !== StatusCode.OK) {
60+
if (span.status.code === StatusCode.ERROR) {
6161
tags.push({ key: 'error', value: true });
6262
}
6363

packages/opentelemetry-exporter-jaeger/test/transform.test.ts

+75-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { Resource } from '@opentelemetry/resources';
2121
import * as api from '@opentelemetry/api';
2222
import { ThriftUtils, Utils, ThriftReferenceType } from '../src/types';
2323
import { hrTimeToMicroseconds } from '@opentelemetry/core';
24-
import { TraceFlags } from '@opentelemetry/api';
24+
import { StatusCode, TraceFlags } from '@opentelemetry/api';
2525

2626
describe('transform', () => {
2727
const spanContext = {
@@ -302,5 +302,79 @@ describe('transform', () => {
302302
'0000000000000000'
303303
);
304304
});
305+
it('should set error flag only if span.status.code is ERROR', () => {
306+
const readableSpan: ReadableSpan = {
307+
name: 'my-span',
308+
kind: api.SpanKind.INTERNAL,
309+
spanContext,
310+
startTime: [1566156729, 709],
311+
endTime: [1566156731, 709],
312+
ended: true,
313+
status: {
314+
code: api.StatusCode.OK,
315+
},
316+
attributes: {
317+
testBool: true,
318+
testString: 'test',
319+
testNum: 3.142,
320+
},
321+
links: [
322+
{
323+
context: {
324+
traceId: 'a4cda95b652f4a1592b449d5929fda1b',
325+
spanId: '3e0c63257de34c92',
326+
},
327+
attributes: {
328+
testBool: true,
329+
testString: 'test',
330+
testNum: 3.142,
331+
},
332+
},
333+
],
334+
events: [
335+
{
336+
name: 'something happened',
337+
attributes: {
338+
error: true,
339+
},
340+
time: [1566156729, 809],
341+
},
342+
],
343+
duration: [32, 800000000],
344+
resource: new Resource({
345+
service: 'ui',
346+
version: 1,
347+
cost: 112.12,
348+
}),
349+
instrumentationLibrary: {
350+
name: 'default',
351+
version: '0.0.1',
352+
},
353+
};
354+
let thriftSpan = spanToThrift(readableSpan);
355+
assert.strictEqual(
356+
thriftSpan.tags.find(tag => tag.key === 'error'),
357+
undefined,
358+
'If span status OK, no error tag'
359+
);
360+
361+
readableSpan.status.code = StatusCode.UNSET;
362+
thriftSpan = spanToThrift(readableSpan);
363+
assert.strictEqual(
364+
thriftSpan.tags.find(tag => tag.key === 'error'),
365+
undefined,
366+
'If span status USET, no error tag'
367+
);
368+
369+
readableSpan.status.code = StatusCode.ERROR;
370+
thriftSpan = spanToThrift(readableSpan);
371+
const errorTag = thriftSpan.tags.find(tag => tag.key === 'error');
372+
373+
assert.strictEqual(
374+
errorTag?.vBool,
375+
true,
376+
'If span status ERROR, error tag must be true'
377+
);
378+
});
305379
});
306380
});

0 commit comments

Comments
 (0)