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'); }); });
describe('Aws SQS transport', () => { it('Using normal constructor', () => { const logger = new AwsSqsLogger({queueUrl: 'http://localhost:4568'}); expect(logger.encoding.encode({ traceId: 'a', id: 'b', annotations: [], tags: {} })) .to.equal('{"traceId":"a","id":"b"}'); }); });
logSpan(span) { const encodedSpan = this.encoding.encode(span); if (this._getPayloadSize(encodedSpan) >= this.messageMaxBytes) { this.processQueue(); if (this._getPayloadSize(encodedSpan) > this.messageMaxBytes) { // Payload size is too large even with an empty queue, we can only drop const err = 'Zipkin span got dropped, reason: payload too large'; if (this.errorListenerSet) { this.emit('error', new Error(err)); } else { this.log.error(err); } return; } } this.queue.push(encodedSpan); this.queueBytes += encodedSpan.length; }
constructor({localServiceName}) { // TODO see if we can conditionally load from package because when testing zipkin itself we want // to use explicit paths const { BatchRecorder, ExplicitContext, TraceId, Tracer, jsonEncoder: {JSON_V2} } = require('zipkin'); this._spans = []; this._tracer = new Tracer({ ctxImpl: new ExplicitContext(), localServiceName, recorder: new BatchRecorder({ logger: { logSpan: (span) => { this._spans.push(JSON.parse(JSON_V2.encode(span))); } } }) }); this._sentinelTraceId = this._tracer.id; this._debugId = new TraceId({spanId: this._tracer.id.traceId, debug: true}); }
} else if (options.encoder === JSON_V2) { this.encoder = {encode: span => `[${JSON_V2.encode(span)}]`}; } else { throw new Error('Unsupported encoder. Valid choices are THRIFT and JSON_V2.');
describe('Aws SQS transport', () => { it('Using normal constructor', () => { const logger = new AwsSqsLogger({queueUrl: 'http://localhost:4568'}); expect(logger.encoding.encode({ traceId: 'a', id: 'b', annotations: [], tags: {} })) .to.equal('{"traceId":"a","id":"b"}'); }); });
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'); }); });
logSpan(span) { const encodedSpan = this.encoding.encode(span); if (this._getPayloadSize(encodedSpan) >= this.messageMaxBytes) { this.processQueue(); if (this._getPayloadSize(encodedSpan) > this.messageMaxBytes) { // Payload size is too large even with an empty queue, we can only drop const err = 'Zipkin span got dropped, reason: payload too large'; if (this.errorListenerSet) { this.emit('error', new Error(err)); } else { this.log.error(err); } return; } } this.queue.push(encodedSpan); this.queueBytes += encodedSpan.length; }
} else if (options.encoder === JSON_V2) { this.encoder = {encode: span => `[${JSON_V2.encode(span)}]`}; } else { throw new Error('Unsupported encoder. Valid choices are THRIFT and JSON_V2.');