Comparing version 0.18.5 to 0.18.6
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.Zipkin={})}(this,function(t){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){for(var n=0;e.length>n;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function o(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),t}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&s(t,e)}function a(t){return(a=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function s(t,e){return(s=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function u(t,e){return!e||"object"!=typeof e&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}var c={get type(){return"None"},get present(){return!1},map:function(){return this},ifPresent:function(){},flatMap:function(){return this},getOrElse:function(t){return t instanceof Function?t():t},equals:function(t){return t===this},toString:function(){return"None"}},h=function(){function t(e){n(this,t),this.value=e}return o(t,[{key:"map",value:function(e){return new t(e(this.value))}},{key:"ifPresent",value:function(t){t(this.value)}},{key:"flatMap",value:function(t){return t(this.value)}},{key:"getOrElse",value:function(){return this.value}},{key:"equals",value:function(e){return e instanceof t&&e.value===this.value}},{key:"toString",value:function(){return"Some(".concat(this.value,")")}},{key:"type",get:function(){return"Some"}},{key:"present",get:function(){return!0}}]),t}();function f(t){return t instanceof h||c.equals(t)}var p={Some:h,None:c,isOptional:f,verifyIsOptional:function(t){if(null==t)throw Error("Error: data is not Optional - it's null");if(!f(t))throw Error("Error: data (".concat(t,") is not an Option!"));if(f(t.value))throw Error("Error: data (".concat(t.value,") is wrapped in Option twice"))},verifyIsNotOptional:function(t){if(f(t))throw Error("Error: data (".concat(t,") is an Option!"))},fromNullable:function(t){return null==t?c:new h(t)}},l="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function d(){throw Error("setTimeout has not been defined")}function m(){throw Error("clearTimeout has not been defined")}var v=d,g=m;function y(t){if(v===setTimeout)return setTimeout(t,0);if((v===d||!v)&&setTimeout)return v=setTimeout,setTimeout(t,0);try{return v(t,0)}catch(e){try{return v.call(null,t,0)}catch(e){return v.call(this,t,0)}}}"function"==typeof l.setTimeout&&(v=setTimeout),"function"==typeof l.clearTimeout&&(g=clearTimeout);var w,I=[],b=!1,E=-1;function S(){b&&w&&(b=!1,w.length?I=w.concat(I):E=-1,I.length&&A())}function A(){if(!b){var t=y(S);b=!0;for(var e=I.length;e;){for(w=I,I=[];++E<e;)w&&w[E].run();E=-1,e=I.length}w=null,b=!1,function(t){if(g===clearTimeout)return clearTimeout(t);if((g===m||!g)&&clearTimeout)return g=clearTimeout,clearTimeout(t);try{g(t)}catch(e){try{return g.call(null,t)}catch(e){return g.call(this,t)}}}(t)}}function R(t,e){this.fun=t,this.array=e}R.prototype.run=function(){this.fun.apply(null,this.array)};function _(){}var k=_,T=_,O=_,C=_,P=_,N=_,U=_;var x=l.performance||{},B=x.now||x.mozNow||x.msNow||x.oNow||x.webkitNow||function(){return(new Date).getTime()};var L=new Date;var M,j={nextTick:function(t){var e=[];if(arguments.length>1)for(var n=1;arguments.length>n;n++)e[n-1]=arguments[n];I.push(new R(t,e)),1!==I.length||b||y(A)},title:"browser",browser:!0,env:{},argv:[],version:"",versions:{},on:k,addListener:T,once:O,off:C,removeListener:P,removeAllListeners:N,emit:U,binding:function(t){throw Error("process.binding is not supported")},cwd:function(){return"/"},chdir:function(t){throw Error("process.chdir is not supported")},umask:function(){return 0},hrtime:function(t){var e=.001*B.call(x),n=Math.floor(e),r=Math.floor(e%1*1e9);return t&&(n-=t[0],0>(r-=t[1])&&(n--,r+=1e9)),[n,r]},platform:"browser",release:{},config:{},uptime:function(){return(new Date-L)/1e3}};function D(){return"/tmp"}var Y={EOL:"\n",tmpdir:D,tmpDir:D,networkInterfaces:function(){},getNetworkInterfaces:function(){},release:function(){return void 0!==l.navigator?l.navigator.appVersion:""},type:function(){return"Browser"},cpus:function(){return[]},totalmem:function(){return Number.MAX_VALUE},freemem:function(){return Number.MAX_VALUE},uptime:function(){return 0},loadavg:function(){return[]},hostname:function(){return void 0!==l.location?l.location.hostname:""},endianness:function(){if(void 0===M){var t=new ArrayBuffer(2),e=new Uint8Array(t),n=new Uint16Array(t);if(e[0]=1,e[1]=2,258===n[0])M="BE";else{if(513!==n[0])throw Error("unable to figure out endianess");M="LE"}}return M}};function q(t,e){for(var n in t)for(var r=t[n].length-1;r>=0;r-=1){var o=t[n][r];if(!o.internal&&o.family===e&&("IPv4"===e||0===o.scopeid))return o.address}return"IPv4"===e?"127.0.0.1":"::1"}function F(t,e){var n={};for(var r in t)r===e&&(n[r]=t[r]);return n}function z(t){var e=Y.networkInterfaces();return t&&(e=F(e,t)),q(e,"IPv4")}z.ipv4=z,z.ipv6=function(t){var e=Y.networkInterfaces();return t&&(e=F(e,t)),q(e,"IPv6")};var K=z,H=function(){function t(e){n(this,t),this.addr=e}return o(t,[{key:"ipv4",value:function(){var t=this.toInt();if(t&&0!==t)return this.addr}},{key:"toInt",value:function(){var t=this.addr.split(".");return t[0]<<24|t[1]<<16|t[2]<<8|t[3]}},{key:"toString",value:function(){return"InetAddress(".concat(this.addr,")")}}]),t}();H.getLocalAddress=function(){return"object"===(void 0===j?"undefined":e(j))&&"function"==typeof j.on?new H(K.ipv4()):new H("127.0.0.1")};var V=H,J=function(){function t(){n(this,t)}return o(t,[{key:"toString",value:function(){return"".concat(this.annotationType,"()")}}]),t}(),X=function(t){function e(){return n(this,e),u(this,a(e).apply(this,arguments))}return i(e,J),e}(),Z=function(t){function e(){return n(this,e),u(this,a(e).apply(this,arguments))}return i(e,J),e}(),$=function(t){function e(){return n(this,e),u(this,a(e).apply(this,arguments))}return i(e,J),e}(),G=function(t){function e(){return n(this,e),u(this,a(e).apply(this,arguments))}return i(e,J),e}(),Q=function(t){function e(){return n(this,e),u(this,a(e).apply(this,arguments))}return i(e,J),e}(),W=function(t){function e(){return n(this,e),u(this,a(e).apply(this,arguments))}return i(e,J),e}(),tt=function(t){function e(){return n(this,e),u(this,a(e).apply(this,arguments))}return i(e,J),e}(),et=function(t){function e(){return n(this,e),u(this,a(e).apply(this,arguments))}return i(e,J),e}();function nt(t){this.name=t}nt.prototype.toString=function(){return'LocalOperationStart("'.concat(this.name,'")')};var rt=function(t){function e(){return n(this,e),u(this,a(e).apply(this,arguments))}return i(e,J),e}();function ot(t){this.message=t}function it(t){this.serviceName=t}function at(t){this.name=t}function st(t){var e=t.port;this.host=t.host,this.port=e}function ut(t){var e=t.host,n=t.port;this.serviceName=t.serviceName,this.host=e||void 0,this.port=n||0}function ct(t){var e=t.port;this.host=t.host||V.getLocalAddress(),this.port=e||0}function ht(t){var e=t.host,n=t.port;this.serviceName=t.serviceName,this.host=e,this.port=n}function ft(t,e){this.key=t,this.value=e}ot.prototype.toString=function(){return'Message("'.concat(this.message,'")')},it.prototype.toString=function(){return'ServiceName("'.concat(this.serviceName,'")')},at.prototype.toString=function(){return'Rpc("'.concat(this.name,'")')},st.prototype.toString=function(){return'ClientAddr(host="'.concat(this.host,'", port=').concat(this.port,")")},ut.prototype.toString=function(){return'ServerAddr(serviceName="'.concat(this.serviceName,'", host="').concat(this.host,'", port=').concat(this.port,")")},ct.prototype.toString=function(){return'LocalAddr(host="'.concat(""+this.host,'", port=').concat(this.port,")")},ht.prototype.toString=function(){return'MessageAddr(serviceName="'.concat(this.serviceName,'", host="').concat(this.host,'", port=').concat(this.port,")")},ft.prototype.toString=function(){return"BinaryAnnotation(".concat(this.key,'="').concat(this.value,'")')};var pt={ClientSend:X,ClientRecv:Z,ServerSend:$,ServerRecv:G,ProducerStart:Q,ProducerStop:W,ConsumerStart:tt,ConsumerStop:et,MessageAddr:ht,Message:ot,ServiceName:it,Rpc:at,ClientAddr:st,ServerAddr:ut,LocalAddr:ct,BinaryAnnotation:ft,LocalOperationStart:nt,LocalOperationStop:rt};Object.keys(pt).forEach(function(t){pt[t].prototype.annotationType=t});var lt=pt,dt=function(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then};var mt=p.Some,vt=function(){function t(e){n(this,t),this.evaluator=e}return o(t,[{key:"shouldSample",value:function(t){var e=this,n=t.sampled.getOrElse(function(){return e.evaluator(t)});return new mt(n)}},{key:"toString",value:function(){return"Sampler(".concat(""+this.evaluator,")")}}]),t}();function gt(t){return!1}function yt(t){return!0}gt.toString=function(){return"never sample"},yt.toString=function(){return"always sample"};var wt={Sampler:vt,CountingSampler:function(t){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return n(this,e),u(this,a(e).call(this,function(t){if(t>0){if(1>t){var e=0,n=parseInt(1/t),r=function(t){var r=0==(e%=n);return e+=1,r};return r.toString=function(){return"countingSampler: sampleRate=".concat(t)},r}return yt}return gt}(1>t?t:1)))}return i(e,vt),e}(),neverSample:gt,alwaysSample:yt},It=function(){function t(e){var r=e.traceId,o=e.timestamp,i=e.annotation;n(this,t),this.traceId=r,this.timestamp=o,this.annotation=i}return o(t,[{key:"toString",value:function(){return"Record(traceId=".concat(""+this.traceId,", annotation=").concat(""+this.annotation,")")}}]),t}(),bt=p.None,Et=p.verifyIsOptional,St=p.verifyIsNotOptional,At=p.isOptional,Rt=new(0,p.Some)(!0),_t=function(){function t(e){n(this,t);var r=e.spanId,o=e.traceId,i=void 0===o?r:o,a=e.parentId,s=void 0===a?bt:a,u=e.flags,c=e.debug,h=void 0===c?1===(void 0===u?0:u):c,f=e.sampled,p=void 0===f?bt:f,l=e.shared,d=void 0!==l&&l;St(r),Et(s),Et(p),this._traceId=At(i)?i.getOrElse(r):null==i?r:i,this._parentId=s,this._spanId=r,this._sampled=h?Rt:p,this._debug=h,this._shared=d}return o(t,[{key:"isDebug",value:function(){return this._debug}},{key:"isShared",value:function(){return this._shared}},{key:"toString",value:function(){return"TraceId(spanId=".concat(""+this.spanId)+", parentSpanId=".concat(""+this.parentSpanId)+", traceId=".concat(""+this.traceId,")")}},{key:"traceId",get:function(){return this._traceId}},{key:"parentSpanId",get:function(){return this._parentId}},{key:"parentId",get:function(){return this._parentId.getOrElse(this._spanId)}},{key:"spanId",get:function(){return this._spanId}},{key:"sampled",get:function(){return this._sampled}},{key:"flags",get:function(){return this._debug?1:0}}]),t}();var kt=function(){for(var t="",e=0;16>e;e+=1)t+="0123456789abcdef"[Math.floor(16*Math.random())];return t},Tt=void 0!==j&&j.hrtime;var Ot={now:Tt?function(t,e){if(t&&e){var n=j.hrtime(e);return t+Math.floor(1e6*n[0]+n[1]/1e3)}return 1e3*Date.now()}:function(){return 1e3*Date.now()},hrtime:Tt?function(){return j.hrtime()}:function(){}};function Ct(t){var e=t.ipv4,n=t.port;this.setServiceName(t.serviceName),this.setIpv4(e),this.setPort(n)}function Pt(t,e){this.timestamp=t,this.value=""+e}function Nt(t){var e=this;this.traceId=t.traceId,t.parentSpanId.ifPresent(function(t){e.parentId=t}),this.id=t.spanId,this.name=void 0,this.kind=void 0,this.timestamp=void 0,this.duration=void 0,this.localEndpoint=void 0,this.remoteEndpoint=void 0,this.annotations=[],this.tags={},this.debug=t.isDebug(),this.shared=t.isShared()}Ct.prototype.setServiceName=function(t){this.serviceName=t?t.toLocaleLowerCase():void 0},Ct.prototype.setIpv4=function(t){this.ipv4=t},Ct.prototype.setPort=function(t){this.port=t||void 0},Ct.prototype.isEmpty=function(){return void 0===this.serviceName&&void 0===this.ipv4&&void 0===this.port},Pt.prototype.toString=function(){return'Annotation(value="'.concat(this.value,'")')},Nt.prototype.setName=function(t){this.name=t?t.toLocaleLowerCase():void 0},Nt.prototype.setKind=function(t){this.kind=t},Nt.prototype.setTimestamp=function(t){this.timestamp=t},Nt.prototype.setDuration=function(t){void 0!==t&&(this.duration=Math.max(t,1))},Nt.prototype.setLocalEndpoint=function(t){this.localEndpoint=t&&!t.isEmpty()?t:void 0},Nt.prototype.setRemoteEndpoint=function(t){this.remoteEndpoint=t&&!t.isEmpty()?t:void 0},Nt.prototype.addAnnotation=function(t,e){this.annotations.push(new Pt(t,e))},Nt.prototype.putTag=function(t,e){this.tags[t]=""+e},Nt.prototype.setDebug=function(t){this.debug=t},Nt.prototype.setShared=function(t){this.shared=t},Nt.prototype.toString=function(){var t=this.annotations.map(function(t){return""+t}).join(", ");return"Span(id=".concat(this.traceId,", annotations=[").concat(t,"])")};var Ut={Endpoint:Ct,Span:Nt},xt=p.None,Bt=p.Some,Lt=wt.Sampler,Mt=wt.alwaysSample,jt=Ot.now,Dt=Ot.hrtime,Yt=Ut.Endpoint;function qt(t){throw Error("Tracer: Missing required argument ".concat(t,"."))}function Ft(t){return null==t}var zt=function(){function t(e){var r=e.ctxImpl,o=void 0===r?qt("ctxImpl"):r,i=e.recorder,a=void 0===i?qt("recorder"):i,s=e.sampler,u=void 0===s?new Lt(Mt):s,c=e.traceId128Bit,h=void 0!==c&&c,f=e.supportsJoin,p=void 0===f||f,l=e.localServiceName,d=e.localEndpoint,m=e.log,v=void 0===m?console:m,g=e.defaultTags;n(this,t),this.log=v,this.recorder=a,this.sampler=u,this.traceId128Bit=h,this.supportsJoin=p,this._localEndpoint=d||new Yt({serviceName:l||"unknown"}),this._ctxImpl=o,this._sentinelTraceId=this.createRootId(),this._startTimestamp=jt(),this._startTick=Dt(),this.recorder.setDefaultTags&&this.recorder.setDefaultTags(g)}return o(t,[{key:"scoped",value:function(t){return this._ctxImpl.scoped(t)}},{key:"letId",value:function(t,e){return this._ctxImpl.letContext(t,e)}},{key:"createRootId",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:xt,e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=kt(),r=this.traceId128Bit?kt()+n:n,o=new _t({traceId:r,parentId:xt,spanId:n,sampled:t,flags:e?1:0});return t===xt&&(o._sampled=this.sampler.shouldSample(o)),o}},{key:"createChildId",value:function(t){if(Ft(t)&&(t=this._ctxImpl.getContext()),t===this._sentinelTraceId||Ft(t))return this.createRootId();var e=new _t({traceId:t.traceId,parentId:new Bt(t.spanId),spanId:kt(),debug:t.isDebug(),sampled:t.sampled});return!1===e.sampled.present&&(e._sampled=this.sampler.shouldSample(e)),e}},{key:"_explicitRecord",value:function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:jt(this._startTimestamp,this._startTick);this.recorder.record(new It({traceId:t,timestamp:n,annotation:e}))}},{key:"local",value:function(t,e){var n=this;if("function"!=typeof e)throw Error("you must pass a function");return this.scoped(function(){var r,o=n.createChildId();n.setId(o),n.recordServiceName(n._localEndpoint.serviceName),n.recordAnnotation(new lt.LocalOperationStart(t));try{r=e()}catch(t){throw n.recordBinary("error",t.message?t.message:""+t),n.recordAnnotation(new lt.LocalOperationStop),t}return dt(r)?o.sampled.getOrElse(!1)?r.then(function(t){return n._explicitRecord(o,new lt.LocalOperationStop),t}).catch(function(t){throw n._explicitRecord(o,new lt.BinaryAnnotation("error",t.message?t.message:""+t)),n._explicitRecord(o,new lt.LocalOperationStop),t}):r:(n.recordAnnotation(new lt.LocalOperationStop),r)})}},{key:"join",value:function(t){if(!(t instanceof _t))throw Error("Must be valid TraceId instance");return this.supportsJoin?(t.sampled===xt?t._sampled=this.sampler.shouldSample(t):t._shared=!0,t):this.createChildId(t)}},{key:"setId",value:function(t){this._ctxImpl.setContext(t)}},{key:"recordAnnotation",value:function(t,e){this.id.sampled.getOrElse(!1)&&this._explicitRecord(this.id,t,e)}},{key:"recordMessage",value:function(t){this.recordAnnotation(new lt.Message(t))}},{key:"recordServiceName",value:function(t){this.recordAnnotation(new lt.ServiceName(t))}},{key:"recordRpc",value:function(t){this.recordAnnotation(new lt.Rpc(t))}},{key:"recordClientAddr",value:function(t){this.recordAnnotation(new lt.ClientAddr(t))}},{key:"recordServerAddr",value:function(t){this.recordAnnotation(new lt.ServerAddr(t))}},{key:"recordLocalAddr",value:function(t){this.recordAnnotation(new lt.LocalAddr(t))}},{key:"recordBinary",value:function(t,e){this.recordAnnotation(new lt.BinaryAnnotation(t,e))}},{key:"writeIdToConsole",value:function(t){this.log.info("".concat(t,": ").concat(""+this.id))}},{key:"setTags",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&this.recordBinary(e,t[e])}},{key:"id",get:function(){return this._ctxImpl.getContext()||this._sentinelTraceId}},{key:"localEndpoint",get:function(){return this._localEndpoint}}]),t}(),Kt=function(){function t(){n(this,t),this.currentCtx=null}return o(t,[{key:"setContext",value:function(t){this.currentCtx=t}},{key:"getContext",value:function(){return this.currentCtx}},{key:"scoped",value:function(t){var e=this.currentCtx,n=t();return this.currentCtx=e,n}},{key:"letContext",value:function(t,e){var n=this;return this.scoped(function(){return n.setContext(t),e()})}}]),t}(),Ht={TraceId:"X-B3-TraceId",SpanId:"X-B3-SpanId",ParentSpanId:"X-B3-ParentSpanId",Sampled:"X-B3-Sampled",Flags:"X-B3-Flags"},Vt=Ot.now,Jt=Ut.Span,Xt=Ut.Endpoint,Zt=6e7,$t=Symbol("defaultTags");var Gt=function(){function t(e,r){n(this,t),this.traceId=e,this.timeoutTimestamp=r,this.delegate=new Jt(e),this.localEndpoint=new Xt({}),this.shouldFlush=!1}return o(t,[{key:"setDuration",value:function(t){if(!this.shouldFlush){this.shouldFlush=!0;var e=this.delegate.timestamp;void 0===e?this.delegate.addAnnotation(t,"finish"):this.delegate.setDuration(t-e)}}}]),t}(),Qt=function(){function t(e){var r=this,o=e.logger,i=e.timeout,a=void 0===i?Zt:i;n(this,t),this.logger=o,this.timeout=a,this.partialSpans=new Map,this[$t]={};var s=setInterval(function(){r.partialSpans.forEach(function(t,e){(function(t){return t.timeoutTimestamp<Vt()})(t)&&r._writeSpan(e,t)})},1e3);s.unref&&s.unref()}return o(t,[{key:"_addDefaultTagsAndLocalEndpoint",value:function(t){var e=this[$t];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.delegate.putTag(n,e[n]);t.delegate.setLocalEndpoint(t.localEndpoint)}},{key:"_writeSpan",value:function(t,e){if(arguments.length>2&&void 0!==arguments[2]&&arguments[2]||"undefined"!==this.partialSpans.get(t)){this.partialSpans.delete(t);var n=e.delegate;e.delegate.timestamp&&this._addDefaultTagsAndLocalEndpoint(e),this.logger.logSpan(n)}}},{key:"_updateSpanMap",value:function(t,e,n){var r,o=!1;this.partialSpans.has(t)?r=this.partialSpans.get(t):(o=!0,r=new Gt(t,e+this.timeout)),n(r),r.shouldFlush?this._writeSpan(t,r,o):this.partialSpans.set(t,r)}},{key:"record",value:function(t){var e=t.traceId;this._updateSpanMap(e,t.timestamp,function(n){switch(t.annotation.annotationType){case"ClientSend":n.delegate.setKind("CLIENT"),n.delegate.setTimestamp(t.timestamp);break;case"ClientRecv":n.delegate.setKind("CLIENT"),n.setDuration(t.timestamp);break;case"ServerSend":n.delegate.setKind("SERVER"),n.setDuration(t.timestamp);break;case"ServerRecv":n.delegate.setShared(e.isShared()),n.delegate.setKind("CLIENT"),n.delegate.setTimestamp(t.timestamp);break;case"ProducerStart":n.delegate.setKind("PRODUCER"),n.delegate.setTimestamp(t.timestamp);break;case"ProducerStop":n.delegate.setKind("PRODUCER"),n.setDuration(t.timestamp);break;case"ConsumerStart":n.delegate.setKind("CONSUMER"),n.delegate.setTimestamp(t.timestamp);break;case"ConsumerStop":n.delegate.setKind("CONSUMER"),n.setDuration(t.timestamp);break;case"MessageAddr":n.delegate.setRemoteEndpoint(new Xt({serviceName:t.annotation.serviceName,ipv4:t.annotation.host&&t.annotation.host.ipv4(),port:t.annotation.port}));break;case"LocalOperationStart":n.delegate.setName(t.annotation.name),n.delegate.setTimestamp(t.timestamp);break;case"LocalOperationStop":n.setDuration(t.timestamp);break;case"Message":n.delegate.addAnnotation(t.timestamp,t.annotation.message);break;case"Rpc":n.delegate.setName(t.annotation.name);break;case"ServiceName":n.localEndpoint.setServiceName(t.annotation.serviceName);break;case"BinaryAnnotation":n.delegate.putTag(t.annotation.key,t.annotation.value);break;case"LocalAddr":n.localEndpoint.setIpv4(t.annotation.host&&t.annotation.host.ipv4()),n.localEndpoint.setPort(t.annotation.port);break;case"ServerAddr":n.delegate.setKind("CLIENT"),n.delegate.setRemoteEndpoint(new Xt({serviceName:t.annotation.serviceName,ipv4:t.annotation.host&&t.annotation.host.ipv4(),port:t.annotation.port}))}})}},{key:"setDefaultTags",value:function(t){this[$t]=t}},{key:"toString",value:function(){return"BatchRecorder()"}}]),t}(),Wt=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:console.log;n(this,t),this.logger=e}return o(t,[{key:"record",value:function(t){var e=t.traceId,n=e.spanId,r=e.parentId,o=e.traceId;this.logger("Record at (timestamp=".concat(t.timestamp,", spanId=").concat(n,", parentId=").concat(r,", ")+"traceId=".concat(o,"): ").concat(""+t.annotation))}},{key:"toString",value:function(){return"consoleTracer"}}]),t}(),te=2147483647,ee=36,ne=1,re=26,oe=38,ie=700,ae=72,se=128,ue="-",ce=/[^\x20-\x7E]/,he=/[\x2E\u3002\uFF0E\uFF61]/g,fe={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},pe=ee-ne,le=Math.floor,de=String.fromCharCode;function me(t){throw new RangeError(fe[t])}function ve(t,e){return t+22+75*(26>t)-((0!=e)<<5)}function ge(t,e,n){var r=0;for(t=n?le(t/ie):t>>1,t+=le(t/e);t>pe*re>>1;r+=ee)t=le(t/pe);return le(r+(pe+1)*t/(t+oe))}function ye(t){return function(t,e){var n=t.split("@"),r="";n.length>1&&(r=n[0]+"@",t=n[1]);var o=function(t,e){for(var n=t.length,r=[];n--;)r[n]=e(t[n]);return r}((t=t.replace(he,".")).split("."),e).join(".");return r+o}(t,function(t){return ce.test(t)?"xn--"+function(t){var e,n,r,o,i,a,s,u,c,h,f,p,l,d,m,v=[];for(p=(t=function(t){for(var e,n,r=[],o=0,i=t.length;i>o;)55296>(e=t.charCodeAt(o++))||e>56319||o>=i?r.push(e):56320==(64512&(n=t.charCodeAt(o++)))?r.push(((1023&e)<<10)+(1023&n)+65536):(r.push(e),o--);return r}(t)).length,e=se,n=0,i=ae,a=0;p>a;++a)128>(f=t[a])&&v.push(de(f));for(r=o=v.length,o&&v.push(ue);p>r;){for(s=te,a=0;p>a;++a)(f=t[a])>=e&&s>f&&(s=f);for(s-e>le((te-n)/(l=r+1))&&me("overflow"),n+=(s-e)*l,e=s,a=0;p>a;++a)if(e>(f=t[a])&&++n>te&&me("overflow"),f==e){for(u=n,c=ee;(h=c>i?i+re>c?c-i:re:ne)<=u;c+=ee)v.push(de(ve(h+(m=u-h)%(d=ee-h),0))),u=le(m/d);v.push(de(ve(u,0))),i=ge(n,l,r==o),n=0,++r}++n,++e}return v.join("")}(t):t})}var we=[],Ie=[],be="undefined"!=typeof Uint8Array?Uint8Array:Array,Ee=!1;function Se(){Ee=!0;for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e=0;64>e;++e)we[e]=t[e],Ie[t.charCodeAt(e)]=e;Ie[45]=62,Ie[95]=63}function Ae(t,e,n){for(var r,o=[],i=e;n>i;i+=3)o.push(we[(r=(t[i]<<16)+(t[i+1]<<8)+t[i+2])>>18&63]+we[r>>12&63]+we[r>>6&63]+we[63&r]);return o.join("")}function Re(t){var e;Ee||Se();for(var n=t.length,r=n%3,o="",i=[],a=0,s=n-r;s>a;a+=16383)i.push(Ae(t,a,a+16383>s?s:a+16383));return 1===r?(o+=we[(e=t[n-1])>>2],o+=we[e<<4&63],o+="=="):2===r&&(o+=we[(e=(t[n-2]<<8)+t[n-1])>>10],o+=we[e>>4&63],o+=we[e<<2&63],o+="="),i.push(o),i.join("")}function _e(t,e,n,r,o){var i,a,s=8*o-r-1,u=(1<<s)-1,c=u>>1,h=-7,f=n?o-1:0,p=n?-1:1,l=t[e+f];for(f+=p,i=l&(1<<-h)-1,l>>=-h,h+=s;h>0;i=256*i+t[e+f],f+=p,h-=8);for(a=i&(1<<-h)-1,i>>=-h,h+=r;h>0;a=256*a+t[e+f],f+=p,h-=8);if(0===i)i=1-c;else{if(i===u)return a?NaN:1/0*(l?-1:1);a+=Math.pow(2,r),i-=c}return(l?-1:1)*a*Math.pow(2,i-r)}function ke(t,e,n,r,o,i){var a,s,u,c=8*i-o-1,h=(1<<c)-1,f=h>>1,p=23===o?5.960464477539062e-8:0,l=r?0:i-1,d=r?1:-1,m=0>e||0===e&&0>1/e?1:0;for(isNaN(e=Math.abs(e))||e===1/0?(s=isNaN(e)?1:0,a=h):(1>e*(u=Math.pow(2,-(a=Math.floor(Math.log(e)/Math.LN2))))&&(a--,u*=2),2>(e+=1>a+f?p*Math.pow(2,1-f):p/u)*u||(a++,u/=2),h>a+f?1>a+f?(s=e*Math.pow(2,f-1)*Math.pow(2,o),a=0):(s=(e*u-1)*Math.pow(2,o),a+=f):(s=0,a=h));o>=8;t[n+l]=255&s,l+=d,s/=256,o-=8);for(a=a<<o|s,c+=o;c>0;t[n+l]=255&a,l+=d,a/=256,c-=8);t[n+l-d]|=128*m}var Te={}.toString,Oe=Array.isArray||function(t){return"[object Array]"==Te.call(t)};function Ce(){return Ne.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function Pe(t,e){if(Ce()<e)throw new RangeError("Invalid typed array length");return Ne.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e)).__proto__=Ne.prototype:(null===t&&(t=new Ne(e)),t.length=e),t}function Ne(t,e,n){if(!(Ne.TYPED_ARRAY_SUPPORT||this instanceof Ne))return new Ne(t,e,n);if("number"==typeof t){if("string"==typeof e)throw Error("If encoding is specified then the first argument must be a string");return Be(this,t)}return Ue(this,t,e,n)}function Ue(t,e,n,r){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer?function(t,e,n,r){if(0>n||n>e.byteLength)throw new RangeError("'offset' is out of bounds");if(n+(r||0)>e.byteLength)throw new RangeError("'length' is out of bounds");e=void 0===n&&void 0===r?new Uint8Array(e):void 0===r?new Uint8Array(e,n):new Uint8Array(e,n,r);Ne.TYPED_ARRAY_SUPPORT?(t=e).__proto__=Ne.prototype:t=Le(t,e);return t}(t,e,n,r):"string"==typeof e?function(t,e,n){"string"==typeof n&&""!==n||(n="utf8");if(!Ne.isEncoding(n))throw new TypeError('"encoding" must be a valid string encoding');var r=0|De(e,n),o=(t=Pe(t,r)).write(e,n);o!==r&&(t=t.slice(0,o));return t}(t,e,n):function(t,e){if(je(e)){var n=0|Me(e.length);return 0===(t=Pe(t,n)).length?t:(e.copy(t,0,0,n),t)}if(e){if("undefined"!=typeof ArrayBuffer&&e.buffer instanceof ArrayBuffer||"length"in e)return"number"!=typeof e.length||(r=e.length)!=r?Pe(t,0):Le(t,e);if("Buffer"===e.type&&Oe(e.data))return Le(t,e.data)}var r;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(t,e)}function xe(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(0>t)throw new RangeError('"size" argument must not be negative')}function Be(t,e){if(xe(e),t=Pe(t,0>e?0:0|Me(e)),!Ne.TYPED_ARRAY_SUPPORT)for(var n=0;e>n;++n)t[n]=0;return t}function Le(t,e){var n=0>e.length?0:0|Me(e.length);t=Pe(t,n);for(var r=0;n>r;r+=1)t[r]=255&e[r];return t}function Me(t){if(t>=Ce())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Ce().toString(16)+" bytes");return 0|t}function je(t){return!(null==t||!t._isBuffer)}function De(t,e){if(je(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var n=t.length;if(0===n)return 0;for(var r=!1;;)switch(e){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return pn(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return ln(t).length;default:if(r)return pn(t).length;e=(""+e).toLowerCase(),r=!0}}function Ye(t,e,n){var r=t[e];t[e]=t[n],t[n]=r}function qe(t,e,n,r,o){if(0===t.length)return-1;if("string"==typeof n?(r=n,n=0):n>2147483647?n=2147483647:-2147483648>n&&(n=-2147483648),isNaN(n=+n)&&(n=o?0:t.length-1),0>n&&(n=t.length+n),t.length>n){if(0>n){if(!o)return-1;n=0}}else{if(o)return-1;n=t.length-1}if("string"==typeof e&&(e=Ne.from(e,r)),je(e))return 0===e.length?-1:Fe(t,e,n,r,o);if("number"==typeof e)return e&=255,Ne.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,e,n):Uint8Array.prototype.lastIndexOf.call(t,e,n):Fe(t,[e],n,r,o);throw new TypeError("val must be string, number or Buffer")}function Fe(t,e,n,r,o){var i,a=1,s=t.length,u=e.length;if(void 0!==r&&("ucs2"===(r=(r+"").toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(2>t.length||2>e.length)return-1;a=2,s/=2,u/=2,n/=2}function c(t,e){return 1===a?t[e]:t.readUInt16BE(e*a)}if(o){var h=-1;for(i=n;s>i;i++)if(c(t,i)===c(e,-1===h?0:i-h)){if(-1===h&&(h=i),i-h+1===u)return h*a}else-1!==h&&(i-=i-h),h=-1}else for(n+u>s&&(n=s-u),i=n;i>=0;i--){for(var f=!0,p=0;u>p;p++)if(c(t,i+p)!==c(e,p)){f=!1;break}if(f)return i}return-1}function ze(t,e,n,r){var o=t.length-(n=+n||0);r?(r=+r)>o&&(r=o):r=o;var i=e.length;if(i%2!=0)throw new TypeError("Invalid hex string");r>i/2&&(r=i/2);for(var a=0;r>a;++a){var s=parseInt(e.substr(2*a,2),16);if(isNaN(s))return a;t[n+a]=s}return a}function Ke(t,e,n,r){return dn(pn(e,t.length-n),t,n,r)}function He(t,e,n,r){return dn(function(t){for(var e=[],n=0;t.length>n;++n)e.push(255&t.charCodeAt(n));return e}(e),t,n,r)}function Ve(t,e,n,r){return He(t,e,n,r)}function Je(t,e,n,r){return dn(ln(e),t,n,r)}function Xe(t,e,n,r){return dn(function(t,e){for(var n,r,o=[],i=0;t.length>i&&0<=(e-=2);++i)n=t.charCodeAt(i),r=n>>8,o.push(n%256),o.push(r);return o}(e,t.length-n),t,n,r)}function Ze(t,e,n){return Re(0===e&&n===t.length?t:t.slice(e,n))}function $e(t,e,n){n=Math.min(t.length,n);for(var r=[],o=e;n>o;){var i,a,s,u,c=t[o],h=null,f=c>239?4:c>223?3:c>191?2:1;if(n>=o+f)switch(f){case 1:128>c&&(h=c);break;case 2:128==(192&(i=t[o+1]))&&(u=(31&c)<<6|63&i)>127&&(h=u);break;case 3:a=t[o+2],128==(192&(i=t[o+1]))&&128==(192&a)&&(u=(15&c)<<12|(63&i)<<6|63&a)>2047&&(55296>u||u>57343)&&(h=u);break;case 4:a=t[o+2],s=t[o+3],128==(192&(i=t[o+1]))&&128==(192&a)&&128==(192&s)&&(u=(15&c)<<18|(63&i)<<12|(63&a)<<6|63&s)>65535&&1114112>u&&(h=u)}null===h?(h=65533,f=1):h>65535&&(r.push((h-=65536)>>>10&1023|55296),h=56320|1023&h),r.push(h),o+=f}return function(t){var e=t.length;if(Ge>=e)return String.fromCharCode.apply(String,t);var n="",r=0;for(;e>r;)n+=String.fromCharCode.apply(String,t.slice(r,r+=Ge));return n}(r)}Ne.TYPED_ARRAY_SUPPORT=void 0===l.TYPED_ARRAY_SUPPORT||l.TYPED_ARRAY_SUPPORT,Ne.poolSize=8192,Ne._augment=function(t){return t.__proto__=Ne.prototype,t},Ne.from=function(t,e,n){return Ue(null,t,e,n)},Ne.TYPED_ARRAY_SUPPORT&&(Ne.prototype.__proto__=Uint8Array.prototype,Ne.__proto__=Uint8Array),Ne.alloc=function(t,e,n){return function(t,e,n,r){return xe(e),e>0&&void 0!==n?"string"==typeof r?Pe(t,e).fill(n,r):Pe(t,e).fill(n):Pe(t,e)}(null,t,e,n)},Ne.allocUnsafe=function(t){return Be(null,t)},Ne.allocUnsafeSlow=function(t){return Be(null,t)},Ne.isBuffer=function(t){return null!=t&&(!!t._isBuffer||mn(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&mn(t.slice(0,0))}(t))},Ne.compare=function(t,e){if(!je(t)||!je(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var n=t.length,r=e.length,o=0,i=Math.min(n,r);i>o;++o)if(t[o]!==e[o]){n=t[o],r=e[o];break}return r>n?-1:n>r?1:0},Ne.isEncoding=function(t){switch((t+"").toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},Ne.concat=function(t,e){if(!Oe(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return Ne.alloc(0);var n;if(void 0===e)for(e=0,n=0;t.length>n;++n)e+=t[n].length;var r=Ne.allocUnsafe(e),o=0;for(n=0;t.length>n;++n){var i=t[n];if(!je(i))throw new TypeError('"list" argument must be an Array of Buffers');i.copy(r,o),o+=i.length}return r},Ne.byteLength=De,Ne.prototype._isBuffer=!0,Ne.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;t>e;e+=2)Ye(this,e,e+1);return this},Ne.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;t>e;e+=4)Ye(this,e,e+3),Ye(this,e+1,e+2);return this},Ne.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;t>e;e+=8)Ye(this,e,e+7),Ye(this,e+1,e+6),Ye(this,e+2,e+5),Ye(this,e+3,e+4);return this},Ne.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?$e(this,0,t):function(t,e,n){var r=!1;if((void 0===e||0>e)&&(e=0),e>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),0>=n)return"";if((e>>>=0)>=(n>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return tn(this,e,n);case"utf8":case"utf-8":return $e(this,e,n);case"ascii":return Qe(this,e,n);case"latin1":case"binary":return We(this,e,n);case"base64":return Ze(this,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return en(this,e,n);default:if(r)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),r=!0}}.apply(this,arguments)},Ne.prototype.equals=function(t){if(!je(t))throw new TypeError("Argument must be a Buffer");return this===t||0===Ne.compare(this,t)},Ne.prototype.inspect=function(){var t="";return this.length>0&&(t=this.toString("hex",0,50).match(/.{2}/g).join(" "),this.length>50&&(t+=" ... ")),"<Buffer "+t+">"},Ne.prototype.compare=function(t,e,n,r,o){if(!je(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===n&&(n=t?t.length:0),void 0===r&&(r=0),void 0===o&&(o=this.length),0>e||n>t.length||0>r||o>this.length)throw new RangeError("out of range index");if(r>=o&&e>=n)return 0;if(r>=o)return-1;if(e>=n)return 1;if(this===t)return 0;for(var i=(o>>>=0)-(r>>>=0),a=(n>>>=0)-(e>>>=0),s=Math.min(i,a),u=this.slice(r,o),c=t.slice(e,n),h=0;s>h;++h)if(u[h]!==c[h]){i=u[h],a=c[h];break}return a>i?-1:i>a?1:0},Ne.prototype.includes=function(t,e,n){return-1!==this.indexOf(t,e,n)},Ne.prototype.indexOf=function(t,e,n){return qe(this,t,e,n,!0)},Ne.prototype.lastIndexOf=function(t,e,n){return qe(this,t,e,n,!1)},Ne.prototype.write=function(t,e,n,r){if(void 0===e)r="utf8",n=this.length,e=0;else if(void 0===n&&"string"==typeof e)r=e,n=this.length,e=0;else{if(!isFinite(e))throw Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e|=0,isFinite(n)?(n|=0,void 0===r&&(r="utf8")):(r=n,n=void 0)}var o=this.length-e;if((void 0===n||n>o)&&(n=o),t.length>0&&(0>n||0>e)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var i=!1;;)switch(r){case"hex":return ze(this,t,e,n);case"utf8":case"utf-8":return Ke(this,t,e,n);case"ascii":return He(this,t,e,n);case"latin1":case"binary":return Ve(this,t,e,n);case"base64":return Je(this,t,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Xe(this,t,e,n);default:if(i)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),i=!0}},Ne.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var Ge=4096;function Qe(t,e,n){var r="";n=Math.min(t.length,n);for(var o=e;n>o;++o)r+=String.fromCharCode(127&t[o]);return r}function We(t,e,n){var r="";n=Math.min(t.length,n);for(var o=e;n>o;++o)r+=String.fromCharCode(t[o]);return r}function tn(t,e,n){var r=t.length;e&&e>=0||(e=0),(!n||0>n||n>r)&&(n=r);for(var o="",i=e;n>i;++i)o+=fn(t[i]);return o}function en(t,e,n){for(var r=t.slice(e,n),o="",i=0;r.length>i;i+=2)o+=String.fromCharCode(r[i]+256*r[i+1]);return o}function nn(t,e,n){if(t%1!=0||0>t)throw new RangeError("offset is not uint");if(t+e>n)throw new RangeError("Trying to access beyond buffer length")}function rn(t,e,n,r,o,i){if(!je(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>o||i>e)throw new RangeError('"value" argument is out of bounds');if(n+r>t.length)throw new RangeError("Index out of range")}function on(t,e,n,r){0>e&&(e=65535+e+1);for(var o=0,i=Math.min(t.length-n,2);i>o;++o)t[n+o]=(e&255<<8*(r?o:1-o))>>>8*(r?o:1-o)}function an(t,e,n,r){0>e&&(e=4294967295+e+1);for(var o=0,i=Math.min(t.length-n,4);i>o;++o)t[n+o]=e>>>8*(r?o:3-o)&255}function sn(t,e,n,r,o,i){if(n+r>t.length)throw new RangeError("Index out of range");if(0>n)throw new RangeError("Index out of range")}function un(t,e,n,r,o){return o||sn(t,0,n,4),ke(t,e,n,r,23,4),n+4}function cn(t,e,n,r,o){return o||sn(t,0,n,8),ke(t,e,n,r,52,8),n+8}Ne.prototype.slice=function(t,e){var n,r=this.length;if(0>(t=~~t)?0>(t+=r)&&(t=0):t>r&&(t=r),0>(e=void 0===e?r:~~e)?0>(e+=r)&&(e=0):e>r&&(e=r),t>e&&(e=t),Ne.TYPED_ARRAY_SUPPORT)(n=this.subarray(t,e)).__proto__=Ne.prototype;else{var o=e-t;n=new Ne(o,void 0);for(var i=0;o>i;++i)n[i]=this[i+t]}return n},Ne.prototype.readUIntLE=function(t,e,n){t|=0,e|=0,n||nn(t,e,this.length);for(var r=this[t],o=1,i=0;++i<e&&(o*=256);)r+=this[t+i]*o;return r},Ne.prototype.readUIntBE=function(t,e,n){t|=0,e|=0,n||nn(t,e,this.length);for(var r=this[t+--e],o=1;e>0&&(o*=256);)r+=this[t+--e]*o;return r},Ne.prototype.readUInt8=function(t,e){return e||nn(t,1,this.length),this[t]},Ne.prototype.readUInt16LE=function(t,e){return e||nn(t,2,this.length),this[t]|this[t+1]<<8},Ne.prototype.readUInt16BE=function(t,e){return e||nn(t,2,this.length),this[t]<<8|this[t+1]},Ne.prototype.readUInt32LE=function(t,e){return e||nn(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},Ne.prototype.readUInt32BE=function(t,e){return e||nn(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},Ne.prototype.readIntLE=function(t,e,n){t|=0,e|=0,n||nn(t,e,this.length);for(var r=this[t],o=1,i=0;++i<e&&(o*=256);)r+=this[t+i]*o;return(o*=128)>r||(r-=Math.pow(2,8*e)),r},Ne.prototype.readIntBE=function(t,e,n){t|=0,e|=0,n||nn(t,e,this.length);for(var r=e,o=1,i=this[t+--r];r>0&&(o*=256);)i+=this[t+--r]*o;return(o*=128)>i||(i-=Math.pow(2,8*e)),i},Ne.prototype.readInt8=function(t,e){return e||nn(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},Ne.prototype.readInt16LE=function(t,e){e||nn(t,2,this.length);var n=this[t]|this[t+1]<<8;return 32768&n?4294901760|n:n},Ne.prototype.readInt16BE=function(t,e){e||nn(t,2,this.length);var n=this[t+1]|this[t]<<8;return 32768&n?4294901760|n:n},Ne.prototype.readInt32LE=function(t,e){return e||nn(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},Ne.prototype.readInt32BE=function(t,e){return e||nn(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},Ne.prototype.readFloatLE=function(t,e){return e||nn(t,4,this.length),_e(this,t,!0,23,4)},Ne.prototype.readFloatBE=function(t,e){return e||nn(t,4,this.length),_e(this,t,!1,23,4)},Ne.prototype.readDoubleLE=function(t,e){return e||nn(t,8,this.length),_e(this,t,!0,52,8)},Ne.prototype.readDoubleBE=function(t,e){return e||nn(t,8,this.length),_e(this,t,!1,52,8)},Ne.prototype.writeUIntLE=function(t,e,n,r){(t=+t,e|=0,n|=0,r)||rn(this,t,e,n,Math.pow(2,8*n)-1,0);var o=1,i=0;for(this[e]=255&t;++i<n&&(o*=256);)this[e+i]=t/o&255;return e+n},Ne.prototype.writeUIntBE=function(t,e,n,r){(t=+t,e|=0,n|=0,r)||rn(this,t,e,n,Math.pow(2,8*n)-1,0);var o=n-1,i=1;for(this[e+o]=255&t;--o>=0&&(i*=256);)this[e+o]=t/i&255;return e+n},Ne.prototype.writeUInt8=function(t,e,n){return t=+t,e|=0,n||rn(this,t,e,1,255,0),Ne.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},Ne.prototype.writeUInt16LE=function(t,e,n){return t=+t,e|=0,n||rn(this,t,e,2,65535,0),Ne.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):on(this,t,e,!0),e+2},Ne.prototype.writeUInt16BE=function(t,e,n){return t=+t,e|=0,n||rn(this,t,e,2,65535,0),Ne.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):on(this,t,e,!1),e+2},Ne.prototype.writeUInt32LE=function(t,e,n){return t=+t,e|=0,n||rn(this,t,e,4,4294967295,0),Ne.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):an(this,t,e,!0),e+4},Ne.prototype.writeUInt32BE=function(t,e,n){return t=+t,e|=0,n||rn(this,t,e,4,4294967295,0),Ne.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):an(this,t,e,!1),e+4},Ne.prototype.writeIntLE=function(t,e,n,r){if(t=+t,e|=0,!r){var o=Math.pow(2,8*n-1);rn(this,t,e,n,o-1,-o)}var i=0,a=1,s=0;for(this[e]=255&t;++i<n&&(a*=256);)0>t&&0===s&&0!==this[e+i-1]&&(s=1),this[e+i]=(t/a>>0)-s&255;return e+n},Ne.prototype.writeIntBE=function(t,e,n,r){if(t=+t,e|=0,!r){var o=Math.pow(2,8*n-1);rn(this,t,e,n,o-1,-o)}var i=n-1,a=1,s=0;for(this[e+i]=255&t;--i>=0&&(a*=256);)0>t&&0===s&&0!==this[e+i+1]&&(s=1),this[e+i]=(t/a>>0)-s&255;return e+n},Ne.prototype.writeInt8=function(t,e,n){return t=+t,e|=0,n||rn(this,t,e,1,127,-128),Ne.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),0>t&&(t=255+t+1),this[e]=255&t,e+1},Ne.prototype.writeInt16LE=function(t,e,n){return t=+t,e|=0,n||rn(this,t,e,2,32767,-32768),Ne.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):on(this,t,e,!0),e+2},Ne.prototype.writeInt16BE=function(t,e,n){return t=+t,e|=0,n||rn(this,t,e,2,32767,-32768),Ne.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):on(this,t,e,!1),e+2},Ne.prototype.writeInt32LE=function(t,e,n){return t=+t,e|=0,n||rn(this,t,e,4,2147483647,-2147483648),Ne.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):an(this,t,e,!0),e+4},Ne.prototype.writeInt32BE=function(t,e,n){return t=+t,e|=0,n||rn(this,t,e,4,2147483647,-2147483648),0>t&&(t=4294967295+t+1),Ne.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):an(this,t,e,!1),e+4},Ne.prototype.writeFloatLE=function(t,e,n){return un(this,t,e,!0,n)},Ne.prototype.writeFloatBE=function(t,e,n){return un(this,t,e,!1,n)},Ne.prototype.writeDoubleLE=function(t,e,n){return cn(this,t,e,!0,n)},Ne.prototype.writeDoubleBE=function(t,e,n){return cn(this,t,e,!1,n)},Ne.prototype.copy=function(t,e,n,r){if(n||(n=0),r||0===r||(r=this.length),t.length>e||(e=t.length),e||(e=0),r>0&&n>r&&(r=n),r===n)return 0;if(0===t.length||0===this.length)return 0;if(0>e)throw new RangeError("targetStart out of bounds");if(0>n||n>=this.length)throw new RangeError("sourceStart out of bounds");if(0>r)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),r-n>t.length-e&&(r=t.length-e+n);var o,i=r-n;if(this===t&&e>n&&r>e)for(o=i-1;o>=0;--o)t[o+e]=this[o+n];else if(1e3>i||!Ne.TYPED_ARRAY_SUPPORT)for(o=0;i>o;++o)t[o+e]=this[o+n];else Uint8Array.prototype.set.call(t,this.subarray(n,n+i),e);return i},Ne.prototype.fill=function(t,e,n,r){if("string"==typeof t){if("string"==typeof e?(r=e,e=0,n=this.length):"string"==typeof n&&(r=n,n=this.length),1===t.length){var o=t.charCodeAt(0);256>o&&(t=o)}if(void 0!==r&&"string"!=typeof r)throw new TypeError("encoding must be a string");if("string"==typeof r&&!Ne.isEncoding(r))throw new TypeError("Unknown encoding: "+r)}else"number"==typeof t&&(t&=255);if(0>e||e>this.length||n>this.length)throw new RangeError("Out of range index");if(e>=n)return this;var i;if(e>>>=0,n=void 0===n?this.length:n>>>0,t||(t=0),"number"==typeof t)for(i=e;n>i;++i)this[i]=t;else{var a=je(t)?t:pn(""+new Ne(t,r)),s=a.length;for(i=0;n-e>i;++i)this[i+e]=a[i%s]}return this};var hn=/[^+\/0-9A-Za-z-_]/g;function fn(t){return 16>t?"0"+t.toString(16):t.toString(16)}function pn(t,e){var n;e=e||1/0;for(var r=t.length,o=null,i=[],a=0;r>a;++a){if((n=t.charCodeAt(a))>55295&&57344>n){if(!o){if(n>56319){(e-=3)>-1&&i.push(239,191,189);continue}if(a+1===r){(e-=3)>-1&&i.push(239,191,189);continue}o=n;continue}if(56320>n){(e-=3)>-1&&i.push(239,191,189),o=n;continue}n=65536+(o-55296<<10|n-56320)}else o&&(e-=3)>-1&&i.push(239,191,189);if(o=null,128>n){if(0>(e-=1))break;i.push(n)}else if(2048>n){if(0>(e-=2))break;i.push(n>>6|192,63&n|128)}else if(65536>n){if(0>(e-=3))break;i.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(n>=1114112)throw Error("Invalid code point");if(0>(e-=4))break;i.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return i}function ln(t){return function(t){var e,n,r,o,i,a;Ee||Se();var s=t.length;if(s%4>0)throw Error("Invalid string. Length must be a multiple of 4");a=new be(3*s/4-(i="="===t[s-2]?2:"="===t[s-1]?1:0)),r=i>0?s-4:s;var u=0;for(e=0,n=0;r>e;e+=4,n+=3)o=Ie[t.charCodeAt(e)]<<18|Ie[t.charCodeAt(e+1)]<<12|Ie[t.charCodeAt(e+2)]<<6|Ie[t.charCodeAt(e+3)],a[u++]=o>>16&255,a[u++]=o>>8&255,a[u++]=255&o;return 2===i?(o=Ie[t.charCodeAt(e)]<<2|Ie[t.charCodeAt(e+1)]>>4,a[u++]=255&o):1===i&&(o=Ie[t.charCodeAt(e)]<<10|Ie[t.charCodeAt(e+1)]<<4|Ie[t.charCodeAt(e+2)]>>2,a[u++]=o>>8&255,a[u++]=255&o),a}(function(t){if(2>(t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(hn,"")).length)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function dn(t,e,n,r){for(var o=0;r>o&&(o+n<e.length&&o<t.length);++o)e[o+n]=t[o];return o}function mn(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}function vn(t){return null===t}function gn(t){return"string"==typeof t}function yn(t){return"object"==typeof t&&null!==t}function wn(t,e){return Object.prototype.hasOwnProperty.call(t,e)}var In=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)};function bn(t){switch(typeof t){case"string":return t;case"boolean":return t?"true":"false";case"number":return isFinite(t)?t:"";default:return""}}function En(t,e){if(t.map)return t.map(e);for(var n=[],r=0;t.length>r;r++)n.push(e(t[r],r));return n}var Sn=Object.keys||function(t){var e=[];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.push(n);return e};function An(t,e,n,r){n=n||"=";var o={};if("string"!=typeof t||0===t.length)return o;var i=/\+/g;t=t.split(e=e||"&");var a=1e3;r&&"number"==typeof r.maxKeys&&(a=r.maxKeys);var s=t.length;a>0&&s>a&&(s=a);for(var u=0;s>u;++u){var c,h,f,p,l=t[u].replace(i,"%20"),d=l.indexOf(n);0>d?(c=l,h=""):(c=l.substr(0,d),h=l.substr(d+1)),f=decodeURIComponent(c),p=decodeURIComponent(h),wn(o,f)?In(o[f])?o[f].push(p):o[f]=[o[f],p]:o[f]=p}return o}var Rn={parse:Yn,resolve:function(t,e){return Yn(t,!1,!0).resolve(e)},resolveObject:function(t,e){return t?Yn(t,!1,!0).resolveObject(e):e},format:function(t){gn(t)&&(t=qn({},t));return Fn(t)},Url:_n};function _n(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}var kn=/^([a-z0-9.+-]+:)/i,Tn=/:[0-9]*$/,On=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,Cn=["{","}","|","\\","^","`"].concat(["<",">",'"',"`"," ","\r","\n","\t"]),Pn=["'"].concat(Cn),Nn=["%","/","?",";","#"].concat(Pn),Un=["/","?","#"],xn=255,Bn=/^[+a-z0-9A-Z_-]{0,63}$/,Ln=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,Mn={javascript:!0,"javascript:":!0},jn={javascript:!0,"javascript:":!0},Dn={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0};function Yn(t,e,n){if(t&&yn(t)&&t instanceof _n)return t;var r=new _n;return r.parse(t,e,n),r}function qn(t,e,n,r){if(!gn(e))throw new TypeError("Parameter 'url' must be a string, not "+typeof e);var o=e.indexOf("?"),i=-1!==o&&o<e.indexOf("#")?"?":"#",a=e.split(i);a[0]=a[0].replace(/\\/g,"/");var s=e=a.join(i);if(s=s.trim(),!r&&1===e.split("#").length){var u=On.exec(s);if(u)return t.path=s,t.href=s,t.pathname=u[1],u[2]?(t.search=u[2],t.query=n?An(t.search.substr(1)):t.search.substr(1)):n&&(t.search="",t.query={}),t}var c,h,f,p=kn.exec(s);if(p){var l=(p=p[0]).toLowerCase();t.protocol=l,s=s.substr(p.length)}if(r||p||s.match(/^\/\/[^@\/]+@[^@\/]+/)){var d="//"===s.substr(0,2);!d||p&&jn[p]||(s=s.substr(2),t.slashes=!0)}if(!jn[p]&&(d||p&&!Dn[p])){var m,v,g=-1;for(c=0;Un.length>c;c++)-1===(h=s.indexOf(Un[c]))||-1!==g&&h>=g||(g=h);for(-1!==(v=-1===g?s.lastIndexOf("@"):s.lastIndexOf("@",g))&&(m=s.slice(0,v),s=s.slice(v+1),t.auth=decodeURIComponent(m)),g=-1,c=0;Nn.length>c;c++)-1===(h=s.indexOf(Nn[c]))||-1!==g&&h>=g||(g=h);-1===g&&(g=s.length),t.host=s.slice(0,g),s=s.slice(g),zn(t),t.hostname=t.hostname||"";var y="["===t.hostname[0]&&"]"===t.hostname[t.hostname.length-1];if(!y){var w=t.hostname.split(/\./);for(c=0,f=w.length;f>c;c++){var I=w[c];if(I&&!I.match(Bn)){for(var b="",E=0,S=I.length;S>E;E++)I.charCodeAt(E)>127?b+="x":b+=I[E];if(!b.match(Bn)){var A=w.slice(0,c),R=w.slice(c+1),_=I.match(Ln);_&&(A.push(_[1]),R.unshift(_[2])),R.length&&(s="/"+R.join(".")+s),t.hostname=A.join(".");break}}}}t.hostname=t.hostname.length>xn?"":t.hostname.toLowerCase(),y||(t.hostname=ye(t.hostname)),t.host=(t.hostname||"")+(t.port?":"+t.port:""),t.href+=t.host,y&&(t.hostname=t.hostname.substr(1,t.hostname.length-2),"/"!==s[0]&&(s="/"+s))}if(!Mn[l])for(c=0,f=Pn.length;f>c;c++){var k=Pn[c];if(-1!==s.indexOf(k)){var T=encodeURIComponent(k);T===k&&(T=escape(k)),s=s.split(k).join(T)}}var O=s.indexOf("#");-1!==O&&(t.hash=s.substr(O),s=s.slice(0,O));var C=s.indexOf("?");(-1!==C?(t.search=s.substr(C),t.query=s.substr(C+1),n&&(t.query=An(t.query)),s=s.slice(0,C)):n&&(t.search="",t.query={}),s&&(t.pathname=s),Dn[l]&&t.hostname&&!t.pathname&&(t.pathname="/"),t.pathname||t.search)&&(t.path=(t.pathname||"")+(t.search||""));return t.href=Fn(t),t}function Fn(t){var e=t.auth||"";e&&(e=(e=encodeURIComponent(e)).replace(/%3A/i,":"),e+="@");var n,r,o,i,a=t.protocol||"",s=t.pathname||"",u=t.hash||"",c=!1,h="";t.host?c=e+t.host:t.hostname&&(c=e+(-1===t.hostname.indexOf(":")?t.hostname:"["+this.hostname+"]"),t.port&&(c+=":"+t.port)),t.query&&yn(t.query)&&Object.keys(t.query).length&&(r=r||"&",o=o||"=",null===(n=t.query)&&(n=void 0),h="object"==typeof n?En(Sn(n),function(t){var e=encodeURIComponent(bn(t))+o;return In(n[t])?En(n[t],function(t){return e+encodeURIComponent(bn(t))}).join(r):e+encodeURIComponent(bn(n[t]))}).join(r):i?encodeURIComponent(bn(i))+o+encodeURIComponent(bn(n)):"");var f=t.search||h&&"?"+h||"";return a&&":"!==a.substr(-1)&&(a+=":"),t.slashes||(!a||Dn[a])&&!1!==c?(c="//"+(c||""),s&&"/"!==s.charAt(0)&&(s="/"+s)):c||(c=""),u&&"#"!==u.charAt(0)&&(u="#"+u),f&&"?"!==f.charAt(0)&&(f="?"+f),a+c+(s=s.replace(/[?#]/g,function(t){return encodeURIComponent(t)}))+(f=f.replace("#","%23"))+u}function zn(t){var e=t.host,n=Tn.exec(e);n&&(":"!==(n=n[0])&&(t.port=n.substr(1)),e=e.substr(0,e.length-n.length)),e&&(t.hostname=e)}_n.prototype.parse=function(t,e,n){return qn(this,t,e,n)},_n.prototype.format=function(){return Fn(this)},_n.prototype.resolve=function(t){return this.resolveObject(Yn(t,!1,!0)).format()},_n.prototype.resolveObject=function(t){if(gn(t)){var e=new _n;e.parse(t,!1,!0),t=e}for(var n,r=new _n,o=Object.keys(this),i=0;o.length>i;i++){var a=o[i];r[a]=this[a]}if(r.hash=t.hash,""===t.href)return r.href=r.format(),r;if(t.slashes&&!t.protocol){for(var s=Object.keys(t),u=0;s.length>u;u++){var c=s[u];"protocol"!==c&&(r[c]=t[c])}return Dn[r.protocol]&&r.hostname&&!r.pathname&&(r.path=r.pathname="/"),r.href=r.format(),r}if(t.protocol&&t.protocol!==r.protocol){if(!Dn[t.protocol]){for(var h=Object.keys(t),f=0;h.length>f;f++){var p=h[f];r[p]=t[p]}return r.href=r.format(),r}if(r.protocol=t.protocol,t.host||jn[t.protocol])r.pathname=t.pathname;else{for(n=(t.pathname||"").split("/");n.length&&!(t.host=n.shift()););t.host||(t.host=""),t.hostname||(t.hostname=""),""!==n[0]&&n.unshift(""),2>n.length&&n.unshift(""),r.pathname=n.join("/")}if(r.search=t.search,r.query=t.query,r.host=t.host||"",r.auth=t.auth,r.hostname=t.hostname||t.host,r.port=t.port,r.pathname||r.search)r.path=(r.pathname||"")+(r.search||"");return r.slashes=r.slashes||t.slashes,r.href=r.format(),r}var l,d=r.pathname&&"/"===r.pathname.charAt(0),m=t.host||t.pathname&&"/"===t.pathname.charAt(0),v=m||d||r.host&&t.pathname,g=v,y=r.pathname&&r.pathname.split("/")||[],w=r.protocol&&!Dn[r.protocol];if(n=t.pathname&&t.pathname.split("/")||[],w&&(r.hostname="",r.port=null,r.host&&(""===y[0]?y[0]=r.host:y.unshift(r.host)),r.host="",t.protocol&&(t.hostname=null,t.port=null,t.host&&(""===n[0]?n[0]=t.host:n.unshift(t.host)),t.host=null),v=v&&(""===n[0]||""===y[0])),m)r.host=t.host||""===t.host?t.host:r.host,r.hostname=t.hostname||""===t.hostname?t.hostname:r.hostname,r.search=t.search,r.query=t.query,y=n;else if(n.length)y||(y=[]),y.pop(),y=y.concat(n),r.search=t.search,r.query=t.query;else if(null!=t.search)return w&&(r.hostname=r.host=y.shift(),(l=!(!r.host||0>=r.host.indexOf("@"))&&r.host.split("@"))&&(r.auth=l.shift(),r.host=r.hostname=l.shift())),r.search=t.search,r.query=t.query,vn(r.pathname)&&vn(r.search)||(r.path=(r.pathname?r.pathname:"")+(r.search?r.search:"")),r.href=r.format(),r;if(!y.length)return r.pathname=null,r.path=r.search?"/"+r.search:null,r.href=r.format(),r;for(var I=y.slice(-1)[0],b=(r.host||t.host||y.length>1)&&("."===I||".."===I)||""===I,E=0,S=y.length;S>=0;S--)"."===(I=y[S])?y.splice(S,1):".."===I?(y.splice(S,1),E++):E&&(y.splice(S,1),E--);if(!v&&!g)for(;E--;E)y.unshift("..");!v||""===y[0]||y[0]&&"/"===y[0].charAt(0)||y.unshift(""),b&&"/"!==y.join("/").substr(-1)&&y.push("");var A=""===y[0]||y[0]&&"/"===y[0].charAt(0);return w&&(r.hostname=r.host=A?"":y.length?y.shift():"",(l=!(!r.host||0>=r.host.indexOf("@"))&&r.host.split("@"))&&(r.auth=l.shift(),r.host=r.hostname=l.shift())),(v=v||r.host&&y.length)&&!A&&y.unshift(""),y.length?r.pathname=y.join("/"):(r.pathname=null,r.path=null),vn(r.pathname)&&vn(r.search)||(r.path=(r.pathname?r.pathname:"")+(r.search?r.search:"")),r.auth=t.auth||r.auth,r.slashes=r.slashes||t.slashes,r.href=r.format(),r},_n.prototype.parseHost=function(){return zn(this)};var Kn=function(t){var e=Rn.parse(t);return{host:e.hostname,path:e.pathname}},Hn=p.Some,Vn=p.None;function Jn(t){return"1"===t||"true"===t}function Xn(t){try{return new Hn(parseInt(t))}catch(t){return Vn}}function Zn(t){throw Error("HttpServerInstrumentation: Missing required argument ".concat(t,"."))}var $n={addZipkinHeaders:function(t,e){var n=function(t,e){var n=t.headers||{};return n[Ht.TraceId]=e.traceId,n[Ht.SpanId]=e.spanId,e.parentSpanId.ifPresent(function(t){n[Ht.ParentSpanId]=t}),e.sampled.ifPresent(function(t){n[Ht.Sampled]=t?"1":"0"}),e.isDebug()&&(n[Ht.Flags]="1"),n}(t,e);return Object.assign({},t,{headers:n})}};var Gn={HttpServer:function(){function t(e){var r=e.tracer,o=void 0===r?Zn("tracer"):r,i=e.serviceName,a=void 0===i?o.localEndpoint.serviceName:i,s=e.host,u=e.port,c=void 0===u?Zn("port"):u;n(this,t),this.tracer=o,this.serviceName=a,this.host=s&&new V(s),this.port=c}return o(t,[{key:"_createIdFromHeaders",value:function(t){if(function(t){return t(Ht.TraceId)!==Vn&&t(Ht.SpanId)!==Vn}(t)){var e=t(Ht.SpanId).map(function(e){var n=t(Ht.TraceId),r=t(Ht.ParentSpanId),o=t(Ht.Sampled),i=t(Ht.Flags).flatMap(Xn).getOrElse(0);return new _t({traceId:n.getOrElse(),parentId:r,spanId:e,debug:1===i,sampled:o.map(Jn)})});return new Hn(this.tracer.join(e.getOrElse()))}if(t(Ht.Flags)!==Vn||t(Ht.Sampled)!==Vn){var n=t(Ht.Sampled)===Vn?Vn:t(Ht.Sampled).map(Jn),r=t(Ht.Flags).flatMap(Xn).getOrElse(0);return new Hn(this.tracer.createRootId(n,1===r))}return new Hn(this.tracer.createRootId())}},{key:"recordRequest",value:function(t,e,n){var r=this;this._createIdFromHeaders(n).ifPresent(function(t){return r.tracer.setId(t)});var o=this.tracer.id,i=Kn(e).path;return this.tracer.recordServiceName(this.serviceName),this.tracer.recordRpc(t.toUpperCase()),this.tracer.recordBinary("http.path",i),this.tracer.recordAnnotation(new lt.ServerRecv),this.tracer.recordAnnotation(new lt.LocalAddr({host:this.host,port:this.port})),o}},{key:"recordResponse",value:function(t,e,n){this.tracer.setId(t),this.tracer.recordBinary("http.status_code",""+e),n?this.tracer.recordBinary("error",""+n):(200>e||e>399)&&this.tracer.recordBinary("error",""+e),this.tracer.recordAnnotation(new lt.ServerSend)}}]),t}(),HttpClient:function(){function t(e){var r=e.tracer,o=void 0===r?function(t){throw Error("HttpClientInstrumentation: Missing required argument ".concat(t,"."))}("tracer"):r,i=e.serviceName,a=void 0===i?o.localEndpoint.serviceName:i,s=e.remoteServiceName;n(this,t),this.tracer=o,this.serviceName=a,this.remoteServiceName=s}return o(t,[{key:"recordRequest",value:function(t,e,n){this.tracer.setId(this.tracer.createChildId());var r=this.tracer.id,o=Kn(e).path;return this.tracer.recordServiceName(this.serviceName),this.tracer.recordRpc(n.toUpperCase()),this.tracer.recordBinary("http.path",o),this.tracer.recordAnnotation(new lt.ClientSend),this.remoteServiceName&&this.tracer.recordAnnotation(new lt.ServerAddr({serviceName:this.remoteServiceName})),$n.addZipkinHeaders(t,r)}},{key:"recordResponse",value:function(t,e){this.tracer.setId(t),this.tracer.recordBinary("http.status_code",""+e),(200>e||e>399)&&this.tracer.recordBinary("error",""+e),this.tracer.recordAnnotation(new lt.ClientRecv)}},{key:"recordError",value:function(t,e){this.tracer.setId(t),this.tracer.recordBinary("error",""+e),this.tracer.recordAnnotation(new lt.ClientRecv)}}]),t}()};function Qn(t){if(void 0!==t){var e={serviceName:t.serviceName||""};return t.ipv4&&(e.ipv4=t.ipv4),t.port&&(e.port=t.port),e}}var Wn={JSON_V1:{encode:function(t){return function(t){var e={traceId:t.traceId};t.parentId&&(e.parentId=t.parentId),e.id=t.id,e.name=t.name||"",t.shared||(e.timestamp=t.timestamp,e.duration=t.duration);var n,r,o,i=Qn(t.localEndpoint);switch(t.kind){case"CLIENT":n=t.timestamp?"cs":void 0,r="cr",o="sa";break;case"SERVER":n=t.timestamp?"sr":void 0,r="ss",o="ca";break;case"PRODUCER":n=t.timestamp?"ms":void 0,r="ws",o="ma";break;case"CONSUMER":t.timestamp&&t.duration?(n="wr",r="mr"):t.timestamp&&(n="mr"),o="ma"}(t.annotations.length>0||n)&&(e.annotations=t.annotations.map(function(t){return function(t,e){return{value:t.value,timestamp:t.timestamp,endpoint:e}}(t,i)})),n&&(e.annotations.push({value:n,timestamp:t.timestamp,endpoint:i}),t.duration&&e.annotations.push({value:r,timestamp:t.timestamp+t.duration,endpoint:i}));var a=Object.keys(t.tags);if((a.length>0||t.remoteEndpoint)&&(e.binaryAnnotations=a.map(function(e){return{key:e,value:t.tags[e],endpoint:i}})),t.remoteEndpoint){var s={key:o,value:!0,endpoint:Qn(t.remoteEndpoint)};e.binaryAnnotations.push(s)}return t.debug&&(e.debug=!0),JSON.stringify(e)}(t)}},JSON_V2:{encode:function(t){return function(t){var e={traceId:t.traceId};return t.parentId&&(e.parentId=t.parentId),e.id=t.id,t.name&&(e.name=t.name),t.kind&&(e.kind=t.kind),t.timestamp&&(e.timestamp=t.timestamp),t.duration&&(e.duration=t.duration),t.localEndpoint&&(e.localEndpoint=t.localEndpoint),t.remoteEndpoint&&(e.remoteEndpoint=t.remoteEndpoint),t.annotations.length>0&&(e.annotations=t.annotations),Object.keys(t.tags).length>0&&(e.tags=t.tags),t.debug&&(e.debug=!0),t.shared&&(e.shared=!0),JSON.stringify(e)}(t)}}};t.option=p,t.Annotation=lt,t.Tracer=zt,t.createNoopTracer=function(){var t=new Kt;return new zt({recorder:{record:function(){}},ctxImpl:t})},t.randomTraceId=kt,t.sampler=wt,t.TraceId=_t,t.HttpHeaders=Ht,t.InetAddress=V,t.BatchRecorder=Qt,t.ConsoleRecorder=Wt,t.ExplicitContext=Kt,t.Instrumentation=Gn,t.Request=$n,t.jsonEncoder=Wn,t.model=Ut,t.parseRequestUrl=Kn,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.Zipkin={})}(this,function(t){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){for(var n=0;e.length>n;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function o(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),t}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&s(t,e)}function a(t){return(a=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function s(t,e){return(s=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function u(t,e){return!e||"object"!=typeof e&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}var c={get type(){return"None"},get present(){return!1},map:function(){return this},ifPresent:function(){},flatMap:function(){return this},getOrElse:function(t){return t instanceof Function?t():t},equals:function(t){return t===this},toString:function(){return"None"}},h=function(){function t(e){n(this,t),this.value=e}return o(t,[{key:"map",value:function(e){return new t(e(this.value))}},{key:"ifPresent",value:function(t){t(this.value)}},{key:"flatMap",value:function(t){return t(this.value)}},{key:"getOrElse",value:function(){return this.value}},{key:"equals",value:function(e){return e instanceof t&&e.value===this.value}},{key:"toString",value:function(){return"Some(".concat(this.value,")")}},{key:"type",get:function(){return"Some"}},{key:"present",get:function(){return!0}}]),t}();function f(t){return t instanceof h||c.equals(t)}var p={Some:h,None:c,isOptional:f,verifyIsOptional:function(t){if(null==t)throw Error("Error: data is not Optional - it's null");if(!f(t))throw Error("Error: data (".concat(t,") is not an Option!"));if(f(t.value))throw Error("Error: data (".concat(t.value,") is wrapped in Option twice"))},verifyIsNotOptional:function(t){if(f(t))throw Error("Error: data (".concat(t,") is an Option!"))},fromNullable:function(t){return null==t?c:new h(t)}},l="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function d(){throw Error("setTimeout has not been defined")}function v(){throw Error("clearTimeout has not been defined")}var m=d,g=v;function y(t){if(m===setTimeout)return setTimeout(t,0);if((m===d||!m)&&setTimeout)return m=setTimeout,setTimeout(t,0);try{return m(t,0)}catch(e){try{return m.call(null,t,0)}catch(e){return m.call(this,t,0)}}}"function"==typeof l.setTimeout&&(m=setTimeout),"function"==typeof l.clearTimeout&&(g=clearTimeout);var w,E=[],I=!1,b=-1;function S(){I&&w&&(I=!1,w.length?E=w.concat(E):b=-1,E.length&&A())}function A(){if(!I){var t=y(S);I=!0;for(var e=E.length;e;){for(w=E,E=[];++b<e;)w&&w[b].run();b=-1,e=E.length}w=null,I=!1,function(t){if(g===clearTimeout)return clearTimeout(t);if((g===v||!g)&&clearTimeout)return g=clearTimeout,clearTimeout(t);try{g(t)}catch(e){try{return g.call(null,t)}catch(e){return g.call(this,t)}}}(t)}}function R(t,e){this.fun=t,this.array=e}R.prototype.run=function(){this.fun.apply(null,this.array)};function _(){}var k=_,T=_,O=_,C=_,P=_,N=_,U=_;var x=l.performance||{},B=x.now||x.mozNow||x.msNow||x.oNow||x.webkitNow||function(){return(new Date).getTime()};var L=new Date;var M,j={nextTick:function(t){var e=[];if(arguments.length>1)for(var n=1;arguments.length>n;n++)e[n-1]=arguments[n];E.push(new R(t,e)),1!==E.length||I||y(A)},title:"browser",browser:!0,env:{},argv:[],version:"",versions:{},on:k,addListener:T,once:O,off:C,removeListener:P,removeAllListeners:N,emit:U,binding:function(t){throw Error("process.binding is not supported")},cwd:function(){return"/"},chdir:function(t){throw Error("process.chdir is not supported")},umask:function(){return 0},hrtime:function(t){var e=.001*B.call(x),n=Math.floor(e),r=Math.floor(e%1*1e9);return t&&(n-=t[0],0>(r-=t[1])&&(n--,r+=1e9)),[n,r]},platform:"browser",release:{},config:{},uptime:function(){return(new Date-L)/1e3}};function D(){return"/tmp"}var Y={EOL:"\n",tmpdir:D,tmpDir:D,networkInterfaces:function(){},getNetworkInterfaces:function(){},release:function(){return void 0!==l.navigator?l.navigator.appVersion:""},type:function(){return"Browser"},cpus:function(){return[]},totalmem:function(){return Number.MAX_VALUE},freemem:function(){return Number.MAX_VALUE},uptime:function(){return 0},loadavg:function(){return[]},hostname:function(){return void 0!==l.location?l.location.hostname:""},endianness:function(){if(void 0===M){var t=new ArrayBuffer(2),e=new Uint8Array(t),n=new Uint16Array(t);if(e[0]=1,e[1]=2,258===n[0])M="BE";else{if(513!==n[0])throw Error("unable to figure out endianess");M="LE"}}return M}};function q(t,e){for(var n in t)for(var r=t[n].length-1;r>=0;r-=1){var o=t[n][r];if(!o.internal&&o.family===e&&("IPv4"===e||0===o.scopeid))return o.address}return"IPv4"===e?"127.0.0.1":"::1"}function F(t,e){var n={};for(var r in t)r===e&&(n[r]=t[r]);return n}function z(t){var e=Y.networkInterfaces();return t&&(e=F(e,t)),q(e,"IPv4")}z.ipv4=z,z.ipv6=function(t){var e=Y.networkInterfaces();return t&&(e=F(e,t)),q(e,"IPv6")};var K=z,H=function(){function t(e){n(this,t),this.addr=e}return o(t,[{key:"ipv4",value:function(){var t=this.toInt();if(t&&0!==t)return this.addr}},{key:"toInt",value:function(){var t=this.addr.split(".");return t[0]<<24|t[1]<<16|t[2]<<8|t[3]}},{key:"toString",value:function(){return"InetAddress(".concat(this.addr,")")}}]),t}();H.getLocalAddress=function(){return"object"===(void 0===j?"undefined":e(j))&&"function"==typeof j.on?new H(K.ipv4()):new H("127.0.0.1")};var V=H,J=function(){function t(){n(this,t)}return o(t,[{key:"toString",value:function(){return"".concat(this.annotationType,"()")}}]),t}(),X=function(t){function e(){return n(this,e),u(this,a(e).apply(this,arguments))}return i(e,J),e}(),Z=function(t){function e(){return n(this,e),u(this,a(e).apply(this,arguments))}return i(e,J),e}(),$=function(t){function e(){return n(this,e),u(this,a(e).apply(this,arguments))}return i(e,J),e}(),G=function(t){function e(){return n(this,e),u(this,a(e).apply(this,arguments))}return i(e,J),e}(),Q=function(t){function e(){return n(this,e),u(this,a(e).apply(this,arguments))}return i(e,J),e}(),W=function(t){function e(){return n(this,e),u(this,a(e).apply(this,arguments))}return i(e,J),e}(),tt=function(t){function e(){return n(this,e),u(this,a(e).apply(this,arguments))}return i(e,J),e}(),et=function(t){function e(){return n(this,e),u(this,a(e).apply(this,arguments))}return i(e,J),e}();function nt(t){this.name=t}nt.prototype.toString=function(){return'LocalOperationStart("'.concat(this.name,'")')};var rt=function(t){function e(){return n(this,e),u(this,a(e).apply(this,arguments))}return i(e,J),e}();function ot(t){this.message=t}function it(t){this.serviceName=t}function at(t){this.name=t}function st(t){var e=t.port;this.host=t.host,this.port=e}function ut(t){var e=t.host,n=t.port;this.serviceName=t.serviceName,this.host=e||void 0,this.port=n||0}function ct(t){var e=t.port;this.host=t.host||V.getLocalAddress(),this.port=e||0}function ht(t){var e=t.host,n=t.port;this.serviceName=t.serviceName,this.host=e,this.port=n}function ft(t,e){this.key=t,this.value=e}ot.prototype.toString=function(){return'Message("'.concat(this.message,'")')},it.prototype.toString=function(){return'ServiceName("'.concat(this.serviceName,'")')},at.prototype.toString=function(){return'Rpc("'.concat(this.name,'")')},st.prototype.toString=function(){return'ClientAddr(host="'.concat(this.host,'", port=').concat(this.port,")")},ut.prototype.toString=function(){return'ServerAddr(serviceName="'.concat(this.serviceName,'", host="').concat(this.host,'", port=').concat(this.port,")")},ct.prototype.toString=function(){return'LocalAddr(host="'.concat(""+this.host,'", port=').concat(this.port,")")},ht.prototype.toString=function(){return'MessageAddr(serviceName="'.concat(this.serviceName,'", host="').concat(this.host,'", port=').concat(this.port,")")},ft.prototype.toString=function(){return"BinaryAnnotation(".concat(this.key,'="').concat(this.value,'")')};var pt={ClientSend:X,ClientRecv:Z,ServerSend:$,ServerRecv:G,ProducerStart:Q,ProducerStop:W,ConsumerStart:tt,ConsumerStop:et,MessageAddr:ht,Message:ot,ServiceName:it,Rpc:at,ClientAddr:st,ServerAddr:ut,LocalAddr:ct,BinaryAnnotation:ft,LocalOperationStart:nt,LocalOperationStop:rt};Object.keys(pt).forEach(function(t){pt[t].prototype.annotationType=t});var lt=pt,dt=function(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then};var vt=p.Some,mt=function(){function t(e){n(this,t),this.evaluator=e}return o(t,[{key:"shouldSample",value:function(t){var e=this,n=t.sampled.getOrElse(function(){return e.evaluator(t)});return new vt(n)}},{key:"toString",value:function(){return"Sampler(".concat(""+this.evaluator,")")}}]),t}();function gt(t){return!1}function yt(t){return!0}gt.toString=function(){return"never sample"},yt.toString=function(){return"always sample"};var wt={Sampler:mt,CountingSampler:function(t){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return n(this,e),u(this,a(e).call(this,function(t){if(t>0){if(1>t){var e=0,n=parseInt(1/t),r=function(t){var r=0==(e%=n);return e+=1,r};return r.toString=function(){return"countingSampler: sampleRate=".concat(t)},r}return yt}return gt}(1>t?t:1)))}return i(e,mt),e}(),neverSample:gt,alwaysSample:yt},Et=function(){function t(e){var r=e.traceId,o=e.timestamp,i=e.annotation;n(this,t),this.traceId=r,this.timestamp=o,this.annotation=i}return o(t,[{key:"toString",value:function(){return"Record(traceId=".concat(""+this.traceId,", annotation=").concat(""+this.annotation,")")}}]),t}(),It=p.None,bt=p.verifyIsOptional,St=p.verifyIsNotOptional,At=p.isOptional,Rt=new(0,p.Some)(!0),_t=function(){function t(e){n(this,t);var r=e.spanId,o=e.traceId,i=void 0===o?r:o,a=e.parentId,s=void 0===a?It:a,u=e.flags,c=e.debug,h=void 0===c?1===(void 0===u?0:u):c,f=e.sampled,p=void 0===f?It:f,l=e.shared,d=void 0!==l&&l;St(r),bt(s),bt(p),this._traceId=At(i)?i.getOrElse(r):null==i?r:i,this._parentId=s,this._spanId=r,this._sampled=h?Rt:p,this._debug=h,this._shared=d}return o(t,[{key:"isDebug",value:function(){return this._debug}},{key:"isShared",value:function(){return this._shared}},{key:"toString",value:function(){return"TraceId(spanId=".concat(""+this.spanId)+", parentSpanId=".concat(""+this.parentSpanId)+", traceId=".concat(""+this.traceId,")")}},{key:"traceId",get:function(){return this._traceId}},{key:"parentSpanId",get:function(){return this._parentId}},{key:"parentId",get:function(){return this._parentId.getOrElse(this._spanId)}},{key:"spanId",get:function(){return this._spanId}},{key:"sampled",get:function(){return this._sampled}},{key:"flags",get:function(){return this._debug?1:0}}]),t}();var kt=function(){for(var t="",e=0;16>e;e+=1)t+="0123456789abcdef"[Math.floor(16*Math.random())];return t},Tt=void 0!==j&&j.hrtime;var Ot={now:Tt?function(t,e){if(t&&e){var n=j.hrtime(e);return t+Math.floor(1e6*n[0]+n[1]/1e3)}return 1e3*Date.now()}:function(){return 1e3*Date.now()},hrtime:Tt?function(){return j.hrtime()}:function(){}};function Ct(t){var e=t.ipv4,n=t.port;this.setServiceName(t.serviceName),this.setIpv4(e),this.setPort(n)}function Pt(t,e){this.timestamp=t,this.value=""+e}function Nt(t){var e=this;this.traceId=t.traceId,t.parentSpanId.ifPresent(function(t){e.parentId=t}),this.id=t.spanId,this.name=void 0,this.kind=void 0,this.timestamp=void 0,this.duration=void 0,this.localEndpoint=void 0,this.remoteEndpoint=void 0,this.annotations=[],this.tags={},this.debug=t.isDebug(),this.shared=t.isShared()}Ct.prototype.setServiceName=function(t){this.serviceName=t?t.toLocaleLowerCase():void 0},Ct.prototype.setIpv4=function(t){this.ipv4=t},Ct.prototype.setPort=function(t){this.port=t||void 0},Ct.prototype.isEmpty=function(){return void 0===this.serviceName&&void 0===this.ipv4&&void 0===this.port},Pt.prototype.toString=function(){return'Annotation(value="'.concat(this.value,'")')},Nt.prototype.setName=function(t){this.name=t?t.toLocaleLowerCase():void 0},Nt.prototype.setKind=function(t){this.kind=t},Nt.prototype.setTimestamp=function(t){this.timestamp=t},Nt.prototype.setDuration=function(t){void 0!==t&&(this.duration=Math.max(t,1))},Nt.prototype.setLocalEndpoint=function(t){this.localEndpoint=t&&!t.isEmpty()?t:void 0},Nt.prototype.setRemoteEndpoint=function(t){this.remoteEndpoint=t&&!t.isEmpty()?t:void 0},Nt.prototype.addAnnotation=function(t,e){this.annotations.push(new Pt(t,e))},Nt.prototype.putTag=function(t,e){this.tags[t]=""+e},Nt.prototype.setDebug=function(t){this.debug=t},Nt.prototype.setShared=function(t){this.shared=t},Nt.prototype.toString=function(){var t=this.annotations.map(function(t){return""+t}).join(", ");return"Span(id=".concat(this.traceId,", annotations=[").concat(t,"])")};var Ut={Endpoint:Ct,Span:Nt},xt=p.None,Bt=p.Some,Lt=wt.Sampler,Mt=wt.alwaysSample,jt=Ot.now,Dt=Ot.hrtime,Yt=Ut.Endpoint;function qt(t){throw Error("Tracer: Missing required argument ".concat(t,"."))}function Ft(t){return null==t}var zt=function(){function t(e){var r=e.ctxImpl,o=void 0===r?qt("ctxImpl"):r,i=e.recorder,a=void 0===i?qt("recorder"):i,s=e.sampler,u=void 0===s?new Lt(Mt):s,c=e.traceId128Bit,h=void 0!==c&&c,f=e.supportsJoin,p=void 0===f||f,l=e.localServiceName,d=e.localEndpoint,v=e.log,m=void 0===v?console:v,g=e.defaultTags;n(this,t),this.log=m,this.recorder=a,this.sampler=u,this.traceId128Bit=h,this.supportsJoin=p,this._localEndpoint=d||new Yt({serviceName:l||"unknown"}),this._ctxImpl=o,this._sentinelTraceId=this.createRootId(),this._startTimestamp=jt(),this._startTick=Dt(),this.recorder.setDefaultTags&&this.recorder.setDefaultTags(g)}return o(t,[{key:"scoped",value:function(t){return this._ctxImpl.scoped(t)}},{key:"letId",value:function(t,e){return this._ctxImpl.letContext(t,e)}},{key:"createRootId",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:xt,e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=kt(),r=this.traceId128Bit?kt()+n:n,o=new _t({traceId:r,parentId:xt,spanId:n,sampled:t,flags:e?1:0});return t===xt&&(o._sampled=this.sampler.shouldSample(o)),o}},{key:"createChildId",value:function(t){if(Ft(t)&&(t=this._ctxImpl.getContext()),t===this._sentinelTraceId||Ft(t))return this.createRootId();var e=new _t({traceId:t.traceId,parentId:new Bt(t.spanId),spanId:kt(),debug:t.isDebug(),sampled:t.sampled});return!1===e.sampled.present&&(e._sampled=this.sampler.shouldSample(e)),e}},{key:"_explicitRecord",value:function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:jt(this._startTimestamp,this._startTick);this.recorder.record(new Et({traceId:t,timestamp:n,annotation:e}))}},{key:"local",value:function(t,e){var n=this;if("function"!=typeof e)throw Error("you must pass a function");return this.scoped(function(){var r,o=n.createChildId();n.setId(o),n.recordServiceName(n._localEndpoint.serviceName),n.recordAnnotation(new lt.LocalOperationStart(t));try{r=e()}catch(t){throw n.recordBinary("error",t.message?t.message:""+t),n.recordAnnotation(new lt.LocalOperationStop),t}return dt(r)?o.sampled.getOrElse(!1)?r.then(function(t){return n._explicitRecord(o,new lt.LocalOperationStop),t}).catch(function(t){throw n._explicitRecord(o,new lt.BinaryAnnotation("error",t.message?t.message:""+t)),n._explicitRecord(o,new lt.LocalOperationStop),t}):r:(n.recordAnnotation(new lt.LocalOperationStop),r)})}},{key:"join",value:function(t){if(Ft(t))throw Error("traceId is a required arg");if(Ft(t._spanId))throw Error("Must be valid TraceId instance");return this.supportsJoin?(t.sampled===xt?t._sampled=this.sampler.shouldSample(t):t._shared=!0,t):this.createChildId(t)}},{key:"setId",value:function(t){this._ctxImpl.setContext(t)}},{key:"recordAnnotation",value:function(t,e){this.id.sampled.getOrElse(!1)&&this._explicitRecord(this.id,t,e)}},{key:"recordMessage",value:function(t){this.recordAnnotation(new lt.Message(t))}},{key:"recordServiceName",value:function(t){this.recordAnnotation(new lt.ServiceName(t))}},{key:"recordRpc",value:function(t){this.recordAnnotation(new lt.Rpc(t))}},{key:"recordClientAddr",value:function(t){this.recordAnnotation(new lt.ClientAddr(t))}},{key:"recordServerAddr",value:function(t){this.recordAnnotation(new lt.ServerAddr(t))}},{key:"recordLocalAddr",value:function(t){this.recordAnnotation(new lt.LocalAddr(t))}},{key:"recordBinary",value:function(t,e){this.recordAnnotation(new lt.BinaryAnnotation(t,e))}},{key:"writeIdToConsole",value:function(t){this.log.info("".concat(t,": ").concat(""+this.id))}},{key:"setTags",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&this.recordBinary(e,t[e])}},{key:"id",get:function(){return this._ctxImpl.getContext()||this._sentinelTraceId}},{key:"localEndpoint",get:function(){return this._localEndpoint}}]),t}(),Kt=function(){function t(){n(this,t),this.currentCtx=null}return o(t,[{key:"setContext",value:function(t){this.currentCtx=t}},{key:"getContext",value:function(){return this.currentCtx}},{key:"scoped",value:function(t){var e=this.currentCtx,n=t();return this.currentCtx=e,n}},{key:"letContext",value:function(t,e){var n=this;return this.scoped(function(){return n.setContext(t),e()})}}]),t}(),Ht={TraceId:"X-B3-TraceId",SpanId:"X-B3-SpanId",ParentSpanId:"X-B3-ParentSpanId",Sampled:"X-B3-Sampled",Flags:"X-B3-Flags"},Vt=Ot.now,Jt=Ut.Span,Xt=Ut.Endpoint,Zt=6e7,$t=Symbol("defaultTags");var Gt=function(){function t(e,r){n(this,t),this.traceId=e,this.timeoutTimestamp=r,this.delegate=new Jt(e),this.localEndpoint=new Xt({}),this.shouldFlush=!1}return o(t,[{key:"setDuration",value:function(t){if(!this.shouldFlush){this.shouldFlush=!0;var e=this.delegate.timestamp;void 0===e?this.delegate.addAnnotation(t,"finish"):this.delegate.setDuration(t-e)}}}]),t}(),Qt=function(){function t(e){var r=this,o=e.logger,i=e.timeout,a=void 0===i?Zt:i;n(this,t),this.logger=o,this.timeout=a,this.partialSpans=new Map,this[$t]={};var s=setInterval(function(){r.partialSpans.forEach(function(t,e){(function(t){return t.timeoutTimestamp<Vt()})(t)&&(t.delegate.addAnnotation(Vt(),"zipkin-js.flush"),r._writeSpan(e,t))})},1e3);s.unref&&s.unref()}return o(t,[{key:"_addDefaultTagsAndLocalEndpoint",value:function(t){var e=this[$t];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.delegate.putTag(n,e[n]);t.delegate.setLocalEndpoint(t.localEndpoint)}},{key:"_writeSpan",value:function(t,e){if(arguments.length>2&&void 0!==arguments[2]&&arguments[2]||"undefined"!==this.partialSpans.get(t)){this.partialSpans.delete(t);var n=e.delegate;e.delegate.timestamp&&this._addDefaultTagsAndLocalEndpoint(e),this.logger.logSpan(n)}}},{key:"_updateSpanMap",value:function(t,e,n){var r,o=!1;this.partialSpans.has(t)?r=this.partialSpans.get(t):(o=!0,r=new Gt(t,e+this.timeout)),n(r),r.shouldFlush?this._writeSpan(t,r,o):this.partialSpans.set(t,r)}},{key:"flush",value:function(){var t=this;this.partialSpans.forEach(function(e,n){t._writeSpan(n,e)})}},{key:"record",value:function(t){var e=t.traceId;this._updateSpanMap(e,t.timestamp,function(n){switch(t.annotation.annotationType){case"ClientAddr":n.delegate.setKind("SERVER"),n.delegate.setRemoteEndpoint(new Xt({serviceName:t.annotation.serviceName,ipv4:t.annotation.host&&t.annotation.host.ipv4(),port:t.annotation.port}));break;case"ClientSend":n.delegate.setKind("CLIENT"),n.delegate.setTimestamp(t.timestamp);break;case"ClientRecv":n.delegate.setKind("CLIENT"),n.setDuration(t.timestamp);break;case"ServerSend":n.delegate.setKind("SERVER"),n.setDuration(t.timestamp);break;case"ServerRecv":n.delegate.setShared(e.isShared()),n.delegate.setKind("SERVER"),n.delegate.setTimestamp(t.timestamp);break;case"ProducerStart":n.delegate.setKind("PRODUCER"),n.delegate.setTimestamp(t.timestamp);break;case"ProducerStop":n.delegate.setKind("PRODUCER"),n.setDuration(t.timestamp);break;case"ConsumerStart":n.delegate.setKind("CONSUMER"),n.delegate.setTimestamp(t.timestamp);break;case"ConsumerStop":n.delegate.setKind("CONSUMER"),n.setDuration(t.timestamp);break;case"MessageAddr":n.delegate.setRemoteEndpoint(new Xt({serviceName:t.annotation.serviceName,ipv4:t.annotation.host&&t.annotation.host.ipv4(),port:t.annotation.port}));break;case"LocalOperationStart":n.delegate.setName(t.annotation.name),n.delegate.setTimestamp(t.timestamp);break;case"LocalOperationStop":n.setDuration(t.timestamp);break;case"Message":n.delegate.addAnnotation(t.timestamp,t.annotation.message);break;case"Rpc":n.delegate.setName(t.annotation.name);break;case"ServiceName":n.localEndpoint.setServiceName(t.annotation.serviceName);break;case"BinaryAnnotation":n.delegate.putTag(t.annotation.key,t.annotation.value);break;case"LocalAddr":n.localEndpoint.setIpv4(t.annotation.host&&t.annotation.host.ipv4()),n.localEndpoint.setPort(t.annotation.port);break;case"ServerAddr":n.delegate.setKind("CLIENT"),n.delegate.setRemoteEndpoint(new Xt({serviceName:t.annotation.serviceName,ipv4:t.annotation.host&&t.annotation.host.ipv4(),port:t.annotation.port}))}})}},{key:"setDefaultTags",value:function(t){this[$t]=t}},{key:"toString",value:function(){return"BatchRecorder()"}}]),t}(),Wt=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:console.log;n(this,t),this.logger=e}return o(t,[{key:"record",value:function(t){var e=t.traceId,n=e.spanId,r=e.parentId,o=e.traceId;this.logger("Record at (timestamp=".concat(t.timestamp,", spanId=").concat(n,", parentId=").concat(r,", ")+"traceId=".concat(o,"): ").concat(""+t.annotation))}},{key:"toString",value:function(){return"consoleTracer"}}]),t}(),te=2147483647,ee=36,ne=1,re=26,oe=38,ie=700,ae=72,se=128,ue="-",ce=/[^\x20-\x7E]/,he=/[\x2E\u3002\uFF0E\uFF61]/g,fe={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},pe=ee-ne,le=Math.floor,de=String.fromCharCode;function ve(t){throw new RangeError(fe[t])}function me(t,e){return t+22+75*(26>t)-((0!=e)<<5)}function ge(t,e,n){var r=0;for(t=n?le(t/ie):t>>1,t+=le(t/e);t>pe*re>>1;r+=ee)t=le(t/pe);return le(r+(pe+1)*t/(t+oe))}function ye(t){return function(t,e){var n=t.split("@"),r="";n.length>1&&(r=n[0]+"@",t=n[1]);var o=function(t,e){for(var n=t.length,r=[];n--;)r[n]=e(t[n]);return r}((t=t.replace(he,".")).split("."),e).join(".");return r+o}(t,function(t){return ce.test(t)?"xn--"+function(t){var e,n,r,o,i,a,s,u,c,h,f,p,l,d,v,m=[];for(p=(t=function(t){for(var e,n,r=[],o=0,i=t.length;i>o;)55296>(e=t.charCodeAt(o++))||e>56319||o>=i?r.push(e):56320==(64512&(n=t.charCodeAt(o++)))?r.push(((1023&e)<<10)+(1023&n)+65536):(r.push(e),o--);return r}(t)).length,e=se,n=0,i=ae,a=0;p>a;++a)128>(f=t[a])&&m.push(de(f));for(r=o=m.length,o&&m.push(ue);p>r;){for(s=te,a=0;p>a;++a)(f=t[a])>=e&&s>f&&(s=f);for(s-e>le((te-n)/(l=r+1))&&ve("overflow"),n+=(s-e)*l,e=s,a=0;p>a;++a)if(e>(f=t[a])&&++n>te&&ve("overflow"),f==e){for(u=n,c=ee;(h=c>i?i+re>c?c-i:re:ne)<=u;c+=ee)m.push(de(me(h+(v=u-h)%(d=ee-h),0))),u=le(v/d);m.push(de(me(u,0))),i=ge(n,l,r==o),n=0,++r}++n,++e}return m.join("")}(t):t})}var we=[],Ee=[],Ie="undefined"!=typeof Uint8Array?Uint8Array:Array,be=!1;function Se(){be=!0;for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e=0;64>e;++e)we[e]=t[e],Ee[t.charCodeAt(e)]=e;Ee[45]=62,Ee[95]=63}function Ae(t,e,n){for(var r,o=[],i=e;n>i;i+=3)o.push(we[(r=(t[i]<<16)+(t[i+1]<<8)+t[i+2])>>18&63]+we[r>>12&63]+we[r>>6&63]+we[63&r]);return o.join("")}function Re(t){var e;be||Se();for(var n=t.length,r=n%3,o="",i=[],a=0,s=n-r;s>a;a+=16383)i.push(Ae(t,a,a+16383>s?s:a+16383));return 1===r?(o+=we[(e=t[n-1])>>2],o+=we[e<<4&63],o+="=="):2===r&&(o+=we[(e=(t[n-2]<<8)+t[n-1])>>10],o+=we[e>>4&63],o+=we[e<<2&63],o+="="),i.push(o),i.join("")}function _e(t,e,n,r,o){var i,a,s=8*o-r-1,u=(1<<s)-1,c=u>>1,h=-7,f=n?o-1:0,p=n?-1:1,l=t[e+f];for(f+=p,i=l&(1<<-h)-1,l>>=-h,h+=s;h>0;i=256*i+t[e+f],f+=p,h-=8);for(a=i&(1<<-h)-1,i>>=-h,h+=r;h>0;a=256*a+t[e+f],f+=p,h-=8);if(0===i)i=1-c;else{if(i===u)return a?NaN:1/0*(l?-1:1);a+=Math.pow(2,r),i-=c}return(l?-1:1)*a*Math.pow(2,i-r)}function ke(t,e,n,r,o,i){var a,s,u,c=8*i-o-1,h=(1<<c)-1,f=h>>1,p=23===o?5.960464477539062e-8:0,l=r?0:i-1,d=r?1:-1,v=0>e||0===e&&0>1/e?1:0;for(isNaN(e=Math.abs(e))||e===1/0?(s=isNaN(e)?1:0,a=h):(1>e*(u=Math.pow(2,-(a=Math.floor(Math.log(e)/Math.LN2))))&&(a--,u*=2),2>(e+=1>a+f?p*Math.pow(2,1-f):p/u)*u||(a++,u/=2),h>a+f?1>a+f?(s=e*Math.pow(2,f-1)*Math.pow(2,o),a=0):(s=(e*u-1)*Math.pow(2,o),a+=f):(s=0,a=h));o>=8;t[n+l]=255&s,l+=d,s/=256,o-=8);for(a=a<<o|s,c+=o;c>0;t[n+l]=255&a,l+=d,a/=256,c-=8);t[n+l-d]|=128*v}var Te={}.toString,Oe=Array.isArray||function(t){return"[object Array]"==Te.call(t)};function Ce(){return Ne.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function Pe(t,e){if(Ce()<e)throw new RangeError("Invalid typed array length");return Ne.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e)).__proto__=Ne.prototype:(null===t&&(t=new Ne(e)),t.length=e),t}function Ne(t,e,n){if(!(Ne.TYPED_ARRAY_SUPPORT||this instanceof Ne))return new Ne(t,e,n);if("number"==typeof t){if("string"==typeof e)throw Error("If encoding is specified then the first argument must be a string");return Be(this,t)}return Ue(this,t,e,n)}function Ue(t,e,n,r){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer?function(t,e,n,r){if(0>n||n>e.byteLength)throw new RangeError("'offset' is out of bounds");if(n+(r||0)>e.byteLength)throw new RangeError("'length' is out of bounds");e=void 0===n&&void 0===r?new Uint8Array(e):void 0===r?new Uint8Array(e,n):new Uint8Array(e,n,r);Ne.TYPED_ARRAY_SUPPORT?(t=e).__proto__=Ne.prototype:t=Le(t,e);return t}(t,e,n,r):"string"==typeof e?function(t,e,n){"string"==typeof n&&""!==n||(n="utf8");if(!Ne.isEncoding(n))throw new TypeError('"encoding" must be a valid string encoding');var r=0|De(e,n),o=(t=Pe(t,r)).write(e,n);o!==r&&(t=t.slice(0,o));return t}(t,e,n):function(t,e){if(je(e)){var n=0|Me(e.length);return 0===(t=Pe(t,n)).length?t:(e.copy(t,0,0,n),t)}if(e){if("undefined"!=typeof ArrayBuffer&&e.buffer instanceof ArrayBuffer||"length"in e)return"number"!=typeof e.length||(r=e.length)!=r?Pe(t,0):Le(t,e);if("Buffer"===e.type&&Oe(e.data))return Le(t,e.data)}var r;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(t,e)}function xe(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(0>t)throw new RangeError('"size" argument must not be negative')}function Be(t,e){if(xe(e),t=Pe(t,0>e?0:0|Me(e)),!Ne.TYPED_ARRAY_SUPPORT)for(var n=0;e>n;++n)t[n]=0;return t}function Le(t,e){var n=0>e.length?0:0|Me(e.length);t=Pe(t,n);for(var r=0;n>r;r+=1)t[r]=255&e[r];return t}function Me(t){if(t>=Ce())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Ce().toString(16)+" bytes");return 0|t}function je(t){return!(null==t||!t._isBuffer)}function De(t,e){if(je(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var n=t.length;if(0===n)return 0;for(var r=!1;;)switch(e){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return pn(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return ln(t).length;default:if(r)return pn(t).length;e=(""+e).toLowerCase(),r=!0}}function Ye(t,e,n){var r=t[e];t[e]=t[n],t[n]=r}function qe(t,e,n,r,o){if(0===t.length)return-1;if("string"==typeof n?(r=n,n=0):n>2147483647?n=2147483647:-2147483648>n&&(n=-2147483648),isNaN(n=+n)&&(n=o?0:t.length-1),0>n&&(n=t.length+n),t.length>n){if(0>n){if(!o)return-1;n=0}}else{if(o)return-1;n=t.length-1}if("string"==typeof e&&(e=Ne.from(e,r)),je(e))return 0===e.length?-1:Fe(t,e,n,r,o);if("number"==typeof e)return e&=255,Ne.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,e,n):Uint8Array.prototype.lastIndexOf.call(t,e,n):Fe(t,[e],n,r,o);throw new TypeError("val must be string, number or Buffer")}function Fe(t,e,n,r,o){var i,a=1,s=t.length,u=e.length;if(void 0!==r&&("ucs2"===(r=(r+"").toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(2>t.length||2>e.length)return-1;a=2,s/=2,u/=2,n/=2}function c(t,e){return 1===a?t[e]:t.readUInt16BE(e*a)}if(o){var h=-1;for(i=n;s>i;i++)if(c(t,i)===c(e,-1===h?0:i-h)){if(-1===h&&(h=i),i-h+1===u)return h*a}else-1!==h&&(i-=i-h),h=-1}else for(n+u>s&&(n=s-u),i=n;i>=0;i--){for(var f=!0,p=0;u>p;p++)if(c(t,i+p)!==c(e,p)){f=!1;break}if(f)return i}return-1}function ze(t,e,n,r){var o=t.length-(n=+n||0);r?(r=+r)>o&&(r=o):r=o;var i=e.length;if(i%2!=0)throw new TypeError("Invalid hex string");r>i/2&&(r=i/2);for(var a=0;r>a;++a){var s=parseInt(e.substr(2*a,2),16);if(isNaN(s))return a;t[n+a]=s}return a}function Ke(t,e,n,r){return dn(pn(e,t.length-n),t,n,r)}function He(t,e,n,r){return dn(function(t){for(var e=[],n=0;t.length>n;++n)e.push(255&t.charCodeAt(n));return e}(e),t,n,r)}function Ve(t,e,n,r){return He(t,e,n,r)}function Je(t,e,n,r){return dn(ln(e),t,n,r)}function Xe(t,e,n,r){return dn(function(t,e){for(var n,r,o=[],i=0;t.length>i&&0<=(e-=2);++i)n=t.charCodeAt(i),r=n>>8,o.push(n%256),o.push(r);return o}(e,t.length-n),t,n,r)}function Ze(t,e,n){return Re(0===e&&n===t.length?t:t.slice(e,n))}function $e(t,e,n){n=Math.min(t.length,n);for(var r=[],o=e;n>o;){var i,a,s,u,c=t[o],h=null,f=c>239?4:c>223?3:c>191?2:1;if(n>=o+f)switch(f){case 1:128>c&&(h=c);break;case 2:128==(192&(i=t[o+1]))&&(u=(31&c)<<6|63&i)>127&&(h=u);break;case 3:a=t[o+2],128==(192&(i=t[o+1]))&&128==(192&a)&&(u=(15&c)<<12|(63&i)<<6|63&a)>2047&&(55296>u||u>57343)&&(h=u);break;case 4:a=t[o+2],s=t[o+3],128==(192&(i=t[o+1]))&&128==(192&a)&&128==(192&s)&&(u=(15&c)<<18|(63&i)<<12|(63&a)<<6|63&s)>65535&&1114112>u&&(h=u)}null===h?(h=65533,f=1):h>65535&&(r.push((h-=65536)>>>10&1023|55296),h=56320|1023&h),r.push(h),o+=f}return function(t){var e=t.length;if(Ge>=e)return String.fromCharCode.apply(String,t);var n="",r=0;for(;e>r;)n+=String.fromCharCode.apply(String,t.slice(r,r+=Ge));return n}(r)}Ne.TYPED_ARRAY_SUPPORT=void 0===l.TYPED_ARRAY_SUPPORT||l.TYPED_ARRAY_SUPPORT,Ne.poolSize=8192,Ne._augment=function(t){return t.__proto__=Ne.prototype,t},Ne.from=function(t,e,n){return Ue(null,t,e,n)},Ne.TYPED_ARRAY_SUPPORT&&(Ne.prototype.__proto__=Uint8Array.prototype,Ne.__proto__=Uint8Array),Ne.alloc=function(t,e,n){return function(t,e,n,r){return xe(e),e>0&&void 0!==n?"string"==typeof r?Pe(t,e).fill(n,r):Pe(t,e).fill(n):Pe(t,e)}(null,t,e,n)},Ne.allocUnsafe=function(t){return Be(null,t)},Ne.allocUnsafeSlow=function(t){return Be(null,t)},Ne.isBuffer=function(t){return null!=t&&(!!t._isBuffer||vn(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&vn(t.slice(0,0))}(t))},Ne.compare=function(t,e){if(!je(t)||!je(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var n=t.length,r=e.length,o=0,i=Math.min(n,r);i>o;++o)if(t[o]!==e[o]){n=t[o],r=e[o];break}return r>n?-1:n>r?1:0},Ne.isEncoding=function(t){switch((t+"").toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},Ne.concat=function(t,e){if(!Oe(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return Ne.alloc(0);var n;if(void 0===e)for(e=0,n=0;t.length>n;++n)e+=t[n].length;var r=Ne.allocUnsafe(e),o=0;for(n=0;t.length>n;++n){var i=t[n];if(!je(i))throw new TypeError('"list" argument must be an Array of Buffers');i.copy(r,o),o+=i.length}return r},Ne.byteLength=De,Ne.prototype._isBuffer=!0,Ne.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;t>e;e+=2)Ye(this,e,e+1);return this},Ne.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;t>e;e+=4)Ye(this,e,e+3),Ye(this,e+1,e+2);return this},Ne.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;t>e;e+=8)Ye(this,e,e+7),Ye(this,e+1,e+6),Ye(this,e+2,e+5),Ye(this,e+3,e+4);return this},Ne.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?$e(this,0,t):function(t,e,n){var r=!1;if((void 0===e||0>e)&&(e=0),e>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),0>=n)return"";if((e>>>=0)>=(n>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return tn(this,e,n);case"utf8":case"utf-8":return $e(this,e,n);case"ascii":return Qe(this,e,n);case"latin1":case"binary":return We(this,e,n);case"base64":return Ze(this,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return en(this,e,n);default:if(r)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),r=!0}}.apply(this,arguments)},Ne.prototype.equals=function(t){if(!je(t))throw new TypeError("Argument must be a Buffer");return this===t||0===Ne.compare(this,t)},Ne.prototype.inspect=function(){var t="";return this.length>0&&(t=this.toString("hex",0,50).match(/.{2}/g).join(" "),this.length>50&&(t+=" ... ")),"<Buffer "+t+">"},Ne.prototype.compare=function(t,e,n,r,o){if(!je(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===n&&(n=t?t.length:0),void 0===r&&(r=0),void 0===o&&(o=this.length),0>e||n>t.length||0>r||o>this.length)throw new RangeError("out of range index");if(r>=o&&e>=n)return 0;if(r>=o)return-1;if(e>=n)return 1;if(this===t)return 0;for(var i=(o>>>=0)-(r>>>=0),a=(n>>>=0)-(e>>>=0),s=Math.min(i,a),u=this.slice(r,o),c=t.slice(e,n),h=0;s>h;++h)if(u[h]!==c[h]){i=u[h],a=c[h];break}return a>i?-1:i>a?1:0},Ne.prototype.includes=function(t,e,n){return-1!==this.indexOf(t,e,n)},Ne.prototype.indexOf=function(t,e,n){return qe(this,t,e,n,!0)},Ne.prototype.lastIndexOf=function(t,e,n){return qe(this,t,e,n,!1)},Ne.prototype.write=function(t,e,n,r){if(void 0===e)r="utf8",n=this.length,e=0;else if(void 0===n&&"string"==typeof e)r=e,n=this.length,e=0;else{if(!isFinite(e))throw Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e|=0,isFinite(n)?(n|=0,void 0===r&&(r="utf8")):(r=n,n=void 0)}var o=this.length-e;if((void 0===n||n>o)&&(n=o),t.length>0&&(0>n||0>e)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var i=!1;;)switch(r){case"hex":return ze(this,t,e,n);case"utf8":case"utf-8":return Ke(this,t,e,n);case"ascii":return He(this,t,e,n);case"latin1":case"binary":return Ve(this,t,e,n);case"base64":return Je(this,t,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Xe(this,t,e,n);default:if(i)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),i=!0}},Ne.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var Ge=4096;function Qe(t,e,n){var r="";n=Math.min(t.length,n);for(var o=e;n>o;++o)r+=String.fromCharCode(127&t[o]);return r}function We(t,e,n){var r="";n=Math.min(t.length,n);for(var o=e;n>o;++o)r+=String.fromCharCode(t[o]);return r}function tn(t,e,n){var r=t.length;e&&e>=0||(e=0),(!n||0>n||n>r)&&(n=r);for(var o="",i=e;n>i;++i)o+=fn(t[i]);return o}function en(t,e,n){for(var r=t.slice(e,n),o="",i=0;r.length>i;i+=2)o+=String.fromCharCode(r[i]+256*r[i+1]);return o}function nn(t,e,n){if(t%1!=0||0>t)throw new RangeError("offset is not uint");if(t+e>n)throw new RangeError("Trying to access beyond buffer length")}function rn(t,e,n,r,o,i){if(!je(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>o||i>e)throw new RangeError('"value" argument is out of bounds');if(n+r>t.length)throw new RangeError("Index out of range")}function on(t,e,n,r){0>e&&(e=65535+e+1);for(var o=0,i=Math.min(t.length-n,2);i>o;++o)t[n+o]=(e&255<<8*(r?o:1-o))>>>8*(r?o:1-o)}function an(t,e,n,r){0>e&&(e=4294967295+e+1);for(var o=0,i=Math.min(t.length-n,4);i>o;++o)t[n+o]=e>>>8*(r?o:3-o)&255}function sn(t,e,n,r,o,i){if(n+r>t.length)throw new RangeError("Index out of range");if(0>n)throw new RangeError("Index out of range")}function un(t,e,n,r,o){return o||sn(t,0,n,4),ke(t,e,n,r,23,4),n+4}function cn(t,e,n,r,o){return o||sn(t,0,n,8),ke(t,e,n,r,52,8),n+8}Ne.prototype.slice=function(t,e){var n,r=this.length;if(0>(t=~~t)?0>(t+=r)&&(t=0):t>r&&(t=r),0>(e=void 0===e?r:~~e)?0>(e+=r)&&(e=0):e>r&&(e=r),t>e&&(e=t),Ne.TYPED_ARRAY_SUPPORT)(n=this.subarray(t,e)).__proto__=Ne.prototype;else{var o=e-t;n=new Ne(o,void 0);for(var i=0;o>i;++i)n[i]=this[i+t]}return n},Ne.prototype.readUIntLE=function(t,e,n){t|=0,e|=0,n||nn(t,e,this.length);for(var r=this[t],o=1,i=0;++i<e&&(o*=256);)r+=this[t+i]*o;return r},Ne.prototype.readUIntBE=function(t,e,n){t|=0,e|=0,n||nn(t,e,this.length);for(var r=this[t+--e],o=1;e>0&&(o*=256);)r+=this[t+--e]*o;return r},Ne.prototype.readUInt8=function(t,e){return e||nn(t,1,this.length),this[t]},Ne.prototype.readUInt16LE=function(t,e){return e||nn(t,2,this.length),this[t]|this[t+1]<<8},Ne.prototype.readUInt16BE=function(t,e){return e||nn(t,2,this.length),this[t]<<8|this[t+1]},Ne.prototype.readUInt32LE=function(t,e){return e||nn(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},Ne.prototype.readUInt32BE=function(t,e){return e||nn(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},Ne.prototype.readIntLE=function(t,e,n){t|=0,e|=0,n||nn(t,e,this.length);for(var r=this[t],o=1,i=0;++i<e&&(o*=256);)r+=this[t+i]*o;return(o*=128)>r||(r-=Math.pow(2,8*e)),r},Ne.prototype.readIntBE=function(t,e,n){t|=0,e|=0,n||nn(t,e,this.length);for(var r=e,o=1,i=this[t+--r];r>0&&(o*=256);)i+=this[t+--r]*o;return(o*=128)>i||(i-=Math.pow(2,8*e)),i},Ne.prototype.readInt8=function(t,e){return e||nn(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},Ne.prototype.readInt16LE=function(t,e){e||nn(t,2,this.length);var n=this[t]|this[t+1]<<8;return 32768&n?4294901760|n:n},Ne.prototype.readInt16BE=function(t,e){e||nn(t,2,this.length);var n=this[t+1]|this[t]<<8;return 32768&n?4294901760|n:n},Ne.prototype.readInt32LE=function(t,e){return e||nn(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},Ne.prototype.readInt32BE=function(t,e){return e||nn(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},Ne.prototype.readFloatLE=function(t,e){return e||nn(t,4,this.length),_e(this,t,!0,23,4)},Ne.prototype.readFloatBE=function(t,e){return e||nn(t,4,this.length),_e(this,t,!1,23,4)},Ne.prototype.readDoubleLE=function(t,e){return e||nn(t,8,this.length),_e(this,t,!0,52,8)},Ne.prototype.readDoubleBE=function(t,e){return e||nn(t,8,this.length),_e(this,t,!1,52,8)},Ne.prototype.writeUIntLE=function(t,e,n,r){(t=+t,e|=0,n|=0,r)||rn(this,t,e,n,Math.pow(2,8*n)-1,0);var o=1,i=0;for(this[e]=255&t;++i<n&&(o*=256);)this[e+i]=t/o&255;return e+n},Ne.prototype.writeUIntBE=function(t,e,n,r){(t=+t,e|=0,n|=0,r)||rn(this,t,e,n,Math.pow(2,8*n)-1,0);var o=n-1,i=1;for(this[e+o]=255&t;--o>=0&&(i*=256);)this[e+o]=t/i&255;return e+n},Ne.prototype.writeUInt8=function(t,e,n){return t=+t,e|=0,n||rn(this,t,e,1,255,0),Ne.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},Ne.prototype.writeUInt16LE=function(t,e,n){return t=+t,e|=0,n||rn(this,t,e,2,65535,0),Ne.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):on(this,t,e,!0),e+2},Ne.prototype.writeUInt16BE=function(t,e,n){return t=+t,e|=0,n||rn(this,t,e,2,65535,0),Ne.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):on(this,t,e,!1),e+2},Ne.prototype.writeUInt32LE=function(t,e,n){return t=+t,e|=0,n||rn(this,t,e,4,4294967295,0),Ne.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):an(this,t,e,!0),e+4},Ne.prototype.writeUInt32BE=function(t,e,n){return t=+t,e|=0,n||rn(this,t,e,4,4294967295,0),Ne.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):an(this,t,e,!1),e+4},Ne.prototype.writeIntLE=function(t,e,n,r){if(t=+t,e|=0,!r){var o=Math.pow(2,8*n-1);rn(this,t,e,n,o-1,-o)}var i=0,a=1,s=0;for(this[e]=255&t;++i<n&&(a*=256);)0>t&&0===s&&0!==this[e+i-1]&&(s=1),this[e+i]=(t/a>>0)-s&255;return e+n},Ne.prototype.writeIntBE=function(t,e,n,r){if(t=+t,e|=0,!r){var o=Math.pow(2,8*n-1);rn(this,t,e,n,o-1,-o)}var i=n-1,a=1,s=0;for(this[e+i]=255&t;--i>=0&&(a*=256);)0>t&&0===s&&0!==this[e+i+1]&&(s=1),this[e+i]=(t/a>>0)-s&255;return e+n},Ne.prototype.writeInt8=function(t,e,n){return t=+t,e|=0,n||rn(this,t,e,1,127,-128),Ne.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),0>t&&(t=255+t+1),this[e]=255&t,e+1},Ne.prototype.writeInt16LE=function(t,e,n){return t=+t,e|=0,n||rn(this,t,e,2,32767,-32768),Ne.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):on(this,t,e,!0),e+2},Ne.prototype.writeInt16BE=function(t,e,n){return t=+t,e|=0,n||rn(this,t,e,2,32767,-32768),Ne.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):on(this,t,e,!1),e+2},Ne.prototype.writeInt32LE=function(t,e,n){return t=+t,e|=0,n||rn(this,t,e,4,2147483647,-2147483648),Ne.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):an(this,t,e,!0),e+4},Ne.prototype.writeInt32BE=function(t,e,n){return t=+t,e|=0,n||rn(this,t,e,4,2147483647,-2147483648),0>t&&(t=4294967295+t+1),Ne.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):an(this,t,e,!1),e+4},Ne.prototype.writeFloatLE=function(t,e,n){return un(this,t,e,!0,n)},Ne.prototype.writeFloatBE=function(t,e,n){return un(this,t,e,!1,n)},Ne.prototype.writeDoubleLE=function(t,e,n){return cn(this,t,e,!0,n)},Ne.prototype.writeDoubleBE=function(t,e,n){return cn(this,t,e,!1,n)},Ne.prototype.copy=function(t,e,n,r){if(n||(n=0),r||0===r||(r=this.length),t.length>e||(e=t.length),e||(e=0),r>0&&n>r&&(r=n),r===n)return 0;if(0===t.length||0===this.length)return 0;if(0>e)throw new RangeError("targetStart out of bounds");if(0>n||n>=this.length)throw new RangeError("sourceStart out of bounds");if(0>r)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),r-n>t.length-e&&(r=t.length-e+n);var o,i=r-n;if(this===t&&e>n&&r>e)for(o=i-1;o>=0;--o)t[o+e]=this[o+n];else if(1e3>i||!Ne.TYPED_ARRAY_SUPPORT)for(o=0;i>o;++o)t[o+e]=this[o+n];else Uint8Array.prototype.set.call(t,this.subarray(n,n+i),e);return i},Ne.prototype.fill=function(t,e,n,r){if("string"==typeof t){if("string"==typeof e?(r=e,e=0,n=this.length):"string"==typeof n&&(r=n,n=this.length),1===t.length){var o=t.charCodeAt(0);256>o&&(t=o)}if(void 0!==r&&"string"!=typeof r)throw new TypeError("encoding must be a string");if("string"==typeof r&&!Ne.isEncoding(r))throw new TypeError("Unknown encoding: "+r)}else"number"==typeof t&&(t&=255);if(0>e||e>this.length||n>this.length)throw new RangeError("Out of range index");if(e>=n)return this;var i;if(e>>>=0,n=void 0===n?this.length:n>>>0,t||(t=0),"number"==typeof t)for(i=e;n>i;++i)this[i]=t;else{var a=je(t)?t:pn(""+new Ne(t,r)),s=a.length;for(i=0;n-e>i;++i)this[i+e]=a[i%s]}return this};var hn=/[^+\/0-9A-Za-z-_]/g;function fn(t){return 16>t?"0"+t.toString(16):t.toString(16)}function pn(t,e){var n;e=e||1/0;for(var r=t.length,o=null,i=[],a=0;r>a;++a){if((n=t.charCodeAt(a))>55295&&57344>n){if(!o){if(n>56319){(e-=3)>-1&&i.push(239,191,189);continue}if(a+1===r){(e-=3)>-1&&i.push(239,191,189);continue}o=n;continue}if(56320>n){(e-=3)>-1&&i.push(239,191,189),o=n;continue}n=65536+(o-55296<<10|n-56320)}else o&&(e-=3)>-1&&i.push(239,191,189);if(o=null,128>n){if(0>(e-=1))break;i.push(n)}else if(2048>n){if(0>(e-=2))break;i.push(n>>6|192,63&n|128)}else if(65536>n){if(0>(e-=3))break;i.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(n>=1114112)throw Error("Invalid code point");if(0>(e-=4))break;i.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return i}function ln(t){return function(t){var e,n,r,o,i,a;be||Se();var s=t.length;if(s%4>0)throw Error("Invalid string. Length must be a multiple of 4");a=new Ie(3*s/4-(i="="===t[s-2]?2:"="===t[s-1]?1:0)),r=i>0?s-4:s;var u=0;for(e=0,n=0;r>e;e+=4,n+=3)o=Ee[t.charCodeAt(e)]<<18|Ee[t.charCodeAt(e+1)]<<12|Ee[t.charCodeAt(e+2)]<<6|Ee[t.charCodeAt(e+3)],a[u++]=o>>16&255,a[u++]=o>>8&255,a[u++]=255&o;return 2===i?(o=Ee[t.charCodeAt(e)]<<2|Ee[t.charCodeAt(e+1)]>>4,a[u++]=255&o):1===i&&(o=Ee[t.charCodeAt(e)]<<10|Ee[t.charCodeAt(e+1)]<<4|Ee[t.charCodeAt(e+2)]>>2,a[u++]=o>>8&255,a[u++]=255&o),a}(function(t){if(2>(t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(hn,"")).length)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function dn(t,e,n,r){for(var o=0;r>o&&(o+n<e.length&&o<t.length);++o)e[o+n]=t[o];return o}function vn(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}function mn(t){return null===t}function gn(t){return"string"==typeof t}function yn(t){return"object"==typeof t&&null!==t}function wn(t,e){return Object.prototype.hasOwnProperty.call(t,e)}var En=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)};function In(t){switch(typeof t){case"string":return t;case"boolean":return t?"true":"false";case"number":return isFinite(t)?t:"";default:return""}}function bn(t,e){if(t.map)return t.map(e);for(var n=[],r=0;t.length>r;r++)n.push(e(t[r],r));return n}var Sn=Object.keys||function(t){var e=[];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.push(n);return e};function An(t,e,n,r){n=n||"=";var o={};if("string"!=typeof t||0===t.length)return o;var i=/\+/g;t=t.split(e=e||"&");var a=1e3;r&&"number"==typeof r.maxKeys&&(a=r.maxKeys);var s=t.length;a>0&&s>a&&(s=a);for(var u=0;s>u;++u){var c,h,f,p,l=t[u].replace(i,"%20"),d=l.indexOf(n);0>d?(c=l,h=""):(c=l.substr(0,d),h=l.substr(d+1)),f=decodeURIComponent(c),p=decodeURIComponent(h),wn(o,f)?En(o[f])?o[f].push(p):o[f]=[o[f],p]:o[f]=p}return o}var Rn={parse:Yn,resolve:function(t,e){return Yn(t,!1,!0).resolve(e)},resolveObject:function(t,e){return t?Yn(t,!1,!0).resolveObject(e):e},format:function(t){gn(t)&&(t=qn({},t));return Fn(t)},Url:_n};function _n(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}var kn=/^([a-z0-9.+-]+:)/i,Tn=/:[0-9]*$/,On=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,Cn=["{","}","|","\\","^","`"].concat(["<",">",'"',"`"," ","\r","\n","\t"]),Pn=["'"].concat(Cn),Nn=["%","/","?",";","#"].concat(Pn),Un=["/","?","#"],xn=255,Bn=/^[+a-z0-9A-Z_-]{0,63}$/,Ln=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,Mn={javascript:!0,"javascript:":!0},jn={javascript:!0,"javascript:":!0},Dn={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0};function Yn(t,e,n){if(t&&yn(t)&&t instanceof _n)return t;var r=new _n;return r.parse(t,e,n),r}function qn(t,e,n,r){if(!gn(e))throw new TypeError("Parameter 'url' must be a string, not "+typeof e);var o=e.indexOf("?"),i=-1!==o&&o<e.indexOf("#")?"?":"#",a=e.split(i);a[0]=a[0].replace(/\\/g,"/");var s=e=a.join(i);if(s=s.trim(),!r&&1===e.split("#").length){var u=On.exec(s);if(u)return t.path=s,t.href=s,t.pathname=u[1],u[2]?(t.search=u[2],t.query=n?An(t.search.substr(1)):t.search.substr(1)):n&&(t.search="",t.query={}),t}var c,h,f,p=kn.exec(s);if(p){var l=(p=p[0]).toLowerCase();t.protocol=l,s=s.substr(p.length)}if(r||p||s.match(/^\/\/[^@\/]+@[^@\/]+/)){var d="//"===s.substr(0,2);!d||p&&jn[p]||(s=s.substr(2),t.slashes=!0)}if(!jn[p]&&(d||p&&!Dn[p])){var v,m,g=-1;for(c=0;Un.length>c;c++)-1===(h=s.indexOf(Un[c]))||-1!==g&&h>=g||(g=h);for(-1!==(m=-1===g?s.lastIndexOf("@"):s.lastIndexOf("@",g))&&(v=s.slice(0,m),s=s.slice(m+1),t.auth=decodeURIComponent(v)),g=-1,c=0;Nn.length>c;c++)-1===(h=s.indexOf(Nn[c]))||-1!==g&&h>=g||(g=h);-1===g&&(g=s.length),t.host=s.slice(0,g),s=s.slice(g),zn(t),t.hostname=t.hostname||"";var y="["===t.hostname[0]&&"]"===t.hostname[t.hostname.length-1];if(!y){var w=t.hostname.split(/\./);for(c=0,f=w.length;f>c;c++){var E=w[c];if(E&&!E.match(Bn)){for(var I="",b=0,S=E.length;S>b;b++)E.charCodeAt(b)>127?I+="x":I+=E[b];if(!I.match(Bn)){var A=w.slice(0,c),R=w.slice(c+1),_=E.match(Ln);_&&(A.push(_[1]),R.unshift(_[2])),R.length&&(s="/"+R.join(".")+s),t.hostname=A.join(".");break}}}}t.hostname=t.hostname.length>xn?"":t.hostname.toLowerCase(),y||(t.hostname=ye(t.hostname)),t.host=(t.hostname||"")+(t.port?":"+t.port:""),t.href+=t.host,y&&(t.hostname=t.hostname.substr(1,t.hostname.length-2),"/"!==s[0]&&(s="/"+s))}if(!Mn[l])for(c=0,f=Pn.length;f>c;c++){var k=Pn[c];if(-1!==s.indexOf(k)){var T=encodeURIComponent(k);T===k&&(T=escape(k)),s=s.split(k).join(T)}}var O=s.indexOf("#");-1!==O&&(t.hash=s.substr(O),s=s.slice(0,O));var C=s.indexOf("?");(-1!==C?(t.search=s.substr(C),t.query=s.substr(C+1),n&&(t.query=An(t.query)),s=s.slice(0,C)):n&&(t.search="",t.query={}),s&&(t.pathname=s),Dn[l]&&t.hostname&&!t.pathname&&(t.pathname="/"),t.pathname||t.search)&&(t.path=(t.pathname||"")+(t.search||""));return t.href=Fn(t),t}function Fn(t){var e=t.auth||"";e&&(e=(e=encodeURIComponent(e)).replace(/%3A/i,":"),e+="@");var n,r,o,i,a=t.protocol||"",s=t.pathname||"",u=t.hash||"",c=!1,h="";t.host?c=e+t.host:t.hostname&&(c=e+(-1===t.hostname.indexOf(":")?t.hostname:"["+this.hostname+"]"),t.port&&(c+=":"+t.port)),t.query&&yn(t.query)&&Object.keys(t.query).length&&(r=r||"&",o=o||"=",null===(n=t.query)&&(n=void 0),h="object"==typeof n?bn(Sn(n),function(t){var e=encodeURIComponent(In(t))+o;return En(n[t])?bn(n[t],function(t){return e+encodeURIComponent(In(t))}).join(r):e+encodeURIComponent(In(n[t]))}).join(r):i?encodeURIComponent(In(i))+o+encodeURIComponent(In(n)):"");var f=t.search||h&&"?"+h||"";return a&&":"!==a.substr(-1)&&(a+=":"),t.slashes||(!a||Dn[a])&&!1!==c?(c="//"+(c||""),s&&"/"!==s.charAt(0)&&(s="/"+s)):c||(c=""),u&&"#"!==u.charAt(0)&&(u="#"+u),f&&"?"!==f.charAt(0)&&(f="?"+f),a+c+(s=s.replace(/[?#]/g,function(t){return encodeURIComponent(t)}))+(f=f.replace("#","%23"))+u}function zn(t){var e=t.host,n=Tn.exec(e);n&&(":"!==(n=n[0])&&(t.port=n.substr(1)),e=e.substr(0,e.length-n.length)),e&&(t.hostname=e)}_n.prototype.parse=function(t,e,n){return qn(this,t,e,n)},_n.prototype.format=function(){return Fn(this)},_n.prototype.resolve=function(t){return this.resolveObject(Yn(t,!1,!0)).format()},_n.prototype.resolveObject=function(t){if(gn(t)){var e=new _n;e.parse(t,!1,!0),t=e}for(var n,r=new _n,o=Object.keys(this),i=0;o.length>i;i++){var a=o[i];r[a]=this[a]}if(r.hash=t.hash,""===t.href)return r.href=r.format(),r;if(t.slashes&&!t.protocol){for(var s=Object.keys(t),u=0;s.length>u;u++){var c=s[u];"protocol"!==c&&(r[c]=t[c])}return Dn[r.protocol]&&r.hostname&&!r.pathname&&(r.path=r.pathname="/"),r.href=r.format(),r}if(t.protocol&&t.protocol!==r.protocol){if(!Dn[t.protocol]){for(var h=Object.keys(t),f=0;h.length>f;f++){var p=h[f];r[p]=t[p]}return r.href=r.format(),r}if(r.protocol=t.protocol,t.host||jn[t.protocol])r.pathname=t.pathname;else{for(n=(t.pathname||"").split("/");n.length&&!(t.host=n.shift()););t.host||(t.host=""),t.hostname||(t.hostname=""),""!==n[0]&&n.unshift(""),2>n.length&&n.unshift(""),r.pathname=n.join("/")}if(r.search=t.search,r.query=t.query,r.host=t.host||"",r.auth=t.auth,r.hostname=t.hostname||t.host,r.port=t.port,r.pathname||r.search)r.path=(r.pathname||"")+(r.search||"");return r.slashes=r.slashes||t.slashes,r.href=r.format(),r}var l,d=r.pathname&&"/"===r.pathname.charAt(0),v=t.host||t.pathname&&"/"===t.pathname.charAt(0),m=v||d||r.host&&t.pathname,g=m,y=r.pathname&&r.pathname.split("/")||[],w=r.protocol&&!Dn[r.protocol];if(n=t.pathname&&t.pathname.split("/")||[],w&&(r.hostname="",r.port=null,r.host&&(""===y[0]?y[0]=r.host:y.unshift(r.host)),r.host="",t.protocol&&(t.hostname=null,t.port=null,t.host&&(""===n[0]?n[0]=t.host:n.unshift(t.host)),t.host=null),m=m&&(""===n[0]||""===y[0])),v)r.host=t.host||""===t.host?t.host:r.host,r.hostname=t.hostname||""===t.hostname?t.hostname:r.hostname,r.search=t.search,r.query=t.query,y=n;else if(n.length)y||(y=[]),y.pop(),y=y.concat(n),r.search=t.search,r.query=t.query;else if(null!=t.search)return w&&(r.hostname=r.host=y.shift(),(l=!(!r.host||0>=r.host.indexOf("@"))&&r.host.split("@"))&&(r.auth=l.shift(),r.host=r.hostname=l.shift())),r.search=t.search,r.query=t.query,mn(r.pathname)&&mn(r.search)||(r.path=(r.pathname?r.pathname:"")+(r.search?r.search:"")),r.href=r.format(),r;if(!y.length)return r.pathname=null,r.path=r.search?"/"+r.search:null,r.href=r.format(),r;for(var E=y.slice(-1)[0],I=(r.host||t.host||y.length>1)&&("."===E||".."===E)||""===E,b=0,S=y.length;S>=0;S--)"."===(E=y[S])?y.splice(S,1):".."===E?(y.splice(S,1),b++):b&&(y.splice(S,1),b--);if(!m&&!g)for(;b--;b)y.unshift("..");!m||""===y[0]||y[0]&&"/"===y[0].charAt(0)||y.unshift(""),I&&"/"!==y.join("/").substr(-1)&&y.push("");var A=""===y[0]||y[0]&&"/"===y[0].charAt(0);return w&&(r.hostname=r.host=A?"":y.length?y.shift():"",(l=!(!r.host||0>=r.host.indexOf("@"))&&r.host.split("@"))&&(r.auth=l.shift(),r.host=r.hostname=l.shift())),(m=m||r.host&&y.length)&&!A&&y.unshift(""),y.length?r.pathname=y.join("/"):(r.pathname=null,r.path=null),mn(r.pathname)&&mn(r.search)||(r.path=(r.pathname?r.pathname:"")+(r.search?r.search:"")),r.auth=t.auth||r.auth,r.slashes=r.slashes||t.slashes,r.href=r.format(),r},_n.prototype.parseHost=function(){return zn(this)};var Kn=function(t){var e=Rn.parse(t);return{host:e.hostname,path:e.pathname}},Hn=p.Some,Vn=p.None;function Jn(t){return"1"===t||"true"===t}function Xn(t){try{return new Hn(parseInt(t))}catch(t){return Vn}}function Zn(t){throw Error("HttpServerInstrumentation: Missing required argument ".concat(t,"."))}var $n={addZipkinHeaders:function(t,e){var n=function(t,e){var n=t.headers||{};return n[Ht.TraceId]=e.traceId,n[Ht.SpanId]=e.spanId,e.parentSpanId.ifPresent(function(t){n[Ht.ParentSpanId]=t}),e.sampled.ifPresent(function(t){n[Ht.Sampled]=t?"1":"0"}),e.isDebug()&&(n[Ht.Flags]="1"),n}(t,e);return Object.assign({},t,{headers:n})}};var Gn={HttpServer:function(){function t(e){var r=e.tracer,o=void 0===r?Zn("tracer"):r,i=e.serviceName,a=void 0===i?o.localEndpoint.serviceName:i,s=e.host,u=e.port,c=void 0===u?Zn("port"):u;n(this,t),this.tracer=o,this.serviceName=a,this.host=s&&new V(s),this.port=c}return o(t,[{key:"_createIdFromHeaders",value:function(t){if(function(t){return t(Ht.TraceId)!==Vn&&t(Ht.SpanId)!==Vn}(t)){var e=t(Ht.SpanId).map(function(e){var n=t(Ht.TraceId),r=t(Ht.ParentSpanId),o=t(Ht.Sampled),i=t(Ht.Flags).flatMap(Xn).getOrElse(0);return new _t({traceId:n.getOrElse(),parentId:r,spanId:e,debug:1===i,sampled:o.map(Jn)})});return new Hn(this.tracer.join(e.getOrElse()))}if(t(Ht.Flags)!==Vn||t(Ht.Sampled)!==Vn){var n=t(Ht.Sampled)===Vn?Vn:t(Ht.Sampled).map(Jn),r=t(Ht.Flags).flatMap(Xn).getOrElse(0);return new Hn(this.tracer.createRootId(n,1===r))}return new Hn(this.tracer.createRootId())}},{key:"recordRequest",value:function(t,e,n){var r=this;this._createIdFromHeaders(n).ifPresent(function(t){return r.tracer.setId(t)});var o=this.tracer.id,i=Kn(e).path;return this.tracer.recordServiceName(this.serviceName),this.tracer.recordRpc(t.toUpperCase()),this.tracer.recordBinary("http.path",i),this.tracer.recordAnnotation(new lt.ServerRecv),this.tracer.recordAnnotation(new lt.LocalAddr({host:this.host,port:this.port})),o}},{key:"recordResponse",value:function(t,e,n){this.tracer.setId(t),this.tracer.recordBinary("http.status_code",""+e),n?this.tracer.recordBinary("error",""+n):(200>e||e>399)&&this.tracer.recordBinary("error",""+e),this.tracer.recordAnnotation(new lt.ServerSend)}}]),t}(),HttpClient:function(){function t(e){var r=e.tracer,o=void 0===r?function(t){throw Error("HttpClientInstrumentation: Missing required argument ".concat(t,"."))}("tracer"):r,i=e.serviceName,a=void 0===i?o.localEndpoint.serviceName:i,s=e.remoteServiceName;n(this,t),this.tracer=o,this.serviceName=a,this.remoteServiceName=s}return o(t,[{key:"recordRequest",value:function(t,e,n){this.tracer.setId(this.tracer.createChildId());var r=this.tracer.id,o=Kn(e).path;return this.tracer.recordServiceName(this.serviceName),this.tracer.recordRpc(n.toUpperCase()),this.tracer.recordBinary("http.path",o),this.tracer.recordAnnotation(new lt.ClientSend),this.remoteServiceName&&this.tracer.recordAnnotation(new lt.ServerAddr({serviceName:this.remoteServiceName})),$n.addZipkinHeaders(t,r)}},{key:"recordResponse",value:function(t,e){this.tracer.setId(t),this.tracer.recordBinary("http.status_code",""+e),(200>e||e>399)&&this.tracer.recordBinary("error",""+e),this.tracer.recordAnnotation(new lt.ClientRecv)}},{key:"recordError",value:function(t,e){this.tracer.setId(t),this.tracer.recordBinary("error",""+e),this.tracer.recordAnnotation(new lt.ClientRecv)}}]),t}()};function Qn(t){if(void 0!==t){var e={serviceName:t.serviceName||""};return t.ipv4&&(e.ipv4=t.ipv4),t.port&&(e.port=t.port),e}}var Wn={JSON_V1:{encode:function(t){return function(t){var e={traceId:t.traceId};t.parentId&&(e.parentId=t.parentId),e.id=t.id,e.name=t.name||"",t.shared||(e.timestamp=t.timestamp,e.duration=t.duration);var n,r,o,i=Qn(t.localEndpoint);switch(t.kind){case"CLIENT":n=t.timestamp?"cs":void 0,r="cr",o="sa";break;case"SERVER":n=t.timestamp?"sr":void 0,r="ss",o="ca";break;case"PRODUCER":n=t.timestamp?"ms":void 0,r="ws",o="ma";break;case"CONSUMER":t.timestamp&&t.duration?(n="wr",r="mr"):t.timestamp&&(n="mr"),o="ma"}(t.annotations.length>0||n)&&(e.annotations=t.annotations.map(function(t){return function(t,e){return{value:t.value,timestamp:t.timestamp,endpoint:e}}(t,i)})),n&&(e.annotations.push({value:n,timestamp:t.timestamp,endpoint:i}),t.duration&&e.annotations.push({value:r,timestamp:t.timestamp+t.duration,endpoint:i}));var a=Object.keys(t.tags);if((a.length>0||t.remoteEndpoint)&&(e.binaryAnnotations=a.map(function(e){return{key:e,value:t.tags[e],endpoint:i}})),t.remoteEndpoint){var s={key:o,value:!0,endpoint:Qn(t.remoteEndpoint)};e.binaryAnnotations.push(s)}return t.debug&&(e.debug=!0),JSON.stringify(e)}(t)}},JSON_V2:{encode:function(t){return function(t){var e={traceId:t.traceId};return t.parentId&&(e.parentId=t.parentId),e.id=t.id,t.name&&(e.name=t.name),t.kind&&(e.kind=t.kind),t.timestamp&&(e.timestamp=t.timestamp),t.duration&&(e.duration=t.duration),t.localEndpoint&&(e.localEndpoint=t.localEndpoint),t.remoteEndpoint&&(e.remoteEndpoint=t.remoteEndpoint),t.annotations.length>0&&(e.annotations=t.annotations),Object.keys(t.tags).length>0&&(e.tags=t.tags),t.debug&&(e.debug=!0),t.shared&&(e.shared=!0),JSON.stringify(e)}(t)}}};t.option=p,t.Annotation=lt,t.Tracer=zt,t.createNoopTracer=function(){var t=new Kt;return new zt({recorder:{record:function(){}},ctxImpl:t})},t.randomTraceId=kt,t.sampler=wt,t.TraceId=_t,t.HttpHeaders=Ht,t.InetAddress=V,t.BatchRecorder=Qt,t.ConsoleRecorder=Wt,t.ExplicitContext=Kt,t.Instrumentation=Gn,t.Request=$n,t.jsonEncoder=Wn,t.model=Ut,t.parseRequestUrl=Kn,Object.defineProperty(t,"__esModule",{value:!0})}); |
@@ -1182,3 +1182,9 @@ import os from 'os'; | ||
value: function join(traceId) { | ||
if (!(traceId instanceof TraceId_1)) { | ||
if (isUndefinedOrNull(traceId)) { | ||
throw new Error('traceId is a required arg'); | ||
} // duck type check until we sort out a better way. We don't want to break | ||
// transpiled usage ex. `traceId instanceof TraceId_1: false` See #422 | ||
if (isUndefinedOrNull(traceId._spanId)) { | ||
throw new Error('Must be valid TraceId instance'); | ||
@@ -1424,3 +1430,3 @@ } | ||
* @param {Object} options | ||
* @property {Logger} logger logs the data to openZipkin | ||
* @property {Logger} logger logs the data to zipkin server | ||
* @property {number} timeout timeout for span in microseconds | ||
@@ -1446,2 +1452,7 @@ */ | ||
if (_timedOut(span)) { | ||
// the zipkin-js.flush annotation makes it explicit that | ||
// the span has been reported because of a timeout, even | ||
// when it is not finished yet (and thus enqueued for reporting) | ||
span.delegate.addAnnotation(now$2(), 'zipkin-js.flush'); | ||
_this._writeSpan(id, span); | ||
@@ -1513,3 +1524,18 @@ } | ||
} | ||
/** | ||
* Calling this will flush any pending spans to the transport. | ||
* | ||
* Note: the transport itself may be batching, in such case you may need to flush that also. | ||
*/ | ||
}, { | ||
key: "flush", | ||
value: function flush() { | ||
var _this2 = this; | ||
this.partialSpans.forEach(function (span, id) { | ||
_this2._writeSpan(id, span); | ||
}); | ||
} | ||
}, { | ||
key: "record", | ||
@@ -1521,2 +1547,11 @@ value: function record(rec) { | ||
switch (rec.annotation.annotationType) { | ||
case 'ClientAddr': | ||
span.delegate.setKind('SERVER'); | ||
span.delegate.setRemoteEndpoint(new Endpoint$2({ | ||
serviceName: rec.annotation.serviceName, | ||
ipv4: rec.annotation.host && rec.annotation.host.ipv4(), | ||
port: rec.annotation.port | ||
})); | ||
break; | ||
case 'ClientSend': | ||
@@ -1539,3 +1574,3 @@ span.delegate.setKind('CLIENT'); | ||
span.delegate.setShared(id.isShared()); | ||
span.delegate.setKind('CLIENT'); | ||
span.delegate.setKind('SERVER'); | ||
span.delegate.setTimestamp(rec.timestamp); | ||
@@ -1542,0 +1577,0 @@ break; |
@@ -277,2 +277,3 @@ // TypeScript type definitions | ||
record: (rec: Record) => void; | ||
flush: () => void; | ||
} | ||
@@ -279,0 +280,0 @@ |
@@ -1188,3 +1188,9 @@ 'use strict'; | ||
value: function join(traceId) { | ||
if (!(traceId instanceof TraceId_1)) { | ||
if (isUndefinedOrNull(traceId)) { | ||
throw new Error('traceId is a required arg'); | ||
} // duck type check until we sort out a better way. We don't want to break | ||
// transpiled usage ex. `traceId instanceof TraceId_1: false` See #422 | ||
if (isUndefinedOrNull(traceId._spanId)) { | ||
throw new Error('Must be valid TraceId instance'); | ||
@@ -1430,3 +1436,3 @@ } | ||
* @param {Object} options | ||
* @property {Logger} logger logs the data to openZipkin | ||
* @property {Logger} logger logs the data to zipkin server | ||
* @property {number} timeout timeout for span in microseconds | ||
@@ -1452,2 +1458,7 @@ */ | ||
if (_timedOut(span)) { | ||
// the zipkin-js.flush annotation makes it explicit that | ||
// the span has been reported because of a timeout, even | ||
// when it is not finished yet (and thus enqueued for reporting) | ||
span.delegate.addAnnotation(now$2(), 'zipkin-js.flush'); | ||
_this._writeSpan(id, span); | ||
@@ -1519,3 +1530,18 @@ } | ||
} | ||
/** | ||
* Calling this will flush any pending spans to the transport. | ||
* | ||
* Note: the transport itself may be batching, in such case you may need to flush that also. | ||
*/ | ||
}, { | ||
key: "flush", | ||
value: function flush() { | ||
var _this2 = this; | ||
this.partialSpans.forEach(function (span, id) { | ||
_this2._writeSpan(id, span); | ||
}); | ||
} | ||
}, { | ||
key: "record", | ||
@@ -1527,2 +1553,11 @@ value: function record(rec) { | ||
switch (rec.annotation.annotationType) { | ||
case 'ClientAddr': | ||
span.delegate.setKind('SERVER'); | ||
span.delegate.setRemoteEndpoint(new Endpoint$2({ | ||
serviceName: rec.annotation.serviceName, | ||
ipv4: rec.annotation.host && rec.annotation.host.ipv4(), | ||
port: rec.annotation.port | ||
})); | ||
break; | ||
case 'ClientSend': | ||
@@ -1545,3 +1580,3 @@ span.delegate.setKind('CLIENT'); | ||
span.delegate.setShared(id.isShared()); | ||
span.delegate.setKind('CLIENT'); | ||
span.delegate.setKind('SERVER'); | ||
span.delegate.setTimestamp(rec.timestamp); | ||
@@ -1548,0 +1583,0 @@ break; |
{ | ||
"name": "zipkin", | ||
"version": "0.18.5", | ||
"version": "0.18.6", | ||
"description": "The core tracer for Zipkin JS", | ||
@@ -23,3 +23,3 @@ "main": "lib/index.js", | ||
}, | ||
"gitHead": "201c6f6360d7ae79eaa04d5e53660908e3602358" | ||
"gitHead": "98f7796d54199ccb2a81dea04c466a40814ccb24" | ||
} |
@@ -64,3 +64,3 @@ const {now} = require('./time'); | ||
* @param {Object} options | ||
* @property {Logger} logger logs the data to openZipkin | ||
* @property {Logger} logger logs the data to zipkin server | ||
* @property {number} timeout timeout for span in microseconds | ||
@@ -79,2 +79,6 @@ */ | ||
if (_timedOut(span)) { | ||
// the zipkin-js.flush annotation makes it explicit that | ||
// the span has been reported because of a timeout, even | ||
// when it is not finished yet (and thus enqueued for reporting) | ||
span.delegate.addAnnotation(now(), 'zipkin-js.flush'); | ||
this._writeSpan(id, span); | ||
@@ -136,2 +140,13 @@ } | ||
/** | ||
* Calling this will flush any pending spans to the transport. | ||
* | ||
* Note: the transport itself may be batching, in such case you may need to flush that also. | ||
*/ | ||
flush() { | ||
this.partialSpans.forEach((span, id) => { | ||
this._writeSpan(id, span); | ||
}); | ||
} | ||
record(rec) { | ||
@@ -142,2 +157,10 @@ const id = rec.traceId; | ||
switch (rec.annotation.annotationType) { | ||
case 'ClientAddr': | ||
span.delegate.setKind('SERVER'); | ||
span.delegate.setRemoteEndpoint(new Endpoint({ | ||
serviceName: rec.annotation.serviceName, | ||
ipv4: rec.annotation.host && rec.annotation.host.ipv4(), | ||
port: rec.annotation.port | ||
})); | ||
break; | ||
case 'ClientSend': | ||
@@ -157,3 +180,3 @@ span.delegate.setKind('CLIENT'); | ||
span.delegate.setShared(id.isShared()); | ||
span.delegate.setKind('CLIENT'); | ||
span.delegate.setKind('SERVER'); | ||
span.delegate.setTimestamp(rec.timestamp); | ||
@@ -160,0 +183,0 @@ break; |
@@ -171,5 +171,12 @@ const isPromise = require('is-promise'); | ||
join(traceId) { | ||
if (!(traceId instanceof TraceId)) { | ||
if (isUndefinedOrNull(traceId)) { | ||
throw new Error('traceId is a required arg'); | ||
} | ||
// duck type check until we sort out a better way. We don't want to break | ||
// transpiled usage ex. `traceId instanceof TraceId_1: false` See #422 | ||
if (isUndefinedOrNull(traceId._spanId)) { | ||
throw new Error('Must be valid TraceId instance'); | ||
} | ||
if (!this.supportsJoin) { | ||
@@ -176,0 +183,0 @@ return this.createChildId(traceId); |
@@ -1,327 +0,489 @@ | ||
const sinon = require('sinon'); | ||
const {expect} = require('chai'); | ||
const lolex = require('lolex'); | ||
const Tracer = require('../src/tracer'); | ||
const Annotation = require('../src/annotation'); | ||
const BatchRecorder = require('../src/batch-recorder'); | ||
const TraceId = require('../src/tracer/TraceId'); | ||
const Annotation = require('../src/annotation'); | ||
const InetAddress = require('../src/InetAddress'); | ||
const {JSON_V2} = require('../src/jsonEncoder'); | ||
const {now} = require('../src/time'); | ||
const Record = require('../src/tracer/record'); | ||
const {Some} = require('../src/option'); | ||
const ExplicitContext = require('../src/explicit-context'); | ||
const TraceId = require('../src/tracer/TraceId'); | ||
describe('Batch Recorder', () => { | ||
it('should accumulate annotations into PartialSpans', () => { | ||
const logSpan = sinon.spy(); | ||
// This test makes data bugs easier to spot by representing transformations as v2 JSON | ||
describe('Batch Recorder - integration test', () => { | ||
let spans; | ||
let recorder; | ||
const ctxImpl = new ExplicitContext(); | ||
const logger = {logSpan}; | ||
const recorder = new BatchRecorder({logger}); | ||
const trace = new Tracer({ctxImpl, recorder}); | ||
beforeEach(() => { | ||
spans = []; | ||
recorder = new BatchRecorder({ | ||
logger: { | ||
logSpan: (span) => { | ||
spans.push(JSON.parse(JSON_V2.encode(span))); | ||
} | ||
} | ||
}); | ||
}); | ||
ctxImpl.scoped(() => { | ||
trace.setId(new TraceId({ | ||
traceId: 'a', | ||
parentId: new Some('a'), | ||
spanId: 'c', | ||
sampled: new Some(true) | ||
})); | ||
afterEach(() => expect(spans).to.be.empty); | ||
trace.recordServiceName('SmoothieStore'); | ||
trace.recordRpc('buySmoothie'); | ||
trace.recordBinary('taste', 'banana'); | ||
trace.recordAnnotation(new Annotation.ServerRecv()); | ||
trace.recordAnnotation(new Annotation.LocalAddr({ | ||
host: new InetAddress('127.0.0.1'), | ||
port: 7070 | ||
})); | ||
function pendingSpan(traceId) { | ||
return recorder.partialSpans.get(traceId); | ||
} | ||
// Should only log after the span is complete | ||
expect(logSpan.calledOnce).to.equal(false); | ||
trace.recordAnnotation(new Annotation.ServerSend()); | ||
expect(logSpan.calledOnce).to.equal(true); | ||
function popSpan() { | ||
expect(spans).to.not.be.empty; // eslint-disable-line no-unused-expressions | ||
return spans.pop(); | ||
} | ||
const loggedSpan = logSpan.getCall(0).args[0]; | ||
const rootId = new TraceId({ | ||
traceId: '5c7d31940cb80828', | ||
spanId: 'cb37670e772e86e2', | ||
sampled: new Some(true) | ||
}); | ||
expect(loggedSpan.traceId).to.equal('a'); | ||
expect(loggedSpan.parentId).to.equal('a'); | ||
expect(loggedSpan.id).to.equal('c'); | ||
expect(loggedSpan.name).to.eql('buysmoothie'); | ||
expect(loggedSpan.kind).to.equal('SERVER'); | ||
expect(loggedSpan.localEndpoint.serviceName).to.equal('smoothiestore'); | ||
expect(loggedSpan.localEndpoint.ipv4).to.equal('127.0.0.1'); | ||
expect(loggedSpan.localEndpoint.port).to.equal(7070); | ||
expect(loggedSpan.tags.taste).to.equal('banana'); | ||
}); | ||
const childId = new TraceId({ | ||
traceId: rootId.traceId, | ||
parentId: new Some(rootId.spanId), | ||
spanId: '5a4c253bd195eaf9', | ||
sampled: new Some(true) | ||
}); | ||
// Applications can override the span name via trace.recordRpc | ||
it('should record span name as last recordRpc', () => { | ||
const logSpan = sinon.spy(); | ||
function record(traceId, timestamp, annotation) { | ||
return new Record({traceId, timestamp, annotation}); | ||
} | ||
const ctxImpl = new ExplicitContext(); | ||
const logger = {logSpan}; | ||
const recorder = new BatchRecorder({logger}); | ||
const trace = new Tracer({ctxImpl, recorder}); | ||
it('should flush Spans not finished within a minute timeout', () => { | ||
const clock = lolex.install(); | ||
recorder = new BatchRecorder({ | ||
logger: { | ||
logSpan: (span) => { | ||
spans.push(JSON.parse(JSON_V2.encode(span))); | ||
} | ||
} | ||
}); | ||
ctxImpl.scoped(() => { | ||
trace.setId(new TraceId({ | ||
traceId: 'a', | ||
parentId: new Some('a'), | ||
spanId: 'c', | ||
sampled: new Some(true) | ||
})); | ||
clock.tick('01'); | ||
recorder.record(record(rootId, now(), new Annotation.ServerRecv())); | ||
trace.recordServiceName('SmoothieStore'); | ||
trace.recordRpc('buySmoothie'); | ||
trace.recordAnnotation(new Annotation.ServerRecv()); | ||
clock.tick('02'); // polling interval is every second | ||
expect(spans).to.be.empty; // eslint-disable-line no-unused-expressions | ||
// some customization code scoped to this trace ID resets the span name | ||
trace.recordRpc('rentSmoothie'); | ||
clock.tick('01:00'); // 1 minute is the default timeout | ||
expect(popSpan()).to.deep.equal({ | ||
traceId: rootId.traceId, | ||
id: rootId.spanId, | ||
kind: 'SERVER', | ||
timestamp: 1000000, | ||
annotations: [{timestamp: 62000000, value: 'zipkin-js.flush'}] | ||
}); | ||
trace.recordAnnotation(new Annotation.ServerSend()); | ||
clock.tick('02'); // Late server-send is still reported | ||
recorder.record(record(rootId, now(), new Annotation.ServerSend())); | ||
const loggedSpan = logSpan.getCall(0).args[0]; | ||
expect(popSpan()).to.deep.equal({ | ||
traceId: rootId.traceId, | ||
id: rootId.spanId, | ||
kind: 'SERVER', | ||
annotations: [{timestamp: 65000000, value: 'finish'}] | ||
}); | ||
expect(loggedSpan.name).to.eql('rentsmoothie'); | ||
clock.uninstall(); | ||
}); | ||
it('should start and finish a client span', () => { | ||
recorder.record(record(rootId, 1, new Annotation.ClientSend())); | ||
recorder.record(record(rootId, 3, new Annotation.ClientRecv())); | ||
expect(popSpan()).to.deep.equal({ | ||
traceId: rootId.traceId, | ||
id: rootId.spanId, | ||
kind: 'CLIENT', | ||
timestamp: 1, | ||
duration: 2 | ||
}); | ||
expect(spans).to.be.empty; // eslint-disable-line no-unused-expressions | ||
}); | ||
it('should copy shared flag from trace id', () => { | ||
const logSpan = sinon.spy(); | ||
it('should record ServerAddr as remote endpoint in a client span', () => { | ||
recorder.record(record(rootId, 1, new Annotation.ClientSend())); | ||
recorder.record(record(rootId, 1, new Annotation.ServerAddr({ | ||
serviceName: 'mysql', | ||
host: new InetAddress('54.0.0.101'), | ||
port: 3306 | ||
}))); | ||
recorder.record(record(rootId, 3, new Annotation.ClientRecv())); | ||
const ctxImpl = new ExplicitContext(); | ||
const logger = {logSpan}; | ||
const recorder = new BatchRecorder({logger}); | ||
const trace = new Tracer({ctxImpl, recorder}); | ||
expect(popSpan()).to.deep.equal({ | ||
traceId: rootId.traceId, | ||
id: rootId.spanId, | ||
kind: 'CLIENT', | ||
timestamp: 1, | ||
duration: 2, | ||
remoteEndpoint: { | ||
ipv4: '54.0.0.101', | ||
port: 3306, | ||
serviceName: 'mysql' | ||
} | ||
}); | ||
ctxImpl.scoped(() => { | ||
trace.setId(new TraceId({ | ||
traceId: 'a', | ||
parentId: new Some('a'), | ||
spanId: 'c', | ||
sampled: new Some(true), | ||
shared: true | ||
})); | ||
expect(spans).to.be.empty; // eslint-disable-line no-unused-expressions | ||
}); | ||
trace.recordServiceName('SmoothieStore'); | ||
trace.recordRpc('buySmoothie'); | ||
trace.recordAnnotation(new Annotation.ServerRecv()); | ||
trace.recordAnnotation(new Annotation.ServerSend()); | ||
it('should start and finish a server span', () => { | ||
recorder.record(record(rootId, 1, new Annotation.ServerRecv())); | ||
recorder.record(record(rootId, 3, new Annotation.ServerSend())); | ||
const loggedSpan = logSpan.getCall(0).args[0]; | ||
expect(popSpan()).to.deep.equal({ | ||
traceId: rootId.traceId, | ||
id: rootId.spanId, | ||
kind: 'SERVER', | ||
timestamp: 1, | ||
duration: 2 | ||
}); | ||
expect(loggedSpan.shared).to.equal(true); | ||
expect(spans).to.be.empty; // eslint-disable-line no-unused-expressions | ||
}); | ||
it('should record ClientAddr as remote endpoint in a server span', () => { | ||
recorder.record(record(rootId, 1, new Annotation.ServerRecv())); | ||
recorder.record(record(rootId, 1, new Annotation.ClientAddr({ | ||
host: new InetAddress('54.0.0.101'), | ||
port: 36656 | ||
}))); | ||
recorder.record(record(rootId, 3, new Annotation.ServerSend())); | ||
expect(popSpan()).to.deep.equal({ | ||
traceId: rootId.traceId, | ||
id: rootId.spanId, | ||
kind: 'SERVER', | ||
timestamp: 1, | ||
duration: 2, | ||
remoteEndpoint: { | ||
ipv4: '54.0.0.101', | ||
port: 36656 | ||
} | ||
}); | ||
expect(spans).to.be.empty; // eslint-disable-line no-unused-expressions | ||
}); | ||
it('should set Span.timestamp to first record', () => { | ||
const clock = lolex.install(12345678); | ||
const logSpan = sinon.spy(); | ||
it('should start and finish a shared server span', () => { | ||
const sharedId = new TraceId({ | ||
traceId: '5c7d31940cb80828', | ||
spanId: 'cb37670e772e86e2', | ||
sampled: new Some(true), | ||
shared: true // shared is a context property | ||
}); | ||
const ctxImpl = new ExplicitContext(); | ||
const logger = {logSpan}; | ||
const recorder = new BatchRecorder({logger}); | ||
const trace = new Tracer({ctxImpl, recorder}); | ||
recorder.record(record(sharedId, 1, new Annotation.ServerRecv())); | ||
recorder.record(record(sharedId, 3, new Annotation.ServerSend())); | ||
ctxImpl.scoped(() => { | ||
trace.setId(new TraceId({ | ||
traceId: 'a', | ||
spanId: 'c', | ||
sampled: new Some(true) | ||
})); | ||
trace.recordServiceName('SmoothieStore'); | ||
trace.recordRpc('buySmoothie'); | ||
trace.recordBinary('taste', 'banana'); | ||
trace.recordAnnotation(new Annotation.ServerRecv()); | ||
trace.recordAnnotation(new Annotation.ServerSend()); | ||
expect(popSpan()).to.deep.equal({ | ||
traceId: rootId.traceId, | ||
id: rootId.spanId, | ||
kind: 'SERVER', | ||
timestamp: 1, | ||
duration: 2, | ||
shared: true | ||
}); | ||
const loggedSpan = logSpan.getCall(0).args[0]; | ||
expect(spans).to.be.empty; // eslint-disable-line no-unused-expressions | ||
}); | ||
expect(loggedSpan.timestamp).to.equal(12345678000); | ||
it('should start and finish a producer span', () => { | ||
recorder.record(record(rootId, 1, new Annotation.ProducerStart())); | ||
recorder.record(record(rootId, 3, new Annotation.ProducerStop())); | ||
clock.uninstall(); | ||
expect(popSpan()).to.deep.equal({ | ||
traceId: rootId.traceId, | ||
id: rootId.spanId, | ||
kind: 'PRODUCER', | ||
timestamp: 1, | ||
duration: 2 | ||
}); | ||
expect(spans).to.be.empty; // eslint-disable-line no-unused-expressions | ||
}); | ||
it('should record duration in microseconds', () => { | ||
// This test is failing under the browser zipkin-js/#315 | ||
if (typeof window !== 'undefined') { | ||
return; | ||
} | ||
it('should record MessageAddr as remote endpoint in a producer span', () => { | ||
recorder.record(record(rootId, 1, new Annotation.ProducerStart())); | ||
recorder.record(record(rootId, 1, new Annotation.MessageAddr({ | ||
serviceName: 'rabbitmq' | ||
}))); | ||
recorder.record(record(rootId, 3, new Annotation.ProducerStop())); | ||
const clock = lolex.install(12345678); | ||
const logSpan = sinon.spy(); | ||
expect(popSpan()).to.deep.equal({ | ||
traceId: rootId.traceId, | ||
id: rootId.spanId, | ||
kind: 'PRODUCER', | ||
timestamp: 1, | ||
duration: 2, | ||
remoteEndpoint: {serviceName: 'rabbitmq'} | ||
}); | ||
const ctxImpl = new ExplicitContext(); | ||
const logger = {logSpan}; | ||
const recorder = new BatchRecorder({logger}); | ||
const trace = new Tracer({ctxImpl, recorder}); | ||
expect(spans).to.be.empty; // eslint-disable-line no-unused-expressions | ||
}); | ||
ctxImpl.scoped(() => { | ||
trace.setId(new TraceId({ | ||
traceId: 'a', | ||
spanId: 'c', | ||
sampled: new Some(true) | ||
})); | ||
trace.recordRpc('GET'); | ||
trace.recordAnnotation(new Annotation.ClientSend()); | ||
clock.tick(0.123456); | ||
trace.recordAnnotation(new Annotation.ClientRecv()); | ||
it('should start and finish a consumer span', () => { | ||
recorder.record(record(rootId, 1, new Annotation.ConsumerStart())); | ||
recorder.record(record(rootId, 3, new Annotation.ConsumerStop())); | ||
const loggedSpan = logSpan.getCall(0).args[0]; | ||
expect(popSpan()).to.deep.equal({ | ||
traceId: rootId.traceId, | ||
id: rootId.spanId, | ||
kind: 'CONSUMER', | ||
timestamp: 1, | ||
duration: 2 | ||
}); | ||
expect(loggedSpan.timestamp).to.equal(12345678000); | ||
expect(loggedSpan.duration).to.equal(123); | ||
expect(spans).to.be.empty; // eslint-disable-line no-unused-expressions | ||
}); | ||
clock.uninstall(); | ||
it('should start and finish a local span', () => { | ||
recorder.record(record(rootId, 1, new Annotation.LocalOperationStart('foo'))); | ||
recorder.record(record(rootId, 3, new Annotation.LocalOperationStop())); | ||
expect(popSpan()).to.deep.equal({ | ||
traceId: rootId.traceId, | ||
id: rootId.spanId, | ||
name: 'foo', | ||
timestamp: 1, | ||
duration: 2 | ||
}); | ||
expect(spans).to.be.empty; // eslint-disable-line no-unused-expressions | ||
}); | ||
it('should flush Spans not finished within a minute timeout', () => { | ||
const clock = lolex.install(); | ||
it('should add default tags', () => { | ||
const tags = {instanceId: 'i-1234567890abcdef0', cluster: 'nodeservice-stage'}; | ||
recorder.setDefaultTags(tags); | ||
const logSpan = sinon.spy(); | ||
const ctxImpl = new ExplicitContext(); | ||
const logger = {logSpan}; | ||
const recorder = new BatchRecorder({logger}); | ||
const trace = new Tracer({ctxImpl, recorder}); | ||
const traceId = new TraceId({ | ||
traceId: 'a', | ||
parentId: new Some('a'), | ||
spanId: 'c', | ||
sampled: new Some(true) | ||
recorder.record(record(rootId, 1, new Annotation.LocalOperationStart('foo'))); | ||
recorder.record(record(rootId, 3, new Annotation.LocalOperationStop())); | ||
expect(popSpan()).to.deep.equal({ | ||
traceId: rootId.traceId, | ||
id: rootId.spanId, | ||
name: 'foo', | ||
timestamp: 1, | ||
duration: 2, | ||
tags | ||
}); | ||
ctxImpl.scoped(() => { | ||
trace.setId(traceId); | ||
expect(spans).to.be.empty; // eslint-disable-line no-unused-expressions | ||
}); | ||
trace.recordServiceName('SmoothieStore'); | ||
trace.recordAnnotation(new Annotation.ServerRecv()); | ||
it('should accommodate late changes to span name', () => { | ||
recorder.record(record(rootId, 1, new Annotation.ServiceName('backend'))); | ||
recorder.record(record(rootId, 1, new Annotation.Rpc('GET'))); | ||
recorder.record(record(rootId, 1, new Annotation.BinaryAnnotation('http.path', '/api'))); | ||
recorder.record(record(rootId, 1, new Annotation.ServerRecv())); | ||
// when the response is ready to send, we have a name change | ||
recorder.record(record(rootId, 3, new Annotation.Rpc('GET /api'))); | ||
recorder.record(record(rootId, 3, new Annotation.BinaryAnnotation('http.status_code', '200'))); | ||
recorder.record(record(rootId, 3, new Annotation.ServerSend())); | ||
expect(popSpan()).to.deep.equal({ | ||
traceId: rootId.traceId, | ||
id: rootId.spanId, | ||
name: 'get /api', | ||
kind: 'SERVER', | ||
timestamp: 1, | ||
duration: 2, | ||
localEndpoint: { | ||
serviceName: 'backend' | ||
}, | ||
tags: { | ||
'http.path': '/api', | ||
'http.status_code': '200' | ||
} | ||
}); | ||
}); | ||
clock.tick('02'); // polling interval is every second | ||
expect(logSpan.calledOnce).to.equal(false); | ||
it('should only flush spans when calling flush method', () => { | ||
recorder = new BatchRecorder({ | ||
logger: { | ||
logSpan: (span) => { | ||
spans.push(JSON.parse(JSON_V2.encode(span))); | ||
} | ||
} | ||
}); | ||
clock.tick('01:00'); // 1 minute is the default timeout | ||
expect(logSpan.calledOnce).to.equal(true); | ||
recorder.record(record(rootId, 1, new Annotation.ServerRecv())); | ||
ctxImpl.scoped(() => { | ||
trace.setId(traceId); | ||
expect(spans).to.be.empty; // eslint-disable-line no-unused-expressions | ||
// ServerSend terminates the span, but it's already expired. | ||
// Span is dropped silently. | ||
trace.recordAnnotation(new Annotation.ServerSend()); | ||
recorder.flush(); | ||
expect(popSpan()).to.deep.equal({ | ||
traceId: rootId.traceId, | ||
id: rootId.spanId, | ||
kind: 'SERVER', | ||
timestamp: 1 | ||
}); | ||
clock.uninstall(); | ||
}); | ||
it('should capture ServerAddr event', () => { | ||
const logSpan = sinon.spy(); | ||
it('should handle overlapping server and client', () => { | ||
recorder.record(record(rootId, 1, new Annotation.ServiceName('frontend'))); | ||
recorder.record(record(rootId, 1, new Annotation.Rpc('GET'))); | ||
recorder.record(record(rootId, 1, new Annotation.BinaryAnnotation('http.path', '/'))); | ||
recorder.record(record(rootId, 1, new Annotation.ServerRecv())); | ||
const ctxImpl = new ExplicitContext(); | ||
const logger = {logSpan}; | ||
const recorder = new BatchRecorder({logger}); | ||
const trace = new Tracer({ctxImpl, recorder}); | ||
recorder.record(record(childId, 3, new Annotation.ServiceName('frontend'))); | ||
recorder.record(record(childId, 3, new Annotation.Rpc('GET'))); | ||
recorder.record(record(childId, 3, new Annotation.BinaryAnnotation('http.path', '/api'))); | ||
recorder.record(record(childId, 3, new Annotation.ClientSend())); | ||
recorder.record(record(childId, 4, new Annotation.BinaryAnnotation('error', 'ECONNREFUSED'))); | ||
recorder.record(record(childId, 4, new Annotation.ClientRecv())); | ||
ctxImpl.scoped(() => { | ||
trace.setId(new TraceId({ | ||
traceId: 'a', | ||
parentId: new Some('a'), | ||
spanId: 'c', | ||
sampled: new Some(true) | ||
})); | ||
trace.recordServiceName('client'); | ||
trace.recordRpc('call'); | ||
trace.recordAnnotation(new Annotation.ClientSend()); | ||
trace.recordAnnotation(new Annotation.ServerAddr({ | ||
serviceName: 'server', | ||
host: new InetAddress('127.0.0.2'), | ||
port: 7071 | ||
})); | ||
trace.recordAnnotation(new Annotation.ClientRecv()); | ||
recorder.record(record(rootId, 6, new Annotation.BinaryAnnotation('http.status_code', '500'))); | ||
recorder.record(record(rootId, 6, new Annotation.BinaryAnnotation('error', 'client fail'))); | ||
recorder.record(record(rootId, 6, new Annotation.ServerSend())); | ||
const loggedSpan = logSpan.getCall(0).args[0]; | ||
expect(loggedSpan.remoteEndpoint.serviceName).to.equal('server'); | ||
expect(loggedSpan.remoteEndpoint.ipv4).to.equal('127.0.0.2'); | ||
expect(loggedSpan.remoteEndpoint.port).to.equal(7071); | ||
expect(popSpan()).to.deep.equal({ | ||
traceId: rootId.traceId, | ||
id: rootId.spanId, | ||
name: 'get', | ||
kind: 'SERVER', | ||
timestamp: 1, | ||
duration: 5, | ||
localEndpoint: { | ||
serviceName: 'frontend' | ||
}, | ||
tags: { | ||
error: 'client fail', | ||
'http.path': '/', | ||
'http.status_code': '500' | ||
} | ||
}); | ||
expect(popSpan()).to.deep.equal({ | ||
traceId: rootId.traceId, | ||
parentId: rootId.spanId, | ||
id: childId.spanId, | ||
name: 'get', | ||
kind: 'CLIENT', | ||
timestamp: 3, | ||
duration: 1, | ||
localEndpoint: { | ||
serviceName: 'frontend' | ||
}, | ||
tags: { | ||
error: 'ECONNREFUSED', | ||
'http.path': '/api' | ||
} | ||
}); | ||
expect(spans).to.be.empty; // eslint-disable-line no-unused-expressions | ||
}); | ||
it('should capture MessageAddr event', () => { | ||
const logSpan = sinon.spy(); | ||
it('should keep state until finished', () => { | ||
recorder.record(record(rootId, 1, new Annotation.ClientSend())); | ||
expect(pendingSpan(rootId)).to.exist; // eslint-disable-line no-unused-expressions | ||
const ctxImpl = new ExplicitContext(); | ||
const logger = {logSpan}; | ||
const recorder = new BatchRecorder({logger}); | ||
const trace = new Tracer({ctxImpl, recorder}); | ||
recorder.record(record(rootId, 3, new Annotation.ClientRecv())); | ||
expect(pendingSpan(rootId)).to.not.exist; // eslint-disable-line no-unused-expressions | ||
ctxImpl.scoped(() => { | ||
trace.setId(new TraceId({ | ||
traceId: 'a', | ||
parentId: new Some('a'), | ||
spanId: 'c', | ||
sampled: new Some(true) | ||
})); | ||
trace.recordServiceName('producer'); | ||
trace.recordRpc('send-msg'); | ||
trace.recordAnnotation(new Annotation.ProducerStart()); | ||
trace.recordAnnotation(new Annotation.MessageAddr({ | ||
serviceName: 'mq', | ||
host: new InetAddress('127.0.0.2'), | ||
port: 7072 | ||
})); | ||
trace.recordAnnotation(new Annotation.ProducerStop()); | ||
popSpan(); // consume the span created above. | ||
}); | ||
const loggedSpan = logSpan.getCall(0).args[0]; | ||
expect(loggedSpan.remoteEndpoint.serviceName).to.equal('mq'); | ||
expect(loggedSpan.remoteEndpoint.ipv4).to.equal('127.0.0.2'); | ||
expect(loggedSpan.remoteEndpoint.port).to.equal(7072); | ||
/** | ||
* Due to the code structure of httpClient.js, we can't externally propagate the start timestamp | ||
* for the purpose of ensuring duration gets recorded even when flushed. | ||
* | ||
* This shows that once we refactor or replace this type, we will be able to restore duration by | ||
* replaying the start event, and without causing confusion when there is not flush. | ||
*/ | ||
it('should allow redundant reporting of start timestamp', () => { | ||
recorder.record(record(rootId, 1, new Annotation.ClientSend())); | ||
// pretend an async callback redundantly replays the send event | ||
recorder.record(record(rootId, 1, new Annotation.ClientSend())); | ||
recorder.record(record(rootId, 3, new Annotation.ClientRecv())); | ||
expect(popSpan()).to.deep.equal({ | ||
traceId: rootId.traceId, | ||
id: rootId.spanId, | ||
kind: 'CLIENT', | ||
timestamp: 1, | ||
duration: 2 | ||
}); | ||
expect(spans).to.be.empty; // eslint-disable-line no-unused-expressions | ||
}); | ||
it('should capture tracer defaultTags', () => { | ||
const logSpan = sinon.spy(); | ||
it('should report sane data even on timeout', () => { | ||
recorder.setDefaultTags({environment: 'production'}); | ||
const ctxImpl = new ExplicitContext(); | ||
const logger = {logSpan}; | ||
const recorder = new BatchRecorder({logger}); | ||
const defaultTags = {instanceId: 'i-1234567890abcdef0', cluster: 'nodeservice-stage'}; | ||
const trace = new Tracer({ctxImpl, recorder, defaultTags}); | ||
recorder.record(record(rootId, 1, new Annotation.ServiceName('frontend'))); | ||
recorder.record(record(rootId, 1, new Annotation.Rpc('GET'))); | ||
recorder.record(record(rootId, 1, new Annotation.BinaryAnnotation('http.path', '/api'))); | ||
recorder.record(record(rootId, 1, new Annotation.ClientSend())); | ||
recorder._writeSpan(rootId, pendingSpan(rootId)); // simulate timeout | ||
expect(pendingSpan(rootId)).to.not.exist; // eslint-disable-line no-unused-expressions | ||
trace.recordServiceName('producer'); | ||
trace.recordRpc('send-msg'); | ||
trace.recordAnnotation(new Annotation.LocalOperationStart()); | ||
trace.recordAnnotation(new Annotation.LocalOperationStop()); | ||
expect(popSpan()).to.deep.equal({ | ||
traceId: rootId.traceId, | ||
id: rootId.spanId, | ||
kind: 'CLIENT', | ||
timestamp: 1, | ||
name: 'get', | ||
localEndpoint: { | ||
serviceName: 'frontend' | ||
}, | ||
tags: { | ||
environment: 'production', | ||
'http.path': '/api' | ||
} | ||
}); | ||
const loggedSpan = logSpan.getCall(0).args[0]; | ||
expect(loggedSpan.tags.instanceId).to.equal(defaultTags.instanceId); | ||
expect(loggedSpan.tags.cluster).to.equal(defaultTags.cluster); | ||
recorder.record(record(rootId, 3, new Annotation.BinaryAnnotation('error', 'timeout'))); | ||
recorder.record(record(rootId, 3, new Annotation.ClientRecv())); | ||
expect(pendingSpan(rootId)).to.not.exist; // eslint-disable-line no-unused-expressions | ||
expect(popSpan()).to.deep.equal({ | ||
traceId: rootId.traceId, | ||
id: rootId.spanId, | ||
kind: 'CLIENT', | ||
// there's no duration here as start timestamp was lost due to the flush | ||
annotations: [{timestamp: 3, value: 'finish'}], | ||
// note: default tags are intentionally not redundantly copied | ||
tags: { | ||
error: 'timeout' | ||
} | ||
}); | ||
expect(spans).to.be.empty; // eslint-disable-line no-unused-expressions | ||
}); | ||
it('should capture tracer defaultTags on local scope', () => { | ||
const logSpan = sinon.spy(); | ||
/* This shows that a single finish event can trigger a report after a flush */ | ||
it('should report sane minimal data even on timeout', () => { | ||
recorder.record(record(rootId, 1, new Annotation.ClientSend())); | ||
recorder._writeSpan(rootId, pendingSpan(rootId)); // simulate timeout | ||
expect(pendingSpan(rootId)).to.not.exist; // eslint-disable-line no-unused-expressions | ||
const ctxImpl = new ExplicitContext(); | ||
const logger = {logSpan}; | ||
const recorder = new BatchRecorder({logger}); | ||
const defaultTags = {instanceId: 'i-1234567890abcdef0', cluster: 'nodeservice-stage'}; | ||
const trace = new Tracer({ctxImpl, recorder, defaultTags}); | ||
expect(popSpan()).to.deep.equal({ | ||
traceId: rootId.traceId, | ||
id: rootId.spanId, | ||
kind: 'CLIENT', | ||
timestamp: 1 | ||
}); | ||
ctxImpl.scoped(() => { | ||
trace.setId(new TraceId({ | ||
traceId: 'a', | ||
parentId: new Some('a'), | ||
spanId: 'c', | ||
sampled: new Some(true) | ||
})); | ||
trace.recordServiceName('producer'); | ||
trace.recordRpc('send-msg'); | ||
trace.recordAnnotation(new Annotation.LocalOperationStart()); | ||
trace.recordAnnotation(new Annotation.LocalOperationStop()); | ||
recorder.record(record(rootId, 3, new Annotation.ClientRecv())); | ||
expect(pendingSpan(rootId)).to.not.exist; // eslint-disable-line no-unused-expressions | ||
const loggedSpan = logSpan.getCall(0).args[0]; | ||
expect(loggedSpan.tags.instanceId).to.equal(defaultTags.instanceId); | ||
expect(loggedSpan.tags.cluster).to.equal(defaultTags.cluster); | ||
expect(popSpan()).to.deep.equal({ | ||
traceId: rootId.traceId, | ||
id: rootId.spanId, | ||
kind: 'CLIENT', | ||
// there's no duration here as start timestamp was lost due to the flush | ||
annotations: [{timestamp: 3, value: 'finish'}] | ||
}); | ||
expect(spans).to.be.empty; // eslint-disable-line no-unused-expressions | ||
}); | ||
}); |
@@ -1,114 +0,122 @@ | ||
const sinon = require('sinon'); | ||
const Tracer = require('../src/tracer'); | ||
const BatchRecorder = require('../src/batch-recorder'); | ||
const ExplicitContext = require('../src/explicit-context'); | ||
const HttpClient = require('../src/instrumentation/httpClient'); | ||
const {JSON_V2} = require('../src/jsonEncoder'); | ||
const Tracer = require('../src/tracer'); | ||
const {expectB3Headers, expectSpan} = require('../../../test/testFixture'); | ||
describe('Http Client Instrumentation', () => { | ||
let recorder; | ||
const serviceName = 'weather-app'; | ||
const remoteServiceName = 'weather-api'; | ||
const baseURL = 'http://127.0.0.1:80'; | ||
beforeEach(() => { | ||
const record = sinon.spy(); | ||
recorder = {record}; | ||
}); | ||
let spans; | ||
let tracer; | ||
let instrumentation; | ||
it('should add headers to requests', () => { | ||
const {record} = recorder; | ||
const ctxImpl = new ExplicitContext(); | ||
const tracer = new Tracer({ctxImpl, recorder}); | ||
const instrumentation = new HttpClient({ | ||
tracer, | ||
serviceName: 'weather-app', | ||
remoteServiceName: 'weather-forecast-service' | ||
beforeEach(() => { // TODO: extract this logic as it is reused in tracer, client and server tests | ||
spans = []; | ||
tracer = new Tracer({ | ||
ctxImpl: new ExplicitContext(), | ||
localServiceName: serviceName, | ||
recorder: new BatchRecorder({ | ||
logger: { | ||
logSpan: (span) => { | ||
spans.push(JSON.parse(JSON_V2.encode(span))); | ||
} | ||
} | ||
}) | ||
}); | ||
instrumentation = new HttpClient({tracer, remoteServiceName}); | ||
}); | ||
const port = '80'; | ||
const host = '127.0.0.1'; | ||
const urlPath = '/weather'; | ||
const url = `http://${host}:${port}${urlPath}?index=10&count=300`; | ||
tracer.scoped(() => { | ||
instrumentation.recordRequest({}, url, 'GET'); | ||
instrumentation.recordResponse(tracer.id, '202'); | ||
}); | ||
const annotations = record.args.map(args => args[0]); | ||
const initialTraceId = annotations[0].traceId.traceId; | ||
annotations.forEach(ann => expect(ann.traceId.traceId) | ||
.to.equal(initialTraceId).and | ||
.to.have.lengthOf(16)); | ||
annotations.forEach(ann => expect(ann.traceId.isShared()).to.equal(false)); | ||
afterEach(() => expect(spans).to.be.empty); | ||
expect(annotations[0].annotation.annotationType).to.equal('ServiceName'); | ||
expect(annotations[0].annotation.serviceName).to.equal('weather-app'); | ||
function popSpan() { | ||
expect(spans).to.not.be.empty; // eslint-disable-line no-unused-expressions | ||
return spans.pop(); | ||
} | ||
expect(annotations[1].annotation.annotationType).to.equal('Rpc'); | ||
expect(annotations[1].annotation.name).to.equal('GET'); | ||
function url(path) { | ||
return `${baseURL}${path}?index=10&count=300`; | ||
} | ||
expect(annotations[2].annotation.annotationType).to.equal('BinaryAnnotation'); | ||
expect(annotations[2].annotation.key).to.equal('http.path'); | ||
expect(annotations[2].annotation.value).to.equal(urlPath); | ||
it('should add headers to requests', () => { | ||
const path = '/weather/wuhan'; | ||
const request = instrumentation.recordRequest({}, url(path), 'GET'); | ||
instrumentation.recordResponse(tracer.id, '202'); | ||
expect(annotations[3].annotation.annotationType).to.equal('ClientSend'); | ||
expectB3Headers(popSpan(), request.headers, false); | ||
}); | ||
expect(annotations[4].annotation.annotationType).to.equal('ServerAddr'); | ||
expect(annotations[4].annotation.serviceName).to.equal('weather-forecast-service'); | ||
it('should support get request', () => { | ||
const path = '/weather/wuhan'; | ||
expect(annotations[5].annotation.annotationType).to.equal('BinaryAnnotation'); | ||
expect(annotations[5].annotation.key).to.equal('http.status_code'); | ||
expect(annotations[5].annotation.value).to.equal('202'); | ||
instrumentation.recordRequest({}, url(path), 'GET'); | ||
instrumentation.recordResponse(tracer.id, '200'); | ||
expect(annotations[6].annotation.annotationType).to.equal('ClientRecv'); | ||
expectSpan(popSpan(), { | ||
name: 'get', | ||
kind: 'CLIENT', | ||
localEndpoint: {serviceName}, | ||
remoteEndpoint: {serviceName: remoteServiceName}, | ||
tags: { | ||
'http.path': path, | ||
'http.status_code': '200' // TODO: It isn't typical to add status on 200 | ||
} | ||
}); | ||
}); | ||
it('should record an error', () => { | ||
const {record} = recorder; | ||
const ctxImpl = new ExplicitContext(); | ||
const tracer = new Tracer({ctxImpl, recorder}); | ||
const instrumentation = new HttpClient({ | ||
tracer, | ||
serviceName: 'weather-app', | ||
remoteServiceName: 'weather-forecast-service' | ||
it('should report 401 in tags', () => { | ||
const path = '/weather/securedTown'; | ||
instrumentation.recordRequest({}, url(path), 'GET'); | ||
instrumentation.recordResponse(tracer.id, '401'); | ||
expectSpan(popSpan(), { | ||
name: 'get', | ||
kind: 'CLIENT', | ||
localEndpoint: {serviceName}, | ||
remoteEndpoint: {serviceName: remoteServiceName}, | ||
tags: { | ||
'http.path': path, | ||
'http.status_code': '401', | ||
error: '401' | ||
} | ||
}); | ||
}); | ||
const url = 'http://127.0.0.1:80/weather?index=10&count=300'; | ||
tracer.scoped(() => { | ||
instrumentation.recordRequest({}, url, 'GET'); | ||
instrumentation.recordError(tracer.id, new Error('nasty error')); | ||
it('should report 500 in tags', () => { | ||
const path = '/weather/bagCity'; | ||
instrumentation.recordRequest({}, url(path), 'GET'); | ||
instrumentation.recordResponse(tracer.id, '500'); | ||
expectSpan(popSpan(), { | ||
name: 'get', | ||
kind: 'CLIENT', | ||
localEndpoint: {serviceName}, | ||
remoteEndpoint: {serviceName: remoteServiceName}, | ||
tags: { | ||
'http.path': path, | ||
'http.status_code': '500', | ||
error: '500' | ||
} | ||
}); | ||
const annotations = record.args.map(args => args[0]); | ||
const initialTraceId = annotations[0].traceId.traceId; | ||
annotations.forEach(ann => expect(ann.traceId.traceId) | ||
.to.equal(initialTraceId).and | ||
.to.have.lengthOf(16)); | ||
expect(annotations[5].annotation.annotationType).to.equal('BinaryAnnotation'); | ||
expect(annotations[5].annotation.key).to.equal('error'); | ||
expect(annotations[5].annotation.value).to.equal('Error: nasty error'); | ||
}); | ||
[400, 500].forEach((statusCode) => { | ||
it('should record an error on status code >399', () => { | ||
const {record} = recorder; | ||
const ctxImpl = new ExplicitContext(); | ||
const tracer = new Tracer({ctxImpl, recorder}); | ||
const instrumentation = new HttpClient({ | ||
tracer, | ||
serviceName: 'weather-app', | ||
remoteServiceName: 'weather-forecast-service' | ||
}); | ||
it('should record an error in tags', () => { | ||
const path = '/weather/bagCity'; | ||
instrumentation.recordRequest({}, url(path), 'GET'); | ||
instrumentation.recordError(tracer.id, new Error('nasty error')); | ||
const url = 'http://127.0.0.1:80/weather?index=10&count=300'; | ||
tracer.scoped(() => { | ||
instrumentation.recordRequest({}, url, 'GET'); | ||
instrumentation.recordResponse(tracer.id, statusCode); | ||
}); | ||
const annotations = record.args.map(args => args[0]); | ||
const initialTraceId = annotations[0].traceId.traceId; | ||
annotations.forEach(ann => expect(ann.traceId.traceId) | ||
.to.equal(initialTraceId).and | ||
.to.have.lengthOf(16)); | ||
expect(annotations[6].annotation.annotationType).to.equal('BinaryAnnotation'); | ||
expect(annotations[6].annotation.key).to.equal('error'); | ||
expect(annotations[6].annotation.value).to.equal(statusCode.toString()); | ||
expectSpan(popSpan(), { | ||
name: 'get', | ||
kind: 'CLIENT', | ||
localEndpoint: {serviceName}, | ||
remoteEndpoint: {serviceName: remoteServiceName}, | ||
tags: { | ||
'http.path': path, | ||
error: 'Error: nasty error' | ||
} | ||
}); | ||
}); | ||
}); |
@@ -1,204 +0,158 @@ | ||
const sinon = require('sinon'); | ||
const Tracer = require('../src/tracer'); | ||
const {Some, None} = require('../src/option'); | ||
const {Sampler, alwaysSample, neverSample} = require('../src/tracer/sampler'); | ||
const BatchRecorder = require('../src/batch-recorder'); | ||
const ExplicitContext = require('../src/explicit-context'); | ||
const HttpServer = require('../src/instrumentation/httpServer'); | ||
const InetAddress = require('../src/InetAddress'); | ||
const {JSON_V2} = require('../src/jsonEncoder'); | ||
const {Some, None} = require('../src/option'); | ||
const Tracer = require('../src/tracer'); | ||
const {expectSpan} = require('../../../test/testFixture'); | ||
const setupTest = () => { | ||
const record = sinon.spy(); | ||
const setDefaultTags = sinon.spy(); | ||
const recorder = {record, setDefaultTags}; | ||
const ctxImpl = new ExplicitContext(); | ||
const defaultTags = {instanceId: 'i-1234567890abcdef0'}; | ||
return { | ||
record, recorder, ctxImpl, defaultTags | ||
}; | ||
}; | ||
describe('Http Server Instrumentation', () => { | ||
const serviceName = 'weather-api'; | ||
const baseURL = 'http://127.0.0.1:80'; | ||
const ipv4 = InetAddress.getLocalAddress().ipv4(); // tracer uses this IP for localEndpoint.ipv4 | ||
const setupServerUrl = () => { | ||
const port = 80; | ||
const host = '127.0.0.1'; | ||
const url = `http://${host}:${port}`; | ||
return {port, host, url}; | ||
}; | ||
function readHeader(headers) { | ||
return name => (headers[name] ? new Some(headers[name]) : None); | ||
} | ||
describe('Http Server Instrumentation', () => { | ||
const serviceName = 'weather-app'; | ||
let spans; | ||
let tracer; | ||
let instrumentation; | ||
it('should create traceId', () => { | ||
const {record, recorder, ctxImpl} = setupTest(); | ||
const tracer = new Tracer({recorder, localServiceName: serviceName, ctxImpl}); | ||
const instrumentation = new HttpServer({tracer, port: 80}); | ||
const url = '/foo'; | ||
ctxImpl.scoped(() => { | ||
const id = instrumentation.recordRequest('POST', url, () => None); | ||
tracer.recordBinary('message', 'hello from within app'); | ||
instrumentation.recordResponse(id, 202); | ||
beforeEach(() => { // TODO: extract this logic as it is reused in tracer, client and server tests | ||
spans = []; | ||
tracer = new Tracer({ | ||
ctxImpl: new ExplicitContext(), | ||
localServiceName: serviceName, | ||
recorder: new BatchRecorder({ | ||
logger: { | ||
logSpan: (span) => { | ||
spans.push(JSON.parse(JSON_V2.encode(span))); | ||
} | ||
} | ||
}) | ||
}); | ||
const annotations = record.args.map(args => args[0]); | ||
const originalTraceId = annotations[0].traceId.traceId; | ||
const originalSpanId = annotations[0].traceId.spanId; | ||
instrumentation = new HttpServer({tracer, port: 80}); | ||
}); | ||
annotations.forEach(ann => expect(ann.traceId.traceId) | ||
.to.have.lengthOf(16).and | ||
.to.equal(originalTraceId)); | ||
annotations.forEach(ann => expect(ann.traceId.spanId) | ||
.to.have.lengthOf(16).and | ||
.to.equal(originalSpanId)); | ||
annotations.forEach(ann => expect(ann.traceId.isShared()).to.equal(false)); | ||
afterEach(() => expect(spans).to.be.empty); | ||
expect(annotations[0].annotation.annotationType).to.equal('ServiceName'); | ||
expect(annotations[0].annotation.serviceName).to.equal(serviceName); | ||
function popSpan() { | ||
expect(spans).to.not.be.empty; // eslint-disable-line no-unused-expressions | ||
return spans.pop(); | ||
} | ||
expect(annotations[1].annotation.annotationType).to.equal('Rpc'); | ||
expect(annotations[1].annotation.name).to.equal('POST'); | ||
function successSpan(path, city) { | ||
return ({ | ||
name: 'get', | ||
kind: 'SERVER', | ||
localEndpoint: {serviceName, ipv4, port: 80}, | ||
tags: { | ||
'http.path': path, | ||
'http.status_code': '200', | ||
city | ||
} | ||
}); | ||
} | ||
expect(annotations[2].annotation.annotationType).to.equal('BinaryAnnotation'); | ||
expect(annotations[2].annotation.key).to.equal('http.path'); | ||
expect(annotations[2].annotation.value).to.equal(url); | ||
function errorSpan(path, city, status) { | ||
return ({ | ||
name: 'get', | ||
kind: 'SERVER', | ||
localEndpoint: {serviceName, ipv4, port: 80}, | ||
tags: { | ||
'http.path': path, | ||
'http.status_code': status.toString(), | ||
error: status.toString(), // TODO: better error message especially on 500 | ||
city | ||
} | ||
}); | ||
} | ||
expect(annotations[3].annotation.annotationType).to.equal('ServerRecv'); | ||
it('should start a new trace', () => { | ||
const path = '/weather/wuhan'; | ||
const id = instrumentation.recordRequest('GET', `${baseURL}${path}`, () => None); | ||
tracer.recordBinary('city', 'wuhan'); | ||
instrumentation.recordResponse(id, 200); | ||
expect(annotations[4].annotation.annotationType).to.equal('LocalAddr'); | ||
expectSpan(popSpan(), successSpan(path, 'wuhan')); | ||
}); | ||
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'); | ||
it('http.path tag should not include query parameters', () => { | ||
const path = '/weather/wuhan'; | ||
const url = `${baseURL}${path}?index=10&count=300`; | ||
const id = instrumentation.recordRequest('GET', url, () => None); | ||
tracer.recordBinary('city', 'wuhan'); | ||
instrumentation.recordResponse(id, 200); | ||
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'); | ||
expectSpan(popSpan(), successSpan(path, 'wuhan')); | ||
}); | ||
const traceContextCases = [ | ||
{ | ||
'X-B3-TraceId': 'aaa', | ||
'X-B3-SpanId': 'bbb', | ||
it('should receive continue a trace from the client', () => { | ||
const headers = { | ||
'X-B3-TraceId': '863ac35c9f6413ad', | ||
'X-B3-SpanId': '48485a3953bb6124', | ||
'X-B3-Flags': '1' | ||
}, | ||
{ | ||
'X-B3-TraceId': 'aaa', | ||
'X-B3-SpanId': 'bbb', | ||
'X-B3-Sampled': '1' | ||
} | ||
]; | ||
}; | ||
traceContextCases.forEach((headers, index) => { | ||
it(`should extract trace from the client and record annotations case ${index}`, () => { | ||
const {record, recorder, ctxImpl} = setupTest(); | ||
const tracer = new Tracer({recorder, ctxImpl}); | ||
const path = '/weather/wuhan'; | ||
const id = instrumentation.recordRequest('GET', `${baseURL}${path}`, readHeader(headers)); | ||
tracer.recordBinary('city', 'wuhan'); | ||
instrumentation.recordResponse(id, 200); | ||
const {port, url} = setupServerUrl(); | ||
const instrumentation = new HttpServer({tracer, serviceName, port}); | ||
const span = popSpan(); | ||
expect(span.traceId).to.equal('863ac35c9f6413ad'); | ||
expect(span.id).to.equal('48485a3953bb6124'); | ||
expectSpan(span, {...successSpan(path, 'wuhan'), ...{debug: true, shared: true}}); | ||
}); | ||
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]); | ||
it('should accept a 128bit X-B3-TraceId', () => { | ||
const traceId = '863ac35c9f6413ad48485a3953bb6124'; | ||
annotations.forEach(ann => expect(ann.traceId.traceId).to.equal('aaa')); | ||
annotations.forEach(ann => expect(ann.traceId.spanId).to.equal('bbb')); | ||
annotations.forEach(ann => expect(ann.traceId.isShared()).to.equal(true)); | ||
const headers = { | ||
'X-B3-TraceId': traceId, | ||
'X-B3-SpanId': '48485a3953bb6124', | ||
'X-B3-Flags': '1' | ||
}; | ||
expect(annotations[0].annotation.annotationType).to.equal('ServiceName'); | ||
expect(annotations[0].annotation.serviceName).to.equal(serviceName); | ||
const path = '/weather/wuhan'; | ||
const id = instrumentation.recordRequest('GET', `${baseURL}${path}`, readHeader(headers)); | ||
instrumentation.recordResponse(id, 200); | ||
expect(annotations[1].annotation.annotationType).to.equal('Rpc'); | ||
expect(annotations[1].annotation.name).to.equal('POST'); | ||
expect(popSpan().traceId).to.equal(traceId); | ||
}); | ||
expect(annotations[2].annotation.annotationType).to.equal('BinaryAnnotation'); | ||
expect(annotations[2].annotation.key).to.equal('http.path'); | ||
expect(annotations[2].annotation.value).to.equal('/'); | ||
it('should report 401 in tags', () => { | ||
const path = '/weather/securedTown'; | ||
const id = instrumentation.recordRequest('GET', `${baseURL}${path}`, () => None); | ||
tracer.recordBinary('city', 'securedTown'); | ||
instrumentation.recordResponse(id, 401); | ||
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'); | ||
}); | ||
expectSpan(popSpan(), errorSpan(path, 'securedTown', 401)); | ||
}); | ||
traceContextCases.forEach((headers, index) => { | ||
it(`should should not join spans if join not supported case ${index}`, () => { | ||
const {record, recorder, ctxImpl} = setupTest(); | ||
const supportsJoin = false; | ||
const tracer = new Tracer({ | ||
recorder, ctxImpl, localServiceName: serviceName, supportsJoin | ||
}); | ||
it('should report 500 in tags', () => { | ||
const path = '/weather/bagCity'; | ||
const id = instrumentation.recordRequest('GET', `${baseURL}${path}`, () => None); | ||
tracer.recordBinary('city', 'bagCity'); | ||
instrumentation.recordResponse(id, 500); | ||
const {port, url} = setupServerUrl(); | ||
const instrumentation = new HttpServer({tracer, 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.parentSpanId.getOrElse()).to.equal('bbb')); | ||
annotations.forEach(ann => expect(ann.traceId.spanId).to.not.equal('bbb')); | ||
annotations.forEach(ann => expect(ann.traceId.isShared()).to.equal(false)); | ||
expect(annotations[0].annotation.annotationType).to.equal('ServiceName'); | ||
expect(annotations[0].annotation.serviceName).to.equal(serviceName); | ||
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'); | ||
}); | ||
expectSpan(popSpan(), errorSpan(path, 'bagCity', 500)); | ||
}); | ||
const samplingFlagCases = [ | ||
{headers: {'X-B3-Flags': '0'}, hasAnnotations: null}, | ||
{headers: {'X-B3-Flags': '1'}, hasAnnotations: true}, | ||
{headers: {'X-B3-Sampled': '0'}, hasAnnotations: false}, | ||
{headers: {'X-B3-Sampled': '1'}, hasAnnotations: true}, | ||
{headers: {'X-B3-Sampled': 'true'}, hasAnnotations: true}, | ||
{headers: {'X-B3-Sampled': 'false'}, hasAnnotations: false}, | ||
{headers: {'X-B3-Sampled': '0', 'X-B3-Flags': '0'}, hasAnnotations: false}, | ||
{headers: {'X-B3-Sampled': '0', 'X-B3-Flags': '1'}, hasAnnotations: true}, | ||
{headers: {'X-B3-Sampled': '1', 'X-B3-Flags': '0'}, hasAnnotations: true}, | ||
{headers: {'X-B3-Sampled': '1', 'X-B3-Flags': '1'}, hasAnnotations: true}, | ||
{headers: {'X-B3-Flags': '0'}, shouldSample: true}, // because this is meaningless | ||
{headers: {'X-B3-Flags': '1'}, shouldSample: true}, | ||
{headers: {'X-B3-Sampled': '0'}, shouldSample: false}, | ||
{headers: {'X-B3-Sampled': '1'}, shouldSample: true}, | ||
{headers: {'X-B3-Sampled': 'true'}, shouldSample: true}, | ||
{headers: {'X-B3-Sampled': 'false'}, shouldSample: false}, | ||
{headers: {'X-B3-Sampled': '0', 'X-B3-Flags': '0'}, shouldSample: false}, | ||
{headers: {'X-B3-Sampled': '0', 'X-B3-Flags': '1'}, shouldSample: true}, | ||
{headers: {'X-B3-Sampled': '1', 'X-B3-Flags': '0'}, shouldSample: true}, | ||
{headers: {'X-B3-Sampled': '1', 'X-B3-Flags': '1'}, shouldSample: true}, | ||
]; | ||
samplingFlagCases.forEach(({headers, hasAnnotations}) => { | ||
samplingFlagCases.forEach(({headers, shouldSample}) => { | ||
const caseName = []; | ||
@@ -219,51 +173,15 @@ | ||
it(`should receive sampling flags from the client with ${caseName.join(', ')}`, () => { | ||
const {record, recorder, ctxImpl} = setupTest(); | ||
const tracer = new Tracer({recorder, localServiceName: serviceName, ctxImpl}); | ||
const path = '/weather/wuhan'; | ||
const id = instrumentation.recordRequest('GET', `${baseURL}${path}`, readHeader(headers)); | ||
tracer.recordBinary('city', 'wuhan'); | ||
instrumentation.recordResponse(id, 200); | ||
const {port, url} = setupServerUrl(); | ||
const instrumentation = new HttpServer({tracer, 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]); | ||
if (hasAnnotations === true) { | ||
annotations.forEach(ann => expect(ann.traceId.traceId).to.not.be.empty); | ||
annotations.forEach(ann => expect(ann.traceId.spanId).to.not.be.empty); | ||
annotations.forEach(ann => expect(ann.traceId.isShared()).to.equal(false)); | ||
expect(annotations[0].annotation.annotationType).to.equal('ServiceName'); | ||
expect(annotations[0].annotation.serviceName).to.equal(serviceName); | ||
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'); | ||
} else if (hasAnnotations === false) { | ||
// nothing should be recorded | ||
expect(annotations.length).to.equal(0); | ||
if (shouldSample === true) { | ||
let expected = successSpan(path, 'wuhan'); | ||
if (headers['X-B3-Flags'] === '1') { | ||
expected = {...expected, ...{debug: true}}; | ||
} | ||
expectSpan(popSpan(), expected); | ||
} else { | ||
expect(spans).to.be.empty; // eslint-disable-line no-unused-expressions | ||
} | ||
@@ -273,150 +191,15 @@ }); | ||
it('should properly report the path excluding the query string', () => { | ||
const {record, recorder, ctxImpl} = setupTest(); | ||
const tracer = new Tracer({recorder, localServiceName: serviceName, ctxImpl}); | ||
it('should allow the host to be overridden', () => { // NOTE: this is actually IP as encoded | ||
instrumentation = new HttpServer({tracer, host: '1.1.1.1', port: 80}); | ||
const port = 80; | ||
const host = '127.0.0.1'; | ||
const urlPath = '/foo'; | ||
const instrumentation = new HttpServer({tracer, port}); | ||
const url = `http://${host}:${port}${urlPath}?abc=123`; | ||
ctxImpl.scoped(() => { | ||
const id = instrumentation.recordRequest('GET', url, () => None); | ||
tracer.recordBinary('message', 'hello from within app'); | ||
instrumentation.recordResponse(id, 202); | ||
}); | ||
const annotations = record.args.map(args => args[0]); | ||
const path = '/weather/wuhan'; | ||
const id = instrumentation.recordRequest('GET', `${baseURL}${path}`, () => None); | ||
tracer.recordBinary('city', 'wuhan'); | ||
instrumentation.recordResponse(id, 200); | ||
expect(annotations[2].annotation.annotationType).to.equal('BinaryAnnotation'); | ||
expect(annotations[2].annotation.key).to.equal('http.path'); | ||
expect(annotations[2].annotation.value).to.equal(urlPath); | ||
}); | ||
it('should accept a 128bit X-B3-TraceId', () => { | ||
const {record, recorder, ctxImpl} = setupTest(); | ||
const tracer = new Tracer({recorder, localServiceName: serviceName, ctxImpl}); | ||
const port = 80; | ||
const instrumentation = new HttpServer({tracer, port}); | ||
const url = `http://127.0.0.1:${port}`; | ||
const traceId = '863ac35c9f6413ad48485a3953bb6124'; | ||
const headers = { | ||
'X-B3-TraceId': traceId, | ||
'X-B3-SpanId': '48485a3953bb6124', | ||
'X-B3-Flags': '1' | ||
}; | ||
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); | ||
expectSpan(popSpan(), { | ||
...successSpan(path, 'wuhan'), | ||
...{localEndpoint: {serviceName, ipv4: '1.1.1.1', port: 80}} | ||
}); | ||
const annotations = record.args.map(args => args[0]); | ||
annotations.forEach(ann => expect(ann.traceId.traceId).to.equal(traceId)); | ||
}); | ||
it('should tolerate boolean literals for sampled header received from the client', () => { | ||
const {recorder, ctxImpl} = setupTest(); | ||
const tracer = new Tracer({recorder, localServiceName: serviceName, ctxImpl}); | ||
const headersCases = [ | ||
{ | ||
'X-B3-TraceId': 'aaa', | ||
'X-B3-SpanId': 'bbb', | ||
'X-B3-Flags': '1', | ||
'X-B3-Sampled': 'true' | ||
}, | ||
{ | ||
'X-B3-Flags': '1', | ||
'X-B3-Sampled': 'true' | ||
} | ||
]; | ||
headersCases.forEach((headers) => { | ||
const port = 80; | ||
const url = `http://127.0.0.1:${port}`; | ||
const instrumentation = new HttpServer({tracer, serviceName, port}); | ||
const readHeader = function(name) { | ||
return headers[name] ? new Some(headers[name]) : None; | ||
}; | ||
ctxImpl.scoped(() => { | ||
const id = instrumentation.recordRequest('POST', url, readHeader); | ||
expect(id._sampled.value).to.equal(true); | ||
}); | ||
}); | ||
}); | ||
const samplerCases = [ | ||
new Sampler(alwaysSample), | ||
new Sampler(neverSample) | ||
]; | ||
samplerCases.forEach((sampler) => { | ||
it(`should use sampler to calculate sampled value if missing in header (${sampler})`, () => { | ||
const {recorder, ctxImpl} = setupTest(); | ||
const tracer = new Tracer({ | ||
recorder, localServiceName: serviceName, ctxImpl, sampler | ||
}); | ||
const headers = { | ||
'X-B3-TraceId': 'aaa', | ||
'X-B3-SpanId': 'bbb' | ||
}; | ||
const {port, url} = setupServerUrl(); | ||
const instrumentation = new HttpServer({tracer, serviceName, port}); | ||
const readHeader = function(name) { | ||
return headers[name] ? new Some(headers[name]) : None; | ||
}; | ||
ctxImpl.scoped(() => { | ||
const id = instrumentation.recordRequest('POST', url, readHeader); | ||
expect(id._sampled.value).to.equal(sampler.shouldSample(id).value); | ||
}); | ||
}); | ||
}); | ||
it('should allow the host to be overridden', () => { | ||
const {record, recorder, ctxImpl} = setupTest(); | ||
const tracer = new Tracer({recorder, localServiceName: serviceName, ctxImpl}); | ||
const instrumentation = new HttpServer({ | ||
tracer, | ||
serviceName, | ||
host: '1.1.1.1', | ||
port: 80 | ||
}); | ||
ctxImpl.scoped(() => { | ||
const id = instrumentation.recordRequest('POST', '/test-url', () => None); | ||
instrumentation.recordResponse(id, 202); | ||
}); | ||
const localAddr = record.args | ||
.map(args => args[0].annotation) | ||
.find(annotation => annotation.annotationType === 'LocalAddr'); | ||
expect(localAddr.host.addr).to.equal('1.1.1.1'); | ||
}); | ||
it('should work if the host option is not defined', () => { | ||
const {record, recorder, ctxImpl} = setupTest(); | ||
const tracer = new Tracer({recorder, localServiceName: serviceName, ctxImpl}); | ||
const instrumentation = new HttpServer({ | ||
tracer, | ||
serviceName, | ||
port: 80 | ||
}); | ||
ctxImpl.scoped(() => { | ||
const id = instrumentation.recordRequest('POST', '/test-url', () => None); | ||
instrumentation.recordResponse(id, 202); | ||
}); | ||
const localAddr = record.args | ||
.map(args => args[0].annotation) | ||
.find(annotation => annotation.annotationType === 'LocalAddr'); | ||
expect(localAddr.host.addr).not.to.equal(undefined); | ||
}); | ||
}); |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2213066
20466
76