Comparing version 0.11.0 to 0.11.1
@@ -143,9 +143,23 @@ 'use strict'; | ||
if (!traceId.sampled.getOrElse(false)) { | ||
return result; // no need to stop as it was never started | ||
} | ||
// At this point we know we are sampled. Explicitly record against the ID | ||
var explicitRecord = function explicitRecord(annotation) { | ||
return _this.recorder.record(new Record({ | ||
traceId: traceId, | ||
timestamp: now(_this._startTimestamp, _this._startTick), | ||
annotation: annotation | ||
})); | ||
}; | ||
// Ensure the span representing the promise completes | ||
return result.then(function (output) { | ||
_this.recordAnnotation(new Annotation.LocalOperationStop()); | ||
explicitRecord(new Annotation.LocalOperationStop()); | ||
return output; | ||
}).catch(function (err) { | ||
_this.recordBinary('error', err.message ? err.message : err.toString()); | ||
_this.recordAnnotation(new Annotation.LocalOperationStop()); | ||
var message = err.message ? err.message : err.toString(); | ||
explicitRecord(new Annotation.BinaryAnnotation('error', message)); | ||
explicitRecord(new Annotation.LocalOperationStop()); | ||
throw err; | ||
@@ -152,0 +166,0 @@ }); |
{ | ||
"name": "zipkin", | ||
"version": "0.11.0", | ||
"version": "0.11.1", | ||
"description": "The core tracer for zipkin.js", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -111,11 +111,23 @@ const {None, Some, fromNullable} = require('../option'); | ||
if (!traceId.sampled.getOrElse(false)) { | ||
return result; // no need to stop as it was never started | ||
} | ||
// At this point we know we are sampled. Explicitly record against the ID | ||
const explicitRecord = (annotation) => this.recorder.record(new Record({ | ||
traceId, | ||
timestamp: now(this._startTimestamp, this._startTick), | ||
annotation | ||
})); | ||
// Ensure the span representing the promise completes | ||
return result | ||
.then((output) => { | ||
this.recordAnnotation(new Annotation.LocalOperationStop()); | ||
explicitRecord(new Annotation.LocalOperationStop()); | ||
return output; | ||
}) | ||
.catch((err) => { | ||
this.recordBinary('error', err.message ? err.message : err.toString()); | ||
this.recordAnnotation(new Annotation.LocalOperationStop()); | ||
const message = err.message ? err.message : err.toString(); | ||
explicitRecord(new Annotation.BinaryAnnotation('error', message)); | ||
explicitRecord(new Annotation.LocalOperationStop()); | ||
throw err; | ||
@@ -122,0 +134,0 @@ }); |
@@ -118,5 +118,3 @@ const sinon = require('sinon'); | ||
Promise.delay(10) | ||
.then(() => { | ||
throw new Error('no smoothies. try our cake'); | ||
}) | ||
.then(() => 'smoothie') | ||
); | ||
@@ -137,9 +135,6 @@ | ||
return promise.catch((error) => { | ||
expect(error).to.eql(new Error('no smoothies. try our cake')); | ||
return promise.then((result) => { | ||
expect(result).to.eql('smoothie'); | ||
expect(record.getCall(2).args[0].annotation).to.eql( | ||
new Annotation.BinaryAnnotation('error', 'no smoothies. try our cake') | ||
); | ||
expect(record.getCall(3).args[0].annotation).to.eql( | ||
new Annotation.LocalOperationStop() | ||
@@ -151,2 +146,31 @@ ); | ||
it('should close the correct span for a promise', () => { | ||
const record = sinon.spy(); | ||
const recorder = {record}; | ||
const ctxImpl = new ExplicitContext(); | ||
const localServiceName = 'smoothie-store'; | ||
const trace = new Tracer({ctxImpl, recorder, localServiceName}); | ||
ctxImpl.scoped(() => { | ||
const promise = trace.local('buy-smoothie', () => | ||
Promise.delay(10) | ||
.then(() => 'smoothie') | ||
); | ||
expect(isPromise(promise)).to.eql(true); | ||
// hasn't finished yet, due to the delay | ||
expect(record.getCall(2)).to.eql(null); | ||
const expectedTraceId = record.getCall(1).args[0].traceId; | ||
return promise.then((result) => { | ||
expect(result).to.eql('smoothie'); | ||
expect(record.getCall(2).args[0].traceId).to.eql( | ||
expectedTraceId | ||
); | ||
}); | ||
}); | ||
}); | ||
it('should make a local span for a promise that produces an error', () => { | ||
@@ -153,0 +177,0 @@ const record = sinon.spy(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
173992
5050