Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit 44b68f7

Browse files
tcolgatekjin
authored andcommitted
fix: fix for non-null parentSpanId (#66)
* fix: thrift encoding of non-null parentSpanId fails * test: add test for span encoding
1 parent 89acafb commit 44b68f7

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

packages/opencensus-exporter-jaeger/src/jaeger-driver/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,14 @@ export function spanToThrift(span: Span) {
6060
const spanLogs = [];
6161
const unsigned = true;
6262
const length = span.spanContext.traceId.length;
63+
const parentSpan = span.parentSpanId ? Utils.encodeInt64(span.parentSpanId) :
64+
ThriftUtils.emptyBuffer;
6365

6466
return {
6567
traceIdLow: Utils.encodeInt64(span.spanContext.traceId),
6668
traceIdHigh: ThriftUtils.emptyBuffer,
6769
spanId: Utils.encodeInt64(span.spanContext.spanId),
68-
parentSpanId: span.parentSpanId || ThriftUtils.emptyBuffer,
70+
parentSpanId: parentSpan,
6971
operationName: span.name,
7072
references: [],
7173
flags: span.spanContext.options || 0x1,

packages/opencensus-exporter-jaeger/test/test-jaeger.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import * as nock from 'nock';
2323
import * as shimmer from 'shimmer';
2424

2525
import {JaegerTraceExporter, JaegerTraceExporterOptions} from '../src/';
26-
import {UDPSender} from '../src/jaeger-driver';
26+
import {spanToThrift, ThriftUtils, UDPSender} from '../src/jaeger-driver';
2727

2828
const DEFAULT_BUFFER_TIMEOUT = 10; // time in milliseconds
2929

@@ -75,6 +75,19 @@ describe('Jaeger Exporter', () => {
7575
exporter.close();
7676
});
7777

78+
/* Should export spans to Jeager */
79+
describe('test spans are valid', () => {
80+
it('should encode as thrift', () => {
81+
return tracer.startRootSpan({name: 'root-s01'}, (rootSpan) => {
82+
const span = tracer.startChildSpan('child-s01');
83+
span.end();
84+
rootSpan.end();
85+
const thriftSpan = spanToThrift(span);
86+
const result = ThriftUtils._thrift.Span.rw.toBuffer(thriftSpan);
87+
assert.strictEqual(result.err, null);
88+
});
89+
});
90+
});
7891

7992
/* Should export spans to Jeager */
8093
describe('publish()', () => {

0 commit comments

Comments
 (0)