it('should write a parent ID when present', () => { const span = new Span(new TraceId({ traceId: '000000000000162e', parentId: new Some('000000000000abcd'), spanId: '000000000000efgh' })); expect(JSON_V1.encode(span)).to.contain( '{"traceId":"000000000000162e","parentId":"000000000000abcd"' ); });
function makeTestTraceId({debug = false, sampled = None}) { return new TraceId({ traceId: 'abc', parentId: new Some('123'), spanId: 'fab', sampled, debug }); }
describe('JsonEncoder', () => { it('should have correct type', () => { const v1: JsonEncoder = jsonEncoder.JSON_V1; const v2: JsonEncoder = jsonEncoder.JSON_V2; const span: model.Span = new model.Span(new TraceId({ spanId: 'xyz' })); expect(v1.encode(span)).to.be.a('string'); expect(v2.encode(span)).to.be.a('string'); }); });
it('should write trace ID high when input is a 128-bit trace ID', () => { const span = new Span(new TraceId({ traceId: '00000000000004d2000000000000162e', spanId: '000000000000162e' })); const expected = new thriftTypes.Span(); expected.trace_id_high = '00000000000004d2'; expected.trace_id = '000000000000162e'; expected.id = '000000000000162e'; expected.name = ''; expect(THRIFT.encode(span)).to.deep.equal(serialize(expected)); });
it('should set timestamp and duration on client span', () => { const span = new Span(new TraceId({ traceId: 'a', parentId: new Some('b'), spanId: 'c' })); span.setName('GET'); span.setKind('CLIENT'); span.setTimestamp(1); span.setDuration(1); expect(JSON_V1.encode(span)).to.contain('"timestamp":1,"duration":1,'); });
it('should write a debug flag', () => { const span = new Span(new TraceId({ traceId: '00000000000004d2000000000000162e', spanId: '000000000000162e', debug: true })); expect(JSON_V1.encode(span)).to.contain(',"debug":true}'); });
it('should set shared', () => { const span = new Span(new TraceId({ traceId: 'a', parentId: new Some('b'), spanId: 'c', shared: true })); const spanJson = JSON_V2.encode(span); expect(spanJson).to.contain('"shared":true'); });
// v1 format requires an empty span name. v2 can leave it out it('should write minimum fields, notably an empty span name', () => { const span = new Span(new TraceId({ spanId: '000000000000162e' })); expect(JSON_V1.encode(span)).to.equal( '{"traceId":"000000000000162e","id":"000000000000162e","name":""}' ); });
it('should write a parent ID when present', () => { const span = new Span(new TraceId({ traceId: '000000000000162e', parentId: new Some('000000000000abcd'), spanId: '000000000000efgh' })); expect(JSON_V1.encode(span)).to.contain( '{"traceId":"000000000000162e","parentId":"000000000000abcd"' ); });
it('should write a 128-bit trace ID', () => { const span = new Span(new TraceId({ traceId: '00000000000004d2000000000000162e', spanId: '000000000000162e' })); expect(JSON_V1.encode(span)).to.contain( '{"traceId":"00000000000004d2000000000000162e"' ); });
it('should write a debug flag', () => { const span = new Span(new TraceId({ traceId: '00000000000004d2000000000000162e', spanId: '000000000000162e', debug: true })); expect(JSON_V1.encode(span)).to.contain(',"debug":true}'); });
it('should write a 128-bit trace ID', () => { const span = new Span(new TraceId({ traceId: '00000000000004d2000000000000162e', spanId: '000000000000162e' })); expect(JSON_V2.encode(span)).to.contain( '{"traceId":"00000000000004d2000000000000162e"' ); });
it('should write a parent ID when present', () => { const span = new Span(new TraceId({ traceId: '000000000000162e', parentId: new Some('000000000000abcd'), spanId: '000000000000efgh' })); expect(JSON_V2.encode(span)).to.contain( '{"traceId":"000000000000162e","parentId":"000000000000abcd"' ); });
it('should write minimum fields', () => { const span = new Span(new TraceId({ spanId: '000000000000162e' })); expect(JSON_V2.encode(span)).to.equal( '{"traceId":"000000000000162e","id":"000000000000162e"}' ); });
it('should set timestamp and duration on client span', () => { const span = new Span(new TraceId({ traceId: 'a', parentId: new Some('b'), spanId: 'c' })); span.setName('GET'); span.setKind('CLIENT'); span.setTimestamp(1); span.setDuration(1); expect(JSON_V2.encode(span)).to.contain('"timestamp":1,"duration":1}'); });