zipkin-core
Advanced tools
Comparing version 0.1.2 to 0.1.3
{ | ||
"name": "zipkin-core", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "The core tracer for zipkin.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
const {Some, verifyIsOptional} = require('./option'); | ||
class TraceId { | ||
constructor({traceId, parentId, spanId, sampled}) { | ||
constructor({traceId, parentId, spanId, sampled, flags = 0}) { | ||
verifyIsOptional(traceId); | ||
@@ -12,3 +12,3 @@ verifyIsOptional(parentId); | ||
this._sampled = sampled; | ||
this._flags = 0; | ||
this._flags = flags; | ||
} | ||
@@ -15,0 +15,0 @@ |
@@ -9,5 +9,7 @@ const {now} = require('./time'); | ||
} = require('./internalRepresentations'); | ||
const {Sampler, alwaysSample} = require('./sampler'); | ||
function ZipkinTracer({ | ||
logger, | ||
sampler = new Sampler(alwaysSample), | ||
timeout = 60 * 1000000 // default timeout = 60 seconds | ||
@@ -18,5 +20,8 @@ }) { | ||
function writeSpan(id) { | ||
logger.logSpan(partialSpans.get(id)); | ||
const spanToWrite = partialSpans.get(id); | ||
// ready for garbage collection | ||
partialSpans.delete(id); | ||
if (sampler.shouldSample(spanToWrite)) { | ||
logger.logSpan(spanToWrite); | ||
} | ||
} | ||
@@ -23,0 +28,0 @@ |
@@ -12,5 +12,2 @@ const sinon = require('sinon'); | ||
trace.withContext(() => { | ||
// let spanHasBeenLogged = false; | ||
// let loggedSpan; | ||
const logSpan = sinon.spy(); | ||
@@ -60,2 +57,31 @@ | ||
}); | ||
it('should respect the Sampler when filtering which spans to log', () => { | ||
function runTest(sample) { | ||
const sampler = { | ||
shouldSample: () => sample | ||
}; | ||
const logSpan = sinon.spy(); | ||
const tracer = new ZipkinTracer({ | ||
logger: {logSpan}, | ||
sampler | ||
}); | ||
trace.withContext(() => { | ||
trace.pushTracer(tracer); | ||
trace.setId(new TraceId({ | ||
traceId: None, | ||
parentId: new Some('a'), | ||
spanId: 'c', | ||
sampled: new Some(true) | ||
})); | ||
trace.recordAnnotation(new Annotation.ServerRecv()); | ||
trace.recordServiceName("test-service"); | ||
trace.recordAnnotation(new Annotation.ServerSend()); | ||
}); | ||
expect(logSpan.calledOnce).to.equal(sample); | ||
} | ||
runTest(true); | ||
runTest(false); | ||
}); | ||
}); |
45400
23
1425