@datadog/browser-rum
Advanced tools
Comparing version 1.25.1 to 1.25.2
@@ -1,1 +0,1 @@ | ||
!function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([,function(e,t,n){"use strict";n.r(t),n.d(t,"datadogRum",(function(){return Wn})),n.d(t,"makeRumGlobal",(function(){return jn}));var r=function(){return(r=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 i(e,t){var n,r,i,o,a={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(;a;)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 a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=(i=a.trys).length>0&&i[i.length-1])&&(6===o[0]||2===o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}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 o(){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],a=0,u=o.length;a<u;a++,i++)r[i]=o[a];return r}var a,u,s,c,f=1e3,d=60*f,l=60*d;function p(e,t,n){var r,i=!n||void 0===n.leading||n.leading,o=!n||void 0===n.trailing||n.trailing,a=!1,u=!1;return{throttled:function(){var n=this;a?u=!0:(i?e.apply(this):u=!0,a=!0,r=window.setTimeout((function(){o&&u&&e.apply(n),a=!1,u=!1}),t))},cancel:function(){window.clearTimeout(r),a=!1,u=!1}}}function E(e){return e?(parseInt(e,10)^16*Math.random()>>parseInt(e,10)/4).toString(16):(1e7+"-1000-4000-8000-100000000000").replace(/[018]/g,E)}function m(e){return 0!==e&&100*Math.random()<=e}function v(e){return"number"!=typeof e?e:+(1e6*e).toFixed(0)}function T(){}function h(e,t,n){if(null==e)return JSON.stringify(e);var r=[!1,void 0];g(e)&&(r=[!0,e.toJSON],delete e.toJSON);var i,o,a=[!1,void 0];"object"==typeof e&&g(i=Object.getPrototypeOf(e))&&(a=[!0,i.toJSON],delete i.toJSON);try{o=JSON.stringify(e,void 0,n)}catch(e){o="<error: unable to serialize object>"}finally{r[0]&&(e.toJSON=r[1]),a[0]&&(i.toJSON=a[1])}return o}function g(e){return"object"==typeof e&&null!==e&&e.hasOwnProperty("toJSON")}function y(e,t){return-1!==e.indexOf(t)}function C(e){return b(e)&&e>=0&&e<=100}function b(e){return"number"==typeof e}function _(e){return Math.floor(R()+e)}function R(){return void 0===c&&(c=performance.timing.navigationStart),c}function O(e){return Object.keys(e).map((function(t){return[t,e[t]]}))}function S(e){if(e.origin)return e.origin;var t=e.host.replace(/(:80|:443)$/,"");return e.protocol+"//"+t}function w(e,t){var n=e.match("(?:^|;)\\s*"+t+"\\s*=\\s*([^;]+)");return n?n[1]:void 0}!function(e){e.BEFORE_UNLOAD="beforeunload",e.CLICK="click",e.KEY_DOWN="keydown",e.LOAD="load",e.POP_STATE="popstate",e.SCROLL="scroll",e.TOUCH_START="touchstart",e.VISIBILITY_CHANGE="visibilitychange",e.DOM_CONTENT_LOADED="DOMContentLoaded"}(a||(a={})),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"}(u||(u={})),function(e){e.FETCH="fetch",e.XHR="xhr"}(s||(s={}));var A,I,L=f;function D(e,t,n,r){var i=new Date;i.setTime(i.getTime()+n);var o="expires="+i.toUTCString(),a=r&&r.crossSite?"none":"strict",u=r&&r.domain?";domain="+r.domain:"",s=r&&r.secure?";secure":"";document.cookie=e+"="+t+";"+o+";path=/;samesite="+a+u+s}function N(e){return w(document.cookie,e)}function x(e){return V(e,S(window.location)).href}function M(e,t){return U(e)===U(t)}function U(e){return S(V(e))}function k(e){var t=V(e).pathname;return"/"===t[0]?t:"/"+t}function V(e,t){if(function(){if(void 0!==I)return I;try{var e=new URL("http://test/path");return I="http://test/path"===e.href}catch(e){I=!1}return I}())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 B={allowedTracingOrigins:[],maxErrorsByMinute:3e3,maxInternalMonitoringMessagesPerPage:15,resourceSampleRate:100,sampleRate:100,silentMultipleInit:!1,trackInteractions:!1,requestErrorResponseLengthLimit:32768,flushTimeout:30*f,maxBatchSize:50,maxMessageSize:262144,batchBytesLimit:16384};function P(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===A){for(var e="dd_site_test_"+E(),t=window.location.hostname.split("."),n=t.pop();t.length&&!N(e);)n=t.pop()+"."+n,D(e,"test",f,{domain:n});A=n}return A}()),t}function H(e,t,n){var r="sdk_version:"+t.sdkVersion+(t.env?",env:"+t.env:"")+(t.service?",service:"+t.service:"")+(t.version?",version:"+t.version:""),i=e+"-http-intake.logs."+t.site,o=t.proxyHost?t.proxyHost:i,a=t.proxyHost?"ddhost="+i+"&":"",u=""+(t.applicationId?"_dd.application_id="+t.applicationId+"&":"")+a+"ddsource="+(n||"browser")+"&ddtags="+r;return"https://"+o+"/v1/input/"+t.clientToken+"?"+u}function W(e,t){return-1!==k(e).indexOf("/v1/input/")&&(M(e,t.logsEndpoint)||M(e,t.rumEndpoint)||M(e,t.traceEndpoint)||!!t.internalMonitoringEndpoint&&M(e,t.internalMonitoringEndpoint)||!!t.replica&&(M(e,t.replica.logsEndpoint)||M(e,t.replica.rumEndpoint)||M(e,t.replica.internalMonitoringEndpoint)))}function j(e){var t={};return Object.keys(e).forEach((function(n){var r;t[(r=n,r.replace(/[A-Z]/g,(function(e,t){return(0!==t?"_":"")+e.toLowerCase()})).replace(/-/g,"_"))]=function e(t){if(Array.isArray(t))return t.map((function(t){return e(t)}));if("object"==typeof t&&null!==t)return j(t);return t}(e[n])})),t}var F=function(e){return Array.isArray(e)},G=function(e){return!Array.isArray(e)&&"object"==typeof e&&null!==e};function q(){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,o,K()))}return e}function z(e){return $(void 0,e,K())}function K(){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}}}function $(e,t,n){if(void 0===t)return e;if(!G(t)&&!F(t))return t;if(!n.hasAlreadyBeenSeen(t)){if(G(t)&&(void 0===e||G(e))){var r=e||{};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(r[i]=$(r[i],t[i],n));return r}if(F(t)&&(void 0===e||F(e))){(r=e||[]).length=Math.max(r.length,t.length);for(var o=0;o<t.length;o+=1)r[o]=$(r[o],t[o],n);return r}return t}}var Y=/[^\u0000-\u007F]/,X=function(){function e(e,t,n){void 0===n&&(n=!1),this.endpointUrl=e,this.bytesLimit=t,this.withBatchTime=n}return e.prototype.send=function(e,t){var n=this.withBatchTime?function(e){return e+(-1===e.indexOf("?")?"?":"&")+"batch_time="+(new Date).getTime()}(this.endpointUrl):this.endpointUrl;if(navigator.sendBeacon&&t<this.bytesLimit&&navigator.sendBeacon(n,e))return;var r=new XMLHttpRequest;r.open("POST",n,!0),r.send(e)},e}();var J=function(){function e(e,t,n,r,i,o){void 0===o&&(o=T),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(){if(0!==this.bufferMessageCount){var e=o(this.pushOnlyBuffer,(t=this.upsertBuffer,n=[],Object.keys(t).forEach((function(e){n.push(t[e])})),n));this.request.send(e.join("\n"),this.bufferBytesSize),this.pushOnlyBuffer=[],this.upsertBuffer={},this.bufferBytesSize=0,this.bufferMessageCount=0}var t,n},e.prototype.sizeInBytes=function(e){return Y.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),r=n.processedMessage,i=n.messageBytesSize;i>=this.maxMessageSize?console.warn("Discarded a message whose size was bigger than the maximum allowed size "+this.maxMessageSize+"KB."):(this.hasMessageFor(t)&&this.remove(t),this.willReachedBytesLimitWith(i)&&this.flush(),this.push(r,i,t),this.isFull()&&this.flush())},e.prototype.process=function(e){var t=h(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((function(){e.flush(),e.flushPeriodically()}),this.flushTimeout)},e.prototype.flushOnVisibilityHidden=function(){var e=this;navigator.sendBeacon&&(window.addEventListener(a.BEFORE_UNLOAD,ce(this.beforeUnloadCallback)),document.addEventListener(a.VISIBILITY_CHANGE,ce((function(){"hidden"===document.visibilityState&&e.flush()}))),window.addEventListener(a.BEFORE_UNLOAD,ce((function(){return e.flush()}))))},e}(),Q="?",Z=/^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/;function ee(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var te,ne=function(){var e,t,n,r,i,o,a=[];function u(e,t,n){var r;for(var i in a)if(ee(a,i))try{a[i](e,t,n)}catch(e){r=e}if(r)throw r}function s(e,r,i,o,a){if(t)re.augmentStackTraceWithInitialElement(t,r,i,""+e),f();else if(a)u(re(a),!0,a);else{var s,c={url:r,column:o,line:i},d=e;if("[object String]"==={}.toString.call(e)){var l=d.match(Z);l&&(s=l[1],d=l[2])}u({name:s,message:d,stack:[c]},!0)}return!!n&&n.apply(this,arguments)}function c(e){var t=e.reason||"Empty reason";u(re(t),!0,t)}function f(){var n=t,r=e;t=void 0,e=void 0,u(n,!1,r)}function d(n){if(t){if(e===n)return;f()}var r=re(n);throw t=r,e=n,setTimeout((function(){e===n&&f()}),r.incomplete?2e3:0),n}return d.subscribe=function(e){!function(){if(r)return;n=window.onerror,window.onerror=ce(s),r=!0}(),function(){if(o)return;i=null!==window.onunhandledrejection?window.onunhandledrejection:void 0,window.onunhandledrejection=ce(c),o=!0}(),a.push(e)},d.unsubscribe=function(e){for(var t=a.length-1;t>=0;t-=1)a[t]===e&&a.splice(t,1);0===a.length&&(r&&(window.onerror=n,r=!1),o&&(window.onunhandledrejection=i,o=!1))},d.traceKitWindowOnError=s,d}(),re=function(){var e=!1;function t(e){if(e.stack){for(var t,n,r,i,o=/^\s*at (.*?) ?\(((?:file|https?|blob|chrome-extension|native|eval|webpack|<anonymous>|\/).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,a=/^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|resource|\[native).*?|[^@]*bundle)(?::(\d+))?(?::(\d+))?\s*$/i,u=/^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i,s=/(\S+) line (\d+)(?: > eval line \d+)* > eval/i,c=/\((\S*)(?::(\d+))(?::(\d+))\)/,f=e.stack.split("\n"),d=[],l=0,p=f.length;l<p;l+=1){if(o.exec(f[l])){var E=(r=o.exec(f[l]))[2]&&0===r[2].indexOf("native");t=r[2]&&0===r[2].indexOf("eval"),n=c.exec(r[2]),t&&n&&(r[2]=n[1],r[3]=n[2],r[4]=n[3]),i={args:E?[r[2]]:[],column:r[4]?+r[4]:void 0,func:r[1]||Q,line:r[3]?+r[3]:void 0,url:E?void 0:r[2]}}else if(u.exec(f[l]))i={args:[],column:(r=u.exec(f[l]))[4]?+r[4]:void 0,func:r[1]||Q,line:+r[3],url:r[2]};else{if(!a.exec(f[l]))continue;t=(r=a.exec(f[l]))[3]&&r[3].indexOf(" > eval")>-1,n=s.exec(r[3]),t&&n?(r[3]=n[1],r[4]=n[2],r[5]=void 0):0!==l||r[5]||void 0===e.columnNumber||(d[0].column=e.columnNumber+1),i={args:r[2]?r[2].split(","):[],column:r[5]?+r[5]:void 0,func:r[1]||Q,line:r[4]?+r[4]:void 0,url:r[3]}}!i.func&&i.line&&(i.func=Q),d.push(i)}if(d.length)return{stack:d,message:e.message,name:e.name}}}function n(e,t,n,r){var i={url:t,line:n?+n:void 0};if(i.url&&i.line){e.incomplete=!1;var o=e.stack;if(o.length>0&&o[0].url===i.url){if(o[0].line===i.line)return!1;if(!o[0].line&&o[0].func===i.func)return o[0].line=i.line,o[0].context=i.context,!1}return o.unshift(i),e.partial=!0,!0}return e.incomplete=!0,!1}function r(e,t){for(var i,o,a=/function\s+([_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*)?\s*\(/i,u=[],s={},c=!1,f=r.caller;f&&!c;f=f.caller)f!==re&&f!==ne&&(o={args:[],column:void 0,func:Q,line:void 0,url:void 0},i=a.exec(f.toString()),f.name?o.func=f.name:i&&(o.func=i[1]),void 0===o.func&&(o.func=i?i.input.substring(0,i.input.indexOf("{")):void 0),s[""+f]?c=!0:s[""+f]=!0,u.push(o));t&&u.splice(0,t);var d={stack:u,message:e.message,name:e.name};return n(d,e.sourceURL||e.fileName,e.line||e.lineNumber,e.message||e.description),d}function i(n,i){var o,a=void 0===i?0:+i;try{if(o=function(e){var t=e.stacktrace;if(t){for(var n,r=/ line (\d+).*script (?:in )?(\S+)(?:: in function (\S+))?$/i,i=/ line (\d+), column (\d+)\s*(?:in (?:<anonymous function: ([^>]+)>|([^\)]+))\((.*)\))? in (.*):\s*$/i,o=t.split("\n"),a=[],u=0;u<o.length;u+=2){var s=void 0;r.exec(o[u])?s={args:[],column:void 0,func:(n=r.exec(o[u]))[3],line:+n[1],url:n[2]}:i.exec(o[u])&&(s={args:(n=i.exec(o[u]))[5]?n[5].split(","):[],column:+n[2],func:n[3]||n[4],line:+n[1],url:n[6]}),s&&(!s.func&&s.line&&(s.func=Q),s.context=[o[u+1]],a.push(s))}if(a.length)return{stack:a,message:e.message,name:e.name}}}(n))return o}catch(t){if(e)throw t}try{if(o=t(n))return o}catch(t){if(e)throw t}try{if(o=function(e){var t=e.message.split("\n");if(!(t.length<4)){var n,r=/^\s*Line (\d+) of linked script ((?:file|https?|blob)\S+)(?:: in function (\S+))?\s*$/i,i=/^\s*Line (\d+) of inline#(\d+) script in ((?:file|https?|blob)\S+)(?:: in function (\S+))?\s*$/i,o=/^\s*Line (\d+) of function script\s*$/i,a=[],u=window&&window.document&&window.document.getElementsByTagName("script"),s=[];for(var c in u)ee(u,c)&&!u[c].src&&s.push(u[c]);for(var f=2;f<t.length;f+=2){var d=void 0;if(r.exec(t[f]))d={args:[],column:void 0,func:(n=r.exec(t[f]))[3],line:+n[1],url:n[2]};else if(i.exec(t[f]))d={args:[],column:void 0,func:(n=i.exec(t[f]))[4],line:+n[1],url:n[3]};else if(o.exec(t[f])){n=o.exec(t[f]),d={url:window.location.href.replace(/#.*$/,""),args:[],column:void 0,func:"",line:+n[1]}}d&&(d.func||(d.func=Q),d.context=[t[f+1]],a.push(d))}if(a.length)return{stack:a,message:t[0],name:e.name}}}(n))return o}catch(t){if(e)throw t}try{if(o=r(n,a+1))return o}catch(t){if(e)throw t}return{message:n.message,name:n.name,stack:[]}}return i.augmentStackTraceWithInitialElement=n,i.computeStackTraceFromStackProp=t,i.ofCaller=function(e){var t=1+(void 0===e?0:+e);try{throw new Error}catch(e){return re(e,t+1)}},i}();!function(e){e.info="info",e.error="error"}(te||(te={}));var ie,oe,ae,ue={maxMessagesPerPage:0,sentMessageCount:0};function se(e){if(e.internalMonitoringEndpoint){var t=function(e){var t,n=r(e.internalMonitoringEndpoint);void 0!==e.replica&&(t=r(e.replica.internalMonitoringEndpoint));function r(t){return new J(new X(t,e.batchBytesLimit),e.maxBatchSize,e.batchBytesLimit,e.maxMessageSize,e.flushTimeout)}return{add:function(e){var r=function(e){return q({date:(new Date).getTime(),view:{referrer:document.referrer,url:window.location.href}},void 0!==ie?ie():{},e)}(e);n.add(r),t&&t.add(r)}}}(e);!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])}))}(ue,{batch:t,maxMessagesPerPage:e.maxInternalMonitoringMessagesPerPage,sentMessageCount:0})}return{setExternalContextProvider:function(e){ie=e}}}function ce(e){return function(){try{return e.apply(this,arguments)}catch(e){Ee(e);try{de(e)}catch(e){Ee(e)}}}}function fe(e,t){!function(e){ue.debugMode&&console.log("[MONITORING MESSAGE]",e)}(e),le(r(r({message:e},t),{status:te.info}))}function de(e){le(r(r({},function(e){if(e instanceof Error){var t=re(e);return{error:{kind:t.name,stack:Me(t)},message:t.message}}return{error:{stack:"Not an instance of error"},message:"Uncaught "+h(e)}}(e)),{status:te.error}))}function le(e){ue.batch&&ue.sentMessageCount<ue.maxMessagesPerPage&&(ue.sentMessageCount+=1,ue.batch.add(e))}function pe(e){ue.debugMode=e}function Ee(e){ue.debugMode&&console.warn("[INTERNAL ERROR]",e)}var me,ve=[],Te=[];function he(){return oe||(!function(){if(!window.fetch)return;ae=window.fetch,window.fetch=ce((function(e,t){var n=this,r=t&&t.method||"object"==typeof e&&e.method||"GET",o=x("object"==typeof e&&e.url||e),a={init:t,method:r,startTime:performance.now(),url:o},u=function(e){return t=n,r=void 0,u=function(){var t,n;return i(this,(function(r){switch(r.label){case 0:return a.duration=performance.now()-a.startTime,"stack"in e||e instanceof Error?(a.status=0,a.response=Me(re(e)),Te.forEach((function(e){return e(a)})),[3,6]):[3,1];case 1:if(!("status"in e))return[3,6];t=void 0,r.label=2;case 2:return r.trys.push([2,4,,5]),[4,e.clone().text()];case 3:return t=r.sent(),[3,5];case 4:return n=r.sent(),t="Unable to retrieve response: "+n,[3,5];case 5:a.response=t,a.responseType=e.type,a.status=e.status,Te.forEach((function(e){return e(a)})),r.label=6;case 6:return[2]}}))},new((o=void 0)||(o=Promise))((function(e,n){function i(e){try{s(u.next(e))}catch(e){n(e)}}function a(e){try{s(u.throw(e))}catch(e){n(e)}}function s(t){t.done?e(t.value):new o((function(e){e(t.value)})).then(i,a)}s((u=u.apply(t,r||[])).next())}));var t,r,o,u};ve.forEach((function(e){return e(a)}));var s=ae.call(this,e,a.init);return s.then(ce(u),ce(u)),s}))}(),oe={beforeSend:function(e){ve.push(e)},onRequestComplete:function(e){Te.push(e)}}),oe}var ge,ye,Ce=[],be=[];function _e(){return me||(ge=XMLHttpRequest.prototype.open,ye=XMLHttpRequest.prototype.send,XMLHttpRequest.prototype.open=ce((function(e,t){return this._datadog_xhr={method:e,startTime:-1,url:x(t)},ge.apply(this,arguments)})),XMLHttpRequest.prototype.send=ce((function(e){var t=this;if(this._datadog_xhr){this._datadog_xhr.startTime=performance.now();var n=this.onreadystatechange;this.onreadystatechange=function(){this.readyState===XMLHttpRequest.DONE&&ce(i)(),n&&n.apply(this,arguments)};var r=!1,i=function(){r||(r=!0,t._datadog_xhr.duration=performance.now()-t._datadog_xhr.startTime,t._datadog_xhr.response=t.response,t._datadog_xhr.status=t.status,be.forEach((function(e){return e(t._datadog_xhr)})))};this.addEventListener("loadend",ce(i)),Ce.forEach((function(e){return e(t._datadog_xhr,t)}))}return ye.apply(this,arguments)})),me={beforeSend:function(e){Ce.push(e)},onRequestComplete:function(e){be.push(e)}}),me}var Re,Oe,Se,we,Ae,Ie,Le=function(){function e(){this.observers=[]}return e.prototype.subscribe=function(e){this.observers.push(e)},e.prototype.notify=function(e){this.observers.forEach((function(t){return t(e)}))},e}();function De(e){if(!Oe){var t=new Le;!function(e,t){function n(n,r){W(r.url,e)||!function(e){return 0===e.status&&"opaque"!==e.responseType}(r)&&!function(e){return e.status>=500}(r)||t.notify({message:ke(n)+" error "+r.method+" "+r.url,resource:{method:r.method,statusCode:r.status,url:r.url},source:Re.NETWORK,stack:Ue(r.response,e)||"Failed to load",startTime:r.startTime})}_e().onRequestComplete((function(e){return n(s.XHR,e)})),he().onRequestComplete((function(e){return n(s.FETCH,e)}))}(e,t),function(e){Se=console.error,console.error=ce((function(t){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];Se.apply(console,o([t],n)),e.notify({message:o(["console error:",t],n).map(Ne).join(" "),source:Re.CONSOLE,startTime:performance.now()})}))}(t),function(e){we=function(t,n,r){var i=xe(t,r,"Uncaught"),o=i.stack,a=i.message,u=i.type;e.notify({message:a,stack:o,type:u,source:Re.SOURCE,startTime:performance.now()})},ne.subscribe(we)}(t),Oe=function(e,t){var n=0,r=new Le;return t.subscribe((function(t){n<e.maxErrorsByMinute?(n+=1,r.notify(t)):n===e.maxErrorsByMinute&&(n+=1,r.notify({message:"Reached max number of errors by minute: "+e.maxErrorsByMinute,source:Re.AGENT,startTime:performance.now()}))})),setInterval((function(){return n=0}),d),r}(e,t)}return Oe}function Ne(e){return"string"==typeof e?e:e instanceof Error?Me(re(e)):h(e,0,2)}function xe(e,t,n){return e&&(void 0!==e.message||t instanceof Error)?{message:e.message||"Empty message",stack:Me(e),type:e.name}:{message:n+" "+h(t),stack:"No stack, consider using an instance of Error",type:e&&e.name}}function Me(e){var t=(e.name||"Error")+": "+e.message;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 Ue(e,t){return e&&e.length>t.requestErrorResponseLengthLimit?e.substring(0,t.requestErrorResponseLengthLimit)+"...":e}function ke(e){return s.XHR===e?"XHR":"Fetch"}!function(e){e.AGENT="agent",e.CONSOLE="console",e.NETWORK="network",e.SOURCE="source",e.LOGGER="logger",e.CUSTOM="custom"}(Re||(Re={})),function(e){e.US="us",e.EU="eu"}(Ie||(Ie={}));var Ve,Be=((Ae={})[Ie.EU]="datadoghq.eu",Ae[Ie.US]="datadoghq.com",Ae);function Pe(e,t,n){var i=function(e,t){var n={applicationId:e.applicationId,buildMode:t.buildMode,clientToken:e.clientToken,env:e.env,proxyHost:e.proxyHost,sdkVersion:t.sdkVersion,service:e.service,site:e.site||Be[e.datacenter||t.datacenter],version:e.version},i=Array.isArray(e.enableExperimentalFeatures)?e.enableExperimentalFeatures:[],o=r({cookieOptions:P(e),isEnabled:function(e){return y(i,e)},logsEndpoint:H("browser",n),proxyHost:e.proxyHost,rumEndpoint:H("rum",n),service:e.service,traceEndpoint:H("public-trace",n)},B);if(e.internalMonitoringApiKey&&(o.internalMonitoringEndpoint=H("browser",n,"browser-agent-internal-monitoring")),"allowedTracingOrigins"in e&&(o.allowedTracingOrigins=e.allowedTracingOrigins),"sampleRate"in e&&(o.sampleRate=e.sampleRate),"resourceSampleRate"in e&&(o.resourceSampleRate=e.resourceSampleRate),"trackInteractions"in e&&(o.trackInteractions=!!e.trackInteractions),n.buildMode===Ve.E2E_TEST&&(o.internalMonitoringEndpoint="<<< E2E INTERNAL MONITORING ENDPOINT >>>",o.logsEndpoint="<<< E2E LOGS ENDPOINT >>>",o.rumEndpoint="<<< E2E RUM ENDPOINT >>>"),n.buildMode===Ve.STAGING&&void 0!==e.replica){var a=r(r({},n),{applicationId:e.replica.applicationId,clientToken:e.replica.clientToken,site:Be[Ie.US]});o.replica={applicationId:e.replica.applicationId,internalMonitoringEndpoint:H("browser",a,"browser-agent-internal-monitoring"),logsEndpoint:H("browser",a),rumEndpoint:H("rum",a)}}return o}(e,t),o=se(i);return{configuration:i,errorObservable:n?De(i):new Le,internalMonitoring:o}}function He(e){return!!function(e){if(void 0===document.cookie||null===document.cookie)return!1;try{var t="dd_cookie_test_"+E();return D(t,"test",f,e),"test"===N(t)}catch(e){return console.error(e),!1}}(e)||(console.warn("Cookies are not authorized, we will not send any data."),!1)}function We(){return"file:"!==window.location.protocol||(console.error("Execution is not allowed in the current context."),!1)}!function(e){e.RELEASE="release",e.STAGING="staging",e.E2E_TEST="e2e-test"}(Ve||(Ve={}));var je,Fe=1e4,Ge=function(){function e(e){void 0===e&&(e=Fe),this.limit=e,this.buffer=[]}return e.prototype.add=function(e){this.buffer.push(e)>this.limit&&this.buffer.splice(0,1)},e.prototype.drain=function(e){this.buffer.forEach((function(t){return e(t)})),this.buffer.length=0},e}();!function(e){e[e.ERROR_COLLECTED=0]="ERROR_COLLECTED",e[e.ERROR_PROVIDED=1]="ERROR_PROVIDED",e[e.PERFORMANCE_ENTRY_COLLECTED=2]="PERFORMANCE_ENTRY_COLLECTED",e[e.CUSTOM_ACTION_COLLECTED=3]="CUSTOM_ACTION_COLLECTED",e[e.AUTO_ACTION_CREATED=4]="AUTO_ACTION_CREATED",e[e.AUTO_ACTION_COMPLETED=5]="AUTO_ACTION_COMPLETED",e[e.AUTO_ACTION_DISCARDED=6]="AUTO_ACTION_DISCARDED",e[e.VIEW_CREATED=7]="VIEW_CREATED",e[e.VIEW_UPDATED=8]="VIEW_UPDATED",e[e.REQUEST_STARTED=9]="REQUEST_STARTED",e[e.REQUEST_COMPLETED=10]="REQUEST_COMPLETED",e[e.SESSION_RENEWED=11]="SESSION_RENEWED",e[e.RESOURCE_ADDED_TO_BATCH=12]="RESOURCE_ADDED_TO_BATCH",e[e.DOM_MUTATED=13]="DOM_MUTATED",e[e.BEFORE_UNLOAD=14]="BEFORE_UNLOAD",e[e.RAW_RUM_EVENT_COLLECTED=15]="RAW_RUM_EVENT_COLLECTED",e[e.RAW_RUM_EVENT_V2_COLLECTED=16]="RAW_RUM_EVENT_V2_COLLECTED",e[e.RUM_EVENT_COLLECTED=17]="RUM_EVENT_COLLECTED",e[e.RUM_EVENT_V2_COLLECTED=18]="RUM_EVENT_V2_COLLECTED"}(je||(je={}));var qe=function(){function e(){this.callbacks={}}return e.prototype.notify=function(e,t){var n=this.callbacks[e];n&&n.forEach((function(e){return e(t)}))},e.prototype.subscribe=function(e,t){var n=this;return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t),{unsubscribe:function(){n.callbacks[e]=n.callbacks[e].filter((function(e){return t!==e}))}}},e}();function ze(e,t){void 0===t&&(t=T);var n={errorCount:0,longTaskCount:0,resourceCount:0,userActionCount:0},r=[];return r.push(e.subscribe(je.ERROR_COLLECTED,(function(){n.errorCount+=1,t(n)}))),r.push(e.subscribe(je.AUTO_ACTION_COMPLETED,(function(){n.userActionCount+=1,t(n)}))),r.push(e.subscribe(je.CUSTOM_ACTION_COLLECTED,(function(){n.userActionCount+=1,t(n)}))),r.push(e.subscribe(je.PERFORMANCE_ENTRY_COLLECTED,(function(e){"longtask"===e.entryType&&(n.longTaskCount+=1,t(n))}))),r.push(e.subscribe(je.RESOURCE_ADDED_TO_BATCH,(function(){n.resourceCount+=1,t(n)}))),{stop:function(){r.forEach((function(e){return e.unsubscribe()}))},eventCounts:n}}var Ke=100,$e=100,Ye=1e4;function Xe(e,t){var n=function(e){var t,n=new Le,r=[],i=0;function o(){n.notify({isBusy:i>0})}return r.push(e.subscribe(je.DOM_MUTATED,(function(){return o()}))),r.push(e.subscribe(je.PERFORMANCE_ENTRY_COLLECTED,(function(e){"resource"===e.entryType&&o()}))),r.push(e.subscribe(je.REQUEST_STARTED,(function(e){void 0===t&&(t=e.requestIndex),i+=1,o()}))),r.push(e.subscribe(je.REQUEST_COMPLETED,(function(e){void 0===t||e.requestIndex<t||(i-=1,o())}))),{observable:n,stop:function(){r.forEach((function(e){return e.unsubscribe()}))}}}(e),r=n.observable,i=n.stop,o=function(e,t,n){var r,i=!1,o=setTimeout(ce((function(){return s(!1,0)})),Ke),a=setTimeout(ce((function(){return s(!0,performance.now())})),Ye);function u(){i=!0,clearTimeout(o),clearTimeout(r),clearTimeout(a),t()}function s(e,t){i||(u(),n(e,t))}return e.subscribe((function(e){var t=e.isBusy;clearTimeout(o),clearTimeout(r);var n=performance.now();t||(r=setTimeout(ce((function(){return s(!0,n)})),$e))})),{stop:u}}(r,i,t).stop;return{stop:function(){o(),i()}}}function Je(e){return function(e){var t;if(function(){void 0===tt&&(tt="closest"in HTMLElement.prototype);return tt}())t=e.closest("["+Qe+"]");else for(var n=e;n;){if(n.hasAttribute(Qe)){t=n;break}n=n.parentElement}if(!t)return;return st(ut(t.getAttribute(Qe).trim()))}(e)||at(e,rt)||at(e,it)||""}var Qe="data-dd-action-name";var Ze,et,tt,nt,rt=[function(e){if(function(){void 0===et&&(et="labels"in HTMLInputElement.prototype);return et}()){if("labels"in e&&e.labels&&e.labels.length>0)return ct(e.labels[0])}else if(e.id){var t=e.ownerDocument&&e.ownerDocument.querySelector('label[for="'+e.id.replace('"','\\"')+'"]');return t&&ct(t)}},function(e){if("INPUT"===e.nodeName){var t=e,n=t.getAttribute("type");if("button"===n||"submit"===n||"reset"===n)return t.value}},function(e){if("BUTTON"===e.nodeName||"LABEL"===e.nodeName||"button"===e.getAttribute("role"))return ct(e)},function(e){return e.getAttribute("aria-label")},function(e){var t=e.getAttribute("aria-labelledby");if(t)return t.split(/\s+/).map((function(t){return function(e,t){return e.ownerDocument?e.ownerDocument.getElementById(t):null}(e,t)})).filter((function(e){return Boolean(e)})).map(ct).join(" ")},function(e){return e.getAttribute("alt")},function(e){return e.getAttribute("name")},function(e){return e.getAttribute("title")},function(e){return e.getAttribute("placeholder")},function(e){if("options"in e&&e.options.length>0)return ct(e.options[0])}],it=[function(e){return ct(e)}],ot=10;function at(e,t){for(var n=e,r=0;r<=ot&&n&&"BODY"!==n.nodeName&&"HTML"!==n.nodeName&&"HEAD"!==n.nodeName;){for(var i=0,o=t;i<o.length;i++){var a=(0,o[i])(n);if("string"==typeof a){var u=a.trim();if(u)return st(ut(u))}}if("FORM"===n.nodeName)break;n=n.parentElement,r+=1}}function ut(e){return e.replace(/\s+/g," ")}function st(e){return e.length>100?(n=100,((r=(t=e).charCodeAt(n-1))>=55296&&r<=56319?t.slice(0,n+1):t.slice(0,n))+" [...]"):e;var t,n,r}function ct(e){if(!e.isContentEditable){if("innerText"in e){var t=e.innerText;if(!function(){if(void 0===Ze){var e=document.createElement("style");e.textContent="*";var t=document.createElement("div");t.appendChild(e),document.body.appendChild(t),Ze=""===t.innerText,document.body.removeChild(t)}return Ze}())for(var n=e.querySelectorAll("script, style"),r=0;r<n.length;r+=1){var i=n[r].innerText;i.trim().length>0&&(t=t.replace(i,""))}return t}return e.textContent}}function ft(e){var t=function(e){var t,n;return{create:function(r,i){if(!t){var o=new dt(e,r,i);t=o,n=Xe(e,(function(e,n){e?o.complete(n):o.discard(),t=void 0}))}},discardCurrent:function(){t&&(n.stop(),t.discard(),t=void 0)}}}(e);function n(e){if(e.target instanceof Element){var n=Je(e.target);n&&t.create(nt.CLICK,n)}}return e.subscribe(je.VIEW_CREATED,(function(){t.discardCurrent()})),addEventListener(a.CLICK,n,{capture:!0}),{stop:function(){t.discardCurrent(),removeEventListener(a.CLICK,n,{capture:!0})}}}!function(e){e.CLICK="click",e.CUSTOM="custom"}(nt||(nt={}));var dt=function(){function e(e,t,n){this.lifeCycle=e,this.type=t,this.name=n,this.id=E(),this.startTime=performance.now(),this.eventCountsSubscription=ze(e),this.lifeCycle.notify(je.AUTO_ACTION_CREATED,{id:this.id,startTime:this.startTime})}return e.prototype.complete=function(e){var t=this.eventCountsSubscription.eventCounts;this.lifeCycle.notify(je.AUTO_ACTION_COMPLETED,{counts:{errorCount:t.errorCount,longTaskCount:t.longTaskCount,resourceCount:t.resourceCount},duration:e-this.startTime,id:this.id,name:this.name,startTime:this.startTime,type:this.type}),this.eventCountsSubscription.stop()},e.prototype.discard=function(){this.lifeCycle.notify(je.AUTO_ACTION_DISCARDED),this.eventCountsSubscription.stop()},e}();function lt(e){var t,n=function(){var e,t=window;if(t.Zone){var n=t.Zone.__symbol__("MutationObserver");e=t[n]}return e||(e=t.MutationObserver),e}();return n&&(t=new n(ce((function(){e.notify(je.DOM_MUTATED)})))).observe(document.documentElement,{attributes:!0,characterData:!0,childList:!0,subtree:!0}),{stop:function(){t&&t.disconnect()}}}var pt="initial_document",Et=[[u.DOCUMENT,function(e){return pt===e}],[u.XHR,function(e){return"xmlhttprequest"===e}],[u.FETCH,function(e){return"fetch"===e}],[u.BEACON,function(e){return"beacon"===e}],[u.CSS,function(e,t){return null!==t.match(/\.css$/i)}],[u.JS,function(e,t){return null!==t.match(/\.js$/i)}],[u.IMAGE,function(e,t){return y(["image","img","icon"],e)||null!==t.match(/\.(gif|jpg|jpeg|tiff|png|svg|ico)$/i)}],[u.FONT,function(e,t){return null!==t.match(/\.(woff|eot|woff2|ttf)$/i)}],[u.MEDIA,function(e,t){return y(["audio","video"],e)||null!==t.match(/\.(mp3|mp4)$/i)}]];function mt(e){var t=e.name;if(!function(e){try{return!!V(e)}catch(e){return!1}}(t))return fe('Failed to construct URL for "'+e.name+'"'),u.OTHER;for(var n=k(t),r=0,i=Et;r<i.length;r++){var o=i[r],a=o[0];if((0,o[1])(e.initiatorType,n))return a}return u.OTHER}function vt(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];for(var n=1;n<e.length;n+=1)if(e[n-1]>e[n])return!1;return!0}function Tt(e){var t=e.duration,n=e.startTime,r=e.responseEnd;return v(0===t&&n<r?r-n:t)}function ht(e){var t=e.startTime,n=e.fetchStart,r=e.domainLookupStart,i=e.domainLookupEnd,o=e.connectStart,a=e.secureConnectionStart,u=e.connectEnd,s=e.requestStart,c=e.responseStart,f=e.responseEnd,d=e.redirectStart,l=e.redirectEnd;if(vt(t,n,r,i,o,u,s,c,f)){var p=n!==t;if(!p||(d<t&&(d=t),l<t&&(l=n),vt(t,d,l,n))){var E={download:gt(t,c,f),firstByte:gt(t,s,c)};return u!==n&&(E.connect=gt(t,o,u),vt(o,a,u)&&(E.ssl=gt(t,a,u))),i!==n&&(E.dns=gt(t,r,i)),p&&(E.redirect=gt(t,d,l)),E}}}function gt(e,t,n){return{duration:v(n-t),start:v(t-e)}}function yt(e){if(e.startTime<e.responseStart)return e.decodedBodySize}function Ct(e,t){return t&&!W(t,e)}var bt,_t,Rt,Ot,St=2*d;function wt(e){var t=function(e){var t=e.querySelector("meta[name=dd-trace-id]"),n=e.querySelector("meta[name=dd-trace-time]");return At(t&&t.content,n&&n.content)}(e)||function(e){var t=function(e){for(var t=0;t<e.childNodes.length;t+=1){if(n=It(e.childNodes[t]))return n}if(e.body)for(t=e.body.childNodes.length-1;t>=0;t-=1){var n,r=e.body.childNodes[t];if(n=It(r))return n;if(!Lt(r))break}}(e);if(!t)return;return At(w(t,"trace-id"),w(t,"trace-time"))}(e);if(t&&!(t.traceTime<=Date.now()-St))return t.traceId}function At(e,t){var n=t&&Number(t);if(e&&n)return{traceId:e,traceTime:n}}function It(e){if(e&&function(e){return"#comment"===e.nodeName}(e)){var t=e.data.match(/^\s*DATADOG;(.*?)\s*$/);if(t)return t[1]}}function Lt(e){return"#text"===e.nodeName}function Dt(){return void 0!==window.performance&&"getEntries"in performance}function Nt(){return window.PerformanceObserver&&void 0!==PerformanceObserver.supportedEntryTypes&&PerformanceObserver.supportedEntryTypes.includes("navigation")}function xt(e,t){var n;if(n=function(n){Vt(e,t,n)},Mt("interactive",(function(){var e,t={entryType:"resource",initiatorType:pt,traceId:wt(document)};if(Nt()&&performance.getEntriesByType("navigation").length>0){var i=performance.getEntriesByType("navigation")[0];e=r(r({},i.toJSON()),t)}else{var o=Ut();e=r(r(r({},o),{decodedBodySize:0,duration:o.responseEnd,name:window.location.href,startTime:0}),t)}n(e)})),Dt()&&kt(e,t,performance.getEntries()),window.PerformanceObserver){var i=new PerformanceObserver(ce((function(n){return kt(e,t,n.getEntries())}))),o=["resource","navigation","longtask"];"visible"===document.visibilityState&&o.push("paint"),i.observe({entryTypes:o}),Dt()&&"addEventListener"in performance&&performance.addEventListener("resourcetimingbufferfull",(function(){performance.clearResourceTimings()}))}Nt()||function(e){function t(){e(r(r({},Ut()),{entryType:"navigation"}))}Mt("complete",(function(){setTimeout(ce(t))}))}((function(n){Vt(e,t,n)}))}function Mt(e,t){if(document.readyState===e||"complete"===document.readyState)t();else{var n="complete"===e?a.LOAD:a.DOM_CONTENT_LOADED,r=ce((function(){window.removeEventListener(n,r),t()}));window.addEventListener(n,r)}}function Ut(){var e={},t=performance.timing;for(var n in t)b(t[n])&&(e[n]=0===t[n]?0:t[n]-R());return e}function kt(e,t,n){n.forEach((function(n){"resource"!==n.entryType&&"navigation"!==n.entryType&&"paint"!==n.entryType&&"longtask"!==n.entryType||Vt(e,t,n)}))}function Vt(e,t,n){(function(e){return"navigation"===e.entryType&&e.loadEventEnd<=0})(n)||function(e,t){return"resource"===t.entryType&&!Ct(e,t.name)}(t,n)||e.notify(je.PERFORMANCE_ENTRY_COLLECTED,n)}function Bt(e,t,n,r,i,o){n.subscribe(je.RAW_RUM_EVENT_COLLECTED,(function(a){var u,s=a.startTime,c=a.rawRumEvent,f=a.savedGlobalContext,d=a.customerContext,l=i.findView(s);if(r.isTracked()&&l&&l.sessionId){var p=i.findAction(s),E={applicationId:e,date:(new Date).getTime(),service:t.service,session:{type:void 0===window._DATADOG_SYNTHETICS_BROWSER?_t.USER:_t.SYNTHETICS}},m=(u=c,-1!==[bt.ERROR,bt.RESOURCE,bt.LONG_TASK].indexOf(u.evt.category)?q(E,l,p,c):q(E,l,c)),v=q(f||o(),d,j(m));n.notify(je.RUM_EVENT_COLLECTED,{rumEvent:m,serverRumEvent:v})}}))}function Pt(e,t,n,r,i,o){n.subscribe(je.RAW_RUM_EVENT_V2_COLLECTED,(function(a){var u,s=a.startTime,c=a.rawRumEvent,f=a.savedGlobalContext,d=a.customerContext,l=i.findViewV2(s);if(r.isTracked()&&l&&l.session.id){var p=i.findActionV2(s),E={_dd:{formatVersion:2},application:{id:e},date:(new Date).getTime(),service:t.service,session:{type:void 0===window._DATADOG_SYNTHETICS_BROWSER?Ot.USER:Ot.SYNTHETICS}},m=(u=c,-1!==[Rt.ERROR,Rt.RESOURCE,Rt.LONG_TASK].indexOf(u.type)?q(E,l,p,c):q(E,l,c)),v=j(m);v.context=q(f||o(),d),n.notify(je.RUM_EVENT_V2_COLLECTED,{rumEvent:m,serverRumEvent:v})}}))}!function(e){e.USER_ACTION="user_action",e.ERROR="error",e.LONG_TASK="long_task",e.VIEW="view",e.RESOURCE="resource"}(bt||(bt={})),function(e){e.SYNTHETICS="synthetics",e.USER="user"}(_t||(_t={})),function(e){e.ACTION="action",e.ERROR="error",e.LONG_TASK="long_task",e.VIEW="view",e.RESOURCE="resource"}(Rt||(Rt={})),function(e){e.SYNTHETICS="synthetics",e.USER="user"}(Ot||(Ot={}));var Ht="_dd",Wt="_dd_r",jt="_dd_l",Ft="rum",Gt="logs";var qt="_dd_s",zt=15*d,Kt=4*l,$t=d;function Yt(e,t,n){var r=function(e,t){var n,r,i=!1,o=function(){i=!0,window.clearTimeout(n),n=window.setTimeout((function(){i=!1}),L)};return{get:function(){return i?r:(r=N(e),o(),r)},set:function(n,i){D(e,n,i,t),r=n,o()}}}(qt,e);!function(e){var t=e.get(),n=N(Ht),r=N(Wt),i=N(jt);if(!t){var o={};n&&(o.id=n),i&&/^[01]$/.test(i)&&(o[Gt]=i),r&&/^[012]$/.test(r)&&(o[Ft]=r),Zt(o,e)}}(r);var i=new Le,o=Qt(r).id,u=p((function(){var e=Qt(r),a=n(e[t]),u=a.trackingType,s=a.isTracked;e[t]=u,s&&!e.id&&(e.id=E(),e.created=String(Date.now())),Zt(e,r),s&&o!==e.id&&(o=e.id,i.notify())}),L).throttled;return u(),function(e){var t=ce(e),n={capture:!0,passive:!0};[a.CLICK,a.TOUCH_START,a.KEY_DOWN,a.SCROLL].forEach((function(e){document.addEventListener(e,t,n),tn.push((function(){return document.removeEventListener(e,t,n)}))}))}(u),function(e){var t=ce((function(){"visible"===document.visibilityState&&e()})),n=window.setInterval(t,$t);document.addEventListener(a.VISIBILITY_CHANGE,t),tn.push((function(){clearInterval(n),document.removeEventListener(a.VISIBILITY_CHANGE,t)}))}((function(){Zt(Qt(r),r)})),{getId:function(){return Qt(r).id},getTrackingType:function(){return Qt(r)[t]},renewObservable:i}}var Xt=/^([a-z]+)=([a-z0-9-]+)$/,Jt="&";function Qt(e){var t=function(e){var t=e.get(),n={};(function(e){return void 0!==e&&(-1!==e.indexOf(Jt)||Xt.test(e))})(t)&&t.split(Jt).forEach((function(e){var t=Xt.exec(e);if(null!==t){var r=t[1],i=t[2];n[r]=i}}));return n}(e);return function(e){return(void 0===e.created||Date.now()-Number(e.created)<Kt)&&(void 0===e.expire||Date.now()<Number(e.expire))}(t)?t:(en(e),{})}function Zt(e,t){if(n=e,0!==Object.keys(n).length){var n;e.expire=String(Date.now()+zt);var r=O(e).map((function(e){return e[0]+"="+e[1]})).join(Jt);t.set(r,zt)}else en(t)}function en(e){e.set("",0)}var tn=[];var nn=Kt,rn=5*d,on=d;function an(e,t,n){if(void 0!==un()&&function(e,t){for(var n=U(t),r=0,i=e.allowedTracingOrigins;r<i.length;r++){var o=i[r];if(n===o||o instanceof RegExp&&o.test(n))return!0}return!1}(e,t)){var r=new cn,i=new cn;return n(function(e,t){return{"x-datadog-origin":"rum","x-datadog-parent-id":t.toDecimalString(),"x-datadog-sampled":"1","x-datadog-sampling-priority":"1","x-datadog-trace-id":e.toDecimalString()}}(r,i)),{traceId:r,spanId:i}}}function un(){return window.crypto||window.msCrypto}var sn,cn=function(){function e(){this.buffer=new Uint8Array(8),un().getRandomValues(this.buffer),this.buffer[0]=127&this.buffer[0]}return e.prototype.toString=function(e){for(var t=this.readInt32(0),n=this.readInt32(4),r="";;){var i=t%e*4294967296+n;if(t=Math.floor(t/e),n=Math.floor(i/e),r=(i%e).toString(e)+r,!t&&!n)break}return r},e.prototype.toDecimalString=function(){return this.toString(10)},e.prototype.readInt32=function(e){return 16777216*this.buffer[e]+(this.buffer[e+1]<<16)+(this.buffer[e+2]<<8)+this.buffer[e+3]},e}(),fn=1;function dn(e,t){var n=function(e){return{traceFetch:function(t){return an(e,t.url,(function(e){t.init=r({},t.init);var n=[];t.init.headers instanceof Headers?t.init.headers.forEach((function(e,t){n.push([t,e])})):Array.isArray(t.init.headers)?t.init.headers.forEach((function(e){n.push(e)})):t.init.headers&&Object.keys(t.init.headers).forEach((function(e){n.push([e,t.init.headers[e]])})),t.init.headers=n.concat(O(e))}))},traceXhr:function(t,n){return an(e,t.url,(function(e){Object.keys(e).forEach((function(t){n.setRequestHeader(t,e[t])}))}))}}}(t);!function(e,t,n){var r=_e();r.beforeSend((function(r,i){if(Ct(t,r.url)){var o=n.traceXhr(r,i);o&&(r.traceId=o.traceId,r.spanId=o.spanId),r.requestIndex=ln(),e.notify(je.REQUEST_STARTED,{requestIndex:r.requestIndex})}})),r.onRequestComplete((function(n){Ct(t,n.url)&&e.notify(je.REQUEST_COMPLETED,{duration:n.duration,method:n.method,requestIndex:n.requestIndex,response:n.response,spanId:n.spanId,startTime:n.startTime,status:n.status,traceId:n.traceId,type:s.XHR,url:n.url})}))}(e,t,n),function(e,t,n){var r=he();r.beforeSend((function(r){if(Ct(t,r.url)){var i=n.traceFetch(r);i&&(r.traceId=i.traceId,r.spanId=i.spanId),r.requestIndex=ln(),e.notify(je.REQUEST_STARTED,{requestIndex:r.requestIndex})}})),r.onRequestComplete((function(n){Ct(t,n.url)&&e.notify(je.REQUEST_COMPLETED,{duration:n.duration,method:n.method,requestIndex:n.requestIndex,response:n.response,responseType:n.responseType,spanId:n.spanId,startTime:n.startTime,status:n.status,traceId:n.traceId,type:s.FETCH,url:n.url})}))}(e,t,n)}function ln(){var e=fn;return fn+=1,e}function pn(e){var t=mn(e)?{duration:v(e.duration),userAction:{id:e.id,measures:e.counts}}:void 0;return{customerContext:mn(e)?void 0:e.context,rawRumEvent:q({date:_(e.startTime),evt:{category:bt.USER_ACTION,name:e.name},userAction:{type:e.type}},t),startTime:e.startTime}}function En(e){var t=mn(e)?{action:{error:{count:e.counts.errorCount},id:e.id,loadingTime:v(e.duration),longTask:{count:e.counts.longTaskCount},resource:{count:e.counts.resourceCount}}}:void 0;return{customerContext:mn(e)?void 0:e.context,rawRumEvent:q({action:{target:{name:e.name},type:e.type},date:_(e.startTime),type:Rt.ACTION},t),startTime:e.startTime}}function mn(e){return e.type!==nt.CUSTOM}function vn(e,t){e.subscribe(je.ERROR_PROVIDED,(function(n){var i=n.error,o=i.error,a=i.startTime,u=i.context,s=i.source,c=n.context,f=function(e,t,n){var i=e instanceof Error?re(e):void 0;return r({startTime:t,source:n},xe(i,e,"Provided"))}(o,a,s);t.isEnabled("v2_format")?e.notify(je.RAW_RUM_EVENT_V2_COLLECTED,r({customerContext:u,savedGlobalContext:c},hn(f))):e.notify(je.RAW_RUM_EVENT_COLLECTED,r({customerContext:u,savedGlobalContext:c},Tn(f)))})),e.subscribe(je.ERROR_COLLECTED,(function(n){t.isEnabled("v2_format")?e.notify(je.RAW_RUM_EVENT_V2_COLLECTED,hn(n)):e.notify(je.RAW_RUM_EVENT_COLLECTED,Tn(n))}))}function Tn(e){return{rawRumEvent:q({date:_(e.startTime),error:{kind:e.type,origin:e.source,stack:e.stack},evt:{category:bt.ERROR},message:e.message},e.resource?{http:{method:e.resource.method,status_code:e.resource.statusCode,url:e.resource.url}}:void 0),startTime:e.startTime}}function hn(e){return{rawRumEvent:{date:_(e.startTime),error:{message:e.message,resource:e.resource,source:e.source,stack:e.stack,type:e.type},type:Rt.ERROR},startTime:e.startTime}}function gn(e){if(performance&&"getEntriesByName"in performance){var t,n=performance.getEntriesByName(e.url,"resource").filter((function(t){return n=t,r=e.startTime,i=yn(e),n.startTime>=r&&yn(n)<=i;var n,r,i}));return 1===n.length?n[0]:2===n.length&&yn((t=n)[0])<=t[1].startTime?n[1]:void 0}}function yn(e){return e.startTime+e.duration}function Cn(e,t,n){e.subscribe(je.REQUEST_COMPLETED,(function(r){n.isTrackedWithResource()&&(t.isEnabled("v2_format")?e.notify(je.RAW_RUM_EVENT_V2_COLLECTED,function(e){var t=e.type===s.XHR?u.XHR:u.FETCH,n=gn(e),r=n?n.startTime:e.startTime,i=n?_n(n):void 0,o=Rn(e),a=q({date:_(r),resource:{type:t,duration:v(e.duration),method:e.method,statusCode:e.status,url:e.url},type:Rt.RESOURCE},o,i);return{startTime:r,rawRumEvent:a}}(r)):e.notify(je.RAW_RUM_EVENT_COLLECTED,function(e){var t=e.type===s.XHR?u.XHR:u.FETCH,n=gn(e),r=n?n.startTime:e.startTime,i=n?bn(n):void 0,o=Rn(e),a=q({date:_(r),duration:v(e.duration),evt:{category:bt.RESOURCE},http:{method:e.method,statusCode:e.status,url:e.url},resource:{kind:t}},o,i);return{startTime:r,rawRumEvent:a}}(r)),e.notify(je.RESOURCE_ADDED_TO_BATCH))})),e.subscribe(je.PERFORMANCE_ENTRY_COLLECTED,(function(r){var i;n.isTrackedWithResource()&&"resource"===r.entryType&&("xmlhttprequest"!==(i=r).initiatorType&&"fetch"!==i.initiatorType)&&(t.isEnabled("v2_format")?e.notify(je.RAW_RUM_EVENT_V2_COLLECTED,function(e){var t=mt(e),n=_n(e),r=On(e),i=q({date:_(e.startTime),resource:{type:t,url:e.name},type:Rt.RESOURCE},r,n);return{startTime:e.startTime,rawRumEvent:i}}(r)):e.notify(je.RAW_RUM_EVENT_COLLECTED,function(e){var t=mt(e),n=bn(e),r=On(e),i=q({date:_(e.startTime),evt:{category:bt.RESOURCE},http:{url:e.name},resource:{kind:t}},r,n);return{startTime:e.startTime,rawRumEvent:i}}(r)),e.notify(je.RESOURCE_ADDED_TO_BATCH))}))}function bn(e){return{duration:Tt(e),http:{performance:ht(e)},network:{bytesWritten:yt(e)}}}function _n(e){return{resource:r({duration:Tt(e),size:yt(e)},ht(e))}}function Rn(e){if(e.traceId&&e.spanId)return{_dd:{spanId:e.spanId.toDecimalString(),traceId:e.traceId.toDecimalString()},resource:{id:E()}}}function On(e){return e.traceId?{_dd:{traceId:e.traceId}}:void 0}!function(e){e.INITIAL_LOAD="initial_load",e.ROUTE_CHANGE="route_change"}(sn||(sn={}));var Sn=3e3,wn=5*d;function An(e,t){var n,i=In(t,e,sn.INITIAL_LOAD,document.referrer,0),o=i,u=function(e,t){var n;return{stop:e.subscribe(je.PERFORMANCE_ENTRY_COLLECTED,(function(e){"navigation"===e.entryType?(n=r(r({},n),{domComplete:e.domComplete,domContentLoaded:e.domContentLoadedEventEnd,domInteractive:e.domInteractive,loadEventEnd:e.loadEventEnd}),t(n)):"paint"===e.entryType&&"first-contentful-paint"===e.name&&(n=r(r({},n),{firstContentfulPaint:e.startTime}),t(n))})).unsubscribe}}(t,(function(e){i.updateTimings(e),i.scheduleUpdate()})).stop;function s(){o.isDifferentView(e)?(o.triggerUpdate(),o.end(),o=In(t,e,sn.ROUTE_CHANGE,o.url)):(o.updateLocation(e),o.triggerUpdate())}!function(e){var t=history.pushState;history.pushState=ce((function(){t.apply(this,arguments),e()}));var n=history.replaceState;history.replaceState=ce((function(){n.apply(this,arguments),e()})),window.addEventListener(a.POP_STATE,ce(e))}(s),n=s,window.addEventListener("hashchange",ce(n)),t.subscribe(je.SESSION_RENEWED,(function(){o.end(),o=In(t,e,sn.ROUTE_CHANGE,o.url)})),t.subscribe(je.BEFORE_UNLOAD,(function(){o.triggerUpdate(),o.end()}));var c=window.setInterval(ce((function(){o.triggerUpdate()})),wn);return{stop:function(){u(),o.end(),clearInterval(c)}}}function In(e,t,n,i,o){void 0===o&&(o=performance.now());var a,u,s=E(),c={errorCount:0,longTaskCount:0,resourceCount:0,userActionCount:0},f={},d=0,l=r({},t);e.notify(je.VIEW_CREATED,{id:s,startTime:o,location:l,referrer:i});var m=p(ce(_),Sn,{leading:!1}),v=m.throttled,T=m.cancel,h=ze(e,(function(e){c=e,v()})).stop,g=function(e,t){var n=e===sn.INITIAL_LOAD,r=!0,i=[];function o(){!r&&!n&&i.length>0&&t(Math.max.apply(Math,i))}return{setLoadEventEnd:function(e){n&&(n=!1,i.push(e),o())},setActivityLoadingTime:function(e){r&&(r=!1,void 0!==e&&i.push(e),o())}}}(n,(function(e){a=e,v()})),y=g.setActivityLoadingTime,C=g.setLoadEventEnd,b=function(e,t){var n=performance.now();return{stop:Xe(e,(function(e,r){t(e?r-n:void 0)})).stop}}(e,y).stop;function _(){d+=1,e.notify(je.VIEW_UPDATED,{documentVersion:d,eventCounts:c,id:s,loadingTime:a,loadingType:n,location:l,referrer:i,startTime:o,timings:f,duration:(void 0===u?performance.now():u)-o})}return(_(),{scheduleUpdate:v,end:function(){u=performance.now(),h(),b()},isDifferentView:function(e){return l.pathname!==e.pathname||(t=e.hash,n=t.substr(1),!document.getElementById(n)&&e.hash!==l.hash);var t,n},triggerUpdate:function(){T(),_()},updateTimings:function(e){f=e,void 0!==e.loadEventEnd&&C(e.loadEventEnd)},updateLocation:function(e){l=r({},e)},get url(){return l.href}})}function Ln(e,t,n){e.subscribe(je.VIEW_UPDATED,(function(n){t.isEnabled("v2_format")?e.notify(je.RAW_RUM_EVENT_V2_COLLECTED,function(e){return{rawRumEvent:{_dd:{documentVersion:e.documentVersion},date:_(e.startTime),type:Rt.VIEW,view:{action:{count:e.eventCounts.userActionCount},domComplete:v(e.timings.domComplete),domContentLoaded:v(e.timings.domContentLoaded),domInteractive:v(e.timings.domInteractive),error:{count:e.eventCounts.errorCount},firstContentfulPaint:v(e.timings.firstContentfulPaint),loadEventEnd:v(e.timings.loadEventEnd),loadingTime:v(e.loadingTime),loadingType:e.loadingType,longTask:{count:e.eventCounts.longTaskCount},resource:{count:e.eventCounts.resourceCount},timeSpent:v(e.duration)}},startTime:e.startTime}}(n)):e.notify(je.RAW_RUM_EVENT_COLLECTED,function(e){return{rawRumEvent:{date:_(e.startTime),duration:v(e.duration),evt:{category:bt.VIEW},rum:{documentVersion:e.documentVersion},view:{loadingTime:v(e.loadingTime),loadingType:e.loadingType,measures:r(r({},e.eventCounts),{domComplete:v(e.timings.domComplete),domContentLoaded:v(e.timings.domContentLoaded),domInteractive:v(e.timings.domInteractive),firstContentfulPaint:v(e.timings.firstContentfulPaint),loadEventEnd:v(e.timings.loadEventEnd)})}},startTime:e.startTime}}(n))})),An(n,e)}var Dn,Nn="rum";function xn(e,t){var n=Yt(e.cookieOptions,Nn,(function(t){return function(e,t){var n;n=function(e){return e===Dn.NOT_TRACKED||e===Dn.TRACKED_WITH_RESOURCES||e===Dn.TRACKED_WITHOUT_RESOURCES}(t)?t:m(e.sampleRate)?m(e.resourceSampleRate)?Dn.TRACKED_WITH_RESOURCES:Dn.TRACKED_WITHOUT_RESOURCES:Dn.NOT_TRACKED;return{trackingType:n,isTracked:Mn(n)}}(e,t)}));return n.renewObservable.subscribe((function(){t.notify(je.SESSION_RENEWED)})),{getId:n.getId,isTracked:function(){return void 0!==n.getId()&&Mn(n.getTrackingType())},isTrackedWithResource:function(){return void 0!==n.getId()&&n.getTrackingType()===Dn.TRACKED_WITH_RESOURCES}}}function Mn(e){return e===Dn.TRACKED_WITH_RESOURCES||e===Dn.TRACKED_WITHOUT_RESOURCES}function Un(e,t){var n=function(e,t){var n,r=o(e.rumEndpoint,(function(){return t.notify(je.BEFORE_UNLOAD)})),i=e.replica;void 0!==i&&(n=o(i.rumEndpoint));function o(t,n){return new J(new X(t,e.batchBytesLimit,!0),e.maxBatchSize,e.batchBytesLimit,e.maxMessageSize,e.flushTimeout,n)}function a(e){return q(e,{application_id:i.applicationId})}var u=!1;return{add:function(e){u||(r.add(e),n&&n.add(a(e)))},stop:function(){u=!0},upsert:function(e,t){u||(r.upsert(e,t),n&&n.upsert(a(e),t))}}}(e,t);return t.subscribe(je.RUM_EVENT_COLLECTED,(function(e){var t=e.rumEvent,r=e.serverRumEvent;t.evt.category===bt.VIEW?n.upsert(r,t.view.id):n.add(r)})),t.subscribe(je.RUM_EVENT_V2_COLLECTED,(function(e){var t=e.rumEvent,r=e.serverRumEvent;t.type===Rt.VIEW?n.upsert(r,t.view.id):n.add(r)})),{stop:function(){n.stop()}}}!function(e){e.NOT_TRACKED="0",e.TRACKED_WITH_RESOURCES="1",e.TRACKED_WITHOUT_RESOURCES="2"}(Dn||(Dn={}));var kn={buildMode:"release",datacenter:"us",sdkVersion:"1.25.1"};var Vn,Bn,Pn,Hn,Wn=jn((function(e,t){var n=new qe,i=Pe(e,kn,!0),o=i.errorObservable,a=i.configuration,u=i.internalMonitoring,s=xn(a,n);u.setExternalContextProvider((function(){return q({application_id:e.applicationId},c.findView(),t())}));var c=function(e,t,n,i,o,a){var u=function(e,t){var n,r,i,o=[],a=[];e.subscribe(je.VIEW_CREATED,(function(e){n&&o.unshift({context:c(),endTime:e.startTime,startTime:n.startTime}),n=e,i=t.getId()})),e.subscribe(je.VIEW_UPDATED,(function(e){n.id===e.id&&(n=e)})),e.subscribe(je.AUTO_ACTION_CREATED,(function(e){r=e})),e.subscribe(je.AUTO_ACTION_COMPLETED,(function(e){r&&a.unshift({context:f(),endTime:r.startTime+e.duration,startTime:r.startTime}),r=void 0})),e.subscribe(je.AUTO_ACTION_DISCARDED,(function(){r=void 0})),e.subscribe(je.SESSION_RENEWED,(function(){o=[],a=[],n=void 0,r=void 0}));var u=window.setInterval(ce((function(){s(o,nn),s(a,rn)})),on);function s(e,t){for(var n=performance.now()-t;e.length>0&&e[e.length-1].startTime<n;)e.pop()}function c(){return{sessionId:i,view:{id:n.id,referrer:n.referrer,url:n.location.href}}}function f(){return{userAction:{id:r.id}}}function d(e,t,n,r){if(void 0===r)return n?e():void 0;if(n&&r>=n.startTime)return e();for(var i=0,o=t;i<o.length;i++){var a=o[i];if(r>a.endTime)break;if(r>=a.startTime)return a.context}}var l={findAction:function(e){return d(f,a,r,e)},findActionV2:function(e){var t=l.findAction(e);if(t)return{action:{id:t.userAction.id}}},findView:function(e){return d(c,o,n,e)},findViewV2:function(e){var t=l.findView(e);if(t)return{session:{id:t.sessionId},view:t.view}},stop:function(){window.clearInterval(u)}};return l}(n,o),s=Un(i,n);return Bt(e,i,n,o,u,a),Pt(e,i,n,o,u,a),function(e,t){e.subscribe(je.PERFORMANCE_ENTRY_COLLECTED,(function(n){if("longtask"===n.entryType)if(t.isEnabled("v2_format")){var r={date:_(n.startTime),longTask:{duration:v(n.duration)},type:Rt.LONG_TASK};e.notify(je.RAW_RUM_EVENT_V2_COLLECTED,{rawRumEvent:r,startTime:n.startTime})}else{r={date:_(n.startTime),duration:v(n.duration),evt:{category:bt.LONG_TASK}};e.notify(je.RAW_RUM_EVENT_COLLECTED,{rawRumEvent:r,startTime:n.startTime})}}))}(n,i),Cn(n,i,o),Ln(n,i,t),vn(n,i),function(e,t){e.subscribe(je.AUTO_ACTION_COMPLETED,(function(n){t.isEnabled("v2_format")?e.notify(je.RAW_RUM_EVENT_V2_COLLECTED,En(n)):e.notify(je.RAW_RUM_EVENT_COLLECTED,pn(n))})),e.subscribe(je.CUSTOM_ACTION_COLLECTED,(function(n){var i=n.action,o=n.context;t.isEnabled("v2_format")?e.notify(je.RAW_RUM_EVENT_V2_COLLECTED,r({savedGlobalContext:o},En(i))):e.notify(je.RAW_RUM_EVENT_COLLECTED,r({savedGlobalContext:o},pn(i)))})),t.trackInteractions&&ft(e)}(n,i),{parentContexts:u,stop:function(){s.stop()}}}(e.applicationId,location,n,a,s,t).parentContexts;dn(n,a),xt(n,a),lt(n);var f=function(e,t,n,r){return{get:function(i){if(r.isEnabled("v2_format")){var o=n.findViewV2(i);if(t.isTracked()&&o&&o.session.id)return j(q({application:{id:e}},o,n.findActionV2(i)))}else{o=n.findView(i);if(t.isTracked()&&o&&o.sessionId)return j(q({applicationId:e},o,n.findAction(i)))}}}}(e.applicationId,s,c,a);return o.subscribe((function(e){return n.notify(je.ERROR_COLLECTED,e)})),{getInternalContext:f.get,addAction:function(e,t){n.notify(je.CUSTOM_ACTION_COLLECTED,{action:e,context:t})},addError:function(e,t){n.notify(je.ERROR_PROVIDED,{error:e,context:t})}}}));function jn(e){var t,n=!1,i=(t={},{get:function(){return t},add:function(e,n){t[e]=n},remove:function(e){delete t[e]},set:function(e){t=e}}),o=function(){},a=new Ge,u=function(e){a.add([e,z(i.get())])},s=new Ge,c=function(e){s.add([e,z(i.get())])},f=function(e){var t=r(r({},e),{onReady:function(e){e()}});return Object.defineProperty(t,"_setDebug",{get:function(){return pe},enumerable:!1}),t}({init:ce((function(t){var r;He(P(t))&&We()&&function(e){if(n)return e.silentMultipleInit||console.error("DD_RUM is already initialized."),!1;if(!e||!e.clientToken&&!e.publicApiKey)return console.error("Client Token is not configured, we will not send any data."),!1;if(!e.applicationId)return console.error("Application ID is not configured, no RUM data will be collected."),!1;if(void 0!==e.sampleRate&&!C(e.sampleRate))return console.error("Sample Rate should be a number between 0 and 100"),!1;if(void 0!==e.resourceSampleRate&&!C(e.resourceSampleRate))return console.error("Resource Sample Rate should be a number between 0 and 100"),!1;if(Array.isArray(e.allowedTracingOrigins)&&0!==e.allowedTracingOrigins.length&&void 0===e.service)return console.error("Service need to be configured when tracing is enabled"),!1;return!0}(t)&&(t.publicApiKey&&(t.clientToken=t.publicApiKey),r=e(t,i.get),u=r.addAction,c=r.addError,o=r.getInternalContext,a.drain((function(e){var t=e[0],n=e[1];return u(t,n)})),s.drain((function(e){var t=e[0],n=e[1];return c(t,n)})),n=!0)})),addRumGlobalContext:ce(i.add),removeRumGlobalContext:ce(i.remove),setRumGlobalContext:ce(i.set),getInternalContext:ce((function(e){return o(e)})),addAction:ce((function(e,t){u({name:e,context:z(t),startTime:performance.now(),type:nt.CUSTOM})})),addUserAction:function(e,t){f.addAction(e,t)},addError:ce((function(e,t,n){var r;void 0===n&&(n=Re.CUSTOM),n===Re.CUSTOM||n===Re.NETWORK||n===Re.SOURCE?r=n:(console.error("DD_RUM.addError: Invalid source '"+n+"'"),r=Re.CUSTOM),c({error:e,context:z(t),source:r,startTime:performance.now()})}))});return f}Vn=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}(),Pn=Wn,Hn=Vn[Bn="DD_RUM"],Vn[Bn]=Pn,Hn&&Hn.q&&Hn.q.forEach((function(e){return e()}))}]); | ||
!function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([,function(e,t,n){"use strict";n.r(t),n.d(t,"datadogRum",(function(){return Gn})),n.d(t,"makeRumGlobal",(function(){return qn}));var r=function(){return(r=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 i(e,t){var n,r,i,o,a={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(;a;)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 a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=(i=a.trys).length>0&&i[i.length-1])&&(6===o[0]||2===o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}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 o(){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],a=0,u=o.length;a<u;a++,i++)r[i]=o[a];return r}var a,u,s,c,f=1e3,d=60*f,l=60*d;function p(e,t,n){var r,i=!n||void 0===n.leading||n.leading,o=!n||void 0===n.trailing||n.trailing,a=!1,u=!1;return{throttled:function(){var n=this;a?u=!0:(i?e.apply(this):u=!0,a=!0,r=window.setTimeout((function(){o&&u&&e.apply(n),a=!1,u=!1}),t))},cancel:function(){window.clearTimeout(r),a=!1,u=!1}}}function E(e){return e?(parseInt(e,10)^16*Math.random()>>parseInt(e,10)/4).toString(16):(1e7+"-1000-4000-8000-100000000000").replace(/[018]/g,E)}function m(e){return 0!==e&&100*Math.random()<=e}function v(e){return"number"!=typeof e?e:+(1e6*e).toFixed(0)}function T(){}function h(e,t,n){if(null==e)return JSON.stringify(e);var r=[!1,void 0];g(e)&&(r=[!0,e.toJSON],delete e.toJSON);var i,o,a=[!1,void 0];"object"==typeof e&&g(i=Object.getPrototypeOf(e))&&(a=[!0,i.toJSON],delete i.toJSON);try{o=JSON.stringify(e,void 0,n)}catch(e){o="<error: unable to serialize object>"}finally{r[0]&&(e.toJSON=r[1]),a[0]&&(i.toJSON=a[1])}return o}function g(e){return"object"==typeof e&&null!==e&&e.hasOwnProperty("toJSON")}function y(e,t){return-1!==e.indexOf(t)}function b(e){return C(e)&&e>=0&&e<=100}function C(e){return"number"==typeof e}function _(e){return Math.floor(R()+e)}function R(){return void 0===c&&(c=performance.timing.navigationStart),c}function O(e){return Object.keys(e).map((function(t){return[t,e[t]]}))}function S(e){if(e.origin)return e.origin;var t=e.host.replace(/(:80|:443)$/,"");return e.protocol+"//"+t}function w(e,t){var n=e.match("(?:^|;)\\s*"+t+"\\s*=\\s*([^;]+)");return n?n[1]:void 0}!function(e){e.BEFORE_UNLOAD="beforeunload",e.CLICK="click",e.KEY_DOWN="keydown",e.LOAD="load",e.POP_STATE="popstate",e.SCROLL="scroll",e.TOUCH_START="touchstart",e.VISIBILITY_CHANGE="visibilitychange",e.DOM_CONTENT_LOADED="DOMContentLoaded"}(a||(a={})),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"}(u||(u={})),function(e){e.FETCH="fetch",e.XHR="xhr"}(s||(s={}));var A,I,L=f;function N(e,t,n,r){var i=new Date;i.setTime(i.getTime()+n);var o="expires="+i.toUTCString(),a=r&&r.crossSite?"none":"strict",u=r&&r.domain?";domain="+r.domain:"",s=r&&r.secure?";secure":"";document.cookie=e+"="+t+";"+o+";path=/;samesite="+a+u+s}function D(e){return w(document.cookie,e)}function x(e){return V(e,S(window.location)).href}function M(e,t){return U(e)===U(t)}function U(e){return S(V(e))}function k(e){var t=V(e).pathname;return"/"===t[0]?t:"/"+t}function V(e,t){if(function(){if(void 0!==I)return I;try{var e=new URL("http://test/path");return I="http://test/path"===e.href}catch(e){I=!1}return I}())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 B={allowedTracingOrigins:[],maxErrorsByMinute:3e3,maxInternalMonitoringMessagesPerPage:15,resourceSampleRate:100,sampleRate:100,silentMultipleInit:!1,trackInteractions:!1,requestErrorResponseLengthLimit:32768,flushTimeout:30*f,maxBatchSize:50,maxMessageSize:262144,batchBytesLimit:16384};function P(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===A){for(var e="dd_site_test_"+E(),t=window.location.hostname.split("."),n=t.pop();t.length&&!D(e);)n=t.pop()+"."+n,N(e,"test",f,{domain:n});A=n}return A}()),t}function W(e,t,n){var r="sdk_version:"+t.sdkVersion+(t.env?",env:"+t.env:"")+(t.service?",service:"+t.service:"")+(t.version?",version:"+t.version:""),i=e+"-http-intake.logs."+t.site,o=t.proxyHost?t.proxyHost:i,a=t.proxyHost?"ddhost="+i+"&":"",u=""+(t.applicationId?"_dd.application_id="+t.applicationId+"&":"")+a+"ddsource="+(n||"browser")+"&ddtags="+r;return"https://"+o+"/v1/input/"+t.clientToken+"?"+u}function H(e,t){return-1!==k(e).indexOf("/v1/input/")&&(M(e,t.logsEndpoint)||M(e,t.rumEndpoint)||M(e,t.traceEndpoint)||!!t.internalMonitoringEndpoint&&M(e,t.internalMonitoringEndpoint)||!!t.replica&&(M(e,t.replica.logsEndpoint)||M(e,t.replica.rumEndpoint)||M(e,t.replica.internalMonitoringEndpoint)))}function j(e){var t={};return Object.keys(e).forEach((function(n){var r;t[(r=n,r.replace(/[A-Z]/g,(function(e,t){return(0!==t?"_":"")+e.toLowerCase()})).replace(/-/g,"_"))]=function e(t){if(Array.isArray(t))return t.map((function(t){return e(t)}));if("object"==typeof t&&null!==t)return j(t);return t}(e[n])})),t}var F,G=function(e){return Array.isArray(e)},q=function(e){return!Array.isArray(e)&&"object"==typeof e&&null!==e};function z(){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=Y(e,o,$()))}return e}function K(e){return Y(void 0,e,$())}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}}}function Y(e,t,n){if(void 0===t)return e;if(!q(t)&&!G(t))return t;if(!n.hasAlreadyBeenSeen(t)){if(q(t)&&(void 0===e||q(e))){var r=e||{};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(r[i]=Y(r[i],t[i],n));return r}if(G(t)&&(void 0===e||G(e))){(r=e||[]).length=Math.max(r.length,t.length);for(var o=0;o<t.length;o+=1)r[o]=Y(r[o],t[o],n);return r}return t}}function X(e,t,n){return e&&(void 0!==e.message||t instanceof Error)?{message:e.message||"Empty message",stack:J(e),type:e.name}:{message:n+" "+h(t),stack:"No stack, consider using an instance of Error",type:e&&e.name}}function J(e){var t=(e.name||"Error")+": "+e.message;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(e){e.AGENT="agent",e.CONSOLE="console",e.NETWORK="network",e.SOURCE="source",e.LOGGER="logger",e.CUSTOM="custom"}(F||(F={}));var Q=/[^\u0000-\u007F]/,Z=function(){function e(e,t,n){void 0===n&&(n=!1),this.endpointUrl=e,this.bytesLimit=t,this.withBatchTime=n}return e.prototype.send=function(e,t){var n=this.withBatchTime?function(e){return e+(-1===e.indexOf("?")?"?":"&")+"batch_time="+(new Date).getTime()}(this.endpointUrl):this.endpointUrl;if(navigator.sendBeacon&&t<this.bytesLimit&&navigator.sendBeacon(n,e))return;var r=new XMLHttpRequest;r.open("POST",n,!0),r.send(e)},e}();var ee=function(){function e(e,t,n,r,i,o){void 0===o&&(o=T),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(){if(0!==this.bufferMessageCount){var e=o(this.pushOnlyBuffer,(t=this.upsertBuffer,n=[],Object.keys(t).forEach((function(e){n.push(t[e])})),n));this.request.send(e.join("\n"),this.bufferBytesSize),this.pushOnlyBuffer=[],this.upsertBuffer={},this.bufferBytesSize=0,this.bufferMessageCount=0}var t,n},e.prototype.sizeInBytes=function(e){return Q.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),r=n.processedMessage,i=n.messageBytesSize;i>=this.maxMessageSize?console.warn("Discarded a message whose size was bigger than the maximum allowed size "+this.maxMessageSize+"KB."):(this.hasMessageFor(t)&&this.remove(t),this.willReachedBytesLimitWith(i)&&this.flush(),this.push(r,i,t),this.isFull()&&this.flush())},e.prototype.process=function(e){var t=h(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((function(){e.flush(),e.flushPeriodically()}),this.flushTimeout)},e.prototype.flushOnVisibilityHidden=function(){var e=this;navigator.sendBeacon&&(window.addEventListener(a.BEFORE_UNLOAD,le(this.beforeUnloadCallback)),document.addEventListener(a.VISIBILITY_CHANGE,le((function(){"hidden"===document.visibilityState&&e.flush()}))),window.addEventListener(a.BEFORE_UNLOAD,le((function(){return e.flush()}))))},e}(),te="?",ne=/^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/;function re(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var ie,oe=function(){var e,t,n,r,i,o,a=[];function u(e,t,n){var r;for(var i in a)if(re(a,i))try{a[i](e,t,n)}catch(e){r=e}if(r)throw r}function s(e,r,i,o,a){if(t)ae.augmentStackTraceWithInitialElement(t,r,i,""+e),f();else if(a)u(ae(a),!0,a);else{var s,c={url:r,column:o,line:i},d=e;if("[object String]"==={}.toString.call(e)){var l=d.match(ne);l&&(s=l[1],d=l[2])}u({name:s,message:d,stack:[c]},!0)}return!!n&&n.apply(this,arguments)}function c(e){var t=e.reason||"Empty reason";u(ae(t),!0,t)}function f(){var n=t,r=e;t=void 0,e=void 0,u(n,!1,r)}function d(n){if(t){if(e===n)return;f()}var r=ae(n);throw t=r,e=n,setTimeout((function(){e===n&&f()}),r.incomplete?2e3:0),n}return d.subscribe=function(e){!function(){if(r)return;n=window.onerror,window.onerror=le(s),r=!0}(),function(){if(o)return;i=null!==window.onunhandledrejection?window.onunhandledrejection:void 0,window.onunhandledrejection=le(c),o=!0}(),a.push(e)},d.unsubscribe=function(e){for(var t=a.length-1;t>=0;t-=1)a[t]===e&&a.splice(t,1);0===a.length&&(r&&(window.onerror=n,r=!1),o&&(window.onunhandledrejection=i,o=!1))},d.traceKitWindowOnError=s,d}(),ae=function(){var e=!1;function t(e){if(e.stack){for(var t,n,r,i,o=/^\s*at (.*?) ?\(((?:file|https?|blob|chrome-extension|native|eval|webpack|<anonymous>|\/).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,a=/^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|resource|\[native).*?|[^@]*bundle)(?::(\d+))?(?::(\d+))?\s*$/i,u=/^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i,s=/(\S+) line (\d+)(?: > eval line \d+)* > eval/i,c=/\((\S*)(?::(\d+))(?::(\d+))\)/,f=e.stack.split("\n"),d=[],l=0,p=f.length;l<p;l+=1){if(o.exec(f[l])){var E=(r=o.exec(f[l]))[2]&&0===r[2].indexOf("native");t=r[2]&&0===r[2].indexOf("eval"),n=c.exec(r[2]),t&&n&&(r[2]=n[1],r[3]=n[2],r[4]=n[3]),i={args:E?[r[2]]:[],column:r[4]?+r[4]:void 0,func:r[1]||te,line:r[3]?+r[3]:void 0,url:E?void 0:r[2]}}else if(u.exec(f[l]))i={args:[],column:(r=u.exec(f[l]))[4]?+r[4]:void 0,func:r[1]||te,line:+r[3],url:r[2]};else{if(!a.exec(f[l]))continue;t=(r=a.exec(f[l]))[3]&&r[3].indexOf(" > eval")>-1,n=s.exec(r[3]),t&&n?(r[3]=n[1],r[4]=n[2],r[5]=void 0):0!==l||r[5]||void 0===e.columnNumber||(d[0].column=e.columnNumber+1),i={args:r[2]?r[2].split(","):[],column:r[5]?+r[5]:void 0,func:r[1]||te,line:r[4]?+r[4]:void 0,url:r[3]}}!i.func&&i.line&&(i.func=te),d.push(i)}if(d.length)return{stack:d,message:e.message,name:e.name}}}function n(e,t,n,r){var i={url:t,line:n?+n:void 0};if(i.url&&i.line){e.incomplete=!1;var o=e.stack;if(o.length>0&&o[0].url===i.url){if(o[0].line===i.line)return!1;if(!o[0].line&&o[0].func===i.func)return o[0].line=i.line,o[0].context=i.context,!1}return o.unshift(i),e.partial=!0,!0}return e.incomplete=!0,!1}function r(e,t){for(var i,o,a=/function\s+([_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*)?\s*\(/i,u=[],s={},c=!1,f=r.caller;f&&!c;f=f.caller)f!==ae&&f!==oe&&(o={args:[],column:void 0,func:te,line:void 0,url:void 0},i=a.exec(f.toString()),f.name?o.func=f.name:i&&(o.func=i[1]),void 0===o.func&&(o.func=i?i.input.substring(0,i.input.indexOf("{")):void 0),s[""+f]?c=!0:s[""+f]=!0,u.push(o));t&&u.splice(0,t);var d={stack:u,message:e.message,name:e.name};return n(d,e.sourceURL||e.fileName,e.line||e.lineNumber,e.message||e.description),d}function i(n,i){var o,a=void 0===i?0:+i;try{if(o=function(e){var t=e.stacktrace;if(t){for(var n,r=/ line (\d+).*script (?:in )?(\S+)(?:: in function (\S+))?$/i,i=/ line (\d+), column (\d+)\s*(?:in (?:<anonymous function: ([^>]+)>|([^\)]+))\((.*)\))? in (.*):\s*$/i,o=t.split("\n"),a=[],u=0;u<o.length;u+=2){var s=void 0;r.exec(o[u])?s={args:[],column:void 0,func:(n=r.exec(o[u]))[3],line:+n[1],url:n[2]}:i.exec(o[u])&&(s={args:(n=i.exec(o[u]))[5]?n[5].split(","):[],column:+n[2],func:n[3]||n[4],line:+n[1],url:n[6]}),s&&(!s.func&&s.line&&(s.func=te),s.context=[o[u+1]],a.push(s))}if(a.length)return{stack:a,message:e.message,name:e.name}}}(n))return o}catch(t){if(e)throw t}try{if(o=t(n))return o}catch(t){if(e)throw t}try{if(o=function(e){var t=e.message.split("\n");if(!(t.length<4)){var n,r=/^\s*Line (\d+) of linked script ((?:file|https?|blob)\S+)(?:: in function (\S+))?\s*$/i,i=/^\s*Line (\d+) of inline#(\d+) script in ((?:file|https?|blob)\S+)(?:: in function (\S+))?\s*$/i,o=/^\s*Line (\d+) of function script\s*$/i,a=[],u=window&&window.document&&window.document.getElementsByTagName("script"),s=[];for(var c in u)re(u,c)&&!u[c].src&&s.push(u[c]);for(var f=2;f<t.length;f+=2){var d=void 0;if(r.exec(t[f]))d={args:[],column:void 0,func:(n=r.exec(t[f]))[3],line:+n[1],url:n[2]};else if(i.exec(t[f]))d={args:[],column:void 0,func:(n=i.exec(t[f]))[4],line:+n[1],url:n[3]};else if(o.exec(t[f])){n=o.exec(t[f]),d={url:window.location.href.replace(/#.*$/,""),args:[],column:void 0,func:"",line:+n[1]}}d&&(d.func||(d.func=te),d.context=[t[f+1]],a.push(d))}if(a.length)return{stack:a,message:t[0],name:e.name}}}(n))return o}catch(t){if(e)throw t}try{if(o=r(n,a+1))return o}catch(t){if(e)throw t}return{message:n.message,name:n.name,stack:[]}}return i.augmentStackTraceWithInitialElement=n,i.computeStackTraceFromStackProp=t,i.ofCaller=function(e){var t=1+(void 0===e?0:+e);try{throw new Error}catch(e){return ae(e,t+1)}},i}();!function(e){e.info="info",e.error="error"}(ie||(ie={}));var ue,se,ce,fe={maxMessagesPerPage:0,sentMessageCount:0};function de(e){if(e.internalMonitoringEndpoint){var t=function(e){var t,n=r(e.internalMonitoringEndpoint);void 0!==e.replica&&(t=r(e.replica.internalMonitoringEndpoint));function r(t){return new ee(new Z(t,e.batchBytesLimit),e.maxBatchSize,e.batchBytesLimit,e.maxMessageSize,e.flushTimeout)}return{add:function(e){var r=function(e){return z({date:(new Date).getTime(),view:{referrer:document.referrer,url:window.location.href}},void 0!==ue?ue():{},e)}(e);n.add(r),t&&t.add(r)}}}(e);!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])}))}(fe,{batch:t,maxMessagesPerPage:e.maxInternalMonitoringMessagesPerPage,sentMessageCount:0})}return{setExternalContextProvider:function(e){ue=e}}}function le(e){return function(){try{return e.apply(this,arguments)}catch(e){Te(e);try{Ee(e)}catch(e){Te(e)}}}}function pe(e,t){!function(e){fe.debugMode&&console.log("[MONITORING MESSAGE]",e)}(e),me(r(r({message:e},t),{status:ie.info}))}function Ee(e){me(r(r({},function(e){if(e instanceof Error){var t=ae(e);return{error:{kind:t.name,stack:J(t)},message:t.message}}return{error:{stack:"Not an instance of error"},message:"Uncaught "+h(e)}}(e)),{status:ie.error}))}function me(e){fe.batch&&fe.sentMessageCount<fe.maxMessagesPerPage&&(fe.sentMessageCount+=1,fe.batch.add(e))}function ve(e){fe.debugMode=e}function Te(e){fe.debugMode&&console.warn("[INTERNAL ERROR]",e)}!function(e){e.US="us",e.EU="eu"}(ce||(ce={}));var he,ge=((se={})[ce.EU]="datadoghq.eu",se[ce.US]="datadoghq.com",se);function ye(e,t){var n=function(e,t){var n={applicationId:e.applicationId,buildMode:t.buildMode,clientToken:e.clientToken,env:e.env,proxyHost:e.proxyHost,sdkVersion:t.sdkVersion,service:e.service,site:e.site||ge[e.datacenter||t.datacenter],version:e.version},i=Array.isArray(e.enableExperimentalFeatures)?e.enableExperimentalFeatures:[],o=r({cookieOptions:P(e),isEnabled:function(e){return y(i,e)},logsEndpoint:W("browser",n),proxyHost:e.proxyHost,rumEndpoint:W("rum",n),service:e.service,traceEndpoint:W("public-trace",n)},B);if(e.internalMonitoringApiKey&&(o.internalMonitoringEndpoint=W("browser",n,"browser-agent-internal-monitoring")),"allowedTracingOrigins"in e&&(o.allowedTracingOrigins=e.allowedTracingOrigins),"sampleRate"in e&&(o.sampleRate=e.sampleRate),"resourceSampleRate"in e&&(o.resourceSampleRate=e.resourceSampleRate),"trackInteractions"in e&&(o.trackInteractions=!!e.trackInteractions),n.buildMode===he.E2E_TEST&&(o.internalMonitoringEndpoint="<<< E2E INTERNAL MONITORING ENDPOINT >>>",o.logsEndpoint="<<< E2E LOGS ENDPOINT >>>",o.rumEndpoint="<<< E2E RUM ENDPOINT >>>"),n.buildMode===he.STAGING&&void 0!==e.replica){var a=r(r({},n),{applicationId:e.replica.applicationId,clientToken:e.replica.clientToken,site:ge[ce.US]});o.replica={applicationId:e.replica.applicationId,internalMonitoringEndpoint:W("browser",a,"browser-agent-internal-monitoring"),logsEndpoint:W("browser",a),rumEndpoint:W("rum",a)}}return o}(e,t);return{configuration:n,internalMonitoring:de(n)}}function be(e){return!!function(e){if(void 0===document.cookie||null===document.cookie)return!1;try{var t="dd_cookie_test_"+E();return N(t,"test",f,e),"test"===D(t)}catch(e){return console.error(e),!1}}(e)||(console.warn("Cookies are not authorized, we will not send any data."),!1)}function Ce(){return"file:"!==window.location.protocol||(console.error("Execution is not allowed in the current context."),!1)}!function(e){e.RELEASE="release",e.STAGING="staging",e.E2E_TEST="e2e-test"}(he||(he={}));var _e,Re=1e4,Oe=function(){function e(e){void 0===e&&(e=Re),this.limit=e,this.buffer=[]}return e.prototype.add=function(e){this.buffer.push(e)>this.limit&&this.buffer.splice(0,1)},e.prototype.drain=function(e){this.buffer.forEach((function(t){return e(t)})),this.buffer.length=0},e}();!function(e){e[e.PERFORMANCE_ENTRY_COLLECTED=0]="PERFORMANCE_ENTRY_COLLECTED",e[e.AUTO_ACTION_CREATED=1]="AUTO_ACTION_CREATED",e[e.AUTO_ACTION_COMPLETED=2]="AUTO_ACTION_COMPLETED",e[e.AUTO_ACTION_DISCARDED=3]="AUTO_ACTION_DISCARDED",e[e.VIEW_CREATED=4]="VIEW_CREATED",e[e.VIEW_UPDATED=5]="VIEW_UPDATED",e[e.REQUEST_STARTED=6]="REQUEST_STARTED",e[e.REQUEST_COMPLETED=7]="REQUEST_COMPLETED",e[e.SESSION_RENEWED=8]="SESSION_RENEWED",e[e.DOM_MUTATED=9]="DOM_MUTATED",e[e.BEFORE_UNLOAD=10]="BEFORE_UNLOAD",e[e.RAW_RUM_EVENT_COLLECTED=11]="RAW_RUM_EVENT_COLLECTED",e[e.RAW_RUM_EVENT_V2_COLLECTED=12]="RAW_RUM_EVENT_V2_COLLECTED",e[e.RUM_EVENT_COLLECTED=13]="RUM_EVENT_COLLECTED",e[e.RUM_EVENT_V2_COLLECTED=14]="RUM_EVENT_V2_COLLECTED"}(_e||(_e={}));var Se,we,Ae=function(){function e(){this.callbacks={}}return e.prototype.notify=function(e,t){var n=this.callbacks[e];n&&n.forEach((function(e){return e(t)}))},e.prototype.subscribe=function(e,t){var n=this;return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t),{unsubscribe:function(){n.callbacks[e]=n.callbacks[e].filter((function(e){return t!==e}))}}},e}();function Ie(e,t){void 0===t&&(t=T);var n={errorCount:0,longTaskCount:0,resourceCount:0,userActionCount:0},r=e.subscribe(_e.RAW_RUM_EVENT_COLLECTED,(function(e){switch(e.rawRumEvent.evt.category){case Se.ERROR:n.errorCount+=1,t(n);break;case Se.USER_ACTION:n.userActionCount+=1,t(n);break;case Se.LONG_TASK:n.longTaskCount+=1,t(n);break;case Se.RESOURCE:n.resourceCount+=1,t(n)}})),i=e.subscribe(_e.RAW_RUM_EVENT_V2_COLLECTED,(function(e){switch(e.rawRumEvent.type){case we.ERROR:n.errorCount+=1,t(n);break;case we.ACTION:n.userActionCount+=1,t(n);break;case we.LONG_TASK:n.longTaskCount+=1,t(n);break;case we.RESOURCE:n.resourceCount+=1,t(n)}}));return{stop:function(){r.unsubscribe(),i.unsubscribe()},eventCounts:n}}!function(e){e.USER_ACTION="user_action",e.ERROR="error",e.LONG_TASK="long_task",e.VIEW="view",e.RESOURCE="resource"}(Se||(Se={})),function(e){e.ACTION="action",e.ERROR="error",e.LONG_TASK="long_task",e.VIEW="view",e.RESOURCE="resource"}(we||(we={}));var Le=function(){function e(){this.observers=[]}return e.prototype.subscribe=function(e){this.observers.push(e)},e.prototype.notify=function(e){this.observers.forEach((function(t){return t(e)}))},e}(),Ne=100,De=100,xe=1e4;function Me(e,t){var n=function(e){var t,n=new Le,r=[],i=0;function o(){n.notify({isBusy:i>0})}return r.push(e.subscribe(_e.DOM_MUTATED,(function(){return o()}))),r.push(e.subscribe(_e.PERFORMANCE_ENTRY_COLLECTED,(function(e){"resource"===e.entryType&&o()}))),r.push(e.subscribe(_e.REQUEST_STARTED,(function(e){void 0===t&&(t=e.requestIndex),i+=1,o()}))),r.push(e.subscribe(_e.REQUEST_COMPLETED,(function(e){void 0===t||e.requestIndex<t||(i-=1,o())}))),{observable:n,stop:function(){r.forEach((function(e){return e.unsubscribe()}))}}}(e),r=n.observable,i=n.stop,o=function(e,t,n){var r,i=!1,o=setTimeout(le((function(){return s(!1,0)})),Ne),a=setTimeout(le((function(){return s(!0,performance.now())})),xe);function u(){i=!0,clearTimeout(o),clearTimeout(r),clearTimeout(a),t()}function s(e,t){i||(u(),n(e,t))}return e.subscribe((function(e){var t=e.isBusy;clearTimeout(o),clearTimeout(r);var n=performance.now();t||(r=setTimeout(le((function(){return s(!0,n)})),De))})),{stop:u}}(r,i,t).stop;return{stop:function(){o(),i()}}}function Ue(e){return function(e){var t;if(function(){void 0===Pe&&(Pe="closest"in HTMLElement.prototype);return Pe}())t=e.closest("["+ke+"]");else for(var n=e;n;){if(n.hasAttribute(ke)){t=n;break}n=n.parentElement}if(!t)return;return ze(qe(t.getAttribute(ke).trim()))}(e)||Ge(e,He)||Ge(e,je)||""}var ke="data-dd-action-name";var Ve,Be,Pe,We,He=[function(e){if(function(){void 0===Be&&(Be="labels"in HTMLInputElement.prototype);return Be}()){if("labels"in e&&e.labels&&e.labels.length>0)return Ke(e.labels[0])}else if(e.id){var t=e.ownerDocument&&e.ownerDocument.querySelector('label[for="'+e.id.replace('"','\\"')+'"]');return t&&Ke(t)}},function(e){if("INPUT"===e.nodeName){var t=e,n=t.getAttribute("type");if("button"===n||"submit"===n||"reset"===n)return t.value}},function(e){if("BUTTON"===e.nodeName||"LABEL"===e.nodeName||"button"===e.getAttribute("role"))return Ke(e)},function(e){return e.getAttribute("aria-label")},function(e){var t=e.getAttribute("aria-labelledby");if(t)return t.split(/\s+/).map((function(t){return function(e,t){return e.ownerDocument?e.ownerDocument.getElementById(t):null}(e,t)})).filter((function(e){return Boolean(e)})).map(Ke).join(" ")},function(e){return e.getAttribute("alt")},function(e){return e.getAttribute("name")},function(e){return e.getAttribute("title")},function(e){return e.getAttribute("placeholder")},function(e){if("options"in e&&e.options.length>0)return Ke(e.options[0])}],je=[function(e){return Ke(e)}],Fe=10;function Ge(e,t){for(var n=e,r=0;r<=Fe&&n&&"BODY"!==n.nodeName&&"HTML"!==n.nodeName&&"HEAD"!==n.nodeName;){for(var i=0,o=t;i<o.length;i++){var a=(0,o[i])(n);if("string"==typeof a){var u=a.trim();if(u)return ze(qe(u))}}if("FORM"===n.nodeName)break;n=n.parentElement,r+=1}}function qe(e){return e.replace(/\s+/g," ")}function ze(e){return e.length>100?(n=100,((r=(t=e).charCodeAt(n-1))>=55296&&r<=56319?t.slice(0,n+1):t.slice(0,n))+" [...]"):e;var t,n,r}function Ke(e){if(!e.isContentEditable){if("innerText"in e){var t=e.innerText;if(!function(){if(void 0===Ve){var e=document.createElement("style");e.textContent="*";var t=document.createElement("div");t.appendChild(e),document.body.appendChild(t),Ve=""===t.innerText,document.body.removeChild(t)}return Ve}())for(var n=e.querySelectorAll("script, style"),r=0;r<n.length;r+=1){var i=n[r].innerText;i.trim().length>0&&(t=t.replace(i,""))}return t}return e.textContent}}function $e(e){var t=function(e){var t,n;return{create:function(r,i){if(!t){var o=new Ye(e,r,i);t=o,n=Me(e,(function(e,n){e?o.complete(n):o.discard(),t=void 0}))}},discardCurrent:function(){t&&(n.stop(),t.discard(),t=void 0)}}}(e);function n(e){if(e.target instanceof Element){var n=Ue(e.target);n&&t.create(We.CLICK,n)}}return e.subscribe(_e.VIEW_CREATED,(function(){t.discardCurrent()})),addEventListener(a.CLICK,n,{capture:!0}),{stop:function(){t.discardCurrent(),removeEventListener(a.CLICK,n,{capture:!0})}}}!function(e){e.CLICK="click",e.CUSTOM="custom"}(We||(We={}));var Ye=function(){function e(e,t,n){this.lifeCycle=e,this.type=t,this.name=n,this.id=E(),this.startTime=performance.now(),this.eventCountsSubscription=Ie(e),this.lifeCycle.notify(_e.AUTO_ACTION_CREATED,{id:this.id,startTime:this.startTime})}return e.prototype.complete=function(e){var t=this.eventCountsSubscription.eventCounts;this.lifeCycle.notify(_e.AUTO_ACTION_COMPLETED,{counts:{errorCount:t.errorCount,longTaskCount:t.longTaskCount,resourceCount:t.resourceCount},duration:e-this.startTime,id:this.id,name:this.name,startTime:this.startTime,type:this.type}),this.eventCountsSubscription.stop()},e.prototype.discard=function(){this.lifeCycle.notify(_e.AUTO_ACTION_DISCARDED),this.eventCountsSubscription.stop()},e}();function Xe(e){var t,n=function(){var e,t=window;if(t.Zone){var n=t.Zone.__symbol__("MutationObserver");e=t[n]}return e||(e=t.MutationObserver),e}();return n&&(t=new n(le((function(){e.notify(_e.DOM_MUTATED)})))).observe(document.documentElement,{attributes:!0,characterData:!0,childList:!0,subtree:!0}),{stop:function(){t&&t.disconnect()}}}var Je="initial_document",Qe=[[u.DOCUMENT,function(e){return Je===e}],[u.XHR,function(e){return"xmlhttprequest"===e}],[u.FETCH,function(e){return"fetch"===e}],[u.BEACON,function(e){return"beacon"===e}],[u.CSS,function(e,t){return null!==t.match(/\.css$/i)}],[u.JS,function(e,t){return null!==t.match(/\.js$/i)}],[u.IMAGE,function(e,t){return y(["image","img","icon"],e)||null!==t.match(/\.(gif|jpg|jpeg|tiff|png|svg|ico)$/i)}],[u.FONT,function(e,t){return null!==t.match(/\.(woff|eot|woff2|ttf)$/i)}],[u.MEDIA,function(e,t){return y(["audio","video"],e)||null!==t.match(/\.(mp3|mp4)$/i)}]];function Ze(e){var t=e.name;if(!function(e){try{return!!V(e)}catch(e){return!1}}(t))return pe('Failed to construct URL for "'+e.name+'"'),u.OTHER;for(var n=k(t),r=0,i=Qe;r<i.length;r++){var o=i[r],a=o[0];if((0,o[1])(e.initiatorType,n))return a}return u.OTHER}function et(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];for(var n=1;n<e.length;n+=1)if(e[n-1]>e[n])return!1;return!0}function tt(e){var t=e.duration,n=e.startTime,r=e.responseEnd;return v(0===t&&n<r?r-n:t)}function nt(e){var t=rt(e);if(t){var n=t.startTime,r=t.fetchStart,i=t.redirectStart,o=t.redirectEnd,a=t.domainLookupStart,u=t.domainLookupEnd,s=t.connectStart,c=t.secureConnectionStart,f=t.connectEnd,d=t.requestStart,l=t.responseStart,p={download:ot(n,l,t.responseEnd),firstByte:ot(n,d,l)};return f!==r&&(p.connect=ot(n,s,f),et(s,c,f)&&(p.ssl=ot(n,c,f))),u!==r&&(p.dns=ot(n,a,u)),it(e)&&(p.redirect=ot(n,i,o)),p}}function rt(e){if(et(e.startTime,e.fetchStart,e.domainLookupStart,e.domainLookupEnd,e.connectStart,e.connectEnd,e.requestStart,e.responseStart,e.responseEnd)){if(!it(e))return e;var t=e.redirectStart,n=e.redirectEnd;if(t<e.startTime&&(t=e.startTime),n<e.startTime&&(n=e.fetchStart),et(e.startTime,t,n,e.fetchStart))return r(r({},e),{redirectEnd:n,redirectStart:t})}}function it(e){return e.fetchStart!==e.startTime}function ot(e,t,n){return{duration:v(n-t),start:v(t-e)}}function at(e){if(e.startTime<e.responseStart)return e.decodedBodySize}function ut(e,t){return t&&!H(t,e)}var st,ct,ft=2*d;function dt(e){var t=function(e){var t=e.querySelector("meta[name=dd-trace-id]"),n=e.querySelector("meta[name=dd-trace-time]");return lt(t&&t.content,n&&n.content)}(e)||function(e){var t=function(e){for(var t=0;t<e.childNodes.length;t+=1){if(n=pt(e.childNodes[t]))return n}if(e.body)for(t=e.body.childNodes.length-1;t>=0;t-=1){var n,r=e.body.childNodes[t];if(n=pt(r))return n;if(!Et(r))break}}(e);if(!t)return;return lt(w(t,"trace-id"),w(t,"trace-time"))}(e);if(t&&!(t.traceTime<=Date.now()-ft))return t.traceId}function lt(e,t){var n=t&&Number(t);if(e&&n)return{traceId:e,traceTime:n}}function pt(e){if(e&&function(e){return"#comment"===e.nodeName}(e)){var t=e.data.match(/^\s*DATADOG;(.*?)\s*$/);if(t)return t[1]}}function Et(e){return"#text"===e.nodeName}function mt(){return void 0!==window.performance&&"getEntries"in performance}function vt(){return window.PerformanceObserver&&void 0!==PerformanceObserver.supportedEntryTypes&&PerformanceObserver.supportedEntryTypes.includes("navigation")}function Tt(e,t){var n;if(n=function(n){bt(e,t,n)},ht("interactive",(function(){var e,t={entryType:"resource",initiatorType:Je,traceId:dt(document)};if(vt()&&performance.getEntriesByType("navigation").length>0){var i=performance.getEntriesByType("navigation")[0];e=r(r({},i.toJSON()),t)}else{var o=gt();e=r(r(r({},o),{decodedBodySize:0,duration:o.responseEnd,name:window.location.href,startTime:0}),t)}n(e)})),mt()&&yt(e,t,performance.getEntries()),window.PerformanceObserver){var i=new PerformanceObserver(le((function(n){return yt(e,t,n.getEntries())}))),o=["resource","navigation","longtask"];"visible"===document.visibilityState&&o.push("paint"),i.observe({entryTypes:o}),mt()&&"addEventListener"in performance&&performance.addEventListener("resourcetimingbufferfull",(function(){performance.clearResourceTimings()}))}vt()||function(e){function t(){e(r(r({},gt()),{entryType:"navigation"}))}ht("complete",(function(){setTimeout(le(t))}))}((function(n){bt(e,t,n)}))}function ht(e,t){if(document.readyState===e||"complete"===document.readyState)t();else{var n="complete"===e?a.LOAD:a.DOM_CONTENT_LOADED,r=le((function(){window.removeEventListener(n,r),t()}));window.addEventListener(n,r)}}function gt(){var e={},t=performance.timing;for(var n in t)C(t[n])&&(e[n]=0===t[n]?0:t[n]-R());return e}function yt(e,t,n){n.forEach((function(n){"resource"!==n.entryType&&"navigation"!==n.entryType&&"paint"!==n.entryType&&"longtask"!==n.entryType||bt(e,t,n)}))}function bt(e,t,n){(function(e){return"navigation"===e.entryType&&e.loadEventEnd<=0})(n)||function(e,t){return"resource"===t.entryType&&!ut(e,t.name)}(t,n)||e.notify(_e.PERFORMANCE_ENTRY_COLLECTED,n)}function Ct(e,t,n,r,i,o){n.subscribe(_e.RAW_RUM_EVENT_COLLECTED,(function(a){var u,s=a.startTime,c=a.rawRumEvent,f=a.savedGlobalContext,d=a.customerContext,l=i.findView(s);if(r.isTracked()&&l&&l.sessionId){var p=i.findAction(s),E={applicationId:e,date:(new Date).getTime(),service:t.service,session:{type:void 0===window._DATADOG_SYNTHETICS_BROWSER?st.USER:st.SYNTHETICS}},m=(u=c,-1!==[Se.ERROR,Se.RESOURCE,Se.LONG_TASK].indexOf(u.evt.category)?z(E,l,p,c):z(E,l,c)),v=z(f||o(),d,j(m));n.notify(_e.RUM_EVENT_COLLECTED,{rumEvent:m,serverRumEvent:v})}}))}function _t(e,t,n,r,i,o){n.subscribe(_e.RAW_RUM_EVENT_V2_COLLECTED,(function(a){var u,s=a.startTime,c=a.rawRumEvent,f=a.savedGlobalContext,d=a.customerContext,l=i.findViewV2(s);if(r.isTracked()&&l&&l.session.id){var p=i.findActionV2(s),E={_dd:{formatVersion:2},application:{id:e},date:(new Date).getTime(),service:t.service,session:{type:void 0===window._DATADOG_SYNTHETICS_BROWSER?ct.USER:ct.SYNTHETICS}},m=(u=c,-1!==[we.ERROR,we.RESOURCE,we.LONG_TASK].indexOf(u.type)?z(E,l,p,c):z(E,l,c)),v=j(m);v.context=z(f||o(),d),n.notify(_e.RUM_EVENT_V2_COLLECTED,{rumEvent:m,serverRumEvent:v})}}))}!function(e){e.SYNTHETICS="synthetics",e.USER="user"}(st||(st={})),function(e){e.SYNTHETICS="synthetics",e.USER="user"}(ct||(ct={}));var Rt="_dd",Ot="_dd_r",St="_dd_l",wt="rum",At="logs";var It="_dd_s",Lt=15*d,Nt=4*l,Dt=d;function xt(e,t,n){var r=function(e,t){var n,r,i=!1,o=function(){i=!0,window.clearTimeout(n),n=window.setTimeout((function(){i=!1}),L)};return{get:function(){return i?r:(r=D(e),o(),r)},set:function(n,i){N(e,n,i,t),r=n,o()}}}(It,e);!function(e){var t=e.get(),n=D(Rt),r=D(Ot),i=D(St);if(!t){var o={};n&&(o.id=n),i&&/^[01]$/.test(i)&&(o[At]=i),r&&/^[012]$/.test(r)&&(o[wt]=r),Vt(o,e)}}(r);var i=new Le,o=kt(r).id,u=p((function(){var e=kt(r),a=n(e[t]),u=a.trackingType,s=a.isTracked;e[t]=u,s&&!e.id&&(e.id=E(),e.created=String(Date.now())),Vt(e,r),s&&o!==e.id&&(o=e.id,i.notify())}),L).throttled;return u(),function(e){var t=le(e),n={capture:!0,passive:!0};[a.CLICK,a.TOUCH_START,a.KEY_DOWN,a.SCROLL].forEach((function(e){document.addEventListener(e,t,n),Pt.push((function(){return document.removeEventListener(e,t,n)}))}))}(u),function(e){var t=le((function(){"visible"===document.visibilityState&&e()})),n=window.setInterval(t,Dt);document.addEventListener(a.VISIBILITY_CHANGE,t),Pt.push((function(){clearInterval(n),document.removeEventListener(a.VISIBILITY_CHANGE,t)}))}((function(){Vt(kt(r),r)})),{getId:function(){return kt(r).id},getTrackingType:function(){return kt(r)[t]},renewObservable:i}}var Mt=/^([a-z]+)=([a-z0-9-]+)$/,Ut="&";function kt(e){var t=function(e){var t=e.get(),n={};(function(e){return void 0!==e&&(-1!==e.indexOf(Ut)||Mt.test(e))})(t)&&t.split(Ut).forEach((function(e){var t=Mt.exec(e);if(null!==t){var r=t[1],i=t[2];n[r]=i}}));return n}(e);return function(e){return(void 0===e.created||Date.now()-Number(e.created)<Nt)&&(void 0===e.expire||Date.now()<Number(e.expire))}(t)?t:(Bt(e),{})}function Vt(e,t){if(n=e,0!==Object.keys(n).length){var n;e.expire=String(Date.now()+Lt);var r=O(e).map((function(e){return e[0]+"="+e[1]})).join(Ut);t.set(r,Lt)}else Bt(t)}function Bt(e){e.set("",0)}var Pt=[];var Wt,Ht=Nt,jt=5*d,Ft=d;var Gt,qt,zt,Kt,$t=[],Yt=[];function Xt(){return Wt||(Gt=XMLHttpRequest.prototype.open,qt=XMLHttpRequest.prototype.send,XMLHttpRequest.prototype.open=le((function(e,t){return this._datadog_xhr={method:e,startTime:-1,url:x(t)},Gt.apply(this,arguments)})),XMLHttpRequest.prototype.send=le((function(e){var t=this;if(this._datadog_xhr){this._datadog_xhr.startTime=performance.now();var n=this.onreadystatechange;this.onreadystatechange=function(){this.readyState===XMLHttpRequest.DONE&&le(i)(),n&&n.apply(this,arguments)};var r=!1,i=function(){r||(r=!0,t._datadog_xhr.duration=performance.now()-t._datadog_xhr.startTime,t._datadog_xhr.response=t.response,t._datadog_xhr.status=t.status,Yt.forEach((function(e){return e(t._datadog_xhr)})))};this.addEventListener("loadend",le(i)),$t.forEach((function(e){return e(t._datadog_xhr,t)}))}return qt.apply(this,arguments)})),Wt={beforeSend:function(e){$t.push(e)},onRequestComplete:function(e){Yt.push(e)}}),Wt}var Jt=[],Qt=[];function Zt(){return zt||(!function(){if(!window.fetch)return;Kt=window.fetch,window.fetch=le((function(e,t){var n=this,r=t&&t.method||"object"==typeof e&&e.method||"GET",o=x("object"==typeof e&&e.url||e),a={init:t,method:r,startTime:performance.now(),url:o},u=function(e){return t=n,r=void 0,u=function(){var t,n;return i(this,(function(r){switch(r.label){case 0:return a.duration=performance.now()-a.startTime,"stack"in e||e instanceof Error?(a.status=0,a.response=J(ae(e)),Qt.forEach((function(e){return e(a)})),[3,6]):[3,1];case 1:if(!("status"in e))return[3,6];t=void 0,r.label=2;case 2:return r.trys.push([2,4,,5]),[4,e.clone().text()];case 3:return t=r.sent(),[3,5];case 4:return n=r.sent(),t="Unable to retrieve response: "+n,[3,5];case 5:a.response=t,a.responseType=e.type,a.status=e.status,Qt.forEach((function(e){return e(a)})),r.label=6;case 6:return[2]}}))},new((o=void 0)||(o=Promise))((function(e,n){function i(e){try{s(u.next(e))}catch(e){n(e)}}function a(e){try{s(u.throw(e))}catch(e){n(e)}}function s(t){t.done?e(t.value):new o((function(e){e(t.value)})).then(i,a)}s((u=u.apply(t,r||[])).next())}));var t,r,o,u};Jt.forEach((function(e){return e(a)}));var s=Kt.call(this,e,a.init);return s.then(le(u),le(u)),s}))}(),zt={beforeSend:function(e){Jt.push(e)},onRequestComplete:function(e){Qt.push(e)}}),zt}function en(e,t,n){if(void 0!==tn()&&function(e,t){for(var n=U(t),r=0,i=e.allowedTracingOrigins;r<i.length;r++){var o=i[r];if(n===o||o instanceof RegExp&&o.test(n))return!0}return!1}(e,t)){var r=new un,i=new un;return n(function(e,t){return{"x-datadog-origin":"rum","x-datadog-parent-id":t.toDecimalString(),"x-datadog-sampled":"1","x-datadog-sampling-priority":"1","x-datadog-trace-id":e.toDecimalString()}}(r,i)),{traceId:r,spanId:i}}}function tn(){return window.crypto||window.msCrypto}var nn,rn,on,an,un=function(){function e(){this.buffer=new Uint8Array(8),tn().getRandomValues(this.buffer),this.buffer[0]=127&this.buffer[0]}return e.prototype.toString=function(e){for(var t=this.readInt32(0),n=this.readInt32(4),r="";;){var i=t%e*4294967296+n;if(t=Math.floor(t/e),n=Math.floor(i/e),r=(i%e).toString(e)+r,!t&&!n)break}return r},e.prototype.toDecimalString=function(){return this.toString(10)},e.prototype.readInt32=function(e){return 16777216*this.buffer[e]+(this.buffer[e+1]<<16)+(this.buffer[e+2]<<8)+this.buffer[e+3]},e}(),sn=1;function cn(e,t){var n=function(e){return{traceFetch:function(t){return en(e,t.url,(function(e){t.init=r({},t.init);var n=[];t.init.headers instanceof Headers?t.init.headers.forEach((function(e,t){n.push([t,e])})):Array.isArray(t.init.headers)?t.init.headers.forEach((function(e){n.push(e)})):t.init.headers&&Object.keys(t.init.headers).forEach((function(e){n.push([e,t.init.headers[e]])})),t.init.headers=n.concat(O(e))}))},traceXhr:function(t,n){return en(e,t.url,(function(e){Object.keys(e).forEach((function(t){n.setRequestHeader(t,e[t])}))}))}}}(t);!function(e,t,n){var r=Xt();r.beforeSend((function(r,i){if(ut(t,r.url)){var o=n.traceXhr(r,i);o&&(r.traceId=o.traceId,r.spanId=o.spanId),r.requestIndex=fn(),e.notify(_e.REQUEST_STARTED,{requestIndex:r.requestIndex})}})),r.onRequestComplete((function(n){ut(t,n.url)&&e.notify(_e.REQUEST_COMPLETED,{duration:n.duration,method:n.method,requestIndex:n.requestIndex,response:n.response,spanId:n.spanId,startTime:n.startTime,status:n.status,traceId:n.traceId,type:s.XHR,url:n.url})}))}(e,t,n),function(e,t,n){var r=Zt();r.beforeSend((function(r){if(ut(t,r.url)){var i=n.traceFetch(r);i&&(r.traceId=i.traceId,r.spanId=i.spanId),r.requestIndex=fn(),e.notify(_e.REQUEST_STARTED,{requestIndex:r.requestIndex})}})),r.onRequestComplete((function(n){ut(t,n.url)&&e.notify(_e.REQUEST_COMPLETED,{duration:n.duration,method:n.method,requestIndex:n.requestIndex,response:n.response,responseType:n.responseType,spanId:n.spanId,startTime:n.startTime,status:n.status,traceId:n.traceId,type:s.FETCH,url:n.url})}))}(e,t,n)}function fn(){var e=sn;return sn+=1,e}function dn(e,t){return e.subscribe(_e.AUTO_ACTION_COMPLETED,(function(n){t.isEnabled("v2_format")?e.notify(_e.RAW_RUM_EVENT_V2_COLLECTED,pn(n)):e.notify(_e.RAW_RUM_EVENT_COLLECTED,ln(n))})),t.trackInteractions&&$e(e),{addAction:function(n,i){t.isEnabled("v2_format")?e.notify(_e.RAW_RUM_EVENT_V2_COLLECTED,r({savedGlobalContext:i},pn(n))):e.notify(_e.RAW_RUM_EVENT_COLLECTED,r({savedGlobalContext:i},ln(n)))}}}function ln(e){var t=En(e)?{duration:v(e.duration),userAction:{id:e.id,measures:e.counts}}:void 0;return{customerContext:En(e)?void 0:e.context,rawRumEvent:z({date:_(e.startTime),evt:{category:Se.USER_ACTION,name:e.name},userAction:{type:e.type}},t),startTime:e.startTime}}function pn(e){var t=En(e)?{action:{error:{count:e.counts.errorCount},id:e.id,loadingTime:v(e.duration),longTask:{count:e.counts.longTaskCount},resource:{count:e.counts.resourceCount}}}:void 0;return{customerContext:En(e)?void 0:e.context,rawRumEvent:z({action:{target:{name:e.name},type:e.type},date:_(e.startTime),type:we.ACTION},t),startTime:e.startTime}}function En(e){return e.type!==We.CUSTOM}function mn(e){if(!nn){var t=new Le;!function(e,t){function n(n,r){H(r.url,e)||!function(e){return 0===e.status&&"opaque"!==e.responseType}(r)&&!function(e){return e.status>=500}(r)||t.notify({message:hn(n)+" error "+r.method+" "+r.url,resource:{method:r.method,statusCode:r.status,url:r.url},source:F.NETWORK,stack:Tn(r.response,e)||"Failed to load",startTime:r.startTime})}Xt().onRequestComplete((function(e){return n(s.XHR,e)})),Zt().onRequestComplete((function(e){return n(s.FETCH,e)}))}(e,t),function(e){rn=console.error,console.error=le((function(t){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];rn.apply(console,o([t],n)),e.notify({message:o(["console error:",t],n).map(vn).join(" "),source:F.CONSOLE,startTime:performance.now()})}))}(t),function(e){on=function(t,n,r){var i=X(t,r,"Uncaught"),o=i.stack,a=i.message,u=i.type;e.notify({message:a,stack:o,type:u,source:F.SOURCE,startTime:performance.now()})},oe.subscribe(on)}(t),nn=function(e,t){var n=0,r=new Le;return t.subscribe((function(t){n<e.maxErrorsByMinute?(n+=1,r.notify(t)):n===e.maxErrorsByMinute&&(n+=1,r.notify({message:"Reached max number of errors by minute: "+e.maxErrorsByMinute,source:F.AGENT,startTime:performance.now()}))})),setInterval((function(){return n=0}),d),r}(e,t)}return nn}function vn(e){return"string"==typeof e?e:e instanceof Error?J(ae(e)):h(e,0,2)}function Tn(e,t){return e&&e.length>t.requestErrorResponseLengthLimit?e.substring(0,t.requestErrorResponseLengthLimit)+"...":e}function hn(e){return s.XHR===e?"XHR":"Fetch"}function gn(e,t){return function(e,t,n){return n.subscribe((function(n){t.isEnabled("v2_format")?e.notify(_e.RAW_RUM_EVENT_V2_COLLECTED,bn(n)):e.notify(_e.RAW_RUM_EVENT_COLLECTED,yn(n))})),{addError:function(n,i){var o=n.error,a=n.startTime,u=n.context,s=function(e,t,n){var i=e instanceof Error?ae(e):void 0;return r({startTime:t,source:n},X(i,e,"Provided"))}(o,a,n.source);t.isEnabled("v2_format")?e.notify(_e.RAW_RUM_EVENT_V2_COLLECTED,r({customerContext:u,savedGlobalContext:i},bn(s))):e.notify(_e.RAW_RUM_EVENT_COLLECTED,r({customerContext:u,savedGlobalContext:i},yn(s)))}}}(e,t,mn(t))}function yn(e){return{rawRumEvent:z({date:_(e.startTime),error:{kind:e.type,origin:e.source,stack:e.stack},evt:{category:Se.ERROR},message:e.message},e.resource?{http:{method:e.resource.method,status_code:e.resource.statusCode,url:e.resource.url}}:void 0),startTime:e.startTime}}function bn(e){return{rawRumEvent:{date:_(e.startTime),error:{message:e.message,resource:e.resource,source:e.source,stack:e.stack,type:e.type},type:we.ERROR},startTime:e.startTime}}function Cn(e){if(performance&&"getEntriesByName"in performance){var t,n=performance.getEntriesByName(e.url,"resource").map((function(e){return e.toJSON()})).filter(rt).filter((function(t){return n=t,r=e.startTime,i=_n(e),n.startTime>=r&&_n(n)<=i;var n,r,i}));return 1===n.length?n[0]:2===n.length&&_n((t=n)[0])<=t[1].startTime?n[1]:void 0}}function _n(e){return e.startTime+e.duration}function Rn(e,t,n){e.subscribe(_e.REQUEST_COMPLETED,(function(r){n.isTrackedWithResource()&&(t.isEnabled("v2_format")?e.notify(_e.RAW_RUM_EVENT_V2_COLLECTED,function(e){var t=e.type===s.XHR?u.XHR:u.FETCH,n=Cn(e),r=n?n.startTime:e.startTime,i=n?Sn(n):void 0,o=wn(e),a=z({date:_(r),resource:{type:t,duration:v(e.duration),method:e.method,statusCode:e.status,url:e.url},type:we.RESOURCE},o,i);return{startTime:r,rawRumEvent:a}}(r)):e.notify(_e.RAW_RUM_EVENT_COLLECTED,function(e){var t=e.type===s.XHR?u.XHR:u.FETCH,n=Cn(e),r=n?n.startTime:e.startTime,i=n?On(n):void 0,o=wn(e),a=z({date:_(r),duration:v(e.duration),evt:{category:Se.RESOURCE},http:{method:e.method,statusCode:e.status,url:e.url},resource:{kind:t}},o,i);return{startTime:r,rawRumEvent:a}}(r)))})),e.subscribe(_e.PERFORMANCE_ENTRY_COLLECTED,(function(r){var i;n.isTrackedWithResource()&&"resource"===r.entryType&&("xmlhttprequest"!==(i=r).initiatorType&&"fetch"!==i.initiatorType)&&(t.isEnabled("v2_format")?e.notify(_e.RAW_RUM_EVENT_V2_COLLECTED,function(e){var t=Ze(e),n=Sn(e),r=An(e),i=z({date:_(e.startTime),resource:{type:t,url:e.name},type:we.RESOURCE},r,n);return{startTime:e.startTime,rawRumEvent:i}}(r)):e.notify(_e.RAW_RUM_EVENT_COLLECTED,function(e){var t=Ze(e),n=On(e),r=An(e),i=z({date:_(e.startTime),evt:{category:Se.RESOURCE},http:{url:e.name},resource:{kind:t}},r,n);return{startTime:e.startTime,rawRumEvent:i}}(r)))}))}function On(e){return{duration:tt(e),http:{performance:nt(e)},network:{bytesWritten:at(e)}}}function Sn(e){return{resource:r({duration:tt(e),size:at(e)},nt(e))}}function wn(e){if(e.traceId&&e.spanId)return{_dd:{spanId:e.spanId.toDecimalString(),traceId:e.traceId.toDecimalString()},resource:{id:E()}}}function An(e){return e.traceId?{_dd:{traceId:e.traceId}}:void 0}!function(e){e.INITIAL_LOAD="initial_load",e.ROUTE_CHANGE="route_change"}(an||(an={}));var In=3e3,Ln=5*d;function Nn(e,t){var n,i=Dn(t,e,an.INITIAL_LOAD,document.referrer,0),o=i,u=function(e,t){var n;return{stop:e.subscribe(_e.PERFORMANCE_ENTRY_COLLECTED,(function(e){"navigation"===e.entryType?(n=r(r({},n),{domComplete:e.domComplete,domContentLoaded:e.domContentLoadedEventEnd,domInteractive:e.domInteractive,loadEventEnd:e.loadEventEnd}),t(n)):"paint"===e.entryType&&"first-contentful-paint"===e.name&&(n=r(r({},n),{firstContentfulPaint:e.startTime}),t(n))})).unsubscribe}}(t,(function(e){i.updateTimings(e),i.scheduleUpdate()})).stop;function s(){o.isDifferentView(e)?(o.triggerUpdate(),o.end(),o=Dn(t,e,an.ROUTE_CHANGE,o.url)):(o.updateLocation(e),o.triggerUpdate())}!function(e){var t=history.pushState;history.pushState=le((function(){t.apply(this,arguments),e()}));var n=history.replaceState;history.replaceState=le((function(){n.apply(this,arguments),e()})),window.addEventListener(a.POP_STATE,le(e))}(s),n=s,window.addEventListener("hashchange",le(n)),t.subscribe(_e.SESSION_RENEWED,(function(){o.end(),o=Dn(t,e,an.ROUTE_CHANGE,o.url)})),t.subscribe(_e.BEFORE_UNLOAD,(function(){o.triggerUpdate(),o.end()}));var c=window.setInterval(le((function(){o.triggerUpdate()})),Ln);return{stop:function(){u(),o.end(),clearInterval(c)}}}function Dn(e,t,n,i,o){void 0===o&&(o=performance.now());var a,u,s=E(),c={errorCount:0,longTaskCount:0,resourceCount:0,userActionCount:0},f={},d=0,l=r({},t);e.notify(_e.VIEW_CREATED,{id:s,startTime:o,location:l,referrer:i});var m=p(le(_),In,{leading:!1}),v=m.throttled,T=m.cancel,h=Ie(e,(function(e){c=e,v()})).stop,g=function(e,t){var n=e===an.INITIAL_LOAD,r=!0,i=[];function o(){!r&&!n&&i.length>0&&t(Math.max.apply(Math,i))}return{setLoadEventEnd:function(e){n&&(n=!1,i.push(e),o())},setActivityLoadingTime:function(e){r&&(r=!1,void 0!==e&&i.push(e),o())}}}(n,(function(e){a=e,v()})),y=g.setActivityLoadingTime,b=g.setLoadEventEnd,C=function(e,t){var n=performance.now();return{stop:Me(e,(function(e,r){t(e?r-n:void 0)})).stop}}(e,y).stop;function _(){d+=1,e.notify(_e.VIEW_UPDATED,{documentVersion:d,eventCounts:c,id:s,loadingTime:a,loadingType:n,location:l,referrer:i,startTime:o,timings:f,duration:(void 0===u?performance.now():u)-o})}return(_(),{scheduleUpdate:v,end:function(){u=performance.now(),h(),C()},isDifferentView:function(e){return l.pathname!==e.pathname||(t=e.hash,n=t.substr(1),!document.getElementById(n)&&e.hash!==l.hash);var t,n},triggerUpdate:function(){T(),_()},updateTimings:function(e){f=e,void 0!==e.loadEventEnd&&b(e.loadEventEnd)},updateLocation:function(e){l=r({},e)},get url(){return l.href}})}function xn(e,t,n){return e.subscribe(_e.VIEW_UPDATED,(function(n){t.isEnabled("v2_format")?e.notify(_e.RAW_RUM_EVENT_V2_COLLECTED,function(e){return{rawRumEvent:{_dd:{documentVersion:e.documentVersion},date:_(e.startTime),type:we.VIEW,view:{action:{count:e.eventCounts.userActionCount},domComplete:v(e.timings.domComplete),domContentLoaded:v(e.timings.domContentLoaded),domInteractive:v(e.timings.domInteractive),error:{count:e.eventCounts.errorCount},firstContentfulPaint:v(e.timings.firstContentfulPaint),loadEventEnd:v(e.timings.loadEventEnd),loadingTime:v(e.loadingTime),loadingType:e.loadingType,longTask:{count:e.eventCounts.longTaskCount},resource:{count:e.eventCounts.resourceCount},timeSpent:v(e.duration)}},startTime:e.startTime}}(n)):e.notify(_e.RAW_RUM_EVENT_COLLECTED,function(e){return{rawRumEvent:{date:_(e.startTime),duration:v(e.duration),evt:{category:Se.VIEW},rum:{documentVersion:e.documentVersion},view:{loadingTime:v(e.loadingTime),loadingType:e.loadingType,measures:r(r({},e.eventCounts),{domComplete:v(e.timings.domComplete),domContentLoaded:v(e.timings.domContentLoaded),domInteractive:v(e.timings.domInteractive),firstContentfulPaint:v(e.timings.firstContentfulPaint),loadEventEnd:v(e.timings.loadEventEnd)})}},startTime:e.startTime}}(n))})),Nn(n,e)}var Mn,Un="rum";function kn(e,t){var n=xt(e.cookieOptions,Un,(function(t){return function(e,t){var n;n=function(e){return e===Mn.NOT_TRACKED||e===Mn.TRACKED_WITH_RESOURCES||e===Mn.TRACKED_WITHOUT_RESOURCES}(t)?t:m(e.sampleRate)?m(e.resourceSampleRate)?Mn.TRACKED_WITH_RESOURCES:Mn.TRACKED_WITHOUT_RESOURCES:Mn.NOT_TRACKED;return{trackingType:n,isTracked:Vn(n)}}(e,t)}));return n.renewObservable.subscribe((function(){t.notify(_e.SESSION_RENEWED)})),{getId:n.getId,isTracked:function(){return void 0!==n.getId()&&Vn(n.getTrackingType())},isTrackedWithResource:function(){return void 0!==n.getId()&&n.getTrackingType()===Mn.TRACKED_WITH_RESOURCES}}}function Vn(e){return e===Mn.TRACKED_WITH_RESOURCES||e===Mn.TRACKED_WITHOUT_RESOURCES}function Bn(e,t){var n=function(e,t){var n,r=o(e.rumEndpoint,(function(){return t.notify(_e.BEFORE_UNLOAD)})),i=e.replica;void 0!==i&&(n=o(i.rumEndpoint));function o(t,n){return new ee(new Z(t,e.batchBytesLimit,!0),e.maxBatchSize,e.batchBytesLimit,e.maxMessageSize,e.flushTimeout,n)}function a(e){return z(e,{application_id:i.applicationId})}var u=!1;return{add:function(e){u||(r.add(e),n&&n.add(a(e)))},stop:function(){u=!0},upsert:function(e,t){u||(r.upsert(e,t),n&&n.upsert(a(e),t))}}}(e,t);return t.subscribe(_e.RUM_EVENT_COLLECTED,(function(e){var t=e.rumEvent,r=e.serverRumEvent;t.evt.category===Se.VIEW?n.upsert(r,t.view.id):n.add(r)})),t.subscribe(_e.RUM_EVENT_V2_COLLECTED,(function(e){var t=e.rumEvent,r=e.serverRumEvent;t.type===we.VIEW?n.upsert(r,t.view.id):n.add(r)})),{stop:function(){n.stop()}}}!function(e){e.NOT_TRACKED="0",e.TRACKED_WITH_RESOURCES="1",e.TRACKED_WITHOUT_RESOURCES="2"}(Mn||(Mn={}));var Pn={buildMode:"release",datacenter:"us",sdkVersion:"1.25.2"};var Wn,Hn,jn,Fn,Gn=qn((function(e,t){var n=new Ae,r=ye(e,Pn),i=r.configuration,o=r.internalMonitoring,a=kn(i,n);o.setExternalContextProvider((function(){return z({application_id:e.applicationId},s.findView(),t())}));var u=function(e,t,n,r,i,o){var a=function(e,t){var n,r,i,o=[],a=[];e.subscribe(_e.VIEW_CREATED,(function(e){n&&o.unshift({context:c(),endTime:e.startTime,startTime:n.startTime}),n=e,i=t.getId()})),e.subscribe(_e.VIEW_UPDATED,(function(e){n.id===e.id&&(n=e)})),e.subscribe(_e.AUTO_ACTION_CREATED,(function(e){r=e})),e.subscribe(_e.AUTO_ACTION_COMPLETED,(function(e){r&&a.unshift({context:f(),endTime:r.startTime+e.duration,startTime:r.startTime}),r=void 0})),e.subscribe(_e.AUTO_ACTION_DISCARDED,(function(){r=void 0})),e.subscribe(_e.SESSION_RENEWED,(function(){o=[],a=[],n=void 0,r=void 0}));var u=window.setInterval(le((function(){s(o,Ht),s(a,jt)})),Ft);function s(e,t){for(var n=performance.now()-t;e.length>0&&e[e.length-1].startTime<n;)e.pop()}function c(){return{sessionId:i,view:{id:n.id,referrer:n.referrer,url:n.location.href}}}function f(){return{userAction:{id:r.id}}}function d(e,t,n,r){if(void 0===r)return n?e():void 0;if(n&&r>=n.startTime)return e();for(var i=0,o=t;i<o.length;i++){var a=o[i];if(r>a.endTime)break;if(r>=a.startTime)return a.context}}var l={findAction:function(e){return d(f,a,r,e)},findActionV2:function(e){var t=l.findAction(e);if(t)return{action:{id:t.userAction.id}}},findView:function(e){return d(c,o,n,e)},findViewV2:function(e){var t=l.findView(e);if(t)return{session:{id:t.sessionId},view:t.view}},stop:function(){window.clearInterval(u)}};return l}(n,i),u=Bn(r,n);Ct(e,r,n,i,a,o),_t(e,r,n,i,a,o),function(e,t){e.subscribe(_e.PERFORMANCE_ENTRY_COLLECTED,(function(n){if("longtask"===n.entryType)if(t.isEnabled("v2_format")){var r={date:_(n.startTime),longTask:{duration:v(n.duration)},type:we.LONG_TASK};e.notify(_e.RAW_RUM_EVENT_V2_COLLECTED,{rawRumEvent:r,startTime:n.startTime})}else{r={date:_(n.startTime),duration:v(n.duration),evt:{category:Se.LONG_TASK}};e.notify(_e.RAW_RUM_EVENT_COLLECTED,{rawRumEvent:r,startTime:n.startTime})}}))}(n,r),Rn(n,r,i),xn(n,r,t);var s=gn(n,r).addError;return{addAction:dn(n,r).addAction,addError:s,parentContexts:a,stop:function(){u.stop()}}}(e.applicationId,location,n,i,a,t),s=u.parentContexts,c=u.addError,f=u.addAction;return cn(n,i),Tt(n,i),Xe(n),{addAction:f,addError:c,getInternalContext:function(e,t,n,r){return{get:function(i){if(r.isEnabled("v2_format")){var o=n.findViewV2(i);if(t.isTracked()&&o&&o.session.id)return j(z({application:{id:e}},o,n.findActionV2(i)))}else{o=n.findView(i);if(t.isTracked()&&o&&o.sessionId)return j(z({applicationId:e},o,n.findAction(i)))}}}}(e.applicationId,a,s,i).get}}));function qn(e){var t,n=!1,i=(t={},{get:function(){return t},add:function(e,n){t[e]=n},remove:function(e){delete t[e]},set:function(e){t=e}}),o=function(){},a=new Oe,u=function(e){a.add([e,K(i.get())])},s=new Oe,c=function(e){s.add([e,K(i.get())])},f=function(e){var t=r(r({},e),{onReady:function(e){e()}});return Object.defineProperty(t,"_setDebug",{get:function(){return ve},enumerable:!1}),t}({init:le((function(t){var r;be(P(t))&&Ce()&&function(e){if(n)return e.silentMultipleInit||console.error("DD_RUM is already initialized."),!1;if(!e||!e.clientToken&&!e.publicApiKey)return console.error("Client Token is not configured, we will not send any data."),!1;if(!e.applicationId)return console.error("Application ID is not configured, no RUM data will be collected."),!1;if(void 0!==e.sampleRate&&!b(e.sampleRate))return console.error("Sample Rate should be a number between 0 and 100"),!1;if(void 0!==e.resourceSampleRate&&!b(e.resourceSampleRate))return console.error("Resource Sample Rate should be a number between 0 and 100"),!1;if(Array.isArray(e.allowedTracingOrigins)&&0!==e.allowedTracingOrigins.length&&void 0===e.service)return console.error("Service need to be configured when tracing is enabled"),!1;return!0}(t)&&(t.publicApiKey&&(t.clientToken=t.publicApiKey),r=e(t,i.get),u=r.addAction,c=r.addError,o=r.getInternalContext,a.drain((function(e){var t=e[0],n=e[1];return u(t,n)})),s.drain((function(e){var t=e[0],n=e[1];return c(t,n)})),n=!0)})),addRumGlobalContext:le(i.add),removeRumGlobalContext:le(i.remove),setRumGlobalContext:le(i.set),getInternalContext:le((function(e){return o(e)})),addAction:le((function(e,t){u({name:e,context:K(t),startTime:performance.now(),type:We.CUSTOM})})),addUserAction:function(e,t){f.addAction(e,t)},addError:le((function(e,t,n){var r;void 0===n&&(n=F.CUSTOM),n===F.CUSTOM||n===F.NETWORK||n===F.SOURCE?r=n:(console.error("DD_RUM.addError: Invalid source '"+n+"'"),r=F.CUSTOM),c({error:e,context:K(t),source:r,startTime:performance.now()})}))});return f}Wn=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}(),jn=Gn,Fn=Wn[Hn="DD_RUM"],Wn[Hn]=jn,Fn&&Fn.q&&Fn.q.forEach((function(e){return e()}))}]); |
@@ -6,4 +6,4 @@ "use strict"; | ||
datacenter: 'us', | ||
sdkVersion: '1.25.1', | ||
sdkVersion: '1.25.2', | ||
}; | ||
//# sourceMappingURL=buildEnv.js.map |
import { Configuration, Context } from '@datadog/browser-core'; | ||
import { LifeCycle } from '../domain/lifeCycle'; | ||
import { CustomAction } from '../domain/rumEventsCollection/action/trackActions'; | ||
import { ProvidedError } from '../domain/rumEventsCollection/error/errorCollection'; | ||
import { RumSession } from '../domain/rumSession'; | ||
import { RumUserConfiguration } from './rum.entry'; | ||
export declare function startRum(userConfiguration: RumUserConfiguration, getGlobalContext: () => Context): { | ||
getInternalContext: (startTime?: number | undefined) => import("..").InternalContext | import("../typesV2").InternalContextV2 | undefined; | ||
addAction(action: CustomAction, context?: Context | undefined): void; | ||
addError(error: ProvidedError, context?: Context | undefined): void; | ||
addAction: (action: import("../domain/rumEventsCollection/action/trackActions").CustomAction, savedGlobalContext?: Context | undefined) => void; | ||
addError: ({ error, startTime, context: customerContext, source }: import("../domain/rumEventsCollection/error/errorCollection").ProvidedError, savedGlobalContext?: Context | undefined) => void; | ||
getInternalContext: (startTime?: number | undefined) => import("../typesV2").InternalContextV2 | import("..").InternalContext | undefined; | ||
}; | ||
export declare function startRumEventCollection(applicationId: string, location: Location, lifeCycle: LifeCycle, configuration: Configuration, session: RumSession, getGlobalContext: () => Context): { | ||
addAction: (action: import("../domain/rumEventsCollection/action/trackActions").CustomAction, savedGlobalContext?: Context | undefined) => void; | ||
addError: ({ error, startTime, context: customerContext, source }: import("../domain/rumEventsCollection/error/errorCollection").ProvidedError, savedGlobalContext?: Context | undefined) => void; | ||
parentContexts: import("../domain/parentContexts").ParentContexts; | ||
stop(): void; | ||
}; |
@@ -12,3 +12,3 @@ import { Context, ErrorSource, UserConfiguration } from '@datadog/browser-core'; | ||
setRumGlobalContext: (newContext: Context) => void; | ||
getInternalContext: (startTime?: number | undefined) => import("..").InternalContext | import("../typesV2").InternalContextV2 | undefined; | ||
getInternalContext: (startTime?: number | undefined) => import("../typesV2").InternalContextV2 | import("..").InternalContext | undefined; | ||
addAction: (name: string, context?: Context | undefined) => void; | ||
@@ -26,3 +26,3 @@ addUserAction: (name: string, context?: Context | undefined) => void; | ||
setRumGlobalContext: (newContext: Context) => void; | ||
getInternalContext: (startTime?: number | undefined) => import("..").InternalContext | import("../typesV2").InternalContextV2 | undefined; | ||
getInternalContext: (startTime?: number | undefined) => import("../typesV2").InternalContextV2 | import("..").InternalContext | undefined; | ||
addAction: (name: string, context?: Context | undefined) => void; | ||
@@ -29,0 +29,0 @@ addUserAction: (name: string, context?: Context | undefined) => void; |
@@ -22,4 +22,3 @@ "use strict"; | ||
var lifeCycle = new lifeCycle_1.LifeCycle(); | ||
var isCollectingError = true; | ||
var _a = browser_core_1.commonInit(userConfiguration, buildEnv_1.buildEnv, isCollectingError), errorObservable = _a.errorObservable, configuration = _a.configuration, internalMonitoring = _a.internalMonitoring; | ||
var _a = browser_core_1.commonInit(userConfiguration, buildEnv_1.buildEnv), configuration = _a.configuration, internalMonitoring = _a.internalMonitoring; | ||
var session = rumSession_1.startRumSession(configuration, lifeCycle); | ||
@@ -31,3 +30,3 @@ internalMonitoring.setExternalContextProvider(function () { | ||
}); | ||
var parentContexts = startRumEventCollection(userConfiguration.applicationId, location, lifeCycle, configuration, session, getGlobalContext).parentContexts; | ||
var _b = startRumEventCollection(userConfiguration.applicationId, location, lifeCycle, configuration, session, getGlobalContext), parentContexts = _b.parentContexts, addError = _b.addError, addAction = _b.addAction; | ||
requestCollection_1.startRequestCollection(lifeCycle, configuration); | ||
@@ -37,11 +36,6 @@ performanceCollection_1.startPerformanceCollection(lifeCycle, configuration); | ||
var internalContext = internalContext_1.startInternalContext(userConfiguration.applicationId, session, parentContexts, configuration); | ||
errorObservable.subscribe(function (errorMessage) { return lifeCycle.notify(lifeCycle_1.LifeCycleEventType.ERROR_COLLECTED, errorMessage); }); | ||
return { | ||
addAction: addAction, | ||
addError: addError, | ||
getInternalContext: internalContext.get, | ||
addAction: function (action, context) { | ||
lifeCycle.notify(lifeCycle_1.LifeCycleEventType.CUSTOM_ACTION_COLLECTED, { action: action, context: context }); | ||
}, | ||
addError: function (error, context) { | ||
lifeCycle.notify(lifeCycle_1.LifeCycleEventType.ERROR_PROVIDED, { error: error, context: context }); | ||
}, | ||
}; | ||
@@ -58,5 +52,7 @@ } | ||
viewCollection_1.startViewCollection(lifeCycle, configuration, location); | ||
errorCollection_1.startErrorCollection(lifeCycle, configuration); | ||
actionCollection_1.startActionCollection(lifeCycle, configuration); | ||
var addError = errorCollection_1.startErrorCollection(lifeCycle, configuration).addError; | ||
var addAction = actionCollection_1.startActionCollection(lifeCycle, configuration).addAction; | ||
return { | ||
addAction: addAction, | ||
addError: addError, | ||
parentContexts: parentContexts, | ||
@@ -63,0 +59,0 @@ stop: function () { |
@@ -7,3 +7,3 @@ import { Configuration } from '@datadog/browser-core'; | ||
export declare function startInternalContext(applicationId: string, session: RumSession, parentContexts: ParentContexts, configuration: Configuration): { | ||
get: (startTime?: number | undefined) => InternalContext | InternalContextV2 | undefined; | ||
get: (startTime?: number | undefined) => InternalContextV2 | InternalContext | undefined; | ||
}; |
@@ -1,2 +0,2 @@ | ||
import { Context, RawError } from '@datadog/browser-core'; | ||
import { Context } from '@datadog/browser-core'; | ||
import { RumPerformanceEntry } from '../browser/performanceCollection'; | ||
@@ -6,25 +6,20 @@ import { RawRumEvent, RumEvent } from '../types'; | ||
import { RequestCompleteEvent, RequestStartEvent } from './requestCollection'; | ||
import { AutoAction, AutoActionCreatedEvent, CustomAction } from './rumEventsCollection/action/trackActions'; | ||
import { ProvidedError } from './rumEventsCollection/error/errorCollection'; | ||
import { AutoAction, AutoActionCreatedEvent } from './rumEventsCollection/action/trackActions'; | ||
import { View, ViewCreatedEvent } from './rumEventsCollection/view/trackViews'; | ||
export declare enum LifeCycleEventType { | ||
ERROR_COLLECTED = 0, | ||
ERROR_PROVIDED = 1, | ||
PERFORMANCE_ENTRY_COLLECTED = 2, | ||
CUSTOM_ACTION_COLLECTED = 3, | ||
AUTO_ACTION_CREATED = 4, | ||
AUTO_ACTION_COMPLETED = 5, | ||
AUTO_ACTION_DISCARDED = 6, | ||
VIEW_CREATED = 7, | ||
VIEW_UPDATED = 8, | ||
REQUEST_STARTED = 9, | ||
REQUEST_COMPLETED = 10, | ||
SESSION_RENEWED = 11, | ||
RESOURCE_ADDED_TO_BATCH = 12, | ||
DOM_MUTATED = 13, | ||
BEFORE_UNLOAD = 14, | ||
RAW_RUM_EVENT_COLLECTED = 15, | ||
RAW_RUM_EVENT_V2_COLLECTED = 16, | ||
RUM_EVENT_COLLECTED = 17, | ||
RUM_EVENT_V2_COLLECTED = 18 | ||
PERFORMANCE_ENTRY_COLLECTED = 0, | ||
AUTO_ACTION_CREATED = 1, | ||
AUTO_ACTION_COMPLETED = 2, | ||
AUTO_ACTION_DISCARDED = 3, | ||
VIEW_CREATED = 4, | ||
VIEW_UPDATED = 5, | ||
REQUEST_STARTED = 6, | ||
REQUEST_COMPLETED = 7, | ||
SESSION_RENEWED = 8, | ||
DOM_MUTATED = 9, | ||
BEFORE_UNLOAD = 10, | ||
RAW_RUM_EVENT_COLLECTED = 11, | ||
RAW_RUM_EVENT_V2_COLLECTED = 12, | ||
RUM_EVENT_COLLECTED = 13, | ||
RUM_EVENT_V2_COLLECTED = 14 | ||
} | ||
@@ -36,7 +31,2 @@ export interface Subscription { | ||
private callbacks; | ||
notify(eventType: LifeCycleEventType.ERROR_COLLECTED, data: RawError): void; | ||
notify(eventType: LifeCycleEventType.ERROR_PROVIDED, data: { | ||
error: ProvidedError; | ||
context?: Context; | ||
}): void; | ||
notify(eventType: LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, data: RumPerformanceEntry): void; | ||
@@ -46,10 +36,6 @@ notify(eventType: LifeCycleEventType.REQUEST_STARTED, data: RequestStartEvent): void; | ||
notify(eventType: LifeCycleEventType.AUTO_ACTION_COMPLETED, data: AutoAction): void; | ||
notify(eventType: LifeCycleEventType.CUSTOM_ACTION_COLLECTED, data: { | ||
action: CustomAction; | ||
context?: Context; | ||
}): void; | ||
notify(eventType: LifeCycleEventType.AUTO_ACTION_CREATED, data: AutoActionCreatedEvent): void; | ||
notify(eventType: LifeCycleEventType.VIEW_CREATED, data: ViewCreatedEvent): void; | ||
notify(eventType: LifeCycleEventType.VIEW_UPDATED, data: View): void; | ||
notify(eventType: LifeCycleEventType.SESSION_RENEWED | LifeCycleEventType.RESOURCE_ADDED_TO_BATCH | LifeCycleEventType.DOM_MUTATED | LifeCycleEventType.BEFORE_UNLOAD | LifeCycleEventType.AUTO_ACTION_DISCARDED): void; | ||
notify(eventType: LifeCycleEventType.SESSION_RENEWED | LifeCycleEventType.DOM_MUTATED | LifeCycleEventType.BEFORE_UNLOAD | LifeCycleEventType.AUTO_ACTION_DISCARDED): void; | ||
notify(eventType: LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, data: { | ||
@@ -75,7 +61,2 @@ startTime: number; | ||
}): void; | ||
subscribe(eventType: LifeCycleEventType.ERROR_COLLECTED, callback: (data: RawError) => void): Subscription; | ||
subscribe(eventType: LifeCycleEventType.ERROR_PROVIDED, callback: (data: { | ||
error: ProvidedError; | ||
context?: Context; | ||
}) => void): Subscription; | ||
subscribe(eventType: LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, callback: (data: RumPerformanceEntry) => void): Subscription; | ||
@@ -86,9 +67,5 @@ subscribe(eventType: LifeCycleEventType.REQUEST_STARTED, callback: (data: RequestStartEvent) => void): Subscription; | ||
subscribe(eventType: LifeCycleEventType.AUTO_ACTION_CREATED, callback: (data: AutoActionCreatedEvent) => void): Subscription; | ||
subscribe(eventType: LifeCycleEventType.CUSTOM_ACTION_COLLECTED, callback: (data: { | ||
action: CustomAction; | ||
context?: Context; | ||
}) => void): Subscription; | ||
subscribe(eventType: LifeCycleEventType.VIEW_CREATED, callback: (data: ViewCreatedEvent) => void): Subscription; | ||
subscribe(eventType: LifeCycleEventType.VIEW_UPDATED, callback: (data: View) => void): Subscription; | ||
subscribe(eventType: LifeCycleEventType.SESSION_RENEWED | LifeCycleEventType.RESOURCE_ADDED_TO_BATCH | LifeCycleEventType.DOM_MUTATED | LifeCycleEventType.BEFORE_UNLOAD | LifeCycleEventType.AUTO_ACTION_DISCARDED, callback: () => void): Subscription; | ||
subscribe(eventType: LifeCycleEventType.SESSION_RENEWED | LifeCycleEventType.DOM_MUTATED | LifeCycleEventType.BEFORE_UNLOAD | LifeCycleEventType.AUTO_ACTION_DISCARDED, callback: () => void): Subscription; | ||
subscribe(eventType: LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, callback: (data: { | ||
@@ -99,3 +76,3 @@ startTime: number; | ||
customerContext?: Context; | ||
}) => void): void; | ||
}) => void): Subscription; | ||
subscribe(eventType: LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, callback: (data: { | ||
@@ -106,11 +83,11 @@ startTime: number; | ||
customerContext?: Context; | ||
}) => void): void; | ||
}) => void): Subscription; | ||
subscribe(eventType: LifeCycleEventType.RUM_EVENT_COLLECTED, callback: (data: { | ||
rumEvent: RumEvent; | ||
serverRumEvent: Context; | ||
}) => void): void; | ||
}) => void): Subscription; | ||
subscribe(eventType: LifeCycleEventType.RUM_EVENT_V2_COLLECTED, callback: (data: { | ||
rumEvent: RumEventV2; | ||
serverRumEvent: Context; | ||
}) => void): void; | ||
}) => void): Subscription; | ||
} |
@@ -5,21 +5,17 @@ "use strict"; | ||
(function (LifeCycleEventType) { | ||
LifeCycleEventType[LifeCycleEventType["ERROR_COLLECTED"] = 0] = "ERROR_COLLECTED"; | ||
LifeCycleEventType[LifeCycleEventType["ERROR_PROVIDED"] = 1] = "ERROR_PROVIDED"; | ||
LifeCycleEventType[LifeCycleEventType["PERFORMANCE_ENTRY_COLLECTED"] = 2] = "PERFORMANCE_ENTRY_COLLECTED"; | ||
LifeCycleEventType[LifeCycleEventType["CUSTOM_ACTION_COLLECTED"] = 3] = "CUSTOM_ACTION_COLLECTED"; | ||
LifeCycleEventType[LifeCycleEventType["AUTO_ACTION_CREATED"] = 4] = "AUTO_ACTION_CREATED"; | ||
LifeCycleEventType[LifeCycleEventType["AUTO_ACTION_COMPLETED"] = 5] = "AUTO_ACTION_COMPLETED"; | ||
LifeCycleEventType[LifeCycleEventType["AUTO_ACTION_DISCARDED"] = 6] = "AUTO_ACTION_DISCARDED"; | ||
LifeCycleEventType[LifeCycleEventType["VIEW_CREATED"] = 7] = "VIEW_CREATED"; | ||
LifeCycleEventType[LifeCycleEventType["VIEW_UPDATED"] = 8] = "VIEW_UPDATED"; | ||
LifeCycleEventType[LifeCycleEventType["REQUEST_STARTED"] = 9] = "REQUEST_STARTED"; | ||
LifeCycleEventType[LifeCycleEventType["REQUEST_COMPLETED"] = 10] = "REQUEST_COMPLETED"; | ||
LifeCycleEventType[LifeCycleEventType["SESSION_RENEWED"] = 11] = "SESSION_RENEWED"; | ||
LifeCycleEventType[LifeCycleEventType["RESOURCE_ADDED_TO_BATCH"] = 12] = "RESOURCE_ADDED_TO_BATCH"; | ||
LifeCycleEventType[LifeCycleEventType["DOM_MUTATED"] = 13] = "DOM_MUTATED"; | ||
LifeCycleEventType[LifeCycleEventType["BEFORE_UNLOAD"] = 14] = "BEFORE_UNLOAD"; | ||
LifeCycleEventType[LifeCycleEventType["RAW_RUM_EVENT_COLLECTED"] = 15] = "RAW_RUM_EVENT_COLLECTED"; | ||
LifeCycleEventType[LifeCycleEventType["RAW_RUM_EVENT_V2_COLLECTED"] = 16] = "RAW_RUM_EVENT_V2_COLLECTED"; | ||
LifeCycleEventType[LifeCycleEventType["RUM_EVENT_COLLECTED"] = 17] = "RUM_EVENT_COLLECTED"; | ||
LifeCycleEventType[LifeCycleEventType["RUM_EVENT_V2_COLLECTED"] = 18] = "RUM_EVENT_V2_COLLECTED"; | ||
LifeCycleEventType[LifeCycleEventType["PERFORMANCE_ENTRY_COLLECTED"] = 0] = "PERFORMANCE_ENTRY_COLLECTED"; | ||
LifeCycleEventType[LifeCycleEventType["AUTO_ACTION_CREATED"] = 1] = "AUTO_ACTION_CREATED"; | ||
LifeCycleEventType[LifeCycleEventType["AUTO_ACTION_COMPLETED"] = 2] = "AUTO_ACTION_COMPLETED"; | ||
LifeCycleEventType[LifeCycleEventType["AUTO_ACTION_DISCARDED"] = 3] = "AUTO_ACTION_DISCARDED"; | ||
LifeCycleEventType[LifeCycleEventType["VIEW_CREATED"] = 4] = "VIEW_CREATED"; | ||
LifeCycleEventType[LifeCycleEventType["VIEW_UPDATED"] = 5] = "VIEW_UPDATED"; | ||
LifeCycleEventType[LifeCycleEventType["REQUEST_STARTED"] = 6] = "REQUEST_STARTED"; | ||
LifeCycleEventType[LifeCycleEventType["REQUEST_COMPLETED"] = 7] = "REQUEST_COMPLETED"; | ||
LifeCycleEventType[LifeCycleEventType["SESSION_RENEWED"] = 8] = "SESSION_RENEWED"; | ||
LifeCycleEventType[LifeCycleEventType["DOM_MUTATED"] = 9] = "DOM_MUTATED"; | ||
LifeCycleEventType[LifeCycleEventType["BEFORE_UNLOAD"] = 10] = "BEFORE_UNLOAD"; | ||
LifeCycleEventType[LifeCycleEventType["RAW_RUM_EVENT_COLLECTED"] = 11] = "RAW_RUM_EVENT_COLLECTED"; | ||
LifeCycleEventType[LifeCycleEventType["RAW_RUM_EVENT_V2_COLLECTED"] = 12] = "RAW_RUM_EVENT_V2_COLLECTED"; | ||
LifeCycleEventType[LifeCycleEventType["RUM_EVENT_COLLECTED"] = 13] = "RUM_EVENT_COLLECTED"; | ||
LifeCycleEventType[LifeCycleEventType["RUM_EVENT_V2_COLLECTED"] = 14] = "RUM_EVENT_V2_COLLECTED"; | ||
})(LifeCycleEventType = exports.LifeCycleEventType || (exports.LifeCycleEventType = {})); | ||
@@ -26,0 +22,0 @@ var LifeCycle = /** @class */ (function () { |
@@ -1,3 +0,6 @@ | ||
import { Configuration } from '@datadog/browser-core'; | ||
import { Configuration, Context } from '@datadog/browser-core'; | ||
import { LifeCycle } from '../../lifeCycle'; | ||
export declare function startActionCollection(lifeCycle: LifeCycle, configuration: Configuration): void; | ||
import { CustomAction } from './trackActions'; | ||
export declare function startActionCollection(lifeCycle: LifeCycle, configuration: Configuration): { | ||
addAction(action: CustomAction, savedGlobalContext?: Context | undefined): void; | ||
}; |
@@ -15,11 +15,12 @@ "use strict"; | ||
}); | ||
lifeCycle.subscribe(lifeCycle_1.LifeCycleEventType.CUSTOM_ACTION_COLLECTED, function (_a) { | ||
var action = _a.action, context = _a.context; | ||
configuration.isEnabled('v2_format') | ||
? lifeCycle.notify(lifeCycle_1.LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, tslib_1.__assign({ savedGlobalContext: context }, processActionV2(action))) | ||
: lifeCycle.notify(lifeCycle_1.LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, tslib_1.__assign({ savedGlobalContext: context }, processAction(action))); | ||
}); | ||
if (configuration.trackInteractions) { | ||
trackActions_1.trackActions(lifeCycle); | ||
} | ||
return { | ||
addAction: function (action, savedGlobalContext) { | ||
configuration.isEnabled('v2_format') | ||
? lifeCycle.notify(lifeCycle_1.LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, tslib_1.__assign({ savedGlobalContext: savedGlobalContext }, processActionV2(action))) | ||
: lifeCycle.notify(lifeCycle_1.LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, tslib_1.__assign({ savedGlobalContext: savedGlobalContext }, processAction(action))); | ||
}, | ||
}; | ||
} | ||
@@ -26,0 +27,0 @@ exports.startActionCollection = startActionCollection; |
@@ -1,2 +0,2 @@ | ||
import { Configuration, Context, ErrorSource } from '@datadog/browser-core'; | ||
import { Configuration, Context, ErrorSource, Observable, RawError } from '@datadog/browser-core'; | ||
import { LifeCycle } from '../../lifeCycle'; | ||
@@ -9,2 +9,7 @@ export interface ProvidedError { | ||
} | ||
export declare function startErrorCollection(lifeCycle: LifeCycle, configuration: Configuration): void; | ||
export declare function startErrorCollection(lifeCycle: LifeCycle, configuration: Configuration): { | ||
addError({ error, startTime, context: customerContext, source }: ProvidedError, savedGlobalContext?: Context | undefined): void; | ||
}; | ||
export declare function doStartErrorCollection(lifeCycle: LifeCycle, configuration: Configuration, observable: Observable<RawError>): { | ||
addError({ error, startTime, context: customerContext, source }: ProvidedError, savedGlobalContext?: Context | undefined): void; | ||
}; |
@@ -9,18 +9,24 @@ "use strict"; | ||
function startErrorCollection(lifeCycle, configuration) { | ||
lifeCycle.subscribe(lifeCycle_1.LifeCycleEventType.ERROR_PROVIDED, function (_a) { | ||
var _b = _a.error, error = _b.error, startTime = _b.startTime, customerContext = _b.context, source = _b.source, savedGlobalContext = _a.context; | ||
var rawError = computeRawError(error, startTime, source); | ||
return doStartErrorCollection(lifeCycle, configuration, browser_core_1.startAutomaticErrorCollection(configuration)); | ||
} | ||
exports.startErrorCollection = startErrorCollection; | ||
function doStartErrorCollection(lifeCycle, configuration, observable) { | ||
observable.subscribe(function (error) { | ||
configuration.isEnabled('v2_format') | ||
? lifeCycle.notify(lifeCycle_1.LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, tslib_1.__assign({ customerContext: customerContext, | ||
savedGlobalContext: savedGlobalContext }, processErrorV2(rawError))) | ||
: lifeCycle.notify(lifeCycle_1.LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, tslib_1.__assign({ customerContext: customerContext, | ||
savedGlobalContext: savedGlobalContext }, processError(rawError))); | ||
}); | ||
lifeCycle.subscribe(lifeCycle_1.LifeCycleEventType.ERROR_COLLECTED, function (error) { | ||
configuration.isEnabled('v2_format') | ||
? lifeCycle.notify(lifeCycle_1.LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, processErrorV2(error)) | ||
: lifeCycle.notify(lifeCycle_1.LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, processError(error)); | ||
}); | ||
return { | ||
addError: function (_a, savedGlobalContext) { | ||
var error = _a.error, startTime = _a.startTime, customerContext = _a.context, source = _a.source; | ||
var rawError = computeRawError(error, startTime, source); | ||
configuration.isEnabled('v2_format') | ||
? lifeCycle.notify(lifeCycle_1.LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, tslib_1.__assign({ customerContext: customerContext, | ||
savedGlobalContext: savedGlobalContext }, processErrorV2(rawError))) | ||
: lifeCycle.notify(lifeCycle_1.LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, tslib_1.__assign({ customerContext: customerContext, | ||
savedGlobalContext: savedGlobalContext }, processError(rawError))); | ||
}, | ||
}; | ||
} | ||
exports.startErrorCollection = startErrorCollection; | ||
exports.doStartErrorCollection = doStartErrorCollection; | ||
function computeRawError(error, startTime, source) { | ||
@@ -27,0 +33,0 @@ var stackTrace = error instanceof Error ? browser_core_1.computeStackTrace(error) : undefined; |
@@ -11,2 +11,3 @@ import { RumPerformanceResourceTiming } from '../../../browser/performanceCollection'; | ||
* Strategy: | ||
* - from valid nested entries | ||
* - if a single timing match, return the timing | ||
@@ -13,0 +14,0 @@ * - if two following timings match (OPTIONS request), return the timing for the actual request |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var resourceUtils_1 = require("./resourceUtils"); | ||
/** | ||
@@ -11,2 +12,3 @@ * Look for corresponding timing in resource timing buffer | ||
* Strategy: | ||
* - from valid nested entries | ||
* - if a single timing match, return the timing | ||
@@ -22,5 +24,5 @@ * - if two following timings match (OPTIONS request), return the timing for the actual request | ||
.getEntriesByName(request.url, 'resource') | ||
.filter(function (entry) { | ||
return isBetween(entry, request.startTime, endTime(request)); | ||
}); | ||
.map(function (entry) { return entry.toJSON(); }) | ||
.filter(resourceUtils_1.toValidEntry) | ||
.filter(function (entry) { return isBetween(entry, request.startTime, endTime(request)); }); | ||
if (candidates.length === 1) { | ||
@@ -27,0 +29,0 @@ return candidates[0]; |
@@ -16,3 +16,2 @@ "use strict"; | ||
: lifeCycle.notify(lifeCycle_1.LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, processRequest(request)); | ||
lifeCycle.notify(lifeCycle_1.LifeCycleEventType.RESOURCE_ADDED_TO_BATCH); | ||
} | ||
@@ -25,3 +24,2 @@ }); | ||
: lifeCycle.notify(lifeCycle_1.LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, processResourceEntry(entry)); | ||
lifeCycle.notify(lifeCycle_1.LifeCycleEventType.RESOURCE_ADDED_TO_BATCH); | ||
} | ||
@@ -28,0 +26,0 @@ }); |
@@ -20,3 +20,4 @@ import { Configuration, ResourceType } from '@datadog/browser-core'; | ||
export declare function computePerformanceResourceDetails(entry: RumPerformanceResourceTiming): PerformanceResourceDetails | undefined; | ||
export declare function toValidEntry(entry: RumPerformanceResourceTiming): RumPerformanceResourceTiming | undefined; | ||
export declare function computeSize(entry: RumPerformanceResourceTiming): number | undefined; | ||
export declare function isAllowedRequestUrl(configuration: Configuration, url: string): boolean | ""; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var browser_core_1 = require("@datadog/browser-core"); | ||
@@ -68,27 +69,7 @@ exports.FAKE_INITIAL_DOCUMENT = 'initial_document'; | ||
function computePerformanceResourceDetails(entry) { | ||
var startTime = entry.startTime, fetchStart = entry.fetchStart, domainLookupStart = entry.domainLookupStart, domainLookupEnd = entry.domainLookupEnd, connectStart = entry.connectStart, secureConnectionStart = entry.secureConnectionStart, connectEnd = entry.connectEnd, requestStart = entry.requestStart, responseStart = entry.responseStart, responseEnd = entry.responseEnd; | ||
var redirectStart = entry.redirectStart, redirectEnd = entry.redirectEnd; | ||
// Ensure timings are in the right order. On top of filtering out potential invalid | ||
// RumPerformanceResourceTiming, it will ignore entries from requests where timings cannot be | ||
// collected, for example cross origin requests without a "Timing-Allow-Origin" header allowing | ||
// it. | ||
if (!areInOrder(startTime, fetchStart, domainLookupStart, domainLookupEnd, connectStart, connectEnd, requestStart, responseStart, responseEnd)) { | ||
var validEntry = toValidEntry(entry); | ||
if (!validEntry) { | ||
return undefined; | ||
} | ||
// The only time fetchStart is different than startTime is if a redirection occurred. | ||
var hasRedirectionOccurred = fetchStart !== startTime; | ||
if (hasRedirectionOccurred) { | ||
// Firefox doesn't provide redirect timings on cross origin requests. Provide a default for | ||
// those. | ||
if (redirectStart < startTime) { | ||
redirectStart = startTime; | ||
} | ||
if (redirectEnd < startTime) { | ||
redirectEnd = fetchStart; | ||
} | ||
// Make sure redirect timings are in order | ||
if (!areInOrder(startTime, redirectStart, redirectEnd, fetchStart)) { | ||
return undefined; | ||
} | ||
} | ||
var startTime = validEntry.startTime, fetchStart = validEntry.fetchStart, redirectStart = validEntry.redirectStart, redirectEnd = validEntry.redirectEnd, domainLookupStart = validEntry.domainLookupStart, domainLookupEnd = validEntry.domainLookupEnd, connectStart = validEntry.connectStart, secureConnectionStart = validEntry.secureConnectionStart, connectEnd = validEntry.connectEnd, requestStart = validEntry.requestStart, responseStart = validEntry.responseStart, responseEnd = validEntry.responseEnd; | ||
var details = { | ||
@@ -110,3 +91,3 @@ download: formatTiming(startTime, responseStart, responseEnd), | ||
} | ||
if (hasRedirectionOccurred) { | ||
if (hasRedirection(entry)) { | ||
details.redirect = formatTiming(startTime, redirectStart, redirectEnd); | ||
@@ -117,2 +98,34 @@ } | ||
exports.computePerformanceResourceDetails = computePerformanceResourceDetails; | ||
function toValidEntry(entry) { | ||
// Ensure timings are in the right order. On top of filtering out potential invalid | ||
// RumPerformanceResourceTiming, it will ignore entries from requests where timings cannot be | ||
// collected, for example cross origin requests without a "Timing-Allow-Origin" header allowing | ||
// it. | ||
if (!areInOrder(entry.startTime, entry.fetchStart, entry.domainLookupStart, entry.domainLookupEnd, entry.connectStart, entry.connectEnd, entry.requestStart, entry.responseStart, entry.responseEnd)) { | ||
return undefined; | ||
} | ||
if (!hasRedirection(entry)) { | ||
return entry; | ||
} | ||
var redirectStart = entry.redirectStart, redirectEnd = entry.redirectEnd; | ||
// Firefox doesn't provide redirect timings on cross origin requests. | ||
// Provide a default for those. | ||
if (redirectStart < entry.startTime) { | ||
redirectStart = entry.startTime; | ||
} | ||
if (redirectEnd < entry.startTime) { | ||
redirectEnd = entry.fetchStart; | ||
} | ||
// Make sure redirect timings are in order | ||
if (!areInOrder(entry.startTime, redirectStart, redirectEnd, entry.fetchStart)) { | ||
return undefined; | ||
} | ||
return tslib_1.__assign(tslib_1.__assign({}, entry), { redirectEnd: redirectEnd, | ||
redirectStart: redirectStart }); | ||
} | ||
exports.toValidEntry = toValidEntry; | ||
function hasRedirection(entry) { | ||
// The only time fetchStart is different than startTime is if a redirection occurred. | ||
return entry.fetchStart !== entry.startTime; | ||
} | ||
function formatTiming(origin, start, end) { | ||
@@ -119,0 +132,0 @@ return { |
import { Configuration } from '@datadog/browser-core'; | ||
import { LifeCycle } from '../../lifeCycle'; | ||
export declare function startViewCollection(lifeCycle: LifeCycle, configuration: Configuration, location: Location): void; | ||
export declare function startViewCollection(lifeCycle: LifeCycle, configuration: Configuration, location: Location): { | ||
stop(): void; | ||
}; |
@@ -15,3 +15,3 @@ "use strict"; | ||
}); | ||
trackViews_1.trackViews(location, lifeCycle); | ||
return trackViews_1.trackViews(location, lifeCycle); | ||
} | ||
@@ -18,0 +18,0 @@ exports.startViewCollection = startViewCollection; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var browser_core_1 = require("@datadog/browser-core"); | ||
var types_1 = require("../types"); | ||
var typesV2_1 = require("../typesV2"); | ||
var lifeCycle_1 = require("./lifeCycle"); | ||
@@ -13,28 +15,48 @@ function trackEventCounts(lifeCycle, callback) { | ||
}; | ||
var subscriptions = []; | ||
subscriptions.push(lifeCycle.subscribe(lifeCycle_1.LifeCycleEventType.ERROR_COLLECTED, function () { | ||
eventCounts.errorCount += 1; | ||
callback(eventCounts); | ||
})); | ||
subscriptions.push(lifeCycle.subscribe(lifeCycle_1.LifeCycleEventType.AUTO_ACTION_COMPLETED, function () { | ||
eventCounts.userActionCount += 1; | ||
callback(eventCounts); | ||
})); | ||
subscriptions.push(lifeCycle.subscribe(lifeCycle_1.LifeCycleEventType.CUSTOM_ACTION_COLLECTED, function () { | ||
eventCounts.userActionCount += 1; | ||
callback(eventCounts); | ||
})); | ||
subscriptions.push(lifeCycle.subscribe(lifeCycle_1.LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, function (entry) { | ||
if (entry.entryType === 'longtask') { | ||
eventCounts.longTaskCount += 1; | ||
callback(eventCounts); | ||
var subscription = lifeCycle.subscribe(lifeCycle_1.LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, function (_a) { | ||
var rawRumEvent = _a.rawRumEvent; | ||
switch (rawRumEvent.evt.category) { | ||
case types_1.RumEventCategory.ERROR: | ||
eventCounts.errorCount += 1; | ||
callback(eventCounts); | ||
break; | ||
case types_1.RumEventCategory.USER_ACTION: | ||
eventCounts.userActionCount += 1; | ||
callback(eventCounts); | ||
break; | ||
case types_1.RumEventCategory.LONG_TASK: | ||
eventCounts.longTaskCount += 1; | ||
callback(eventCounts); | ||
break; | ||
case types_1.RumEventCategory.RESOURCE: | ||
eventCounts.resourceCount += 1; | ||
callback(eventCounts); | ||
break; | ||
} | ||
})); | ||
subscriptions.push(lifeCycle.subscribe(lifeCycle_1.LifeCycleEventType.RESOURCE_ADDED_TO_BATCH, function () { | ||
eventCounts.resourceCount += 1; | ||
callback(eventCounts); | ||
})); | ||
}); | ||
var subscriptionV2 = lifeCycle.subscribe(lifeCycle_1.LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, function (_a) { | ||
var rawRumEvent = _a.rawRumEvent; | ||
switch (rawRumEvent.type) { | ||
case typesV2_1.RumEventType.ERROR: | ||
eventCounts.errorCount += 1; | ||
callback(eventCounts); | ||
break; | ||
case typesV2_1.RumEventType.ACTION: | ||
eventCounts.userActionCount += 1; | ||
callback(eventCounts); | ||
break; | ||
case typesV2_1.RumEventType.LONG_TASK: | ||
eventCounts.longTaskCount += 1; | ||
callback(eventCounts); | ||
break; | ||
case typesV2_1.RumEventType.RESOURCE: | ||
eventCounts.resourceCount += 1; | ||
callback(eventCounts); | ||
break; | ||
} | ||
}); | ||
return { | ||
stop: function () { | ||
subscriptions.forEach(function (s) { return s.unsubscribe(); }); | ||
subscription.unsubscribe(); | ||
subscriptionV2.unsubscribe(); | ||
}, | ||
@@ -41,0 +63,0 @@ eventCounts: eventCounts, |
export var buildEnv = { | ||
buildMode: 'release', | ||
datacenter: 'us', | ||
sdkVersion: '1.25.1', | ||
sdkVersion: '1.25.2', | ||
}; | ||
//# sourceMappingURL=buildEnv.js.map |
import { Configuration, Context } from '@datadog/browser-core'; | ||
import { LifeCycle } from '../domain/lifeCycle'; | ||
import { CustomAction } from '../domain/rumEventsCollection/action/trackActions'; | ||
import { ProvidedError } from '../domain/rumEventsCollection/error/errorCollection'; | ||
import { RumSession } from '../domain/rumSession'; | ||
import { RumUserConfiguration } from './rum.entry'; | ||
export declare function startRum(userConfiguration: RumUserConfiguration, getGlobalContext: () => Context): { | ||
getInternalContext: (startTime?: number | undefined) => import("..").InternalContext | import("../typesV2").InternalContextV2 | undefined; | ||
addAction(action: CustomAction, context?: Context | undefined): void; | ||
addError(error: ProvidedError, context?: Context | undefined): void; | ||
addAction: (action: import("../domain/rumEventsCollection/action/trackActions").CustomAction, savedGlobalContext?: Context | undefined) => void; | ||
addError: ({ error, startTime, context: customerContext, source }: import("../domain/rumEventsCollection/error/errorCollection").ProvidedError, savedGlobalContext?: Context | undefined) => void; | ||
getInternalContext: (startTime?: number | undefined) => import("../typesV2").InternalContextV2 | import("..").InternalContext | undefined; | ||
}; | ||
export declare function startRumEventCollection(applicationId: string, location: Location, lifeCycle: LifeCycle, configuration: Configuration, session: RumSession, getGlobalContext: () => Context): { | ||
addAction: (action: import("../domain/rumEventsCollection/action/trackActions").CustomAction, savedGlobalContext?: Context | undefined) => void; | ||
addError: ({ error, startTime, context: customerContext, source }: import("../domain/rumEventsCollection/error/errorCollection").ProvidedError, savedGlobalContext?: Context | undefined) => void; | ||
parentContexts: import("../domain/parentContexts").ParentContexts; | ||
stop(): void; | ||
}; |
@@ -12,3 +12,3 @@ import { Context, ErrorSource, UserConfiguration } from '@datadog/browser-core'; | ||
setRumGlobalContext: (newContext: Context) => void; | ||
getInternalContext: (startTime?: number | undefined) => import("..").InternalContext | import("../typesV2").InternalContextV2 | undefined; | ||
getInternalContext: (startTime?: number | undefined) => import("../typesV2").InternalContextV2 | import("..").InternalContext | undefined; | ||
addAction: (name: string, context?: Context | undefined) => void; | ||
@@ -26,3 +26,3 @@ addUserAction: (name: string, context?: Context | undefined) => void; | ||
setRumGlobalContext: (newContext: Context) => void; | ||
getInternalContext: (startTime?: number | undefined) => import("..").InternalContext | import("../typesV2").InternalContextV2 | undefined; | ||
getInternalContext: (startTime?: number | undefined) => import("../typesV2").InternalContextV2 | import("..").InternalContext | undefined; | ||
addAction: (name: string, context?: Context | undefined) => void; | ||
@@ -29,0 +29,0 @@ addUserAction: (name: string, context?: Context | undefined) => void; |
@@ -7,3 +7,3 @@ import { combine, commonInit } from '@datadog/browser-core'; | ||
import { startInternalContext } from '../domain/internalContext'; | ||
import { LifeCycle, LifeCycleEventType } from '../domain/lifeCycle'; | ||
import { LifeCycle } from '../domain/lifeCycle'; | ||
import { startParentContexts } from '../domain/parentContexts'; | ||
@@ -21,4 +21,3 @@ import { startRequestCollection } from '../domain/requestCollection'; | ||
var lifeCycle = new LifeCycle(); | ||
var isCollectingError = true; | ||
var _a = commonInit(userConfiguration, buildEnv, isCollectingError), errorObservable = _a.errorObservable, configuration = _a.configuration, internalMonitoring = _a.internalMonitoring; | ||
var _a = commonInit(userConfiguration, buildEnv), configuration = _a.configuration, internalMonitoring = _a.internalMonitoring; | ||
var session = startRumSession(configuration, lifeCycle); | ||
@@ -30,3 +29,3 @@ internalMonitoring.setExternalContextProvider(function () { | ||
}); | ||
var parentContexts = startRumEventCollection(userConfiguration.applicationId, location, lifeCycle, configuration, session, getGlobalContext).parentContexts; | ||
var _b = startRumEventCollection(userConfiguration.applicationId, location, lifeCycle, configuration, session, getGlobalContext), parentContexts = _b.parentContexts, addError = _b.addError, addAction = _b.addAction; | ||
startRequestCollection(lifeCycle, configuration); | ||
@@ -36,11 +35,6 @@ startPerformanceCollection(lifeCycle, configuration); | ||
var internalContext = startInternalContext(userConfiguration.applicationId, session, parentContexts, configuration); | ||
errorObservable.subscribe(function (errorMessage) { return lifeCycle.notify(LifeCycleEventType.ERROR_COLLECTED, errorMessage); }); | ||
return { | ||
addAction: addAction, | ||
addError: addError, | ||
getInternalContext: internalContext.get, | ||
addAction: function (action, context) { | ||
lifeCycle.notify(LifeCycleEventType.CUSTOM_ACTION_COLLECTED, { action: action, context: context }); | ||
}, | ||
addError: function (error, context) { | ||
lifeCycle.notify(LifeCycleEventType.ERROR_PROVIDED, { error: error, context: context }); | ||
}, | ||
}; | ||
@@ -56,5 +50,7 @@ } | ||
startViewCollection(lifeCycle, configuration, location); | ||
startErrorCollection(lifeCycle, configuration); | ||
startActionCollection(lifeCycle, configuration); | ||
var addError = startErrorCollection(lifeCycle, configuration).addError; | ||
var addAction = startActionCollection(lifeCycle, configuration).addAction; | ||
return { | ||
addAction: addAction, | ||
addError: addError, | ||
parentContexts: parentContexts, | ||
@@ -61,0 +57,0 @@ stop: function () { |
@@ -7,3 +7,3 @@ import { Configuration } from '@datadog/browser-core'; | ||
export declare function startInternalContext(applicationId: string, session: RumSession, parentContexts: ParentContexts, configuration: Configuration): { | ||
get: (startTime?: number | undefined) => InternalContext | InternalContextV2 | undefined; | ||
get: (startTime?: number | undefined) => InternalContextV2 | InternalContext | undefined; | ||
}; |
@@ -1,2 +0,2 @@ | ||
import { Context, RawError } from '@datadog/browser-core'; | ||
import { Context } from '@datadog/browser-core'; | ||
import { RumPerformanceEntry } from '../browser/performanceCollection'; | ||
@@ -6,25 +6,20 @@ import { RawRumEvent, RumEvent } from '../types'; | ||
import { RequestCompleteEvent, RequestStartEvent } from './requestCollection'; | ||
import { AutoAction, AutoActionCreatedEvent, CustomAction } from './rumEventsCollection/action/trackActions'; | ||
import { ProvidedError } from './rumEventsCollection/error/errorCollection'; | ||
import { AutoAction, AutoActionCreatedEvent } from './rumEventsCollection/action/trackActions'; | ||
import { View, ViewCreatedEvent } from './rumEventsCollection/view/trackViews'; | ||
export declare enum LifeCycleEventType { | ||
ERROR_COLLECTED = 0, | ||
ERROR_PROVIDED = 1, | ||
PERFORMANCE_ENTRY_COLLECTED = 2, | ||
CUSTOM_ACTION_COLLECTED = 3, | ||
AUTO_ACTION_CREATED = 4, | ||
AUTO_ACTION_COMPLETED = 5, | ||
AUTO_ACTION_DISCARDED = 6, | ||
VIEW_CREATED = 7, | ||
VIEW_UPDATED = 8, | ||
REQUEST_STARTED = 9, | ||
REQUEST_COMPLETED = 10, | ||
SESSION_RENEWED = 11, | ||
RESOURCE_ADDED_TO_BATCH = 12, | ||
DOM_MUTATED = 13, | ||
BEFORE_UNLOAD = 14, | ||
RAW_RUM_EVENT_COLLECTED = 15, | ||
RAW_RUM_EVENT_V2_COLLECTED = 16, | ||
RUM_EVENT_COLLECTED = 17, | ||
RUM_EVENT_V2_COLLECTED = 18 | ||
PERFORMANCE_ENTRY_COLLECTED = 0, | ||
AUTO_ACTION_CREATED = 1, | ||
AUTO_ACTION_COMPLETED = 2, | ||
AUTO_ACTION_DISCARDED = 3, | ||
VIEW_CREATED = 4, | ||
VIEW_UPDATED = 5, | ||
REQUEST_STARTED = 6, | ||
REQUEST_COMPLETED = 7, | ||
SESSION_RENEWED = 8, | ||
DOM_MUTATED = 9, | ||
BEFORE_UNLOAD = 10, | ||
RAW_RUM_EVENT_COLLECTED = 11, | ||
RAW_RUM_EVENT_V2_COLLECTED = 12, | ||
RUM_EVENT_COLLECTED = 13, | ||
RUM_EVENT_V2_COLLECTED = 14 | ||
} | ||
@@ -36,7 +31,2 @@ export interface Subscription { | ||
private callbacks; | ||
notify(eventType: LifeCycleEventType.ERROR_COLLECTED, data: RawError): void; | ||
notify(eventType: LifeCycleEventType.ERROR_PROVIDED, data: { | ||
error: ProvidedError; | ||
context?: Context; | ||
}): void; | ||
notify(eventType: LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, data: RumPerformanceEntry): void; | ||
@@ -46,10 +36,6 @@ notify(eventType: LifeCycleEventType.REQUEST_STARTED, data: RequestStartEvent): void; | ||
notify(eventType: LifeCycleEventType.AUTO_ACTION_COMPLETED, data: AutoAction): void; | ||
notify(eventType: LifeCycleEventType.CUSTOM_ACTION_COLLECTED, data: { | ||
action: CustomAction; | ||
context?: Context; | ||
}): void; | ||
notify(eventType: LifeCycleEventType.AUTO_ACTION_CREATED, data: AutoActionCreatedEvent): void; | ||
notify(eventType: LifeCycleEventType.VIEW_CREATED, data: ViewCreatedEvent): void; | ||
notify(eventType: LifeCycleEventType.VIEW_UPDATED, data: View): void; | ||
notify(eventType: LifeCycleEventType.SESSION_RENEWED | LifeCycleEventType.RESOURCE_ADDED_TO_BATCH | LifeCycleEventType.DOM_MUTATED | LifeCycleEventType.BEFORE_UNLOAD | LifeCycleEventType.AUTO_ACTION_DISCARDED): void; | ||
notify(eventType: LifeCycleEventType.SESSION_RENEWED | LifeCycleEventType.DOM_MUTATED | LifeCycleEventType.BEFORE_UNLOAD | LifeCycleEventType.AUTO_ACTION_DISCARDED): void; | ||
notify(eventType: LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, data: { | ||
@@ -75,7 +61,2 @@ startTime: number; | ||
}): void; | ||
subscribe(eventType: LifeCycleEventType.ERROR_COLLECTED, callback: (data: RawError) => void): Subscription; | ||
subscribe(eventType: LifeCycleEventType.ERROR_PROVIDED, callback: (data: { | ||
error: ProvidedError; | ||
context?: Context; | ||
}) => void): Subscription; | ||
subscribe(eventType: LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, callback: (data: RumPerformanceEntry) => void): Subscription; | ||
@@ -86,9 +67,5 @@ subscribe(eventType: LifeCycleEventType.REQUEST_STARTED, callback: (data: RequestStartEvent) => void): Subscription; | ||
subscribe(eventType: LifeCycleEventType.AUTO_ACTION_CREATED, callback: (data: AutoActionCreatedEvent) => void): Subscription; | ||
subscribe(eventType: LifeCycleEventType.CUSTOM_ACTION_COLLECTED, callback: (data: { | ||
action: CustomAction; | ||
context?: Context; | ||
}) => void): Subscription; | ||
subscribe(eventType: LifeCycleEventType.VIEW_CREATED, callback: (data: ViewCreatedEvent) => void): Subscription; | ||
subscribe(eventType: LifeCycleEventType.VIEW_UPDATED, callback: (data: View) => void): Subscription; | ||
subscribe(eventType: LifeCycleEventType.SESSION_RENEWED | LifeCycleEventType.RESOURCE_ADDED_TO_BATCH | LifeCycleEventType.DOM_MUTATED | LifeCycleEventType.BEFORE_UNLOAD | LifeCycleEventType.AUTO_ACTION_DISCARDED, callback: () => void): Subscription; | ||
subscribe(eventType: LifeCycleEventType.SESSION_RENEWED | LifeCycleEventType.DOM_MUTATED | LifeCycleEventType.BEFORE_UNLOAD | LifeCycleEventType.AUTO_ACTION_DISCARDED, callback: () => void): Subscription; | ||
subscribe(eventType: LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, callback: (data: { | ||
@@ -99,3 +76,3 @@ startTime: number; | ||
customerContext?: Context; | ||
}) => void): void; | ||
}) => void): Subscription; | ||
subscribe(eventType: LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, callback: (data: { | ||
@@ -106,11 +83,11 @@ startTime: number; | ||
customerContext?: Context; | ||
}) => void): void; | ||
}) => void): Subscription; | ||
subscribe(eventType: LifeCycleEventType.RUM_EVENT_COLLECTED, callback: (data: { | ||
rumEvent: RumEvent; | ||
serverRumEvent: Context; | ||
}) => void): void; | ||
}) => void): Subscription; | ||
subscribe(eventType: LifeCycleEventType.RUM_EVENT_V2_COLLECTED, callback: (data: { | ||
rumEvent: RumEventV2; | ||
serverRumEvent: Context; | ||
}) => void): void; | ||
}) => void): Subscription; | ||
} |
export var LifeCycleEventType; | ||
(function (LifeCycleEventType) { | ||
LifeCycleEventType[LifeCycleEventType["ERROR_COLLECTED"] = 0] = "ERROR_COLLECTED"; | ||
LifeCycleEventType[LifeCycleEventType["ERROR_PROVIDED"] = 1] = "ERROR_PROVIDED"; | ||
LifeCycleEventType[LifeCycleEventType["PERFORMANCE_ENTRY_COLLECTED"] = 2] = "PERFORMANCE_ENTRY_COLLECTED"; | ||
LifeCycleEventType[LifeCycleEventType["CUSTOM_ACTION_COLLECTED"] = 3] = "CUSTOM_ACTION_COLLECTED"; | ||
LifeCycleEventType[LifeCycleEventType["AUTO_ACTION_CREATED"] = 4] = "AUTO_ACTION_CREATED"; | ||
LifeCycleEventType[LifeCycleEventType["AUTO_ACTION_COMPLETED"] = 5] = "AUTO_ACTION_COMPLETED"; | ||
LifeCycleEventType[LifeCycleEventType["AUTO_ACTION_DISCARDED"] = 6] = "AUTO_ACTION_DISCARDED"; | ||
LifeCycleEventType[LifeCycleEventType["VIEW_CREATED"] = 7] = "VIEW_CREATED"; | ||
LifeCycleEventType[LifeCycleEventType["VIEW_UPDATED"] = 8] = "VIEW_UPDATED"; | ||
LifeCycleEventType[LifeCycleEventType["REQUEST_STARTED"] = 9] = "REQUEST_STARTED"; | ||
LifeCycleEventType[LifeCycleEventType["REQUEST_COMPLETED"] = 10] = "REQUEST_COMPLETED"; | ||
LifeCycleEventType[LifeCycleEventType["SESSION_RENEWED"] = 11] = "SESSION_RENEWED"; | ||
LifeCycleEventType[LifeCycleEventType["RESOURCE_ADDED_TO_BATCH"] = 12] = "RESOURCE_ADDED_TO_BATCH"; | ||
LifeCycleEventType[LifeCycleEventType["DOM_MUTATED"] = 13] = "DOM_MUTATED"; | ||
LifeCycleEventType[LifeCycleEventType["BEFORE_UNLOAD"] = 14] = "BEFORE_UNLOAD"; | ||
LifeCycleEventType[LifeCycleEventType["RAW_RUM_EVENT_COLLECTED"] = 15] = "RAW_RUM_EVENT_COLLECTED"; | ||
LifeCycleEventType[LifeCycleEventType["RAW_RUM_EVENT_V2_COLLECTED"] = 16] = "RAW_RUM_EVENT_V2_COLLECTED"; | ||
LifeCycleEventType[LifeCycleEventType["RUM_EVENT_COLLECTED"] = 17] = "RUM_EVENT_COLLECTED"; | ||
LifeCycleEventType[LifeCycleEventType["RUM_EVENT_V2_COLLECTED"] = 18] = "RUM_EVENT_V2_COLLECTED"; | ||
LifeCycleEventType[LifeCycleEventType["PERFORMANCE_ENTRY_COLLECTED"] = 0] = "PERFORMANCE_ENTRY_COLLECTED"; | ||
LifeCycleEventType[LifeCycleEventType["AUTO_ACTION_CREATED"] = 1] = "AUTO_ACTION_CREATED"; | ||
LifeCycleEventType[LifeCycleEventType["AUTO_ACTION_COMPLETED"] = 2] = "AUTO_ACTION_COMPLETED"; | ||
LifeCycleEventType[LifeCycleEventType["AUTO_ACTION_DISCARDED"] = 3] = "AUTO_ACTION_DISCARDED"; | ||
LifeCycleEventType[LifeCycleEventType["VIEW_CREATED"] = 4] = "VIEW_CREATED"; | ||
LifeCycleEventType[LifeCycleEventType["VIEW_UPDATED"] = 5] = "VIEW_UPDATED"; | ||
LifeCycleEventType[LifeCycleEventType["REQUEST_STARTED"] = 6] = "REQUEST_STARTED"; | ||
LifeCycleEventType[LifeCycleEventType["REQUEST_COMPLETED"] = 7] = "REQUEST_COMPLETED"; | ||
LifeCycleEventType[LifeCycleEventType["SESSION_RENEWED"] = 8] = "SESSION_RENEWED"; | ||
LifeCycleEventType[LifeCycleEventType["DOM_MUTATED"] = 9] = "DOM_MUTATED"; | ||
LifeCycleEventType[LifeCycleEventType["BEFORE_UNLOAD"] = 10] = "BEFORE_UNLOAD"; | ||
LifeCycleEventType[LifeCycleEventType["RAW_RUM_EVENT_COLLECTED"] = 11] = "RAW_RUM_EVENT_COLLECTED"; | ||
LifeCycleEventType[LifeCycleEventType["RAW_RUM_EVENT_V2_COLLECTED"] = 12] = "RAW_RUM_EVENT_V2_COLLECTED"; | ||
LifeCycleEventType[LifeCycleEventType["RUM_EVENT_COLLECTED"] = 13] = "RUM_EVENT_COLLECTED"; | ||
LifeCycleEventType[LifeCycleEventType["RUM_EVENT_V2_COLLECTED"] = 14] = "RUM_EVENT_V2_COLLECTED"; | ||
})(LifeCycleEventType || (LifeCycleEventType = {})); | ||
@@ -23,0 +19,0 @@ var LifeCycle = /** @class */ (function () { |
@@ -1,3 +0,6 @@ | ||
import { Configuration } from '@datadog/browser-core'; | ||
import { Configuration, Context } from '@datadog/browser-core'; | ||
import { LifeCycle } from '../../lifeCycle'; | ||
export declare function startActionCollection(lifeCycle: LifeCycle, configuration: Configuration): void; | ||
import { CustomAction } from './trackActions'; | ||
export declare function startActionCollection(lifeCycle: LifeCycle, configuration: Configuration): { | ||
addAction(action: CustomAction, savedGlobalContext?: Context | undefined): void; | ||
}; |
@@ -13,11 +13,12 @@ import { __assign } from "tslib"; | ||
}); | ||
lifeCycle.subscribe(LifeCycleEventType.CUSTOM_ACTION_COLLECTED, function (_a) { | ||
var action = _a.action, context = _a.context; | ||
configuration.isEnabled('v2_format') | ||
? lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, __assign({ savedGlobalContext: context }, processActionV2(action))) | ||
: lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, __assign({ savedGlobalContext: context }, processAction(action))); | ||
}); | ||
if (configuration.trackInteractions) { | ||
trackActions(lifeCycle); | ||
} | ||
return { | ||
addAction: function (action, savedGlobalContext) { | ||
configuration.isEnabled('v2_format') | ||
? lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, __assign({ savedGlobalContext: savedGlobalContext }, processActionV2(action))) | ||
: lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, __assign({ savedGlobalContext: savedGlobalContext }, processAction(action))); | ||
}, | ||
}; | ||
} | ||
@@ -24,0 +25,0 @@ function processAction(action) { |
@@ -1,2 +0,2 @@ | ||
import { Configuration, Context, ErrorSource } from '@datadog/browser-core'; | ||
import { Configuration, Context, ErrorSource, Observable, RawError } from '@datadog/browser-core'; | ||
import { LifeCycle } from '../../lifeCycle'; | ||
@@ -9,2 +9,7 @@ export interface ProvidedError { | ||
} | ||
export declare function startErrorCollection(lifeCycle: LifeCycle, configuration: Configuration): void; | ||
export declare function startErrorCollection(lifeCycle: LifeCycle, configuration: Configuration): { | ||
addError({ error, startTime, context: customerContext, source }: ProvidedError, savedGlobalContext?: Context | undefined): void; | ||
}; | ||
export declare function doStartErrorCollection(lifeCycle: LifeCycle, configuration: Configuration, observable: Observable<RawError>): { | ||
addError({ error, startTime, context: customerContext, source }: ProvidedError, savedGlobalContext?: Context | undefined): void; | ||
}; |
import { __assign } from "tslib"; | ||
import { combine, computeStackTrace, formatUnknownError, getTimestamp, } from '@datadog/browser-core'; | ||
import { combine, computeStackTrace, formatUnknownError, getTimestamp, startAutomaticErrorCollection, } from '@datadog/browser-core'; | ||
import { RumEventCategory } from '../../../types'; | ||
@@ -7,16 +7,21 @@ import { RumEventType } from '../../../typesV2'; | ||
export function startErrorCollection(lifeCycle, configuration) { | ||
lifeCycle.subscribe(LifeCycleEventType.ERROR_PROVIDED, function (_a) { | ||
var _b = _a.error, error = _b.error, startTime = _b.startTime, customerContext = _b.context, source = _b.source, savedGlobalContext = _a.context; | ||
var rawError = computeRawError(error, startTime, source); | ||
return doStartErrorCollection(lifeCycle, configuration, startAutomaticErrorCollection(configuration)); | ||
} | ||
export function doStartErrorCollection(lifeCycle, configuration, observable) { | ||
observable.subscribe(function (error) { | ||
configuration.isEnabled('v2_format') | ||
? lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, __assign({ customerContext: customerContext, | ||
savedGlobalContext: savedGlobalContext }, processErrorV2(rawError))) | ||
: lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, __assign({ customerContext: customerContext, | ||
savedGlobalContext: savedGlobalContext }, processError(rawError))); | ||
}); | ||
lifeCycle.subscribe(LifeCycleEventType.ERROR_COLLECTED, function (error) { | ||
configuration.isEnabled('v2_format') | ||
? lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, processErrorV2(error)) | ||
: lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, processError(error)); | ||
}); | ||
return { | ||
addError: function (_a, savedGlobalContext) { | ||
var error = _a.error, startTime = _a.startTime, customerContext = _a.context, source = _a.source; | ||
var rawError = computeRawError(error, startTime, source); | ||
configuration.isEnabled('v2_format') | ||
? lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, __assign({ customerContext: customerContext, | ||
savedGlobalContext: savedGlobalContext }, processErrorV2(rawError))) | ||
: lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, __assign({ customerContext: customerContext, | ||
savedGlobalContext: savedGlobalContext }, processError(rawError))); | ||
}, | ||
}; | ||
} | ||
@@ -23,0 +28,0 @@ function computeRawError(error, startTime, source) { |
@@ -11,2 +11,3 @@ import { RumPerformanceResourceTiming } from '../../../browser/performanceCollection'; | ||
* Strategy: | ||
* - from valid nested entries | ||
* - if a single timing match, return the timing | ||
@@ -13,0 +14,0 @@ * - if two following timings match (OPTIONS request), return the timing for the actual request |
@@ -0,1 +1,2 @@ | ||
import { toValidEntry } from './resourceUtils'; | ||
/** | ||
@@ -9,2 +10,3 @@ * Look for corresponding timing in resource timing buffer | ||
* Strategy: | ||
* - from valid nested entries | ||
* - if a single timing match, return the timing | ||
@@ -20,5 +22,5 @@ * - if two following timings match (OPTIONS request), return the timing for the actual request | ||
.getEntriesByName(request.url, 'resource') | ||
.filter(function (entry) { | ||
return isBetween(entry, request.startTime, endTime(request)); | ||
}); | ||
.map(function (entry) { return entry.toJSON(); }) | ||
.filter(toValidEntry) | ||
.filter(function (entry) { return isBetween(entry, request.startTime, endTime(request)); }); | ||
if (candidates.length === 1) { | ||
@@ -25,0 +27,0 @@ return candidates[0]; |
@@ -14,3 +14,2 @@ import { __assign } from "tslib"; | ||
: lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, processRequest(request)); | ||
lifeCycle.notify(LifeCycleEventType.RESOURCE_ADDED_TO_BATCH); | ||
} | ||
@@ -23,3 +22,2 @@ }); | ||
: lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, processResourceEntry(entry)); | ||
lifeCycle.notify(LifeCycleEventType.RESOURCE_ADDED_TO_BATCH); | ||
} | ||
@@ -26,0 +24,0 @@ }); |
@@ -20,3 +20,4 @@ import { Configuration, ResourceType } from '@datadog/browser-core'; | ||
export declare function computePerformanceResourceDetails(entry: RumPerformanceResourceTiming): PerformanceResourceDetails | undefined; | ||
export declare function toValidEntry(entry: RumPerformanceResourceTiming): RumPerformanceResourceTiming | undefined; | ||
export declare function computeSize(entry: RumPerformanceResourceTiming): number | undefined; | ||
export declare function isAllowedRequestUrl(configuration: Configuration, url: string): boolean | ""; |
@@ -0,1 +1,2 @@ | ||
import { __assign } from "tslib"; | ||
import { addMonitoringMessage, getPathName, includes, isIntakeRequest, isValidUrl, msToNs, ResourceType, } from '@datadog/browser-core'; | ||
@@ -63,27 +64,7 @@ export var FAKE_INITIAL_DOCUMENT = 'initial_document'; | ||
export function computePerformanceResourceDetails(entry) { | ||
var startTime = entry.startTime, fetchStart = entry.fetchStart, domainLookupStart = entry.domainLookupStart, domainLookupEnd = entry.domainLookupEnd, connectStart = entry.connectStart, secureConnectionStart = entry.secureConnectionStart, connectEnd = entry.connectEnd, requestStart = entry.requestStart, responseStart = entry.responseStart, responseEnd = entry.responseEnd; | ||
var redirectStart = entry.redirectStart, redirectEnd = entry.redirectEnd; | ||
// Ensure timings are in the right order. On top of filtering out potential invalid | ||
// RumPerformanceResourceTiming, it will ignore entries from requests where timings cannot be | ||
// collected, for example cross origin requests without a "Timing-Allow-Origin" header allowing | ||
// it. | ||
if (!areInOrder(startTime, fetchStart, domainLookupStart, domainLookupEnd, connectStart, connectEnd, requestStart, responseStart, responseEnd)) { | ||
var validEntry = toValidEntry(entry); | ||
if (!validEntry) { | ||
return undefined; | ||
} | ||
// The only time fetchStart is different than startTime is if a redirection occurred. | ||
var hasRedirectionOccurred = fetchStart !== startTime; | ||
if (hasRedirectionOccurred) { | ||
// Firefox doesn't provide redirect timings on cross origin requests. Provide a default for | ||
// those. | ||
if (redirectStart < startTime) { | ||
redirectStart = startTime; | ||
} | ||
if (redirectEnd < startTime) { | ||
redirectEnd = fetchStart; | ||
} | ||
// Make sure redirect timings are in order | ||
if (!areInOrder(startTime, redirectStart, redirectEnd, fetchStart)) { | ||
return undefined; | ||
} | ||
} | ||
var startTime = validEntry.startTime, fetchStart = validEntry.fetchStart, redirectStart = validEntry.redirectStart, redirectEnd = validEntry.redirectEnd, domainLookupStart = validEntry.domainLookupStart, domainLookupEnd = validEntry.domainLookupEnd, connectStart = validEntry.connectStart, secureConnectionStart = validEntry.secureConnectionStart, connectEnd = validEntry.connectEnd, requestStart = validEntry.requestStart, responseStart = validEntry.responseStart, responseEnd = validEntry.responseEnd; | ||
var details = { | ||
@@ -105,3 +86,3 @@ download: formatTiming(startTime, responseStart, responseEnd), | ||
} | ||
if (hasRedirectionOccurred) { | ||
if (hasRedirection(entry)) { | ||
details.redirect = formatTiming(startTime, redirectStart, redirectEnd); | ||
@@ -111,2 +92,33 @@ } | ||
} | ||
export function toValidEntry(entry) { | ||
// Ensure timings are in the right order. On top of filtering out potential invalid | ||
// RumPerformanceResourceTiming, it will ignore entries from requests where timings cannot be | ||
// collected, for example cross origin requests without a "Timing-Allow-Origin" header allowing | ||
// it. | ||
if (!areInOrder(entry.startTime, entry.fetchStart, entry.domainLookupStart, entry.domainLookupEnd, entry.connectStart, entry.connectEnd, entry.requestStart, entry.responseStart, entry.responseEnd)) { | ||
return undefined; | ||
} | ||
if (!hasRedirection(entry)) { | ||
return entry; | ||
} | ||
var redirectStart = entry.redirectStart, redirectEnd = entry.redirectEnd; | ||
// Firefox doesn't provide redirect timings on cross origin requests. | ||
// Provide a default for those. | ||
if (redirectStart < entry.startTime) { | ||
redirectStart = entry.startTime; | ||
} | ||
if (redirectEnd < entry.startTime) { | ||
redirectEnd = entry.fetchStart; | ||
} | ||
// Make sure redirect timings are in order | ||
if (!areInOrder(entry.startTime, redirectStart, redirectEnd, entry.fetchStart)) { | ||
return undefined; | ||
} | ||
return __assign(__assign({}, entry), { redirectEnd: redirectEnd, | ||
redirectStart: redirectStart }); | ||
} | ||
function hasRedirection(entry) { | ||
// The only time fetchStart is different than startTime is if a redirection occurred. | ||
return entry.fetchStart !== entry.startTime; | ||
} | ||
function formatTiming(origin, start, end) { | ||
@@ -113,0 +125,0 @@ return { |
import { Configuration } from '@datadog/browser-core'; | ||
import { LifeCycle } from '../../lifeCycle'; | ||
export declare function startViewCollection(lifeCycle: LifeCycle, configuration: Configuration, location: Location): void; | ||
export declare function startViewCollection(lifeCycle: LifeCycle, configuration: Configuration, location: Location): { | ||
stop(): void; | ||
}; |
@@ -13,3 +13,3 @@ import { __assign } from "tslib"; | ||
}); | ||
trackViews(location, lifeCycle); | ||
return trackViews(location, lifeCycle); | ||
} | ||
@@ -16,0 +16,0 @@ function processViewUpdate(view) { |
import { noop } from '@datadog/browser-core'; | ||
import { RumEventCategory } from '../types'; | ||
import { RumEventType } from '../typesV2'; | ||
import { LifeCycleEventType } from './lifeCycle'; | ||
@@ -11,28 +13,48 @@ export function trackEventCounts(lifeCycle, callback) { | ||
}; | ||
var subscriptions = []; | ||
subscriptions.push(lifeCycle.subscribe(LifeCycleEventType.ERROR_COLLECTED, function () { | ||
eventCounts.errorCount += 1; | ||
callback(eventCounts); | ||
})); | ||
subscriptions.push(lifeCycle.subscribe(LifeCycleEventType.AUTO_ACTION_COMPLETED, function () { | ||
eventCounts.userActionCount += 1; | ||
callback(eventCounts); | ||
})); | ||
subscriptions.push(lifeCycle.subscribe(LifeCycleEventType.CUSTOM_ACTION_COLLECTED, function () { | ||
eventCounts.userActionCount += 1; | ||
callback(eventCounts); | ||
})); | ||
subscriptions.push(lifeCycle.subscribe(LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, function (entry) { | ||
if (entry.entryType === 'longtask') { | ||
eventCounts.longTaskCount += 1; | ||
callback(eventCounts); | ||
var subscription = lifeCycle.subscribe(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, function (_a) { | ||
var rawRumEvent = _a.rawRumEvent; | ||
switch (rawRumEvent.evt.category) { | ||
case RumEventCategory.ERROR: | ||
eventCounts.errorCount += 1; | ||
callback(eventCounts); | ||
break; | ||
case RumEventCategory.USER_ACTION: | ||
eventCounts.userActionCount += 1; | ||
callback(eventCounts); | ||
break; | ||
case RumEventCategory.LONG_TASK: | ||
eventCounts.longTaskCount += 1; | ||
callback(eventCounts); | ||
break; | ||
case RumEventCategory.RESOURCE: | ||
eventCounts.resourceCount += 1; | ||
callback(eventCounts); | ||
break; | ||
} | ||
})); | ||
subscriptions.push(lifeCycle.subscribe(LifeCycleEventType.RESOURCE_ADDED_TO_BATCH, function () { | ||
eventCounts.resourceCount += 1; | ||
callback(eventCounts); | ||
})); | ||
}); | ||
var subscriptionV2 = lifeCycle.subscribe(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, function (_a) { | ||
var rawRumEvent = _a.rawRumEvent; | ||
switch (rawRumEvent.type) { | ||
case RumEventType.ERROR: | ||
eventCounts.errorCount += 1; | ||
callback(eventCounts); | ||
break; | ||
case RumEventType.ACTION: | ||
eventCounts.userActionCount += 1; | ||
callback(eventCounts); | ||
break; | ||
case RumEventType.LONG_TASK: | ||
eventCounts.longTaskCount += 1; | ||
callback(eventCounts); | ||
break; | ||
case RumEventType.RESOURCE: | ||
eventCounts.resourceCount += 1; | ||
callback(eventCounts); | ||
break; | ||
} | ||
}); | ||
return { | ||
stop: function () { | ||
subscriptions.forEach(function (s) { return s.unsubscribe(); }); | ||
subscription.unsubscribe(); | ||
subscriptionV2.unsubscribe(); | ||
}, | ||
@@ -39,0 +61,0 @@ eventCounts: eventCounts, |
{ | ||
"name": "@datadog/browser-rum", | ||
"version": "1.25.1", | ||
"version": "1.25.2", | ||
"license": "Apache-2.0", | ||
@@ -16,9 +16,7 @@ "main": "cjs/index.js", | ||
"dependencies": { | ||
"@datadog/browser-core": "1.25.1", | ||
"@datadog/browser-core": "1.25.2", | ||
"tslib": "^1.10.0" | ||
}, | ||
"devDependencies": { | ||
"@types/sinon": "7.0.13", | ||
"ajv": "6.12.6", | ||
"sinon": "7.3.2" | ||
"ajv": "6.12.6" | ||
}, | ||
@@ -30,3 +28,3 @@ "repository": { | ||
}, | ||
"gitHead": "e2a15f2b957fadc47263116af9acb960cc5354b2" | ||
"gitHead": "761c01fbdc918772af0e6a2a2c38ba682c24f2ae" | ||
} |
import { isIE } from '@datadog/browser-core' | ||
import sinon from 'sinon' | ||
import { setup, TestSetupBuilder } from '../../test/specHelper' | ||
import { RumPerformanceNavigationTiming } from '../browser/performanceCollection' | ||
import { LifeCycleEventType } from '../domain/lifeCycle' | ||
import { AutoAction } from '../domain/rumEventsCollection/action/trackActions' | ||
import { LifeCycle, LifeCycleEventType } from '../domain/lifeCycle' | ||
import { SESSION_KEEP_ALIVE_INTERVAL, THROTTLE_VIEW_UPDATE_PERIOD } from '../domain/rumEventsCollection/view/trackViews' | ||
import { RumEvent } from '../index' | ||
import { startRumEventCollection } from './rum' | ||
function getServerRequestBodies<T>(server: sinon.SinonFakeServer) { | ||
return server.requests.map((r) => JSON.parse(r.requestBody) as T) | ||
} | ||
function getRumMessage(server: sinon.SinonFakeServer, index: number) { | ||
return JSON.parse(server.requests[index].requestBody) as RumEvent | ||
} | ||
interface ExpectedRequestBody { | ||
interface ServerRumEvent { | ||
application_id: string | ||
@@ -33,7 +23,20 @@ date: number | ||
referrer: string | ||
url: string | ||
} | ||
} | ||
function collectServerEvents(lifeCycle: LifeCycle) { | ||
const serverRumEvents: ServerRumEvent[] = [] | ||
lifeCycle.subscribe(LifeCycleEventType.RUM_EVENT_COLLECTED, ({ serverRumEvent }) => { | ||
serverRumEvents.push(serverRumEvent as any) | ||
}) | ||
lifeCycle.subscribe(LifeCycleEventType.RUM_EVENT_V2_COLLECTED, ({ serverRumEvent }) => { | ||
serverRumEvents.push(serverRumEvent as any) | ||
}) | ||
return serverRumEvents | ||
} | ||
describe('rum session', () => { | ||
let setupBuilder: TestSetupBuilder | ||
let serverRumEvents: ServerRumEvent[] | ||
@@ -45,5 +48,6 @@ beforeEach(() => { | ||
setupBuilder = setup() | ||
.withFakeServer() | ||
.withRum() | ||
setupBuilder = setup().beforeBuild(({ applicationId, location, lifeCycle, configuration, session }) => { | ||
serverRumEvents = collectServerEvents(lifeCycle) | ||
return startRumEventCollection(applicationId, location, lifeCycle, configuration, session, () => ({})) | ||
}) | ||
}) | ||
@@ -57,3 +61,3 @@ | ||
let sessionId = '42' | ||
const { server, lifeCycle } = setupBuilder | ||
const { lifeCycle } = setupBuilder | ||
.withSession({ | ||
@@ -64,23 +68,20 @@ getId: () => sessionId, | ||
}) | ||
.beforeBuild((_, configuration) => { | ||
configuration.isEnabled = () => false | ||
.withConfiguration({ | ||
isEnabled: () => false, | ||
}) | ||
.build() | ||
const initialRequests = getServerRequestBodies<ExpectedRequestBody>(server) | ||
expect(initialRequests.length).toEqual(1) | ||
expect(initialRequests[0].evt.category).toEqual('view') | ||
expect(initialRequests[0].session_id).toEqual('42') | ||
expect(serverRumEvents.length).toEqual(1) | ||
expect(serverRumEvents[0].evt.category).toEqual('view') | ||
expect(serverRumEvents[0].session_id).toEqual('42') | ||
server.requests = [] | ||
sessionId = '43' | ||
lifeCycle.notify(LifeCycleEventType.SESSION_RENEWED) | ||
const subsequentRequests = getServerRequestBodies<ExpectedRequestBody>(server) | ||
expect(subsequentRequests.length).toEqual(1) | ||
expect(serverRumEvents.length).toEqual(2) | ||
// New view event | ||
expect(subsequentRequests[0].evt.category).toEqual('view') | ||
expect(subsequentRequests[0].session_id).toEqual('43') | ||
expect(subsequentRequests[0].view.id).not.toEqual(initialRequests[0].view.id) | ||
expect(serverRumEvents[1].evt.category).toEqual('view') | ||
expect(serverRumEvents[1].session_id).toEqual('43') | ||
expect(serverRumEvents[1].view.id).not.toEqual(serverRumEvents[0].view.id) | ||
}) | ||
@@ -90,3 +91,3 @@ | ||
let sessionId = '42' | ||
const { server, lifeCycle } = setupBuilder | ||
const { lifeCycle } = setupBuilder | ||
.withSession({ | ||
@@ -99,18 +100,15 @@ getId: () => sessionId, | ||
const initialRequests = getServerRequestBodies<ExpectedRequestBody>(server) | ||
expect(initialRequests.length).toEqual(1) | ||
expect(initialRequests[0].type).toEqual('view') | ||
expect(initialRequests[0].session.id).toEqual('42') | ||
expect(serverRumEvents.length).toEqual(1) | ||
expect(serverRumEvents[0].type).toEqual('view') | ||
expect(serverRumEvents[0].session.id).toEqual('42') | ||
server.requests = [] | ||
sessionId = '43' | ||
lifeCycle.notify(LifeCycleEventType.SESSION_RENEWED) | ||
const subsequentRequests = getServerRequestBodies<ExpectedRequestBody>(server) | ||
expect(subsequentRequests.length).toEqual(1) | ||
expect(serverRumEvents.length).toEqual(2) | ||
// New view event | ||
expect(subsequentRequests[0].type).toEqual('view') | ||
expect(subsequentRequests[0].session.id).toEqual('43') | ||
expect(subsequentRequests[0].view.id).not.toEqual(initialRequests[0].view.id) | ||
expect(serverRumEvents[1].type).toEqual('view') | ||
expect(serverRumEvents[1].session.id).toEqual('43') | ||
expect(serverRumEvents[1].view.id).not.toEqual(serverRumEvents[0].view.id) | ||
}) | ||
@@ -121,4 +119,4 @@ }) | ||
let isSessionTracked: boolean | ||
let requests: ExpectedRequestBody[] | ||
let setupBuilder: TestSetupBuilder | ||
let serverRumEvents: ServerRumEvent[] | ||
@@ -131,3 +129,2 @@ beforeEach(() => { | ||
setupBuilder = setup() | ||
.withFakeServer() | ||
.withFakeClock() | ||
@@ -139,3 +136,6 @@ .withSession({ | ||
}) | ||
.withRum() | ||
.beforeBuild(({ applicationId, location, lifeCycle, configuration, session }) => { | ||
serverRumEvents = collectServerEvents(lifeCycle) | ||
return startRumEventCollection(applicationId, location, lifeCycle, configuration, session, () => ({})) | ||
}) | ||
}) | ||
@@ -148,5 +148,5 @@ | ||
it('should send a view update regularly (v1)', () => { | ||
const { server, clock } = setupBuilder | ||
.beforeBuild((_, configuration) => { | ||
configuration.isEnabled = () => false | ||
const { clock } = setupBuilder | ||
.withConfiguration({ | ||
isEnabled: () => false, | ||
}) | ||
@@ -157,3 +157,3 @@ .build() | ||
clock.tick(SESSION_KEEP_ALIVE_INTERVAL * 0.9) | ||
server.requests = [] | ||
serverRumEvents.length = 0 | ||
@@ -163,6 +163,4 @@ clock.tick(SESSION_KEEP_ALIVE_INTERVAL * 0.1) | ||
// view update | ||
requests = getServerRequestBodies<ExpectedRequestBody>(server) | ||
server.requests = [] | ||
expect(requests.length).toEqual(1) | ||
expect(requests[0].evt.category).toEqual('view') | ||
expect(serverRumEvents.length).toEqual(1) | ||
expect(serverRumEvents[0].evt.category).toEqual('view') | ||
@@ -172,14 +170,12 @@ clock.tick(SESSION_KEEP_ALIVE_INTERVAL) | ||
// view update | ||
requests = getServerRequestBodies<ExpectedRequestBody>(server) | ||
server.requests = [] | ||
expect(requests.length).toEqual(1) | ||
expect(requests[0].evt.category).toEqual('view') | ||
expect(serverRumEvents.length).toEqual(2) | ||
expect(serverRumEvents[1].evt.category).toEqual('view') | ||
}) | ||
it('should send a view update regularly', () => { | ||
const { server, clock } = setupBuilder.build() | ||
const { clock } = setupBuilder.build() | ||
// clear initial events | ||
clock.tick(SESSION_KEEP_ALIVE_INTERVAL * 0.9) | ||
server.requests = [] | ||
serverRumEvents.length = 0 | ||
@@ -189,6 +185,4 @@ clock.tick(SESSION_KEEP_ALIVE_INTERVAL * 0.1) | ||
// view update | ||
requests = getServerRequestBodies<ExpectedRequestBody>(server) | ||
server.requests = [] | ||
expect(requests.length).toEqual(1) | ||
expect(requests[0].type).toEqual('view') | ||
expect(serverRumEvents.length).toEqual(1) | ||
expect(serverRumEvents[0].type).toEqual('view') | ||
@@ -198,14 +192,12 @@ clock.tick(SESSION_KEEP_ALIVE_INTERVAL) | ||
// view update | ||
requests = getServerRequestBodies<ExpectedRequestBody>(server) | ||
server.requests = [] | ||
expect(requests.length).toEqual(1) | ||
expect(requests[0].type).toEqual('view') | ||
expect(serverRumEvents.length).toEqual(2) | ||
expect(serverRumEvents[1].type).toEqual('view') | ||
}) | ||
it('should not send view update when session is expired', () => { | ||
const { server, clock } = setupBuilder.build() | ||
const { clock } = setupBuilder.build() | ||
// clear initial events | ||
clock.tick(SESSION_KEEP_ALIVE_INTERVAL * 0.9) | ||
server.requests = [] | ||
serverRumEvents.length = 0 | ||
@@ -217,4 +209,3 @@ // expire session | ||
requests = getServerRequestBodies<ExpectedRequestBody>(server) | ||
expect(requests.length).toEqual(0) | ||
expect(serverRumEvents.length).toEqual(0) | ||
}) | ||
@@ -234,7 +225,9 @@ }) | ||
let setupBuilder: TestSetupBuilder | ||
let serverRumEvents: ServerRumEvent[] | ||
beforeEach(() => { | ||
setupBuilder = setup() | ||
.withFakeServer() | ||
.withRum() | ||
setupBuilder = setup().beforeBuild(({ applicationId, location, lifeCycle, configuration, session }) => { | ||
serverRumEvents = collectServerEvents(lifeCycle) | ||
return startRumEventCollection(applicationId, location, lifeCycle, configuration, session, () => ({})) | ||
}) | ||
}) | ||
@@ -247,15 +240,15 @@ | ||
it('should keep the same URL when updating a view ended by a URL change', () => { | ||
const { server } = setupBuilder.withFakeLocation('http://foo.com/').build() | ||
setupBuilder.withFakeLocation('http://foo.com/').build() | ||
server.requests = [] | ||
serverRumEvents.length = 0 | ||
history.pushState({}, '', '/bar') | ||
expect(server.requests.length).toEqual(2) | ||
expect(getRumMessage(server, 0).view.url).toEqual('http://foo.com/') | ||
expect(getRumMessage(server, 1).view.url).toEqual('http://foo.com/bar') | ||
expect(serverRumEvents.length).toEqual(2) | ||
expect(serverRumEvents[0].view.url).toEqual('http://foo.com/') | ||
expect(serverRumEvents[1].view.url).toEqual('http://foo.com/bar') | ||
}) | ||
it('should keep the same URL when updating an ended view', () => { | ||
const { server, lifeCycle, clock } = setupBuilder | ||
const { lifeCycle, clock } = setupBuilder | ||
.withFakeClock() | ||
@@ -269,3 +262,3 @@ .withFakeLocation('http://foo.com/') | ||
server.requests = [] | ||
serverRumEvents.length = 0 | ||
@@ -275,5 +268,5 @@ lifeCycle.notify(LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, FAKE_NAVIGATION_ENTRY) | ||
expect(server.requests.length).toEqual(1) | ||
expect(getRumMessage(server, 0).view.url).toEqual('http://foo.com/') | ||
expect(serverRumEvents.length).toEqual(1) | ||
expect(serverRumEvents[0].view.url).toEqual('http://foo.com/') | ||
}) | ||
}) |
@@ -7,8 +7,7 @@ import { combine, commonInit, Configuration, Context } from '@datadog/browser-core' | ||
import { startInternalContext } from '../domain/internalContext' | ||
import { LifeCycle, LifeCycleEventType } from '../domain/lifeCycle' | ||
import { LifeCycle } from '../domain/lifeCycle' | ||
import { startParentContexts } from '../domain/parentContexts' | ||
import { startRequestCollection } from '../domain/requestCollection' | ||
import { startActionCollection } from '../domain/rumEventsCollection/action/actionCollection' | ||
import { CustomAction } from '../domain/rumEventsCollection/action/trackActions' | ||
import { ProvidedError, startErrorCollection } from '../domain/rumEventsCollection/error/errorCollection' | ||
import { startErrorCollection } from '../domain/rumEventsCollection/error/errorCollection' | ||
import { startLongTaskCollection } from '../domain/rumEventsCollection/longTask/longTaskCollection' | ||
@@ -26,8 +25,3 @@ import { startResourceCollection } from '../domain/rumEventsCollection/resource/resourceCollection' | ||
const isCollectingError = true | ||
const { errorObservable, configuration, internalMonitoring } = commonInit( | ||
userConfiguration, | ||
buildEnv, | ||
isCollectingError | ||
) | ||
const { configuration, internalMonitoring } = commonInit(userConfiguration, buildEnv) | ||
const session = startRumSession(configuration, lifeCycle) | ||
@@ -45,3 +39,3 @@ | ||
const { parentContexts } = startRumEventCollection( | ||
const { parentContexts, addError, addAction } = startRumEventCollection( | ||
userConfiguration.applicationId, | ||
@@ -61,14 +55,6 @@ location, | ||
errorObservable.subscribe((errorMessage) => lifeCycle.notify(LifeCycleEventType.ERROR_COLLECTED, errorMessage)) | ||
return { | ||
addAction, | ||
addError, | ||
getInternalContext: internalContext.get, | ||
addAction(action: CustomAction, context?: Context) { | ||
lifeCycle.notify(LifeCycleEventType.CUSTOM_ACTION_COLLECTED, { action, context }) | ||
}, | ||
addError(error: ProvidedError, context?: Context) { | ||
lifeCycle.notify(LifeCycleEventType.ERROR_PROVIDED, { error, context }) | ||
}, | ||
} | ||
@@ -92,6 +78,8 @@ } | ||
startViewCollection(lifeCycle, configuration, location) | ||
startErrorCollection(lifeCycle, configuration) | ||
startActionCollection(lifeCycle, configuration) | ||
const { addError } = startErrorCollection(lifeCycle, configuration) | ||
const { addAction } = startActionCollection(lifeCycle, configuration) | ||
return { | ||
addAction, | ||
addError, | ||
parentContexts, | ||
@@ -98,0 +86,0 @@ |
import { isIE, restorePageVisibility, setPageVisibility } from '@datadog/browser-core' | ||
import { setup, TestSetupBuilder } from '../../test/specHelper' | ||
import { retrieveInitialDocumentResourceTiming } from './performanceCollection' | ||
import { retrieveInitialDocumentResourceTiming, startPerformanceCollection } from './performanceCollection' | ||
describe('rum first_contentful_paint', () => { | ||
let setupBuilder: TestSetupBuilder | ||
let performanceObserverObserveSpy: jasmine.Spy<(options?: PerformanceObserverInit | undefined) => void> | ||
beforeEach(() => { | ||
@@ -13,5 +15,6 @@ if (isIE()) { | ||
setupBuilder = setup() | ||
.withPerformanceObserverStubBuilder() | ||
.withPerformanceCollection() | ||
performanceObserverObserveSpy = spyOn(PerformanceObserver.prototype, 'observe') | ||
setupBuilder = setup().beforeBuild(({ lifeCycle, configuration }) => { | ||
startPerformanceCollection(lifeCycle, configuration) | ||
}) | ||
}) | ||
@@ -26,5 +29,5 @@ | ||
setPageVisibility('hidden') | ||
const { stubBuilder } = setupBuilder.build() | ||
setupBuilder.build() | ||
expect(stubBuilder.getEntryTypes()).not.toContain('paint') | ||
expect(performanceObserverObserveSpy.calls.argsFor(0)[0]!.entryTypes).not.toContain('paint') | ||
}) | ||
@@ -34,5 +37,5 @@ | ||
setPageVisibility('visible') | ||
const { stubBuilder } = setupBuilder.build() | ||
setupBuilder.build() | ||
expect(stubBuilder.getEntryTypes()).toContain('paint') | ||
expect(performanceObserverObserveSpy.calls.argsFor(0)[0]!.entryTypes).toContain('paint') | ||
}) | ||
@@ -44,3 +47,5 @@ }) | ||
beforeEach(() => { | ||
setupBuilder = setup().withPerformanceCollection() | ||
setupBuilder = setup().beforeBuild(({ lifeCycle, configuration }) => { | ||
startPerformanceCollection(lifeCycle, configuration) | ||
}) | ||
}) | ||
@@ -47,0 +52,0 @@ |
@@ -5,2 +5,3 @@ import { Context } from '@datadog/browser-core' | ||
import { RawRumEvent } from '../types' | ||
import { startRumAssembly } from './assembly' | ||
import { LifeCycle, LifeCycleEventType } from './lifeCycle' | ||
@@ -31,3 +32,3 @@ | ||
let lifeCycle: LifeCycle | ||
let setGlobalContext: (context: Context) => void | ||
let globalContext: Context | ||
let serverRumEvents: ServerRumEvents[] | ||
@@ -76,4 +77,6 @@ let isTracked: boolean | ||
}) | ||
.withAssembly() | ||
;({ lifeCycle, setGlobalContext } = setupBuilder.build()) | ||
.beforeBuild(({ applicationId, configuration, lifeCycle: localLifeCycle, session, parentContexts }) => { | ||
startRumAssembly(applicationId, configuration, localLifeCycle, session, parentContexts, () => globalContext) | ||
}) | ||
;({ lifeCycle } = setupBuilder.build()) | ||
@@ -121,3 +124,3 @@ serverRumEvents = [] | ||
it('should be merged with event attributes', () => { | ||
setGlobalContext({ bar: 'foo' }) | ||
globalContext = { bar: 'foo' } | ||
generateRawRumEvent(RumEventCategory.VIEW) | ||
@@ -129,4 +132,3 @@ | ||
it('should ignore subsequent context mutation', () => { | ||
const globalContext = { bar: 'foo' } | ||
setGlobalContext(globalContext) | ||
globalContext = { bar: 'foo' } | ||
generateRawRumEvent(RumEventCategory.VIEW) | ||
@@ -141,3 +143,3 @@ delete globalContext.bar | ||
it('should not be automatically snake cased', () => { | ||
setGlobalContext({ fooBar: 'foo' }) | ||
globalContext = { fooBar: 'foo' } | ||
generateRawRumEvent(RumEventCategory.VIEW) | ||
@@ -149,3 +151,3 @@ | ||
it('should ignore the current global context when a saved global context is provided', () => { | ||
setGlobalContext({ replacedContext: 'b', addedContext: 'x' }) | ||
globalContext = { replacedContext: 'b', addedContext: 'x' } | ||
@@ -152,0 +154,0 @@ generateRawRumEvent(RumEventCategory.VIEW, undefined, { replacedContext: 'a' }) |
import { Context } from '@datadog/browser-core' | ||
import { createRawRumEvent } from '../../test/fixtures' | ||
import { setup, TestSetupBuilder } from '../../test/specHelper' | ||
import { RawRumEventV2, RumEventType } from '../typesV2' | ||
import { RumEventType } from '../typesV2' | ||
import { startRumAssemblyV2 } from './assemblyV2' | ||
import { LifeCycle, LifeCycleEventType } from './lifeCycle' | ||
@@ -35,3 +37,3 @@ | ||
let lifeCycle: LifeCycle | ||
let setGlobalContext: (context: Context) => void | ||
let globalContext: Context | ||
let serverRumEvents: ServerRumEvents[] | ||
@@ -41,17 +43,2 @@ let isTracked: boolean | ||
function generateRawRumEvent( | ||
type: RumEventType, | ||
properties?: Partial<RawRumEventV2>, | ||
savedGlobalContext?: Context, | ||
customerContext?: Context | ||
) { | ||
const event = { type, ...properties } | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, { | ||
customerContext, | ||
savedGlobalContext, | ||
rawRumEvent: event as RawRumEventV2, | ||
startTime: 0, | ||
}) | ||
} | ||
beforeEach(() => { | ||
@@ -83,4 +70,6 @@ isTracked = true | ||
}) | ||
.withAssemblyV2() | ||
;({ lifeCycle, setGlobalContext } = setupBuilder.build()) | ||
.beforeBuild(({ applicationId, configuration, lifeCycle: localLifeCycle, session, parentContexts }) => { | ||
startRumAssemblyV2(applicationId, configuration, localLifeCycle, session, parentContexts, () => globalContext) | ||
}) | ||
;({ lifeCycle } = setupBuilder.build()) | ||
@@ -99,3 +88,6 @@ serverRumEvents = [] | ||
it('should have snake cased attributes', () => { | ||
generateRawRumEvent(RumEventType.LONG_TASK, { longTask: { duration: 2 } }) | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, { | ||
rawRumEvent: createRawRumEvent(RumEventType.LONG_TASK, { longTask: { duration: 2 } }), | ||
startTime: 0, | ||
}) | ||
@@ -108,3 +100,6 @@ expect(serverRumEvents[0].long_task!.duration).toBe(2) | ||
it('should be merged with event attributes', () => { | ||
generateRawRumEvent(RumEventType.VIEW) | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, { | ||
rawRumEvent: createRawRumEvent(RumEventType.VIEW, undefined), | ||
startTime: 0, | ||
}) | ||
@@ -116,3 +111,6 @@ expect(serverRumEvents[0].view.id).toBeDefined() | ||
it('should be snake cased', () => { | ||
generateRawRumEvent(RumEventType.VIEW) | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, { | ||
rawRumEvent: createRawRumEvent(RumEventType.VIEW, undefined), | ||
startTime: 0, | ||
}) | ||
@@ -123,3 +121,6 @@ expect(serverRumEvents[0]._dd.format_version).toBe(2) | ||
it('should be overwritten by event attributes', () => { | ||
generateRawRumEvent(RumEventType.VIEW, { date: 10 }) | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, { | ||
rawRumEvent: createRawRumEvent(RumEventType.VIEW, { date: 10 }), | ||
startTime: 0, | ||
}) | ||
@@ -132,4 +133,7 @@ expect(serverRumEvents[0].date).toBe(10) | ||
it('should be merged with event attributes', () => { | ||
setGlobalContext({ bar: 'foo' }) | ||
generateRawRumEvent(RumEventType.VIEW) | ||
globalContext = { bar: 'foo' } | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, { | ||
rawRumEvent: createRawRumEvent(RumEventType.VIEW), | ||
startTime: 0, | ||
}) | ||
@@ -140,7 +144,12 @@ expect((serverRumEvents[0].context as any).bar).toEqual('foo') | ||
it('should ignore subsequent context mutation', () => { | ||
const globalContext = { bar: 'foo' } | ||
setGlobalContext(globalContext) | ||
generateRawRumEvent(RumEventType.VIEW) | ||
globalContext = { bar: 'foo' } | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, { | ||
rawRumEvent: createRawRumEvent(RumEventType.VIEW), | ||
startTime: 0, | ||
}) | ||
delete globalContext.bar | ||
generateRawRumEvent(RumEventType.VIEW) | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, { | ||
rawRumEvent: createRawRumEvent(RumEventType.VIEW), | ||
startTime: 0, | ||
}) | ||
@@ -152,4 +161,7 @@ expect((serverRumEvents[0].context as any).bar).toEqual('foo') | ||
it('should not be automatically snake cased', () => { | ||
setGlobalContext({ fooBar: 'foo' }) | ||
generateRawRumEvent(RumEventType.VIEW) | ||
globalContext = { fooBar: 'foo' } | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, { | ||
rawRumEvent: createRawRumEvent(RumEventType.VIEW), | ||
startTime: 0, | ||
}) | ||
@@ -160,5 +172,9 @@ expect((serverRumEvents[0].context as any).fooBar).toEqual('foo') | ||
it('should ignore the current global context when a saved global context is provided', () => { | ||
setGlobalContext({ replacedContext: 'b', addedContext: 'x' }) | ||
globalContext = { replacedContext: 'b', addedContext: 'x' } | ||
generateRawRumEvent(RumEventType.VIEW, undefined, { replacedContext: 'a' }) | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, { | ||
rawRumEvent: createRawRumEvent(RumEventType.VIEW), | ||
savedGlobalContext: { replacedContext: 'a' }, | ||
startTime: 0, | ||
}) | ||
@@ -172,3 +188,7 @@ expect((serverRumEvents[0].context as any).replacedContext).toEqual('a') | ||
it('should be merged with event attributes', () => { | ||
generateRawRumEvent(RumEventType.VIEW, undefined, undefined, { foo: 'bar' }) | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, { | ||
customerContext: { foo: 'bar' }, | ||
rawRumEvent: createRawRumEvent(RumEventType.VIEW), | ||
startTime: 0, | ||
}) | ||
@@ -179,3 +199,7 @@ expect((serverRumEvents[0].context as any).foo).toEqual('bar') | ||
it('should not be automatically snake cased', () => { | ||
generateRawRumEvent(RumEventType.VIEW, undefined, undefined, { fooBar: 'foo' }) | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, { | ||
customerContext: { fooBar: 'foo' }, | ||
rawRumEvent: createRawRumEvent(RumEventType.VIEW), | ||
startTime: 0, | ||
}) | ||
@@ -189,11 +213,23 @@ expect((serverRumEvents[0].context as any).fooBar).toEqual('foo') | ||
;[RumEventType.RESOURCE, RumEventType.LONG_TASK, RumEventType.ERROR].forEach((category) => { | ||
generateRawRumEvent(category) | ||
expect(serverRumEvents[0].action.id).toBeDefined() | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, { | ||
rawRumEvent: createRawRumEvent(category), | ||
startTime: 0, | ||
}) | ||
expect(serverRumEvents[0].action).toEqual({ id: '7890' }) | ||
serverRumEvents = [] | ||
}) | ||
;[RumEventType.VIEW, RumEventType.ACTION].forEach((category) => { | ||
generateRawRumEvent(category) | ||
expect(serverRumEvents[0].action).not.toBeDefined() | ||
serverRumEvents = [] | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, { | ||
rawRumEvent: createRawRumEvent(RumEventType.VIEW), | ||
startTime: 0, | ||
}) | ||
expect(serverRumEvents[0].action).not.toBeDefined() | ||
serverRumEvents = [] | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, { | ||
rawRumEvent: createRawRumEvent(RumEventType.ACTION), | ||
startTime: 0, | ||
}) | ||
expect(serverRumEvents[0].action.id).not.toBeDefined() | ||
serverRumEvents = [] | ||
}) | ||
@@ -204,3 +240,6 @@ }) | ||
it('should be merged with event attributes', () => { | ||
generateRawRumEvent(RumEventType.ACTION) | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, { | ||
rawRumEvent: createRawRumEvent(RumEventType.ACTION), | ||
startTime: 0, | ||
}) | ||
expect(serverRumEvents[0].view).toEqual({ | ||
@@ -219,3 +258,6 @@ id: 'abcde', | ||
generateRawRumEvent(RumEventType.VIEW) | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, { | ||
rawRumEvent: createRawRumEvent(RumEventType.VIEW), | ||
startTime: 0, | ||
}) | ||
expect(serverRumEvents.length).toBe(1) | ||
@@ -227,3 +269,6 @@ }) | ||
generateRawRumEvent(RumEventType.VIEW) | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, { | ||
rawRumEvent: createRawRumEvent(RumEventType.VIEW), | ||
startTime: 0, | ||
}) | ||
expect(serverRumEvents.length).toBe(0) | ||
@@ -235,3 +280,6 @@ }) | ||
generateRawRumEvent(RumEventType.VIEW) | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, { | ||
rawRumEvent: createRawRumEvent(RumEventType.VIEW), | ||
startTime: 0, | ||
}) | ||
expect(serverRumEvents.length).toBe(1) | ||
@@ -243,3 +291,6 @@ }) | ||
generateRawRumEvent(RumEventType.VIEW) | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, { | ||
rawRumEvent: createRawRumEvent(RumEventType.VIEW), | ||
startTime: 0, | ||
}) | ||
expect(serverRumEvents.length).toBe(0) | ||
@@ -246,0 +297,0 @@ }) |
import { setup, TestSetupBuilder } from '../../test/specHelper' | ||
import { startInternalContext } from './internalContext' | ||
import { ParentContexts } from './parentContexts' | ||
@@ -7,2 +8,3 @@ | ||
let parentContextsStub: Partial<ParentContexts> | ||
let internalContext: ReturnType<typeof startInternalContext> | ||
@@ -27,6 +29,8 @@ beforeEach(() => { | ||
.withParentContexts(parentContextsStub) | ||
.withInternalContext() | ||
.beforeBuild((_, configuration) => { | ||
configuration.isEnabled = () => false | ||
.withConfiguration({ | ||
isEnabled: () => false, | ||
}) | ||
.beforeBuild(({ applicationId, session, parentContexts, configuration }) => { | ||
internalContext = startInternalContext(applicationId, session, parentContexts, configuration) | ||
}) | ||
}) | ||
@@ -39,3 +43,3 @@ | ||
it('should return current internal context', () => { | ||
const { internalContext } = setupBuilder.build() | ||
setupBuilder.build() | ||
@@ -57,3 +61,3 @@ expect(internalContext.get()).toEqual({ | ||
it("should return undefined if the session isn't tracked", () => { | ||
const { internalContext } = setupBuilder | ||
setupBuilder | ||
.withSession({ | ||
@@ -70,3 +74,3 @@ getId: () => '1234', | ||
it('should return internal context corresponding to startTime', () => { | ||
const { internalContext } = setupBuilder.build() | ||
setupBuilder.build() | ||
@@ -83,2 +87,3 @@ internalContext.get(123) | ||
let parentContextsStub: Partial<ParentContexts> | ||
let internalContext: ReturnType<typeof startInternalContext> | ||
@@ -105,3 +110,5 @@ beforeEach(() => { | ||
.withParentContexts(parentContextsStub) | ||
.withInternalContext() | ||
.beforeBuild(({ applicationId, session, parentContexts, configuration }) => { | ||
internalContext = startInternalContext(applicationId, session, parentContexts, configuration) | ||
}) | ||
}) | ||
@@ -114,3 +121,3 @@ | ||
it('should return current internal context', () => { | ||
const { internalContext } = setupBuilder.build() | ||
setupBuilder.build() | ||
@@ -136,3 +143,3 @@ expect(internalContext.get()).toEqual({ | ||
it("should return undefined if the session isn't tracked", () => { | ||
const { internalContext } = setupBuilder | ||
setupBuilder | ||
.withSession({ | ||
@@ -149,3 +156,3 @@ getId: () => '1234', | ||
it('should return internal context corresponding to startTime', () => { | ||
const { internalContext } = setupBuilder.build() | ||
setupBuilder.build() | ||
@@ -152,0 +159,0 @@ internalContext.get(123) |
@@ -1,2 +0,2 @@ | ||
import { Context, RawError } from '@datadog/browser-core' | ||
import { Context } from '@datadog/browser-core' | ||
import { RumPerformanceEntry } from '../browser/performanceCollection' | ||
@@ -7,10 +7,6 @@ import { RawRumEvent, RumEvent } from '../types' | ||
import { AutoAction, AutoActionCreatedEvent, CustomAction } from './rumEventsCollection/action/trackActions' | ||
import { ProvidedError } from './rumEventsCollection/error/errorCollection' | ||
import { View, ViewCreatedEvent } from './rumEventsCollection/view/trackViews' | ||
export enum LifeCycleEventType { | ||
ERROR_COLLECTED, | ||
ERROR_PROVIDED, | ||
PERFORMANCE_ENTRY_COLLECTED, | ||
CUSTOM_ACTION_COLLECTED, | ||
AUTO_ACTION_CREATED, | ||
@@ -24,3 +20,2 @@ AUTO_ACTION_COMPLETED, | ||
SESSION_RENEWED, | ||
RESOURCE_ADDED_TO_BATCH, | ||
DOM_MUTATED, | ||
@@ -41,4 +36,2 @@ BEFORE_UNLOAD, | ||
notify(eventType: LifeCycleEventType.ERROR_COLLECTED, data: RawError): void | ||
notify(eventType: LifeCycleEventType.ERROR_PROVIDED, data: { error: ProvidedError; context?: Context }): void | ||
notify(eventType: LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, data: RumPerformanceEntry): void | ||
@@ -48,3 +41,2 @@ notify(eventType: LifeCycleEventType.REQUEST_STARTED, data: RequestStartEvent): void | ||
notify(eventType: LifeCycleEventType.AUTO_ACTION_COMPLETED, data: AutoAction): void | ||
notify(eventType: LifeCycleEventType.CUSTOM_ACTION_COLLECTED, data: { action: CustomAction; context?: Context }): void | ||
notify(eventType: LifeCycleEventType.AUTO_ACTION_CREATED, data: AutoActionCreatedEvent): void | ||
@@ -56,3 +48,2 @@ notify(eventType: LifeCycleEventType.VIEW_CREATED, data: ViewCreatedEvent): void | ||
| LifeCycleEventType.SESSION_RENEWED | ||
| LifeCycleEventType.RESOURCE_ADDED_TO_BATCH | ||
| LifeCycleEventType.DOM_MUTATED | ||
@@ -92,8 +83,3 @@ | LifeCycleEventType.BEFORE_UNLOAD | ||
subscribe(eventType: LifeCycleEventType.ERROR_COLLECTED, callback: (data: RawError) => void): Subscription | ||
subscribe( | ||
eventType: LifeCycleEventType.ERROR_PROVIDED, | ||
callback: (data: { error: ProvidedError; context?: Context }) => void | ||
): Subscription | ||
subscribe( | ||
eventType: LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, | ||
@@ -112,6 +98,2 @@ callback: (data: RumPerformanceEntry) => void | ||
): Subscription | ||
subscribe( | ||
eventType: LifeCycleEventType.CUSTOM_ACTION_COLLECTED, | ||
callback: (data: { action: CustomAction; context?: Context }) => void | ||
): Subscription | ||
subscribe(eventType: LifeCycleEventType.VIEW_CREATED, callback: (data: ViewCreatedEvent) => void): Subscription | ||
@@ -122,3 +104,2 @@ subscribe(eventType: LifeCycleEventType.VIEW_UPDATED, callback: (data: View) => void): Subscription | ||
| LifeCycleEventType.SESSION_RENEWED | ||
| LifeCycleEventType.RESOURCE_ADDED_TO_BATCH | ||
| LifeCycleEventType.DOM_MUTATED | ||
@@ -137,3 +118,3 @@ | LifeCycleEventType.BEFORE_UNLOAD | ||
}) => void | ||
): void | ||
): Subscription | ||
subscribe( | ||
@@ -147,11 +128,11 @@ eventType: LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, | ||
}) => void | ||
): void | ||
): Subscription | ||
subscribe( | ||
eventType: LifeCycleEventType.RUM_EVENT_COLLECTED, | ||
callback: (data: { rumEvent: RumEvent; serverRumEvent: Context }) => void | ||
): void | ||
): Subscription | ||
subscribe( | ||
eventType: LifeCycleEventType.RUM_EVENT_V2_COLLECTED, | ||
callback: (data: { rumEvent: RumEventV2; serverRumEvent: Context }) => void | ||
): void | ||
): Subscription | ||
subscribe(eventType: LifeCycleEventType, callback: (data?: any) => void) { | ||
@@ -158,0 +139,0 @@ if (!this.callbacks[eventType]) { |
@@ -6,2 +6,4 @@ import { setup, TestSetupBuilder } from '../../test/specHelper' | ||
CLEAR_OLD_CONTEXTS_INTERVAL, | ||
ParentContexts, | ||
startParentContexts, | ||
VIEW_CONTEXT_TIME_OUT_DELAY, | ||
@@ -27,2 +29,3 @@ } from './parentContexts' | ||
let setupBuilder: TestSetupBuilder | ||
let parentContexts: ParentContexts | ||
@@ -38,3 +41,6 @@ beforeEach(() => { | ||
}) | ||
.withParentContexts() | ||
.beforeBuild(({ lifeCycle, session }) => { | ||
parentContexts = startParentContexts(lifeCycle, session) | ||
return parentContexts | ||
}) | ||
}) | ||
@@ -48,3 +54,3 @@ | ||
it('should return undefined when there is no current view and no startTime', () => { | ||
const { parentContexts } = setupBuilder.build() | ||
setupBuilder.build() | ||
@@ -55,3 +61,3 @@ expect(parentContexts.findView()).toBeUndefined() | ||
it('should return the current view context when there is no start time', () => { | ||
const { lifeCycle, parentContexts } = setupBuilder.build() | ||
const { lifeCycle } = setupBuilder.build() | ||
@@ -65,3 +71,3 @@ lifeCycle.notify(LifeCycleEventType.VIEW_CREATED, buildViewCreatedEvent()) | ||
it('should return the view context corresponding to startTime', () => { | ||
const { lifeCycle, parentContexts } = setupBuilder.build() | ||
const { lifeCycle } = setupBuilder.build() | ||
@@ -78,3 +84,3 @@ lifeCycle.notify(LifeCycleEventType.VIEW_CREATED, buildViewCreatedEvent({ startTime: 10, id: 'view 1' })) | ||
it('should return undefined when no view context corresponding to startTime', () => { | ||
const { lifeCycle, parentContexts } = setupBuilder.build() | ||
const { lifeCycle } = setupBuilder.build() | ||
@@ -88,3 +94,3 @@ lifeCycle.notify(LifeCycleEventType.VIEW_CREATED, buildViewCreatedEvent({ startTime: 10, id: 'view 1' })) | ||
it('should replace the current view context on VIEW_CREATED', () => { | ||
const { lifeCycle, parentContexts } = setupBuilder.build() | ||
const { lifeCycle } = setupBuilder.build() | ||
@@ -99,3 +105,3 @@ lifeCycle.notify(LifeCycleEventType.VIEW_CREATED, buildViewCreatedEvent()) | ||
it('should return the current url with the current view', () => { | ||
const { lifeCycle, parentContexts, fakeLocation } = setupBuilder.build() | ||
const { lifeCycle, fakeLocation } = setupBuilder.build() | ||
@@ -111,3 +117,3 @@ lifeCycle.notify(LifeCycleEventType.VIEW_CREATED, buildViewCreatedEvent({ location: fakeLocation as Location })) | ||
it('should update session id only on VIEW_CREATED', () => { | ||
const { lifeCycle, parentContexts } = setupBuilder.build() | ||
const { lifeCycle } = setupBuilder.build() | ||
@@ -127,3 +133,3 @@ lifeCycle.notify(LifeCycleEventType.VIEW_CREATED, buildViewCreatedEvent()) | ||
it('should return undefined when there is no current action and no startTime', () => { | ||
const { parentContexts } = setupBuilder.build() | ||
setupBuilder.build() | ||
@@ -134,3 +140,3 @@ expect(parentContexts.findAction()).toBeUndefined() | ||
it('should return the current action context when no startTime', () => { | ||
const { lifeCycle, parentContexts } = setupBuilder.build() | ||
const { lifeCycle } = setupBuilder.build() | ||
@@ -144,3 +150,3 @@ lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_CREATED, { startTime, id: FAKE_ID }) | ||
it('should return the action context corresponding to startTime', () => { | ||
const { lifeCycle, parentContexts } = setupBuilder.build() | ||
const { lifeCycle } = setupBuilder.build() | ||
@@ -162,3 +168,3 @@ lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_CREATED, { startTime: 10, id: 'action 1' }) | ||
it('should return undefined if no action context corresponding to startTime', () => { | ||
const { lifeCycle, parentContexts } = setupBuilder.build() | ||
const { lifeCycle } = setupBuilder.build() | ||
@@ -174,3 +180,3 @@ lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_CREATED, { startTime: 10, id: 'action 1' }) | ||
it('should clear the current action on ACTION_DISCARDED', () => { | ||
const { lifeCycle, parentContexts } = setupBuilder.build() | ||
const { lifeCycle } = setupBuilder.build() | ||
@@ -184,3 +190,3 @@ lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_CREATED, { startTime, id: FAKE_ID }) | ||
it('should clear the current action on ACTION_COMPLETED', () => { | ||
const { lifeCycle, parentContexts } = setupBuilder.build() | ||
const { lifeCycle } = setupBuilder.build() | ||
@@ -196,3 +202,3 @@ lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_CREATED, { startTime, id: FAKE_ID }) | ||
it('should be cleared on SESSION_RENEWED', () => { | ||
const { lifeCycle, parentContexts } = setupBuilder.build() | ||
const { lifeCycle } = setupBuilder.build() | ||
@@ -231,3 +237,3 @@ lifeCycle.notify( | ||
it('should be cleared when too old', () => { | ||
const { lifeCycle, parentContexts, clock } = setupBuilder.withFakeClock().build() | ||
const { lifeCycle, clock } = setupBuilder.withFakeClock().build() | ||
@@ -234,0 +240,0 @@ const originalTime = performance.now() |
@@ -10,8 +10,12 @@ import { setup, TestSetupBuilder } from '../../../../test/specHelper' | ||
let setupBuilder: TestSetupBuilder | ||
let addAction: ReturnType<typeof startActionCollection>['addAction'] | ||
beforeEach(() => { | ||
setupBuilder = setup().beforeBuild((lifeCycle, configuration) => { | ||
configuration.isEnabled = () => false | ||
startActionCollection(lifeCycle, configuration) | ||
}) | ||
setupBuilder = setup() | ||
.withConfiguration({ | ||
isEnabled: () => false, | ||
}) | ||
.beforeBuild(({ lifeCycle, configuration }) => { | ||
;({ addAction } = startActionCollection(lifeCycle, configuration)) | ||
}) | ||
}) | ||
@@ -58,9 +62,7 @@ | ||
it('should create action from custom action', () => { | ||
const { lifeCycle, rawRumEvents } = setupBuilder.build() | ||
lifeCycle.notify(LifeCycleEventType.CUSTOM_ACTION_COLLECTED, { | ||
action: { | ||
name: 'foo', | ||
startTime: 1234, | ||
type: ActionType.CUSTOM, | ||
}, | ||
const { rawRumEvents } = setupBuilder.build() | ||
addAction({ | ||
name: 'foo', | ||
startTime: 1234, | ||
type: ActionType.CUSTOM, | ||
}) | ||
@@ -84,8 +86,12 @@ | ||
let setupBuilder: TestSetupBuilder | ||
let addAction: ReturnType<typeof startActionCollection>['addAction'] | ||
beforeEach(() => { | ||
setupBuilder = setup().beforeBuild((lifeCycle, configuration) => { | ||
configuration.isEnabled = () => true | ||
startActionCollection(lifeCycle, configuration) | ||
}) | ||
setupBuilder = setup() | ||
.withConfiguration({ | ||
isEnabled: () => true, | ||
}) | ||
.beforeBuild(({ lifeCycle, configuration }) => { | ||
;({ addAction } = startActionCollection(lifeCycle, configuration)) | ||
}) | ||
}) | ||
@@ -105,3 +111,3 @@ | ||
duration: 100, | ||
id: 'xxx', | ||
id: 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee', | ||
name: 'foo', | ||
@@ -118,3 +124,3 @@ startTime: 1234, | ||
}, | ||
id: 'xxx', | ||
id: 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee', | ||
loadingTime: 100 * 1e6, | ||
@@ -138,9 +144,7 @@ longTask: { | ||
it('should create action from custom action', () => { | ||
const { lifeCycle, rawRumEventsV2 } = setupBuilder.build() | ||
lifeCycle.notify(LifeCycleEventType.CUSTOM_ACTION_COLLECTED, { | ||
action: { | ||
name: 'foo', | ||
startTime: 1234, | ||
type: ActionType.CUSTOM, | ||
}, | ||
const { rawRumEventsV2 } = setupBuilder.build() | ||
addAction({ | ||
name: 'foo', | ||
startTime: 1234, | ||
type: ActionType.CUSTOM, | ||
}) | ||
@@ -147,0 +151,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { combine, Configuration, getTimestamp, msToNs } from '@datadog/browser-core' | ||
import { combine, Configuration, Context, getTimestamp, msToNs } from '@datadog/browser-core' | ||
import { RumEventCategory, RumUserActionEvent } from '../../../types' | ||
@@ -14,17 +14,19 @@ import { RumActionEventV2, RumEventType } from '../../../typesV2' | ||
lifeCycle.subscribe(LifeCycleEventType.CUSTOM_ACTION_COLLECTED, ({ action, context }) => { | ||
configuration.isEnabled('v2_format') | ||
? lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, { | ||
savedGlobalContext: context, | ||
...processActionV2(action), | ||
}) | ||
: lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, { | ||
savedGlobalContext: context, | ||
...processAction(action), | ||
}) | ||
}) | ||
if (configuration.trackInteractions) { | ||
trackActions(lifeCycle) | ||
} | ||
return { | ||
addAction(action: CustomAction, savedGlobalContext?: Context) { | ||
configuration.isEnabled('v2_format') | ||
? lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, { | ||
savedGlobalContext, | ||
...processActionV2(action), | ||
}) | ||
: lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, { | ||
savedGlobalContext, | ||
...processAction(action), | ||
}) | ||
}, | ||
} | ||
} | ||
@@ -31,0 +33,0 @@ |
@@ -1,6 +0,9 @@ | ||
import { DOM_EVENT, RawError } from '@datadog/browser-core' | ||
import { DOM_EVENT } from '@datadog/browser-core' | ||
import { createRawRumEvent } from '../../../../test/fixtures' | ||
import { setup, TestSetupBuilder } from '../../../../test/specHelper' | ||
import { RumErrorEvent, RumEventCategory } from '../../../types' | ||
import { RumEventType } from '../../../typesV2' | ||
import { LifeCycle, LifeCycleEventType } from '../../lifeCycle' | ||
import { PAGE_ACTIVITY_MAX_DURATION, PAGE_ACTIVITY_VALIDATION_DELAY } from '../../trackPageActivities' | ||
import { ActionType, AutoAction } from './trackActions' | ||
import { ActionType, AutoAction, trackActions } from './trackActions' | ||
@@ -60,7 +63,7 @@ // Used to wait some time after the creation of a action | ||
.withFakeClock() | ||
.withActionCollection() | ||
.beforeBuild((lifeCycle) => { | ||
.beforeBuild(({ lifeCycle }) => { | ||
lifeCycle.subscribe(LifeCycleEventType.AUTO_ACTION_CREATED, createSpy) | ||
lifeCycle.subscribe(LifeCycleEventType.AUTO_ACTION_COMPLETED, pushEvent) | ||
lifeCycle.subscribe(LifeCycleEventType.AUTO_ACTION_DISCARDED, discardSpy) | ||
return trackActions(lifeCycle) | ||
}) | ||
@@ -150,3 +153,5 @@ }) | ||
.withFakeClock() | ||
.withActionCollection() | ||
.beforeBuild(({ lifeCycle }) => { | ||
return trackActions(lifeCycle) | ||
}) | ||
}) | ||
@@ -177,3 +182,6 @@ | ||
const { lifeCycle, clock } = setupBuilder.build() | ||
const error = {} | ||
const collectedRawRumEvent = { | ||
rawRumEvent: ({ evt: { category: RumEventCategory.ERROR } } as unknown) as RumErrorEvent, | ||
startTime: 0, | ||
} | ||
lifeCycle.subscribe(LifeCycleEventType.AUTO_ACTION_COMPLETED, pushEvent) | ||
@@ -183,9 +191,9 @@ | ||
lifeCycle.notify(LifeCycleEventType.ERROR_COLLECTED, error as RawError) | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, collectedRawRumEvent) | ||
clock.tick(BEFORE_PAGE_ACTIVITY_VALIDATION_DELAY) | ||
lifeCycle.notify(LifeCycleEventType.DOM_MUTATED) | ||
lifeCycle.notify(LifeCycleEventType.ERROR_COLLECTED, error as RawError) | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, collectedRawRumEvent) | ||
clock.tick(EXPIRE_DELAY) | ||
lifeCycle.notify(LifeCycleEventType.ERROR_COLLECTED, error as RawError) | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, collectedRawRumEvent) | ||
@@ -200,2 +208,29 @@ expect(events.length).toBe(1) | ||
}) | ||
it('counts errors occurring during the action v2', () => { | ||
const { lifeCycle, clock } = setupBuilder.build() | ||
const collectedRawRumEvent = { | ||
rawRumEvent: createRawRumEvent(RumEventType.ERROR), | ||
startTime: 0, | ||
} | ||
lifeCycle.subscribe(LifeCycleEventType.AUTO_ACTION_COMPLETED, pushEvent) | ||
newClick('test-1') | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, collectedRawRumEvent) | ||
clock.tick(BEFORE_PAGE_ACTIVITY_VALIDATION_DELAY) | ||
lifeCycle.notify(LifeCycleEventType.DOM_MUTATED) | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, collectedRawRumEvent) | ||
clock.tick(EXPIRE_DELAY) | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, collectedRawRumEvent) | ||
expect(events.length).toBe(1) | ||
const action = events[0] as AutoAction | ||
expect(action.counts).toEqual({ | ||
errorCount: 2, | ||
longTaskCount: 0, | ||
resourceCount: 0, | ||
}) | ||
}) | ||
}) |
@@ -0,15 +1,20 @@ | ||
import { Observable, RawError } from '@datadog/browser-core' | ||
import { setup, TestSetupBuilder } from '../../../../test/specHelper' | ||
import { ErrorSource, RumEventCategory } from '../../../index' | ||
import { RumEventType } from '../../../typesV2' | ||
import { LifeCycleEventType } from '../../lifeCycle' | ||
import { startErrorCollection } from './errorCollection' | ||
import { doStartErrorCollection } from './errorCollection' | ||
describe('error collection', () => { | ||
let setupBuilder: TestSetupBuilder | ||
const errorObservable = new Observable<RawError>() | ||
let addError: ReturnType<typeof doStartErrorCollection>['addError'] | ||
beforeEach(() => { | ||
setupBuilder = setup().beforeBuild((lifeCycle, configuration) => { | ||
configuration.isEnabled = () => false | ||
startErrorCollection(lifeCycle, configuration) | ||
}) | ||
setupBuilder = setup() | ||
.withConfiguration({ | ||
isEnabled: () => false, | ||
}) | ||
.beforeBuild(({ lifeCycle, configuration }) => { | ||
;({ addError } = doStartErrorCollection(lifeCycle, configuration, errorObservable)) | ||
}) | ||
}) | ||
@@ -23,9 +28,7 @@ | ||
it('notifies a raw rum error event', () => { | ||
const { lifeCycle, rawRumEvents } = setupBuilder.build() | ||
lifeCycle.notify(LifeCycleEventType.ERROR_PROVIDED, { | ||
error: { | ||
error: new Error('foo'), | ||
source: ErrorSource.CUSTOM, | ||
startTime: 12, | ||
}, | ||
const { rawRumEvents } = setupBuilder.build() | ||
addError({ | ||
error: new Error('foo'), | ||
source: ErrorSource.CUSTOM, | ||
startTime: 12, | ||
}) | ||
@@ -54,10 +57,8 @@ | ||
it('should save the specified customer context', () => { | ||
const { lifeCycle, rawRumEvents } = setupBuilder.build() | ||
lifeCycle.notify(LifeCycleEventType.ERROR_PROVIDED, { | ||
error: { | ||
context: { foo: 'bar' }, | ||
error: new Error('foo'), | ||
source: ErrorSource.CUSTOM, | ||
startTime: 12, | ||
}, | ||
const { rawRumEvents } = setupBuilder.build() | ||
addError({ | ||
context: { foo: 'bar' }, | ||
error: new Error('foo'), | ||
source: ErrorSource.CUSTOM, | ||
startTime: 12, | ||
}) | ||
@@ -70,6 +71,5 @@ expect(rawRumEvents[0].customerContext).toEqual({ | ||
it('should save the global context', () => { | ||
const { lifeCycle, rawRumEvents } = setupBuilder.build() | ||
lifeCycle.notify(LifeCycleEventType.ERROR_PROVIDED, { | ||
context: { foo: 'bar' }, | ||
error: { | ||
const { rawRumEvents } = setupBuilder.build() | ||
addError( | ||
{ | ||
error: new Error('foo'), | ||
@@ -79,3 +79,4 @@ source: ErrorSource.CUSTOM, | ||
}, | ||
}) | ||
{ foo: 'bar' } | ||
) | ||
expect(rawRumEvents[0].savedGlobalContext).toEqual({ | ||
@@ -89,4 +90,4 @@ foo: 'bar', | ||
it('should create error event from collected error', () => { | ||
const { lifeCycle, rawRumEvents } = setupBuilder.build() | ||
lifeCycle.notify(LifeCycleEventType.ERROR_COLLECTED, { | ||
const { rawRumEvents } = setupBuilder.build() | ||
errorObservable.notify({ | ||
message: 'hello', | ||
@@ -128,8 +129,13 @@ resource: { | ||
let setupBuilder: TestSetupBuilder | ||
const errorObservable = new Observable<RawError>() | ||
let addError: ReturnType<typeof doStartErrorCollection>['addError'] | ||
beforeEach(() => { | ||
setupBuilder = setup().beforeBuild((lifeCycle, configuration) => { | ||
configuration.isEnabled = () => true | ||
startErrorCollection(lifeCycle, configuration) | ||
}) | ||
setupBuilder = setup() | ||
.withConfiguration({ | ||
isEnabled: () => true, | ||
}) | ||
.beforeBuild(({ lifeCycle, configuration }) => { | ||
;({ addError } = doStartErrorCollection(lifeCycle, configuration, errorObservable)) | ||
}) | ||
}) | ||
@@ -143,9 +149,7 @@ | ||
it('notifies a raw rum error event', () => { | ||
const { lifeCycle, rawRumEventsV2 } = setupBuilder.build() | ||
lifeCycle.notify(LifeCycleEventType.ERROR_PROVIDED, { | ||
error: { | ||
error: new Error('foo'), | ||
source: ErrorSource.CUSTOM, | ||
startTime: 12, | ||
}, | ||
const { rawRumEventsV2 } = setupBuilder.build() | ||
addError({ | ||
error: new Error('foo'), | ||
source: ErrorSource.CUSTOM, | ||
startTime: 12, | ||
}) | ||
@@ -173,10 +177,8 @@ | ||
it('should save the specified customer context', () => { | ||
const { lifeCycle, rawRumEventsV2 } = setupBuilder.build() | ||
lifeCycle.notify(LifeCycleEventType.ERROR_PROVIDED, { | ||
error: { | ||
context: { foo: 'bar' }, | ||
error: new Error('foo'), | ||
source: ErrorSource.CUSTOM, | ||
startTime: 12, | ||
}, | ||
const { rawRumEventsV2 } = setupBuilder.build() | ||
addError({ | ||
context: { foo: 'bar' }, | ||
error: new Error('foo'), | ||
source: ErrorSource.CUSTOM, | ||
startTime: 12, | ||
}) | ||
@@ -189,6 +191,5 @@ expect(rawRumEventsV2[0].customerContext).toEqual({ | ||
it('should save the global context', () => { | ||
const { lifeCycle, rawRumEventsV2 } = setupBuilder.build() | ||
lifeCycle.notify(LifeCycleEventType.ERROR_PROVIDED, { | ||
context: { foo: 'bar' }, | ||
error: { | ||
const { rawRumEventsV2 } = setupBuilder.build() | ||
addError( | ||
{ | ||
error: new Error('foo'), | ||
@@ -198,3 +199,4 @@ source: ErrorSource.CUSTOM, | ||
}, | ||
}) | ||
{ foo: 'bar' } | ||
) | ||
expect(rawRumEventsV2[0].savedGlobalContext).toEqual({ | ||
@@ -208,4 +210,4 @@ foo: 'bar', | ||
it('should create error event from collected error', () => { | ||
const { lifeCycle, rawRumEventsV2 } = setupBuilder.build() | ||
lifeCycle.notify(LifeCycleEventType.ERROR_COLLECTED, { | ||
const { rawRumEventsV2 } = setupBuilder.build() | ||
errorObservable.notify({ | ||
message: 'hello', | ||
@@ -212,0 +214,0 @@ resource: { |
@@ -9,3 +9,5 @@ import { | ||
getTimestamp, | ||
Observable, | ||
RawError, | ||
startAutomaticErrorCollection, | ||
} from '@datadog/browser-core' | ||
@@ -24,5 +26,18 @@ import { RumErrorEvent, RumEventCategory } from '../../../types' | ||
export function startErrorCollection(lifeCycle: LifeCycle, configuration: Configuration) { | ||
lifeCycle.subscribe( | ||
LifeCycleEventType.ERROR_PROVIDED, | ||
({ error: { error, startTime, context: customerContext, source }, context: savedGlobalContext }) => { | ||
return doStartErrorCollection(lifeCycle, configuration, startAutomaticErrorCollection(configuration)) | ||
} | ||
export function doStartErrorCollection( | ||
lifeCycle: LifeCycle, | ||
configuration: Configuration, | ||
observable: Observable<RawError> | ||
) { | ||
observable.subscribe((error) => { | ||
configuration.isEnabled('v2_format') | ||
? lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, processErrorV2(error)) | ||
: lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, processError(error)) | ||
}) | ||
return { | ||
addError({ error, startTime, context: customerContext, source }: ProvidedError, savedGlobalContext?: Context) { | ||
const rawError = computeRawError(error, startTime, source) | ||
@@ -41,9 +56,4 @@ | ||
}) | ||
} | ||
) | ||
lifeCycle.subscribe(LifeCycleEventType.ERROR_COLLECTED, (error: RawError) => { | ||
configuration.isEnabled('v2_format') | ||
? lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, processErrorV2(error)) | ||
: lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, processError(error)) | ||
}) | ||
}, | ||
} | ||
} | ||
@@ -50,0 +60,0 @@ |
@@ -12,8 +12,15 @@ import { setup, TestSetupBuilder } from '../../../../test/specHelper' | ||
beforeEach(() => { | ||
setupBuilder = setup().beforeBuild((lifeCycle, configuration) => { | ||
configuration.isEnabled = () => false | ||
startLongTaskCollection(lifeCycle, configuration) | ||
}) | ||
setupBuilder = setup() | ||
.withConfiguration({ | ||
isEnabled: () => false, | ||
}) | ||
.beforeBuild(({ lifeCycle, configuration }) => { | ||
startLongTaskCollection(lifeCycle, configuration) | ||
}) | ||
}) | ||
afterEach(() => { | ||
setupBuilder.cleanup() | ||
}) | ||
it('should only listen to long task performance entry', () => { | ||
@@ -55,8 +62,15 @@ const { lifeCycle, rawRumEvents } = setupBuilder.build() | ||
beforeEach(() => { | ||
setupBuilder = setup().beforeBuild((lifeCycle, configuration) => { | ||
configuration.isEnabled = () => true | ||
startLongTaskCollection(lifeCycle, configuration) | ||
}) | ||
setupBuilder = setup() | ||
.withConfiguration({ | ||
isEnabled: () => true, | ||
}) | ||
.beforeBuild(({ lifeCycle, configuration }) => { | ||
startLongTaskCollection(lifeCycle, configuration) | ||
}) | ||
}) | ||
afterEach(() => { | ||
setupBuilder.cleanup() | ||
}) | ||
it('should only listen to long task performance entry', () => { | ||
@@ -63,0 +77,0 @@ const { lifeCycle, rawRumEventsV2 } = setupBuilder.build() |
import { isIE } from '@datadog/browser-core' | ||
import { createResourceEntry } from '../../../../test/fixtures' | ||
import { RumPerformanceResourceTiming } from '../../../browser/performanceCollection' | ||
@@ -20,13 +21,13 @@ import { RequestCompleteEvent } from '../../requestCollection' | ||
it('should match single timing nested in the request ', () => { | ||
const match: Partial<RumPerformanceResourceTiming> = { startTime: 200, duration: 300 } | ||
entries.push(match as RumPerformanceResourceTiming) | ||
const match = createResourceEntry({ startTime: 200, duration: 300 }) | ||
entries.push(match) | ||
const timing = matchRequestTiming(FAKE_REQUEST as RequestCompleteEvent) | ||
expect(timing).toEqual(match as RumPerformanceResourceTiming) | ||
expect(timing).toEqual(match) | ||
}) | ||
it('should not match single timing outside the request ', () => { | ||
const match: Partial<RumPerformanceResourceTiming> = { startTime: 0, duration: 300 } | ||
entries.push(match as RumPerformanceResourceTiming) | ||
const match = createResourceEntry({ startTime: 0, duration: 300 }) | ||
entries.push(match) | ||
@@ -39,15 +40,15 @@ const timing = matchRequestTiming(FAKE_REQUEST as RequestCompleteEvent) | ||
it('should match two following timings nested in the request ', () => { | ||
const optionsTiming: Partial<RumPerformanceResourceTiming> = { startTime: 200, duration: 50 } | ||
const actualTiming: Partial<RumPerformanceResourceTiming> = { startTime: 300, duration: 100 } | ||
entries.push(optionsTiming as RumPerformanceResourceTiming, actualTiming as RumPerformanceResourceTiming) | ||
const optionsTiming = createResourceEntry({ startTime: 150, duration: 50 }) | ||
const actualTiming = createResourceEntry({ startTime: 200, duration: 100 }) | ||
entries.push(optionsTiming, actualTiming) | ||
const timing = matchRequestTiming(FAKE_REQUEST as RequestCompleteEvent) | ||
expect(timing).toEqual(actualTiming as RumPerformanceResourceTiming) | ||
expect(timing).toEqual(actualTiming) | ||
}) | ||
it('should not match two not following timings nested in the request ', () => { | ||
const match1: Partial<RumPerformanceResourceTiming> = { startTime: 200, duration: 100 } | ||
const match2: Partial<RumPerformanceResourceTiming> = { startTime: 250, duration: 100 } | ||
entries.push(match1 as RumPerformanceResourceTiming, match2 as RumPerformanceResourceTiming) | ||
const match1 = createResourceEntry({ startTime: 150, duration: 100 }) | ||
const match2 = createResourceEntry({ startTime: 200, duration: 100 }) | ||
entries.push(match1, match2) | ||
@@ -60,10 +61,6 @@ const timing = matchRequestTiming(FAKE_REQUEST as RequestCompleteEvent) | ||
it('should not match multiple timings nested in the request', () => { | ||
const match1: Partial<RumPerformanceResourceTiming> = { startTime: 100, duration: 100 } | ||
const match2: Partial<RumPerformanceResourceTiming> = { startTime: 200, duration: 100 } | ||
const match3: Partial<RumPerformanceResourceTiming> = { startTime: 300, duration: 100 } | ||
entries.push( | ||
match1 as RumPerformanceResourceTiming, | ||
match2 as RumPerformanceResourceTiming, | ||
match3 as RumPerformanceResourceTiming | ||
) | ||
const match1 = createResourceEntry({ startTime: 100, duration: 50 }) | ||
const match2 = createResourceEntry({ startTime: 150, duration: 50 }) | ||
const match3 = createResourceEntry({ startTime: 200, duration: 50 }) | ||
entries.push(match1, match2, match3) | ||
@@ -74,2 +71,15 @@ const timing = matchRequestTiming(FAKE_REQUEST as RequestCompleteEvent) | ||
}) | ||
it('should match invalid timing nested in the request ', () => { | ||
const match = createResourceEntry({ | ||
duration: 100, | ||
fetchStart: 0, | ||
startTime: 200, | ||
}) | ||
entries.push(match) | ||
const timing = matchRequestTiming(FAKE_REQUEST as RequestCompleteEvent) | ||
expect(timing).toEqual(undefined) | ||
}) | ||
}) |
import { RumPerformanceResourceTiming } from '../../../browser/performanceCollection' | ||
import { RequestCompleteEvent } from '../../requestCollection' | ||
import { toValidEntry } from './resourceUtils' | ||
@@ -17,2 +18,3 @@ interface Timing { | ||
* Strategy: | ||
* - from valid nested entries | ||
* - if a single timing match, return the timing | ||
@@ -26,7 +28,7 @@ * - if two following timings match (OPTIONS request), return the timing for the actual request | ||
} | ||
const candidates = (performance | ||
const candidates = performance | ||
.getEntriesByName(request.url, 'resource') | ||
.filter((entry) => | ||
isBetween(entry, request.startTime, endTime(request)) | ||
) as unknown) as RumPerformanceResourceTiming[] | ||
.map((entry) => entry.toJSON() as RumPerformanceResourceTiming) | ||
.filter(toValidEntry) | ||
.filter((entry) => isBetween(entry, request.startTime, endTime(request))) | ||
@@ -33,0 +35,0 @@ if (candidates.length === 1) { |
import { RequestType, ResourceType } from '@datadog/browser-core' | ||
import { createResourceEntry } from '../../../../test/fixtures' | ||
import { setup, TestSetupBuilder } from '../../../../test/specHelper' | ||
import { RumPerformanceResourceTiming } from '../../../browser/performanceCollection' | ||
import { RumEventCategory, RumResourceEvent } from '../../../types' | ||
@@ -23,4 +23,6 @@ import { RumEventType, RumResourceEventV2 } from '../../../typesV2' | ||
}) | ||
.beforeBuild((lifeCycle, configuration, session: RumSession) => { | ||
configuration.isEnabled = () => false | ||
.withConfiguration({ | ||
isEnabled: () => false, | ||
}) | ||
.beforeBuild(({ lifeCycle, configuration, session }) => { | ||
startResourceCollection(lifeCycle, configuration, session) | ||
@@ -53,3 +55,3 @@ }) | ||
http: { | ||
performance: jasmine.anything() as any, | ||
performance: undefined, | ||
url: 'https://resource.com/valid', | ||
@@ -107,4 +109,6 @@ }, | ||
}) | ||
.beforeBuild((lifeCycle, configuration, session: RumSession) => { | ||
configuration.isEnabled = () => false | ||
.withConfiguration({ | ||
isEnabled: () => false, | ||
}) | ||
.beforeBuild(({ lifeCycle, configuration, session }) => { | ||
startResourceCollection(lifeCycle, configuration, session) | ||
@@ -143,4 +147,6 @@ }) | ||
}) | ||
.beforeBuild((lifeCycle, configuration, session: RumSession) => { | ||
configuration.isEnabled = () => false | ||
.withConfiguration({ | ||
isEnabled: () => false, | ||
}) | ||
.beforeBuild(({ lifeCycle, configuration, session }) => { | ||
startResourceCollection(lifeCycle, configuration, session) | ||
@@ -187,6 +193,9 @@ }) | ||
beforeEach(() => { | ||
setupBuilder = setup().beforeBuild((lifeCycle, configuration, session: RumSession) => { | ||
configuration.isEnabled = () => false | ||
startResourceCollection(lifeCycle, configuration, session) | ||
}) | ||
setupBuilder = setup() | ||
.withConfiguration({ | ||
isEnabled: () => false, | ||
}) | ||
.beforeBuild(({ lifeCycle, configuration, session }) => { | ||
startResourceCollection(lifeCycle, configuration, session) | ||
}) | ||
}) | ||
@@ -241,4 +250,6 @@ | ||
}) | ||
.beforeBuild((lifeCycle, configuration, session: RumSession) => { | ||
configuration.isEnabled = () => true | ||
.withConfiguration({ | ||
isEnabled: () => true, | ||
}) | ||
.beforeBuild(({ lifeCycle, configuration, session }) => { | ||
startResourceCollection(lifeCycle, configuration, session) | ||
@@ -267,6 +278,3 @@ }) | ||
resource: { | ||
download: jasmine.anything(), | ||
duration: 100 * 1e6, | ||
firstByte: jasmine.anything(), | ||
redirect: jasmine.anything(), | ||
size: undefined, | ||
@@ -317,4 +325,6 @@ type: ResourceType.OTHER, | ||
}) | ||
.beforeBuild((lifeCycle, configuration, session: RumSession) => { | ||
configuration.isEnabled = () => true | ||
.withConfiguration({ | ||
isEnabled: () => true, | ||
}) | ||
.beforeBuild(({ lifeCycle, configuration, session }) => { | ||
startResourceCollection(lifeCycle, configuration, session) | ||
@@ -353,4 +363,6 @@ }) | ||
}) | ||
.beforeBuild((lifeCycle, configuration, session: RumSession) => { | ||
configuration.isEnabled = () => true | ||
.withConfiguration({ | ||
isEnabled: () => true, | ||
}) | ||
.beforeBuild(({ lifeCycle, configuration, session }) => { | ||
startResourceCollection(lifeCycle, configuration, session) | ||
@@ -397,6 +409,9 @@ }) | ||
beforeEach(() => { | ||
setupBuilder = setup().beforeBuild((lifeCycle, configuration, session: RumSession) => { | ||
configuration.isEnabled = () => true | ||
startResourceCollection(lifeCycle, configuration, session) | ||
}) | ||
setupBuilder = setup() | ||
.withConfiguration({ | ||
isEnabled: () => true, | ||
}) | ||
.beforeBuild(({ lifeCycle, configuration, session }) => { | ||
startResourceCollection(lifeCycle, configuration, session) | ||
}) | ||
}) | ||
@@ -413,3 +428,3 @@ | ||
createResourceEntry({ | ||
traceId: 'xxx', | ||
traceId: '1234', | ||
}) | ||
@@ -420,3 +435,3 @@ ) | ||
expect(traceInfo).toBeDefined() | ||
expect(traceInfo.traceId).toBe('xxx') | ||
expect(traceInfo.traceId).toBe('1234') | ||
}) | ||
@@ -442,13 +457,2 @@ | ||
function createResourceEntry(details?: Partial<RumPerformanceResourceTiming>): RumPerformanceResourceTiming { | ||
const entry: Partial<RumPerformanceResourceTiming> = { | ||
duration: 100, | ||
entryType: 'resource', | ||
name: 'https://resource.com/valid', | ||
startTime: 1234, | ||
...details, | ||
} | ||
return entry as RumPerformanceResourceTiming | ||
} | ||
function createCompletedRequest(details?: Partial<RequestCompleteEvent>): RequestCompleteEvent { | ||
@@ -455,0 +459,0 @@ const request: Partial<RequestCompleteEvent> = { |
@@ -31,3 +31,2 @@ import { | ||
: lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, processRequest(request)) | ||
lifeCycle.notify(LifeCycleEventType.RESOURCE_ADDED_TO_BATCH) | ||
} | ||
@@ -41,3 +40,2 @@ }) | ||
: lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, processResourceEntry(entry)) | ||
lifeCycle.notify(LifeCycleEventType.RESOURCE_ADDED_TO_BATCH) | ||
} | ||
@@ -44,0 +42,0 @@ }) |
@@ -92,5 +92,12 @@ import { | ||
): PerformanceResourceDetails | undefined { | ||
const validEntry = toValidEntry(entry) | ||
if (!validEntry) { | ||
return undefined | ||
} | ||
const { | ||
startTime, | ||
fetchStart, | ||
redirectStart, | ||
redirectEnd, | ||
domainLookupStart, | ||
@@ -104,44 +111,4 @@ domainLookupEnd, | ||
responseEnd, | ||
} = entry | ||
let { redirectStart, redirectEnd } = entry | ||
} = validEntry | ||
// Ensure timings are in the right order. On top of filtering out potential invalid | ||
// RumPerformanceResourceTiming, it will ignore entries from requests where timings cannot be | ||
// collected, for example cross origin requests without a "Timing-Allow-Origin" header allowing | ||
// it. | ||
if ( | ||
!areInOrder( | ||
startTime, | ||
fetchStart, | ||
domainLookupStart, | ||
domainLookupEnd, | ||
connectStart, | ||
connectEnd, | ||
requestStart, | ||
responseStart, | ||
responseEnd | ||
) | ||
) { | ||
return undefined | ||
} | ||
// The only time fetchStart is different than startTime is if a redirection occurred. | ||
const hasRedirectionOccurred = fetchStart !== startTime | ||
if (hasRedirectionOccurred) { | ||
// Firefox doesn't provide redirect timings on cross origin requests. Provide a default for | ||
// those. | ||
if (redirectStart < startTime) { | ||
redirectStart = startTime | ||
} | ||
if (redirectEnd < startTime) { | ||
redirectEnd = fetchStart | ||
} | ||
// Make sure redirect timings are in order | ||
if (!areInOrder(startTime, redirectStart, redirectEnd, fetchStart)) { | ||
return undefined | ||
} | ||
} | ||
const details: PerformanceResourceDetails = { | ||
@@ -167,3 +134,3 @@ download: formatTiming(startTime, responseStart, responseEnd), | ||
if (hasRedirectionOccurred) { | ||
if (hasRedirection(entry)) { | ||
details.redirect = formatTiming(startTime, redirectStart, redirectEnd) | ||
@@ -175,2 +142,54 @@ } | ||
export function toValidEntry(entry: RumPerformanceResourceTiming) { | ||
// Ensure timings are in the right order. On top of filtering out potential invalid | ||
// RumPerformanceResourceTiming, it will ignore entries from requests where timings cannot be | ||
// collected, for example cross origin requests without a "Timing-Allow-Origin" header allowing | ||
// it. | ||
if ( | ||
!areInOrder( | ||
entry.startTime, | ||
entry.fetchStart, | ||
entry.domainLookupStart, | ||
entry.domainLookupEnd, | ||
entry.connectStart, | ||
entry.connectEnd, | ||
entry.requestStart, | ||
entry.responseStart, | ||
entry.responseEnd | ||
) | ||
) { | ||
return undefined | ||
} | ||
if (!hasRedirection(entry)) { | ||
return entry | ||
} | ||
let { redirectStart, redirectEnd } = entry | ||
// Firefox doesn't provide redirect timings on cross origin requests. | ||
// Provide a default for those. | ||
if (redirectStart < entry.startTime) { | ||
redirectStart = entry.startTime | ||
} | ||
if (redirectEnd < entry.startTime) { | ||
redirectEnd = entry.fetchStart | ||
} | ||
// Make sure redirect timings are in order | ||
if (!areInOrder(entry.startTime, redirectStart, redirectEnd, entry.fetchStart)) { | ||
return undefined | ||
} | ||
return { | ||
...entry, | ||
redirectEnd, | ||
redirectStart, | ||
} | ||
} | ||
function hasRedirection(entry: RumPerformanceResourceTiming) { | ||
// The only time fetchStart is different than startTime is if a redirection occurred. | ||
return entry.fetchStart !== entry.startTime | ||
} | ||
function formatTiming(origin: number, start: number, end: number) { | ||
@@ -177,0 +196,0 @@ return { |
@@ -0,9 +1,8 @@ | ||
import { createRawRumEvent } from '../../../../test/fixtures' | ||
import { setup, TestSetupBuilder } from '../../../../test/specHelper' | ||
import { | ||
RumPerformanceLongTaskTiming, | ||
RumPerformanceNavigationTiming, | ||
RumPerformancePaintTiming, | ||
} from '../../../browser/performanceCollection' | ||
import { RumPerformanceNavigationTiming, RumPerformancePaintTiming } from '../../../browser/performanceCollection' | ||
import { RawRumEvent, RumEventCategory } from '../../../types' | ||
import { RumEventType } from '../../../typesV2' | ||
import { LifeCycleEventType } from '../../lifeCycle' | ||
import { | ||
@@ -14,4 +13,3 @@ PAGE_ACTIVITY_END_DELAY, | ||
} from '../../trackPageActivities' | ||
import { ActionType, AutoAction, CustomAction } from '../action/trackActions' | ||
import { THROTTLE_VIEW_UPDATE_PERIOD, View, ViewCreatedEvent, ViewLoadingType } from './trackViews' | ||
import { THROTTLE_VIEW_UPDATE_PERIOD, trackViews, View, ViewCreatedEvent, ViewLoadingType } from './trackViews' | ||
@@ -22,19 +20,2 @@ const AFTER_PAGE_ACTIVITY_MAX_DURATION = PAGE_ACTIVITY_MAX_DURATION * 1.1 | ||
const FAKE_LONG_TASK: RumPerformanceLongTaskTiming = { | ||
duration: 123, | ||
entryType: 'longtask', | ||
startTime: 456, | ||
} | ||
const FAKE_CUSTOM_USER_ACTION: CustomAction = { | ||
context: { | ||
bar: 123, | ||
}, | ||
name: 'foo', | ||
startTime: 123, | ||
type: ActionType.CUSTOM, | ||
} | ||
const FAKE_AUTO_USER_ACTION: Partial<AutoAction> = { | ||
name: 'foo', | ||
type: ActionType.CLICK, | ||
} | ||
const FAKE_PAINT_ENTRY: RumPerformancePaintTiming = { | ||
@@ -95,7 +76,5 @@ entryType: 'paint', | ||
beforeEach(() => { | ||
const fakeLocation: Partial<Location> = { pathname: '/foo', hash: '' } | ||
setupBuilder = setup() | ||
.withFakeLocation('/foo') | ||
.withViewCollection() | ||
.beforeBuild((lifeCycle) => { | ||
.beforeBuild(({ location, lifeCycle }) => { | ||
const subscription = lifeCycle.subscribe(LifeCycleEventType.VIEW_CREATED, ({ id }) => { | ||
@@ -105,2 +84,3 @@ initialViewId = id | ||
}) | ||
return trackViews(location, lifeCycle) | ||
}) | ||
@@ -238,4 +218,3 @@ createSpy = jasmine.createSpy('create') | ||
.withFakeLocation('/foo') | ||
.withViewCollection() | ||
.beforeBuild((lifeCycle) => { | ||
.beforeBuild(({ location, lifeCycle }) => { | ||
const subscription = lifeCycle.subscribe(LifeCycleEventType.VIEW_CREATED, (event) => { | ||
@@ -245,2 +224,3 @@ initialViewCreatedEvent = event | ||
}) | ||
return trackViews(location, lifeCycle) | ||
}) | ||
@@ -306,4 +286,3 @@ createSpy = jasmine.createSpy('create') | ||
.withFakeLocation('/foo') | ||
.withViewCollection() | ||
.beforeBuild((lifeCycle) => { | ||
.beforeBuild(({ lifeCycle, location }) => { | ||
lifeCycle.subscribe(LifeCycleEventType.VIEW_UPDATED, handler) | ||
@@ -314,2 +293,3 @@ const subscription = lifeCycle.subscribe(LifeCycleEventType.VIEW_CREATED, ({ id }) => { | ||
}) | ||
return trackViews(location, lifeCycle) | ||
}) | ||
@@ -344,3 +324,3 @@ }) | ||
describe('rum track load duration', () => { | ||
describe('rum track loading type', () => { | ||
let setupBuilder: TestSetupBuilder | ||
@@ -356,4 +336,6 @@ let handler: jasmine.Spy | ||
.withFakeLocation('/foo') | ||
.withViewCollection() | ||
.beforeBuild((lifeCycle) => lifeCycle.subscribe(LifeCycleEventType.VIEW_UPDATED, handler)) | ||
.beforeBuild(({ location, lifeCycle }) => { | ||
lifeCycle.subscribe(LifeCycleEventType.VIEW_UPDATED, handler) | ||
return trackViews(location, lifeCycle) | ||
}) | ||
}) | ||
@@ -393,4 +375,6 @@ | ||
.withFakeLocation('/foo') | ||
.withViewCollection() | ||
.beforeBuild((lifeCycle) => lifeCycle.subscribe(LifeCycleEventType.VIEW_UPDATED, handler)) | ||
.beforeBuild(({ location, lifeCycle }) => { | ||
lifeCycle.subscribe(LifeCycleEventType.VIEW_UPDATED, handler) | ||
return trackViews(location, lifeCycle) | ||
}) | ||
}) | ||
@@ -485,4 +469,6 @@ | ||
.withFakeLocation('/foo') | ||
.withViewCollection() | ||
.beforeBuild((lifeCycle) => lifeCycle.subscribe(LifeCycleEventType.VIEW_UPDATED, handler)) | ||
.beforeBuild(({ location, lifeCycle }) => { | ||
lifeCycle.subscribe(LifeCycleEventType.VIEW_UPDATED, handler) | ||
return trackViews(location, lifeCycle) | ||
}) | ||
}) | ||
@@ -494,235 +480,411 @@ | ||
it('should track error count', () => { | ||
const { lifeCycle } = setupBuilder.build() | ||
expect(getHandledCount()).toEqual(1) | ||
expect(getViewEvent(0).eventCounts.errorCount).toEqual(0) | ||
describe('timings', () => { | ||
it('should update timings when notified with a PERFORMANCE_ENTRY_COLLECTED event (throttled)', () => { | ||
const { lifeCycle, clock } = setupBuilder.withFakeClock().build() | ||
expect(getHandledCount()).toEqual(1) | ||
expect(getViewEvent(0).timings).toEqual({}) | ||
lifeCycle.notify(LifeCycleEventType.ERROR_COLLECTED, {} as any) | ||
lifeCycle.notify(LifeCycleEventType.ERROR_COLLECTED, {} as any) | ||
history.pushState({}, '', '/bar') | ||
lifeCycle.notify(LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, FAKE_NAVIGATION_ENTRY) | ||
expect(getHandledCount()).toEqual(3) | ||
expect(getViewEvent(1).eventCounts.errorCount).toEqual(2) | ||
expect(getViewEvent(2).eventCounts.errorCount).toEqual(0) | ||
}) | ||
expect(getHandledCount()).toEqual(1) | ||
it('should track long task count', () => { | ||
const { lifeCycle } = setupBuilder.build() | ||
expect(getHandledCount()).toEqual(1) | ||
expect(getViewEvent(0).eventCounts.longTaskCount).toEqual(0) | ||
clock.tick(THROTTLE_VIEW_UPDATE_PERIOD) | ||
lifeCycle.notify(LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, FAKE_LONG_TASK) | ||
history.pushState({}, '', '/bar') | ||
expect(getHandledCount()).toEqual(2) | ||
expect(getViewEvent(1).timings).toEqual({ | ||
domComplete: 456, | ||
domContentLoaded: 345, | ||
domInteractive: 234, | ||
loadEventEnd: 567, | ||
}) | ||
}) | ||
expect(getHandledCount()).toEqual(3) | ||
expect(getViewEvent(1).eventCounts.longTaskCount).toEqual(1) | ||
expect(getViewEvent(2).eventCounts.longTaskCount).toEqual(0) | ||
}) | ||
it('should update timings when ending a view', () => { | ||
const { lifeCycle } = setupBuilder.build() | ||
expect(getHandledCount()).toEqual(1) | ||
expect(getViewEvent(0).timings).toEqual({}) | ||
it('should track resource count', () => { | ||
const { lifeCycle } = setupBuilder.build() | ||
expect(getHandledCount()).toEqual(1) | ||
expect(getViewEvent(0).eventCounts.resourceCount).toEqual(0) | ||
lifeCycle.notify(LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, FAKE_PAINT_ENTRY) | ||
lifeCycle.notify(LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, FAKE_NAVIGATION_ENTRY) | ||
expect(getHandledCount()).toEqual(1) | ||
lifeCycle.notify(LifeCycleEventType.RESOURCE_ADDED_TO_BATCH) | ||
history.pushState({}, '', '/bar') | ||
history.pushState({}, '', '/bar') | ||
expect(getHandledCount()).toEqual(3) | ||
expect(getViewEvent(1).eventCounts.resourceCount).toEqual(1) | ||
expect(getViewEvent(2).eventCounts.resourceCount).toEqual(0) | ||
}) | ||
expect(getHandledCount()).toEqual(3) | ||
expect(getViewEvent(1).timings).toEqual({ | ||
domComplete: 456, | ||
domContentLoaded: 345, | ||
domInteractive: 234, | ||
firstContentfulPaint: 123, | ||
loadEventEnd: 567, | ||
}) | ||
expect(getViewEvent(2).timings).toEqual({}) | ||
}) | ||
it('should track action count', () => { | ||
const { lifeCycle } = setupBuilder.build() | ||
expect(getHandledCount()).toEqual(1) | ||
expect(getViewEvent(0).eventCounts.userActionCount).toEqual(0) | ||
describe('load event happening after initial view end', () => { | ||
let initialView: { init: View; end: View; last: View } | ||
let secondView: { init: View; last: View } | ||
const VIEW_DURATION = 100 | ||
lifeCycle.notify(LifeCycleEventType.CUSTOM_ACTION_COLLECTED, { action: FAKE_CUSTOM_USER_ACTION, context: {} }) | ||
lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_COMPLETED, FAKE_AUTO_USER_ACTION as AutoAction) | ||
history.pushState({}, '', '/bar') | ||
beforeEach(() => { | ||
const { lifeCycle, clock } = setupBuilder.withFakeClock().build() | ||
expect(getHandledCount()).toEqual(1) | ||
expect(getHandledCount()).toEqual(3) | ||
expect(getViewEvent(1).eventCounts.userActionCount).toEqual(2) | ||
expect(getViewEvent(2).eventCounts.userActionCount).toEqual(0) | ||
}) | ||
clock.tick(VIEW_DURATION) | ||
it('should reset event count when the view changes', () => { | ||
const { lifeCycle } = setupBuilder.build() | ||
expect(getHandledCount()).toEqual(1) | ||
expect(getViewEvent(0).eventCounts.resourceCount).toEqual(0) | ||
history.pushState({}, '', '/bar') | ||
lifeCycle.notify(LifeCycleEventType.RESOURCE_ADDED_TO_BATCH) | ||
history.pushState({}, '', '/bar') | ||
clock.tick(VIEW_DURATION) | ||
expect(getHandledCount()).toEqual(3) | ||
expect(getViewEvent(1).eventCounts.resourceCount).toEqual(1) | ||
expect(getViewEvent(2).eventCounts.resourceCount).toEqual(0) | ||
expect(getHandledCount()).toEqual(3) | ||
lifeCycle.notify(LifeCycleEventType.RESOURCE_ADDED_TO_BATCH) | ||
lifeCycle.notify(LifeCycleEventType.RESOURCE_ADDED_TO_BATCH) | ||
history.pushState({}, '', '/baz') | ||
lifeCycle.notify(LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, FAKE_PAINT_ENTRY) | ||
lifeCycle.notify(LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, FAKE_NAVIGATION_ENTRY) | ||
expect(getHandledCount()).toEqual(5) | ||
expect(getViewEvent(3).eventCounts.resourceCount).toEqual(2) | ||
expect(getViewEvent(4).eventCounts.resourceCount).toEqual(0) | ||
}) | ||
clock.tick(THROTTLE_VIEW_UPDATE_PERIOD) | ||
it('should update eventCounts when notified with a PERFORMANCE_ENTRY_COLLECTED event (throttled)', () => { | ||
const { lifeCycle, clock } = setupBuilder.withFakeClock().build() | ||
expect(getHandledCount()).toEqual(1) | ||
expect(getViewEvent(0).eventCounts).toEqual({ | ||
errorCount: 0, | ||
longTaskCount: 0, | ||
resourceCount: 0, | ||
userActionCount: 0, | ||
}) | ||
expect(getHandledCount()).toEqual(4) | ||
lifeCycle.notify(LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, FAKE_NAVIGATION_ENTRY) | ||
initialView = { | ||
end: getViewEvent(1), | ||
init: getViewEvent(0), | ||
last: getViewEvent(3), | ||
} | ||
secondView = { | ||
init: getViewEvent(2), | ||
last: getViewEvent(2), | ||
} | ||
}) | ||
expect(getHandledCount()).toEqual(1) | ||
it('should not set timings to the second view', () => { | ||
expect(secondView.last.timings).toEqual({}) | ||
}) | ||
clock.tick(THROTTLE_VIEW_UPDATE_PERIOD) | ||
it('should set timings only on the initial view', () => { | ||
expect(initialView.last.timings).toEqual({ | ||
domComplete: 456, | ||
domContentLoaded: 345, | ||
domInteractive: 234, | ||
firstContentfulPaint: 123, | ||
loadEventEnd: 567, | ||
}) | ||
}) | ||
expect(getHandledCount()).toEqual(2) | ||
expect(getViewEvent(1).eventCounts).toEqual({ | ||
errorCount: 0, | ||
longTaskCount: 0, | ||
resourceCount: 0, | ||
userActionCount: 0, | ||
it('should not update the initial view duration when updating it with new timings', () => { | ||
expect(initialView.end.duration).toBe(VIEW_DURATION) | ||
expect(initialView.last.duration).toBe(VIEW_DURATION) | ||
}) | ||
it('should update the initial view loadingTime following the loadEventEnd value', () => { | ||
expect(initialView.last.loadingTime).toBe(FAKE_NAVIGATION_ENTRY.loadEventEnd) | ||
}) | ||
}) | ||
}) | ||
it('should update eventCounts when notified with a RESOURCE_ADDED_TO_BATCH event (throttled)', () => { | ||
const { lifeCycle, clock } = setupBuilder.withFakeClock().build() | ||
expect(getHandledCount()).toEqual(1) | ||
expect(getViewEvent(0).eventCounts).toEqual({ | ||
errorCount: 0, | ||
longTaskCount: 0, | ||
resourceCount: 0, | ||
userActionCount: 0, | ||
describe('event counts', () => { | ||
function createFakeCollectedRawRumEvent(category: RumEventCategory) { | ||
return { | ||
rawRumEvent: ({ evt: { category } } as unknown) as RawRumEvent, | ||
startTime: 0, | ||
} | ||
} | ||
it('should track error count', () => { | ||
const { lifeCycle } = setupBuilder.build() | ||
expect(getHandledCount()).toEqual(1) | ||
expect(getViewEvent(0).eventCounts.errorCount).toEqual(0) | ||
lifeCycle.notify( | ||
LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, | ||
createFakeCollectedRawRumEvent(RumEventCategory.ERROR) | ||
) | ||
lifeCycle.notify( | ||
LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, | ||
createFakeCollectedRawRumEvent(RumEventCategory.ERROR) | ||
) | ||
history.pushState({}, '', '/bar') | ||
expect(getHandledCount()).toEqual(3) | ||
expect(getViewEvent(1).eventCounts.errorCount).toEqual(2) | ||
expect(getViewEvent(2).eventCounts.errorCount).toEqual(0) | ||
}) | ||
lifeCycle.notify(LifeCycleEventType.RESOURCE_ADDED_TO_BATCH) | ||
it('should track long task count', () => { | ||
const { lifeCycle } = setupBuilder.build() | ||
expect(getHandledCount()).toEqual(1) | ||
expect(getViewEvent(0).eventCounts.longTaskCount).toEqual(0) | ||
expect(getHandledCount()).toEqual(1) | ||
lifeCycle.notify( | ||
LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, | ||
createFakeCollectedRawRumEvent(RumEventCategory.LONG_TASK) | ||
) | ||
history.pushState({}, '', '/bar') | ||
clock.tick(THROTTLE_VIEW_UPDATE_PERIOD) | ||
expect(getHandledCount()).toEqual(2) | ||
expect(getViewEvent(1).eventCounts).toEqual({ | ||
errorCount: 0, | ||
longTaskCount: 0, | ||
resourceCount: 1, | ||
userActionCount: 0, | ||
expect(getHandledCount()).toEqual(3) | ||
expect(getViewEvent(1).eventCounts.longTaskCount).toEqual(1) | ||
expect(getViewEvent(2).eventCounts.longTaskCount).toEqual(0) | ||
}) | ||
}) | ||
it('should update eventCounts when ending a view', () => { | ||
const { lifeCycle } = setupBuilder.build() | ||
expect(getHandledCount()).toEqual(1) | ||
expect(getViewEvent(0).eventCounts).toEqual({ | ||
errorCount: 0, | ||
longTaskCount: 0, | ||
resourceCount: 0, | ||
userActionCount: 0, | ||
it('should track resource count', () => { | ||
const { lifeCycle } = setupBuilder.build() | ||
expect(getHandledCount()).toEqual(1) | ||
expect(getViewEvent(0).eventCounts.resourceCount).toEqual(0) | ||
lifeCycle.notify( | ||
LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, | ||
createFakeCollectedRawRumEvent(RumEventCategory.RESOURCE) | ||
) | ||
history.pushState({}, '', '/bar') | ||
expect(getHandledCount()).toEqual(3) | ||
expect(getViewEvent(1).eventCounts.resourceCount).toEqual(1) | ||
expect(getViewEvent(2).eventCounts.resourceCount).toEqual(0) | ||
}) | ||
lifeCycle.notify(LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, FAKE_PAINT_ENTRY) | ||
lifeCycle.notify(LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, FAKE_NAVIGATION_ENTRY) | ||
expect(getHandledCount()).toEqual(1) | ||
it('should track action count', () => { | ||
const { lifeCycle } = setupBuilder.build() | ||
expect(getHandledCount()).toEqual(1) | ||
expect(getViewEvent(0).eventCounts.userActionCount).toEqual(0) | ||
history.pushState({}, '', '/bar') | ||
lifeCycle.notify( | ||
LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, | ||
createFakeCollectedRawRumEvent(RumEventCategory.USER_ACTION) | ||
) | ||
history.pushState({}, '', '/bar') | ||
expect(getHandledCount()).toEqual(3) | ||
expect(getViewEvent(1).eventCounts).toEqual({ | ||
errorCount: 0, | ||
longTaskCount: 0, | ||
resourceCount: 0, | ||
userActionCount: 0, | ||
expect(getHandledCount()).toEqual(3) | ||
expect(getViewEvent(1).eventCounts.userActionCount).toEqual(1) | ||
expect(getViewEvent(2).eventCounts.userActionCount).toEqual(0) | ||
}) | ||
expect(getViewEvent(2).eventCounts).toEqual({ | ||
errorCount: 0, | ||
longTaskCount: 0, | ||
resourceCount: 0, | ||
userActionCount: 0, | ||
}) | ||
}) | ||
it('should not update eventCounts after ending a view', () => { | ||
const { lifeCycle, clock } = setupBuilder.withFakeClock().build() | ||
expect(getHandledCount()).toEqual(1) | ||
it('should reset event count when the view changes', () => { | ||
const { lifeCycle } = setupBuilder.build() | ||
expect(getHandledCount()).toEqual(1) | ||
expect(getViewEvent(0).eventCounts.resourceCount).toEqual(0) | ||
lifeCycle.notify(LifeCycleEventType.RESOURCE_ADDED_TO_BATCH) | ||
lifeCycle.notify( | ||
LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, | ||
createFakeCollectedRawRumEvent(RumEventCategory.RESOURCE) | ||
) | ||
history.pushState({}, '', '/bar') | ||
expect(getHandledCount()).toEqual(1) | ||
expect(getHandledCount()).toEqual(3) | ||
expect(getViewEvent(1).eventCounts.resourceCount).toEqual(1) | ||
expect(getViewEvent(2).eventCounts.resourceCount).toEqual(0) | ||
history.pushState({}, '', '/bar') | ||
lifeCycle.notify( | ||
LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, | ||
createFakeCollectedRawRumEvent(RumEventCategory.RESOURCE) | ||
) | ||
lifeCycle.notify( | ||
LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, | ||
createFakeCollectedRawRumEvent(RumEventCategory.RESOURCE) | ||
) | ||
history.pushState({}, '', '/baz') | ||
expect(getHandledCount()).toEqual(3) | ||
expect(getViewEvent(1).id).toEqual(getViewEvent(0).id) | ||
expect(getViewEvent(2).id).not.toEqual(getViewEvent(0).id) | ||
expect(getHandledCount()).toEqual(5) | ||
expect(getViewEvent(3).eventCounts.resourceCount).toEqual(2) | ||
expect(getViewEvent(4).eventCounts.resourceCount).toEqual(0) | ||
}) | ||
clock.tick(THROTTLE_VIEW_UPDATE_PERIOD) | ||
it('should update eventCounts when a resource event is collected (throttled)', () => { | ||
const { lifeCycle, clock } = setupBuilder.withFakeClock().build() | ||
expect(getHandledCount()).toEqual(1) | ||
expect(getViewEvent(0).eventCounts).toEqual({ | ||
errorCount: 0, | ||
longTaskCount: 0, | ||
resourceCount: 0, | ||
userActionCount: 0, | ||
}) | ||
expect(getHandledCount()).toEqual(3) | ||
}) | ||
lifeCycle.notify( | ||
LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, | ||
createFakeCollectedRawRumEvent(RumEventCategory.RESOURCE) | ||
) | ||
describe('load event happening after initial view end', () => { | ||
let initialView: { init: View; end: View; last: View } | ||
let secondView: { init: View; last: View } | ||
const VIEW_DURATION = 100 | ||
expect(getHandledCount()).toEqual(1) | ||
beforeEach(() => { | ||
clock.tick(THROTTLE_VIEW_UPDATE_PERIOD) | ||
expect(getHandledCount()).toEqual(2) | ||
expect(getViewEvent(1).eventCounts).toEqual({ | ||
errorCount: 0, | ||
longTaskCount: 0, | ||
resourceCount: 1, | ||
userActionCount: 0, | ||
}) | ||
}) | ||
it('should not update eventCounts after ending a view', () => { | ||
const { lifeCycle, clock } = setupBuilder.withFakeClock().build() | ||
expect(getHandledCount()).toEqual(1) | ||
clock.tick(VIEW_DURATION) | ||
lifeCycle.notify( | ||
LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, | ||
createFakeCollectedRawRumEvent(RumEventCategory.RESOURCE) | ||
) | ||
expect(getHandledCount()).toEqual(1) | ||
history.pushState({}, '', '/bar') | ||
clock.tick(VIEW_DURATION) | ||
expect(getHandledCount()).toEqual(3) | ||
expect(getViewEvent(1).id).toEqual(getViewEvent(0).id) | ||
expect(getViewEvent(2).id).not.toEqual(getViewEvent(0).id) | ||
clock.tick(THROTTLE_VIEW_UPDATE_PERIOD) | ||
expect(getHandledCount()).toEqual(3) | ||
}) | ||
}) | ||
lifeCycle.notify(LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, FAKE_PAINT_ENTRY) | ||
lifeCycle.notify(LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, FAKE_NAVIGATION_ENTRY) | ||
describe('event counts V2', () => { | ||
it('should track error count', () => { | ||
const { lifeCycle } = setupBuilder.build() | ||
expect(getHandledCount()).toEqual(1) | ||
expect(getViewEvent(0).eventCounts.errorCount).toEqual(0) | ||
clock.tick(THROTTLE_VIEW_UPDATE_PERIOD) | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, { | ||
rawRumEvent: createRawRumEvent(RumEventType.ERROR), | ||
startTime: 0, | ||
}) | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, { | ||
rawRumEvent: createRawRumEvent(RumEventType.ERROR), | ||
startTime: 0, | ||
}) | ||
history.pushState({}, '', '/bar') | ||
expect(getHandledCount()).toEqual(4) | ||
expect(getHandledCount()).toEqual(3) | ||
expect(getViewEvent(1).eventCounts.errorCount).toEqual(2) | ||
expect(getViewEvent(2).eventCounts.errorCount).toEqual(0) | ||
}) | ||
initialView = { | ||
end: getViewEvent(1), | ||
init: getViewEvent(0), | ||
last: getViewEvent(3), | ||
} | ||
secondView = { | ||
init: getViewEvent(2), | ||
last: getViewEvent(2), | ||
} | ||
it('should track long task count', () => { | ||
const { lifeCycle } = setupBuilder.build() | ||
expect(getHandledCount()).toEqual(1) | ||
expect(getViewEvent(0).eventCounts.longTaskCount).toEqual(0) | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, { | ||
rawRumEvent: createRawRumEvent(RumEventType.LONG_TASK), | ||
startTime: 0, | ||
}) | ||
history.pushState({}, '', '/bar') | ||
expect(getHandledCount()).toEqual(3) | ||
expect(getViewEvent(1).eventCounts.longTaskCount).toEqual(1) | ||
expect(getViewEvent(2).eventCounts.longTaskCount).toEqual(0) | ||
}) | ||
it('should not set timings to the second view', () => { | ||
expect(secondView.last.timings).toEqual({}) | ||
it('should track resource count', () => { | ||
const { lifeCycle } = setupBuilder.build() | ||
expect(getHandledCount()).toEqual(1) | ||
expect(getViewEvent(0).eventCounts.resourceCount).toEqual(0) | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, { | ||
rawRumEvent: createRawRumEvent(RumEventType.RESOURCE), | ||
startTime: 0, | ||
}) | ||
history.pushState({}, '', '/bar') | ||
expect(getHandledCount()).toEqual(3) | ||
expect(getViewEvent(1).eventCounts.resourceCount).toEqual(1) | ||
expect(getViewEvent(2).eventCounts.resourceCount).toEqual(0) | ||
}) | ||
it('should set timings only on the initial view', () => { | ||
expect(initialView.last.timings).toEqual({ | ||
domComplete: 456, | ||
domContentLoaded: 345, | ||
domInteractive: 234, | ||
firstContentfulPaint: 123, | ||
loadEventEnd: 567, | ||
it('should track action count', () => { | ||
const { lifeCycle } = setupBuilder.build() | ||
expect(getHandledCount()).toEqual(1) | ||
expect(getViewEvent(0).eventCounts.userActionCount).toEqual(0) | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, { | ||
rawRumEvent: createRawRumEvent(RumEventType.ACTION), | ||
startTime: 0, | ||
}) | ||
history.pushState({}, '', '/bar') | ||
expect(getHandledCount()).toEqual(3) | ||
expect(getViewEvent(1).eventCounts.userActionCount).toEqual(1) | ||
expect(getViewEvent(2).eventCounts.userActionCount).toEqual(0) | ||
}) | ||
it('should not update the initial view duration when updating it with new timings', () => { | ||
expect(initialView.end.duration).toBe(VIEW_DURATION) | ||
expect(initialView.last.duration).toBe(VIEW_DURATION) | ||
it('should reset event count when the view changes', () => { | ||
const { lifeCycle } = setupBuilder.build() | ||
expect(getHandledCount()).toEqual(1) | ||
expect(getViewEvent(0).eventCounts.resourceCount).toEqual(0) | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, { | ||
rawRumEvent: createRawRumEvent(RumEventType.RESOURCE), | ||
startTime: 0, | ||
}) | ||
history.pushState({}, '', '/bar') | ||
expect(getHandledCount()).toEqual(3) | ||
expect(getViewEvent(1).eventCounts.resourceCount).toEqual(1) | ||
expect(getViewEvent(2).eventCounts.resourceCount).toEqual(0) | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, { | ||
rawRumEvent: createRawRumEvent(RumEventType.RESOURCE), | ||
startTime: 0, | ||
}) | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, { | ||
rawRumEvent: createRawRumEvent(RumEventType.RESOURCE), | ||
startTime: 0, | ||
}) | ||
history.pushState({}, '', '/baz') | ||
expect(getHandledCount()).toEqual(5) | ||
expect(getViewEvent(3).eventCounts.resourceCount).toEqual(2) | ||
expect(getViewEvent(4).eventCounts.resourceCount).toEqual(0) | ||
}) | ||
it('should update the initial view loadingTime following the loadEventEnd value', () => { | ||
expect(initialView.last.loadingTime).toBe(FAKE_NAVIGATION_ENTRY.loadEventEnd) | ||
it('should update eventCounts when a resource event is collected (throttled)', () => { | ||
const { lifeCycle, clock } = setupBuilder.withFakeClock().build() | ||
expect(getHandledCount()).toEqual(1) | ||
expect(getViewEvent(0).eventCounts).toEqual({ | ||
errorCount: 0, | ||
longTaskCount: 0, | ||
resourceCount: 0, | ||
userActionCount: 0, | ||
}) | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, { | ||
rawRumEvent: createRawRumEvent(RumEventType.RESOURCE), | ||
startTime: 0, | ||
}) | ||
expect(getHandledCount()).toEqual(1) | ||
clock.tick(THROTTLE_VIEW_UPDATE_PERIOD) | ||
expect(getHandledCount()).toEqual(2) | ||
expect(getViewEvent(1).eventCounts).toEqual({ | ||
errorCount: 0, | ||
longTaskCount: 0, | ||
resourceCount: 1, | ||
userActionCount: 0, | ||
}) | ||
}) | ||
it('should not update eventCounts after ending a view', () => { | ||
const { lifeCycle, clock } = setupBuilder.withFakeClock().build() | ||
expect(getHandledCount()).toEqual(1) | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, { | ||
rawRumEvent: createRawRumEvent(RumEventType.RESOURCE), | ||
startTime: 0, | ||
}) | ||
expect(getHandledCount()).toEqual(1) | ||
history.pushState({}, '', '/bar') | ||
expect(getHandledCount()).toEqual(3) | ||
expect(getViewEvent(1).id).toEqual(getViewEvent(0).id) | ||
expect(getViewEvent(2).id).not.toEqual(getViewEvent(0).id) | ||
clock.tick(THROTTLE_VIEW_UPDATE_PERIOD) | ||
expect(getHandledCount()).toEqual(3) | ||
}) | ||
}) | ||
}) |
@@ -12,6 +12,9 @@ import { setup, TestSetupBuilder } from '../../../../test/specHelper' | ||
beforeEach(() => { | ||
setupBuilder = setup().beforeBuild((lifeCycle, configuration) => { | ||
configuration.isEnabled = () => false | ||
startViewCollection(lifeCycle, configuration, location) | ||
}) | ||
setupBuilder = setup() | ||
.withConfiguration({ | ||
isEnabled: () => false, | ||
}) | ||
.beforeBuild(({ lifeCycle, configuration }) => { | ||
startViewCollection(lifeCycle, configuration, location) | ||
}) | ||
}) | ||
@@ -50,4 +53,4 @@ | ||
expect(rawRumEvents[0].startTime).toBe(1234) | ||
expect(rawRumEvents[0].rawRumEvent).toEqual({ | ||
expect(rawRumEvents[rawRumEvents.length - 1].startTime).toBe(1234) | ||
expect(rawRumEvents[rawRumEvents.length - 1].rawRumEvent).toEqual({ | ||
date: jasmine.any(Number), | ||
@@ -84,6 +87,9 @@ duration: 100 * 1e6, | ||
beforeEach(() => { | ||
setupBuilder = setup().beforeBuild((lifeCycle, configuration) => { | ||
configuration.isEnabled = () => true | ||
startViewCollection(lifeCycle, configuration, location) | ||
}) | ||
setupBuilder = setup() | ||
.withConfiguration({ | ||
isEnabled: () => true, | ||
}) | ||
.beforeBuild(({ lifeCycle, configuration }) => { | ||
startViewCollection(lifeCycle, configuration, location) | ||
}) | ||
}) | ||
@@ -122,4 +128,4 @@ | ||
expect(rawRumEventsV2[0].startTime).toBe(1234) | ||
expect(rawRumEventsV2[0].rawRumEvent).toEqual({ | ||
expect(rawRumEventsV2[rawRumEventsV2.length - 1].startTime).toBe(1234) | ||
expect(rawRumEventsV2[rawRumEventsV2.length - 1].rawRumEvent).toEqual({ | ||
_dd: { | ||
@@ -126,0 +132,0 @@ documentVersion: 3, |
@@ -14,3 +14,3 @@ import { Configuration, getTimestamp, msToNs } from '@datadog/browser-core' | ||
trackViews(location, lifeCycle) | ||
return trackViews(location, lifeCycle) | ||
} | ||
@@ -17,0 +17,0 @@ |
@@ -1,5 +0,5 @@ | ||
import { objectValues, RawError } from '@datadog/browser-core' | ||
import { RumPerformanceLongTaskTiming, RumPerformanceNavigationTiming } from '../browser/performanceCollection' | ||
import { objectValues } from '@datadog/browser-core' | ||
import { RawRumEvent, RumEventCategory } from '../types' | ||
import { RawRumEventV2, RumEventType } from '../typesV2' | ||
import { LifeCycle, LifeCycleEventType } from './lifeCycle' | ||
import { AutoAction, CustomAction } from './rumEventsCollection/action/trackActions' | ||
import { EventCounts, trackEventCounts } from './trackEventCounts' | ||
@@ -14,6 +14,12 @@ | ||
function notifyCollectedRawRumEvent(category: RumEventCategory) { | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, { | ||
rawRumEvent: ({ evt: { category } } as unknown) as RawRumEvent, | ||
startTime: 0, | ||
}) | ||
} | ||
it('tracks errors', () => { | ||
const { eventCounts } = trackEventCounts(lifeCycle) | ||
const error = {} | ||
lifeCycle.notify(LifeCycleEventType.ERROR_COLLECTED, error as RawError) | ||
notifyCollectedRawRumEvent(RumEventCategory.ERROR) | ||
expect(eventCounts.errorCount).toBe(1) | ||
@@ -24,14 +30,9 @@ }) | ||
const { eventCounts } = trackEventCounts(lifeCycle) | ||
const performanceTiming = { entryType: 'longtask' } | ||
lifeCycle.notify(LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, performanceTiming as RumPerformanceLongTaskTiming) | ||
notifyCollectedRawRumEvent(RumEventCategory.LONG_TASK) | ||
expect(eventCounts.longTaskCount).toBe(1) | ||
}) | ||
it("doesn't track navigation entries", () => { | ||
it("doesn't track views", () => { | ||
const { eventCounts } = trackEventCounts(lifeCycle) | ||
const performanceTiming = { entryType: 'navigation' } | ||
lifeCycle.notify( | ||
LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, | ||
performanceTiming as RumPerformanceNavigationTiming | ||
) | ||
notifyCollectedRawRumEvent(RumEventCategory.VIEW) | ||
expect(objectValues(eventCounts).every((value) => value === 0)).toBe(true) | ||
@@ -42,14 +43,76 @@ }) | ||
const { eventCounts } = trackEventCounts(lifeCycle) | ||
const action = {} | ||
lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_COMPLETED, action as AutoAction) | ||
lifeCycle.notify(LifeCycleEventType.CUSTOM_ACTION_COLLECTED, { | ||
action: action as CustomAction, | ||
context: {}, | ||
notifyCollectedRawRumEvent(RumEventCategory.USER_ACTION) | ||
expect(eventCounts.userActionCount).toBe(1) | ||
}) | ||
it('tracks resources', () => { | ||
const { eventCounts } = trackEventCounts(lifeCycle) | ||
notifyCollectedRawRumEvent(RumEventCategory.RESOURCE) | ||
expect(eventCounts.resourceCount).toBe(1) | ||
}) | ||
it('stops tracking when stop is called', () => { | ||
const { eventCounts, stop } = trackEventCounts(lifeCycle) | ||
notifyCollectedRawRumEvent(RumEventCategory.RESOURCE) | ||
expect(eventCounts.resourceCount).toBe(1) | ||
stop() | ||
notifyCollectedRawRumEvent(RumEventCategory.RESOURCE) | ||
expect(eventCounts.resourceCount).toBe(1) | ||
}) | ||
it('invokes a potential callback when a count is increased', () => { | ||
const spy = jasmine.createSpy<(eventCounts: EventCounts) => void>() | ||
trackEventCounts(lifeCycle, spy) | ||
notifyCollectedRawRumEvent(RumEventCategory.RESOURCE) | ||
expect(spy).toHaveBeenCalledTimes(1) | ||
expect(spy.calls.mostRecent().args[0].resourceCount).toBe(1) | ||
notifyCollectedRawRumEvent(RumEventCategory.RESOURCE) | ||
expect(spy).toHaveBeenCalledTimes(2) | ||
expect(spy.calls.mostRecent().args[0].resourceCount).toBe(2) | ||
}) | ||
}) | ||
describe('trackEventCounts v2', () => { | ||
let lifeCycle: LifeCycle | ||
beforeEach(() => { | ||
lifeCycle = new LifeCycle() | ||
}) | ||
function notifyCollectedRawRumEvent(type: RumEventType) { | ||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, { | ||
rawRumEvent: ({ type } as unknown) as RawRumEventV2, | ||
startTime: 0, | ||
}) | ||
expect(eventCounts.userActionCount).toBe(2) | ||
} | ||
it('tracks errors', () => { | ||
const { eventCounts } = trackEventCounts(lifeCycle) | ||
notifyCollectedRawRumEvent(RumEventType.ERROR) | ||
expect(eventCounts.errorCount).toBe(1) | ||
}) | ||
it('tracks long tasks', () => { | ||
const { eventCounts } = trackEventCounts(lifeCycle) | ||
notifyCollectedRawRumEvent(RumEventType.LONG_TASK) | ||
expect(eventCounts.longTaskCount).toBe(1) | ||
}) | ||
it("doesn't track views", () => { | ||
const { eventCounts } = trackEventCounts(lifeCycle) | ||
notifyCollectedRawRumEvent(RumEventType.VIEW) | ||
expect(objectValues(eventCounts).every((value) => value === 0)).toBe(true) | ||
}) | ||
it('tracks actions', () => { | ||
const { eventCounts } = trackEventCounts(lifeCycle) | ||
notifyCollectedRawRumEvent(RumEventType.ACTION) | ||
expect(eventCounts.userActionCount).toBe(1) | ||
}) | ||
it('tracks resources', () => { | ||
const { eventCounts } = trackEventCounts(lifeCycle) | ||
lifeCycle.notify(LifeCycleEventType.RESOURCE_ADDED_TO_BATCH) | ||
notifyCollectedRawRumEvent(RumEventType.RESOURCE) | ||
expect(eventCounts.resourceCount).toBe(1) | ||
@@ -60,6 +123,6 @@ }) | ||
const { eventCounts, stop } = trackEventCounts(lifeCycle) | ||
lifeCycle.notify(LifeCycleEventType.RESOURCE_ADDED_TO_BATCH) | ||
notifyCollectedRawRumEvent(RumEventType.RESOURCE) | ||
expect(eventCounts.resourceCount).toBe(1) | ||
stop() | ||
lifeCycle.notify(LifeCycleEventType.RESOURCE_ADDED_TO_BATCH) | ||
notifyCollectedRawRumEvent(RumEventType.RESOURCE) | ||
expect(eventCounts.resourceCount).toBe(1) | ||
@@ -72,7 +135,7 @@ }) | ||
lifeCycle.notify(LifeCycleEventType.RESOURCE_ADDED_TO_BATCH) | ||
notifyCollectedRawRumEvent(RumEventType.RESOURCE) | ||
expect(spy).toHaveBeenCalledTimes(1) | ||
expect(spy.calls.mostRecent().args[0].resourceCount).toBe(1) | ||
lifeCycle.notify(LifeCycleEventType.RESOURCE_ADDED_TO_BATCH) | ||
notifyCollectedRawRumEvent(RumEventType.RESOURCE) | ||
expect(spy).toHaveBeenCalledTimes(2) | ||
@@ -79,0 +142,0 @@ expect(spy.calls.mostRecent().args[0].resourceCount).toBe(2) |
import { noop } from '@datadog/browser-core' | ||
import { LifeCycle, LifeCycleEventType, Subscription } from './lifeCycle' | ||
import { RumEventCategory } from '../types' | ||
import { RumEventType } from '../typesV2' | ||
import { LifeCycle, LifeCycleEventType } from './lifeCycle' | ||
@@ -18,39 +20,49 @@ export interface EventCounts { | ||
} | ||
const subscriptions: Subscription[] = [] | ||
subscriptions.push( | ||
lifeCycle.subscribe(LifeCycleEventType.ERROR_COLLECTED, () => { | ||
eventCounts.errorCount += 1 | ||
callback(eventCounts) | ||
}) | ||
) | ||
subscriptions.push( | ||
lifeCycle.subscribe(LifeCycleEventType.AUTO_ACTION_COMPLETED, () => { | ||
eventCounts.userActionCount += 1 | ||
callback(eventCounts) | ||
}) | ||
) | ||
subscriptions.push( | ||
lifeCycle.subscribe(LifeCycleEventType.CUSTOM_ACTION_COLLECTED, () => { | ||
eventCounts.userActionCount += 1 | ||
callback(eventCounts) | ||
}) | ||
) | ||
subscriptions.push( | ||
lifeCycle.subscribe(LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, (entry) => { | ||
if (entry.entryType === 'longtask') { | ||
const subscription = lifeCycle.subscribe(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, ({ rawRumEvent }): void => { | ||
switch (rawRumEvent.evt.category) { | ||
case RumEventCategory.ERROR: | ||
eventCounts.errorCount += 1 | ||
callback(eventCounts) | ||
break | ||
case RumEventCategory.USER_ACTION: | ||
eventCounts.userActionCount += 1 | ||
callback(eventCounts) | ||
break | ||
case RumEventCategory.LONG_TASK: | ||
eventCounts.longTaskCount += 1 | ||
callback(eventCounts) | ||
} | ||
}) | ||
) | ||
subscriptions.push( | ||
lifeCycle.subscribe(LifeCycleEventType.RESOURCE_ADDED_TO_BATCH, () => { | ||
eventCounts.resourceCount += 1 | ||
callback(eventCounts) | ||
}) | ||
) | ||
break | ||
case RumEventCategory.RESOURCE: | ||
eventCounts.resourceCount += 1 | ||
callback(eventCounts) | ||
break | ||
} | ||
}) | ||
const subscriptionV2 = lifeCycle.subscribe(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, ({ rawRumEvent }): void => { | ||
switch (rawRumEvent.type) { | ||
case RumEventType.ERROR: | ||
eventCounts.errorCount += 1 | ||
callback(eventCounts) | ||
break | ||
case RumEventType.ACTION: | ||
eventCounts.userActionCount += 1 | ||
callback(eventCounts) | ||
break | ||
case RumEventType.LONG_TASK: | ||
eventCounts.longTaskCount += 1 | ||
callback(eventCounts) | ||
break | ||
case RumEventType.RESOURCE: | ||
eventCounts.resourceCount += 1 | ||
callback(eventCounts) | ||
break | ||
} | ||
}) | ||
return { | ||
stop() { | ||
subscriptions.forEach((s) => s.unsubscribe()) | ||
subscription.unsubscribe() | ||
subscriptionV2.unsubscribe() | ||
}, | ||
@@ -57,0 +69,0 @@ eventCounts, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
770833
1
14074
+ Added@datadog/browser-core@1.25.2(transitive)
- Removed@datadog/browser-core@1.25.1(transitive)
Updated@datadog/browser-core@1.25.2