Comparing version 0.9.0 to 0.10.0
@@ -88,2 +88,12 @@ // TypeScript type definitions | ||
interface JsonEncoder { | ||
// TODO: make a typesafe def for model.Endpoint,Span using Span here | ||
encode: (span: any) => string; | ||
} | ||
namespace jsonEncoder { | ||
const JSON_V1: JsonEncoder; | ||
const JSON_V2: JsonEncoder; | ||
} | ||
interface IAnnotation { | ||
@@ -154,4 +164,2 @@ } | ||
const serializeSpan: () => void; | ||
class ExplicitContext { | ||
@@ -167,4 +175,29 @@ } | ||
} | ||
namespace Instrumentation { | ||
class HttpServer { | ||
constructor(args: { tracer: Tracer, serviceName: string, port: string | number }); | ||
recordRequest( | ||
method: string, | ||
requestUrl: string, | ||
readHeader: <T> (header: string) => option.IOption<T> | ||
): string; | ||
recordResponse(traceId: string, statusCode: string, error?: Error): void; | ||
} | ||
class HttpClient { | ||
constructor(args: { tracer: Tracer, serviceName: string, remoteServiceName?: string }); | ||
recordRequest<T>( | ||
request: T, | ||
url: string, | ||
method: string | ||
): T; | ||
recordResponse(traceId: string, statusCode: string): void; | ||
recordError(traceId: string, error: Error): void; | ||
} | ||
} | ||
} | ||
export = zipkin; |
@@ -8,11 +8,16 @@ 'use strict'; | ||
var _require = require('./time'), | ||
now = _require.now; | ||
now = _require.now, | ||
hrtime = _require.hrtime; | ||
var thriftTypes = require('./gen-nodejs/zipkinCore_types'); | ||
var _require2 = require('./model'), | ||
Span = _require2.Span, | ||
Endpoint = _require2.Endpoint; | ||
var _require2 = require('./internalRepresentations'), | ||
MutableSpan = _require2.MutableSpan, | ||
Endpoint = _require2.Endpoint, | ||
ZipkinAnnotation = _require2.ZipkinAnnotation, | ||
BinaryAnnotation = _require2.BinaryAnnotation; | ||
function PartialSpan(traceId) { | ||
this.traceId = traceId; | ||
this.startTimestamp = now(); | ||
this.startTick = hrtime(); | ||
this.delegate = new Span(traceId); | ||
this.localEndpoint = new Endpoint({ serviceName: 'unknown' }); | ||
} | ||
@@ -51,5 +56,11 @@ var BatchRecorder = function () { | ||
value: function _writeSpan(id) { | ||
var spanToWrite = this.partialSpans.get(id); | ||
var span = this.partialSpans.get(id); | ||
// ready for garbage collection | ||
this.partialSpans.delete(id); | ||
var spanToWrite = span.delegate; | ||
if (span.endTimestamp) { | ||
spanToWrite.setTimestamp(span.startTimestamp); | ||
spanToWrite.setDuration(span.endTimestamp - span.startTimestamp); | ||
} | ||
this.logger.logSpan(spanToWrite); | ||
@@ -64,3 +75,3 @@ } | ||
} else { | ||
span = new MutableSpan(id); | ||
span = new PartialSpan(id); | ||
} | ||
@@ -80,21 +91,14 @@ updater(span); | ||
}, { | ||
key: '_annotate', | ||
value: function _annotate(span, _ref2, value) { | ||
var timestamp = _ref2.timestamp; | ||
span.addAnnotation(new ZipkinAnnotation({ | ||
timestamp: timestamp, | ||
value: value | ||
})); | ||
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: '_binaryAnnotate', | ||
value: function _binaryAnnotate(span, key, value) { | ||
span.addBinaryAnnotation(new BinaryAnnotation({ | ||
key: key, | ||
value: value, | ||
annotationType: thriftTypes.AnnotationType.STRING | ||
})); | ||
} | ||
}, { | ||
key: 'record', | ||
@@ -109,37 +113,40 @@ value: function record(rec) { | ||
case 'ClientSend': | ||
_this2._annotate(span, rec, thriftTypes.CLIENT_SEND); | ||
span.delegate.setKind('CLIENT'); | ||
break; | ||
case 'ClientRecv': | ||
_this2._annotate(span, rec, thriftTypes.CLIENT_RECV); | ||
if (!span.endTimestamp) { | ||
span.endTimestamp = now(span.startTimestamp, span.startTick); | ||
} | ||
span.delegate.setKind('CLIENT'); | ||
break; | ||
case 'ServerSend': | ||
_this2._annotate(span, rec, thriftTypes.SERVER_SEND); | ||
if (!span.endTimestamp) { | ||
span.endTimestamp = now(span.startTimestamp, span.startTick); | ||
} | ||
span.delegate.setKind('SERVER'); | ||
break; | ||
case 'ServerRecv': | ||
_this2._annotate(span, rec, thriftTypes.SERVER_RECV); | ||
// TODO: only set this to false when we know we in an existing trace | ||
span.delegate.setShared(id.parentId !== id.spanId); | ||
span.delegate.setKind('CLIENT'); | ||
break; | ||
case 'Message': | ||
_this2._annotate(span, rec, rec.annotation.message); | ||
span.delegate.addAnnotation(rec.timestamp, rec.annotation.message); | ||
break; | ||
case 'Rpc': | ||
span.setName(rec.annotation.name); | ||
span.delegate.setName(rec.annotation.name); | ||
break; | ||
case 'ServiceName': | ||
span.setServiceName(rec.annotation.serviceName); | ||
span.localEndpoint.serviceName = rec.annotation.serviceName; | ||
span.delegate.setLocalEndpoint(span.localEndpoint); | ||
break; | ||
case 'BinaryAnnotation': | ||
_this2._binaryAnnotate(span, rec.annotation.key, rec.annotation.value); | ||
span.delegate.putTag(rec.annotation.key, rec.annotation.value); | ||
break; | ||
case 'LocalAddr': | ||
span.setEndpoint(new Endpoint({ | ||
host: rec.annotation.host.toInt(), | ||
port: rec.annotation.port | ||
})); | ||
span.delegate.setLocalEndpoint(_this2._decorateEndpoint(span.delegate.localEndpoint, rec.annotation)); | ||
break; | ||
case 'ServerAddr': | ||
span.setServerAddr(new Endpoint({ | ||
serviceName: rec.annotation.serviceName, | ||
host: rec.annotation.host ? rec.annotation.host.toInt() : undefined, | ||
port: rec.annotation.port | ||
})); | ||
span.delegate.setKind('CLIENT'); | ||
span.delegate.setRemoteEndpoint(_this2._decorateEndpoint(new Endpoint({ serviceName: rec.annotation.serviceName }), rec.annotation)); | ||
break; | ||
@@ -146,0 +153,0 @@ default: |
@@ -17,7 +17,10 @@ 'use strict'; | ||
var serializeSpan = require('./serializeSpan'); | ||
var ExplicitContext = require('./explicit-context'); | ||
var Request = require('./request'); | ||
var Instrumentation = require('./instrumentation'); | ||
var model = require('./model'); | ||
var jsonEncoder = require('./jsonEncoder'); | ||
module.exports = { | ||
@@ -33,6 +36,8 @@ Tracer: Tracer, | ||
ConsoleRecorder: ConsoleRecorder, | ||
serializeSpan: serializeSpan, | ||
ExplicitContext: ExplicitContext, | ||
sampler: sampler, | ||
Request: Request | ||
Request: Request, | ||
Instrumentation: Instrumentation, | ||
model: model, | ||
jsonEncoder: jsonEncoder | ||
}; |
@@ -16,3 +16,16 @@ 'use strict'; | ||
// returns undefined if this isn't an IPv4 string | ||
_createClass(InetAddress, [{ | ||
key: 'ipv4', | ||
value: function ipv4() { | ||
// coercing to int forces validation here | ||
var ipv4Int = this.toInt(); | ||
if (ipv4Int && ipv4Int !== 0) { | ||
return this.addr; | ||
} | ||
return undefined; | ||
} | ||
}, { | ||
key: 'toInt', | ||
@@ -50,3 +63,3 @@ value: function toInt() { | ||
// eslint-disable-next-line global-require | ||
var networkAddress = require('network-address'); | ||
var networkAddress = require.call(null, 'network-address'); | ||
return new InetAddress(networkAddress.ipv4()); | ||
@@ -53,0 +66,0 @@ }; |
{ | ||
"name": "zipkin", | ||
"version": "0.9.0", | ||
"version": "0.10.0", | ||
"description": "The core tracer for zipkin.js", | ||
@@ -9,3 +9,2 @@ "main": "lib/index.js", | ||
"build": "babel src -d lib", | ||
"gen-thrift": "thrift -gen js:node -o src/ src/zipkinCore.thrift", | ||
"test": "tsc index.d.ts && mocha --require ../../test/helper.js", | ||
@@ -19,4 +18,3 @@ "prepublish": "npm run build" | ||
"base64-js": "^1.1.2", | ||
"network-address": "^1.1.0", | ||
"thrift": "^0.10.0" | ||
"network-address": "^1.1.0" | ||
}, | ||
@@ -23,0 +21,0 @@ "devDependencies": { |
@@ -1,10 +0,12 @@ | ||
const {now} = require('./time'); | ||
const thriftTypes = require('./gen-nodejs/zipkinCore_types'); | ||
const { | ||
MutableSpan, | ||
Endpoint, | ||
ZipkinAnnotation, | ||
BinaryAnnotation | ||
} = require('./internalRepresentations'); | ||
const {now, hrtime} = require('./time'); | ||
const {Span, Endpoint} = require('./model'); | ||
function PartialSpan(traceId) { | ||
this.traceId = traceId; | ||
this.startTimestamp = now(); | ||
this.startTick = hrtime(); | ||
this.delegate = new Span(traceId); | ||
this.localEndpoint = new Endpoint({serviceName: 'unknown'}); | ||
} | ||
class BatchRecorder { | ||
@@ -34,5 +36,11 @@ constructor({ | ||
_writeSpan(id) { | ||
const spanToWrite = this.partialSpans.get(id); | ||
const span = this.partialSpans.get(id); | ||
// ready for garbage collection | ||
this.partialSpans.delete(id); | ||
const spanToWrite = span.delegate; | ||
if (span.endTimestamp) { | ||
spanToWrite.setTimestamp(span.startTimestamp); | ||
spanToWrite.setDuration(span.endTimestamp - span.startTimestamp); | ||
} | ||
this.logger.logSpan(spanToWrite); | ||
@@ -46,3 +54,3 @@ } | ||
} else { | ||
span = new MutableSpan(id); | ||
span = new PartialSpan(id); | ||
} | ||
@@ -61,18 +69,13 @@ updater(span); | ||
_annotate(span, {timestamp}, value) { | ||
span.addAnnotation(new ZipkinAnnotation({ | ||
timestamp, | ||
value | ||
})); | ||
_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; | ||
} | ||
_binaryAnnotate(span, key, value) { | ||
span.addBinaryAnnotation(new BinaryAnnotation({ | ||
key, | ||
value, | ||
annotationType: thriftTypes.AnnotationType.STRING | ||
})); | ||
} | ||
record(rec) { | ||
@@ -84,37 +87,46 @@ const id = rec.traceId; | ||
case 'ClientSend': | ||
this._annotate(span, rec, thriftTypes.CLIENT_SEND); | ||
span.delegate.setKind('CLIENT'); | ||
break; | ||
case 'ClientRecv': | ||
this._annotate(span, rec, thriftTypes.CLIENT_RECV); | ||
if (!span.endTimestamp) { | ||
span.endTimestamp = now(span.startTimestamp, span.startTick); | ||
} | ||
span.delegate.setKind('CLIENT'); | ||
break; | ||
case 'ServerSend': | ||
this._annotate(span, rec, thriftTypes.SERVER_SEND); | ||
if (!span.endTimestamp) { | ||
span.endTimestamp = now(span.startTimestamp, span.startTick); | ||
} | ||
span.delegate.setKind('SERVER'); | ||
break; | ||
case 'ServerRecv': | ||
this._annotate(span, rec, thriftTypes.SERVER_RECV); | ||
// TODO: only set this to false when we know we in an existing trace | ||
span.delegate.setShared(id.parentId !== id.spanId); | ||
span.delegate.setKind('CLIENT'); | ||
break; | ||
case 'Message': | ||
this._annotate(span, rec, rec.annotation.message); | ||
span.delegate.addAnnotation(rec.timestamp, rec.annotation.message); | ||
break; | ||
case 'Rpc': | ||
span.setName(rec.annotation.name); | ||
span.delegate.setName(rec.annotation.name); | ||
break; | ||
case 'ServiceName': | ||
span.setServiceName(rec.annotation.serviceName); | ||
span.localEndpoint.serviceName = rec.annotation.serviceName; | ||
span.delegate.setLocalEndpoint(span.localEndpoint); | ||
break; | ||
case 'BinaryAnnotation': | ||
this._binaryAnnotate(span, rec.annotation.key, rec.annotation.value); | ||
span.delegate.putTag(rec.annotation.key, rec.annotation.value); | ||
break; | ||
case 'LocalAddr': | ||
span.setEndpoint(new Endpoint({ | ||
host: rec.annotation.host.toInt(), | ||
port: rec.annotation.port | ||
})); | ||
span.delegate.setLocalEndpoint(this._decorateEndpoint( | ||
span.delegate.localEndpoint, | ||
rec.annotation | ||
)); | ||
break; | ||
case 'ServerAddr': | ||
span.setServerAddr(new Endpoint({ | ||
serviceName: rec.annotation.serviceName, | ||
host: rec.annotation.host ? rec.annotation.host.toInt() : undefined, | ||
port: rec.annotation.port | ||
})); | ||
span.delegate.setKind('CLIENT'); | ||
span.delegate.setRemoteEndpoint(this._decorateEndpoint( | ||
new Endpoint({serviceName: rec.annotation.serviceName}), | ||
rec.annotation | ||
)); | ||
break; | ||
@@ -121,0 +133,0 @@ default: |
@@ -15,7 +15,10 @@ const option = require('./option'); | ||
const serializeSpan = require('./serializeSpan'); | ||
const ExplicitContext = require('./explicit-context'); | ||
const Request = require('./request'); | ||
const Instrumentation = require('./instrumentation'); | ||
const model = require('./model'); | ||
const jsonEncoder = require('./jsonEncoder'); | ||
module.exports = { | ||
@@ -31,6 +34,8 @@ Tracer, | ||
ConsoleRecorder, | ||
serializeSpan, | ||
ExplicitContext, | ||
sampler, | ||
Request | ||
Request, | ||
Instrumentation, | ||
model, | ||
jsonEncoder | ||
}; |
@@ -5,2 +5,13 @@ class InetAddress { | ||
} | ||
// returns undefined if this isn't an IPv4 string | ||
ipv4() { | ||
// coercing to int forces validation here | ||
const ipv4Int = this.toInt(); | ||
if (ipv4Int && ipv4Int !== 0) { | ||
return this.addr; | ||
} | ||
return undefined; | ||
} | ||
toInt() { | ||
@@ -17,2 +28,3 @@ // e.g. 10.57.50.83 | ||
} | ||
toString() { | ||
@@ -31,3 +43,3 @@ return `InetAddress(${this.addr})`; | ||
// eslint-disable-next-line global-require | ||
const networkAddress = require('network-address'); | ||
const networkAddress = require.call(null, 'network-address'); | ||
return new InetAddress(networkAddress.ipv4()); | ||
@@ -34,0 +46,0 @@ }; |
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
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
129653
2
61
3715
1
- Removedthrift@^0.10.0
- Removedcommander@2.1.0(transitive)
- Removednan@1.0.0(transitive)
- Removednode-int64@0.3.3(transitive)
- Removedoptions@0.0.6(transitive)
- Removedq@1.0.1(transitive)
- Removedthrift@0.10.0(transitive)
- Removedtinycolor@0.0.1(transitive)
- Removedws@0.4.32(transitive)