/**
 * Minified by jsDelivr using Terser v5.19.2.
 * Original file: /npm/zipkin@0.22.0/lib/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";function _interopDefault(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var os=_interopDefault(require("os")),url=_interopDefault(require("url"));function _typeof(t){return _typeof="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},_typeof(t)}function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _defineProperties(t,e){for(var n=0;n<e.length;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 _createClass(t,e,n){return e&&_defineProperties(t.prototype,e),n&&_defineProperties(t,n),t}function _inherits(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&&_setPrototypeOf(t,e)}function _getPrototypeOf(t){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},_getPrototypeOf(t)}function _setPrototypeOf(t,e){return _setPrototypeOf=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},_setPrototypeOf(t,e)}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function _assertThisInitialized(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function _possibleConstructorReturn(t,e){return!e||"object"!=typeof e&&"function"!=typeof e?_assertThisInitialized(t):e}function _createSuper(t){var e=_isNativeReflectConstruct();return function(){var n,r=_getPrototypeOf(t);if(e){var o=_getPrototypeOf(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return _possibleConstructorReturn(this,n)}}var None={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"}},Some=function(){function t(e){_classCallCheck(this,t),this.value=e}return _createClass(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 isOptional(t){return t instanceof Some||None.equals(t)}function verifyIsOptional(t){if(null==t)throw new Error("Error: data is not Optional - it's null");if(!isOptional(t))throw new Error("Error: data (".concat(t,") is not an Option!"));if(isOptional(t.value))throw new Error("Error: data (".concat(t.value,") is wrapped in Option twice"))}function verifyIsNotOptional(t){if(isOptional(t))throw new Error("Error: data (".concat(t,") is an Option!"))}function fromNullable(t){return null==t?None:new Some(t)}var Some_1=Some,None_1=None,isOptional_1=isOptional,verifyIsOptional_1=verifyIsOptional,verifyIsNotOptional_1=verifyIsNotOptional,fromNullable_1=fromNullable,option={Some:Some_1,None:None_1,isOptional:isOptional_1,verifyIsOptional:verifyIsOptional_1,verifyIsNotOptional:verifyIsNotOptional_1,fromNullable:fromNullable_1};function pickInterface(t,e){for(var n in t)for(var r=t[n].length-1;r>=0;r-=1){var o=t[n][r],a="IPv4"===e||0===o.scopeid;if(!o.internal&&o.family===e&&a)return o.address}return"IPv4"===e?"127.0.0.1":"::1"}function reduceInterfaces(t,e){var n={};for(var r in t)r===e&&(n[r]=t[r]);return n}function ipv4(t){var e=os.networkInterfaces();return t&&(e=reduceInterfaces(e,t)),pickInterface(e,"IPv4")}function ipv6(t){var e=os.networkInterfaces();return t&&(e=reduceInterfaces(e,t)),pickInterface(e,"IPv6")}ipv4.ipv4=ipv4,ipv4.ipv6=ipv6;var network=ipv4,InetAddress=function(){function t(e){_classCallCheck(this,t),this.addr=e}return _createClass(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}();function getLocalAddress(){return"object"===("undefined"==typeof process?"undefined":_typeof(process))&&"function"==typeof process.on?new InetAddress(network.ipv4()):new InetAddress("127.0.0.1")}var cachedLocalAddress=getLocalAddress();InetAddress.getLocalAddress=function(){return cachedLocalAddress};var InetAddress_1=InetAddress,SimpleAnnotation=function(){function t(){_classCallCheck(this,t)}return _createClass(t,[{key:"toString",value:function(){return"".concat(this.annotationType,"()")}}]),t}(),ClientSend=function(t){_inherits(n,SimpleAnnotation);var e=_createSuper(n);function n(){return _classCallCheck(this,n),e.apply(this,arguments)}return n}(),ClientRecv=function(t){_inherits(n,SimpleAnnotation);var e=_createSuper(n);function n(){return _classCallCheck(this,n),e.apply(this,arguments)}return n}(),ServerSend=function(t){_inherits(n,SimpleAnnotation);var e=_createSuper(n);function n(){return _classCallCheck(this,n),e.apply(this,arguments)}return n}(),ServerRecv=function(t){_inherits(n,SimpleAnnotation);var e=_createSuper(n);function n(){return _classCallCheck(this,n),e.apply(this,arguments)}return n}(),ProducerStart=function(t){_inherits(n,SimpleAnnotation);var e=_createSuper(n);function n(){return _classCallCheck(this,n),e.apply(this,arguments)}return n}(),ProducerStop=function(t){_inherits(n,SimpleAnnotation);var e=_createSuper(n);function n(){return _classCallCheck(this,n),e.apply(this,arguments)}return n}(),ConsumerStart=function(t){_inherits(n,SimpleAnnotation);var e=_createSuper(n);function n(){return _classCallCheck(this,n),e.apply(this,arguments)}return n}(),ConsumerStop=function(t){_inherits(n,SimpleAnnotation);var e=_createSuper(n);function n(){return _classCallCheck(this,n),e.apply(this,arguments)}return n}();function LocalOperationStart(t){this.name=t}LocalOperationStart.prototype.toString=function(){return'LocalOperationStart("'.concat(this.name,'")')};var LocalOperationStop=function(t){_inherits(n,SimpleAnnotation);var e=_createSuper(n);function n(){return _classCallCheck(this,n),e.apply(this,arguments)}return n}();function Message(t){this.message=t}function ServiceName(t){this.serviceName=t}function Rpc(t){this.name=t}function ClientAddr(t){var e=t.host,n=t.port;this.host=e,this.port=n}function ServerAddr(t){var e=t.serviceName,n=t.host,r=t.port;this.serviceName=e,this.host=n||void 0,this.port=r||0}function LocalAddr(t){var e=t.host,n=t.port;this.host=e||InetAddress_1.getLocalAddress(),this.port=n||0}function MessageAddr(t){var e=t.serviceName,n=t.host,r=t.port;this.serviceName=e,this.host=n,this.port=r}function BinaryAnnotation(t,e){this.key=t,this.value=e}Message.prototype.toString=function(){return'Message("'.concat(this.message,'")')},ServiceName.prototype.toString=function(){return'ServiceName("'.concat(this.serviceName,'")')},Rpc.prototype.toString=function(){return'Rpc("'.concat(this.name,'")')},ClientAddr.prototype.toString=function(){return'ClientAddr(host="'.concat(this.host,'", port=').concat(this.port,")")},ServerAddr.prototype.toString=function(){return'ServerAddr(serviceName="'.concat(this.serviceName,'", host="').concat(this.host,'", port=').concat(this.port,")")},LocalAddr.prototype.toString=function(){return'LocalAddr(host="'.concat(this.host.toString(),'", port=').concat(this.port,")")},MessageAddr.prototype.toString=function(){return'MessageAddr(serviceName="'.concat(this.serviceName,'", host="').concat(this.host,'", port=').concat(this.port,")")},BinaryAnnotation.prototype.toString=function(){return"BinaryAnnotation(".concat(this.key,'="').concat(this.value,'")')};var annotation={ClientSend:ClientSend,ClientRecv:ClientRecv,ServerSend:ServerSend,ServerRecv:ServerRecv,ProducerStart:ProducerStart,ProducerStop:ProducerStop,ConsumerStart:ConsumerStart,ConsumerStop:ConsumerStop,MessageAddr:MessageAddr,Message:Message,ServiceName:ServiceName,Rpc:Rpc,ClientAddr:ClientAddr,ServerAddr:ServerAddr,LocalAddr:LocalAddr,BinaryAnnotation:BinaryAnnotation,LocalOperationStart:LocalOperationStart,LocalOperationStop:LocalOperationStop};Object.keys(annotation).forEach((function(t){annotation[t].prototype.annotationType=t}));var annotation_1=annotation,isPromise_1=isPromise,default_1=isPromise;function isPromise(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}isPromise_1.default=default_1;var Some$1=option.Some,Sampler=function(){function t(e){_classCallCheck(this,t),this.evaluator=e}return _createClass(t,[{key:"shouldSample",value:function(t){var e=this,n=t.sampled.getOrElse((function(){return e.evaluator(t)}));return new Some$1(n)}},{key:"toString",value:function(){return"Sampler(".concat(this.evaluator.toString(),")")}}]),t}();function neverSample(t){return!1}function alwaysSample(t){return!0}function makeCountingEvaluator(t){if(t<=0)return neverSample;if(t>=1)return alwaysSample;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}neverSample.toString=function(){return"never sample"},alwaysSample.toString=function(){return"always sample"};var CountingSampler=function(t){_inherits(n,Sampler);var e=_createSuper(n);function n(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return _classCallCheck(this,n),e.call(this,makeCountingEvaluator(t<1?t:1))}return n}(),sampler={Sampler:Sampler,CountingSampler:CountingSampler,neverSample:neverSample,alwaysSample:alwaysSample},Record=function(){function t(e){var n=e.traceId,r=e.timestamp,o=e.annotation;_classCallCheck(this,t),this.traceId=n,this.timestamp=r,this.annotation=o}return _createClass(t,[{key:"toString",value:function(){return"Record(traceId=".concat(this.traceId.toString(),", annotation=").concat(this.annotation.toString(),")")}}]),t}(),record=Record,Some$2=option.Some,None$1=option.None,verifyIsOptional$1=option.verifyIsOptional,verifyIsNotOptional$1=option.verifyIsNotOptional,isOptional$1=option.isOptional,T=new Some$2(!0),TraceId=function(){function t(e){_classCallCheck(this,t);var n=e.spanId,r=e.traceId,o=void 0===r?n:r,a=e.parentId,i=void 0===a?None$1:a,s=e.flags,c=void 0===s?0:s,p=e.debug,d=void 0===p?1===c:p,u=e.sampled,l=void 0===u?None$1:u,h=e.shared,f=void 0!==h&&h;verifyIsNotOptional$1(n),verifyIsOptional$1(i),verifyIsOptional$1(l),isOptional$1(o)?this._traceId=o.getOrElse(n):this._traceId=null==o?n:o,this._parentId=i,this._spanId=n,this._sampled=d?T:l,this._debug=d,this._shared=f}return _createClass(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.toString())+", parentSpanId=".concat(this.parentSpanId.toString())+", traceId=".concat(this.traceId.toString(),")")}},{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}(),TraceId_1=TraceId;function randomTraceId(){for(var t="",e=0;e<16;e+=1){t+="0123456789abcdef"[Math.floor(16*Math.random())]}return t}var randomTraceId_1=randomTraceId,hrTimeSupport="undefined"!=typeof process&&process.hrtime;function nowLegacy(){return 1e3*Date.now()}function nowHrTime(t,e){if(t&&e){var n=process.hrtime(e);return t+Math.floor(1e6*n[0]+n[1]/1e3)}return 1e3*Date.now()}var now=hrTimeSupport?nowHrTime:nowLegacy,hrtime=hrTimeSupport?function(){return process.hrtime()}:function(){},time={now:now,hrtime:hrtime};function Endpoint(t){var e=t.serviceName,n=t.ipv4,r=t.port;this.setServiceName(e),this.setIpv4(n),this.setPort(r)}function Annotation(t,e){this.timestamp=t,this.value=e.toString()}function Span(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()}Endpoint.prototype.setServiceName=function(t){this.serviceName=t?t.toLocaleLowerCase():void 0},Endpoint.prototype.setIpv4=function(t){this.ipv4=t},Endpoint.prototype.setPort=function(t){this.port=t||void 0},Endpoint.prototype.isEmpty=function(){return void 0===this.serviceName&&void 0===this.ipv4&&void 0===this.port},Annotation.prototype.toString=function(){return'Annotation(value="'.concat(this.value,'")')},Span.prototype.setName=function(t){this.name=t?t.toLocaleLowerCase():void 0},Span.prototype.setKind=function(t){this.kind=t},Span.prototype.setTimestamp=function(t){this.timestamp=t},Span.prototype.setDuration=function(t){void 0!==t&&(this.duration=Math.max(t,1))},Span.prototype.setLocalEndpoint=function(t){t&&!t.isEmpty()?this.localEndpoint=t:this.localEndpoint=void 0},Span.prototype.setRemoteEndpoint=function(t){t&&!t.isEmpty()?this.remoteEndpoint=t:this.remoteEndpoint=void 0},Span.prototype.addAnnotation=function(t,e){this.annotations.push(new Annotation(t,e))},Span.prototype.putTag=function(t,e){this.tags[t]=e.toString()},Span.prototype.setDebug=function(t){this.debug=t},Span.prototype.setShared=function(t){this.shared=t},Span.prototype.toString=function(){var t=this.annotations.map((function(t){return t.toString()})).join(", ");return"Span(id=".concat(this.traceId,", annotations=[").concat(t,"])")};var Endpoint_1=Endpoint,Span_1=Span,model={Endpoint:Endpoint_1,Span:Span_1},None$2=option.None,Some$3=option.Some,Sampler$1=sampler.Sampler,alwaysSample$1=sampler.alwaysSample,now$1=time.now,hrtime$1=time.hrtime,Endpoint$1=model.Endpoint;function requiredArg(t){throw new Error("Tracer: Missing required argument ".concat(t,"."))}function isUndefinedOrNull(t){return null==t}var Tracer=function(){function t(e){var n=e.ctxImpl,r=void 0===n?requiredArg("ctxImpl"):n,o=e.recorder,a=void 0===o?requiredArg("recorder"):o,i=e.sampler,s=void 0===i?new Sampler$1(alwaysSample$1):i,c=e.traceId128Bit,p=void 0!==c&&c,d=e.supportsJoin,u=void 0===d||d,l=e.localServiceName,h=e.localEndpoint,f=e.log,m=void 0===f?console:f,v=e.defaultTags;_classCallCheck(this,t),this.log=m,this.recorder=a,this.sampler=s,this.traceId128Bit=p,this.supportsJoin=u,this._localEndpoint=h||new Endpoint$1({serviceName:l||"unknown"}),this._ctxImpl=r,this._sentinelTraceId=this.createRootId(),this._startTimestamp=now$1(),this._startTick=hrtime$1(),this.recorder.setDefaultTags&&this.recorder.setDefaultTags(v)}return _createClass(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]:None$2,e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=randomTraceId_1(),r=this.traceId128Bit?randomTraceId_1()+n:n,o=new TraceId_1({traceId:r,parentId:None$2,spanId:n,sampled:t,flags:e?1:0});return t===None$2&&(o._sampled=this.sampler.shouldSample(o)),o}},{key:"createChildId",value:function(t){if(isUndefinedOrNull(t)&&(t=this._ctxImpl.getContext()),t===this._sentinelTraceId||isUndefinedOrNull(t))return this.createRootId();var e=new TraceId_1({traceId:t.traceId,parentId:new Some$3(t.spanId),spanId:randomTraceId_1(),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]:now$1(this._startTimestamp,this._startTick);this.recorder.record(new record({traceId:t,timestamp:n,annotation:e}))}},{key:"local",value:function(t,e){var n=this;if("function"!=typeof e)throw new 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 annotation_1.LocalOperationStart(t));try{r=e()}catch(t){throw n.recordBinary("error",t.message?t.message:t.toString()),n.recordAnnotation(new annotation_1.LocalOperationStop),t}return isPromise_1(r)?o.sampled.getOrElse(!1)?r.then((function(t){return n._explicitRecord(o,new annotation_1.LocalOperationStop),t})).catch((function(t){var e=t.message?t.message:t.toString();throw n._explicitRecord(o,new annotation_1.BinaryAnnotation("error",e)),n._explicitRecord(o,new annotation_1.LocalOperationStop),t})):r:(n.recordAnnotation(new annotation_1.LocalOperationStop),r)}))}},{key:"join",value:function(t){if(isUndefinedOrNull(t))throw new Error("traceId is a required arg");if(isUndefinedOrNull(t._spanId))throw new Error("Must be valid TraceId instance");return this.supportsJoin?(t.sampled===None$2?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 annotation_1.Message(t))}},{key:"recordServiceName",value:function(t){this.recordAnnotation(new annotation_1.ServiceName(t))}},{key:"recordRpc",value:function(t){this.recordAnnotation(new annotation_1.Rpc(t))}},{key:"recordClientAddr",value:function(t){this.recordAnnotation(new annotation_1.ClientAddr(t))}},{key:"recordServerAddr",value:function(t){this.recordAnnotation(new annotation_1.ServerAddr(t))}},{key:"recordLocalAddr",value:function(t){this.recordAnnotation(new annotation_1.LocalAddr(t))}},{key:"recordBinary",value:function(t,e){this.recordAnnotation(new annotation_1.BinaryAnnotation(t,e))}},{key:"writeIdToConsole",value:function(t){this.log.info("".concat(t,": ").concat(this.id.toString()))}},{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}(),tracer=Tracer,explicitContext=function(){function t(){_classCallCheck(this,t),this.currentCtx=null}return _createClass(t,[{key:"setContext",value:function(t){this.currentCtx=t}},{key:"getContext",value:function(){return this.currentCtx}},{key:"scoped",value:function(t){var e=this.getContext();try{return t()}finally{this.setContext(e)}}},{key:"letContext",value:function(t,e){var n=this;return this.scoped((function(){return n.setContext(t),e()}))}}]),t}(),noop=function(){var t=new explicitContext;return new tracer({recorder:{record:function(){}},ctxImpl:t})},httpHeaders={TraceId:"X-B3-TraceId",SpanId:"X-B3-SpanId",ParentSpanId:"X-B3-ParentSpanId",Sampled:"X-B3-Sampled",Flags:"X-B3-Flags"},now$2=time.now,Span$1=model.Span,Endpoint$2=model.Endpoint,defaultTagsSymbol=Symbol("defaultTags");function _timedOut(t){return t.timeoutTimestamp<now$2()}var PartialSpan=function(){function t(e,n){_classCallCheck(this,t),this.traceId=e,this.timeoutTimestamp=n,this.delegate=new Span$1(e),this.localEndpoint=new Endpoint$2({}),this.shouldFlush=!1}return _createClass(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}(),defaultTimeout=6e7,BatchRecorder=function(){function t(e){var n=this,r=e.logger,o=e.timeout,a=void 0===o?defaultTimeout:o;_classCallCheck(this,t),this.logger=r,this.timeout=a,this.partialSpans=new Map,this[defaultTagsSymbol]={};var i=setInterval((function(){n.partialSpans.forEach((function(t,e){_timedOut(t)&&(t.delegate.addAnnotation(now$2(),"zipkin-js.flush"),n._writeSpan(e,t))}))}),1e3);i.unref&&i.unref()}return _createClass(t,[{key:"_addDefaultTagsAndLocalEndpoint",value:function(t){var e=this[defaultTagsSymbol];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]||void 0!==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 PartialSpan(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 Endpoint$2({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 Endpoint$2({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 Endpoint$2({serviceName:t.annotation.serviceName,ipv4:t.annotation.host&&t.annotation.host.ipv4(),port:t.annotation.port}))}}))}},{key:"setDefaultTags",value:function(t){this[defaultTagsSymbol]=t}},{key:"toString",value:function(){return"BatchRecorder()"}}]),t}(),batchRecorder=BatchRecorder,ConsoleRecorder=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:console.log;_classCallCheck(this,t),this.logger=e}return _createClass(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.toString()))}},{key:"toString",value:function(){return"consoleTracer"}}]),t}(),consoleRecorder=ConsoleRecorder;function parseRequestUrl(t){var e=url.parse(t);return{host:e.hostname,path:e.pathname}}var parseUrl=parseRequestUrl,Some$4=option.Some,None$3=option.None;function stringToBoolean(t){return"1"===t||"true"===t}function stringToIntOption(t){try{return new Some$4(parseInt(t))}catch(t){return None$3}}function containsRequiredHeaders(t){return t(httpHeaders.TraceId)!==None$3&&t(httpHeaders.SpanId)!==None$3}function requiredArg$1(t){throw new Error("HttpServerInstrumentation: Missing required argument ".concat(t,"."))}var HttpServerInstrumentation=function(){function t(e){var n=e.tracer,r=void 0===n?requiredArg$1("tracer"):n,o=e.serviceName,a=void 0===o?r.localEndpoint.serviceName:o,i=e.host,s=e.port,c=void 0===s?requiredArg$1("port"):s;_classCallCheck(this,t),this.tracer=r,this.serviceName=a,this.host=i&&new InetAddress_1(i),this.port=c}return _createClass(t,[{key:"_createIdFromHeaders",value:function(t){if(containsRequiredHeaders(t)){var e=t(httpHeaders.SpanId).map((function(e){var n=t(httpHeaders.TraceId),r=t(httpHeaders.ParentSpanId),o=t(httpHeaders.Sampled),a=t(httpHeaders.Flags).flatMap(stringToIntOption).getOrElse(0);return new TraceId_1({traceId:n.getOrElse(),parentId:r,spanId:e,debug:1===a,sampled:o.map(stringToBoolean)})}));return new Some$4(this.tracer.join(e.getOrElse()))}if(t(httpHeaders.Flags)!==None$3||t(httpHeaders.Sampled)!==None$3){var n=t(httpHeaders.Sampled)===None$3?None$3:t(httpHeaders.Sampled).map(stringToBoolean),r=t(httpHeaders.Flags).flatMap(stringToIntOption).getOrElse(0);return new Some$4(this.tracer.createRootId(n,1===r))}return new Some$4(this.tracer.createRootId())}},{key:"spanNameFromRoute",value:function(t,e,n){return n>299&&n<400?"".concat(t," redirected"):404===n?"".concat(t," not_found"):e&&""!==e?"".concat(t," ").concat(e):t}},{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,a=parseUrl(e).path;return this.tracer.recordServiceName(this.serviceName),this.tracer.recordRpc(t.toUpperCase()),this.tracer.recordBinary("http.path",a),this.tracer.recordAnnotation(new annotation_1.ServerRecv),this.tracer.recordAnnotation(new annotation_1.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.toString()),n?this.tracer.recordBinary("error",n.toString()):(e<200||e>399)&&this.tracer.recordBinary("error",e.toString()),this.tracer.recordAnnotation(new annotation_1.ServerSend)}}]),t}(),httpServer=HttpServerInstrumentation;function appendZipkinHeaders(t,e){var n=t.headers||{};return n[httpHeaders.TraceId]=e.traceId,n[httpHeaders.SpanId]=e.spanId,e.parentSpanId.ifPresent((function(t){n[httpHeaders.ParentSpanId]=t})),e.sampled.ifPresent((function(t){n[httpHeaders.Sampled]=t?"1":"0"})),e.isDebug()&&(n[httpHeaders.Flags]="1"),n}function addZipkinHeaders(t,e){var n=appendZipkinHeaders(t,e);return Object.assign({},t,{headers:n})}var request={addZipkinHeaders:addZipkinHeaders};function requiredArg$2(t){throw new Error("HttpClientInstrumentation: Missing required argument ".concat(t,"."))}var HttpClientInstrumentation=function(){function t(e){var n=e.tracer,r=void 0===n?requiredArg$2("tracer"):n,o=e.serviceName,a=void 0===o?r.localEndpoint.serviceName:o,i=e.remoteServiceName;_classCallCheck(this,t),this.tracer=r,this.serviceName=a,this.remoteServiceName=i}return _createClass(t,[{key:"recordRequest",value:function(t,e,n){this.tracer.setId(this.tracer.createChildId());var r=this.tracer.id,o=parseUrl(e).path;return this.tracer.recordServiceName(this.serviceName),this.tracer.recordRpc(n.toUpperCase()),this.tracer.recordBinary("http.path",o),this.tracer.recordAnnotation(new annotation_1.ClientSend),this.remoteServiceName&&this.tracer.recordAnnotation(new annotation_1.ServerAddr({serviceName:this.remoteServiceName})),request.addZipkinHeaders(t,r)}},{key:"recordResponse",value:function(t,e){this.tracer.setId(t),this.tracer.recordBinary("http.status_code",e.toString()),(e<200||e>399)&&this.tracer.recordBinary("error",e.toString()),this.tracer.recordAnnotation(new annotation_1.ClientRecv)}},{key:"recordError",value:function(t,e){this.tracer.setId(t),this.tracer.recordBinary("error",e.toString()),this.tracer.recordAnnotation(new annotation_1.ClientRecv)}}]),t}(),httpClient=HttpClientInstrumentation,instrumentation={HttpServer:httpServer,HttpClient:httpClient};function toV1Endpoint(t){if(void 0!==t){var e={serviceName:t.serviceName||""};return t.ipv4&&(e.ipv4=t.ipv4),t.port&&(e.port=t.port),e}}function toV1Annotation(t,e){return{value:t.value,timestamp:t.timestamp,endpoint:e}}function encodeV1(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,a=toV1Endpoint(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 toV1Annotation(t,a)}))),n&&(e.annotations.push({value:n,timestamp:t.timestamp,endpoint:a}),t.duration&&e.annotations.push({value:r,timestamp:t.timestamp+t.duration,endpoint:a}));var i=Object.keys(t.tags);if((i.length>0||t.remoteEndpoint)&&(e.binaryAnnotations=i.map((function(e){return{key:e,value:t.tags[e],endpoint:a}}))),t.remoteEndpoint){var s={key:o,value:!0,endpoint:toV1Endpoint(t.remoteEndpoint)};e.binaryAnnotations.push(s)}return t.debug&&(e.debug=!0),JSON.stringify(e)}function encodeV2(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)}var JSON_V1={encode:function(t){return encodeV1(t)}},JSON_V2={encode:function(t){return encodeV2(t)}},jsonEncoder={JSON_V1:JSON_V1,JSON_V2:JSON_V2};exports.option=option,exports.Annotation=annotation_1,exports.Tracer=tracer,exports.createNoopTracer=noop,exports.randomTraceId=randomTraceId_1,exports.sampler=sampler,exports.TraceId=TraceId_1,exports.HttpHeaders=httpHeaders,exports.InetAddress=InetAddress_1,exports.BatchRecorder=batchRecorder,exports.ConsoleRecorder=consoleRecorder,exports.ExplicitContext=explicitContext,exports.Instrumentation=instrumentation,exports.Request=request,exports.jsonEncoder=jsonEncoder,exports.model=model,exports.parseRequestUrl=parseUrl;
//# sourceMappingURL=/sm/41c8c6bcd352c27f0eed212d0995587af4041fcc5580eef1bd53786255d7b804.map