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 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('SERVER'); span.setTimestamp(1); span.setDuration(1); const spanThrift = deserialize(THRIFT.encode(span)); expect(spanThrift.timestamp.toNumber()).to.equal(1); expect(spanThrift.duration.toNumber()).to.equal(1); });
describe('Model', () => { describe('Endpoint', () => { it('should have correct type', () => { const endpoint: model.Endpoint = new model.Endpoint({ serviceName: 'Unknown', ipv4: '10.0.0.1', port: 8000 }); expect(endpoint.setIpv4).to.be.a('function'); }); }); describe('Span', () => { it('should have correct type', () => { const span: model.Span = new model.Span(new TraceId({ traceId: 'a', spanId: 'b' })); expect(span.traceId).to.be.a('string'); }); }); });
// make sure nothing strange happens like object interpretation of dots it('should serialize tags with dotted names as binary annotations', () => { const span = new Span(new TraceId({ spanId: '000000000000162e' })); span.setName('GET'); span.putTag('http.path', '/api'); const expected = new thriftTypes.Span(); expected.trace_id = '000000000000162e'; expected.id = '000000000000162e'; expected.name = 'get'; expected.binary_annotations = [ new thriftTypes.BinaryAnnotation({ key: 'http.path', value: Buffer.from('/api'), annotation_type: thriftTypes.AnnotationType.STRING }) ]; expect(THRIFT.encode(span)).to.deep.equal(serialize(expected)); });
spanId: '000000000000162e' })); span.setName('GET'); span.setKind('CLIENT'); span.setRemoteEndpoint(new Endpoint({ serviceName: 'there', ipv4: '10.57.50.84',
spanId: 'c' })); span.setName('GET'); span.setLocalEndpoint(new Endpoint({ serviceName: 'PortalService', ipv4: '10.57.50.83', port: 8080 })); span.setKind('SERVER'); span.setTimestamp(1); span.setDuration(1); span.setShared(true); span.putTag('warning', 'The cake is a lie');
it('should not set timestamp or duration on shared span', () => { const span = new Span(new TraceId({ traceId: 'a', parentId: new Some('b'), spanId: 'c' })); span.setName('GET'); span.setKind('SERVER'); span.setTimestamp(1); span.setDuration(1); span.setShared(true); const spanThrift = deserialize(THRIFT.encode(span)); expect(spanThrift.timestamp).to.equal(null); expect(spanThrift.duration).to.equal(null); });
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 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('SERVER'); span.setTimestamp(1); span.setDuration(1); const spanThrift = deserialize(THRIFT.encode(span)); expect(spanThrift.timestamp.toNumber()).to.equal(1); expect(spanThrift.duration.toNumber()).to.equal(1); });
it('should not set timestamp or duration on shared span', () => { const span = new Span(new TraceId({ traceId: 'a', parentId: new Some('b'), spanId: 'c' })); span.setName('GET'); span.setKind('SERVER'); span.setTimestamp(1); span.setDuration(1); span.setShared(true); const spanThrift = deserialize(THRIFT.encode(span)); expect(spanThrift.timestamp).to.equal(null); expect(spanThrift.duration).to.equal(null); });
// make sure nothing strange happens like object interpretation of dots it('should serialize tags with dotted names as binary annotations', () => { const span = new Span(new TraceId({ spanId: '000000000000162e' })); span.setName('GET'); span.putTag('http.path', '/api'); const expected = new thriftTypes.Span(); expected.trace_id = '000000000000162e'; expected.id = '000000000000162e'; expected.name = 'get'; expected.binary_annotations = [ new thriftTypes.BinaryAnnotation({ key: 'http.path', value: Buffer.from('/api'), annotation_type: thriftTypes.AnnotationType.STRING }) ]; expect(THRIFT.encode(span)).to.deep.equal(serialize(expected)); });
describe('Model', () => { describe('Endpoint', () => { it('should have correct type', () => { const endpoint: model.Endpoint = new model.Endpoint({ serviceName: 'Unknown', ipv4: '10.0.0.1', port: 8000 }); expect(endpoint.setIpv4).to.be.a('function'); }); }); describe('Span', () => { it('should have correct type', () => { const span: model.Span = new model.Span(new TraceId({ traceId: 'a', spanId: 'b' })); expect(span.traceId).to.be.a('string'); }); }); });
spanId: '000000000000162e' })); span.setName('GET'); span.setKind('CLIENT'); span.setRemoteEndpoint(new Endpoint({ serviceName: 'there', ipv4: '10.57.50.84',
spanId: 'c' })); span.setName('GET'); span.setLocalEndpoint(new Endpoint({ serviceName: 'PortalService', ipv4: '10.57.50.83', port: 8080 })); span.setKind('SERVER'); span.setTimestamp(1); span.setDuration(1); span.setShared(true); span.putTag('warning', 'The cake is a lie');