Comparing version 0.10.0 to 0.10.1
@@ -20,4 +20,10 @@ 'use strict'; | ||
this.delegate = new Span(traceId); | ||
this.localEndpoint = new Endpoint({ serviceName: 'unknown' }); | ||
this.localEndpoint = new Endpoint({}); | ||
} | ||
PartialSpan.prototype.finish = function finish() { | ||
if (this.endTimestamp) { | ||
return; | ||
} | ||
this.endTimestamp = now(this.startTimestamp, this.startTick); | ||
}; | ||
@@ -61,2 +67,3 @@ var BatchRecorder = function () { | ||
var spanToWrite = span.delegate; | ||
spanToWrite.setLocalEndpoint(span.localEndpoint); | ||
if (span.endTimestamp) { | ||
@@ -90,18 +97,4 @@ spanToWrite.setTimestamp(span.startTimestamp); | ||
}, { | ||
key: '_decorateEndpoint', | ||
value: function _decorateEndpoint(endpoint, ann) { | ||
/* eslint-disable no-param-reassign */ | ||
if (ann.host) { | ||
endpoint.ipv4 = ann.host.ipv4(); | ||
} | ||
if (ann.port && ann.port !== 0) { | ||
endpoint.port = ann.port; | ||
} | ||
return endpoint; | ||
} | ||
}, { | ||
key: 'record', | ||
value: function record(rec) { | ||
var _this2 = this; | ||
var id = rec.traceId; | ||
@@ -115,11 +108,7 @@ | ||
case 'ClientRecv': | ||
if (!span.endTimestamp) { | ||
span.endTimestamp = now(span.startTimestamp, span.startTick); | ||
} | ||
span.finish(); | ||
span.delegate.setKind('CLIENT'); | ||
break; | ||
case 'ServerSend': | ||
if (!span.endTimestamp) { | ||
span.endTimestamp = now(span.startTimestamp, span.startTick); | ||
} | ||
span.finish(); | ||
span.delegate.setKind('SERVER'); | ||
@@ -139,4 +128,3 @@ break; | ||
case 'ServiceName': | ||
span.localEndpoint.serviceName = rec.annotation.serviceName; | ||
span.delegate.setLocalEndpoint(span.localEndpoint); | ||
span.localEndpoint.setServiceName(rec.annotation.serviceName); | ||
break; | ||
@@ -147,7 +135,12 @@ case 'BinaryAnnotation': | ||
case 'LocalAddr': | ||
span.delegate.setLocalEndpoint(_this2._decorateEndpoint(span.delegate.localEndpoint, rec.annotation)); | ||
span.localEndpoint.setIpv4(rec.annotation.host && rec.annotation.host.ipv4()); | ||
span.localEndpoint.setPort(rec.annotation.port); | ||
break; | ||
case 'ServerAddr': | ||
span.delegate.setKind('CLIENT'); | ||
span.delegate.setRemoteEndpoint(_this2._decorateEndpoint(new Endpoint({ serviceName: rec.annotation.serviceName }), rec.annotation)); | ||
span.delegate.setRemoteEndpoint(new Endpoint({ | ||
serviceName: rec.annotation.serviceName, | ||
ipv4: rec.annotation.host && rec.annotation.host.ipv4(), | ||
port: rec.annotation.port | ||
})); | ||
break; | ||
@@ -154,0 +147,0 @@ default: |
'use strict'; | ||
function toV1Endpoint(endpoint) { | ||
if (endpoint === undefined || endpoint.isUnknown()) { | ||
if (endpoint === undefined) { | ||
return undefined; | ||
@@ -6,0 +6,0 @@ } |
@@ -8,9 +8,19 @@ 'use strict'; | ||
this.serviceName = serviceName; | ||
this.ipv4 = ipv4; | ||
this.port = port; | ||
this.setServiceName(serviceName); | ||
this.setIpv4(ipv4); | ||
this.setPort(port); | ||
} | ||
Endpoint.prototype.isUnknown = function isUnknown() { | ||
return (this.serviceName === undefined || this.serviceName === 'unknown') && this.ipv4 === undefined && this.port === undefined; | ||
Endpoint.prototype.setServiceName = function setServiceName(serviceName) { | ||
// In zipkin, names are lowercase. This eagerly converts to alert users early. | ||
this.serviceName = serviceName ? serviceName.toLocaleLowerCase() : undefined; | ||
}; | ||
Endpoint.prototype.setIpv4 = function setIpv4(ipv4) { | ||
this.ipv4 = ipv4; | ||
}; | ||
Endpoint.prototype.setPort = function setPort(port) { | ||
this.port = port || undefined; | ||
}; | ||
Endpoint.prototype.isEmpty = function isEmpty() { | ||
return this.serviceName === undefined && this.ipv4 === undefined && this.port === undefined; | ||
}; | ||
@@ -46,3 +56,4 @@ function Annotation(timestamp, value) { | ||
Span.prototype.setName = function setName(name) { | ||
this.name = name; | ||
// In zipkin, names are lowercase. This eagerly converts to alert users early. | ||
this.name = name ? name.toLocaleLowerCase() : undefined; | ||
}; | ||
@@ -62,3 +73,3 @@ Span.prototype.setKind = function setKind(kind) { | ||
Span.prototype.setLocalEndpoint = function setLocalEndpoint(ep) { | ||
if (ep && !ep.isUnknown()) { | ||
if (ep && !ep.isEmpty()) { | ||
this.localEndpoint = ep; | ||
@@ -70,3 +81,7 @@ } else { | ||
Span.prototype.setRemoteEndpoint = function setRemoteEndpoint(ep) { | ||
this.remoteEndpoint = ep; | ||
if (ep && !ep.isEmpty()) { | ||
this.remoteEndpoint = ep; | ||
} else { | ||
this.remoteEndpoint = undefined; | ||
} | ||
}; | ||
@@ -73,0 +88,0 @@ Span.prototype.addAnnotation = function addAnnotation(timestamp, value) { |
{ | ||
"name": "zipkin", | ||
"version": "0.10.0", | ||
"version": "0.10.1", | ||
"description": "The core tracer for zipkin.js", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -9,4 +9,10 @@ const {now, hrtime} = require('./time'); | ||
this.delegate = new Span(traceId); | ||
this.localEndpoint = new Endpoint({serviceName: 'unknown'}); | ||
this.localEndpoint = new Endpoint({}); | ||
} | ||
PartialSpan.prototype.finish = function finish() { | ||
if (this.endTimestamp) { | ||
return; | ||
} | ||
this.endTimestamp = now(this.startTimestamp, this.startTick); | ||
}; | ||
@@ -42,2 +48,3 @@ class BatchRecorder { | ||
const spanToWrite = span.delegate; | ||
spanToWrite.setLocalEndpoint(span.localEndpoint); | ||
if (span.endTimestamp) { | ||
@@ -69,13 +76,2 @@ spanToWrite.setTimestamp(span.startTimestamp); | ||
_decorateEndpoint(endpoint, ann) { | ||
/* eslint-disable no-param-reassign */ | ||
if (ann.host) { | ||
endpoint.ipv4 = ann.host.ipv4(); | ||
} | ||
if (ann.port && ann.port !== 0) { | ||
endpoint.port = ann.port; | ||
} | ||
return endpoint; | ||
} | ||
record(rec) { | ||
@@ -90,11 +86,7 @@ const id = rec.traceId; | ||
case 'ClientRecv': | ||
if (!span.endTimestamp) { | ||
span.endTimestamp = now(span.startTimestamp, span.startTick); | ||
} | ||
span.finish(); | ||
span.delegate.setKind('CLIENT'); | ||
break; | ||
case 'ServerSend': | ||
if (!span.endTimestamp) { | ||
span.endTimestamp = now(span.startTimestamp, span.startTick); | ||
} | ||
span.finish(); | ||
span.delegate.setKind('SERVER'); | ||
@@ -114,4 +106,3 @@ break; | ||
case 'ServiceName': | ||
span.localEndpoint.serviceName = rec.annotation.serviceName; | ||
span.delegate.setLocalEndpoint(span.localEndpoint); | ||
span.localEndpoint.setServiceName(rec.annotation.serviceName); | ||
break; | ||
@@ -122,13 +113,14 @@ case 'BinaryAnnotation': | ||
case 'LocalAddr': | ||
span.delegate.setLocalEndpoint(this._decorateEndpoint( | ||
span.delegate.localEndpoint, | ||
rec.annotation | ||
)); | ||
span.localEndpoint.setIpv4( | ||
rec.annotation.host && rec.annotation.host.ipv4() | ||
); | ||
span.localEndpoint.setPort(rec.annotation.port); | ||
break; | ||
case 'ServerAddr': | ||
span.delegate.setKind('CLIENT'); | ||
span.delegate.setRemoteEndpoint(this._decorateEndpoint( | ||
new Endpoint({serviceName: rec.annotation.serviceName}), | ||
rec.annotation | ||
)); | ||
span.delegate.setRemoteEndpoint(new Endpoint({ | ||
serviceName: rec.annotation.serviceName, | ||
ipv4: rec.annotation.host && rec.annotation.host.ipv4(), | ||
port: rec.annotation.port | ||
})); | ||
break; | ||
@@ -135,0 +127,0 @@ default: |
function toV1Endpoint(endpoint) { | ||
if (endpoint === undefined || endpoint.isUnknown()) { | ||
if (endpoint === undefined) { | ||
return undefined; | ||
@@ -4,0 +4,0 @@ } |
function Endpoint({serviceName, ipv4, port}) { | ||
this.serviceName = serviceName; | ||
this.ipv4 = ipv4; | ||
this.port = port; | ||
this.setServiceName(serviceName); | ||
this.setIpv4(ipv4); | ||
this.setPort(port); | ||
} | ||
Endpoint.prototype.isUnknown = function isUnknown() { | ||
return (this.serviceName === undefined || this.serviceName === 'unknown') && | ||
this.ipv4 === undefined && this.port === undefined; | ||
Endpoint.prototype.setServiceName = function setServiceName(serviceName) { | ||
// In zipkin, names are lowercase. This eagerly converts to alert users early. | ||
this.serviceName = serviceName ? serviceName.toLocaleLowerCase() : undefined; | ||
}; | ||
Endpoint.prototype.setIpv4 = function setIpv4(ipv4) { | ||
this.ipv4 = ipv4; | ||
}; | ||
Endpoint.prototype.setPort = function setPort(port) { | ||
this.port = port || undefined; | ||
}; | ||
Endpoint.prototype.isEmpty = function isEmpty() { | ||
return this.serviceName === undefined && | ||
this.ipv4 === undefined && this.port === undefined; | ||
}; | ||
@@ -38,3 +48,4 @@ function Annotation(timestamp, value) { | ||
Span.prototype.setName = function setName(name) { | ||
this.name = name; | ||
// In zipkin, names are lowercase. This eagerly converts to alert users early. | ||
this.name = name ? name.toLocaleLowerCase() : undefined; | ||
}; | ||
@@ -54,3 +65,3 @@ Span.prototype.setKind = function setKind(kind) { | ||
Span.prototype.setLocalEndpoint = function setLocalEndpoint(ep) { | ||
if (ep && !ep.isUnknown()) { | ||
if (ep && !ep.isEmpty()) { | ||
this.localEndpoint = ep; | ||
@@ -62,3 +73,7 @@ } else { | ||
Span.prototype.setRemoteEndpoint = function setRemoteEndpoint(ep) { | ||
this.remoteEndpoint = ep; | ||
if (ep && !ep.isEmpty()) { | ||
this.remoteEndpoint = ep; | ||
} else { | ||
this.remoteEndpoint = undefined; | ||
} | ||
}; | ||
@@ -65,0 +80,0 @@ Span.prototype.addAnnotation = function addAnnotation(timestamp, value) { |
@@ -47,5 +47,5 @@ const sinon = require('sinon'); | ||
expect(loggedSpan.id).to.equal('c'); | ||
expect(loggedSpan.name).to.eql('buySmoothie'); | ||
expect(loggedSpan.name).to.eql('buysmoothie'); | ||
expect(loggedSpan.kind).to.equal('SERVER'); | ||
expect(loggedSpan.localEndpoint.serviceName).to.equal('SmoothieStore'); | ||
expect(loggedSpan.localEndpoint.serviceName).to.equal('smoothiestore'); | ||
expect(loggedSpan.localEndpoint.ipv4).to.equal('127.0.0.1'); | ||
@@ -85,3 +85,3 @@ expect(loggedSpan.localEndpoint.port).to.equal(7070); | ||
expect(loggedSpan.name).to.eql('rentSmoothie'); | ||
expect(loggedSpan.name).to.eql('rentsmoothie'); | ||
}); | ||
@@ -147,3 +147,3 @@ }); | ||
it('should record minimum duration of 1 microsecond', () => { | ||
it('should record duration in microseconds', () => { | ||
const clock = lolex.install(12345678); | ||
@@ -165,3 +165,3 @@ const logSpan = sinon.spy(); | ||
trace.recordAnnotation(new Annotation.ClientSend()); | ||
clock.tick(0.000123); | ||
clock.tick(0.123456); | ||
trace.recordAnnotation(new Annotation.ClientRecv()); | ||
@@ -172,3 +172,3 @@ | ||
expect(loggedSpan.timestamp).to.equal(12345678000); | ||
expect(loggedSpan.duration).to.equal(1); // rounds up! | ||
expect(loggedSpan.duration).to.equal(123); | ||
@@ -175,0 +175,0 @@ clock.uninstall(); |
@@ -75,3 +75,3 @@ const TraceId = require('../src/tracer/TraceId'); | ||
traceId: 'a', | ||
name: 'GET', | ||
name: 'get', | ||
id: 'c', | ||
@@ -82,3 +82,3 @@ parentId: 'b', | ||
endpoint: { | ||
serviceName: 'PortalService', | ||
serviceName: 'portalservice', | ||
ipv4: '10.57.50.83', | ||
@@ -92,3 +92,3 @@ port: 8080 | ||
endpoint: { | ||
serviceName: 'PortalService', | ||
serviceName: 'portalservice', | ||
ipv4: '10.57.50.83', | ||
@@ -106,3 +106,3 @@ port: 8080, | ||
endpoint: { | ||
serviceName: 'PortalService', | ||
serviceName: 'portalservice', | ||
ipv4: '10.57.50.83', | ||
@@ -109,0 +109,0 @@ port: 8080 |
@@ -73,3 +73,3 @@ const TraceId = require('../src/tracer/TraceId'); | ||
traceId: 'a', | ||
name: 'GET', | ||
name: 'get', | ||
id: 'c', | ||
@@ -81,3 +81,3 @@ parentId: 'b', | ||
localEndpoint: { | ||
serviceName: 'PortalService', | ||
serviceName: 'portalservice', | ||
ipv4: '10.57.50.83', | ||
@@ -84,0 +84,0 @@ port: 8080 |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
131892
62
3784
0