@elastic/apm-rum
Version:
Elastic APM JavaScript agent
2 lines • 54.2 kB
JavaScript
/*! For license information please see elastic-apm-rum.umd.min.js.LICENSE */
!function(n){var r={};function i(t){if(r[t])return r[t].exports;var e=r[t]={i:t,l:!1,exports:{}};return n[t].call(e.exports,e,e.exports,i),e.l=!0,e.exports}i.m=n,i.c=r,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)i.d(n,r,function(t){return e[t]}.bind(null,r));return n},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=5)}([function(t,e,n){t.exports=function(){"use strict";function c(t){return"function"==typeof t}var n=Array.isArray?Array.isArray:function(t){return"[object Array]"===Object.prototype.toString.call(t)},r=0,e=void 0,i=void 0,s=function(t,e){h[r]=t,h[r+1]=e,2===(r+=2)&&(i?i(v):y())},t="undefined"!=typeof window?window:void 0,o=t||{},a=o.MutationObserver||o.WebKitMutationObserver,u="undefined"==typeof self&&"undefined"!=typeof process&&"[object process]"==={}.toString.call(process),f="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel;function d(){var t=setTimeout;return function(){return t(v,1)}}var h=new Array(1e3);function v(){for(var t=0;t<r;t+=2){var e=h[t],n=h[t+1];e(n),h[t]=void 0,h[t+1]=void 0}r=0}var l,p,g,m,y=void 0;function _(t,e){var n=this,r=new this.constructor(w);void 0===r[b]&&M(r);var i=n._state;if(i){var o=arguments[i-1];s(function(){return F(i,r,o,n._result)})}else j(n,r,t,e);return r}function S(t){if(t&&"object"==typeof t&&t.constructor===this)return t;var e=new this(w);return k(e,t),e}y=u?function(){return process.nextTick(v)}:a?(p=0,g=new a(v),m=document.createTextNode(""),g.observe(m,{characterData:!0}),function(){m.data=p=++p%2}):f?((l=new MessageChannel).port1.onmessage=v,function(){return l.port2.postMessage(0)}):void 0===t?function(){try{var t=Function("return this")().require("vertx");return void 0===(e=t.runOnLoop||t.runOnContext)?d():function(){e(v)}}catch(t){return d()}}():d();var b=Math.random().toString(36).substring(2);function w(){}var T=void 0,E=1,x=2;function C(t,e,n,r){try{t.call(e,n,r)}catch(t){return t}}function L(t,e,n){var r,i,o,a;e.constructor===t.constructor&&n===_&&e.constructor.resolve===S?(o=t,(a=e)._state===E?I(o,a._result):a._state===x?N(o,a._result):j(a,void 0,function(t){return k(o,t)},function(t){return N(o,t)})):void 0===n?I(t,e):c(n)?(r=e,i=n,s(function(e){var n=!1,t=C(i,r,function(t){n||(n=!0,r!==t?k(e,t):I(e,t))},function(t){n||(n=!0,N(e,t))},e._label);!n&&t&&(n=!0,N(e,t))},t)):I(t,e)}function k(e,t){if(e===t)N(e,new TypeError("You cannot resolve a promise with itself"));else if(i=typeof(r=t),null===r||"object"!==i&&"function"!==i)I(e,t);else{var n=void 0;try{n=t.then}catch(t){return void N(e,t)}L(e,t,n)}var r,i}function O(t){t._onerror&&t._onerror(t._result),A(t)}function I(t,e){t._state===T&&(t._result=e,t._state=E,0!==t._subscribers.length&&s(A,t))}function N(t,e){t._state===T&&(t._state=x,t._result=e,s(O,t))}function j(t,e,n,r){var i=t._subscribers,o=i.length;t._onerror=null,i[o]=e,i[o+E]=n,i[o+x]=r,0===o&&t._state&&s(A,t)}function A(t){var e=t._subscribers,n=t._state;if(0!==e.length){for(var r=void 0,i=void 0,o=t._result,a=0;a<e.length;a+=3)r=e[a],i=e[a+n],r?F(n,r,i,o):i(o);t._subscribers.length=0}}function F(t,e,n,r){var i=c(n),o=void 0,a=void 0,s=!0;if(i){try{o=n(r)}catch(t){s=!1,a=t}if(e===o)return void N(e,new TypeError("A promises callback cannot return that same promise."))}else o=r;e._state!==T||(i&&s?k(e,o):!1===s?N(e,a):t===E?I(e,o):t===x&&N(e,o))}var R=0;function M(t){t[b]=R++,t._state=void 0,t._result=void 0,t._subscribers=[]}var P=function(){function t(t,e){this._instanceConstructor=t,this.promise=new t(w),this.promise[b]||M(this.promise),n(e)?(this.length=e.length,this._remaining=e.length,this._result=new Array(this.length),0===this.length?I(this.promise,this._result):(this.length=this.length||0,this._enumerate(e),0===this._remaining&&I(this.promise,this._result))):N(this.promise,new Error("Array Methods must be provided an Array"))}return t.prototype._enumerate=function(t){for(var e=0;this._state===T&&e<t.length;e++)this._eachEntry(t[e],e)},t.prototype._eachEntry=function(e,t){var n=this._instanceConstructor,r=n.resolve;if(r===S){var i=void 0,o=void 0,a=!1;try{i=e.then}catch(t){a=!0,o=t}if(i===_&&e._state!==T)this._settledAt(e._state,t,e._result);else if("function"!=typeof i)this._remaining--,this._result[t]=e;else if(n===q){var s=new n(w);a?N(s,o):L(s,e,i),this._willSettleAt(s,t)}else this._willSettleAt(new n(function(t){return t(e)}),t)}else this._willSettleAt(r(e),t)},t.prototype._settledAt=function(t,e,n){var r=this.promise;r._state===T&&(this._remaining--,t===x?N(r,n):this._result[e]=n),0===this._remaining&&I(r,this._result)},t.prototype._willSettleAt=function(t,e){var n=this;j(t,void 0,function(t){return n._settledAt(E,e,t)},function(t){return n._settledAt(x,e,t)})},t}(),q=function(){function e(t){this[b]=R++,this._result=this._state=void 0,this._subscribers=[],w!==t&&("function"!=typeof t&&function(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}(),this instanceof e?function(e,t){try{t(function(t){k(e,t)},function(t){N(e,t)})}catch(t){N(e,t)}}(this,t):function(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}())}return e.prototype.catch=function(t){return this.then(null,t)},e.prototype.finally=function(e){var n=this.constructor;return c(e)?this.then(function(t){return n.resolve(e()).then(function(){return t})},function(t){return n.resolve(e()).then(function(){throw t})}):this.then(e,e)},e}();return q.prototype.then=_,q.all=function(t){return new P(this,t).promise},q.race=function(i){var o=this;return n(i)?new o(function(t,e){for(var n=i.length,r=0;r<n;r++)o.resolve(i[r]).then(t,e)}):new o(function(t,e){return e(new TypeError("You must pass an array to race."))})},q.resolve=S,q.reject=function(t){var e=new this(w);return N(e,t),e},q._setScheduler=function(t){i=t},q._setAsap=function(t){s=t},q._asap=s,q.polyfill=function(){var t=void 0;if("undefined"!=typeof global)t=global;else if("undefined"!=typeof self)t=self;else try{t=Function("return this")()}catch(t){throw new Error("polyfill failed because global object is unavailable in this environment")}var e=t.Promise;if(e){var n=null;try{n=Object.prototype.toString.call(e.resolve())}catch(t){}if("[object Promise]"===n&&!e.cast)return}t.Promise=q},q.Promise=q}()},function(t,e){var n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(n){var r=new Uint8Array(16);t.exports=function(){return n(r),r}}else{var i=new Array(16);t.exports=function(){for(var t,e=0;e<16;e++)0==(3&e)&&(t=4294967296*Math.random()),i[e]=t>>>((3&e)<<3)&255;return i}}},function(n,r,i){var o,a,s;!function(t,e){"use strict";a=[i(4)],void 0===(s="function"==typeof(o=function(s){var n=/(^|@)\S+\:\d+/,r=/^\s*at .*(\S+\:\d+|\(native\))/m,i=/^(eval@)?(\[native code\])?$/;function o(t,e,n){if("function"==typeof Array.prototype.map)return t.map(e,n);for(var r=new Array(t.length),i=0;i<t.length;i++)r[i]=e.call(n,t[i]);return r}function a(t,e,n){if("function"==typeof Array.prototype.filter)return t.filter(e,n);for(var r=[],i=0;i<t.length;i++)e.call(n,t[i])&&r.push(t[i]);return r}return{parse:function(t){if(void 0!==t.stacktrace||void 0!==t["opera#sourceloc"])return this.parseOpera(t);if(t.stack&&t.stack.match(r))return this.parseV8OrIE(t);if(t.stack)return this.parseFFOrSafari(t);throw new Error("Cannot parse given Error object")},extractLocation:function(t){if(-1===t.indexOf(":"))return[t];var e=/(.+?)(?:\:(\d+))?(?:\:(\d+))?$/.exec(t.replace(/[\(\)]/g,""));return[e[1],e[2]||void 0,e[3]||void 0]},parseV8OrIE:function(t){var e=a(t.stack.split("\n"),function(t){return!!t.match(r)},this);return o(e,function(t){-1<t.indexOf("(eval ")&&(t=t.replace(/eval code/g,"eval").replace(/(\(eval at [^\()]*)|(\)\,.*$)/g,""));var e=t.replace(/^\s+/,"").replace(/\(eval code/g,"(").split(/\s+/).slice(1),n=this.extractLocation(e.pop()),r=e.join(" ")||void 0,i=-1<function(t,e){{if("function"==typeof Array.prototype.indexOf)return t.indexOf(e);for(var n=0;n<t.length;n++)if(t[n]===e)return n;return-1}}(["eval","<anonymous>"],n[0])?void 0:n[0];return new s(r,void 0,i,n[1],n[2],t)},this)},parseFFOrSafari:function(t){var e=a(t.stack.split("\n"),function(t){return!t.match(i)},this);return o(e,function(t){if(-1<t.indexOf(" > eval")&&(t=t.replace(/ line (\d+)(?: > eval line \d+)* > eval\:\d+\:\d+/g,":$1")),-1===t.indexOf("@")&&-1===t.indexOf(":"))return new s(t);var e=t.split("@"),n=this.extractLocation(e.pop()),r=e.join("@")||void 0;return new s(r,void 0,n[0],n[1],n[2],t)},this)},parseOpera:function(t){return!t.stacktrace||-1<t.message.indexOf("\n")&&t.message.split("\n").length>t.stacktrace.split("\n").length?this.parseOpera9(t):t.stack?this.parseOpera11(t):this.parseOpera10(t)},parseOpera9:function(t){for(var e=/Line (\d+).*script (?:in )?(\S+)/i,n=t.message.split("\n"),r=[],i=2,o=n.length;i<o;i+=2){var a=e.exec(n[i]);a&&r.push(new s(void 0,void 0,a[2],a[1],void 0,n[i]))}return r},parseOpera10:function(t){for(var e=/Line (\d+).*script (?:in )?(\S+)(?:: In function (\S+))?$/i,n=t.stacktrace.split("\n"),r=[],i=0,o=n.length;i<o;i+=2){var a=e.exec(n[i]);a&&r.push(new s(a[3]||void 0,void 0,a[2],a[1],void 0,n[i]))}return r},parseOpera11:function(t){var e=a(t.stack.split("\n"),function(t){return!!t.match(n)&&!t.match(/^Error created at/)},this);return o(e,function(t){var e,n=t.split("@"),r=this.extractLocation(n.pop()),i=n.shift()||"",o=i.replace(/<anonymous function(: (\w+))?>/,"$2").replace(/\([^\)]*\)/g,"")||void 0;i.match(/\(([^\)]*)\)/)&&(e=i.replace(/^[^\(]+\(([^\)]*)\)$/,"$1"));var a=void 0===e||"[arguments not available]"===e?void 0:e.split(",");return new s(o,a,r[0],r[1],r[2],t)},this)}}})?o.apply(r,a):o)||(n.exports=s)}()},,function(n,r,t){var i,o,a;!function(t,e){"use strict";o=[],void 0===(a="function"==typeof(i=function(){function e(t){return!isNaN(parseFloat(t))&&isFinite(t)}function t(t,e,n,r,i,o){void 0!==t&&this.setFunctionName(t),void 0!==e&&this.setArgs(e),void 0!==n&&this.setFileName(n),void 0!==r&&this.setLineNumber(r),void 0!==i&&this.setColumnNumber(i),void 0!==o&&this.setSource(o)}return t.prototype={getFunctionName:function(){return this.functionName},setFunctionName:function(t){this.functionName=String(t)},getArgs:function(){return this.args},setArgs:function(t){if("[object Array]"!==Object.prototype.toString.call(t))throw new TypeError("Args must be an Array");this.args=t},getFileName:function(){return this.fileName},setFileName:function(t){this.fileName=String(t)},getLineNumber:function(){return this.lineNumber},setLineNumber:function(t){if(!e(t))throw new TypeError("Line Number must be a Number");this.lineNumber=Number(t)},getColumnNumber:function(){return this.columnNumber},setColumnNumber:function(t){if(!e(t))throw new TypeError("Column Number must be a Number");this.columnNumber=Number(t)},getSource:function(){return this.source},setSource:function(t){this.source=String(t)},toString:function(){return(this.getFunctionName()||"{anonymous}")+"("+(this.getArgs()||[]).join(",")+")"+(this.getFileName()?"@"+this.getFileName():"")+(e(this.getLineNumber())?":"+this.getLineNumber():"")+(e(this.getColumnNumber())?":"+this.getColumnNumber():"")}},t})?i.apply(r,o):i)||(n.exports=a)}()},function(t,e,n){"use strict";n.r(e);var r=n(1),o=n.n(r),i=[].slice;for(var a=[],s=0;s<256;++s)a[s]=(s+256).toString(16).substr(1);function c(t){if(t&&t.traceId&&t.id&&t.parentId){var e=t.sampled?"01":"00",n=t.sampled?t.id:t.parentId;return"00-"+t.traceId+"-"+n+"-"+e}}function v(e,t){var n=!1;return"string"==typeof t?n=e===t:Array.isArray(t)&&t.forEach(function(t){n||(n=v(e,t))}),n}function l(t){var e,n,r,i;return(e=o()(),r=n||0,[(i=a)[e[r++]],i[e[r++]],i[e[r++]],i[e[r++]],i[e[r++]],i[e[r++]],i[e[r++]],i[e[r++]],i[e[r++]],i[e[r++]],i[e[r++]],i[e[r++]],i[e[r++]],i[e[r++]],i[e[r++]],i[e[r++]]].join("")).substr(0,t)}function u(){return"undefined"!=typeof window&&"function"==typeof Array.prototype.forEach&&"function"==typeof JSON.stringify&&"function"==typeof Function.bind&&window.performance&&"function"==typeof window.performance.now&&"withCredentials"in new window.XMLHttpRequest}function f(t,e,n){if(n&&t){var r=T(t);return e&&(e=String(e)),n[r]=e,n}}var d=["fetchStart","domainLookupStart","domainLookupEnd","connectStart","connectEnd","secureConnectionStart","requestStart","responseStart","responseEnd","domLoading","domInteractive","domContentLoadedEventStart","domContentLoadedEventEnd","domComplete","loadEventStart","loadEventEnd"];function p(){return{page:{referer:document.referrer,url:window.location.href}}}function g(t){return t&&t.split("?")[0]}function h(t){return null!==t&&"object"==typeof t}function m(t,e,n){for(var r=0,i=e.length;r<i;++r){var o=e[r];if(h(o)||"function"==typeof o)for(var a=Object.keys(o),s=0,c=a.length;s<c;s++){var u=a[s],f=o[u];n&&h(f)?(h(t[u])||(t[u]=Array.isArray(f)?[]:{}),m(t[u],[f],!1)):t[u]=f}}return t}function y(){if("undefined"!=typeof document){var t=document.currentScript;return t||function(){if("undefined"!=typeof document)for(var t=document.getElementsByTagName("script"),e=0,n=t.length;e<n;e++){var r=t[e];if(0<r.src.indexOf("elastic"))return r}}()}}function _(t){return m(t,i.call(arguments,1),!1)}function S(t){return m(t,i.call(arguments,1),!0)}function b(t){return void 0===t}function w(){}function T(t){return t.replace(/[.*"]/g,"_")}function E(){var n,r,i,t=(n=window.performance.timing,r=n.fetchStart,i={},d.forEach(function(t){var e=n[t];e&&r<=e&&(i[t]=e-r)}),i),e=function(){var t={},e=window.performance;if("function"==typeof e.getEntriesByType){var n=e.getEntriesByType("paint");if(0<n.length)for(var r=e.timing,i=r.fetchStart-r.navigationStart,o=0;o<n.length;o++){var a=n[o],s=0<=i?a.startTime-i:a.startTime;t[a.name]=s}}return t}(),o={timeToFirstByte:t.responseStart,domInteractive:t.domInteractive,domComplete:t.domComplete};return e["first-contentful-paint"]&&(o.firstContentfulPaint=e["first-contentful-paint"]),{navigationTiming:t,agent:o}}function x(){return window.performance.now()}function C(t,e){return b(e)||b(t)?null:parseFloat(e-t)}var L={fetchInProgress:!1};function k(t){return"__apm_symbol__"+t}function O(t,e,n){for(var r=t;r&&!r.hasOwnProperty(e);)r=Object.getPrototypeOf(r);!r&&t[e]&&(r=t);var i,o,a,s,c=k(e);if(r&&!(i=r[c])){i=r[c]=r[e];var u=r&&Object.getOwnPropertyDescriptor(r,e);if(!(s=u)||!1!==s.writable&&("function"!=typeof s.get||void 0!==s.set)){var f=n(i,c,e);r[e]=function(){return f(this,arguments)},o=r[e],a=i,o[k("OriginalDelegate")]=a}}return i}var I=k("xhrIgnore"),N=k("xhrSync"),j=k("xhrURL"),A=k("xhrMethod"),F="schedule",R="invoke",M="clear",P="addEventListener",q="removeEventListener",D=["link","css","script","img","xmlhttprequest","fetch","beacon","iframe"],H=3e5,B="page-load",Q="Unknown",U=60,z=1024,$="transaction:end",V="config:change",X="xmlhttprequest",J="fetch",Y="history",Z=k("xhrTask"),G=k("xhrListener"),K=k("xhrScheduled");function W(a){var t=XMLHttpRequest.prototype,s=t[P],c=t[q];if(!s){var e=window.XMLHttpRequestEventTarget;if(e){var n=e.prototype;s=n[P],c=n[q]}}var u="readystatechange";function f(t){t.state=R,t.ignore||a(R,t)}var r=O(t,"open",function(){return function(t,e){return t[A]=e[0],t[j]=e[1],t[N]=!1===e[2],r.apply(t,e)}}),d=O(t,"send",function(){return function(t,e){var n={source:X,state:"",type:"macroTask",ignore:t[I],data:{target:t,method:t[A],sync:t[N],url:t[j],args:e,aborted:!1}},r=function(t){XMLHttpRequest[K]=!1,t.state=F,t.ignore||a(F,t);var e=t.data,n=e.target,r=n[G];s||(s=n[P],c=n[q]),r&&c.call(n,u,r);var i=n[G]=function(){n.readyState===n.DONE&&!e.aborted&&XMLHttpRequest[K]&&t.state===F&&f(t)};s.call(n,u,i),n[Z]||(n[Z]=t);var o=d.apply(n,e.args);return XMLHttpRequest[K]=!0,o}(n);return t[N]&&f(n),r}}),i=O(t,"abort",function(){return function(t,e){var n,r=t[Z];if(r&&"string"==typeof r.type){if(r.data&&r.data.aborted)return;(n=r).state=M,a(M,n),n.data.aborted=!0}return i.apply(t,e)}})}var tt=n(0);function et(s){if(window.fetch&&window.Request){var c=window.fetch;window.fetch=function(t,e){var i,n,o=this,r=arguments;if("string"==typeof t)i=new Request(t,e),n=t;else{if(!t)return c.apply(o,r);n=(i=t).url}var a={source:J,state:"",type:"macroTask",data:{target:i,method:i.method,sync:!1,url:n,args:r,aborted:!1}};return new tt.Promise(function(e,n){var t,r;L.fetchInProgress=!0,(t=a).state=F,s(F,t);try{r=c.apply(o,[i])}catch(t){return n(t),a.data.error=t,u(a),void(L.fetchInProgress=!1)}r.then(function(t){e(t),tt.Promise.resolve().then(function(){a.data.response=t,u(a)})},function(t){n(t),tt.Promise.resolve().then(function(){a.data.error=t,u(a)})}),L.fetchInProgress=!1})}}function u(t){t.state=R,s(R,t)}}var nt=function(){function t(){this.observers={}}var e=t.prototype;return e.observe=function(e,n){var r=this;if("function"==typeof n)return this.observers[e]||(this.observers[e]=[]),this.observers[e].push(n),function(){var t=r.observers[e].indexOf(n);-1<t&&r.observers[e].splice(t,1)}},e.sendOnly=function(t,e){var n=this.observers[t];n&&n.forEach(function(t){try{t.apply(void 0,e)}catch(t){console.log(t,t.stack)}})},e.send=function(t,e){this.sendOnly(t+":before",e),this.sendOnly(t,e),this.sendOnly(t+":after",e)},t}(),rt=new nt,it=!1;function ot(){return it||(it=!0,W(function(t,e){rt.send(X,[t,e])}),et(function(t,e){rt.send(J,[t,e])}),function(r){if(window.history){var i=history.pushState;"function"==typeof i&&(history.pushState=function(t,e,n){r(R,{source:Y,data:{state:t,title:e,url:n}}),i.apply(this,arguments)})}}(function(t,e){rt.send(Y,[t,e])})),rt}var at=!1,st=!1;var ct=n(2),ut=n.n(ct);function ft(t){var e=t.error,n=t.filename,r=t.lineno,i=t.colno,o=[];if(e)try{o=ut.a.parse(e)}catch(t){}return 0===o.length&&(o=[{fileName:n,lineNumber:r,columnNumber:i}]),o.map(function(t){return t.functionName&&(t.functionName=(e=t.functionName,e=1<(n=(e=(e=(e=1<(n=e.split("/")).length?["Object",n[n.length-1]].join("."):n[0]).replace(/.<$/gi,".<anonymous>")).replace(/^Anonymous function$/,"<anonymous>")).split(".")).length?n[n.length-1]:n[0])),t;var e,n}).map(function(t){var e=t.fileName,n=t.lineNumber,r=t.columnNumber,i=t.functionName,o=void 0===i?"<anonymous>":i;if(!e&&!n)return{};if(!r&&!n)return{};var a,s,c,u,f=(void 0===(a=e)&&(a=""),"<anonymous>"===a&&(a=""),a),d=(s=f,c=window.location.origin||window.location.protocol+"//"+window.location.hostname+(window.location.port?":"+window.location.port:""),-1<s.indexOf(c)&&(s=s.replace(c+"/","")),s);return(u=f)&&0===window.location.href.indexOf(u)&&(d="(inline script)"),{abs_path:e,filename:d,function:o,lineno:n,colno:r}})}var dt={service:{name:[z,!0],version:!0,agent:{version:[z,!0]},environment:!0}},ht={"*":!0,headers:{"*":!0}},vt={user:{id:!0,email:!0,username:!0},tags:{"*":!0},http:{response:ht},response:ht},lt={name:[z,!0],type:[z,!0],id:[z,!0],trace_id:[z,!0],parent_id:[z,!0],transaction_id:[z,!0],subtype:!0,action:!0,context:vt},pt={name:!0,parent_id:!0,type:[z,!0],id:[z,!0],trace_id:[z,!0],span_count:{started:[z,!0]},context:vt},gt={id:[z,!0],trace_id:!0,transaction_id:!0,parent_id:!0,culprit:!0,exception:{type:!0},transaction:{type:!0},context:vt};function mt(t){return null==t||""===t||void 0===t}function yt(t,e,n){var r,i,o,a,s=(r=t[e],i=n[0],o=n[1],void 0===i&&(i=z),void 0===o&&(o=!1),void 0===a&&(a="N/A"),o&&mt(r)&&(r=a),"string"==typeof r?r.substring(0,i):r);mt(s)?delete t[e]:t[e]=s}function _t(r,i,o){void 0===r&&(r={}),void 0===o&&(o=i);for(var a=Object.keys(r),s=[],t=function(t){var e=a[t],n=!0===r[e]?s:r[e];Array.isArray(n)?"*"===e?Object.keys(o).forEach(function(t){return yt(o,t,n)}):yt(o,e,n):_t(n,i,o[e])},e=0;e<a.length;e++)t(e);return i}var St=function(){function t(t,e,n){this._apmServer=t,this._configService=e,this._transactionService=n}var e=t.prototype;return e.createErrorDataModel=function(t){var e=ft(t),n=e.filter(function(t){var e=t.filename,n=t.lineno;return void 0!==e&&void 0!==n}),r="(inline script)",i=n[n.length-1];i&&i.filename&&(r=i.filename);var o=t.message,a=t.error,s=o,c="",u={};a&&"object"==typeof a&&(s=s||a.message,c=a.name,u=this._getErrorProperties(a)),c||s&&-1<s.indexOf(":")&&(c=s.split(":")[0]);var f=this._configService.get("context"),d=S({},p(),f,u),h={id:l(),culprit:r,exception:{message:s,stacktrace:n,type:c},context:d},v=this._transactionService.getCurrentTransaction();return v&&(h.trace_id=v.traceId,h.parent_id=v.id,h.transaction_id=v.id,h.transaction={type:v.type,sampled:v.sampled}),_t(gt,h)},e.logErrorEvent=function(t,e){if(void 0!==t){var n=this.createErrorDataModel(t);if(void 0!==n.exception.message)return e?this._apmServer.sendErrors([n]):this._apmServer.addError(n)}},e.registerListeners=function(){var e=this;window.addEventListener("error",function(t){return e.logErrorEvent(t)}),window.addEventListener("unhandledrejection",function(t){return e.logPromiseEvent(t)})},e.logPromiseEvent=function(t){var e="Unhandled promise rejection: ",n=t.reason;null==n?this.logError(e+"<no reason specified>"):"string"==typeof n.message?this.logError({message:e+n.message,stack:n.stack?n.stack:null}):"object"!=typeof n&&this.logError(e+n)},e.logError=function(t){var e={};return"string"==typeof t?e.message=t:e.error=t,this.logErrorEvent(e)},e._getErrorProperties=function(n){var r={};return Object.keys(n).forEach(function(t){if("stack"!==t){var e=n[t];if(null!==e){switch(typeof e){case"function":return;case"object":if("function"!=typeof e.toISOString)return;e=e.toISOString()}r[t]=e}}}),r},t}(),bt=function(r){r.registerServiceCreator("ErrorLogging",function(){var t=r.getService("ApmServer"),e=r.getService("ConfigService"),n=r.getService("TransactionService");return new St(t,e,n)})},wt=[["#","hash"],["?","query"],["/","path"],["@","auth",1],[NaN,"host",void 0,1]],Tt=/^([a-z][a-z0-9.+-]*:)?(\/\/)?([\S\s]*)/i,Et=function(){function t(t){var e,n=this.extractProtocol(t||""),r=n.protocol,i=n.address,o=n.slashes,a=!r&&!o,s=this.getLocation(),c=wt.slice();i=i.replace("\\","/"),o||(c[2]=[NaN,"path"]);for(var u=0;u<c.length;u++){var f=c[u],d=f[0],h=f[1];if("string"==typeof d){if(~(e=i.indexOf(d))){var v=f[2];if(v){var l=i.lastIndexOf(d);e=Math.max(e,l),this[h]=i.slice(0,e),i=i.slice(e+v)}else this[h]=i.slice(e),i=i.slice(0,e)}}else this[h]=i,i="";this[h]=this[h]||a&&f[3]&&s[h]||"",f[3]&&(this[h]=this[h].toLowerCase())}a&&"/"!==this.path.charAt(0)&&(this.path="/"+this.path),this.relative=a,this.protocol=r||s.protocol,this.origin=this.protocol&&this.host&&"file:"!==this.protocol?this.protocol+"//"+this.host:"null",this.href=this.toString()}var e=t.prototype;return e.toString=function(){var t=this.protocol;if(t+="//",this.auth){var e="[REDACTED]",n=this.auth.split(":");t+=(n[0]?e:"")+(n[1]?":"+e:"")+"@"}return t+=this.host,t+=this.path,t+=this.query,t+=this.hash},e.getLocation=function(){var t={};return"undefined"!=typeof window&&(t=window),t.location},e.extractProtocol=function(t){var e=Tt.exec(t);return{protocol:e[1]?e[1].toLowerCase():"",slashes:!!e[2],address:e[3]}},t}(),xt=function(){function t(t,e,n,r){this._apmServer=t,this._configService=e,this._logginService=n,this._transactionService=r}var e=t.prototype;return e.init=function(t){var n=this;void 0===t&&(t={}),this._configService.events.observe($+":after",function(t){var e=n.createTransactionPayload(t);e&&n._apmServer.addTransaction(e)}),t[Y]&&rt.observe(Y,this.getHistorySub()),t[X]&&rt.observe(X,this.getXHRSub()),t[J]&&rt.observe(J,this.getFetchSub())},e.getHistorySub=function(){var n=this._transactionService;return function(t,e){e.source===Y&&t===R&&n.startTransaction(e.data.title,"route-change",{managed:!0,canReuse:!0})}},e.getXHRSub=function(){var n=this;return function(t,e){e.source!==X||L.fetchInProgress||n.processAPICalls(t,e)}},e.getFetchSub=function(){var n=this;return function(t,e){e.source===J&&n.processAPICalls(t,e)}},e.processAPICalls=function(t,e){var n=this._configService,r=this._transactionService;if(t===F&&e.data){var i=new Et(e.data.url),o=e.data.method+" "+(i.relative?i.path:g(i.href)),a=r.startSpan(o,"external.http"),s=r.addTask();if(!a)return;var c=n.get("distributedTracing"),u=n.get("distributedTracingOrigins"),f=new Et(window.location.href),d=v(i.origin,f.origin)||v(i.origin,u),h=e.data.target;c&&d&&h&&this.injectDtHeader(a,h),a.addContext({http:{method:e.data.method,url:i.href}}),a.sync=e.data.sync,e.data.span=a,e.id=s}t===R&&e.data&&e.data.span&&(void 0!==e.data.target.status?e.data.span.addContext({http:{status_code:e.data.target.status}}):e.data.response&&e.data.span.addContext({http:{status_code:e.data.response.status}}),e.data.span.end()),t===R&&e.id&&r.removeTask(e.id)},e.injectDtHeader=function(t,e){var n,r=this._configService,i=r.get("distributedTracingHeaderName"),o=r.get("distributedTracingHeaderValueCallback")(t),a=/^[\da-f]{2}-[\da-f]{32}-[\da-f]{16}-[\da-f]{2}$/.test(n=o)&&"00000000000000000000000000000000"!==n.slice(3,35)&&"0000000000000000"!==n.slice(36,52);i&&o&&a&&("function"==typeof e.setRequestHeader?e.setRequestHeader(i,o):e.headers&&"function"==typeof e.headers.append?e.headers.append(i,o):e[i]=o)},e.extractDtHeader=function(t){var e=this._configService.get("distributedTracingHeaderName");if(t)return function(t){var e=/^([\da-f]{2})-([\da-f]{32})-([\da-f]{16})-([\da-f]{2})$/.exec(t);if(e){var n="00"!==e[4];return{traceId:e[2],id:e[3],sampled:n}}}(t[e])},e.setTransactionContext=function(t){var e=this._configService.get("context");e&&t.addContext(e)},e.filterTransaction=function(t){var e=this._configService.get("transactionDurationThreshold"),n=t.duration();if(!n)return!1;if(e<n)return!1;if(0===t.spans.length)return!1;t.sampled||t.resetSpans();var r=this._configService.get("browserResponsivenessInterval");if(this._configService.get("checkBrowserResponsiveness")&&t.options.checkBrowserResponsiveness){var i=this._configService.get("browserResponsivenessBuffer");if(!this.checkBrowserResponsiveness(t,r,i))return!1}return!0},e.adjustTransactionTime=function(t){var e=t.spans,n=function(t){for(var e=t[0],n=1;n<t.length;n++){var r=t[n];e._start>r._start&&(e=r)}return e}(e);n&&n._start<t._start&&(t._start=n._start);var r=function(t){for(var e=null,n=0;n<t.length;n++){var r=t[n];-1===String(r.type).indexOf("external")&&(!e||e._end<r._end)&&(e=r)}return e}(e);r&&r._end>t._end&&(t._end=r._end);for(var i=t._end,o=0;o<e.length;o++){var a=e[o];a._end>i&&(a._end=i,a.type+=".truncated"),a._start>i&&(a._start=i)}},e.prepareTransaction=function(e){if(e.spans.sort(function(t,e){return t._start-e._start}),this._configService.get("groupSimilarSpans")){var t=this._configService.get("similarSpanThreshold");e.spans=this.groupSmallContinuouslySimilarSpans(e,t)}e.spans=e.spans.filter(function(t){return 0<t.duration()&&t._start>=e._start&&t._end<=e._end}),this.setTransactionContext(e)},e.createTransactionDataModel=function(n){var t=this._configService.get("context"),r=n._start,e=n.spans.map(function(t){var e={id:t.id,transaction_id:n.id,parent_id:t.parentId||n.id,trace_id:n.traceId,name:t.name,type:t.type,subType:t.subType,action:t.action,sync:t.sync,start:t._start-r,duration:t.duration(),context:t.context};return _t(lt,e)}),i=S({},t,n.context),o={id:n.id,trace_id:n.traceId,name:n.name,type:n.type,duration:n.duration(),spans:e,context:i,marks:n.marks,breakdown:n.breakdownTimings,span_count:{started:e.length},sampled:n.sampled};return _t(pt,o)},e.createTransactionPayload=function(t){if(this.adjustTransactionTime(t),this.prepareTransaction(t),this.filterTransaction(t))return this.createTransactionDataModel(t)},e.convertTransactionsToServerModel=function(t){var e=this;return t.map(function(t){return e.createTransactionDataModel(t)})},e.groupSmallContinuouslySimilarSpans=function(o,a){var s=o.duration(),c=[],u=1;return o.spans.forEach(function(t,e){if(0===c.length)c.push(t);else{var n=c[c.length-1],r=n.type===t.type&&n.subType===t.subType&&n.action===t.action&&n.name===t.name&&t.duration()/s<a&&(t._start-n._end)/s<a,i=o.spans.length===e+1;r&&(u++,n._end=t._end),1<u&&(!r||i)&&(n.name=u+"x "+n.name,u=1),r||c.push(t)}}),c},e.checkBrowserResponsiveness=function(t,e,n){var r=t.browserResponsivenessCounter;if(void 0===e||void 0===r)return!0;var i=t.duration();return Math.floor(i/e)<=r+n},t}(),Ct=function(){function t(t,e,n){void 0===n&&(n={}),t||(t=Q),e||(e="custom"),this.name=t,this.type=e,this.options=n,this.id=n.id||l(16),this.traceId=n.traceId,this.sampled=n.sampled,this.timestamp=n.timestamp,this._start=x(),this._end=void 0,this.ended=!1,this.onEnd=n.onEnd}var e=t.prototype;return e.ensureContext=function(){this.context||(this.context={})},e.addTags=function(t){console.warn("addTags deprecated, please use addLabels"),this.addLabels(t)},e.addLabels=function(e){this.ensureContext();var n=this.context;n.tags||(n.tags={}),Object.keys(e).forEach(function(t){return f(t,e[t],n.tags)})},e.addContext=function(t){t&&(this.ensureContext(),S(this.context,t))},e.end=function(){this.ended||(this.ended=!0,this._end=x(),this.callOnEnd())},e.callOnEnd=function(){"function"==typeof this.onEnd&&this.onEnd(this)},e.duration=function(){return C(this._start,this._end)},t}();var Lt=function(o){var t,e;function n(t,e,n){var r;if((r=o.call(this,t,e,n)||this).parentId=r.options.parentId,r.subType=void 0,r.action=void 0,-1!==r.type.indexOf(".")){var i=r.type.split(".",3);r.type=i[0],r.subType=i[1],r.action=i[2]}return r.sync=r.options.sync,r}return e=o,(t=n).prototype=Object.create(e.prototype),(t.prototype.constructor=t).__proto__=e,n}(Ct),kt=[["fetchStart","responseEnd","Network"],["domLoading","domInteractive","DOM Processing"],["domInteractive","loadEventEnd","Page Render"]];function Ot(t){return{value:t}}function It(t,e){var n=e.details,r=e.count,i=void 0===r?1:r,o=e.duration;return{transaction:t,span:n,samples:{"span.self_time.count":Ot(i),"span.self_time.sum.us":Ot(o)}}}var Nt=function(i){var t,e;function n(t,e,n){var r;return(r=i.call(this,t,e,n)||this).traceId=l(),r.marks=void 0,r.spans=[],r._activeSpans={},r.nextAutoTaskId=1,r._scheduledTasks=[],r.captureTimings=!1,r.selfTime=null,r.breakdownTimings=[],r.childStart=0,r.childDuration=0,r.sampled=Math.random()<=r.options.transactionSampleRate,r}e=i,(t=n).prototype=Object.create(e.prototype),(t.prototype.constructor=t).__proto__=e;var r=n.prototype;return r.addMarks=function(t){this.marks=S(this.marks||{},t)},r.mark=function(t){var e=T(t),n=x()-this._start,r={};r[e]=n,this.addMarks({custom:r})},r.canReuse=function(t){return void 0===t&&(t=5e3),!!this.options.canReuse&&!this.ended&&x()-this._start<t},r.redefine=function(t,e,n){t&&(this.name=t),e&&(this.type=e),n&&(this.options=_(this.options,n))},r.startSpan=function(t,e,n){var r=this;if(!this.ended){var i=_({},n);i.onEnd=function(t){r._onSpanEnd(t)},i.traceId=this.traceId,i.sampled=this.sampled,i.parentId||(i.parentId=this.id);var o=new Lt(t,e,i);return this._activeSpans[o.id]=o,1===Object.keys(this._activeSpans).length&&(this.childStart=o._start),o}},r.isFinished=function(){return 0===this._scheduledTasks.length},r.detectFinish=function(){this.isFinished()&&this.end()},r.end=function(){if(!this.ended){for(var t in this.ended=!0,this._end=x(),this._activeSpans){var e=this._activeSpans[t];e.type=e.type+".truncated",e.end()}this.selfTime=this.duration()-this.childDuration;var n=p();this.addContext(n),this.callOnEnd()}},r.captureBreakdown=function(){this.breakdownTimings=function(t,e){void 0===e&&(e=window.performance.timing);var s=[],n=t.duration(),r=t.name,i=t.type,o=t.sampled,c={name:r,type:i};if(s.push({transaction:c,samples:{"transaction.duration.count":Ot(1),"transaction.duration.sum.us":Ot(n),"transaction.breakdown.count":Ot(o?1:0)}}),!o)return s;if(i===B&&e)for(var a=0;a<kt.length;a++){var u=kt[a],f=C(e[u[0]],e[u[1]]);0!==f&&null!=f&&s.push(It(c,{details:{type:u[2]},duration:f}))}else{var d=function(t){var e={},n=t.selfTime;e.app={count:1,duration:n};for(var r=t.spans,i=0;i<r.length;i++){var o=r[i],a=o.type,s=o.subType,c=o.duration();if(0!==c&&null!=c){var u=a;s&&(u+="."+s),e[u]||(e[u]={duration:0,count:0}),e[u].count++,e[u].duration+=c}}return e}(t);Object.keys(d).forEach(function(t){var e=t.split("."),n=e[0],r=e[1],i=d[t],o=i.duration,a=i.count;s.push(It(c,{details:{type:n,subtype:r},duration:o,count:a}))})}return s}(this)},r.addTask=function(t){if(void 0===t&&(t="task"+this.nextAutoTaskId++),-1==this._scheduledTasks.indexOf(t))return this._scheduledTasks.push(t),t},r.removeTask=function(t){var e=this._scheduledTasks.indexOf(t);-1<e&&this._scheduledTasks.splice(e,1),this.detectFinish()},r.resetSpans=function(){this.spans=[]},r._onSpanEnd=function(t){this.spans.push(t),delete this._activeSpans[t.id],0===Object.keys(this._activeSpans).length&&(this.childDuration+=t._end-this.childStart,this.childStart=0)},n}(Ct),jt=[["domainLookupStart","domainLookupEnd","Domain lookup"],["connectStart","connectEnd","Making a connection to the server"],["requestStart","responseEnd","Requesting and receiving the document"],["domLoading","domInteractive","Parsing the document, executing sync. scripts"],["domContentLoadedEventStart","domContentLoadedEventEnd",'Fire "DOMContentLoaded" event'],["loadEventStart","loadEventEnd",'Fire "load" event']];function At(t,e,n,r,i){return void 0===i&&(i=0),"number"==typeof t&&"number"==typeof e&&i<=t&&t<e&&n<=t-i&&e-i<=r&&e-t<H&&t-i<H&&e-i<H}function Ft(t){var e={transfer_size:t.transferSize,encoded_body_size:t.encodedBodySize,decoded_body_size:t.decodedBodySize},n=function(t){void 0===t&&(t=[]);for(var e=[],n=0;n<t.length;n++){var r=t[n],i=r.name,o=r.duration,a=r.description,s=i;a&&(s+=";desc="+a),o&&(s+=";dur="+o),e.push(s)}return e.join(", ")}(t.serverTiming);return n&&(e.headers={"server-timing":n}),e}function Rt(t){var e=t.name,n=t.initiatorType,r=t.startTime,i=t.responseEnd,o="resource";n&&(o+="."+n);var a=g(e),s=new Lt(a,o);return s.addContext({http:{url:e,response:Ft(t)}}),s._start=r,s.end(),s._end=i,s}function Mt(e){if(e.captureTimings){var t=window.performance,n=e._end;if(e.type===B){if(e.marks&&e.marks.custom){var r=e.marks.custom;Object.keys(r).forEach(function(t){r[t]+=e._start})}e._start=0;var i=t.timing;(function(t,e,n,r){for(var i=[],o=0;o<jt.length;o++){var a=t[jt[o][0]],s=t[jt[o][1]];if(At(a,s,n,r,e)){var c=new Lt(jt[o][2],"hard-navigation.browser-timing");"requestStart"===jt[o][0]&&(c.pageResponse=!0),c._start=a-e,c.ended=!0,c._end=s-e,i.push(c)}}return i})(i,i.fetchStart,0,n).forEach(function(t){t.traceId=e.traceId,t.sampled=e.sampled,t.pageResponse&&e.options.pageLoadSpanId&&(t.id=e.options.pageLoadSpanId),e.spans.push(t)}),e.addMarks(E())}if("function"==typeof t.getEntriesByType){var o=e._start;if(function(t,e,n,r){for(var i=[],o=0;o<t.length;o++){var a=t[o],s=a.initiatorType,c=a.name,u=a.startTime,f=a.responseEnd;if("xmlhttprequest"!==s&&"fetch"!==s&&c)if(-1!==D.indexOf(s)){if(!At(u,f,n,r))continue;i.push(Rt(t[o]))}else{if(null!=s)continue;for(var d=!1,h=0;h<e.length;h++){var v=c.lastIndexOf(e[h]);if(-1<v&&v===c.length-e[h].length){d=!0;break}}!d&&At(u,f,n,r)&&i.push(Rt(t[o]))}}return i}(t.getEntriesByType("resource"),function(t){for(var e=t.spans,n=[],r=0;r<e.length;r++){var i=e[r];"external"===i.type&&"http"===i.subType||n.push(i.name.split(" ")[1])}return n}(e),o,n).forEach(function(t){return e.spans.push(t)}),function(t,e,n){for(var r=[],i=0;i<t.length;i++){var o=t[i],a=o.name,s=o.startTime,c=o.duration,u=s+c;if(!(c<=U)&&At(s,u,e,n)){var f=new Lt(a,"app");f._start=s,f.end(),f._end=u,r.push(f)}}return r}(t.getEntriesByType("measure"),o,n).forEach(function(t){return e.spans.push(t)}),e.type===B){var a=t.getEntriesByType("navigation");a&&0<a.length&&(a=a[0],e.addContext({response:Ft(a)}))}}}}var Pt=function(){function t(t,e){this._config=e,this._logger=t,this.currentTransaction=void 0}var e=t.prototype;return e.ensureCurrentTransaction=function(t){t||(t=this.createOptions());var e=this.getCurrentTransaction();return e||(t.canReuse=!0,t.managed=!0,this.createTransaction(void 0,void 0,t))},e.getCurrentTransaction=function(){if(this.currentTransaction&&!this.currentTransaction.ended)return this.currentTransaction},e.setCurrentTransaction=function(t){this.currentTransaction=t},e.createTransaction=function(t,e,n){var r=new Nt(t,e,n);return this.setCurrentTransaction(r),n.checkBrowserResponsiveness&&this.startCounter(r),r},e.startCounter=function(t){t.browserResponsivenessCounter=0;var e=this._config.get("browserResponsivenessInterval");if(void 0!==e)var n=setInterval(function(){t.ended?window.clearInterval(n):t.browserResponsivenessCounter++},e)},e.createOptions=function(t){var e=this._config.config,n=_({transactionSampleRate:e.transactionSampleRate},t);return n.managed&&(n=_({pageLoadTraceId:e.pageLoadTraceId,pageLoadSampled:e.pageLoadSampled,pageLoadSpanId:e.pageLoadSpanId,pageLoadTransactionName:e.pageLoadTransactionName,checkBrowserResponsiveness:e.checkBrowserResponsiveness},n)),n},e.startManagedTransaction=function(t,e,n){var r=this.getCurrentTransaction();return r?r.canReuse()&&n.canReuse?r.redefine(t,void 0,n):(r.end(),r=this.createTransaction(t,e,n)):r=this.createTransaction(t,e,n),r.captureTimings=!0,e===B&&(r.options.checkBrowserResponsiveness=!1,n.pageLoadTraceId&&(r.traceId=n.pageLoadTraceId),n.pageLoadSampled&&(r.sampled=n.pageLoadSampled),r.name===Q&&n.pageLoadTransactionName&&(r.name=n.pageLoadTransactionName)),r},e.startTransaction=function(t,e,n){var r,i=this,o=this.createOptions(n);return(r=o.managed?this.startManagedTransaction(t,e,o):new Nt(t,e,o)).onEnd=function(){return i.handleTransactionEnd(r)},this._config.events.send("transaction:start",[r]),r},e.handleTransactionEnd=function(e){var n=this;return tt.Promise.resolve().then(function(){if(!n.shouldIgnoreTransaction(e.name)){if(n._config.get("breakdownMetrics")&&e.captureBreakdown(),e.type===B){var t=n._config.get("pageLoadTransactionName");e.name===Q&&t&&(e.name=t)}Mt(e),n.add(e)}},function(t){0})},e.shouldIgnoreTransaction=function(t){var e=this._config.get("ignoreTransactions");if(e&&e.length)for(var n=0;n<e.length;n++){var r=e[n];if("function"==typeof r.test){if(r.test(t))return!0}else if(r===t)return!0}return!1},e.startSpan=function(t,e,n){var r=this.ensureCurrentTransaction();if(r)return r.startSpan(t,e,n)},e.add=function(t){this._config.events.send($,[t])},e.addTask=function(t){var e=this.ensureCurrentTransaction();if(e){t=e.addTask(t);0}return t},e.removeTask=function(t){var e=this.getCurrentTransaction();e&&e.removeTask(t)},t}(),qt=function(i){i.registerServiceCreator("TransactionService",function(){var t=i.getService("ConfigService"),e=i.getService("LoggingService");return new Pt(e,t)}),i.registerServiceCreator("PerformanceMonitoring",function(){var t=i.getService("ConfigService"),e=i.getService("LoggingService"),n=i.getService("ApmServer"),r=i.getService("TransactionService");return new xt(n,t,e,r)})},Dt=function(){function t(t,e){e||(e={}),this.onFlush=t,this.items=[],this.queueLimit=e.queueLimit||-1,this.flushInterval=e.flushInterval||0,this.timeoutId=void 0}var e=t.prototype;return e._setTimer=function(){var t=this;this.timeoutId=setTimeout(function(){t.flush()},this.flushInterval)},e.flush=function(){this.onFlush(this.items),this._clear()},e._clear=function(){void 0!==this.timeoutId&&(clearTimeout(this.timeoutId),this.timeoutId=void 0),this.items=[]},e.add=function(t){this.items.push(t),-1!==this.queueLimit&&this.items.length>=this.queueLimit?this.flush():void 0===this.timeoutId&&this._setTimer()},t}();var Ht=function(e,n,t){var r,i=t.context||this,o=t.limit,a=t.interval,s=t.countFn||function(){},c=0;return function(){var t="function"==typeof s&&s.apply(i,arguments);return"number"!=typeof t&&(t=1),c+=t,void 0===r&&(r=setTimeout(function(){r=void(c=0)},a)),o<c?"function"==typeof n?n.apply(i,arguments):void 0:e.apply(i,arguments)}},Bt=function(){function t(){}return t.stringify=function(t){return JSON.stringify(t)+"\n"},t}();function Qt(){return(Qt=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}var Ut=function(){function t(t,e){this._configService=t,this._loggingService=e,this.errorQueue=void 0,this.transactionQueue=void 0,this.throttleAddError=void 0,this.throttleAddTransaction=void 0,this.initialized=!1}var e=t.prototype;return e.init=function(){this.initialized||(this.initialized=!0,this.initErrorQueue(),this.initTransactionQueue())},e.createMetaData=function(){var t=this._configService,e={service:{name:t.get("serviceName"),version:t.get("serviceVersion"),agent:{name:"js-base",version:t.version},language:{name:"javascript"},environment:t.get("environment")}};return _t(dt,e)},e._postJson=function(t,e){return this._makeHttpRequest("POST",t,{payload:e,headers:{"Content-Type":"application/x-ndjson"}})},e._constructError=function(t){var e=t.url,n=t.status,r=(t.responseText,e+" HTTP status: "+n);return new Error(r)},e._makeHttpRequest=function(e,o,t){var n=void 0===t?{timeout:1e4}:t,a=n.timeout,s=n.payload,c=n.headers;return new tt.Promise(function(n,r){var i=new window.XMLHttpRequest;if(i[I]=!0,i.open(e,o,!0),i.timeout=a,c)for(var t in c)c.hasOwnProperty(t)&&i.setRequestHeader(t,c[t]);i.onreadystatechange=function(){if(4===i.readyState){var t=i.status,e=i.responseText;0===t||399<t&&t<600?r({url:o,status:t,responseText:e}):n(e)}},i.onerror=function(){var t=i.status,e=i.responseText;r({url:o,status:t,responseText:e})},i.send(s)})},e._createQueue=function(t){var e=this._configService.get("queueLimit"),n=this._configService.get("flushInterval");return new Dt(t,{queueLimit:e,flushInterval:n})},e.fetchConfig=function(t,e){var n=this,r=this._configService.get("serverUrl")+"/config/v1/agents";return t?(r+="?service.name="+t,e&&(r+="&service.environment="+e),this._makeHttpRequest("GET",r,{timeout:5e3}).then(function(t){return JSON.parse(t)}).catch(function(t){var e=n._constructError(t);return tt.Promise.reject(e)})):tt.Promise.reject("serviceName is required for fetching central config.")},e.initErrorQueue=function(){var n=this;this.errorQueue&&this.errorQueue.flush(),this.errorQueue=this._createQueue(function(t){var e=n.sendErrors(t);e&&e.catch(function(t){n._loggingService.warn("Failed sending errors!",n._constructError(t))})});var t=this._configService.get("errorThrottleLimit"),e=this._configService.get("errorThrottleInterval");this.throttleAddError=Ht(this.errorQueue.add.bind(this.errorQueue),function(){return n._loggingService.warn("Dropped error due to throttling!")},{limit:t,interval:e})},e.initTransactionQueue=function(){var n=this;this.transactionQueue&&this.transactionQueue.flush(),this.transactionQueue=this._createQueue(function(t){var e=n.sendTransactions(t);e&&e.catch(function(t){n._loggingService.warn("Failed sending transactions!",n._constructError(t))})});var t=this._configService.get("transactionThrottleLimit"),e=this._configService.get("transactionThrottleInterval");this.throttleAddTransaction=Ht(this.transactionQueue.add.bind(this.transactionQueue),function(){return n._loggingService.warn("Dropped transaction due to throttling!")},{limit:t,interval:e})},e.addError=function(t){this.errorQueue||this.initErrorQueue(),this.throttleAddError(t)},e.addTransaction=function(t){this.transactionQueue||this.initTransactionQueue(),this.throttleAddTransaction(t)},e.ndjsonErrors=function(t){return t.map(function(t){return Bt.stringify({error:t})})},e.ndjsonMetricsets=function(t){var e=Date.now();return t.map(function(t){return Bt.stringify({metricset:Qt({timestamp:e},t)})}).join("")},e.ndjsonTransactions=function(t){var r=this;return t.map(function(t){var e="";t.spans&&(e=t.spans.map(function(t){return Bt.stringify({span:t})}).join(""),delete t.spans);var n="";return t.breakdown&&(n=r.ndjsonMetricsets(t.breakdown),delete t.breakdown),Bt.stringify({transaction:t})+e+n})},e._send=function(t,e){if(void 0===t&&(t=[]),void 0===e&&(e="transaction"),0!==t.length){var n={service:this.createMetaData().service,data:t},r=this._configService.applyFilters(n);if(r){var i;if("errors"===e)i=this.ndjsonErrors(r.data);else{if("transaction"!==e)return void 0;i=this.ndjsonTransactions(r.data)}i.unshift(Bt.stringify({metadata:{service:r.service}}));var o=i.join(""),a=this._configService.getEndpointUrl();return this._postJson(a,o)}this._loggingService.warn("Dropped payload due to filtering!")}},e.sendTransactions=function(t){return this._send(t)},e.sendErrors=function(t){return this._send(t,"errors")},t}();var zt=function(){function t(){this.config={},this.defaults={serviceName:"",serviceVersion:"",environment:"",serverUrl:"http://localhost:8200",serverUrlPrefix:"/intake/v2/rum/events",active:!0,instrument:!0,disableInstrumentations:[],debug:!1,logLevel:"warn",breakdownMetrics:!1,browserResponsivenessInterval:500,browserResponsivenessBuffer:3,checkBrowserResponsiveness:!0,groupSimilarSpans:!0,similarSpanThreshold:.05,ignoreTransactions:[],errorThrottleLimit:20,errorThrottleInterval:3e4,transactionThrottleLimit:20,transactionThrottleInterval:3e4,transactionDurationThreshold:6e4,queueLimit:-1,flushInterval:500,distributedTracing:!0,distributedTracingOrigins:[],distributedTracingHeaderValueCallback:c,distributedTracingHeaderName:"elastic-apm-traceparent",pageLoadTraceId:"",pageLoadSpanId:"",pageLoadSampled:!1,pageLoadTransactionName:"",transactionSampleRate:1,centralConfig:!1,context:{}},this.events=new nt,this.filters=[],this.version=""}var e=t.prototype;return e.init=function(){var t=function(t){if(!t)return{};for(var e={},n=/^data-([\w-]+)$/,r=t.attributes,i=0;i<r.length;i++){var o=r[i];if(n.test(o.nodeName)){var a=o.nodeName.match(n)[1],s=a.split("-").map(function(t,e){return 0<e?t.charAt(0).toUpperCase()+t.substring(1):t}).join("");e[s]=o.value||o.nodeValue}}return e}(y());this.setConfig(t)},e.isActive=function(){return this.get("active")},e.setVersion=function(t){this.version=t},e.addFilter=function(t){if("function"!=typeof t)throw new Error("Argument to must be function");this.filters.push(t)},e.applyFilters=function(t){for(var e=0;e<this.filters.length;e++)if(!(t=this.filters[e](t)))return;return t},e.get=function(t){return t.split(".").reduce(function(t,e){return t&&t[e]},this.config)},e.getEndpointUrl=function(){return this.config.serverUrl+this.config.serverUrlPrefix},e.set=function(t,e){for(var n=t.split("."),r=n.length-1,i=this.config,o=0;o<r+1;o++){var a=n[o];if(a)if(o===r)i[a]=e;else{var s=i[a]||{};i[a]=s,i=s}}},e.setUserContext=function(t){void 0===t&&(t={});var e={},n=t,r=n.id,i=n.username,o=n.email;"number"!=typeof r&&"string"!=typeof r||(e.id=r),"string"==typeof i&&(e.username=i),"string"==typeof o&&(e.email=o),this.set("context.user",e)},e.setCustomContext=function(t){t&&"object"==typeof t&&this.set("context.custom",t)},e.addLabels=function(e){var n=this;this.config.context.tags||(this.config.context.tags={}),Object.keys(e).forEach(function(t){return f(t,e[t],n.config.context.tags)})},e.setConfig=function(t){void 0===t&&(t={}),t.serverUrl&&(t.serverUrl=t.serverUrl.replace(/\/+$/,"")),this.config=S({},this.defaults,this.config,t),this.events.send(V,[this.config])},e.validate=function(e){void 0===e&&(e={});var n=["serviceName","serverUrl"],r={missing:[],invalid:[]};Object.keys(e).forEach(function(t){-1===n.indexOf(t)||e[t]||r.missing.push(t)}),e.serviceName&&!/^[a-zA-Z0-9 _-]+$/.test(e.serviceName)&&r.invalid.push({key:"serviceName",value:e.serviceName,allowed:"a-z, A-Z, 0-9, _, -, <space>"});var t=e.transactionSampleRate;return void 0!==t&&("number"!=typeof t||isNaN(t)||t<0||1<t)&&r.invalid.push({key:"transactionSampleRate",value:t,allowed:"Number between 0 and 1"}),r},t}(),$t=function(){function t(t){t||(t={}),this.levels=["trace","debug","info","warn","error"],this.level=t.level||"info",this.prefix=t.prefix||"",this.resetLogMethods()}var e=t.prototype;return e.shouldLog=function(t){return this.levels.indexOf(t)>=this.levels.indexOf(this.level)},e.setLevel=function(t){this.level=t,this.resetLogMethods()},e.resetLogMethods=function(){var o=this;this.levels.forEach(function(i){o[i]=o.shouldLog(i)?function(){var t,e=o.prefix;switch(i){case"trace":case"debug":t="info";break;default:t=i}var n=arguments;e&&("function"==typeof e&&(e=e(i)),n[0]=e+n[0]);if(console){var r=console[t]?console[t]:console.log;"function"==typeof r&&r.apply(console,n)}}:w})},t}(),Vt=function(){function t(){this._serviceCreators={},this._serviceInstances={},this.initialized=!1}var e=t.prototype;return e.registerCoreServices=function(){var t=this;this.registerServiceCreator("ConfigService",function(){return new zt}),this.registerServiceCreator("LoggingService",function(){return new $t}),this.registerServiceCreator("ApmServer",function(){return new Ut(t.getService("ConfigService"),t.getService("LoggingService"))})},e.init=function(){if(!this.initialized){this.initialized=!0;var t=this.getService("ConfigService");t.init();var e=this.getService("LoggingService");n(e,t),t.events.observe(V,function(){n(e,t)}),this.getService("ApmServer").init()}function n(t,e){var n=e.get("debug"),r=e.get("logLevel");!0===n&&"trace"!==r?t.setLevel("debug"):t.setLevel(r)}},e.registerServiceCreator=function(t,e){this._serviceCreators[t]=e},e.registerServiceInstance=function(t,e){this._serviceInstances[t]=e},e.getService=function(t){if(!this._serviceInstances[t]){if("function"!=typeof this._serviceCreators[t])throw new Error("Can not get service, No creator for: "+t);this._serviceInstances[t]=this._serviceCreators[t](this)}return this._serviceInstances[t]},t}();var Xt=function(){function t