rontgen-1.5.1.js.下载 23 KB

1
  1. !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).YouzanRontgen={})}(this,(function(t){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n={},r={__esModule:!0,LEGACY_HTTP_TRACE_HEADER:"x-cat-trace",X_YZ_TEACE_HEADER:"x-yz-trace",X_SERVICE_CHIAN_HEADER:"x-service-chain",X_YZ_ACTION_ID_HEADER:"x-yz-action-id",LEGACY_DUBBO_TRACE_ATTACHMENT:"CAT_TRACE",LEGACY_NAQ_TRACE_EXTENSION_KEY:"_catContext",DUBBO_TRACE_ATTACHMENT:"rontgen",NAQ_TRACE__EXTENSION_KEY:"_rontgen",HTTP_TRACE_HEADER:"x-rontgen",SAMPLE_MARK:"sample=true",DUBBO_PROTOCOL_NAME:"dubbo"},o={__esModule:!0},i=function(){function t(t){var e=t.traceId,n=t.parentId,r=t.spanId,o=t.appName;this.durationNano=0,this.finished=!1,this.spanId=r,this.traceId=e||"null",this.parentId=n,this.appName=o,this.logs=[]}return t.prototype.isFinished=function(){return this.finished},t.prototype.markError=function(t){try{this.finish(),this.tags[0][1]="true",t&&"object"==typeof t?(void 0!==t.code&&this.addTag("error.code",String(t.code)),this.addLog("error.message",String(t.message||t.msg||JSON.stringify(t))),t.stack&&this.addLog("error.stack",t.stack)):this.addLog("error.message",JSON.stringify(t))}catch(t){console.warn("[rontgen] markError fail",t)}},t.prototype.hasError=function(){return"true"===this.tags[0][1]},t.prototype.addTag=function(t,e){this.tags.push([t,e])},t.prototype.getTag=function(t){var e;return(null===(e=this.tags.find((function(e){return e[0]===t})))||void 0===e?void 0:e[1])||null},t.prototype.setTagVal=function(t,e){var n=this.tags.find((function(e){return e[0]===t}));n?n[1]=e:this.addTag(t,e)},t.prototype.addLog=function(t,e){var n;this.logs.push(((n={})[t]=e,n))},t.prototype.setOperation=function(t,e){this.operationType=t,this.operationName=e},t.prototype.toString=function(){return'{"app":"'+this.appName+'","traceId":"'+this.traceId+'","parentId":'+(null===this.parentId?"null":'"'+this.parentId+'"')+',"spanId":"'+this.spanId+'","opType":"'+this.operationType+'","opName":"'+this.operationName+'","time":'+this.startTimeNano+',"duration":'+this.durationNano+',"tags":'+JSON.stringify(this.tags)+',"logs":'+JSON.stringify(this.logs)+"}"},t}();o.Span=i;var a={__esModule:!0},s=function(){function t(){}return t.encode=function(t){var e=t.getTag("segment_id");return'{"_catRootMessageId": "'+t.traceId+'","_catParentMessageId": "'+e+'","_catChildMessageId":"'+t.spanId+'"}'},t.decode=function(t){return t?JSON.parse(t):null},t}();a.LegacyHeaderCodec=s;var u={__esModule:!0},c="traceId=",l="sample=",p=function(){function t(){}return t.decode=function(t){if(!t)return null;var e,n=t.split(";"),r=!1;try{for(var o=0;o<n.length;o++)n[o].startsWith(c)?e=decodeURIComponent(n[o].substring(c.length)):n[o].startsWith(l)&&(r="false"!==n[o].substring(l.length))}catch(t){console.error(t)}return e?{traceId:e,sample:r}:null},t}();u.CookieHeaderCodec=p;var d={};!function(t){t.__esModule=!0,function(t){t.FRONT="FRONT",t.HTTP_SERVER="HTTP_SERVER",t.HTTP_CLIENT="HTTP_CLIENT",t.DUBBO_SERVER="DUBBO_SERVER",t.DUBBO_CLIENT="DUBBO_CLIENT",t.TETHER_SERVER="TETHER_SERVER",t.TETHER_CLIENT="TETHER_CLIENT",t.NSQ_SERVER="NSQ_SERVER",t.NSQ_CLIENT="NSQ_CLIENT",t.CUSTOMER_SERVER="CUSTOMER_SERVER",t.SQL_CLIENT="SQL_CLIENT",t.CONNECT_CLIENT="CONNECT_CLIENT",t.REDIS_CLIENT="REDIS_CLIENT",t.CUSTOMER_METHOD_CLIENT="CUSTOMER_METHOD_CLIENT",t.MARCH_CLIENT="MARCH_CLIENT",t.DUMB_SERVER="DUMB_SERVER",t.ASYNC_CLIENT="ASYNC_CLIENT"}(t.OperationTypeEnum||(t.OperationTypeEnum={})),function(t){t.SEGMENT="segment",t.SEGMENT_ID="segment_id",t.ACTION_ID="act_id",t.ERROR="error",t.ERROR_CODE="error.code",t.PEER_HOSTNAME="peer.hostname",t.PEER_PORT="peer.port",t.PEER_IP="peer.ip",t.LOCAL_HOSTNAME="local.hostname",t.LOCAL_PORT="local.port",t.LOCAL_IP="local.ip",t.MQ_CHANNEL="mq.channel",t.PROTOCOL="protocol",t.DB_NAME="db.name",t.DB_COMMAND="db.command",t.REDIS_ARG0="redis.arg0",t.HTTP_CODE="http.code",t.HTTP_HOST="http.host",t.HTTP_METHOD="http.method",t.HTTP_URL_PATTERN="http.url_pattern",t.SC_NAME="sc.name",t.SC_ZAN_TEST="sc.zan_test",t.YZ_KDT_ID="yz.kdt_id",t.YZ_USER_ID="yz.user_id",t.YZ_GOODS_ID="yz.goods_id",t.YZ_GOODS_ALIAS="yz.goods_alias",t.YZ_ORDER_NO="yz.order_no",t.YZ_STORE_ID="yz.store_id",t.YZ_APP_ID="yz.app_id"}(t.TagEnum||(t.TagEnum={})),function(t){t.TIME="time",t.EVENT="event",t.EXTRA_DATA="extra_data",t.SC_DATA="sc.data",t.ERROR_STACK="error.stack",t.ERROR_MESSAGE="error.message",t.DB_STATEMENT="db.statement",t.HTTP_URL="http.url",t.DUBBO_QUEUE_TIME="dubbo.queue_time",t.NODE_QUERY="nodeQuery",t.SAMPLED="sampled",t.SAMPLED_SCENE="sampled_scene",t.SAMPLE_RULE="sample_rule"}(t.LogEnum||(t.LogEnum={}))}(d);var h={__esModule:!0},f=function(){function t(t){var e=t.parentId,n=t.traceId,r=t.appName;this.traceWithException=!1,this.spanQueue=[],this.appName=r,this.rootId=n||"null",this.parentId=e||"null",this.segmentId="null"}return t.prototype.enqueue=function(t){this.spanQueue.push(t)},t.prototype.hasError=function(){return this.traceWithException||this.spanQueue.some((function(t){return t.hasError()}))},t}();h.BaseTraceContext=f,h.isTraceContext=function(t){if(!t)return!1;if(t instanceof f)return!0;var e=Object.prototype.hasOwnProperty;return!!(e.call(t,"rootId")&&e.call(t,"parentId")&&e.call(t,"logger")&&e.call(t,"traceWithException"))};var g={},T={};T.__esModule=!0,T.generateHexIp=function(t){var e=function(t){var e=0;return t.split(".").forEach((function(t,n){e+=Number(t)*(1<<8*(3-n))})),e}(t).toString(16);return e.length<8&&(e="0"+e),e},T.getRandomInt=function(t,e){return t=Math.ceil(t),(Math.random()*(Math.floor(e)-t)|0)+t},T.calSamplingValue=function(t){return 100*(255&t)/256},T.randomString=function(t){return t||(t=8),String.fromCharCode.apply(null,Array(t).fill(void 0).map((function(){var t=62*Math.random()|0;return t<10?t+48:t<36?t+55:t+61})))};var E=/^([a-z][a-z0-9.+-]*:)?([\\/]{1,})?([\S\s]*)/i;T.parseUrl=function(t){var e,n=E.exec(t)||[],r=n[1]?n[1].toLowerCase():"",o=n[2]&&1===n[2].length?"/"+n[3]:n[3],i={protocol:r,hash:"",search:"",pathname:"",host:"",port:"",hostname:""},a=-1;return-1!==(a=o.indexOf("#"))&&(i.hash=o.slice(a),o=o.slice(0,a)),-1!==(a=o.indexOf("?"))&&(i.search=o.slice(a),o=o.slice(0,a)),-1!==(a=o.indexOf("/"))&&(i.pathname=o.slice(a),o=o.slice(0,a)),-1!==(a=o.indexOf("@"))&&(o=o.slice(0,a)),i.host=o,(e=/:(\d+)$/.exec(o))&&(i.port=e[1],o=o.slice(0,e.index)),i.hostname=o,i},T.debounce=function(t,e,n){var r=null;return function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];r&&clearTimeout(r),r=setTimeout((function(){return t.apply(n,o)}),e)}},g.__esModule=!0;var _=T,m=function(){function t(t){var e=t.logger,n=t.interval;this.queue=[],this.logger=e,this.interval=n,this.delayFlush=_.debounce(this.flush,this.interval,this)}return t.prototype.getQueue=function(){return this.queue},t.prototype.add=function(t){var e;Array.isArray(t)?(e=this.queue).push.apply(e,t):this.queue.push(t)},t.prototype.clear=function(){this.queue.length=0},t.prototype.flush=function(){this.queue.length>0&&(this.logger.info(this.queue),this.queue.length=0)},t.prototype.intervalFlush=function(){var t=this;this.timer=setTimeout((function(){t.flush(),t.intervalFlush()}),this.interval)},t.prototype.clearInterval=function(){clearTimeout(this.timer)},t}();g.ReportQueue=m;var y={__esModule:!0},v=function(t){this.span=t};y.AbstractTagCollector=v;var I={__esModule:!0},S=function(t){this.appName=t};I.TraceIdGenerator=S;var R={__esModule:!0},C=function(t){this.sampleConfig=t};R.AbstractSampler=C;var N=e&&e.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e};n.__esModule=!0;var O=N(r),A=n.constants=O,b=o,x=n.Span=b.Span,w=a,M=n.LegacyHeaderCodec=w.LegacyHeaderCodec,L=u,H=n.CookieHeaderCodec=L.CookieHeaderCodec,D=d,P=n.TagEnum=D.TagEnum,B=n.LogEnum=D.LogEnum,Q=n.OperationTypeEnum=D.OperationTypeEnum,q=h,U=n.BaseTraceContext=q.BaseTraceContext,k=n.isTraceContext=q.isTraceContext,z=g,F=n.ReportQueue=z.ReportQueue,j=y,V=n.AbstractTagCollector=j.AbstractTagCollector,Y=I,G=n.TraceIdGenerator=Y.TraceIdGenerator,X=R,W=n.AbstractSampler=X.AbstractSampler,Z=T,J=n.getRandomInt=Z.getRandomInt,K=n.calSamplingValue=Z.calSamplingValue,$=n.generateHexIp=Z.generateHexIp,tt=n.randomString=Z.randomString,et=n.parseUrl=Z.parseUrl,nt=function(t,e){return nt=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},nt(t,e)};function rt(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}nt(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var ot=function(){return ot=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},ot.apply(this,arguments)};function it(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}u((r=r.apply(t,e||[])).next())}))}function at(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}var st="https://tj.youzan.com",ut=[/\/\/tj[0-9]?/,/\/\/probe\./,"skynet-web-agent.qa.qima-inc.com","fp.youzanyun.com"],ct=A.X_YZ_TEACE_HEADER,lt=A.HTTP_TRACE_HEADER;function pt(t){return ut.some((function(e){return function(t,e){return!(!t||!e)&&("[object RegExp]"===Object.prototype.toString.call(t)?t.test(e):"string"==typeof t&&"string"==typeof e&&-1!==e.indexOf(t))}(e,t)}))}function dt(t,e,n){if(t&&e in t){var r=t[e];t[e]=function(t,e){var n=e(t);if("function"==typeof n)try{n.prototype=n.prototype||{},Object.defineProperties(n,{__rontgen__:{enumerable:!1,value:!0},__rontgen_source__:{enumerable:!1,value:t}})}catch(t){console.error("[Rontgen] wrap function failed",t)}return n}(r,n)}}function ht(t,e,n){if(e>>=0,n=String(void 0!==n?n:""),t.length>e)return String(t);if((e-=t.length)>n.length)for(var r=n,o=e/n.length,i=0;i<o;i++)n+=r;return String(t)+n.slice(0,e)}function ft(){if("undefined"!=typeof performance&&"function"==typeof performance.now&&"number"==typeof performance.timeOrigin){var t=String(performance.now()+performance.timeOrigin),e=t.indexOf(".");return-1===e?t+"000000":t.substring(0,e)+ht(t.substring(e+1,e+4),6,"0")}return ht(String(Date.now()),19,"0")}function gt(t,e){return void 0===e&&(e=location.host),!(et(t).host||!t.startsWith("/"))||e===et(t).host}function Tt(){return _global&&_global.rontgen&&_global.rontgen.actionId}function Et(t){var e=t.getResponseHeader(ct);if(!e){var n=t.getResponseHeader(lt),r=H.decode(n);return(null==r?void 0:r.traceId)?r.traceId:null}return e.split(",")[0]}var _t=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return rt(e,t),e.prototype.resolveBegin=function(t){var e=t[0],n=t[1];this.span.addTag(P.HTTP_METHOD,e);var r=et(n),o=r.hostname,i=r.pathname;this.span.setOperation(Q.FRONT,i),this.span.addTag(P.HTTP_HOST,o||location.hostname),this.span.addTag(P.HTTP_URL_PATTERN,i),this.span.addLog(B.HTTP_URL,n),this.span.addLog("extra_data",location.href);var a=Tt();a&&this.span.addTag(P.ACTION_ID,a)},e.prototype.resolveFinish=function(t){var e;this.span.addTag(P.HTTP_CODE,String(t.status));var n=Et(t);n&&(null===(e=this.span)||void 0===e||e.setTraceId(n))},e}(V),mt=function(t){function e(e){var n=t.call(this,e)||this;return n.collector=new _t(n),n.tags=[[P.ERROR,"false"],[P.SEGMENT_ID,n.spanId],[P.SEGMENT,"true"]],n}return rt(e,t),e.prototype.setTraceId=function(t){this.traceId=t,this.spanId=t,this.setTagVal(P.SEGMENT_ID,t)},e.prototype.isFinished=function(){return this.finished},e.prototype.begin=function(){void 0===this.startTimeNano&&(this.startTimeNano=ft())},e.prototype.finish=function(){var t,e;this.finished||(this.finished=!0,this.durationNano=(t=ft(),e=this.startTimeNano,"function"==typeof BigInt?Number(BigInt(t)-BigInt(e)):1e3*(+t.slice(0,-3)-+e.slice(0,-3))))},e.prototype.resolveBegin=function(t){this.begin(),this.collector.resolveBegin(t)},e.prototype.resolveFinish=function(t){this.finish(),this.collector.resolveFinish(t)},e.prototype.equal=function(t){return this===t||this.spanId===t.spanId&&this.operationType===t.operationType&&this.operationName===t.operationName},e}(x),yt=function(){function t(t){this.request=t}return t.prototype.getUrl=function(){return"/api/rontgen/spans"},t.prototype.info=function(t){var e="["+t.map((function(t){return t.toString()})).join(",")+"]";try{JSON.parse(e),this.request({url:this.getUrl(),method:"POST",data:e})}catch(t){console.warn("[rontgen] illegal Span data",t)}},t}(),vt=function(t){function e(e){var n=e.parentId,r=e.traceId,o=e.appName,i=e.request,a=e.strategy,s=e.reportInterval,u=e.maxQueueSize,c=t.call(this,{parentId:n,traceId:r,appName:o})||this;return c.traceWithException=!1,c.spanQueue=[],c.maxQueueSize=u,c.logger=new yt(i),c.queue=new F({logger:c.logger,interval:s}),c.strategy=a,"interval"===a&&c.queue.intervalFlush(),c}return rt(e,t),e.prototype.createSegment=function(){var t=new mt({spanId:"null",parentId:"null",appName:this.appName});return this.enqueue(t),t},e.prototype.getFinishSpan=function(){return this.spanQueue.filter((function(t){return t.isFinished()}))},e.prototype.getUnflushSpans=function(){return[].concat(this.queue.getQueue(),this.getFinishSpan())},e.prototype.flush=function(){var t=this.getFinishSpan();this.spanQueue=this.spanQueue.filter((function(t){return!t.isFinished()}));var e=t.filter((function(t){return"null"!==t.traceId}));this.queue.add(e),"delay"===this.strategy&&this.queue.delayFlush(),this.queue.getQueue().length>this.maxQueueSize&&this.queue.flush()},e.prototype.forceFlush=function(){var t=this.getFinishSpan().filter((function(t){return"null"!==t.traceId}));this.queue.add(t),this.queue.flush()},e.prototype.shouldSample=function(){return!1},e.prototype.removeSpan=function(t){this.spanQueue=this.spanQueue.filter((function(e){return!e.equal(t)}))},e}(U),It=function(){function t(t,e){void 0===t&&(t={}),this.containerElm=null,this.pageWidth=0,this.dpr=window.devicePixelRatio,this.traceQueue=[],this.actionId="";var n=t.style,r=void 0===n?{mobile:{},pc:{}}:n;this.request=e,this.options=ot(ot({maxLength:10,containerElmId:"yzTraceWaterMarkContainer",autoRemove:0},t),{style:ot(ot({opacity:.01,letterSpacing:4,colors:["rgb(142,142,142)","rgb(255,255,0)","rgb(255,0,255,.7)","rgb(0,255,255)"]},r),{mobile:ot({marginBottom:10,marginRight:10,fontSize:20},r.mobile),pc:ot({marginBottom:10,marginRight:10,fontSize:30},r.pc)})})}return t.prototype.clear=function(){this.containerElm&&document.body.removeChild(this.containerElm),this.containerElm=null,this.context=null,this.traceQueue=[]},t.prototype.add=function(t){return it(this,void 0,void 0,(function(){var e,n;return at(this,(function(r){switch(r.label){case 0:return t.traceId?this.actionId?[3,2]:(e=this,[4,this.toShortTraceId(Tt())]):[2];case 1:e.actionId=r.sent(),r.label=2;case 2:return[4,this.toShortTraceId(t.traceId)];case 3:return(n=r.sent())&&(this.traceQueue.push({traceId:n}),this.traceQueue.splice(0,this.traceQueue.length-this.options.maxLength)),this.draw(),[2]}}))}))},t.prototype.toShortTraceId=function(t){return it(this,void 0,void 0,(function(){return at(this,(function(e){return t?[2,this.request({url:"/api/rontgen/shortTraceId?traceId="+t,method:"GET"})]:[2]}))}))},t.prototype.format=function(t,e){return"#"+(e+1)+"_"+t.traceId},t.prototype.makeContainer=function(){if(window&&document&&!document.getElementById(this.options.containerElmId)){var t=this.options.style,e=document.createElement("canvas");e.id=this.options.containerElmId,e.style.cssText="\n position: fixed;\n width: 100%;\n height: 100%;\n left: 0;\n right: 0;\n top: 0;\n bottom: 0;\n pointer-events: none;\n z-index: 99999;\n opacity: "+t.opacity+";\n letter-spacing: "+t.letterSpacing+"px;\n ",this.context=e.getContext("2d"),document.body.appendChild(e);var n=e.offsetHeight,r=e.offsetWidth;this.pageWidth=r,e.width=this.calc(r),e.height=this.calc(n),this.containerElm=e}},t.prototype.getStyle=function(){var t=this.options.style;return this.pageWidth>1e3?t.pc:t.mobile},t.prototype.calc=function(t){return t*this.dpr},t.prototype.draw=function(){var t=this;if(this.traceQueue.length){this.context||this.makeContainer();var e=this,n=e.context,r=e.options,o=r.style,i=r.autoRemove,a=e.traceQueue,s=void 0===a?[]:a;if(n){var u=n.canvas.getBoundingClientRect(),c=u.width,l=u.height;n.clearRect(0,0,this.calc(c),this.calc(l)),n.font="bold "+this.calc(this.getStyle().fontSize)+"px monospace";for(var p=0,d=this.calc(this.getStyle().fontSize),h=!1,f=function(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;var r=Array(t),o=0;for(e=0;e<n;e++)for(var i=arguments[e],a=0,s=i.length;a<s;a++,o++)r[o]=i[a];return r}([{traceId:this.actionId}],s);!h;)for(var g=0,T=f.length;g<T;g++)for(var E=this.format(f[g],g),_=n.measureText(E).width,m=0,y=o.colors.length;m<y;m++){var v=o.colors[m];if(p+_>this.calc(c)&&(p=0,d+=this.calc(this.getStyle().fontSize+this.getStyle().marginBottom)),d>this.calc(l)){h=!0;break}n.fillStyle=v,n.fillText(E,p,d),p+=Math.ceil(_)+this.calc(this.getStyle().marginRight)}i&&(clearTimeout(this.timer),this.timer=window.setTimeout((function(){return t.clear()}),i))}}},t}(),St=A.HTTP_TRACE_HEADER,Rt=A.SAMPLE_MARK,Ct=A.X_YZ_ACTION_ID_HEADER;function Nt(){}var Ot=function(){function t(t){var e,n=(e=t.loggerUrl||st,function(t){var n=t.url,r=t.method,o=t.data,i=t.headers;return new Promise((function(t){var a=new XMLHttpRequest;a.open(r,e+n,!0),a.timeout=1e4,a.setRequestHeader("Content-Type","application/json; charset=utf-8"),i&&Object.keys(i).forEach((function(t){a.setRequestHeader(t,i[t])})),a.ontimeout=function(e){console.warn("Timeout of 10000 ms exceeded",e),t()},a.onerror=function(e){console.warn("Network Error",e),t()},a.onreadystatechange=function(){4===a.readyState&&t(200===a.status?a.response:void 0)},a.send(o)}))});this.options={appName:t.appName||"unkown-app",request:n,collector:t.collector||Nt,strategy:t.strategy||"delay",reportInterval:t.reportInterval||1e3,maxQueueSize:t.maxQueueSize||10,successCodes:t.successCodes||[0,200],successTextCodes:t.successCodes?t.successCodes.map((function(t){return'"code":'+t+","})):['"code":0,','"code":200,']},t.isResponseFailed&&(this.options.isResponseFailed=t.isResponseFailed),this.waterMark=new It(t.watermark,n)}return t.init=function(e){return this.instance||(this.instance=new t(e),this.instance.interceptXhr(),this.instance.updateSpanBeforeUnload(e.loggerUrl||st)),this.instance},t.setOptions=function(t){if(!this.instance)throw new Error("should call RontgenBrowser#init() first.");t.collector&&(this.instance.options.collector=t.collector),t.isResponseFailed&&(this.instance.options.isResponseFailed=t.isResponseFailed),t.successCodes&&(this.instance.options.successCodes=t.successCodes,this.instance.options.successTextCodes=t.successCodes.map((function(t){return'"code":'+t+","})))},t.prototype.interceptXhr=function(){if("XMLHttpRequest"in window){var t=this.options,e=t.appName,n=t.request,r=t.reportInterval,o=t.strategy,i=t.maxQueueSize,a=new vt({parentId:"null",traceId:"null",appName:e,request:n,strategy:o,reportInterval:r,maxQueueSize:i});this.traceContext=a;var s=this;dt(window.XMLHttpRequest.prototype,"open",(function(t){return function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];e[0];var r,o=e[1],i=this;try{(r=a.createSegment()).resolveBegin(e);var u=function(t,e){r.setTagVal(t,e)};s.options.collector&&s.options.collector(e,u)}catch(t){console.error("[Rontgen] collect tags failed before request",t)}function c(){if(4===i.readyState)try{if(pt(o))return a.removeSpan(r);r.resolveFinish(i);var t=!1,e=Et(i);if(200===i.status){var n=s.options,u=n.isResponseFailed,c=n.successCodes,l=n.successTextCodes;if("json"===i.responseType){var p=i.response;p&&"object"==typeof p&&("code"in p&&!c.includes(+p.code)||"data"in p&&p.data&&"object"==typeof p.data&&"code"in p.data&&0!=+p.data.code&&200!=+p.data.code||u&&"function"==typeof u&&u(o,p))&&(t=!0,null==r||r.markError(p),s.waterMark.add({traceId:e}))}if(""===i.responseType||"text"===i.responseType){var d=i.responseText;("{"===d[0]&&l.every((function(t){return!d.includes(t)}))||u&&"function"==typeof u&&u(o,d))&&(t=!0,null==r||r.markError(d),s.waterMark.add({traceId:e}))}}else i.status>=400&&("json"===i.responseType?(r.markError(i.response),s.waterMark.add({traceId:e})):""!==i.responseType&&"text"!==i.responseType||(r.markError(i.responseText),s.waterMark.add({traceId:e})));var h=i.getResponseHeader(St);t||(null==h?void 0:h.includes(Rt))?a.flush():a.removeSpan(r)}catch(t){console.error("[Rontgen] collect tags failed after request finish",t)}}"onreadystatechange"in i&&"function"==typeof i.onreadystatechange?dt(i,"onreadystatechange",(function(t){return function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return c(),t.apply(i,e)}})):i.addEventListener("readystatechange",c);var l=t.apply(i,e);try{var p=Tt();gt(e[1])&&p&&i.setRequestHeader(Ct,p)}catch(t){console.error("[Rontgen] can't set actionId to header",t)}return l}}))}},t.prototype.updateSpanBeforeUnload=function(t){var e=this.traceContext;window.addEventListener("unload",(function(){var n=null==e?void 0:e.getUnflushSpans();if(n&&n.length>0){var r="["+n.map((function(t){return t.toString()})).join(",")+"]";navigator.sendBeacon&&navigator.sendBeacon(t+"/api/rontgen/spans",r)}}))},t}();t.AbstractSampler=W,t.AbstractTagCollector=V,t.BaseTraceContext=U,t.CookieHeaderCodec=H,t.LegacyHeaderCodec=M,t.LogEnum=B,t.OperationTypeEnum=Q,t.ReportQueue=F,t.RontgenBrowser=Ot,t.Span=x,t.TagEnum=P,t.TraceIdGenerator=G,t.__moduleExports=n,t.calSamplingValue=K,t.constants=A,t.generateHexIp=$,t.getActId=Tt,t.getActionId=Tt,t.getRandomInt=J,t.isTraceContext=k,t.parseUrl=et,t.randomString=tt,Object.defineProperty(t,"__esModule",{value:!0})}));