Comparing version
@@ -33,3 +33,12 @@ // TypeScript type definitions | ||
class Tracer { | ||
constructor(args: { ctxImpl: Context<TraceId>, recorder: Recorder, sampler?: sampler.Sampler, traceId128Bit?: boolean, localServiceName?: string, localEndpoint?: model.Endpoint }); | ||
constructor(args: { | ||
ctxImpl: Context<TraceId>, | ||
recorder: Recorder, | ||
sampler?: sampler.Sampler, | ||
traceId128Bit?: boolean, | ||
localServiceName?: string, | ||
localEndpoint?: model.Endpoint, | ||
log?: Console | ||
}); | ||
id: TraceId; | ||
@@ -43,3 +52,3 @@ | ||
setId(traceId: TraceId): void; | ||
recordAnnotation(annotation: IAnnotation): void; | ||
recordAnnotation(annotation: IAnnotation, timestamp?: number): void; | ||
recordMessage(message: string): void; | ||
@@ -79,10 +88,7 @@ recordServiceName(serviceName: string): void; | ||
namespace option { | ||
interface IOption<T> { | ||
type: 'Some' | 'None'; | ||
present: boolean; | ||
abstract class Option<T> { | ||
map<V>(fn: (value: T) => V): IOption<V>; | ||
ifPresent<V>(fn: (value: T) => V): IOption<V>; | ||
flatMap<V>(fn: (value: T) => V): IOption<V>; | ||
getOrElse<V>(fnOrValue: (() => V) | V): T; | ||
ifPresent(fn: (value: T) => any): void; | ||
flatMap<V>(fn: (value: T) => IOption<V>): IOption<V>; | ||
getOrElse(fnOrValue: (() => T) | T): T; | ||
equals(other: IOption<T>): boolean; | ||
@@ -92,26 +98,16 @@ toString(): string; | ||
interface INone extends IOption<any> { | ||
type: 'None'; | ||
present: false; | ||
map<V>(fn: (value: any) => V): INone; | ||
flatMap<V>(fn: (value: any) => V): INone; | ||
equals(other: IOption<any>): boolean; | ||
toString(): string; | ||
class Some<T> extends Option<T> { | ||
constructor(value: T); | ||
readonly type: 'Some'; | ||
readonly present: true; | ||
} | ||
const None: INone; | ||
interface INone<T> extends Option<T> { | ||
readonly type: 'None'; | ||
readonly present: false; | ||
} | ||
class Some<T> implements IOption<T> { | ||
constructor(value: T); | ||
type: 'Some' | 'None'; | ||
present: true; | ||
type IOption<T> = Some<T> | INone<T>; | ||
map: <V>(fn: (value: T) => V) => IOption<V>; | ||
ifPresent: <V>(fn: (value: T) => V) => IOption<V>; | ||
flatMap: <V>(fn: (value: T) => V) => IOption<V>; | ||
getOrElse: () => T; | ||
equals: (other: IOption<T>) => boolean; | ||
toString: () => string; | ||
} | ||
const None: INone<never>; | ||
@@ -131,3 +127,3 @@ function isOptional(data: any): boolean; | ||
isEmpty(): void; | ||
isEmpty(): boolean; | ||
} | ||
@@ -318,3 +314,9 @@ | ||
class HttpServer { | ||
constructor(args: { tracer: Tracer, port: number }); | ||
constructor(args: { | ||
tracer: Tracer, | ||
port: number, | ||
serviceName?: string, | ||
host?: string, | ||
serverTags?: {[key: string]: string} | ||
}); | ||
@@ -321,0 +323,0 @@ recordRequest( |
@@ -1,14 +0,26 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
var InetAddress = require('./InetAddress'); | ||
var SimpleAnnotation = function () { | ||
var SimpleAnnotation = | ||
/*#__PURE__*/ | ||
function () { | ||
function SimpleAnnotation() { | ||
@@ -19,5 +31,5 @@ _classCallCheck(this, SimpleAnnotation); | ||
_createClass(SimpleAnnotation, [{ | ||
key: 'toString', | ||
key: "toString", | ||
value: function toString() { | ||
return this.annotationType + '()'; | ||
return "".concat(this.annotationType, "()"); | ||
} | ||
@@ -29,3 +41,5 @@ }]); | ||
var ClientSend = function (_SimpleAnnotation) { | ||
var ClientSend = | ||
/*#__PURE__*/ | ||
function (_SimpleAnnotation) { | ||
_inherits(ClientSend, _SimpleAnnotation); | ||
@@ -36,3 +50,3 @@ | ||
return _possibleConstructorReturn(this, (ClientSend.__proto__ || Object.getPrototypeOf(ClientSend)).apply(this, arguments)); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(ClientSend).apply(this, arguments)); | ||
} | ||
@@ -43,3 +57,5 @@ | ||
var ClientRecv = function (_SimpleAnnotation2) { | ||
var ClientRecv = | ||
/*#__PURE__*/ | ||
function (_SimpleAnnotation2) { | ||
_inherits(ClientRecv, _SimpleAnnotation2); | ||
@@ -50,3 +66,3 @@ | ||
return _possibleConstructorReturn(this, (ClientRecv.__proto__ || Object.getPrototypeOf(ClientRecv)).apply(this, arguments)); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(ClientRecv).apply(this, arguments)); | ||
} | ||
@@ -57,3 +73,5 @@ | ||
var ServerSend = function (_SimpleAnnotation3) { | ||
var ServerSend = | ||
/*#__PURE__*/ | ||
function (_SimpleAnnotation3) { | ||
_inherits(ServerSend, _SimpleAnnotation3); | ||
@@ -64,3 +82,3 @@ | ||
return _possibleConstructorReturn(this, (ServerSend.__proto__ || Object.getPrototypeOf(ServerSend)).apply(this, arguments)); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(ServerSend).apply(this, arguments)); | ||
} | ||
@@ -71,3 +89,5 @@ | ||
var ServerRecv = function (_SimpleAnnotation4) { | ||
var ServerRecv = | ||
/*#__PURE__*/ | ||
function (_SimpleAnnotation4) { | ||
_inherits(ServerRecv, _SimpleAnnotation4); | ||
@@ -78,3 +98,3 @@ | ||
return _possibleConstructorReturn(this, (ServerRecv.__proto__ || Object.getPrototypeOf(ServerRecv)).apply(this, arguments)); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(ServerRecv).apply(this, arguments)); | ||
} | ||
@@ -85,3 +105,5 @@ | ||
var ProducerStart = function (_SimpleAnnotation5) { | ||
var ProducerStart = | ||
/*#__PURE__*/ | ||
function (_SimpleAnnotation5) { | ||
_inherits(ProducerStart, _SimpleAnnotation5); | ||
@@ -92,3 +114,3 @@ | ||
return _possibleConstructorReturn(this, (ProducerStart.__proto__ || Object.getPrototypeOf(ProducerStart)).apply(this, arguments)); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(ProducerStart).apply(this, arguments)); | ||
} | ||
@@ -99,3 +121,5 @@ | ||
var ProducerStop = function (_SimpleAnnotation6) { | ||
var ProducerStop = | ||
/*#__PURE__*/ | ||
function (_SimpleAnnotation6) { | ||
_inherits(ProducerStop, _SimpleAnnotation6); | ||
@@ -106,3 +130,3 @@ | ||
return _possibleConstructorReturn(this, (ProducerStop.__proto__ || Object.getPrototypeOf(ProducerStop)).apply(this, arguments)); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(ProducerStop).apply(this, arguments)); | ||
} | ||
@@ -113,3 +137,5 @@ | ||
var ConsumerStart = function (_SimpleAnnotation7) { | ||
var ConsumerStart = | ||
/*#__PURE__*/ | ||
function (_SimpleAnnotation7) { | ||
_inherits(ConsumerStart, _SimpleAnnotation7); | ||
@@ -120,3 +146,3 @@ | ||
return _possibleConstructorReturn(this, (ConsumerStart.__proto__ || Object.getPrototypeOf(ConsumerStart)).apply(this, arguments)); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(ConsumerStart).apply(this, arguments)); | ||
} | ||
@@ -127,3 +153,5 @@ | ||
var ConsumerStop = function (_SimpleAnnotation8) { | ||
var ConsumerStop = | ||
/*#__PURE__*/ | ||
function (_SimpleAnnotation8) { | ||
_inherits(ConsumerStop, _SimpleAnnotation8); | ||
@@ -134,3 +162,3 @@ | ||
return _possibleConstructorReturn(this, (ConsumerStop.__proto__ || Object.getPrototypeOf(ConsumerStop)).apply(this, arguments)); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(ConsumerStop).apply(this, arguments)); | ||
} | ||
@@ -144,7 +172,10 @@ | ||
} | ||
LocalOperationStart.prototype.toString = function () { | ||
return 'LocalOperationStart("' + this.name + '")'; | ||
return "LocalOperationStart(\"".concat(this.name, "\")"); | ||
}; | ||
var LocalOperationStop = function (_SimpleAnnotation9) { | ||
var LocalOperationStop = | ||
/*#__PURE__*/ | ||
function (_SimpleAnnotation9) { | ||
_inherits(LocalOperationStop, _SimpleAnnotation9); | ||
@@ -155,3 +186,3 @@ | ||
return _possibleConstructorReturn(this, (LocalOperationStop.__proto__ || Object.getPrototypeOf(LocalOperationStop)).apply(this, arguments)); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(LocalOperationStop).apply(this, arguments)); | ||
} | ||
@@ -165,4 +196,5 @@ | ||
} | ||
Message.prototype.toString = function () { | ||
return 'Message("' + this.message + '")'; | ||
return "Message(\"".concat(this.message, "\")"); | ||
}; | ||
@@ -173,4 +205,5 @@ | ||
} | ||
ServiceName.prototype.toString = function () { | ||
return 'ServiceName("' + this.serviceName + '")'; | ||
return "ServiceName(\"".concat(this.serviceName, "\")"); | ||
}; | ||
@@ -181,4 +214,5 @@ | ||
} | ||
Rpc.prototype.toString = function () { | ||
return 'Rpc("' + this.name + '")'; | ||
return "Rpc(\"".concat(this.name, "\")"); | ||
}; | ||
@@ -189,8 +223,8 @@ | ||
port = _ref.port; | ||
this.host = host; | ||
this.port = port; | ||
} | ||
ClientAddr.prototype.toString = function () { | ||
return 'ClientAddr(host="' + this.host + '", port=' + this.port + ')'; | ||
return "ClientAddr(host=\"".concat(this.host, "\", port=").concat(this.port, ")"); | ||
}; | ||
@@ -202,3 +236,2 @@ | ||
port = _ref2.port; | ||
this.serviceName = serviceName; | ||
@@ -208,4 +241,5 @@ this.host = host || undefined; | ||
} | ||
ServerAddr.prototype.toString = function () { | ||
return 'ServerAddr(serviceName="' + this.serviceName + '", host="' + this.host + '", port=' + this.port + ')'; | ||
return "ServerAddr(serviceName=\"".concat(this.serviceName, "\", host=\"").concat(this.host, "\", port=").concat(this.port, ")"); | ||
}; | ||
@@ -216,8 +250,8 @@ | ||
port = _ref3.port; | ||
this.host = host || InetAddress.getLocalAddress(); | ||
this.port = port || 0; | ||
} | ||
LocalAddr.prototype.toString = function () { | ||
return 'LocalAddr(host="' + this.host.toString() + '", port=' + this.port + ')'; | ||
return "LocalAddr(host=\"".concat(this.host.toString(), "\", port=").concat(this.port, ")"); | ||
}; | ||
@@ -229,3 +263,2 @@ | ||
port = _ref4.port; | ||
this.serviceName = serviceName; | ||
@@ -235,4 +268,5 @@ this.host = host; | ||
} | ||
MessageAddr.prototype.toString = function () { | ||
return 'MessageAddr(serviceName="' + this.serviceName + '", host="' + this.host + '", port=' + this.port + ')'; | ||
return "MessageAddr(serviceName=\"".concat(this.serviceName, "\", host=\"").concat(this.host, "\", port=").concat(this.port, ")"); | ||
}; | ||
@@ -244,4 +278,5 @@ | ||
} | ||
BinaryAnnotation.prototype.toString = function () { | ||
return 'BinaryAnnotation(' + this.key + '="' + this.value + '")'; | ||
return "BinaryAnnotation(".concat(this.key, "=\"").concat(this.value, "\")"); | ||
}; | ||
@@ -269,7 +304,5 @@ | ||
}; | ||
Object.keys(annotation).forEach(function (key) { | ||
annotation[key].prototype.annotationType = key; | ||
}); | ||
module.exports = annotation; |
@@ -1,7 +0,9 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
var _require = require('./time'), | ||
@@ -22,2 +24,3 @@ now = _require.now, | ||
} | ||
PartialSpan.prototype.finish = function finish() { | ||
@@ -27,6 +30,9 @@ if (this.endTimestamp) { | ||
} | ||
this.endTimestamp = now(this.startTimestamp, this.startTick); | ||
}; | ||
var BatchRecorder = function () { | ||
var BatchRecorder = | ||
/*#__PURE__*/ | ||
function () { | ||
function BatchRecorder(_ref) { | ||
@@ -37,3 +43,3 @@ var _this = this; | ||
_ref$timeout = _ref.timeout, | ||
timeout = _ref$timeout === undefined ? 60 * 1000000 : _ref$timeout; | ||
timeout = _ref$timeout === void 0 ? 60 * 1000000 : _ref$timeout; | ||
@@ -44,6 +50,5 @@ _classCallCheck(this, BatchRecorder); | ||
this.timeout = timeout; | ||
this.partialSpans = new Map(); | ||
this.partialSpans = new Map(); // read through the partials spans regularly | ||
// and collect any timed-out ones | ||
// read through the partials spans regularly | ||
// and collect any timed-out ones | ||
var timer = setInterval(function () { | ||
@@ -56,2 +61,3 @@ _this.partialSpans.forEach(function (span, id) { | ||
}, 1000); | ||
if (timer.unref) { | ||
@@ -64,17 +70,16 @@ // unref might not be available in browsers | ||
_createClass(BatchRecorder, [{ | ||
key: '_writeSpan', | ||
key: "_writeSpan", | ||
value: function _writeSpan(id) { | ||
var span = this.partialSpans.get(id); | ||
var span = this.partialSpans.get(id); // TODO(adriancole) refactor so this responsibility isn't in writeSpan | ||
// TODO(adriancole) refactor so this responsibility isn't in writeSpan | ||
if (span === undefined) { | ||
// Span not found. Could have been expired. | ||
return; | ||
} | ||
} // ready for garbage collection | ||
// ready for garbage collection | ||
this.partialSpans.delete(id); | ||
var spanToWrite = span.delegate; | ||
spanToWrite.setLocalEndpoint(span.localEndpoint); | ||
if (span.endTimestamp) { | ||
@@ -84,8 +89,10 @@ spanToWrite.setTimestamp(span.startTimestamp); | ||
} | ||
this.logger.logSpan(spanToWrite); | ||
} | ||
}, { | ||
key: '_updateSpanMap', | ||
key: "_updateSpanMap", | ||
value: function _updateSpanMap(id, updater) { | ||
var span = void 0; | ||
var span; | ||
if (this.partialSpans.has(id)) { | ||
@@ -96,3 +103,5 @@ span = this.partialSpans.get(id); | ||
} | ||
updater(span); | ||
if (span.endTimestamp) { | ||
@@ -105,3 +114,3 @@ this._writeSpan(id); | ||
}, { | ||
key: '_timedOut', | ||
key: "_timedOut", | ||
value: function _timedOut(span) { | ||
@@ -111,3 +120,3 @@ return span.startTimestamp + this.timeout < now(); | ||
}, { | ||
key: 'record', | ||
key: "record", | ||
value: function record(rec) { | ||
@@ -121,2 +130,3 @@ var id = rec.traceId; | ||
break; | ||
case 'ClientRecv': | ||
@@ -126,2 +136,3 @@ span.finish(); | ||
break; | ||
case 'ServerSend': | ||
@@ -131,2 +142,3 @@ span.finish(); | ||
break; | ||
case 'ServerRecv': | ||
@@ -137,5 +149,7 @@ // TODO: only set this to false when we know we in an existing trace | ||
break; | ||
case 'ProducerStart': | ||
span.delegate.setKind('PRODUCER'); | ||
break; | ||
case 'ProducerStop': | ||
@@ -145,5 +159,7 @@ span.finish(); | ||
break; | ||
case 'ConsumerStart': | ||
span.delegate.setKind('CONSUMER'); | ||
break; | ||
case 'ConsumerStop': | ||
@@ -153,2 +169,3 @@ span.finish(); | ||
break; | ||
case 'MessageAddr': | ||
@@ -161,20 +178,27 @@ span.delegate.setRemoteEndpoint(new Endpoint({ | ||
break; | ||
case 'LocalOperationStart': | ||
span.delegate.setName(rec.annotation.name); | ||
break; | ||
case 'LocalOperationStop': | ||
span.finish(); | ||
break; | ||
case 'Message': | ||
span.delegate.addAnnotation(rec.timestamp, rec.annotation.message); | ||
break; | ||
case 'Rpc': | ||
span.delegate.setName(rec.annotation.name); | ||
break; | ||
case 'ServiceName': | ||
span.localEndpoint.setServiceName(rec.annotation.serviceName); | ||
break; | ||
case 'BinaryAnnotation': | ||
span.delegate.putTag(rec.annotation.key, rec.annotation.value); | ||
break; | ||
case 'LocalAddr': | ||
@@ -184,2 +208,3 @@ span.localEndpoint.setIpv4(rec.annotation.host && rec.annotation.host.ipv4()); | ||
break; | ||
case 'ServerAddr': | ||
@@ -193,2 +218,3 @@ span.delegate.setKind('CLIENT'); | ||
break; | ||
default: | ||
@@ -200,3 +226,3 @@ break; | ||
}, { | ||
key: 'toString', | ||
key: "toString", | ||
value: function toString() { | ||
@@ -203,0 +229,0 @@ return 'BatchRecorder()'; |
@@ -1,8 +0,12 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var ConsoleRecorder = function () { | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
var ConsoleRecorder = | ||
/*#__PURE__*/ | ||
function () { | ||
/* eslint-disable no-console */ | ||
@@ -18,9 +22,9 @@ function ConsoleRecorder() { | ||
_createClass(ConsoleRecorder, [{ | ||
key: 'record', | ||
key: "record", | ||
value: function record(rec) { | ||
var id = rec.traceId; | ||
this.logger('Record at (spanId=' + id.spanId + ', parentId=' + id.parentId + ',' + (' traceId=' + id.traceId + '): ' + rec.annotation.toString())); | ||
this.logger("Record at (spanId=".concat(id.spanId, ", parentId=").concat(id.parentId, ",") + " traceId=".concat(id.traceId, "): ").concat(rec.annotation.toString())); | ||
} | ||
}, { | ||
key: 'toString', | ||
key: "toString", | ||
value: function toString() { | ||
@@ -27,0 +31,0 @@ return 'consoleTracer'; |
"use strict"; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
module.exports = function () { | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
module.exports = | ||
/*#__PURE__*/ | ||
function () { | ||
function ExplicitContext() { | ||
@@ -39,2 +43,3 @@ _classCallCheck(this, ExplicitContext); | ||
_this.setContext(ctx); | ||
return callable(); | ||
@@ -41,0 +46,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -3,0 +3,0 @@ module.exports = { |
@@ -1,45 +0,57 @@ | ||
'use strict'; | ||
"use strict"; | ||
var option = require('./option'); | ||
var _option = _interopRequireDefault(require("./option")); | ||
var Annotation = require('./annotation'); | ||
var Tracer = require('./tracer'); | ||
var createNoopTracer = require('./tracer/noop'); | ||
var randomTraceId = require('./tracer/randomTraceId'); | ||
var TraceId = require('./tracer/TraceId'); | ||
var sampler = require('./tracer/sampler'); | ||
var _annotation = _interopRequireDefault(require("./annotation")); | ||
var HttpHeaders = require('./httpHeaders'); | ||
var InetAddress = require('./InetAddress'); | ||
var _tracer = _interopRequireDefault(require("./tracer")); | ||
var BatchRecorder = require('./batch-recorder'); | ||
var ConsoleRecorder = require('./console-recorder'); | ||
var _noop = _interopRequireDefault(require("./tracer/noop")); | ||
var ExplicitContext = require('./explicit-context'); | ||
var _randomTraceId = _interopRequireDefault(require("./tracer/randomTraceId")); | ||
var Request = require('./request'); | ||
var Instrumentation = require('./instrumentation'); | ||
var _sampler = _interopRequireDefault(require("./tracer/sampler")); | ||
var model = require('./model'); | ||
var jsonEncoder = require('./jsonEncoder'); | ||
var parseRequestUrl = require('./parseUrl'); | ||
var _TraceId = _interopRequireDefault(require("./tracer/TraceId")); | ||
var _httpHeaders = _interopRequireDefault(require("./httpHeaders")); | ||
var _InetAddress = _interopRequireDefault(require("./InetAddress")); | ||
var _batchRecorder = _interopRequireDefault(require("./batch-recorder")); | ||
var _consoleRecorder = _interopRequireDefault(require("./console-recorder")); | ||
var _explicitContext = _interopRequireDefault(require("./explicit-context")); | ||
var _instrumentation = _interopRequireDefault(require("./instrumentation")); | ||
var _request = _interopRequireDefault(require("./request")); | ||
var _jsonEncoder = _interopRequireDefault(require("./jsonEncoder")); | ||
var _model = _interopRequireDefault(require("./model")); | ||
var _parseUrl = _interopRequireDefault(require("./parseUrl")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
module.exports = { | ||
Tracer: Tracer, | ||
createNoopTracer: createNoopTracer, | ||
randomTraceId: randomTraceId, | ||
TraceId: TraceId, | ||
option: option, | ||
Annotation: Annotation, | ||
InetAddress: InetAddress, | ||
HttpHeaders: HttpHeaders, | ||
BatchRecorder: BatchRecorder, | ||
ConsoleRecorder: ConsoleRecorder, | ||
ExplicitContext: ExplicitContext, | ||
sampler: sampler, | ||
Request: Request, | ||
Instrumentation: Instrumentation, | ||
model: model, | ||
jsonEncoder: jsonEncoder, | ||
parseRequestUrl: parseRequestUrl | ||
Tracer: _tracer.default, | ||
createNoopTracer: _noop.default, | ||
randomTraceId: _randomTraceId.default, | ||
TraceId: _TraceId.default, | ||
option: _option.default, | ||
Annotation: _annotation.default, | ||
InetAddress: _InetAddress.default, | ||
HttpHeaders: _httpHeaders.default, | ||
BatchRecorder: _batchRecorder.default, | ||
ConsoleRecorder: _consoleRecorder.default, | ||
ExplicitContext: _explicitContext.default, | ||
sampler: _sampler.default, | ||
Request: _request.default, | ||
Instrumentation: _instrumentation.default, | ||
model: _model.default, | ||
jsonEncoder: _jsonEncoder.default, | ||
parseRequestUrl: _parseUrl.default | ||
}; |
@@ -1,10 +0,14 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var InetAddress = function () { | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
var InetAddress = | ||
/*#__PURE__*/ | ||
function () { | ||
function InetAddress(addr) { | ||
@@ -14,19 +18,19 @@ _classCallCheck(this, InetAddress); | ||
this.addr = addr; | ||
} | ||
} // returns undefined if this isn't an IPv4 string | ||
// returns undefined if this isn't an IPv4 string | ||
_createClass(InetAddress, [{ | ||
key: 'ipv4', | ||
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', | ||
key: "toInt", | ||
value: function toInt() { | ||
@@ -36,13 +40,12 @@ // e.g. 10.57.50.83 | ||
// 171520595 | ||
var parts = this.addr.split('.'); | ||
// The jshint tool always complains about using bitwise operators, | ||
var parts = this.addr.split('.'); // The jshint tool always complains about using bitwise operators, | ||
// but in this case it's actually intentional, so we disable the warning: | ||
// jshint bitwise: false | ||
return parts[0] << 24 | parts[1] << 16 | parts[2] << 8 | parts[3]; | ||
} | ||
}, { | ||
key: 'toString', | ||
key: "toString", | ||
value: function toString() { | ||
return 'InetAddress(' + this.addr + ')'; | ||
return "InetAddress(".concat(this.addr, ")"); | ||
} | ||
@@ -52,15 +55,15 @@ }]); | ||
return InetAddress; | ||
}(); | ||
}(); // In non-node environments we fallback to 127.0.0.1 | ||
// In non-node environments we fallback to 127.0.0.1 | ||
InetAddress.getLocalAddress = function getLocalAddress() { | ||
var isNode = (typeof process === "undefined" ? "undefined" : _typeof(process)) === 'object' && typeof process.on === 'function'; | ||
InetAddress.getLocalAddress = function getLocalAddress() { | ||
var isNode = (typeof process === 'undefined' ? 'undefined' : _typeof(process)) === 'object' && typeof process.on === 'function'; | ||
if (!isNode) { | ||
return new InetAddress('127.0.0.1'); | ||
} | ||
} // eslint-disable-next-line global-require | ||
// eslint-disable-next-line global-require | ||
var networkAddress = require('network-address'); | ||
var networkAddress = require('./network'); | ||
return new InetAddress(networkAddress.ipv4()); | ||
@@ -67,0 +70,0 @@ }; |
@@ -1,21 +0,27 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
var Annotation = require('../annotation'); | ||
var Request = require('../request'); | ||
var parseRequestUrl = require('../parseUrl'); | ||
function requiredArg(name) { | ||
throw new Error('HttpClientInstrumentation: Missing required argument ' + name + '.'); | ||
throw new Error("HttpClientInstrumentation: Missing required argument ".concat(name, ".")); | ||
} | ||
var HttpClientInstrumentation = function () { | ||
var HttpClientInstrumentation = | ||
/*#__PURE__*/ | ||
function () { | ||
function HttpClientInstrumentation(_ref) { | ||
var _ref$tracer = _ref.tracer, | ||
tracer = _ref$tracer === undefined ? requiredArg('tracer') : _ref$tracer, | ||
tracer = _ref$tracer === void 0 ? requiredArg('tracer') : _ref$tracer, | ||
_ref$serviceName = _ref.serviceName, | ||
serviceName = _ref$serviceName === undefined ? tracer.localEndpoint.serviceName : _ref$serviceName, | ||
serviceName = _ref$serviceName === void 0 ? tracer.localEndpoint.serviceName : _ref$serviceName, | ||
remoteServiceName = _ref.remoteServiceName; | ||
@@ -31,3 +37,3 @@ | ||
_createClass(HttpClientInstrumentation, [{ | ||
key: 'recordRequest', | ||
key: "recordRequest", | ||
value: function recordRequest(request, url, method) { | ||
@@ -44,2 +50,3 @@ this.tracer.setId(this.tracer.createChildId()); | ||
this.tracer.recordAnnotation(new Annotation.ClientSend()); | ||
if (this.remoteServiceName) { | ||
@@ -55,13 +62,15 @@ // TODO: can we get the host and port of the http connection? | ||
}, { | ||
key: 'recordResponse', | ||
key: "recordResponse", | ||
value: function recordResponse(traceId, statusCode) { | ||
this.tracer.setId(traceId); | ||
this.tracer.recordBinary('http.status_code', statusCode.toString()); | ||
if (statusCode < 200 || statusCode > 399) { | ||
this.tracer.recordBinary('error', statusCode.toString()); | ||
} | ||
this.tracer.recordAnnotation(new Annotation.ClientRecv()); | ||
} | ||
}, { | ||
key: 'recordError', | ||
key: "recordError", | ||
value: function recordError(traceId, error) { | ||
@@ -68,0 +77,0 @@ this.tracer.setId(traceId); |
@@ -1,11 +0,17 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
var Annotation = require('../annotation'); | ||
var Header = require('../httpHeaders'); | ||
var InetAddress = require('../InetAddress'); | ||
var TraceId = require('../tracer/TraceId'); | ||
var parseRequestUrl = require('../parseUrl'); | ||
@@ -34,14 +40,16 @@ | ||
function requiredArg(name) { | ||
throw new Error('HttpServerInstrumentation: Missing required argument ' + name + '.'); | ||
throw new Error("HttpServerInstrumentation: Missing required argument ".concat(name, ".")); | ||
} | ||
var HttpServerInstrumentation = function () { | ||
var HttpServerInstrumentation = | ||
/*#__PURE__*/ | ||
function () { | ||
function HttpServerInstrumentation(_ref) { | ||
var _ref$tracer = _ref.tracer, | ||
tracer = _ref$tracer === undefined ? requiredArg('tracer') : _ref$tracer, | ||
tracer = _ref$tracer === void 0 ? requiredArg('tracer') : _ref$tracer, | ||
_ref$serviceName = _ref.serviceName, | ||
serviceName = _ref$serviceName === undefined ? tracer.localEndpoint.serviceName : _ref$serviceName, | ||
serviceName = _ref$serviceName === void 0 ? tracer.localEndpoint.serviceName : _ref$serviceName, | ||
host = _ref.host, | ||
_ref$port = _ref.port, | ||
port = _ref$port === undefined ? requiredArg('port') : _ref$port; | ||
port = _ref$port === void 0 ? requiredArg('port') : _ref$port; | ||
@@ -57,7 +65,9 @@ _classCallCheck(this, HttpServerInstrumentation); | ||
_createClass(HttpServerInstrumentation, [{ | ||
key: '_createIdFromHeaders', | ||
key: "_createIdFromHeaders", | ||
value: function _createIdFromHeaders(readHeader) { | ||
var _this = this; | ||
if (containsRequiredHeaders(readHeader)) { | ||
var spanId = readHeader(Header.SpanId); | ||
return spanId.map(function (sid) { | ||
var parentId = spanId.map(function (sid) { | ||
var traceId = readHeader(Header.TraceId); | ||
@@ -75,2 +85,7 @@ var parentSpanId = readHeader(Header.ParentSpanId); | ||
}); | ||
return !this.tracer.supportsJoin ? parentId.map(function (id) { | ||
return _this.tracer.letId(id, function () { | ||
return _this.tracer.createChildId(); | ||
}); | ||
}) : parentId; | ||
} else { | ||
@@ -87,9 +102,10 @@ if (readHeader(Header.Flags) !== None || readHeader(Header.Sampled) !== None) { | ||
}, { | ||
key: 'recordRequest', | ||
key: "recordRequest", | ||
value: function recordRequest(method, requestUrl, readHeader) { | ||
var _this = this; | ||
var _this2 = this; | ||
this._createIdFromHeaders(readHeader).ifPresent(function (id) { | ||
return _this.tracer.setId(id); | ||
return _this2.tracer.setId(id); | ||
}); | ||
var id = this.tracer.id; | ||
@@ -104,11 +120,14 @@ | ||
this.tracer.recordAnnotation(new Annotation.ServerRecv()); | ||
this.tracer.recordAnnotation(new Annotation.LocalAddr({ host: this.host, port: this.port })); | ||
this.tracer.recordAnnotation(new Annotation.LocalAddr({ | ||
host: this.host, | ||
port: this.port | ||
})); | ||
return id; | ||
} | ||
}, { | ||
key: 'recordResponse', | ||
key: "recordResponse", | ||
value: function recordResponse(id, statusCode, error) { | ||
this.tracer.setId(id); | ||
this.tracer.recordBinary('http.status_code', statusCode.toString()); | ||
if (error) { | ||
@@ -119,2 +138,3 @@ this.tracer.recordBinary('error', error.toString()); | ||
} | ||
this.tracer.recordAnnotation(new Annotation.ServerSend()); | ||
@@ -121,0 +141,0 @@ } |
@@ -1,4 +0,5 @@ | ||
'use strict'; | ||
"use strict"; | ||
var HttpServer = require('./httpServer'); | ||
var HttpClient = require('./httpClient'); | ||
@@ -5,0 +6,0 @@ |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -7,11 +7,16 @@ function toV1Endpoint(endpoint) { | ||
} | ||
var res = { | ||
serviceName: endpoint.serviceName || '' // undefined is not allowed in v1 | ||
}; | ||
if (endpoint.ipv4) { | ||
res.ipv4 = endpoint.ipv4; | ||
} | ||
if (endpoint.port) { | ||
res.port = endpoint.port; | ||
} | ||
return res; | ||
@@ -32,2 +37,3 @@ } | ||
}; | ||
if (span.parentId) { | ||
@@ -37,6 +43,7 @@ // instead of writing "parentId": NULL | ||
} | ||
res.id = span.id; | ||
res.name = span.name || ''; // undefined is not allowed in v1 | ||
// Log timestamp and duration if this tracer started and completed this span. | ||
// Log timestamp and duration if this tracer started and completed this span. | ||
if (!span.shared) { | ||
@@ -48,6 +55,6 @@ res.timestamp = span.timestamp; | ||
var jsonEndpoint = toV1Endpoint(span.localEndpoint); | ||
var beginAnnotation; | ||
var endAnnotation; | ||
var addressKey; | ||
var beginAnnotation = void 0; | ||
var endAnnotation = void 0; | ||
var addressKey = void 0; | ||
switch (span.kind) { | ||
@@ -59,2 +66,3 @@ case 'CLIENT': | ||
break; | ||
case 'SERVER': | ||
@@ -65,2 +73,3 @@ beginAnnotation = span.timestamp ? 'sr' : undefined; | ||
break; | ||
case 'PRODUCER': | ||
@@ -71,2 +80,3 @@ beginAnnotation = span.timestamp ? 'ms' : undefined; | ||
break; | ||
case 'CONSUMER': | ||
@@ -79,4 +89,6 @@ if (span.timestamp && span.duration) { | ||
} | ||
addressKey = 'ma'; | ||
break; | ||
default: | ||
@@ -98,2 +110,3 @@ } | ||
}); | ||
if (span.duration) { | ||
@@ -109,2 +122,3 @@ res.annotations.push({ | ||
var keys = Object.keys(span.tags); | ||
if (keys.length > 0 || span.remoteEndpoint) { | ||
@@ -134,2 +148,3 @@ // don't write empty array | ||
} | ||
return JSON.stringify(res); | ||
@@ -142,36 +157,49 @@ } | ||
}; | ||
if (span.parentId) { | ||
copy.parentId = span.parentId; | ||
} | ||
copy.id = span.id; | ||
if (span.name) { | ||
copy.name = span.name; | ||
} | ||
if (span.kind) { | ||
copy.kind = span.kind; | ||
} | ||
if (span.timestamp) { | ||
copy.timestamp = span.timestamp; | ||
} | ||
if (span.duration) { | ||
copy.duration = span.duration; | ||
} | ||
if (span.localEndpoint) { | ||
copy.localEndpoint = span.localEndpoint; | ||
} | ||
if (span.remoteEndpoint) { | ||
copy.remoteEndpoint = span.remoteEndpoint; | ||
} | ||
if (span.annotations.length > 0) { | ||
copy.annotations = span.annotations; | ||
} | ||
if (Object.keys(span.tags).length > 0) { | ||
copy.tags = span.tags; | ||
} | ||
if (span.debug) { | ||
copy.debug = true; | ||
} | ||
if (span.shared) { | ||
copy.shared = true; | ||
} | ||
return JSON.stringify(copy); | ||
@@ -178,0 +206,0 @@ } |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -7,3 +7,2 @@ function Endpoint(_ref) { | ||
port = _ref.port; | ||
this.setServiceName(serviceName); | ||
@@ -13,2 +12,3 @@ this.setIpv4(ipv4); | ||
} | ||
Endpoint.prototype.setServiceName = function setServiceName(serviceName) { | ||
@@ -18,8 +18,11 @@ // In zipkin, names are lowercase. This eagerly converts to alert users early. | ||
}; | ||
Endpoint.prototype.setIpv4 = function setIpv4(ipv4) { | ||
this.ipv4 = ipv4; | ||
}; | ||
Endpoint.prototype.setPort = function setPort(port) { | ||
this.port = port || undefined; | ||
}; | ||
Endpoint.prototype.isEmpty = function isEmpty() { | ||
@@ -33,4 +36,5 @@ return this.serviceName === undefined && this.ipv4 === undefined && this.port === undefined; | ||
} | ||
Annotation.prototype.toString = function toString() { | ||
return 'Annotation(value="' + this.value + '")'; | ||
return "Annotation(value=\"".concat(this.value, "\")"); | ||
}; | ||
@@ -42,12 +46,18 @@ | ||
this.traceId = traceId.traceId; | ||
traceId._parentId.ifPresent(function (id) { | ||
_this.parentId = id; | ||
}); | ||
this.id = traceId.spanId; | ||
this.name = undefined; // no default | ||
this.kind = undefined; // no default | ||
this.timestamp = undefined; | ||
this.duration = undefined; | ||
this.localEndpoint = undefined; // no default | ||
this.remoteEndpoint = undefined; // no default | ||
this.annotations = []; | ||
@@ -63,8 +73,11 @@ this.tags = {}; | ||
}; | ||
Span.prototype.setKind = function setKind(kind) { | ||
this.kind = kind; | ||
}; | ||
Span.prototype.setTimestamp = function setTimestamp(timestamp) { | ||
this.timestamp = timestamp; | ||
}; | ||
Span.prototype.setDuration = function setDuration(duration) { | ||
@@ -76,2 +89,3 @@ // Due to rounding errors, a fraction ends up as zero, so check undefined | ||
}; | ||
Span.prototype.setLocalEndpoint = function setLocalEndpoint(ep) { | ||
@@ -84,2 +98,3 @@ if (ep && !ep.isEmpty()) { | ||
}; | ||
Span.prototype.setRemoteEndpoint = function setRemoteEndpoint(ep) { | ||
@@ -92,14 +107,19 @@ if (ep && !ep.isEmpty()) { | ||
}; | ||
Span.prototype.addAnnotation = function addAnnotation(timestamp, value) { | ||
this.annotations.push(new Annotation(timestamp, value)); | ||
}; | ||
Span.prototype.putTag = function putTag(key, value) { | ||
this.tags[key] = value.toString(); | ||
}; | ||
Span.prototype.setDebug = function setDebug(debug) { | ||
this.debug = debug; | ||
}; | ||
Span.prototype.setShared = function setShared(shared) { | ||
this.shared = shared; | ||
}; | ||
Span.prototype.toString = function toString() { | ||
@@ -109,3 +129,3 @@ var annotations = this.annotations.map(function (a) { | ||
}).join(', '); | ||
return 'Span(id=' + this.traceId + ', annotations=[' + annotations + '])'; | ||
return "Span(id=".concat(this.traceId, ", annotations=[").concat(annotations, "])"); | ||
}; | ||
@@ -112,0 +132,0 @@ |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -15,2 +15,3 @@ var os = require('os'); | ||
} | ||
return family === 'IPv4' ? '127.0.0.1' : '::1'; | ||
@@ -22,2 +23,3 @@ } | ||
/*eslint-disable */ | ||
for (var i in interfaces) { | ||
@@ -27,2 +29,3 @@ /*eslint-enable */ | ||
} | ||
return ifaces; | ||
@@ -45,3 +48,2 @@ } | ||
ipv4.ipv6 = ipv6; | ||
module.exports = ipv4; |
@@ -1,7 +0,9 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
var None = { | ||
@@ -11,29 +13,28 @@ get type() { | ||
}, | ||
get present() { | ||
return false; | ||
}, | ||
map: function map() { | ||
return None; | ||
return this; | ||
}, | ||
ifPresent: function ifPresent() {}, | ||
flatMap: function flatMap() { | ||
return None; | ||
return this; | ||
}, | ||
getOrElse: function getOrElse(f) { | ||
if (f instanceof Function) { | ||
return f(); | ||
} else { | ||
return f; | ||
} | ||
return f instanceof Function ? f() : f; | ||
}, | ||
equals: function equals(other) { | ||
return other.type === 'None'; | ||
return other === this; | ||
}, | ||
toString: function toString() { | ||
return 'None'; | ||
}, | ||
get present() { | ||
return false; | ||
} | ||
}; | ||
var Some = function () { | ||
var Some = | ||
/*#__PURE__*/ | ||
function () { | ||
function Some(value) { | ||
@@ -46,3 +47,3 @@ _classCallCheck(this, Some); | ||
_createClass(Some, [{ | ||
key: 'map', | ||
key: "map", | ||
value: function map(f) { | ||
@@ -52,13 +53,13 @@ return new Some(f(this.value)); | ||
}, { | ||
key: 'ifPresent', | ||
key: "ifPresent", | ||
value: function ifPresent(f) { | ||
return this.map(f); | ||
f(this.value); | ||
} | ||
}, { | ||
key: 'flatMap', | ||
key: "flatMap", | ||
value: function flatMap(f) { | ||
return this.map(f).getOrElse(None); | ||
return f(this.value); | ||
} | ||
}, { | ||
key: 'getOrElse', | ||
key: "getOrElse", | ||
value: function getOrElse() { | ||
@@ -68,3 +69,3 @@ return this.value; | ||
}, { | ||
key: 'equals', | ||
key: "equals", | ||
value: function equals(other) { | ||
@@ -74,15 +75,15 @@ return other instanceof Some && other.value === this.value; | ||
}, { | ||
key: 'toString', | ||
key: "toString", | ||
value: function toString() { | ||
return 'Some(' + this.value.toString() + ')'; | ||
return "Some(".concat(this.value, ")"); | ||
} | ||
}, { | ||
key: 'present', | ||
key: "type", | ||
get: function get() { | ||
return true; | ||
return 'Some'; | ||
} | ||
}, { | ||
key: 'type', | ||
key: "present", | ||
get: function get() { | ||
return 'Some'; | ||
return true; | ||
} | ||
@@ -92,9 +93,7 @@ }]); | ||
return Some; | ||
}(); | ||
}(); // Used to validate input arguments | ||
// Used to validate input arguments | ||
function isOptional(data) { | ||
return data != null && (data instanceof Some || data === None || data.type === 'Some' || data.type === 'None'); | ||
return data instanceof Some || None.equals(data); | ||
} | ||
@@ -106,8 +105,9 @@ | ||
} | ||
if (isOptional(data)) { | ||
if (isOptional(data.value)) { | ||
throw new Error('Error: data (' + data.value.toString() + ') is wrapped in Option twice'); | ||
throw new Error("Error: data (".concat(data.value, ") is wrapped in Option twice")); | ||
} | ||
} else { | ||
throw new Error('Error: data (' + data + ') is not an Option!'); | ||
throw new Error("Error: data (".concat(data, ") is not an Option!")); | ||
} | ||
@@ -117,4 +117,4 @@ } | ||
function verifyIsNotOptional(data) { | ||
if (data != null && isOptional(data)) { | ||
throw new Error('Error: data (' + data + ') is an Option!'); | ||
if (isOptional(data)) { | ||
throw new Error("Error: data (".concat(data, ") is an Option!")); | ||
} | ||
@@ -124,7 +124,3 @@ } | ||
function fromNullable(nullable) { | ||
if (nullable != null) { | ||
return new Some(nullable); | ||
} else { | ||
return None; | ||
} | ||
return nullable == null ? None : new Some(nullable); | ||
} | ||
@@ -131,0 +127,0 @@ |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -7,3 +7,2 @@ var url = require('url'); | ||
var parsed = url.parse(requestUrl); | ||
return { | ||
@@ -10,0 +9,0 @@ host: parsed.hostname, |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -13,2 +13,3 @@ var HttpHeaders = require('./httpHeaders'); | ||
}); | ||
traceId.sampled.ifPresent(function (sampled) { | ||
@@ -18,2 +19,6 @@ headers[HttpHeaders.Sampled] = sampled ? '1' : '0'; | ||
if (traceId.isDebug()) { | ||
headers[HttpHeaders.Flags] = '1'; | ||
} | ||
return headers; | ||
@@ -24,3 +29,5 @@ } | ||
var headers = appendZipkinHeaders(req, traceId); | ||
return Object.assign({}, req, { headers: headers }); | ||
return Object.assign({}, req, { | ||
headers: headers | ||
}); | ||
} | ||
@@ -27,0 +34,0 @@ |
@@ -1,6 +0,5 @@ | ||
'use strict'; | ||
"use strict"; | ||
var hrTimeSupport = typeof process !== 'undefined' && process.hrtime; | ||
var hrTimeSupport = typeof process !== 'undefined' && process.hrtime; // since hrtime isn't available, we can ignore the input parameters | ||
// since hrtime isn't available, we can ignore the input parameters | ||
function nowLegacy() { | ||
@@ -18,7 +17,7 @@ return Date.now() * 1000; | ||
} | ||
} | ||
// Returns the current time in epoch microseconds | ||
} // Returns the current time in epoch microseconds | ||
// if startTimestamp and startTick are present, process.hrtime is used | ||
// See https://nodejs.org/api/process.html#process_process_hrtime_time | ||
module.exports.now = hrTimeSupport ? nowHrTime : nowLegacy; | ||
@@ -25,0 +24,0 @@ module.exports.hrtime = hrTimeSupport ? function () { |
@@ -1,7 +0,9 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
var _require = require('../option'), | ||
@@ -17,4 +19,7 @@ None = _require.None, | ||
var Annotation = require('../annotation'); | ||
var Record = require('./record'); | ||
var TraceId = require('./TraceId'); | ||
var randomTraceId = require('./randomTraceId'); | ||
@@ -32,23 +37,33 @@ | ||
function requiredArg(name) { | ||
throw new Error('Tracer: Missing required argument ' + name + '.'); | ||
throw new Error("Tracer: Missing required argument ".concat(name, ".")); | ||
} | ||
var Tracer = function () { | ||
var Tracer = | ||
/*#__PURE__*/ | ||
function () { | ||
function Tracer(_ref) { | ||
var _ref$ctxImpl = _ref.ctxImpl, | ||
ctxImpl = _ref$ctxImpl === undefined ? requiredArg('ctxImpl') : _ref$ctxImpl, | ||
ctxImpl = _ref$ctxImpl === void 0 ? requiredArg('ctxImpl') : _ref$ctxImpl, | ||
_ref$recorder = _ref.recorder, | ||
recorder = _ref$recorder === undefined ? requiredArg('recorder') : _ref$recorder, | ||
recorder = _ref$recorder === void 0 ? requiredArg('recorder') : _ref$recorder, | ||
_ref$sampler = _ref.sampler, | ||
sampler = _ref$sampler === undefined ? new Sampler(alwaysSample) : _ref$sampler, | ||
sampler = _ref$sampler === void 0 ? new Sampler(alwaysSample) : _ref$sampler, | ||
_ref$traceId128Bit = _ref.traceId128Bit, | ||
traceId128Bit = _ref$traceId128Bit === undefined ? false : _ref$traceId128Bit, | ||
traceId128Bit = _ref$traceId128Bit === void 0 ? false : _ref$traceId128Bit, | ||
_ref$supportsJoin = _ref.supportsJoin, | ||
supportsJoin = _ref$supportsJoin === void 0 ? true : _ref$supportsJoin, | ||
localServiceName = _ref.localServiceName, | ||
localEndpoint = _ref.localEndpoint; | ||
localEndpoint = _ref.localEndpoint, | ||
_ref$log = _ref.log, | ||
log = _ref$log === void 0 ? console : _ref$log, | ||
defaultTags = _ref.defaultTags; | ||
_classCallCheck(this, Tracer); | ||
this.log = log; | ||
this.recorder = recorder; | ||
this.sampler = sampler; | ||
this.traceId128Bit = traceId128Bit; | ||
this.supportsJoin = supportsJoin; | ||
if (localEndpoint) { | ||
@@ -61,2 +76,3 @@ this._localEndpoint = localEndpoint; | ||
} | ||
this._ctxImpl = ctxImpl; | ||
@@ -66,6 +82,10 @@ this._defaultTraceId = this.createRootId(); | ||
this._startTick = hrtime(); | ||
if (defaultTags) { | ||
this.setTags(defaultTags); | ||
} | ||
} | ||
_createClass(Tracer, [{ | ||
key: 'scoped', | ||
key: "scoped", | ||
value: function scoped(callback) { | ||
@@ -75,3 +95,3 @@ return this._ctxImpl.scoped(callback); | ||
}, { | ||
key: 'letId', | ||
key: "letId", | ||
value: function letId(id, callback) { | ||
@@ -81,7 +101,6 @@ return this._ctxImpl.letContext(id, callback); | ||
}, { | ||
key: 'createRootId', | ||
key: "createRootId", | ||
value: function createRootId() { | ||
var isSampled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : None; | ||
var isDebug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
var rootSpanId = randomTraceId(); | ||
@@ -104,6 +123,5 @@ var traceId = this.traceId128Bit ? new Some(randomTraceId() + rootSpanId) : None; | ||
}, { | ||
key: 'createChildId', | ||
key: "createChildId", | ||
value: function createChildId() { | ||
var currentId = fromNullable(this._ctxImpl.getContext()); | ||
var childId = new TraceId({ | ||
@@ -124,13 +142,13 @@ traceId: currentId.map(function (id) { | ||
}); | ||
if (childId.sampled.present === false) { | ||
childId._sampled = this.sampler.shouldSample(childId); | ||
} | ||
return childId; | ||
} | ||
// creates a span, timing the given callable, adding any error as a tag | ||
} // creates a span, timing the given callable, adding any error as a tag | ||
// if the callable returns a promise, a span stops after the promise resolves | ||
}, { | ||
key: 'local', | ||
key: "local", | ||
value: function local(operationName, callable) { | ||
@@ -142,9 +160,14 @@ var _this = this; | ||
} | ||
return this.scoped(function () { | ||
var traceId = _this.createChildId(); | ||
_this.setId(traceId); | ||
_this.recordServiceName(_this._localEndpoint.serviceName); | ||
_this.recordAnnotation(new Annotation.LocalOperationStart(operationName)); | ||
var result = void 0; | ||
var result; | ||
try { | ||
@@ -154,9 +177,12 @@ result = callable(); | ||
_this.recordBinary('error', err.message ? err.message : err.toString()); | ||
_this.recordAnnotation(new Annotation.LocalOperationStop()); | ||
throw err; | ||
} | ||
} // Finish the span on a synchronous success | ||
// Finish the span on a synchronous success | ||
if (!isPromise(result)) { | ||
_this.recordAnnotation(new Annotation.LocalOperationStop()); | ||
return result; | ||
@@ -167,5 +193,5 @@ } | ||
return result; // no need to stop as it was never started | ||
} | ||
} // At this point we know we are sampled. Explicitly record against the ID | ||
// At this point we know we are sampled. Explicitly record against the ID | ||
var explicitRecord = function explicitRecord(annotation) { | ||
@@ -177,5 +203,5 @@ return _this.recorder.record(new Record({ | ||
})); | ||
}; | ||
}; // Ensure the span representing the promise completes | ||
// Ensure the span representing the promise completes | ||
return result.then(function (output) { | ||
@@ -193,3 +219,3 @@ explicitRecord(new Annotation.LocalOperationStop()); | ||
}, { | ||
key: 'setId', | ||
key: "setId", | ||
value: function setId(traceId) { | ||
@@ -199,6 +225,7 @@ this._ctxImpl.setContext(traceId); | ||
}, { | ||
key: 'recordAnnotation', | ||
key: "recordAnnotation", | ||
value: function recordAnnotation(annotation) { | ||
var _this2 = this; | ||
var timestamp = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : now(this._startTimestamp, this._startTick); | ||
this.id.sampled.ifPresent(function (sampled) { | ||
@@ -209,3 +236,3 @@ if (!sampled) return; | ||
traceId: _this2.id, | ||
timestamp: now(_this2._startTimestamp, _this2._startTick), | ||
timestamp: timestamp, | ||
annotation: annotation | ||
@@ -216,3 +243,3 @@ })); | ||
}, { | ||
key: 'recordMessage', | ||
key: "recordMessage", | ||
value: function recordMessage(message) { | ||
@@ -222,3 +249,3 @@ this.recordAnnotation(new Annotation.Message(message)); | ||
}, { | ||
key: 'recordServiceName', | ||
key: "recordServiceName", | ||
value: function recordServiceName(serviceName) { | ||
@@ -228,3 +255,3 @@ this.recordAnnotation(new Annotation.ServiceName(serviceName)); | ||
}, { | ||
key: 'recordRpc', | ||
key: "recordRpc", | ||
value: function recordRpc(name) { | ||
@@ -234,3 +261,3 @@ this.recordAnnotation(new Annotation.Rpc(name)); | ||
}, { | ||
key: 'recordClientAddr', | ||
key: "recordClientAddr", | ||
value: function recordClientAddr(ia) { | ||
@@ -240,3 +267,3 @@ this.recordAnnotation(new Annotation.ClientAddr(ia)); | ||
}, { | ||
key: 'recordServerAddr', | ||
key: "recordServerAddr", | ||
value: function recordServerAddr(ia) { | ||
@@ -246,3 +273,3 @@ this.recordAnnotation(new Annotation.ServerAddr(ia)); | ||
}, { | ||
key: 'recordLocalAddr', | ||
key: "recordLocalAddr", | ||
value: function recordLocalAddr(ia) { | ||
@@ -252,3 +279,3 @@ this.recordAnnotation(new Annotation.LocalAddr(ia)); | ||
}, { | ||
key: 'recordBinary', | ||
key: "recordBinary", | ||
value: function recordBinary(key, value) { | ||
@@ -258,9 +285,20 @@ this.recordAnnotation(new Annotation.BinaryAnnotation(key, value)); | ||
}, { | ||
key: 'writeIdToConsole', | ||
key: "writeIdToConsole", | ||
value: function writeIdToConsole(message) { | ||
/* eslint-disable no-console */ | ||
console.log(message + ': ' + this.id.toString()); | ||
this.log.info("".concat(message, ": ").concat(this.id.toString())); | ||
} | ||
}, { | ||
key: 'id', | ||
key: "setTags", | ||
value: function setTags() { | ||
var tags = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
// eslint-disable-next-line no-restricted-syntax | ||
for (var tag in tags) { | ||
if (tags.hasOwnProperty(tag)) { | ||
this.recordBinary(tag, tags[tag]); | ||
} | ||
} | ||
} | ||
}, { | ||
key: "id", | ||
get: function get() { | ||
@@ -270,3 +308,3 @@ return this._ctxImpl.getContext() || this._defaultTraceId; | ||
}, { | ||
key: 'localEndpoint', | ||
key: "localEndpoint", | ||
get: function get() { | ||
@@ -273,0 +311,0 @@ return this._localEndpoint; |
@@ -1,4 +0,5 @@ | ||
'use strict'; | ||
"use strict"; | ||
var Tracer = require('./'); | ||
var ExplicitContext = require('../explicit-context'); | ||
@@ -11,3 +12,6 @@ | ||
var ctxImpl = new ExplicitContext(); | ||
return new Tracer({ recorder: recorder, ctxImpl: ctxImpl }); | ||
return new Tracer({ | ||
recorder: recorder, | ||
ctxImpl: ctxImpl | ||
}); | ||
}; |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -7,2 +7,3 @@ // === Generate a random 64-bit number in fixed-length hex format | ||
var n = ''; | ||
for (var i = 0; i < 16; i++) { | ||
@@ -12,2 +13,3 @@ var rand = Math.floor(Math.random() * 16); | ||
} | ||
return n; | ||
@@ -14,0 +16,0 @@ } |
"use strict"; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var Record = function () { | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
var Record = | ||
/*#__PURE__*/ | ||
function () { | ||
function Record(_ref) { | ||
@@ -23,3 +27,3 @@ var traceId = _ref.traceId, | ||
value: function toString() { | ||
return "Record(traceId=" + this.traceId.toString() + ", annotation=" + this.annotation.toString() + ")"; | ||
return "Record(traceId=".concat(this.traceId.toString(), ", annotation=").concat(this.annotation.toString(), ")"); | ||
} | ||
@@ -26,0 +30,0 @@ }]); |
@@ -1,14 +0,23 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
var _require = require('../option'), | ||
Some = _require.Some; | ||
// Determines whether or not a traceId should be sampled. | ||
Some = _require.Some; // Determines whether or not a traceId should be sampled. | ||
// If no sample decision is already made (by a debug flag, or | ||
@@ -20,3 +29,5 @@ // the "sampled" property is set), it will use evaluator, | ||
var Sampler = function () { | ||
var Sampler = | ||
/*#__PURE__*/ | ||
function () { | ||
function Sampler(evaluator) { | ||
@@ -29,3 +40,3 @@ _classCallCheck(this, Sampler); | ||
_createClass(Sampler, [{ | ||
key: 'shouldSample', | ||
key: "shouldSample", | ||
value: function shouldSample(traceId) { | ||
@@ -40,5 +51,5 @@ var _this = this; | ||
}, { | ||
key: 'toString', | ||
key: "toString", | ||
value: function toString() { | ||
return 'Sampler(' + this.evaluator.toString() + ')'; | ||
return "Sampler(".concat(this.evaluator.toString(), ")"); | ||
} | ||
@@ -54,2 +65,3 @@ }]); | ||
} | ||
neverSample.toString = function () { | ||
@@ -63,2 +75,3 @@ return 'never sample'; | ||
} | ||
alwaysSample.toString = function () { | ||
@@ -76,2 +89,3 @@ return 'always sample'; | ||
var limit = parseInt(1 / sampleRate); | ||
var counting = function counting(traceId) { | ||
@@ -84,5 +98,7 @@ // eslint-disable-line no-unused-vars | ||
}; | ||
counting.toString = function () { | ||
return 'countingSampler: sampleRate=' + sampleRate; | ||
return "countingSampler: sampleRate=".concat(sampleRate); | ||
}; | ||
return counting; | ||
@@ -92,3 +108,5 @@ } | ||
var CountingSampler = function (_Sampler) { | ||
var CountingSampler = | ||
/*#__PURE__*/ | ||
function (_Sampler) { | ||
_inherits(CountingSampler, _Sampler); | ||
@@ -101,3 +119,3 @@ | ||
return _possibleConstructorReturn(this, (CountingSampler.__proto__ || Object.getPrototypeOf(CountingSampler)).call(this, makeCountingEvaluator(sampleRate < 1 ? sampleRate : 1))); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(CountingSampler).call(this, makeCountingEvaluator(sampleRate < 1 ? sampleRate : 1))); | ||
} | ||
@@ -108,2 +126,7 @@ | ||
module.exports = { Sampler: Sampler, CountingSampler: CountingSampler, neverSample: neverSample, alwaysSample: alwaysSample }; | ||
module.exports = { | ||
Sampler: Sampler, | ||
CountingSampler: CountingSampler, | ||
neverSample: neverSample, | ||
alwaysSample: alwaysSample | ||
}; |
@@ -1,7 +0,9 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
var _require = require('../option'), | ||
@@ -13,3 +15,5 @@ Some = _require.Some, | ||
var TraceId = function () { | ||
var TraceId = | ||
/*#__PURE__*/ | ||
function () { | ||
function TraceId(params) { | ||
@@ -19,11 +23,10 @@ _classCallCheck(this, TraceId); | ||
var _params$traceId = params.traceId, | ||
traceId = _params$traceId === undefined ? None : _params$traceId, | ||
traceId = _params$traceId === void 0 ? None : _params$traceId, | ||
_params$parentId = params.parentId, | ||
parentId = _params$parentId === undefined ? None : _params$parentId, | ||
parentId = _params$parentId === void 0 ? None : _params$parentId, | ||
spanId = params.spanId, | ||
_params$sampled = params.sampled, | ||
sampled = _params$sampled === undefined ? None : _params$sampled, | ||
sampled = _params$sampled === void 0 ? None : _params$sampled, | ||
_params$flags = params.flags, | ||
flags = _params$flags === undefined ? 0 : _params$flags; | ||
flags = _params$flags === void 0 ? 0 : _params$flags; | ||
verifyIsOptional(traceId); | ||
@@ -41,3 +44,3 @@ verifyIsOptional(parentId); | ||
_createClass(TraceId, [{ | ||
key: 'isDebug', | ||
key: "isDebug", | ||
value: function isDebug() { | ||
@@ -50,8 +53,8 @@ // The jshint tool always complains about using bitwise operators, | ||
}, { | ||
key: 'toString', | ||
key: "toString", | ||
value: function toString() { | ||
return 'TraceId(spanId=' + this.spanId.toString() + (', parentId=' + this.parentId.toString()) + (', traceId=' + this.traceId.toString() + ')'); | ||
return "TraceId(spanId=".concat(this.spanId.toString()) + ", parentId=".concat(this.parentId.toString()) + ", traceId=".concat(this.traceId.toString(), ")"); | ||
} | ||
}, { | ||
key: 'spanId', | ||
key: "spanId", | ||
get: function get() { | ||
@@ -61,3 +64,3 @@ return this._spanId; | ||
}, { | ||
key: 'parentId', | ||
key: "parentId", | ||
get: function get() { | ||
@@ -67,3 +70,3 @@ return this._parentId.getOrElse(this.spanId); | ||
}, { | ||
key: 'traceId', | ||
key: "traceId", | ||
get: function get() { | ||
@@ -73,3 +76,3 @@ return this._traceId.getOrElse(this.parentId); | ||
}, { | ||
key: 'sampled', | ||
key: "sampled", | ||
get: function get() { | ||
@@ -79,3 +82,3 @@ return this.isDebug() ? new Some(true) : this._sampled; | ||
}, { | ||
key: 'flags', | ||
key: "flags", | ||
get: function get() { | ||
@@ -82,0 +85,0 @@ return this._flags; |
{ | ||
"name": "zipkin", | ||
"version": "0.14.3", | ||
"version": "0.15.0", | ||
"description": "The core tracer for zipkin.js", | ||
@@ -8,4 +8,4 @@ "main": "lib/index.js", | ||
"scripts": { | ||
"build": "babel src -d lib", | ||
"test": "tsc index.d.ts && mocha --require ../../test/helper.js", | ||
"build": "babel src -d lib --extensions \".ts\" --extensions \".js\"", | ||
"test": "tsc index.d.ts && mocha --require ../../test/helper.js --require @babel/register", | ||
"prepublish": "npm run build" | ||
@@ -18,11 +18,13 @@ }, | ||
"base64-js": "^1.1.2", | ||
"is-promise": "^2.1.0", | ||
"network-address": "^1.1.0" | ||
"is-promise": "^2.1.0" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.23.0", | ||
"@babel/cli": "7.1.5", | ||
"@babel/core": "7.1.5", | ||
"@babel/preset-typescript": "7.1.0", | ||
"bluebird": "^3.5.1", | ||
"mocha": "^3.2.0", | ||
"mocha": "^5.2.0", | ||
"typescript": "^2.4.2" | ||
} | ||
}, | ||
"gitHead": "efd22b807a6d6056a319d9468231480e7a58a402" | ||
} |
@@ -41,3 +41,3 @@ class InetAddress { | ||
// eslint-disable-next-line global-require | ||
const networkAddress = require('network-address'); | ||
const networkAddress = require('./network'); | ||
return new InetAddress(networkAddress.ipv4()); | ||
@@ -44,0 +44,0 @@ }; |
@@ -28,2 +28,3 @@ const Annotation = require('../annotation'); | ||
this.tracer.recordBinary('http.path', path); | ||
this.tracer.recordAnnotation(new Annotation.ClientSend()); | ||
@@ -30,0 +31,0 @@ if (this.remoteServiceName) { |
@@ -33,3 +33,3 @@ const Annotation = require('../annotation'); | ||
host, | ||
port = requiredArg('port'), | ||
port = requiredArg('port') | ||
}) { | ||
@@ -45,3 +45,3 @@ this.tracer = tracer; | ||
const spanId = readHeader(Header.SpanId); | ||
return spanId.map(sid => { | ||
const parentId = spanId.map(sid => { | ||
const traceId = readHeader(Header.TraceId); | ||
@@ -59,2 +59,9 @@ const parentSpanId = readHeader(Header.ParentSpanId); | ||
}); | ||
return !this.tracer.supportsJoin | ||
? parentId.map(id => | ||
this.tracer.letId(id, () => | ||
this.tracer.createChildId() | ||
) | ||
) | ||
: parentId; | ||
} else { | ||
@@ -80,2 +87,3 @@ if (readHeader(Header.Flags) !== None || readHeader(Header.Sampled) !== None) { | ||
this.tracer.recordBinary('http.path', path); | ||
this.tracer.recordAnnotation(new Annotation.ServerRecv()); | ||
@@ -82,0 +90,0 @@ this.tracer.recordAnnotation(new Annotation.LocalAddr({host: this.host, port: this.port})); |
@@ -5,28 +5,23 @@ const None = { | ||
}, | ||
get present() { | ||
return false; | ||
}, | ||
map() { | ||
return None; | ||
return this; | ||
}, | ||
ifPresent() {}, | ||
flatMap() { | ||
return None; | ||
return this; | ||
}, | ||
getOrElse(f) { | ||
if (f instanceof Function) { | ||
return f(); | ||
} else { | ||
return f; | ||
} | ||
return f instanceof Function ? f() : f; | ||
}, | ||
equals(other) { | ||
return other.type === 'None'; | ||
return other === this; | ||
}, | ||
toString() { | ||
return 'None'; | ||
}, | ||
get present() { | ||
return false; | ||
} | ||
}; | ||
class Some { | ||
@@ -36,2 +31,8 @@ constructor(value) { | ||
} | ||
get type() { | ||
return 'Some'; | ||
} | ||
get present() { | ||
return true; | ||
} | ||
map(f) { | ||
@@ -41,6 +42,6 @@ return new Some(f(this.value)); | ||
ifPresent(f) { | ||
return this.map(f); | ||
f(this.value); | ||
} | ||
flatMap(f) { | ||
return this.map(f).getOrElse(None); | ||
return f(this.value); | ||
} | ||
@@ -54,10 +55,4 @@ getOrElse() { | ||
toString() { | ||
return `Some(${this.value.toString()})`; | ||
return `Some(${this.value})`; | ||
} | ||
get present() { | ||
return true; | ||
} | ||
get type() { | ||
return 'Some'; | ||
} | ||
} | ||
@@ -67,8 +62,3 @@ | ||
function isOptional(data) { | ||
return data != null && ( | ||
data instanceof Some || | ||
data === None || | ||
data.type === 'Some' || | ||
data.type === 'None' | ||
); | ||
return data instanceof Some || None.equals(data); | ||
} | ||
@@ -82,3 +72,3 @@ | ||
if (isOptional(data.value)) { | ||
throw new Error(`Error: data (${data.value.toString()}) is wrapped in Option twice`); | ||
throw new Error(`Error: data (${data.value}) is wrapped in Option twice`); | ||
} | ||
@@ -91,3 +81,3 @@ } else { | ||
function verifyIsNotOptional(data) { | ||
if (data != null && isOptional(data)) { | ||
if (isOptional(data)) { | ||
throw new Error(`Error: data (${data}) is an Option!`); | ||
@@ -98,7 +88,3 @@ } | ||
function fromNullable(nullable) { | ||
if (nullable != null) { | ||
return new Some(nullable); | ||
} else { | ||
return None; | ||
} | ||
return nullable == null ? None : new Some(nullable); | ||
} | ||
@@ -105,0 +91,0 @@ |
@@ -15,2 +15,6 @@ const HttpHeaders = require('./httpHeaders'); | ||
if (traceId.isDebug()) { | ||
headers[HttpHeaders.Flags] = '1'; | ||
} | ||
return headers; | ||
@@ -17,0 +21,0 @@ } |
@@ -27,8 +27,18 @@ const {None, Some, fromNullable} = require('../option'); | ||
traceId128Bit = false, | ||
// supportsJoin enables using the same span ID for both server spans and client | ||
// spans. By default it is set to true, but if you are sending the tracing data | ||
// to a service that expects to have a unique span ID for each span you must set | ||
// this to false. | ||
supportsJoin = true, | ||
localServiceName, | ||
localEndpoint | ||
localEndpoint, | ||
/* eslint-disable no-console */ | ||
log = console, | ||
defaultTags | ||
}) { | ||
this.log = log; | ||
this.recorder = recorder; | ||
this.sampler = sampler; | ||
this.traceId128Bit = traceId128Bit; | ||
this.supportsJoin = supportsJoin; | ||
if (localEndpoint) { | ||
@@ -45,2 +55,5 @@ this._localEndpoint = localEndpoint; | ||
this._startTick = hrtime(); | ||
if (defaultTags) { | ||
this.setTags(defaultTags); | ||
} | ||
} | ||
@@ -159,3 +172,3 @@ | ||
recordAnnotation(annotation) { | ||
recordAnnotation(annotation, timestamp = now(this._startTimestamp, this._startTick)) { | ||
this.id.sampled.ifPresent(sampled => { | ||
@@ -166,3 +179,3 @@ if (!sampled) return; | ||
traceId: this.id, | ||
timestamp: now(this._startTimestamp, this._startTick), | ||
timestamp, | ||
annotation | ||
@@ -216,7 +229,15 @@ })); | ||
writeIdToConsole(message) { | ||
/* eslint-disable no-console */ | ||
console.log(`${message}: ${this.id.toString()}`); | ||
this.log.info(`${message}: ${this.id.toString()}`); | ||
} | ||
setTags(tags = {}) { | ||
// eslint-disable-next-line no-restricted-syntax | ||
for (const tag in tags) { | ||
if (tags.hasOwnProperty(tag)) { | ||
this.recordBinary(tag, tags[tag]); | ||
} | ||
} | ||
} | ||
} | ||
module.exports = Tracer; |
@@ -0,3 +1,3 @@ | ||
import {expect} from 'chai'; | ||
import { Annotation, InetAddress } from 'zipkin'; | ||
import {expect} from 'chai'; | ||
@@ -4,0 +4,0 @@ describe('Annotation types', () => { |
@@ -0,3 +1,3 @@ | ||
import {expect} from 'chai'; | ||
import { ExplicitContext } from 'zipkin'; | ||
import {expect} from 'chai'; | ||
@@ -4,0 +4,0 @@ describe('ExplicitContext', () => { |
@@ -0,3 +1,3 @@ | ||
import { expect } from 'chai'; | ||
import { InetAddress } from 'zipkin'; | ||
import { expect } from 'chai'; | ||
@@ -4,0 +4,0 @@ describe('InetAddress', () => { |
@@ -1,3 +0,3 @@ | ||
import {Instrumentation, Tracer, ExplicitContext, ConsoleRecorder} from 'zipkin'; | ||
import {expect} from 'chai'; | ||
import {ConsoleRecorder, ExplicitContext, Instrumentation, Tracer} from 'zipkin'; | ||
@@ -10,3 +10,3 @@ describe('Instrumentation', () => { | ||
ctxImpl: new ExplicitContext(), | ||
recorder: new ConsoleRecorder(), | ||
recorder: new ConsoleRecorder() | ||
}), | ||
@@ -26,5 +26,5 @@ serviceName: 'weather-app', | ||
ctxImpl: new ExplicitContext(), | ||
recorder: new ConsoleRecorder(), | ||
recorder: new ConsoleRecorder() | ||
}), | ||
port: 8000, | ||
port: 8000 | ||
} | ||
@@ -31,0 +31,0 @@ ); |
@@ -1,3 +0,3 @@ | ||
import { jsonEncoder, JsonEncoder, model, TraceId, option } from 'zipkin'; | ||
import { expect } from 'chai'; | ||
import { jsonEncoder, JsonEncoder, model, option, TraceId } from 'zipkin'; | ||
@@ -14,2 +14,2 @@ describe('JsonEncoder', () => { | ||
}); | ||
}); | ||
}); |
@@ -0,3 +1,3 @@ | ||
import {expect} from 'chai'; | ||
import {model, option, TraceId} from 'zipkin'; | ||
import {expect} from 'chai'; | ||
@@ -10,3 +10,3 @@ describe('Model', () => { | ||
ipv4: '10.0.0.1', | ||
port: 8000, | ||
port: 8000 | ||
}); | ||
@@ -21,3 +21,3 @@ | ||
traceId: new option.Some('a'), | ||
spanId: 'b', | ||
spanId: 'b' | ||
})); | ||
@@ -24,0 +24,0 @@ |
@@ -0,3 +1,3 @@ | ||
import { expect } from 'chai'; | ||
import { randomTraceId } from 'zipkin'; | ||
import { expect } from 'chai'; | ||
@@ -4,0 +4,0 @@ describe('RandomTraceId', () => { |
@@ -1,3 +0,3 @@ | ||
import { ConsoleRecorder, BatchRecorder, Logger, model } from 'zipkin'; | ||
import {expect} from 'chai'; | ||
import { BatchRecorder, ConsoleRecorder, Logger, model } from 'zipkin'; | ||
@@ -7,8 +7,9 @@ describe('Recorder types', () => { | ||
it('should return correct type', () => { | ||
class Log implements Logger { | ||
logSpan(span: model.Span): void { | ||
} | ||
} | ||
const batchRecorder: BatchRecorder = new BatchRecorder({ | ||
logger: new class implements Logger { | ||
logSpan(span: model.Span): void { | ||
} | ||
}, | ||
timeout: 1000, | ||
logger: new Log(), | ||
timeout: 1000 | ||
}); | ||
@@ -15,0 +16,0 @@ |
import { expect } from 'chai'; | ||
import {Request, TraceId, option, RequestZipkinHeaders} from 'zipkin'; | ||
import {option, Request, RequestZipkinHeaders, TraceId} from 'zipkin'; | ||
import Some = option.Some; | ||
@@ -28,3 +28,3 @@ | ||
const requestWithCookie: RequestZipkinHeaders<{ url : string}, { cookie: string }> = | ||
const requestWithCookie: RequestZipkinHeaders<{ url: string}, { cookie: string }> = | ||
Request.addZipkinHeaders( | ||
@@ -31,0 +31,0 @@ { url: 'google.com', headers: { cookie: 'abc' } }, |
@@ -0,3 +1,3 @@ | ||
import { expect } from 'chai'; | ||
import { sampler } from 'zipkin'; | ||
import { expect } from 'chai'; | ||
@@ -4,0 +4,0 @@ describe('Sampler', () => { |
@@ -1,3 +0,3 @@ | ||
import { Tracer, ExplicitContext } from 'zipkin'; | ||
import { expect } from 'chai'; | ||
import { ExplicitContext, Tracer } from 'zipkin'; | ||
@@ -4,0 +4,0 @@ describe('Tracer', () => { |
@@ -1,3 +0,3 @@ | ||
import { TraceId, option } from 'zipkin'; | ||
import { expect } from 'chai'; | ||
import { option, TraceId } from 'zipkin'; | ||
@@ -4,0 +4,0 @@ describe('TraceId', () => { |
@@ -7,7 +7,19 @@ const sinon = require('sinon'); | ||
const setupTest = () => { | ||
const record = sinon.spy(); | ||
const recorder = {record}; | ||
const ctxImpl = new ExplicitContext(); | ||
return {record, recorder, ctxImpl}; | ||
}; | ||
const setupServerUrl = () => { | ||
const port = 80; | ||
const host = '127.0.0.1'; | ||
const url = `http://${host}:${port}`; | ||
return {port, host, url}; | ||
}; | ||
describe('Http Server Instrumentation', () => { | ||
it('should create traceId', () => { | ||
const record = sinon.spy(); | ||
const recorder = {record}; | ||
const ctxImpl = new ExplicitContext(); | ||
const {record, recorder, ctxImpl} = setupTest(); | ||
const tracer = new Tracer({recorder, ctxImpl}); | ||
@@ -73,10 +85,6 @@ const instrumentation = new HttpServer({tracer, serviceName: 'service-a', port: 80}); | ||
it(`should extract trace from the client and record annotations case ${index}`, () => { | ||
const record = sinon.spy(); | ||
const recorder = {record}; | ||
const ctxImpl = new ExplicitContext(); | ||
const {record, recorder, ctxImpl} = setupTest(); | ||
const tracer = new Tracer({recorder, ctxImpl}); | ||
const port = 80; | ||
const host = '127.0.0.1'; | ||
const url = `http://${host}:${port}`; | ||
const {port, url} = setupServerUrl(); | ||
const instrumentation = new HttpServer({tracer, serviceName: 'service-a', port}); | ||
@@ -123,2 +131,54 @@ | ||
traceContextCases.forEach((headers, index) => { | ||
it(`should should not join spans if join not supported case ${index}`, () => { | ||
const {record, recorder, ctxImpl} = setupTest(); | ||
const tracer = new Tracer({recorder, ctxImpl, supportsJoin: false}); | ||
const {port, url} = setupServerUrl(); | ||
const instrumentation = new HttpServer({ | ||
tracer, | ||
serviceName: 'service-a', | ||
port | ||
}); | ||
const readHeader = function(name) { | ||
return headers[name] ? new Some(headers[name]) : None; | ||
}; | ||
ctxImpl.scoped(() => { | ||
const id = instrumentation.recordRequest('POST', url, readHeader); | ||
tracer.recordBinary('message', 'hello from within app'); | ||
instrumentation.recordResponse(id, 202); | ||
}); | ||
const annotations = record.args.map(args => args[0]); | ||
annotations.forEach(ann => expect(ann.traceId.traceId).to.equal('aaa')); | ||
annotations.forEach(ann => expect(ann.traceId.parentId).to.equal('bbb')); | ||
annotations.forEach(ann => expect(ann.traceId.spanId).to.not.equal('bbb')); | ||
expect(annotations[0].annotation.annotationType).to.equal('ServiceName'); | ||
expect(annotations[0].annotation.serviceName).to.equal('service-a'); | ||
expect(annotations[1].annotation.annotationType).to.equal('Rpc'); | ||
expect(annotations[1].annotation.name).to.equal('POST'); | ||
expect(annotations[2].annotation.annotationType).to.equal('BinaryAnnotation'); | ||
expect(annotations[2].annotation.key).to.equal('http.path'); | ||
expect(annotations[2].annotation.value).to.equal('/'); | ||
expect(annotations[3].annotation.annotationType).to.equal('ServerRecv'); | ||
expect(annotations[4].annotation.annotationType).to.equal('LocalAddr'); | ||
expect(annotations[5].annotation.annotationType).to.equal('BinaryAnnotation'); | ||
expect(annotations[5].annotation.key).to.equal('message'); | ||
expect(annotations[5].annotation.value).to.equal('hello from within app'); | ||
expect(annotations[6].annotation.annotationType).to.equal('BinaryAnnotation'); | ||
expect(annotations[6].annotation.key).to.equal('http.status_code'); | ||
expect(annotations[6].annotation.value).to.equal('202'); | ||
expect(annotations[7].annotation.annotationType).to.equal('ServerSend'); | ||
}); | ||
}); | ||
const samplingFlagCases = [ | ||
@@ -153,9 +213,6 @@ {headers: {'X-B3-Flags': '0'}, hasAnnotations: null}, | ||
it(`should receive sampling flags from the client with ${caseName.join(', ')}`, () => { | ||
const record = sinon.spy(); | ||
const recorder = {record}; | ||
const ctxImpl = new ExplicitContext(); | ||
const {record, recorder, ctxImpl} = setupTest(); | ||
const tracer = new Tracer({recorder, ctxImpl}); | ||
const port = 80; | ||
const url = `http://127.0.0.1:${port}`; | ||
const {port, url} = setupServerUrl(); | ||
const instrumentation = new HttpServer({tracer, serviceName: 'service-a', port}); | ||
@@ -211,5 +268,3 @@ | ||
it('should properly report the path excluding the query string', () => { | ||
const record = sinon.spy(); | ||
const recorder = {record}; | ||
const ctxImpl = new ExplicitContext(); | ||
const {record, recorder, ctxImpl} = setupTest(); | ||
const tracer = new Tracer({recorder, ctxImpl}); | ||
@@ -235,5 +290,3 @@ | ||
it('should accept a 128bit X-B3-TraceId', () => { | ||
const record = sinon.spy(); | ||
const recorder = {record}; | ||
const ctxImpl = new ExplicitContext(); | ||
const {record, recorder, ctxImpl} = setupTest(); | ||
const tracer = new Tracer({recorder, ctxImpl}); | ||
@@ -263,5 +316,3 @@ | ||
it('should tolerate boolean literals for sampled header received from the client', () => { | ||
const record = sinon.spy(); | ||
const recorder = {record}; | ||
const ctxImpl = new ExplicitContext(); | ||
const {recorder, ctxImpl} = setupTest(); | ||
const tracer = new Tracer({recorder, ctxImpl}); | ||
@@ -297,5 +348,3 @@ | ||
it('should allow the host to be overridden', () => { | ||
const record = sinon.spy(); | ||
const recorder = {record}; | ||
const ctxImpl = new ExplicitContext(); | ||
const {record, recorder, ctxImpl} = setupTest(); | ||
const tracer = new Tracer({recorder, ctxImpl}); | ||
@@ -322,5 +371,3 @@ const instrumentation = new HttpServer({ | ||
it('should work if the host option is not defined', () => { | ||
const record = sinon.spy(); | ||
const recorder = {record}; | ||
const ctxImpl = new ExplicitContext(); | ||
const {record, recorder, ctxImpl} = setupTest(); | ||
const tracer = new Tracer({recorder, ctxImpl}); | ||
@@ -327,0 +374,0 @@ const instrumentation = new HttpServer({ |
@@ -31,2 +31,13 @@ const Request = require('../src/request.js'); | ||
}); | ||
it('should add flags headers if debug is on', () => { | ||
const traceId = new TraceId({ | ||
spanId: '48485a3953bb6124', | ||
flags: 1 | ||
}); | ||
const req = Request.addZipkinHeaders({}, traceId); | ||
expect(req.headers[HttpHeaders.Flags]).to.equal('1'); | ||
expect(req.headers[HttpHeaders.SpanId]).to.equal('48485a3953bb6124'); | ||
}); | ||
}); |
@@ -99,2 +99,47 @@ const sinon = require('sinon'); | ||
it('should record binary tags', () => { | ||
const record = sinon.spy(); | ||
const recorder = {record}; | ||
const ctxImpl = new ExplicitContext(); | ||
const localServiceName = 'smoothie-store'; | ||
const trace = new Tracer({ctxImpl, recorder, localServiceName}); | ||
const defaultTags = {instanceId: 'i-1234567890abcdef0', cluster: 'nodeservice-stage'}; | ||
ctxImpl.scoped(() => { | ||
trace.setTags(defaultTags); | ||
const annotations = record.args.map(args => args[0]); | ||
expect(annotations[0].annotation.annotationType).to.equal('BinaryAnnotation'); | ||
expect(annotations[0].annotation.key).to.equal('instanceId'); | ||
expect(annotations[0].annotation.value).to.equal('i-1234567890abcdef0'); | ||
expect(annotations[1].annotation.annotationType).to.equal('BinaryAnnotation'); | ||
expect(annotations[1].annotation.key).to.equal('cluster'); | ||
expect(annotations[1].annotation.value).to.equal('nodeservice-stage'); | ||
}); | ||
}); | ||
it('should record defaultTags', () => { | ||
const record = sinon.spy(); | ||
const recorder = {record}; | ||
const ctxImpl = new ExplicitContext(); | ||
const localServiceName = 'smoothie-store'; | ||
const defaultTags = {instanceId: 'i-1234567890abcdef0', cluster: 'nodeservice-stage'}; | ||
// eslint-disable-next-line no-unused-vars | ||
const trace = new Tracer({ctxImpl, recorder, localServiceName, defaultTags}); | ||
ctxImpl.scoped(() => { | ||
const annotations = record.args.map(args => args[0]); | ||
expect(annotations[0].annotation.annotationType).to.equal('BinaryAnnotation'); | ||
expect(annotations[0].annotation.key).to.equal('instanceId'); | ||
expect(annotations[0].annotation.value).to.equal('i-1234567890abcdef0'); | ||
expect(annotations[1].annotation.annotationType).to.equal('BinaryAnnotation'); | ||
expect(annotations[1].annotation.key).to.equal('cluster'); | ||
expect(annotations[1].annotation.value).to.equal('nodeservice-stage'); | ||
}); | ||
}); | ||
it('should complete a local span on error type', () => { | ||
@@ -334,2 +379,14 @@ const record = sinon.spy(); | ||
it('should log timestamps from second parameter if it present', () => { | ||
const record = sinon.spy(); | ||
const recorder = {record}; | ||
const ctxImpl = new ExplicitContext(); | ||
const trace = new Tracer({ctxImpl, recorder}); | ||
ctxImpl.scoped(() => { | ||
trace.recordAnnotation(new Annotation.ServerSend(), 87654321); | ||
expect(record.getCall(0).args[0].timestamp).to.equal(87654321); | ||
}); | ||
}); | ||
it('should create fixed-length 64-bit trace ID by default', () => { | ||
@@ -336,0 +393,0 @@ const recorder = { |
Sorry, the diff of this file is too big to display
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
2166357
2.78%2
-33.33%94
18.99%13392
6.39%0
-100%6
50%- Removed
- Removed