Socket
Socket
Sign inDemoInstall

@datadog/browser-logs

Package Overview
Dependencies
Maintainers
1
Versions
256
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@datadog/browser-logs - npm Package Compare versions

Comparing version 4.0.1 to 4.1.0

2

bundle/datadog-logs.js

@@ -1,1 +0,1 @@

!function(){"use strict";var e=function(){return(e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)};function t(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}}function n(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;var r=Array(e),i=0;for(t=0;t<n;t++)for(var o=arguments[t],s=0,u=o.length;s<u;s++,i++)r[i]=o[s];return r}var r={log:console.log.bind(console),warn:console.warn.bind(console),error:console.error.bind(console)},i="?";function o(e,t){var n,r=void 0===t?0:+t;try{if(n=function(e){var t=a(e,"stacktrace");if(!t)return;for(var n,r=/ line (\d+).*script (?:in )?(\S+)(?:: in function (\S+))?$/i,o=/ line (\d+), column (\d+)\s*(?:in (?:<anonymous function: ([^>]+)>|([^)]+))\((.*)\))? in (.*):\s*$/i,s=t.split("\n"),u=[],c=0;c<s.length;c+=2){var f=void 0;r.exec(s[c])?f={args:[],column:void 0,func:(n=r.exec(s[c]))[3],line:+n[1],url:n[2]}:o.exec(s[c])&&(f={args:(n=o.exec(s[c]))[5]?n[5].split(","):[],column:+n[2],func:n[3]||n[4],line:+n[1],url:n[6]}),f&&(!f.func&&f.line&&(f.func=i),f.context=[s[c+1]],u.push(f))}if(!u.length)return;return{stack:u,message:a(e,"message"),name:a(e,"name")}}(e))return n}catch(e){if(s)throw e}try{if(n=function(e){var t=a(e,"stack");if(!t)return;for(var n,r,o,s,u=/^\s*at (.*?) ?\(((?:file|https?|blob|chrome-extension|native|eval|webpack|<anonymous>|\/).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,c=/^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|resource|capacitor|\[native).*?|[^@]*bundle)(?::(\d+))?(?::(\d+))?\s*$/i,l=/^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i,d=/(\S+) line (\d+)(?: > eval line \d+)* > eval/i,p=/\((\S*)(?::(\d+))(?::(\d+))\)/,h=t.split("\n"),v=[],g=0,m=h.length;g<m;g+=1){if(u.exec(h[g])){var y=(o=u.exec(h[g]))[2]&&0===o[2].indexOf("native");n=o[2]&&0===o[2].indexOf("eval"),r=p.exec(o[2]),n&&r&&(o[2]=r[1],o[3]=r[2],o[4]=r[3]),s={args:y?[o[2]]:[],column:o[4]?+o[4]:void 0,func:o[1]||i,line:o[3]?+o[3]:void 0,url:y?void 0:o[2]}}else if(l.exec(h[g]))s={args:[],column:(o=l.exec(h[g]))[4]?+o[4]:void 0,func:o[1]||i,line:+o[3],url:o[2]};else{if(!c.exec(h[g]))continue;n=(o=c.exec(h[g]))[3]&&o[3].indexOf(" > eval")>-1,r=d.exec(o[3]),n&&r?(o[3]=r[1],o[4]=r[2],o[5]=void 0):0!==g||o[5]||f(e.columnNumber)||(v[0].column=e.columnNumber+1),s={args:o[2]?o[2].split(","):[],column:o[5]?+o[5]:void 0,func:o[1]||i,line:o[4]?+o[4]:void 0,url:o[3]}}!s.func&&s.line&&(s.func=i),v.push(s)}if(!v.length)return;return{stack:v,message:a(e,"message"),name:a(e,"name")}}(e))return n}catch(e){if(s)throw e}try{if(n=function(e){var t=a(e,"message");if(!t)return;var n=t.split("\n");if(n.length<4)return;var r,o=/^\s*Line (\d+) of linked script ((?:file|https?|blob)\S+)(?:: in function (\S+))?\s*$/i,s=/^\s*Line (\d+) of inline#(\d+) script in ((?:file|https?|blob)\S+)(?:: in function (\S+))?\s*$/i,u=/^\s*Line (\d+) of function script\s*$/i,f=[],l=window&&window.document&&window.document.getElementsByTagName("script"),d=[];for(var p in l)c(l,p)&&!l[p].src&&d.push(l[p]);for(var h=2;h<n.length;h+=2){var v=void 0;if(o.exec(n[h]))v={args:[],column:void 0,func:(r=o.exec(n[h]))[3],line:+r[1],url:r[2]};else if(s.exec(n[h]))v={args:[],column:void 0,func:(r=s.exec(n[h]))[4],line:+r[1],url:r[3]};else if(u.exec(n[h])){r=u.exec(n[h]),v={url:window.location.href.replace(/#.*$/,""),args:[],column:void 0,func:"",line:+r[1]}}v&&(v.func||(v.func=i),v.context=[n[h+1]],f.push(v))}if(!f.length)return;return{stack:f,message:n[0],name:a(e,"name")}}(e))return n}catch(e){if(s)throw e}try{if(n=u(e,r+1))return n}catch(e){if(s)throw e}return{message:a(e,"message"),name:a(e,"name"),stack:[]}}var s=!1;function u(e,t){for(var n,r,s=/function\s+([_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*)?\s*\(/i,c=[],f={},l=!1,d=u.caller;d&&!l;d=d.caller)d!==o&&(r={args:[],column:void 0,func:i,line:void 0,url:void 0},n=s.exec(d.toString()),d.name?r.func=d.name:n&&(r.func=n[1]),void 0===r.func&&(r.func=n?n.input.substring(0,n.input.indexOf("{")):void 0),f[d.toString()]?l=!0:f[d.toString()]=!0,c.push(r));t&&c.splice(0,t);var p={stack:c,message:a(e,"message"),name:a(e,"name")};return function(e,t,n){var r={url:t,line:n?+n:void 0};if(r.url&&r.line){e.incomplete=!1;var i=e.stack;if(i.length>0&&i[0].url===r.url){if(i[0].line===r.line)return!1;if(!i[0].line&&i[0].func===r.func)return i[0].line=r.line,i[0].context=r.context,!1}return i.unshift(r),e.partial=!0,!0}e.incomplete=!0}(p,a(e,"sourceURL")||a(e,"fileName"),a(e,"line")||a(e,"lineNumber")),p}function a(e,t){if("object"==typeof e&&e&&t in e){var n=e[t];return"string"==typeof n?n:void 0}}function c(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function f(e){return void 0===e}var l,d,p=1e3,h=6e4;function v(e,t,n){var r,i,o=!n||void 0===n.leading||n.leading,s=!n||void 0===n.trailing||n.trailing,u=!1;return{throttled:function(){for(var n=[],a=0;a<arguments.length;a++)n[a]=arguments[a];u?r=n:(o?e.apply(void 0,n):r=n,u=!0,i=setTimeout((function(){s&&r&&e.apply(void 0,r),u=!1,r=void 0}),t))},cancel:function(){clearTimeout(i),u=!1,r=void 0}}}function g(e){return e?(parseInt(e,10)^16*Math.random()>>parseInt(e,10)/4).toString(16):"10000000-1000-4000-8000-100000000000".replace(/[018]/g,g)}function m(){}function y(e,t,n){if(null==e)return JSON.stringify(e);var r=[!1,void 0];b(e)&&(r=[!0,e.toJSON],delete e.toJSON);var i,o,s=[!1,void 0];"object"==typeof e&&b(i=Object.getPrototypeOf(e))&&(s=[!0,i.toJSON],delete i.toJSON);try{o=JSON.stringify(e,t,n)}catch(e){o="<error: unable to serialize object>"}finally{r[0]&&(e.toJSON=r[1]),s[0]&&(i.toJSON=s[1])}return o}function b(e){return"object"==typeof e&&null!==e&&Object.prototype.hasOwnProperty.call(e,"toJSON")}function w(e,t){return-1!==e.indexOf(t)}function x(e){return Object.keys(e).map((function(t){return e[t]}))}function S(e,t,n,r){return E(e,[t],n,r)}function E(e,t,n,r){var i=void 0===r?{}:r,o=i.once,s=i.capture,u=i.passive,a=W(o?function(e){f(),n(e)}:n),c=u?{capture:s,passive:u}:s;t.forEach((function(t){return e.addEventListener(t,a,c)}));var f=function(){return t.forEach((function(t){return e.removeEventListener(t,a,c)}))};return{stop:f}}function k(e,t,n){if(void 0===n&&(n=function(){if("undefined"!=typeof WeakSet){var e=new WeakSet;return{hasAlreadyBeenSeen:function(t){var n=e.has(t);return n||e.add(t),n}}}var t=[];return{hasAlreadyBeenSeen:function(e){var n=t.indexOf(e)>=0;return n||t.push(e),n}}}()),void 0===t)return e;if("object"!=typeof t||null===t)return t;if(t instanceof Date)return new Date(t.getTime());if(t instanceof RegExp){var r=t.flags||[t.global?"g":"",t.ignoreCase?"i":"",t.multiline?"m":"",t.sticky?"y":"",t.unicode?"u":""].join("");return new RegExp(t.source,r)}if(!n.hasAlreadyBeenSeen(t)){if(Array.isArray(t)){for(var i=Array.isArray(e)?e:[],o=0;o<t.length;++o)i[o]=k(i[o],t[o],n);return i}var s,u="object"==(null===(s=e)?"null":Array.isArray(s)?"array":typeof s)?e:{};for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&(u[a]=k(u[a],t[a],n));return u}}function T(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];for(var r=0,i=t;r<i.length;r++){var o=i[r];null!=o&&(e=k(e,o))}return e}!function(e){e.DOCUMENT="document",e.XHR="xhr",e.BEACON="beacon",e.FETCH="fetch",e.CSS="css",e.JS="js",e.IMAGE="image",e.FONT="font",e.MEDIA="media",e.OTHER="other"}(l||(l={})),function(e){e.FETCH="fetch",e.XHR="xhr"}(d||(d={}));var O,C,R="agent",M="console",L="logger",B="network",A="source";function N(e){var t=I(e);return e.stack.forEach((function(e){var n="?"===e.func?"<anonymous>":e.func,r=e.args&&e.args.length>0?"("+e.args.join(", ")+")":"",i=e.line?":"+e.line:"",o=e.line&&e.column?":"+e.column:"";t+="\n at "+n+r+" @ "+e.url+i+o})),t}function I(e){return(e.name||"Error")+": "+e.message}function D(){var e,t=new Error;if(!t.stack)try{throw t}catch(e){}return V((function(){var n=o(t);n.stack=n.stack.slice(2),e=N(n)})),e}function _(){var e,t=(e="event-bridge",C&&C.has(e)?window.DatadogEventBridge:null);if(t)return{getAllowedWebViewHosts:function(){return JSON.parse(t.getAllowedWebViewHosts())},send:function(e,n){t.send(JSON.stringify({eventType:e,event:n}))}}}function j(){var e=_();return!!e&&w(e.getAllowedWebViewHosts(),window.location.hostname)}!function(e){e.HANDLED="handled",e.UNHANDLED="unhandled"}(O||(O={}));var z,P=/[^\u0000-\u007F]/,U=function(){function e(e,t,n,r,i,o){void 0===o&&(o=m),this.request=e,this.maxSize=t,this.bytesLimit=n,this.maxMessageSize=r,this.flushTimeout=i,this.beforeUnloadCallback=o,this.pushOnlyBuffer=[],this.upsertBuffer={},this.bufferBytesSize=0,this.bufferMessageCount=0,this.flushOnVisibilityHidden(),this.flushPeriodically()}return e.prototype.add=function(e){this.addOrUpdate(e)},e.prototype.upsert=function(e,t){this.addOrUpdate(e,t)},e.prototype.flush=function(e){if(0!==this.bufferMessageCount){var t=n(this.pushOnlyBuffer,x(this.upsertBuffer));this.request.send(t.join("\n"),this.bufferBytesSize,e),this.pushOnlyBuffer=[],this.upsertBuffer={},this.bufferBytesSize=0,this.bufferMessageCount=0}},e.prototype.sizeInBytes=function(e){return P.test(e)?void 0!==window.TextEncoder?(new TextEncoder).encode(e).length:new Blob([e]).size:e.length},e.prototype.addOrUpdate=function(e,t){var n=this.process(e),i=n.processedMessage,o=n.messageBytesSize;o>=this.maxMessageSize?r.warn("Discarded a message whose size was bigger than the maximum allowed size "+this.maxMessageSize+"KB."):(this.hasMessageFor(t)&&this.remove(t),this.willReachedBytesLimitWith(o)&&this.flush("willReachedBytesLimitWith"),this.push(i,o,t),this.isFull()&&this.flush("isFull"))},e.prototype.process=function(e){var t=y(e);return{processedMessage:t,messageBytesSize:this.sizeInBytes(t)}},e.prototype.push=function(e,t,n){this.bufferMessageCount>0&&(this.bufferBytesSize+=1),void 0!==n?this.upsertBuffer[n]=e:this.pushOnlyBuffer.push(e),this.bufferBytesSize+=t,this.bufferMessageCount+=1},e.prototype.remove=function(e){var t=this.upsertBuffer[e];delete this.upsertBuffer[e];var n=this.sizeInBytes(t);this.bufferBytesSize-=n,this.bufferMessageCount-=1,this.bufferMessageCount>0&&(this.bufferBytesSize-=1)},e.prototype.hasMessageFor=function(e){return void 0!==e&&void 0!==this.upsertBuffer[e]},e.prototype.willReachedBytesLimitWith=function(e){return this.bufferBytesSize+e+1>=this.bytesLimit},e.prototype.isFull=function(){return this.bufferMessageCount===this.maxSize||this.bufferBytesSize>=this.bytesLimit},e.prototype.flushPeriodically=function(){var e=this;setTimeout(W((function(){e.flush("flushPeriodically"),e.flushPeriodically()})),this.flushTimeout)},e.prototype.flushOnVisibilityHidden=function(){var e=this;navigator.sendBeacon&&(S(window,"beforeunload",this.beforeUnloadCallback),S(document,"visibilitychange",(function(){"hidden"===document.visibilityState&&e.flush("visibilitychange")})),S(window,"beforeunload",(function(){return e.flush("beforeunload")})))},e}(),H=!1,F=function(){function e(e,t){this.endpointBuilder=e,this.bytesLimit=t}return e.prototype.send=function(e,t,n){var r=this.endpointBuilder.build(),i=!!navigator.sendBeacon&&t<this.bytesLimit;if(i)try{if(navigator.sendBeacon(r,e))return}catch(e){!function(e){q||(q=!0,Z(e))}(e)}var o=new XMLHttpRequest;o.addEventListener("loadend",W((function(e){return function(e){var o=null==e?void 0:e.currentTarget;o.status>=200&&o.status<300||H||(H=!0,Y("XHR fallback failed",{on_line:navigator.onLine,size:t,url:r,try_beacon:i,flush_reason:n,event:{is_trusted:e.isTrusted,total:e.total,loaded:e.loaded},request:{status:o.status,ready_state:o.readyState,response_text:o.responseText.slice(0,512)}}))}(e)}))),o.open("POST",r,!0),o.send(e)},e}(),q=!1;!function(e){e.info="info",e.error="error"}(z||(z={}));var G,$,K={maxMessagesPerPage:0,sentMessageCount:0};function J(e){var t;if(j()){var n=_();G=function(e){return n.send("internal_log",i(e))}}else if(e.internalMonitoringEndpointBuilder){var r=function(e){var t,n=r(e.internalMonitoringEndpointBuilder);function r(t){return new U(new F(t,e.batchBytesLimit),e.maxBatchSize,e.batchBytesLimit,e.maxMessageSize,e.flushTimeout)}return void 0!==e.replica&&(t=r(e.replica.internalMonitoringEndpointBuilder)),{add:function(e){n.add(e),t&&t.add(e)}}}(e);G=function(e){return r.add(i(e))}}function i(e){return T({date:(new Date).getTime()},void 0!==t?t():{},e)}return function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];t.forEach((function(t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}))}(K,{maxMessagesPerPage:e.maxInternalMonitoringMessagesPerPage,sentMessageCount:0}),{setExternalContextProvider:function(e){t=e}}}function X(e,t,n){var r=n.value;n.value=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=G?W(r):r;return n.apply(this,e)}}function W(e){return function(){return V(e,this,arguments)}}function V(e,t,n){try{return e.apply(t,n)}catch(e){te(e);try{Z(e)}catch(e){te(e)}}}function Y(t,n){!function(e,t){K.debugMode&&r.log("[MONITORING MESSAGE]",e,t)}(t,n),Q(e(e({message:t},n),{status:z.info}))}function Z(t){Q(e(e({},function(e){if(e instanceof Error){var t=o(e);return{error:{kind:t.name,stack:N(t)},message:t.message}}return{error:{stack:"Not an instance of error"},message:"Uncaught "+y(e)}}(t)),{status:z.error}))}function Q(e){G&&K.sentMessageCount<K.maxMessagesPerPage&&(K.sentMessageCount+=1,G(e))}function ee(e){K.debugMode=e}function te(e){K.debugMode&&r.error("[INTERNAL ERROR]",e)}function ne(e,t){return function(){for(var n=[],i=0;i<arguments.length;i++)n[i]=arguments[i];try{return e.apply(void 0,n)}catch(e){r.error(t,e)}}}function re(){var e={};return{get:function(){return e},add:function(t,n){e[t]=n},remove:function(t){delete e[t]},set:function(t){e=t}}}!function(e){e.RELEASE="release",e.STAGING="staging",e.CANARY="canary",e.E2E_TEST="e2e-test"}($||($={}));var ie,oe,se,ue=function(){function e(){this.buffer=[]}return e.prototype.add=function(e){this.buffer.push(e)>500&&this.buffer.splice(0,1)},e.prototype.drain=function(){this.buffer.forEach((function(e){return e()})),this.buffer.length=0},e}();function ae(e,t,n,r){var i=new Date;i.setTime(i.getTime()+n);var o="expires="+i.toUTCString(),s=r&&r.crossSite?"none":"strict",u=r&&r.domain?";domain="+r.domain:"",a=r&&r.secure?";secure":"";document.cookie=e+"="+t+";"+o+";path=/;samesite="+s+u+a}function ce(e){return function(e,t){var n=new RegExp("(?:^|;)\\s*"+t+"\\s*=\\s*([^;]+)").exec(e);return n?n[1]:void 0}(document.cookie,e)}function fe(e,t){ae(e,"",0,t)}function le(){return Date.now()}function de(){return performance.now()}function pe(){return{relative:de(),timeStamp:le()}}function he(e,t){return t-e}function ve(){return void 0===oe&&(oe=performance.timing.navigationStart),oe}function ge(e){return me(e,function(e){if(e.origin)return e.origin;var t=e.host.replace(/(:80|:443)$/,"");return e.protocol+"//"+t}(window.location)).href}function me(e,t){if(function(){if(void 0!==se)return se;try{var e=new URL("http://test/path");return se="http://test/path"===e.href}catch(e){se=!1}return se}())return void 0!==t?new URL(e,t):new URL(e);if(void 0===t&&!/:/.test(e))throw new Error("Invalid URL: '"+e+"'");var n=document,r=n.createElement("a");if(void 0!==t){var i=(n=document.implementation.createHTMLDocument("")).createElement("base");i.href=t,n.head.appendChild(i),n.body.appendChild(r)}return r.href=e,r}var ye={logs:"logs",rum:"rum",sessionReplay:"session-replay"},be={logs:"logs",rum:"rum",sessionReplay:"replay"},we="datadoghq.com";function xe(e,t,n,r,i){var o=e.site,s=void 0===o?we:o,u=e.clientToken,a=s.split("."),c=a.pop(),f="https://"+(ye[n]+".browser-intake-"+a.join("-")+"."+c)+"/api/v2/"+be[n],l=e.proxyUrl&&ge(e.proxyUrl);return{build:function(){var e="ddsource="+(i||"browser")+"&ddtags="+encodeURIComponent(["sdk_version:"+t.sdkVersion].concat(r).join(","))+"&dd-api-key="+u+"&dd-evp-origin-version="+encodeURIComponent(t.sdkVersion)+"&dd-evp-origin=browser&dd-request-id="+g();"rum"===n&&(e+="&batch_time="+le());var o=f+"?"+e;return l?l+"?ddforward="+encodeURIComponent(o):o},buildIntakeUrl:function(){return l?l+"?ddforward":f}}}var Se=/[^a-z0-9_:./-]/;function Ee(e,t){var n=200-e.length-1;return(t.length>n||Se.test(t))&&r.warn(e+" value doesn't meet tag requirements and will be sanitized"),e+":"+t.replace(/,/g,"_")}function ke(t,n){var r=function(e){var t=e.env,n=e.service,r=e.version,i=[];return t&&i.push(Ee("env",t)),n&&i.push(Ee("service",n)),r&&i.push(Ee("version",r)),i}(t),i=function(t,n,r){if(n.buildMode===$.E2E_TEST){var i=function(e){return{build:function(){return e},buildIntakeUrl:function(){return e}}};return{logsEndpointBuilder:i("<<< E2E LOGS ENDPOINT >>>"),rumEndpointBuilder:i("<<< E2E RUM ENDPOINT >>>"),sessionReplayEndpointBuilder:i("<<< E2E SESSION REPLAY ENDPOINT >>>"),internalMonitoringEndpointBuilder:i("<<< E2E INTERNAL MONITORING ENDPOINT >>>")}}var o={logsEndpointBuilder:xe(t,n,"logs",r),rumEndpointBuilder:xe(t,n,"rum",r),sessionReplayEndpointBuilder:xe(t,n,"sessionReplay",r)};if(t.internalMonitoringApiKey)return e(e({},o),{internalMonitoringEndpointBuilder:xe(e(e({},t),{clientToken:t.internalMonitoringApiKey}),n,"logs",r,"browser-agent-internal-monitoring")});return o}(t,n,r),o=x(i).map((function(e){return e.buildIntakeUrl()})),s=function(t,n,r,i){if(n.buildMode!==$.STAGING||void 0===t.replica)return;var o=e(e({},t),{site:we,clientToken:t.replica.clientToken}),s={logsEndpointBuilder:xe(o,n,"logs",i),rumEndpointBuilder:xe(o,n,"rum",i),internalMonitoringEndpointBuilder:xe(o,n,"logs",i,"browser-agent-internal-monitoring")};return r.push.apply(r,x(s).map((function(e){return e.buildIntakeUrl()}))),e({applicationId:t.replica.applicationId},s)}(t,n,o,r);return e(e({isIntakeUrl:function(e){return o.some((function(t){return 0===e.indexOf(t)}))}},i),{replica:s})}function Te(t,n){var i;if(t&&t.clientToken){var o,s;if(void 0===t.sampleRate||function(e){return"number"==typeof e}(o=t.sampleRate)&&o>=0&&o<=100)return s=t.enableExperimentalFeatures,Array.isArray(s)&&(C||(C=new Set(s)),s.filter((function(e){return"string"==typeof e})).forEach((function(e){C.add(e)}))),e(e({},ke(t,n)),{beforeSend:t.beforeSend&&ne(t.beforeSend,"beforeSend threw an error:"),cookieOptions:Oe(t),sampleRate:null!==(i=t.sampleRate)&&void 0!==i?i:100,service:t.service,silentMultipleInit:!!t.silentMultipleInit,batchBytesLimit:16384,maxErrorsPerMinute:3e3,maxInternalMonitoringMessagesPerPage:15,requestErrorResponseLengthLimit:32768,flushTimeout:3e4,maxBatchSize:50,maxMessageSize:262144});r.error("Sample Rate should be a number between 0 and 100")}else r.error("Client Token is not configured, we will not send any data.")}function Oe(e){var t={};return t.secure=function(e){return!!e.useSecureSessionCookie||!!e.useCrossSiteSessionCookie}(e),t.crossSite=!!e.useCrossSiteSessionCookie,e.trackSessionAcrossSubdomains&&(t.domain=function(){if(void 0===ie){for(var e="dd_site_test_"+g(),t=window.location.hostname.split("."),n=t.pop();t.length&&!ce(e);)n=t.pop()+"."+n,ae(e,"test",p,{domain:n});fe(e,{domain:n}),ie=n}return ie}()),t}var Ce,Re={buildMode:"release",sdkVersion:"4.0.1"};var Me={debug:"debug",error:"error",info:"info",warn:"warn"},Le=((Ce={})[Me.debug]=0,Ce[Me.info]=1,Ce[Me.warn]=2,Ce[Me.error]=3,Ce),Be=(Object.keys(Me),"console"),Ae="http",Ne=function(){function t(e,t,n,r){void 0===t&&(t=Ae),void 0===n&&(n=Me.debug),void 0===r&&(r={}),this.sendLog=e,this.handlerType=t,this.level=n,this.contextManager=re(),this.contextManager.set(r)}return t.prototype.log=function(t,n,i){if(void 0===i&&(i=Me.info),Le[i]>=Le[this.level]){var o=Array.isArray(this.handlerType)?this.handlerType:[this.handlerType];w(o,Ae)&&this.sendLog(e({message:t,status:i},T(this.contextManager.get(),n))),w(o,Be)&&r.log(i+": "+t,T(this.contextManager.get(),n))}},t.prototype.debug=function(e,t){this.log(e,t,Me.debug)},t.prototype.info=function(e,t){this.log(e,t,Me.info)},t.prototype.warn=function(e,t){this.log(e,t,Me.warn)},t.prototype.error=function(e,t){var n={error:{origin:L}};this.log(e,T(n,t),Me.error)},t.prototype.setContext=function(e){this.contextManager.set(e)},t.prototype.addContext=function(e,t){this.contextManager.add(e,t)},t.prototype.removeContext=function(e){this.contextManager.remove(e)},t.prototype.setHandler=function(e){this.handlerType=e},t.prototype.setLevel=function(e){this.level=e},function(e,t,n,r){var i,o=arguments.length,s=o<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var u=e.length-1;u>=0;u--)(i=e[u])&&(s=(o<3?i(s):o>3?i(t,n,s):i(t,n))||s);o>3&&s&&Object.defineProperty(t,n,s)}([X],t.prototype,"log",null),t}();var Ie,De,_e=function(){function e(e){this.onFirstSubscribe=e,this.observers=[]}return e.prototype.subscribe=function(e){var t=this;return!this.observers.length&&this.onFirstSubscribe&&(this.onLastUnsubscribe=this.onFirstSubscribe()||void 0),this.observers.push(e),{unsubscribe:function(){t.observers=t.observers.filter((function(t){return e!==t})),!t.observers.length&&t.onLastUnsubscribe&&t.onLastUnsubscribe()}}},e.prototype.notify=function(e){this.observers.forEach((function(t){return t(e)}))},e}();function je(t){(function(){De||(De=new _e,Ie=console.error,console.error=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var r=D();V((function(){Ie.apply(console,t);var n=e(e({},ze(t,r)),{source:M,startClocks:pe(),handling:O.HANDLED});De.notify(n)}))});return De})().subscribe((function(e){return t.notify(e)}))}function ze(e,t){var r=function(e,t){for(var n=0;n<e.length;n+=1){var r=e[n];if(t(r,n,e))return r}}(e,(function(e){return e instanceof Error}));return{message:n(["console error:"],e).map((function(e){return function(e){if("string"==typeof e)return e;if(e instanceof Error)return I(o(e));return y(e,void 0,2)}(e)})).join(" "),stack:r?N(o(r)):void 0,handlingStack:t}}function Pe(e,t,n){var r=e[t],i=n(r),o=function(){return i.apply(this,arguments)};return e[t]=o,{stop:function(){e[t]===o?e[t]=r:i=r}}}function Ue(e,t,n){var r=n.before,i=n.after;return Pe(e,t,(function(e){return function(){var t,n=arguments;return r&&V(r,this,n),"function"==typeof e&&(t=e.apply(this,n)),i&&V(i,this,n),t}}))}var He,Fe=/^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/;function qe(e){var t=function(e){return Ue(window,"onerror",{before:function(t,n,r,i,s){var u;if(s)u=o(s),e(u,s);else{var a,c={url:n,column:i,line:r},f=t;if("[object String]"==={}.toString.call(t)){var l=Fe.exec(f);l&&(a=l[1],f=l[2])}e(u={name:a,message:"string"==typeof f?f:void 0,stack:[c]},t)}}})}(e).stop,n=function(e){return Ue(window,"onunhandledrejection",{before:function(t){var n=t.reason||"Empty reason",r=o(n);e(r,n)}})}(e).stop;return{stop:function(){t(),n()}}}function Ge(e){return qe((function(t,n){var r=function(e,t,n,r){return e&&(void 0!==e.message||t instanceof Error)?{message:e.message||"Empty message",stack:N(e),handlingStack:r,type:e.name}:{message:n+" "+y(t),stack:"No stack, consider using an instance of Error",handlingStack:r,type:e&&e.name}}(t,n,"Uncaught"),i=r.stack,o=r.message,s=r.type;e.notify({message:o,stack:i,type:s,source:A,startClocks:pe(),originalError:n,handling:O.UNHANDLED})}))}var $e,Ke=new WeakMap;function Je(){var e;return He||(e=new _e((function(){var t=Ue(XMLHttpRequest.prototype,"open",{before:Xe}).stop,n=Ue(XMLHttpRequest.prototype,"send",{before:function(){We.call(this,e)}}).stop,r=Ue(XMLHttpRequest.prototype,"abort",{before:Ve}).stop;return function(){t(),n(),r()}})),He=e),He}function Xe(e,t){Ke.set(this,{state:"open",method:e,url:ge(t)})}function We(t){var n=this,r=Ke.get(this);if(r){var i=r;i.state="start",i.startTime=de(),i.startClocks=pe(),i.isAborted=!1,i.xhr=this;var o=!1,s=Ue(this,"onreadystatechange",{before:function(){this.readyState===XMLHttpRequest.DONE&&u()}}).stop,u=W((function(){if(n.removeEventListener("loadend",u),s(),!o){o=!0;var a=r;a.state="complete",a.duration=he(i.startClocks.timeStamp,le()),a.responseText=n.response,a.status=n.status,t.notify(e({},a))}}));this.addEventListener("loadend",u),t.notify(i)}}function Ve(){var e=Ke.get(this);e&&(e.isAborted=!0)}function Ye(){var e;return $e||(e=new _e((function(){if(window.fetch)return Pe(window,"fetch",(function(t){return function(n,r){var i,o=V(Ze,null,[e,n,r]);return o?(i=t.call(this,o.input,o.init),V(Qe,null,[e,i,o])):i=t.call(this,n,r),i}})).stop})),$e=e),$e}function Ze(e,t,n){var r=n&&n.method||"object"==typeof t&&t.method||"GET",i=ge("object"==typeof t&&t.url||t),o={state:"start",init:n,input:t,method:r,startClocks:pe(),url:i};return e.notify(o),o}function Qe(e,n,r){var i=this,s=function(n){return s=i,u=void 0,c=function(){var i,s,u;return t(this,(function(t){switch(t.label){case 0:return(i=r).state="complete",i.duration=he(i.startClocks.timeStamp,le()),"stack"in n||n instanceof Error?(i.status=0,i.responseText=N(o(n)),i.isAborted=n instanceof DOMException&&n.code===DOMException.ABORT_ERR,i.error=n,e.notify(i),[3,6]):[3,1];case 1:if(!("status"in n))return[3,6];s=void 0,t.label=2;case 2:return t.trys.push([2,4,,5]),[4,n.clone().text()];case 3:return s=t.sent(),[3,5];case 4:return u=t.sent(),s="Unable to retrieve response: "+u,[3,5];case 5:i.response=n,i.responseText=s,i.responseType=n.type,i.status=n.status,i.isAborted=!1,e.notify(i),t.label=6;case 6:return[2]}}))},new((a=void 0)||(a=Promise))((function(e,t){function n(e){try{i(c.next(e))}catch(e){t(e)}}function r(e){try{i(c.throw(e))}catch(e){t(e)}}function i(t){t.done?e(t.value):new a((function(e){e(t.value)})).then(n,r)}i((c=c.apply(s,u||[])).next())}));var s,u,a,c};n.then(W(s),W(s))}function et(e,t){return e&&e.length>t.requestErrorResponseLengthLimit?e.substring(0,t.requestErrorResponseLengthLimit)+"...":e}function tt(e){return d.XHR===e?"XHR":"Fetch"}var nt=function(){function e(e){var t=this;this.expireDelay=e,this.previousContexts=[],this.clearOldContextsInterval=setInterval((function(){return t.clearOldContexts()}),6e4)}return e.prototype.find=function(e){if(void 0===e||void 0!==this.current&&void 0!==this.currentStart&&e>=this.currentStart)return this.current;for(var t=0,n=this.previousContexts;t<n.length;t++){var r=n[t];if(e>r.endTime)break;if(e>=r.startTime)return r.context}},e.prototype.setCurrent=function(e,t){this.current=e,this.currentStart=t},e.prototype.getCurrent=function(){return this.current},e.prototype.clearCurrent=function(){this.current=void 0,this.currentStart=void 0},e.prototype.closeCurrent=function(e){void 0!==this.current&&void 0!==this.currentStart&&(this.previousContexts.unshift({endTime:e,context:this.current,startTime:this.currentStart}),this.clearCurrent())},e.prototype.clearOldContexts=function(){for(var e=de()-this.expireDelay;this.previousContexts.length>0&&this.previousContexts[this.previousContexts.length-1].startTime<e;)this.previousContexts.pop()},e.prototype.reset=function(){this.clearCurrent(),this.previousContexts=[]},e.prototype.stop=function(){clearInterval(this.clearOldContextsInterval)},e}(),rt="_dd_s",it=9e5,ot=144e5,st=/^([a-z]+)=([a-z0-9-]+)$/,ut="&";function at(e,t,n){var r=new _e,i=new _e,o=setInterval(W(u),1e3),s=ct(e);function u(){var n=ct(e);return a()&&(!function(e){if(s.id!==e.id)return e.id&&ft(s)&&c(e,"different id"),!0;if(s[t]!==e[t])return c(e,"different tracking type"),!0;return!1}(n)?s=n:(s={},i.notify())),n}function a(){return void 0!==s[t]}function c(e,n){Y("Session inconsistencies detected",{debug:{productKey:t,sessionCache:s,cookieSession:e,cause:n}})}return{expandOrRenewSession:v(W((function(){var i=u();(function(r){var i=n(r[t]),o=i.trackingType,s=i.isTracked;r[t]=o,s&&!r.id&&(r.id=g(),r.created=String(Date.now()));return lt(r,e),s})(i)&&!a()&&function(e){s=e,r.notify()}(i),s=i})),1e3).throttled,expandSession:function(){var t=u();a()&&lt(t,e)},getSession:function(){return s},renewObservable:r,expireObservable:i,stop:function(){clearInterval(o)}}}function ct(e){var t=function(){var e=ce(rt),t={};(function(e){return void 0!==e&&(-1!==e.indexOf("&")||st.test(e))})(e)&&e.split(ut).forEach((function(e){var n=st.exec(e);if(null!==n){var r=n[1],i=n[2];t[r]=i}}));return t}();return ft(t)?t:(dt(e),{})}function ft(e){return(void 0===e.created||Date.now()-Number(e.created)<ot)&&(void 0===e.expire||Date.now()<Number(e.expire))}function lt(e,t){if(n=e,0!==Object.keys(n).length){var n;e.expire=String(Date.now()+it);var r=function(e){return Object.keys(e).map((function(t){return[t,e[t]]}))}(e).map((function(e){return e[0]+"="+e[1]})).join(ut);ae(rt,r,it,t)}else dt(t)}function dt(e){ae(rt,"",0,e)}var pt=[];function ht(e,t,n){!function(e){var t=ce(rt),n=ce("_dd"),r=ce("_dd_r"),i=ce("_dd_l");if(!t){var o={};n&&(o.id=n),i&&/^[01]$/.test(i)&&(o.logs=i),r&&/^[012]$/.test(r)&&(o.rum=r),lt(o,e)}}(e);var r=at(e,t,n);pt.push((function(){return r.stop()}));var i,o=new nt(144e5);function s(){return{id:r.getSession().id,trackingType:r.getSession()[t]}}return pt.push((function(){return o.stop()})),r.renewObservable.subscribe((function(){o.setCurrent(s(),de())})),r.expireObservable.subscribe((function(){o.closeCurrent(de())})),r.expandOrRenewSession(),o.setCurrent(s(),[0,ve()][0]),i=E(window,["click","touchstart","keydown","scroll"],(function(){return r.expandOrRenewSession()}),{capture:!0,passive:!0}).stop,pt.push(i),function(e){var t=W((function(){"visible"===document.visibilityState&&e()})),n=S(document,"visibilitychange",t).stop;pt.push(n);var r=setInterval(t,6e4);pt.push((function(){clearInterval(r)}))}((function(){return r.expandSession()})),{findActiveSession:function(e){return o.find(e)},renewObservable:r.renewObservable,expireObservable:r.expireObservable}}var vt;function gt(e){var t=ht(e.cookieOptions,"logs",(function(t){return function(e,t){var n=function(e){return e===vt.NOT_TRACKED||e===vt.TRACKED}(t)?t:mt(e);return{trackingType:n,isTracked:n===vt.TRACKED}}(e,t)}));return{findTrackedSession:function(e){var n=t.findActiveSession(e);return n&&n.trackingType===vt.TRACKED?{id:n.id}:void 0}}}function mt(e){return 0!==(t=e.sampleRate)&&100*Math.random()<=t?vt.TRACKED:vt.NOT_TRACKED;var t}function yt(e){var t=window.DD_RUM;return t&&t.getInternalContext?t.getInternalContext(e):void 0}!function(e){e.NOT_TRACKED="0",e.TRACKED="1"}(vt||(vt={}));var bt,wt,xt,St,Et=function(t){var n,i,o=!1,s=re(),u={},a=new ue,c=function(e,t){a.add((function(){return c(e,t)}))},f=function(){},l=new Ne(d);return n={logger:l,init:W((function(n){if(j()&&(n=function(t){return e(e({},t),{clientToken:"empty"})}(n)),function(e){return!o||(e.silentMultipleInit||r.error("DD_LOGS is already initialized."),!1)}(n)){var i=function(t){var n=Te(t,Re);if(n)return e(e({},n),{forwardErrorsToLogs:!!t.forwardErrorsToLogs})}(n);i&&(c=t(i,l),f=function(){return k(void 0,n)},a.drain(),o=!0)}})),getLoggerGlobalContext:W(s.get),setLoggerGlobalContext:W(s.set),addLoggerGlobalContext:W(s.add),removeLoggerGlobalContext:W(s.remove),createLogger:W((function(t,n){return void 0===n&&(n={}),u[t]=new Ne(d,n.handler,n.level,e(e({},n.context),{logger:{name:t}})),u[t]})),getLogger:W((function(e){return u[e]})),getInitConfiguration:W((function(){return f()}))},i=e(e({},n),{onReady:function(e){e()}}),Object.defineProperty(i,"_setDebug",{get:function(){return ee},enumerable:!1}),i;function d(e){c(e,T({date:Date.now(),view:{referrer:document.referrer,url:window.location.href}},s.get()))}}((function(e,t){var n=J(e),i=new _e;return e.forwardErrorsToLogs&&(je(i),Ge(i),function(e,t){var n=Je().subscribe((function(e){"complete"===e.state&&i(d.XHR,e)})),r=Ye().subscribe((function(e){"complete"===e.state&&i(d.FETCH,e)}));function i(n,r){e.isIntakeUrl(r.url)||!function(e){return 0===e.status&&"opaque"!==e.responseType}(r)&&!function(e){return e.status>=500}(r)||t.notify({message:tt(n)+" error "+r.method+" "+r.url,resource:{method:r.method,statusCode:r.status,url:r.url},source:B,stack:et(r.responseText,e)||"Failed to load",startClocks:r.startClocks})}}(e,i)),function(e,t,n,r,i){n.setExternalContextProvider((function(){var e;return T({session_id:null===(e=r.findTrackedSession())||void 0===e?void 0:e.id},yt(),{view:{name:null,url:null,referrer:null}})}));var o,s=function(e,t,n){var r=(i=Me.error,o=t.maxErrorsPerMinute,s=n,u=0,a=!1,{isLimitReached:function(){if(0===u&&setTimeout((function(){u=0}),h),(u+=1)<=o||a)return a=!1,!1;if(u===o+1){a=!0;try{s({message:"Reached max number of "+i+"s by minute: "+o,source:R,startClocks:pe()})}finally{a=!1}}return!0}});var i,o,s,u,a;return function(n,i){var o=n.date?n.date-ve():void 0,s=e.findTrackedSession(o);if(s){var u=T({service:t.service,session_id:s.id},i,yt(o),n);if(!(t.beforeSend&&!1===t.beforeSend(u)||u.status===Me.error&&r.isLimitReached()))return u}}}(r,e,c);if(j()){var u=_();o=function(e){return u.send("log",e)}}else{var a=function(e){var t,n=r(e.logsEndpointBuilder);function r(t){return new U(new F(t,e.batchBytesLimit),e.maxBatchSize,e.batchBytesLimit,e.maxMessageSize,e.flushTimeout)}return void 0!==e.replica&&(t=r(e.replica.logsEndpointBuilder)),{add:function(e){n.add(e),t&&t.add(e)}}}(e);o=function(e){return a.add(e)}}function c(e){i.error(e.message,T({date:e.startClocks.timeStamp,error:{kind:e.type,origin:e.source,stack:e.stack}},e.resource?{http:{method:e.resource.method,status_code:e.resource.statusCode,url:e.resource.url}}:void 0))}return t.subscribe(c),function(e,t){var n=s(e,t);n&&o(n)}}(e,i,n,function(e){if(void 0===document.cookie||null===document.cookie)return!1;try{var t="dd_cookie_test_"+g(),n="test";ae(t,n,p,e);var i=ce(t)===n;return fe(t,e),i}catch(e){return r.error(e),!1}}(e.cookieOptions)&&!j()?gt(e):function(e){var t=mt(e)===vt.TRACKED?{}:void 0;return{findTrackedSession:function(){return t}}}(e),t)}));bt=function(){if("object"==typeof globalThis)return globalThis;Object.defineProperty(Object.prototype,"_dd_temp_",{get:function(){return this},configurable:!0});var e=_dd_temp_;return delete Object.prototype._dd_temp_,"object"!=typeof e&&(e="object"==typeof self?self:"object"==typeof window?window:{}),e}(),xt=Et,St=bt[wt="DD_LOGS"],bt[wt]=xt,St&&St.q&&St.q.forEach((function(e){return ne(e,"onReady callback threw an error:")()}))}();
!function(){"use strict";var e=function(){return(e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)};function t(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}}function n(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;var r=Array(e),i=0;for(t=0;t<n;t++)for(var o=arguments[t],s=0,u=o.length;s<u;s++,i++)r[i]=o[s];return r}var r={log:console.log.bind(console),warn:console.warn.bind(console),error:console.error.bind(console)},i="?";function o(e,t){var n,r=void 0===t?0:+t;try{if(n=function(e){var t=a(e,"stacktrace");if(!t)return;for(var n,r=/ line (\d+).*script (?:in )?(\S+)(?:: in function (\S+))?$/i,o=/ line (\d+), column (\d+)\s*(?:in (?:<anonymous function: ([^>]+)>|([^)]+))\((.*)\))? in (.*):\s*$/i,s=t.split("\n"),u=[],c=0;c<s.length;c+=2){var f=void 0;r.exec(s[c])?f={args:[],column:void 0,func:(n=r.exec(s[c]))[3],line:+n[1],url:n[2]}:o.exec(s[c])&&(f={args:(n=o.exec(s[c]))[5]?n[5].split(","):[],column:+n[2],func:n[3]||n[4],line:+n[1],url:n[6]}),f&&(!f.func&&f.line&&(f.func=i),f.context=[s[c+1]],u.push(f))}if(!u.length)return;return{stack:u,message:a(e,"message"),name:a(e,"name")}}(e))return n}catch(e){if(s)throw e}try{if(n=function(e){var t=a(e,"stack");if(!t)return;for(var n,r,o,s,u=/^\s*at (.*?) ?\(((?:file|https?|blob|chrome-extension|native|eval|webpack|<anonymous>|\/).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,c=/^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|resource|capacitor|\[native).*?|[^@]*bundle)(?::(\d+))?(?::(\d+))?\s*$/i,l=/^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i,d=/(\S+) line (\d+)(?: > eval line \d+)* > eval/i,p=/\((\S*)(?::(\d+))(?::(\d+))\)/,v=t.split("\n"),h=[],g=0,m=v.length;g<m;g+=1){if(u.exec(v[g])){var y=(o=u.exec(v[g]))[2]&&0===o[2].indexOf("native");n=o[2]&&0===o[2].indexOf("eval"),r=p.exec(o[2]),n&&r&&(o[2]=r[1],o[3]=r[2],o[4]=r[3]),s={args:y?[o[2]]:[],column:o[4]?+o[4]:void 0,func:o[1]||i,line:o[3]?+o[3]:void 0,url:y?void 0:o[2]}}else if(l.exec(v[g]))s={args:[],column:(o=l.exec(v[g]))[4]?+o[4]:void 0,func:o[1]||i,line:+o[3],url:o[2]};else{if(!c.exec(v[g]))continue;n=(o=c.exec(v[g]))[3]&&o[3].indexOf(" > eval")>-1,r=d.exec(o[3]),n&&r?(o[3]=r[1],o[4]=r[2],o[5]=void 0):0!==g||o[5]||f(e.columnNumber)||(h[0].column=e.columnNumber+1),s={args:o[2]?o[2].split(","):[],column:o[5]?+o[5]:void 0,func:o[1]||i,line:o[4]?+o[4]:void 0,url:o[3]}}!s.func&&s.line&&(s.func=i),h.push(s)}if(!h.length)return;return{stack:h,message:a(e,"message"),name:a(e,"name")}}(e))return n}catch(e){if(s)throw e}try{if(n=function(e){var t=a(e,"message");if(!t)return;var n=t.split("\n");if(n.length<4)return;var r,o=/^\s*Line (\d+) of linked script ((?:file|https?|blob)\S+)(?:: in function (\S+))?\s*$/i,s=/^\s*Line (\d+) of inline#(\d+) script in ((?:file|https?|blob)\S+)(?:: in function (\S+))?\s*$/i,u=/^\s*Line (\d+) of function script\s*$/i,f=[],l=window&&window.document&&window.document.getElementsByTagName("script"),d=[];for(var p in l)c(l,p)&&!l[p].src&&d.push(l[p]);for(var v=2;v<n.length;v+=2){var h=void 0;if(o.exec(n[v]))h={args:[],column:void 0,func:(r=o.exec(n[v]))[3],line:+r[1],url:r[2]};else if(s.exec(n[v]))h={args:[],column:void 0,func:(r=s.exec(n[v]))[4],line:+r[1],url:r[3]};else if(u.exec(n[v])){r=u.exec(n[v]),h={url:window.location.href.replace(/#.*$/,""),args:[],column:void 0,func:"",line:+r[1]}}h&&(h.func||(h.func=i),h.context=[n[v+1]],f.push(h))}if(!f.length)return;return{stack:f,message:n[0],name:a(e,"name")}}(e))return n}catch(e){if(s)throw e}try{if(n=u(e,r+1))return n}catch(e){if(s)throw e}return{message:a(e,"message"),name:a(e,"name"),stack:[]}}var s=!1;function u(e,t){for(var n,r,s=/function\s+([_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*)?\s*\(/i,c=[],f={},l=!1,d=u.caller;d&&!l;d=d.caller)d!==o&&(r={args:[],column:void 0,func:i,line:void 0,url:void 0},n=s.exec(d.toString()),d.name?r.func=d.name:n&&(r.func=n[1]),void 0===r.func&&(r.func=n?n.input.substring(0,n.input.indexOf("{")):void 0),f[d.toString()]?l=!0:f[d.toString()]=!0,c.push(r));t&&c.splice(0,t);var p={stack:c,message:a(e,"message"),name:a(e,"name")};return function(e,t,n){var r={url:t,line:n?+n:void 0};if(r.url&&r.line){e.incomplete=!1;var i=e.stack;if(i.length>0&&i[0].url===r.url){if(i[0].line===r.line)return!1;if(!i[0].line&&i[0].func===r.func)return i[0].line=r.line,i[0].context=r.context,!1}return i.unshift(r),e.partial=!0,!0}e.incomplete=!0}(p,a(e,"sourceURL")||a(e,"fileName"),a(e,"line")||a(e,"lineNumber")),p}function a(e,t){if("object"==typeof e&&e&&t in e){var n=e[t];return"string"==typeof n?n:void 0}}function c(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function f(e){return void 0===e}var l,d,p=1e3,v=6e4;function h(e,t,n){var r,i,o=!n||void 0===n.leading||n.leading,s=!n||void 0===n.trailing||n.trailing,u=!1;return{throttled:function(){for(var n=[],a=0;a<arguments.length;a++)n[a]=arguments[a];u?r=n:(o?e.apply(void 0,n):r=n,u=!0,i=setTimeout((function(){s&&r&&e.apply(void 0,r),u=!1,r=void 0}),t))},cancel:function(){clearTimeout(i),u=!1,r=void 0}}}function g(e){return e?(parseInt(e,10)^16*Math.random()>>parseInt(e,10)/4).toString(16):"10000000-1000-4000-8000-100000000000".replace(/[018]/g,g)}function m(){}function y(e,t,n){if(null==e)return JSON.stringify(e);var r=[!1,void 0];b(e)&&(r=[!0,e.toJSON],delete e.toJSON);var i,o,s=[!1,void 0];"object"==typeof e&&b(i=Object.getPrototypeOf(e))&&(s=[!0,i.toJSON],delete i.toJSON);try{o=JSON.stringify(e,t,n)}catch(e){o="<error: unable to serialize object>"}finally{r[0]&&(e.toJSON=r[1]),s[0]&&(i.toJSON=s[1])}return o}function b(e){return"object"==typeof e&&null!==e&&Object.prototype.hasOwnProperty.call(e,"toJSON")}function w(e,t){return-1!==e.indexOf(t)}function x(e){return Object.keys(e).map((function(t){return e[t]}))}function S(e,t,n,r){return k(e,[t],n,r)}function k(e,t,n,r){var i=void 0===r?{}:r,o=i.once,s=i.capture,u=i.passive,a=V(o?function(e){f(),n(e)}:n),c=u?{capture:s,passive:u}:s;t.forEach((function(t){return e.addEventListener(t,a,c)}));var f=function(){return t.forEach((function(t){return e.removeEventListener(t,a,c)}))};return{stop:f}}function E(e,t,n){if(void 0===n&&(n=function(){if("undefined"!=typeof WeakSet){var e=new WeakSet;return{hasAlreadyBeenSeen:function(t){var n=e.has(t);return n||e.add(t),n}}}var t=[];return{hasAlreadyBeenSeen:function(e){var n=t.indexOf(e)>=0;return n||t.push(e),n}}}()),void 0===t)return e;if("object"!=typeof t||null===t)return t;if(t instanceof Date)return new Date(t.getTime());if(t instanceof RegExp){var r=t.flags||[t.global?"g":"",t.ignoreCase?"i":"",t.multiline?"m":"",t.sticky?"y":"",t.unicode?"u":""].join("");return new RegExp(t.source,r)}if(!n.hasAlreadyBeenSeen(t)){if(Array.isArray(t)){for(var i=Array.isArray(e)?e:[],o=0;o<t.length;++o)i[o]=E(i[o],t[o],n);return i}var s,u="object"==(null===(s=e)?"null":Array.isArray(s)?"array":typeof s)?e:{};for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&(u[a]=E(u[a],t[a],n));return u}}function T(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];for(var r=0,i=t;r<i.length;r++){var o=i[r];null!=o&&(e=E(e,o))}return e}!function(e){e.DOCUMENT="document",e.XHR="xhr",e.BEACON="beacon",e.FETCH="fetch",e.CSS="css",e.JS="js",e.IMAGE="image",e.FONT="font",e.MEDIA="media",e.OTHER="other"}(l||(l={})),function(e){e.FETCH="fetch",e.XHR="xhr"}(d||(d={}));var O,C,R="agent",L="console",M="logger",B="network",A="source";function N(e){var t=D(e);return e.stack.forEach((function(e){var n="?"===e.func?"<anonymous>":e.func,r=e.args&&e.args.length>0?"("+e.args.join(", ")+")":"",i=e.line?":"+e.line:"",o=e.line&&e.column?":"+e.column:"";t+="\n at "+n+r+" @ "+e.url+i+o})),t}function D(e){return(e.name||"Error")+": "+e.message}function I(){var e,t=new Error;if(!t.stack)try{throw t}catch(e){}return Y((function(){var n=o(t);n.stack=n.stack.slice(2),e=N(n)})),e}function _(e){return!!C&&C.has(e)}function j(){var e=_("event-bridge")?window.DatadogEventBridge:null;if(e)return{getAllowedWebViewHosts:function(){return JSON.parse(e.getAllowedWebViewHosts())},send:function(t,n){e.send(JSON.stringify({eventType:t,event:n}))}}}function z(){var e=j();return!!e&&w(e.getAllowedWebViewHosts(),window.location.hostname)}!function(e){e.HANDLED="handled",e.UNHANDLED="unhandled"}(O||(O={}));var U,P=/[^\u0000-\u007F]/,H=function(){function e(e,t,n,r,i,o){void 0===o&&(o=m),this.request=e,this.maxSize=t,this.bytesLimit=n,this.maxMessageSize=r,this.flushTimeout=i,this.beforeUnloadCallback=o,this.pushOnlyBuffer=[],this.upsertBuffer={},this.bufferBytesSize=0,this.bufferMessageCount=0,this.flushOnVisibilityHidden(),this.flushPeriodically()}return e.prototype.add=function(e){this.addOrUpdate(e)},e.prototype.upsert=function(e,t){this.addOrUpdate(e,t)},e.prototype.flush=function(e){if(0!==this.bufferMessageCount){var t=n(this.pushOnlyBuffer,x(this.upsertBuffer));this.request.send(t.join("\n"),this.bufferBytesSize,e),this.pushOnlyBuffer=[],this.upsertBuffer={},this.bufferBytesSize=0,this.bufferMessageCount=0}},e.prototype.sizeInBytes=function(e){return P.test(e)?void 0!==window.TextEncoder?(new TextEncoder).encode(e).length:new Blob([e]).size:e.length},e.prototype.addOrUpdate=function(e,t){var n=this.process(e),i=n.processedMessage,o=n.messageBytesSize;o>=this.maxMessageSize?r.warn("Discarded a message whose size was bigger than the maximum allowed size "+this.maxMessageSize+"KB."):(this.hasMessageFor(t)&&this.remove(t),this.willReachedBytesLimitWith(o)&&this.flush("willReachedBytesLimitWith"),this.push(i,o,t),this.isFull()&&this.flush("isFull"))},e.prototype.process=function(e){var t=y(e);return{processedMessage:t,messageBytesSize:this.sizeInBytes(t)}},e.prototype.push=function(e,t,n){this.bufferMessageCount>0&&(this.bufferBytesSize+=1),void 0!==n?this.upsertBuffer[n]=e:this.pushOnlyBuffer.push(e),this.bufferBytesSize+=t,this.bufferMessageCount+=1},e.prototype.remove=function(e){var t=this.upsertBuffer[e];delete this.upsertBuffer[e];var n=this.sizeInBytes(t);this.bufferBytesSize-=n,this.bufferMessageCount-=1,this.bufferMessageCount>0&&(this.bufferBytesSize-=1)},e.prototype.hasMessageFor=function(e){return void 0!==e&&void 0!==this.upsertBuffer[e]},e.prototype.willReachedBytesLimitWith=function(e){return this.bufferBytesSize+e+1>=this.bytesLimit},e.prototype.isFull=function(){return this.bufferMessageCount===this.maxSize||this.bufferBytesSize>=this.bytesLimit},e.prototype.flushPeriodically=function(){var e=this;setTimeout(V((function(){e.flush("flushPeriodically"),e.flushPeriodically()})),this.flushTimeout)},e.prototype.flushOnVisibilityHidden=function(){var e=this;navigator.sendBeacon&&(S(window,"beforeunload",this.beforeUnloadCallback),S(document,"visibilitychange",(function(){"hidden"===document.visibilityState&&e.flush("visibilitychange")})),S(window,"beforeunload",(function(){return e.flush("beforeunload")})))},e}(),F=!1,q=function(){function e(e,t){this.endpointBuilder=e,this.bytesLimit=t}return e.prototype.send=function(e,t,n){var r=this.endpointBuilder.build(),i=!!navigator.sendBeacon&&t<this.bytesLimit;if(i)try{if(navigator.sendBeacon(r,e))return}catch(e){!function(e){$||($=!0,Q(e))}(e)}var o=new XMLHttpRequest;o.addEventListener("loadend",V((function(e){return function(e){var o=null==e?void 0:e.currentTarget;o.status>=200&&o.status<300||F||(F=!0,Z("XHR fallback failed",{on_line:navigator.onLine,size:t,url:r,try_beacon:i,flush_reason:n,event:{is_trusted:e.isTrusted,total:e.total,loaded:e.loaded},request:{status:o.status,ready_state:o.readyState,response_text:o.responseText.slice(0,512)}}))}(e)}))),o.open("POST",r,!0),o.send(e)},e}(),$=!1;!function(e){e.info="info",e.error="error"}(U||(U={}));var G,K,J={maxMessagesPerPage:0,sentMessageCount:0};function X(e){var t;if(z()){var n=j();G=function(e){return n.send("internal_log",i(e))}}else if(e.internalMonitoringEndpointBuilder){var r=function(e){var t,n=r(e.internalMonitoringEndpointBuilder);function r(t){return new H(new q(t,e.batchBytesLimit),e.maxBatchSize,e.batchBytesLimit,e.maxMessageSize,e.flushTimeout)}return void 0!==e.replica&&(t=r(e.replica.internalMonitoringEndpointBuilder)),{add:function(e){n.add(e),t&&t.add(e)}}}(e);G=function(e){return r.add(i(e))}}function i(e){return T({date:(new Date).getTime()},void 0!==t?t():{},e)}return function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];t.forEach((function(t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}))}(J,{maxMessagesPerPage:e.maxInternalMonitoringMessagesPerPage,sentMessageCount:0}),{setExternalContextProvider:function(e){t=e}}}function W(e,t,n){var r=n.value;n.value=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=G?V(r):r;return n.apply(this,e)}}function V(e){return function(){return Y(e,this,arguments)}}function Y(e,t,n){try{return e.apply(t,n)}catch(e){ne(e);try{Q(e)}catch(e){ne(e)}}}function Z(t,n){!function(e,t){J.debugMode&&r.log("[MONITORING MESSAGE]",e,t)}(t,n),ee(e(e({message:t},n),{status:U.info}))}function Q(t){ee(e(e({},function(e){if(e instanceof Error){var t=o(e);return{error:{kind:t.name,stack:N(t)},message:t.message}}return{error:{stack:"Not an instance of error"},message:"Uncaught "+y(e)}}(t)),{status:U.error}))}function ee(e){G&&J.sentMessageCount<J.maxMessagesPerPage&&(J.sentMessageCount+=1,G(e))}function te(e){J.debugMode=e}function ne(e){J.debugMode&&r.error("[INTERNAL ERROR]",e)}function re(e,t){return function(){for(var n=[],i=0;i<arguments.length;i++)n[i]=arguments[i];try{return e.apply(void 0,n)}catch(e){r.error(t,e)}}}function ie(){var e={};return{get:function(){return e},add:function(t,n){e[t]=n},remove:function(t){delete e[t]},set:function(t){e=t}}}!function(e){e.RELEASE="release",e.CANARY="canary",e.E2E_TEST="e2e-test"}(K||(K={}));var oe,se,ue,ae=function(){function e(){this.buffer=[]}return e.prototype.add=function(e){this.buffer.push(e)>500&&this.buffer.splice(0,1)},e.prototype.drain=function(){this.buffer.forEach((function(e){return e()})),this.buffer.length=0},e}();function ce(e,t,n,r){var i=new Date;i.setTime(i.getTime()+n);var o="expires="+i.toUTCString(),s=r&&r.crossSite?"none":"strict",u=r&&r.domain?";domain="+r.domain:"",a=r&&r.secure?";secure":"";document.cookie=e+"="+t+";"+o+";path=/;samesite="+s+u+a}function fe(e){return function(e,t){var n=new RegExp("(?:^|;)\\s*"+t+"\\s*=\\s*([^;]+)").exec(e);return n?n[1]:void 0}(document.cookie,e)}function le(e,t){ce(e,"",0,t)}function de(){return Date.now()}function pe(){return performance.now()}function ve(){return{relative:pe(),timeStamp:de()}}function he(e,t){return t-e}function ge(){return void 0===se&&(se=performance.timing.navigationStart),se}function me(e){return ye(e,function(e){if(e.origin)return e.origin;var t=e.host.replace(/(:80|:443)$/,"");return e.protocol+"//"+t}(window.location)).href}function ye(e,t){if(function(){if(void 0!==ue)return ue;try{var e=new URL("http://test/path");return ue="http://test/path"===e.href}catch(e){ue=!1}return ue}())return void 0!==t?new URL(e,t):new URL(e);if(void 0===t&&!/:/.test(e))throw new Error("Invalid URL: '"+e+"'");var n=document,r=n.createElement("a");if(void 0!==t){var i=(n=document.implementation.createHTMLDocument("")).createElement("base");i.href=t,n.head.appendChild(i),n.body.appendChild(r)}return r.href=e,r}var be={logs:"logs",rum:"rum",sessionReplay:"session-replay"},we={logs:"logs",rum:"rum",sessionReplay:"replay"},xe="datadoghq.com";function Se(e,t,n,r,i){var o=e.site,s=void 0===o?xe:o,u=e.clientToken,a=s.split("."),c=a.pop(),f="https://"+(be[n]+".browser-intake-"+a.join("-")+"."+c)+"/api/v2/"+we[n],l=e.proxyUrl&&me(e.proxyUrl);return{build:function(){var e="ddsource="+(i||"browser")+"&ddtags="+encodeURIComponent(["sdk_version:"+t.sdkVersion].concat(r).join(","))+"&dd-api-key="+u+"&dd-evp-origin-version="+encodeURIComponent(t.sdkVersion)+"&dd-evp-origin=browser&dd-request-id="+g();"rum"===n&&(e+="&batch_time="+de());var o=f+"?"+e;return l?l+"?ddforward="+encodeURIComponent(o):o},buildIntakeUrl:function(){return l?l+"?ddforward":f}}}var ke=/[^a-z0-9_:./-]/;function Ee(e,t){var n=200-e.length-1;return(t.length>n||ke.test(t))&&r.warn(e+" value doesn't meet tag requirements and will be sanitized"),e+":"+t.replace(/,/g,"_")}function Te(t,n){var r=function(e){var t=e.env,n=e.service,r=e.version,i=e.datacenter,o=[];return t&&o.push(Ee("env",t)),n&&o.push(Ee("service",n)),r&&o.push(Ee("version",r)),i&&o.push(Ee("datacenter",i)),o}(t),i=function(t,n,r){if(n.buildMode===K.E2E_TEST){var i=function(e){return{build:function(){return e},buildIntakeUrl:function(){return e}}};return{logsEndpointBuilder:i("<<< E2E LOGS ENDPOINT >>>"),rumEndpointBuilder:i("<<< E2E RUM ENDPOINT >>>"),sessionReplayEndpointBuilder:i("<<< E2E SESSION REPLAY ENDPOINT >>>"),internalMonitoringEndpointBuilder:i("<<< E2E INTERNAL MONITORING ENDPOINT >>>")}}var o={logsEndpointBuilder:Se(t,n,"logs",r),rumEndpointBuilder:Se(t,n,"rum",r),sessionReplayEndpointBuilder:Se(t,n,"sessionReplay",r)};if(t.internalMonitoringApiKey)return e(e({},o),{internalMonitoringEndpointBuilder:Se(e(e({},t),{clientToken:t.internalMonitoringApiKey}),n,"logs",r,"browser-agent-internal-monitoring")});return o}(t,n,r),o=x(i).map((function(e){return e.buildIntakeUrl()})),s=function(t,n,r,i){if(!t.replica)return;var o=e(e({},t),{site:xe,clientToken:t.replica.clientToken}),s={logsEndpointBuilder:Se(o,n,"logs",i),rumEndpointBuilder:Se(o,n,"rum",i),internalMonitoringEndpointBuilder:Se(o,n,"logs",i,"browser-agent-internal-monitoring")};return r.push.apply(r,x(s).map((function(e){return e.buildIntakeUrl()}))),e({applicationId:t.replica.applicationId},s)}(t,n,o,r);return e(e({isIntakeUrl:function(e){return o.some((function(t){return 0===e.indexOf(t)}))}},i),{replica:s})}function Oe(t,n){var i;if(t&&t.clientToken){var o,s;if(void 0===t.sampleRate||function(e){return"number"==typeof e}(o=t.sampleRate)&&o>=0&&o<=100)return s=t.enableExperimentalFeatures,Array.isArray(s)&&(C||(C=new Set(s)),s.filter((function(e){return"string"==typeof e})).forEach((function(e){C.add(e)}))),e(e({},Te(t,n)),{beforeSend:t.beforeSend&&re(t.beforeSend,"beforeSend threw an error:"),cookieOptions:Ce(t),sampleRate:null!==(i=t.sampleRate)&&void 0!==i?i:100,service:t.service,silentMultipleInit:!!t.silentMultipleInit,batchBytesLimit:16384,eventRateLimiterThreshold:3e3,maxInternalMonitoringMessagesPerPage:15,requestErrorResponseLengthLimit:32768,flushTimeout:3e4,maxBatchSize:50,maxMessageSize:262144});r.error("Sample Rate should be a number between 0 and 100")}else r.error("Client Token is not configured, we will not send any data.")}function Ce(e){var t={};return t.secure=function(e){return!!e.useSecureSessionCookie||!!e.useCrossSiteSessionCookie}(e),t.crossSite=!!e.useCrossSiteSessionCookie,e.trackSessionAcrossSubdomains&&(t.domain=function(){if(void 0===oe){for(var e="dd_site_test_"+g(),t=window.location.hostname.split("."),n=t.pop();t.length&&!fe(e);)n=t.pop()+"."+n,ce(e,"test",p,{domain:n});le(e,{domain:n}),oe=n}return oe}()),t}var Re,Le={buildMode:"release",sdkVersion:"4.1.0"};var Me={debug:"debug",error:"error",info:"info",warn:"warn"},Be=((Re={})[Me.debug]=0,Re[Me.info]=1,Re[Me.warn]=2,Re[Me.error]=3,Re),Ae=(Object.keys(Me),"console"),Ne="http",De=function(){function t(e,t,n,r){void 0===t&&(t=Ne),void 0===n&&(n=Me.debug),void 0===r&&(r={}),this.sendLog=e,this.handlerType=t,this.level=n,this.contextManager=ie(),this.contextManager.set(r)}return t.prototype.log=function(t,n,i){if(void 0===i&&(i=Me.info),Be[i]>=Be[this.level]){var o=Array.isArray(this.handlerType)?this.handlerType:[this.handlerType];w(o,Ne)&&this.sendLog(e({message:t,status:i},T(this.contextManager.get(),n))),w(o,Ae)&&r.log(i+": "+t,T(this.contextManager.get(),n))}},t.prototype.debug=function(e,t){this.log(e,t,Me.debug)},t.prototype.info=function(e,t){this.log(e,t,Me.info)},t.prototype.warn=function(e,t){this.log(e,t,Me.warn)},t.prototype.error=function(e,t){var n={error:{origin:M}};this.log(e,T(n,t),Me.error)},t.prototype.setContext=function(e){this.contextManager.set(e)},t.prototype.addContext=function(e,t){this.contextManager.add(e,t)},t.prototype.removeContext=function(e){this.contextManager.remove(e)},t.prototype.setHandler=function(e){this.handlerType=e},t.prototype.setLevel=function(e){this.level=e},function(e,t,n,r){var i,o=arguments.length,s=o<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var u=e.length-1;u>=0;u--)(i=e[u])&&(s=(o<3?i(s):o>3?i(t,n,s):i(t,n))||s);o>3&&s&&Object.defineProperty(t,n,s)}([W],t.prototype,"log",null),t}();var Ie,_e,je=function(){function e(e){this.onFirstSubscribe=e,this.observers=[]}return e.prototype.subscribe=function(e){var t=this;return!this.observers.length&&this.onFirstSubscribe&&(this.onLastUnsubscribe=this.onFirstSubscribe()||void 0),this.observers.push(e),{unsubscribe:function(){t.observers=t.observers.filter((function(t){return e!==t})),!t.observers.length&&t.onLastUnsubscribe&&t.onLastUnsubscribe()}}},e.prototype.notify=function(e){this.observers.forEach((function(t){return t(e)}))},e}();function ze(t){(function(){_e||(_e=new je,Ie=console.error,console.error=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var r=I();Y((function(){Ie.apply(console,t);var n=e(e({},Ue(t,r)),{source:L,startClocks:ve(),handling:O.HANDLED});_e.notify(n)}))});return _e})().subscribe((function(e){return t.notify(e)}))}function Ue(e,t){var r=function(e,t){for(var n=0;n<e.length;n+=1){var r=e[n];if(t(r,n,e))return r}}(e,(function(e){return e instanceof Error}));return{message:n(["console error:"],e).map((function(e){return function(e){if("string"==typeof e)return e;if(e instanceof Error)return D(o(e));return y(e,void 0,2)}(e)})).join(" "),stack:r?N(o(r)):void 0,handlingStack:t}}function Pe(e,t,n){var r=e[t],i=n(r),o=function(){return i.apply(this,arguments)};return e[t]=o,{stop:function(){e[t]===o?e[t]=r:i=r}}}function He(e,t,n){var r=n.before,i=n.after;return Pe(e,t,(function(e){return function(){var t,n=arguments;return r&&Y(r,this,n),"function"==typeof e&&(t=e.apply(this,n)),i&&Y(i,this,n),t}}))}var Fe,qe=/^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/;function $e(e){var t=function(e){return He(window,"onerror",{before:function(t,n,r,i,s){var u;if(s)u=o(s),e(u,s);else{var a,c={url:n,column:i,line:r},f=t;if("[object String]"==={}.toString.call(t)){var l=qe.exec(f);l&&(a=l[1],f=l[2])}e(u={name:a,message:"string"==typeof f?f:void 0,stack:[c]},t)}}})}(e).stop,n=function(e){return He(window,"onunhandledrejection",{before:function(t){var n=t.reason||"Empty reason",r=o(n);e(r,n)}})}(e).stop;return{stop:function(){t(),n()}}}function Ge(e){return $e((function(t,n){var r=function(e,t,n,r){return e&&(void 0!==e.message||t instanceof Error)?{message:e.message||"Empty message",stack:N(e),handlingStack:r,type:e.name}:{message:n+" "+y(t),stack:"No stack, consider using an instance of Error",handlingStack:r,type:e&&e.name}}(t,n,"Uncaught"),i=r.stack,o=r.message,s=r.type;e.notify({message:o,stack:i,type:s,source:A,startClocks:ve(),originalError:n,handling:O.UNHANDLED})}))}function Ke(e,t,n){var r=0,i=!1;return{isLimitReached:function(){if(0===r&&setTimeout((function(){r=0}),v),(r+=1)<=t||i)return i=!1,!1;if(r===t+1){i=!0;try{n({message:"Reached max number of "+e+"s by minute: "+t,source:R,startClocks:ve()})}finally{i=!1}}return!0}}}var Je,Xe=new WeakMap;function We(){var e;return Fe||(e=new je((function(){var t=He(XMLHttpRequest.prototype,"open",{before:Ve}).stop,n=He(XMLHttpRequest.prototype,"send",{before:function(){Ye.call(this,e)}}).stop,r=He(XMLHttpRequest.prototype,"abort",{before:Ze}).stop;return function(){t(),n(),r()}})),Fe=e),Fe}function Ve(e,t){Xe.set(this,{state:"open",method:e,url:me(t)})}function Ye(t){var n=this,r=Xe.get(this);if(r){var i=r;i.state="start",i.startTime=pe(),i.startClocks=ve(),i.isAborted=!1,i.xhr=this;var o=!1,s=He(this,"onreadystatechange",{before:function(){this.readyState===XMLHttpRequest.DONE&&u()}}).stop,u=V((function(){if(n.removeEventListener("loadend",u),s(),!o){o=!0;var a=r;a.state="complete",a.duration=he(i.startClocks.timeStamp,de()),a.responseText=n.response,a.status=n.status,t.notify(e({},a))}}));this.addEventListener("loadend",u),t.notify(i)}}function Ze(){var e=Xe.get(this);e&&(e.isAborted=!0)}function Qe(){var e;return Je||(e=new je((function(){if(window.fetch)return Pe(window,"fetch",(function(t){return function(n,r){var i,o=Y(et,null,[e,n,r]);return o?(i=t.call(this,o.input,o.init),Y(tt,null,[e,i,o])):i=t.call(this,n,r),i}})).stop})),Je=e),Je}function et(e,t,n){var r=n&&n.method||"object"==typeof t&&t.method||"GET",i=me("object"==typeof t&&t.url||t),o={state:"start",init:n,input:t,method:r,startClocks:ve(),url:i};return e.notify(o),o}function tt(e,n,r){var i=this,s=function(n){return s=i,u=void 0,c=function(){var i,s,u;return t(this,(function(t){switch(t.label){case 0:return(i=r).state="complete",i.duration=he(i.startClocks.timeStamp,de()),"stack"in n||n instanceof Error?(i.status=0,i.responseText=N(o(n)),i.isAborted=n instanceof DOMException&&n.code===DOMException.ABORT_ERR,i.error=n,e.notify(i),[3,6]):[3,1];case 1:if(!("status"in n))return[3,6];s=void 0,t.label=2;case 2:return t.trys.push([2,4,,5]),[4,n.clone().text()];case 3:return s=t.sent(),[3,5];case 4:return u=t.sent(),s="Unable to retrieve response: "+u,[3,5];case 5:i.response=n,i.responseText=s,i.responseType=n.type,i.status=n.status,i.isAborted=!1,e.notify(i),t.label=6;case 6:return[2]}}))},new((a=void 0)||(a=Promise))((function(e,t){function n(e){try{i(c.next(e))}catch(e){t(e)}}function r(e){try{i(c.throw(e))}catch(e){t(e)}}function i(t){t.done?e(t.value):new a((function(e){e(t.value)})).then(n,r)}i((c=c.apply(s,u||[])).next())}));var s,u,a,c};n.then(V(s),V(s))}function nt(e,t){return e&&e.length>t.requestErrorResponseLengthLimit?e.substring(0,t.requestErrorResponseLengthLimit)+"...":e}function rt(e){return d.XHR===e?"XHR":"Fetch"}var it=function(){function e(e){var t=this;this.expireDelay=e,this.previousContexts=[],this.clearOldContextsInterval=setInterval((function(){return t.clearOldContexts()}),6e4)}return e.prototype.find=function(e){if(void 0===e||void 0!==this.current&&void 0!==this.currentStart&&e>=this.currentStart)return this.current;for(var t=0,n=this.previousContexts;t<n.length;t++){var r=n[t];if(e>r.endTime)break;if(e>=r.startTime)return r.context}},e.prototype.setCurrent=function(e,t){this.current=e,this.currentStart=t},e.prototype.getCurrent=function(){return this.current},e.prototype.clearCurrent=function(){this.current=void 0,this.currentStart=void 0},e.prototype.closeCurrent=function(e){void 0!==this.current&&void 0!==this.currentStart&&(this.previousContexts.unshift({endTime:e,context:this.current,startTime:this.currentStart}),this.clearCurrent())},e.prototype.clearOldContexts=function(){for(var e=pe()-this.expireDelay;this.previousContexts.length>0&&this.previousContexts[this.previousContexts.length-1].startTime<e;)this.previousContexts.pop()},e.prototype.reset=function(){this.clearCurrent(),this.previousContexts=[]},e.prototype.stop=function(){clearInterval(this.clearOldContextsInterval)},e}(),ot=9e5,st=144e5;function ut(e,t,n){var r=new je,i=new je,o=setInterval(V((function(){pt({options:e,process:function(e){return f(e)?void 0:{}},after:u})})),1e3),s=function(){var e=yt();if(f(e))return e;return{}}();function u(e){return f(e)||(e={}),a()&&(!function(e){if(s.id!==e.id)return e.id&&f(s)&&c(e,"different id"),!0;if(s[t]!==e[t])return c(e,"different tracking type"),!0;return!1}(e)?s=e:(s={},i.notify())),e}function a(){return void 0!==s[t]}function c(e,n){Z("Session inconsistencies detected",{debug:{productKey:t,sessionCache:s,cookieSession:e,cause:n}})}function f(e){return(void 0===e.created||Date.now()-Number(e.created)<st)&&(void 0===e.expire||Date.now()<Number(e.expire))}return{expandOrRenewSession:h(V((function(){var i;pt({options:e,process:function(e){var r=u(e);return i=function(e){var r=n(e[t]),i=r.trackingType,o=r.isTracked;e[t]=i,o&&!e.id&&(e.id=g(),e.created=String(Date.now()));return o}(r),r},after:function(e){i&&!a()&&function(e){s=e,r.notify()}(e),s=e}})})),1e3).throttled,expandSession:function(){pt({options:e,process:function(e){return a()?u(e):void 0}})},getSession:function(){return s},renewObservable:r,expireObservable:i,stop:function(){clearInterval(o)}}}var at,ct=/^([a-z]+)=([a-z0-9-]+)$/,ft="&",lt="_dd_s",dt=[];function pt(e,t){var n;if(void 0===t&&(t=0),at||(at=e),e===at){if(t>=50)return Z("Reach max lock retry"),void ht();var r,i=yt();if(_("cookie-lock")){if(i.lock)return void vt(e,t);if(r=g(),i.lock=r,mt(i,e.options),(i=yt()).lock!==r)return void vt(e,t)}var o=e.process(i);if(_("cookie-lock")&&(i=yt()).lock!==r)vt(e,t);else{if(o&&gt(o,e.options),_("cookie-lock")&&(!o||!bt(o))){if((i=yt()).lock!==r)return void vt(e,t);delete i.lock,mt(i,e.options),o=i}null===(n=e.after)||void 0===n||n.call(e,o||i),ht()}}else dt.push(e)}function vt(e,t){setTimeout(V((function(){pt(e,t+1)})),10)}function ht(){at=void 0;var e=dt.shift();e&&pt(e)}function gt(e,t){bt(e)?function(e){ce(lt,"",0,e)}(t):(e.expire=String(Date.now()+ot),mt(e,t))}function mt(e,t){ce(lt,function(e){return(t=e,Object.keys(t).map((function(e){return[e,t[e]]}))).map((function(e){return e[0]+"="+e[1]})).join(ft);var t}(e),ot,t)}function yt(){var e=fe(lt),t={};return function(e){return void 0!==e&&(-1!==e.indexOf(ft)||ct.test(e))}(e)&&e.split(ft).forEach((function(e){var n=ct.exec(e);if(null!==n){var r=n[1],i=n[2];t[r]=i}})),t}function bt(e){return t=e,0===Object.keys(t).length;var t}var wt=[];function xt(e,t,n){!function(e){var t=fe(lt),n=fe("_dd"),r=fe("_dd_r"),i=fe("_dd_l");if(!t){var o={};n&&(o.id=n),i&&/^[01]$/.test(i)&&(o.logs=i),r&&/^[012]$/.test(r)&&(o.rum=r),gt(o,e)}}(e);var r=ut(e,t,n);wt.push((function(){return r.stop()}));var i,o=new it(144e5);function s(){return{id:r.getSession().id,trackingType:r.getSession()[t]}}return wt.push((function(){return o.stop()})),r.renewObservable.subscribe((function(){o.setCurrent(s(),pe())})),r.expireObservable.subscribe((function(){o.closeCurrent(pe())})),r.expandOrRenewSession(),o.setCurrent(s(),[0,ge()][0]),i=k(window,["click","touchstart","keydown","scroll"],(function(){return r.expandOrRenewSession()}),{capture:!0,passive:!0}).stop,wt.push(i),function(e){var t=V((function(){"visible"===document.visibilityState&&e()})),n=S(document,"visibilitychange",t).stop;wt.push(n);var r=setInterval(t,6e4);wt.push((function(){clearInterval(r)}))}((function(){return r.expandSession()})),{findActiveSession:function(e){return o.find(e)},renewObservable:r.renewObservable,expireObservable:r.expireObservable}}var St;function kt(e){var t=xt(e.cookieOptions,"logs",(function(t){return function(e,t){var n=function(e){return e===St.NOT_TRACKED||e===St.TRACKED}(t)?t:Et(e);return{trackingType:n,isTracked:n===St.TRACKED}}(e,t)}));return{findTrackedSession:function(e){var n=t.findActiveSession(e);return n&&n.trackingType===St.TRACKED?{id:n.id}:void 0}}}function Et(e){return 0!==(t=e.sampleRate)&&100*Math.random()<=t?St.TRACKED:St.NOT_TRACKED;var t}function Tt(e){var t=window.DD_RUM;return t&&t.getInternalContext?t.getInternalContext(e):void 0}!function(e){e.NOT_TRACKED="0",e.TRACKED="1"}(St||(St={}));var Ot,Ct,Rt,Lt,Mt=function(t){var n,i,o=!1,s=ie(),u={},a=new ae,c=function(e,t){a.add((function(){return c(e,t)}))},f=function(){},l=new De(d);return n={logger:l,init:V((function(n){if(z()&&(n=function(t){return e(e({},t),{clientToken:"empty"})}(n)),function(e){return!o||(e.silentMultipleInit||r.error("DD_LOGS is already initialized."),!1)}(n)){var i=function(t){var n=Oe(t,Le);if(n)return e(e({},n),{forwardErrorsToLogs:!!t.forwardErrorsToLogs})}(n);i&&(c=t(i,l),f=function(){return E(void 0,n)},a.drain(),o=!0)}})),getLoggerGlobalContext:V(s.get),setLoggerGlobalContext:V(s.set),addLoggerGlobalContext:V(s.add),removeLoggerGlobalContext:V(s.remove),createLogger:V((function(t,n){return void 0===n&&(n={}),u[t]=new De(d,n.handler,n.level,e(e({},n.context),{logger:{name:t}})),u[t]})),getLogger:V((function(e){return u[e]})),getInitConfiguration:V((function(){return f()}))},i=e(e({},n),{onReady:function(e){e()}}),Object.defineProperty(i,"_setDebug",{get:function(){return te},enumerable:!1}),i;function d(e){c(e,T({date:Date.now(),view:{referrer:document.referrer,url:window.location.href}},s.get()))}}((function(e,t){var n=X(e),i=new je;return e.forwardErrorsToLogs&&(ze(i),Ge(i),function(e,t){var n=We().subscribe((function(e){"complete"===e.state&&i(d.XHR,e)})),r=Qe().subscribe((function(e){"complete"===e.state&&i(d.FETCH,e)}));function i(n,r){e.isIntakeUrl(r.url)||!function(e){return 0===e.status&&"opaque"!==e.responseType}(r)&&!function(e){return e.status>=500}(r)||t.notify({message:rt(n)+" error "+r.method+" "+r.url,resource:{method:r.method,statusCode:r.status,url:r.url},source:B,stack:nt(r.responseText,e)||"Failed to load",startClocks:r.startClocks})}}(e,i)),function(e,t,n,r,i){n.setExternalContextProvider((function(){var e;return T({session_id:null===(e=r.findTrackedSession())||void 0===e?void 0:e.id},Tt(),{view:{name:null,url:null,referrer:null}})}));var o,s=function(e,t,n){var r,i=((r={})[Me.error]=Ke(Me.error,t.eventRateLimiterThreshold,n),r[Me.warn]=Ke(Me.warn,t.eventRateLimiterThreshold,n),r[Me.info]=Ke(Me.info,t.eventRateLimiterThreshold,n),r[Me.debug]=Ke(Me.debug,t.eventRateLimiterThreshold,n),r.custom=Ke("custom",t.eventRateLimiterThreshold,n),r);return function(n,r){var o,s,u=n.date?n.date-ge():void 0,a=e.findTrackedSession(u);if(a){var c=T({service:t.service,session_id:a.id},r,Tt(u),n);if(!1!==(null===(o=t.beforeSend)||void 0===o?void 0:o.call(t,c))&&!(null!==(s=i[c.status])&&void 0!==s?s:i.custom).isLimitReached())return c}}}(r,e,c);if(z()){var u=j();o=function(e){return u.send("log",e)}}else{var a=function(e){var t,n=r(e.logsEndpointBuilder);function r(t){return new H(new q(t,e.batchBytesLimit),e.maxBatchSize,e.batchBytesLimit,e.maxMessageSize,e.flushTimeout)}return void 0!==e.replica&&(t=r(e.replica.logsEndpointBuilder)),{add:function(e){n.add(e),t&&t.add(e)}}}(e);o=function(e){return a.add(e)}}function c(e){i.error(e.message,T({date:e.startClocks.timeStamp,error:{kind:e.type,origin:e.source,stack:e.stack}},e.resource?{http:{method:e.resource.method,status_code:e.resource.statusCode,url:e.resource.url}}:void 0))}return t.subscribe(c),function(e,t){var n=s(e,t);n&&o(n)}}(e,i,n,function(e){if(void 0===document.cookie||null===document.cookie)return!1;try{var t="dd_cookie_test_"+g(),n="test";ce(t,n,p,e);var i=fe(t)===n;return le(t,e),i}catch(e){return r.error(e),!1}}(e.cookieOptions)&&!z()?kt(e):function(e){var t=Et(e)===St.TRACKED?{}:void 0;return{findTrackedSession:function(){return t}}}(e),t)}));Ot=function(){if("object"==typeof globalThis)return globalThis;Object.defineProperty(Object.prototype,"_dd_temp_",{get:function(){return this},configurable:!0});var e=_dd_temp_;return delete Object.prototype._dd_temp_,"object"!=typeof e&&(e="object"==typeof self?self:"object"==typeof window?window:{}),e}(),Rt=Mt,Lt=Ot[Ct="DD_LOGS"],Ot[Ct]=Rt,Lt&&Lt.q&&Lt.q.forEach((function(e){return re(e,"onReady callback threw an error:")()}))}();

@@ -6,4 +6,4 @@ "use strict";

buildMode: 'release',
sdkVersion: '4.0.1',
sdkVersion: '4.1.0',
};
//# sourceMappingURL=buildEnv.js.map

@@ -68,4 +68,12 @@ "use strict";

function buildAssemble(sessionManager, configuration, reportError) {
var errorRateLimiter = browser_core_1.createEventRateLimiter(logger_1.StatusType.error, configuration.maxErrorsPerMinute, reportError);
var _a;
var logRateLimiters = (_a = {},
_a[logger_1.StatusType.error] = browser_core_1.createEventRateLimiter(logger_1.StatusType.error, configuration.eventRateLimiterThreshold, reportError),
_a[logger_1.StatusType.warn] = browser_core_1.createEventRateLimiter(logger_1.StatusType.warn, configuration.eventRateLimiterThreshold, reportError),
_a[logger_1.StatusType.info] = browser_core_1.createEventRateLimiter(logger_1.StatusType.info, configuration.eventRateLimiterThreshold, reportError),
_a[logger_1.StatusType.debug] = browser_core_1.createEventRateLimiter(logger_1.StatusType.debug, configuration.eventRateLimiterThreshold, reportError),
_a['custom'] = browser_core_1.createEventRateLimiter('custom', configuration.eventRateLimiterThreshold, reportError),
_a);
return function (message, currentContext) {
var _a, _b;
var startTime = message.date ? browser_core_1.getRelativeTime(message.date) : undefined;

@@ -77,8 +85,6 @@ var session = sessionManager.findTrackedSession(startTime);

var contextualizedMessage = browser_core_1.combine({ service: configuration.service, session_id: session.id }, currentContext, getRUMInternalContext(startTime), message);
if (configuration.beforeSend && configuration.beforeSend(contextualizedMessage) === false) {
if (((_a = configuration.beforeSend) === null || _a === void 0 ? void 0 : _a.call(configuration, contextualizedMessage)) === false ||
((_b = logRateLimiters[contextualizedMessage.status]) !== null && _b !== void 0 ? _b : logRateLimiters['custom']).isLimitReached()) {
return undefined;
}
if (contextualizedMessage.status === logger_1.StatusType.error && errorRateLimiter.isLimitReached()) {
return undefined;
}
return contextualizedMessage;

@@ -85,0 +91,0 @@ };

export var buildEnv = {
buildMode: 'release',
sdkVersion: '4.0.1',
sdkVersion: '4.1.0',
};
//# sourceMappingURL=buildEnv.js.map

@@ -63,4 +63,12 @@ import { areCookiesAuthorized, combine, createEventRateLimiter, Observable, trackRuntimeError, trackConsoleError, canUseEventBridge, getEventBridge, getRelativeTime, startInternalMonitoring, } from '@datadog/browser-core';

export function buildAssemble(sessionManager, configuration, reportError) {
var errorRateLimiter = createEventRateLimiter(StatusType.error, configuration.maxErrorsPerMinute, reportError);
var _a;
var logRateLimiters = (_a = {},
_a[StatusType.error] = createEventRateLimiter(StatusType.error, configuration.eventRateLimiterThreshold, reportError),
_a[StatusType.warn] = createEventRateLimiter(StatusType.warn, configuration.eventRateLimiterThreshold, reportError),
_a[StatusType.info] = createEventRateLimiter(StatusType.info, configuration.eventRateLimiterThreshold, reportError),
_a[StatusType.debug] = createEventRateLimiter(StatusType.debug, configuration.eventRateLimiterThreshold, reportError),
_a['custom'] = createEventRateLimiter('custom', configuration.eventRateLimiterThreshold, reportError),
_a);
return function (message, currentContext) {
var _a, _b;
var startTime = message.date ? getRelativeTime(message.date) : undefined;

@@ -72,8 +80,6 @@ var session = sessionManager.findTrackedSession(startTime);

var contextualizedMessage = combine({ service: configuration.service, session_id: session.id }, currentContext, getRUMInternalContext(startTime), message);
if (configuration.beforeSend && configuration.beforeSend(contextualizedMessage) === false) {
if (((_a = configuration.beforeSend) === null || _a === void 0 ? void 0 : _a.call(configuration, contextualizedMessage)) === false ||
((_b = logRateLimiters[contextualizedMessage.status]) !== null && _b !== void 0 ? _b : logRateLimiters['custom']).isLimitReached()) {
return undefined;
}
if (contextualizedMessage.status === StatusType.error && errorRateLimiter.isLimitReached()) {
return undefined;
}
return contextualizedMessage;

@@ -80,0 +86,0 @@ };

{
"name": "@datadog/browser-logs",
"version": "4.0.1",
"version": "4.1.0",
"license": "Apache-2.0",

@@ -16,3 +16,3 @@ "main": "cjs/entries/main.js",

"dependencies": {
"@datadog/browser-core": "4.0.1",
"@datadog/browser-core": "4.1.0",
"tslib": "^1.10.0"

@@ -29,3 +29,3 @@ },

},
"gitHead": "a24681d36c129ec6ae0a71f0758fe5833f7f7474"
"gitHead": "27c7b4c01354dd77116f5bfb6eef370d4e2585bd"
}

@@ -59,3 +59,3 @@ # Browser Log Collection

n=o.getElementsByTagName(u)[0];n.parentNode.insertBefore(d,n)
})(window,document,'script','https://www.datadoghq-browser-agent.com/datadog-logs-v3.js','DD_LOGS')
})(window,document,'script','https://www.datadoghq-browser-agent.com/datadog-logs-v4.js','DD_LOGS')
DD_LOGS.onReady(function() {

@@ -84,3 +84,3 @@ DD_LOGS.init({

<title>Example to send logs to Datadog</title>
<script type="text/javascript" src="https://www.datadoghq-browser-agent.com/datadog-logs-v3.js"></script>
<script type="text/javascript" src="https://www.datadoghq-browser-agent.com/datadog-logs-v4.js"></script>
<script>

@@ -87,0 +87,0 @@ window.DD_LOGS &&

@@ -343,5 +343,5 @@ import {

describe('error logs limitation', () => {
describe('logs limitation', () => {
let clock: Clock
const configuration = { eventRateLimiterThreshold: 1 }
beforeEach(() => {

@@ -354,58 +354,86 @@ clock = mockClock()

})
;[
{ status: StatusType.error, message: 'Reached max number of errors by minute: 1' },
{ status: StatusType.warn, message: 'Reached max number of warns by minute: 1' },
{ status: StatusType.info, message: 'Reached max number of infos by minute: 1' },
{ status: StatusType.debug, message: 'Reached max number of debugs by minute: 1' },
{ status: 'unknown' as StatusType, message: 'Reached max number of customs by minute: 1' },
].forEach(({ status, message }) => {
it(`stops sending ${status} logs when reaching the limit`, () => {
const sendLogSpy = jasmine.createSpy<(message: LogsMessage & { foo?: string }) => void>()
const sendLog = startLogs({ errorLogger: new Logger(sendLogSpy), configuration })
sendLog({ message: 'foo', status }, {})
sendLog({ message: 'bar', status }, {})
it('stops sending error logs when reaching the limit', () => {
const sendLogSpy = jasmine.createSpy<(message: LogsMessage & { foo?: string }) => void>()
const sendLog = startLogs({ errorLogger: new Logger(sendLogSpy), configuration: { maxErrorsPerMinute: 1 } })
sendLog({ message: 'foo', status: StatusType.error }, {})
sendLog({ message: 'bar', status: StatusType.error }, {})
expect(server.requests.length).toEqual(1)
expect(getLoggedMessage(server, 0).message).toBe('foo')
expect(sendLogSpy).toHaveBeenCalledOnceWith({
message: 'Reached max number of errors by minute: 1',
status: StatusType.error,
error: {
origin: ErrorSource.AGENT,
kind: undefined,
stack: undefined,
},
date: Date.now(),
expect(server.requests.length).toEqual(1)
expect(getLoggedMessage(server, 0).message).toBe('foo')
expect(sendLogSpy).toHaveBeenCalledOnceWith({
message,
status: StatusType.error,
error: {
origin: ErrorSource.AGENT,
kind: undefined,
stack: undefined,
},
date: Date.now(),
})
})
})
it('does not take discarded errors into account', () => {
const sendLogSpy = jasmine.createSpy<(message: LogsMessage & { foo?: string }) => void>()
const sendLog = startLogs({
errorLogger: new Logger(sendLogSpy),
configuration: {
maxErrorsPerMinute: 1,
beforeSend(event) {
if (event.message === 'discard me') {
return false
}
it(`does not take discarded ${status} logs into account`, () => {
const sendLogSpy = jasmine.createSpy<(message: LogsMessage & { foo?: string }) => void>()
const sendLog = startLogs({
errorLogger: new Logger(sendLogSpy),
configuration: {
...configuration,
beforeSend(event) {
if (event.message === 'discard me') {
return false
}
},
},
},
})
sendLog({ message: 'discard me', status }, {})
sendLog({ message: 'discard me', status }, {})
sendLog({ message: 'discard me', status }, {})
sendLog({ message: 'foo', status }, {})
expect(server.requests.length).toEqual(1)
expect(getLoggedMessage(server, 0).message).toBe('foo')
expect(sendLogSpy).not.toHaveBeenCalled()
})
sendLog({ message: 'discard me', status: StatusType.error }, {})
sendLog({ message: 'discard me', status: StatusType.error }, {})
sendLog({ message: 'discard me', status: StatusType.error }, {})
sendLog({ message: 'foo', status: StatusType.error }, {})
expect(server.requests.length).toEqual(1)
expect(getLoggedMessage(server, 0).message).toBe('foo')
expect(sendLogSpy).not.toHaveBeenCalled()
it(`allows to send new ${status}s after a minute`, () => {
const sendLog = startLogs({ configuration })
sendLog({ message: 'foo', status }, {})
sendLog({ message: 'bar', status }, {})
clock.tick(ONE_MINUTE)
sendLog({ message: 'baz', status }, {})
expect(server.requests.length).toEqual(2)
expect(getLoggedMessage(server, 0).message).toBe('foo')
expect(getLoggedMessage(server, 1).message).toBe('baz')
})
it('allows to send logs with a different status when reaching the limit', () => {
const otherLogStatus = status === StatusType.error ? 'other' : StatusType.error
const sendLog = startLogs({ configuration })
sendLog({ message: 'foo', status }, {})
sendLog({ message: 'bar', status }, {})
sendLog({ message: 'baz', status: otherLogStatus as StatusType }, {})
expect(server.requests.length).toEqual(2)
expect(getLoggedMessage(server, 0).message).toBe('foo')
expect(getLoggedMessage(server, 1).message).toBe('baz')
})
})
it('allows to send new errors after a minute', () => {
const sendLog = startLogs({ configuration: { maxErrorsPerMinute: 1 } })
sendLog({ message: 'foo', status: StatusType.error }, {})
sendLog({ message: 'bar', status: StatusType.error }, {})
clock.tick(ONE_MINUTE)
sendLog({ message: 'baz', status: StatusType.error }, {})
it('two different custom statuses are accounted by the same limit', () => {
const sendLog = startLogs({ configuration })
sendLog({ message: 'foo', status: 'foo' as StatusType }, {})
sendLog({ message: 'bar', status: 'bar' as StatusType }, {})
expect(server.requests.length).toEqual(2)
expect(server.requests.length).toEqual(1)
expect(getLoggedMessage(server, 0).message).toBe('foo')
expect(getLoggedMessage(server, 1).message).toBe('baz')
})
})
})

@@ -105,9 +105,18 @@ import {

) {
const errorRateLimiter = createEventRateLimiter(StatusType.error, configuration.maxErrorsPerMinute, reportError)
const logRateLimiters = {
[StatusType.error]: createEventRateLimiter(StatusType.error, configuration.eventRateLimiterThreshold, reportError),
[StatusType.warn]: createEventRateLimiter(StatusType.warn, configuration.eventRateLimiterThreshold, reportError),
[StatusType.info]: createEventRateLimiter(StatusType.info, configuration.eventRateLimiterThreshold, reportError),
[StatusType.debug]: createEventRateLimiter(StatusType.debug, configuration.eventRateLimiterThreshold, reportError),
['custom']: createEventRateLimiter('custom', configuration.eventRateLimiterThreshold, reportError),
}
return (message: LogsMessage, currentContext: Context) => {
const startTime = message.date ? getRelativeTime(message.date) : undefined
const session = sessionManager.findTrackedSession(startTime)
if (!session) {
return undefined
}
const contextualizedMessage = combine(

@@ -119,8 +128,10 @@ { service: configuration.service, session_id: session.id },

)
if (configuration.beforeSend && configuration.beforeSend(contextualizedMessage) === false) {
if (
configuration.beforeSend?.(contextualizedMessage) === false ||
(logRateLimiters[contextualizedMessage.status] ?? logRateLimiters['custom']).isLimitReached()
) {
return undefined
}
if (contextualizedMessage.status === StatusType.error && errorRateLimiter.isLimitReached()) {
return undefined
}
return contextualizedMessage as Context

@@ -127,0 +138,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc