!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="9f2db6ad-60cb-39ae-9f83-28a9b53da1f4")}catch(e){}}(); define(["require","exports","./c_init_data_debug_panel","./c_flux_action_type","./c_lodash-es_lodash","./e_core_exception","./c_api_v2_routes_team_provider"],(function(e,t,n,s,i,r,o){"use strict";class a extends s.Message{constructor(e){super(),this.seconds=s.protoInt64.zero,this.nanos=0,s.proto3.util.initPartial(e,this)}fromJson(e,t){if("string"!=typeof e)throw new Error(`cannot decode google.protobuf.Timestamp from JSON: ${s.proto3.json.debug(e)}`);const n=e.match(/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(?:Z|\.([0-9]{3,9})Z|([+-][0-9][0-9]:[0-9][0-9]))$/);if(!n)throw new Error("cannot decode google.protobuf.Timestamp from JSON: invalid RFC 3339 string");const i=Date.parse(n[1]+"-"+n[2]+"-"+n[3]+"T"+n[4]+":"+n[5]+":"+n[6]+(n[8]?n[8]:"Z"));if(Number.isNaN(i))throw new Error("cannot decode google.protobuf.Timestamp from JSON: invalid RFC 3339 string");if(iDate.parse("9999-12-31T23:59:59Z"))throw new Error("cannot decode message google.protobuf.Timestamp from JSON: must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive");return this.seconds=s.protoInt64.parse(i/1e3),this.nanos=0,n[7]&&(this.nanos=parseInt("1"+n[7]+"0".repeat(9-n[7].length))-1e9),this}toJson(e){const t=1e3*Number(this.seconds);if(tDate.parse("9999-12-31T23:59:59Z"))throw new Error("cannot encode google.protobuf.Timestamp to JSON: must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive");if(this.nanos<0)throw new Error("cannot encode google.protobuf.Timestamp to JSON: nanos must not be negative");let n="Z";if(this.nanos>0){const e=(this.nanos+1e9).toString().substring(1);n="000000"===e.substring(3)?"."+e.substring(0,3)+"Z":"000"===e.substring(6)?"."+e.substring(0,6)+"Z":"."+e+"Z"}return new Date(t).toISOString().replace(".000Z",n)}toDate(){return new Date(1e3*Number(this.seconds)+Math.ceil(this.nanos/1e6))}static now(){return a.fromDate(new Date)}static fromDate(e){const t=e.getTime();return new a({seconds:s.protoInt64.parse(Math.floor(t/1e3)),nanos:t%1e3*1e6})}static fromBinary(e,t){return(new a).fromBinary(e,t)}static fromJson(e,t){return(new a).fromJson(e,t)}static fromJsonString(e,t){return(new a).fromJsonString(e,t)}static equals(e,t){return s.proto3.util.equals(a,e,t)}}a.runtime=s.proto3,a.typeName="google.protobuf.Timestamp",a.fields=s.proto3.util.newFieldList((()=>[{no:1,name:"seconds",kind:"scalar",T:3},{no:2,name:"nanos",kind:"scalar",T:5}]));class c extends s.Message{constructor(e){super(),s.proto3.util.initPartial(e,this)}static fromBinary(e,t){return(new c).fromBinary(e,t)}static fromJson(e,t){return(new c).fromJson(e,t)}static fromJsonString(e,t){return(new c).fromJsonString(e,t)}static equals(e,t){return s.proto3.util.equals(c,e,t)}}c.runtime=s.proto3,c.typeName="google.protobuf.Empty",c.fields=s.proto3.util.newFieldList((()=>[]));class l{now(){return{value:performance.now(),unit:n.TimeUnit.MILLISECONDS}}}class u{static toMilliseconds(e){switch(e.unit){case n.TimeUnit.NANOSECONDS:return e.value/1e6;case n.TimeUnit.MILLISECONDS:return e.value;case n.TimeUnit.SECONDS:return 1e3*e.value;case n.TimeUnit.MINUTES:return 6e4*e.value;case n.TimeUnit.HOURS:return 36e5*e.value;case n.TimeUnit.DAYS:return 24*e.value*36e5}}}class d{constructor(e){this.jitterStrategy=e}executeEvery(e,t){const n=u.toMilliseconds(e),s=u.toMilliseconds(this.jitterStrategy());setTimeout((()=>{t()&&this.executeEvery(e,t)}),n+s)}}const p=256,m=new RegExp("^[^0-9a-zA-Z]+"),h=new RegExp("[^0-9a-zA-Z._-]","g"),f=h,g=new RegExp("[^0-9a-zA-Z/._-]","g"),v=h;function w(e){return{ns:(n=e.ns,_(n,"namespace",p,m,f)),name:(t=e.name,_(t,"metric name",p,m,g))};var t,n}function S(e){const t={};for(const n in e)if(e.hasOwnProperty(n)){t[_(n,"tag name",p,m,v)]=_(e[n],"tag value",p)}return t}function _(e,t,n,s,i){const r=[];if("string"!=typeof e&&r.push("identifier is not a string"),s&&s.test(e)&&r.push("invalid prefix"),i&&i.test(e)&&r.push("invalid characters"),e.length>n&&r.push(`exceeds ${n} characters`),0===e.length&&r.push("is empty"),0!==r.length)throw new Error(`${t} identifier '${e}' is invalid: ${r}`);return e}const b=3432918353,y=461845907;function k(e){if(4!=e.length)throw new Error("strToUint32 expected length 4 byte array");return e[0]+(e[1]<<8)+(e[2]<<16)+(e[3]<<24)}const E=2**32,x=[1,.5,.25,.125,.0625,.03125,.015625,.0078125,.00390625,.001953125,.0009765625,.00048828125,.000244140625,.0001220703125,6103515625e-14,30517578125e-15,152587890625e-16,762939453125e-17,3814697265625e-18,19073486328125e-19,9.5367431640625e-7,4.76837158203125e-7,2.384185791015625e-7,1.1920928955078125e-7,5.960464477539063e-8,2.9802322387695312e-8,1.4901161193847656e-8,7.450580596923828e-9,3.725290298461914e-9,1.862645149230957e-9,9.313225746154785e-10,4.656612873077393e-10,2.3283064365386963e-10],N=512;function O(e){return function(e,t){let n=t;const s=Math.floor(e.length/4);for(let t=0;t>>0|s>>>17)>>>0,s=Math.imul(s,y),n^=s,n>>>=0,n=(n<<13>>>0|n>>>19)>>>0,n=Math.imul(n,5)+3864292196>>>0}let i=e.slice(4*s),r=0;const o=3&i.length;return 3==o&&(r^=i[2]<<16>>>0,r>>>=0),o>=2&&(r^=i[1]<<8>>>0,r>>>=0),o>=1&&(r^=i[0],r=Math.imul(r,b),r=(r<<15>>>0|r>>>17)>>>0,r=Math.imul(r,y),n^=r,n>>>=0),n^=e.length,n>>>=0,n^=n>>>16,n>>>=0,n=Math.imul(n,2246822507),n^=n>>>13,n>>>=0,n=Math.imul(n,3266489909),n^=n>>>16,n>>>=0,n}(function(e){const t=[];let n=0;for(let s=0;s>6|192,t[n++]=63&i|128):(t[n++]=i>>12|224,t[n++]=i>>6&63|128,t[n++]=63&i|128)}return t}(e),538513424)}class C{constructor(e=[]){this.registers=new Array(N).fill(0),e.forEach((e=>this.add(e)))}add(e){if(e>=E)throw new Error("add only accepts 32-bit unsigned integers");const t=function(e,t){let n=1;for(;(2147483648&e)>>>0==0&&n<=t;)n++,e=e<<1>>>0;return n}(e<<9>>>0,23),n=e>>>23;t>this.registers[n]&&(this.registers[n]=t)}count(){let e=this.registers.reduce(((e,t)=>e+x[t]),0),t=this.registers.reduce(((e,t)=>e+(0==t?1:0)),0);if(t==N)return 0;let n=188686.82445861166/e;return n<=1280?t>0&&(n=N*Math.log(N/t)):n>1/30*E&&(n=-E*Math.log(1-n/E)),n}merge(e){for(let t=0;tthis.registers[t]&&(this.registers[t]=n)}}compressed(){const e=[];for(let t=0;t<64;t++){const n=D(this.registers.slice(8*t,8*(t+1)));for(const t of n)e.push(t)}return String.fromCharCode(...e)}}function D(e){if(8!=e.length)throw new Error("Number of registers in stripCompress routine is not 8");const t=[];let n=0;for(let t=0;t<8;t++){if(n*=32,e[t]>=32)throw new Error("Register in HLL greater than max allowed value");n+=e[t]}for(let e=0;e<5;e++)t.unshift(Number(n%256)),n=Math.floor(n/256);return t}class T{constructor(e,t,n,s={}){this.sink=e,this.clock=t,this.originId=n,this.tags=s}static root(e,t,n=""){return new T(e,t,n)}child(e){return new T(this.sink,this.clock,this.originId,Object.assign(Object.assign({},this.tags),S(e)))}createStats(e,t={}){return new M(w(e),Object.assign(Object.assign({},this.tags),S(t)),this.sink)}createCounter(e,t={}){return new I(w(e),Object.assign(Object.assign({},this.tags),S(t)),this.sink)}createTimer(e,t={}){return new P(w(e),Object.assign(Object.assign({},this.tags),S(t)),this.sink,this.clock)}createSet(e,t={}){return new F(w(e),Object.assign(Object.assign({},this.tags),S(t)),this.sink,this.originId)}}class M{constructor(e,t,n){this.metric=e,this.tags=t,this.sink=n}record(e){R(e,this.metric,this.tags,this.sink)}recordDuration(e,t){R(u.toMilliseconds({value:e,unit:t}),this.metric,this.tags,this.sink)}}class I{constructor(e,t,n,s=0){this.metric=e,this.tags=t,this.sink=n,this.value=s}decrement(e=1){this.value-=e}increment(e=1){this.value+=e}reset(e=0){this.value=e}record(){R(this.value,this.metric,this.tags,this.sink),this.reset()}}class P{constructor(e,t,n,s,i=0){this.metric=e,this.tags=t,this.sink=n,this.clock=s,this.value=i,this.value=u.toMilliseconds(this.clock.now())}record(){R(u.toMilliseconds(this.clock.now())-this.value,this.metric,this.tags,this.sink),this.reset()}reset(){this.value=u.toMilliseconds(this.clock.now())}}class F{constructor(e,t,n,s){this.metric=e,this.tags=t,this.sink=n,this.originId=s}observe(e){if("string"!=typeof e)throw new Error("value must be a string");const t=O(e);this.sink.recordSetSpan({namespace:this.metric.ns,metricName:this.metric.name,tags:this.tags,samples:[t],type:"set"})}observeOriginId(){this.observe(this.originId)}}function R(e,t,n,s){if("number"!=typeof e)throw new Error("value must be a number");s.recordSpan({namespace:t.ns,metricName:t.name,tags:n,samples:[e],type:"histogram"})}class B{recordSpan(){}recordSetSpan(){}}function L(e){const t=[];for(const n in e)if(e.hasOwnProperty(n)){const s=e[n];t.push({name:{value:{".tag":"string_value",string_value:n}},value:{value:{".tag":"string_value",string_value:s}}})}return t}function q(e,t){if(e.length!==t.length)throw new Error("Cannot zip values of different dimensions!");return e.map(((e,n)=>({name:{value:{".tag":"string_value",string_value:e}},value:{value:{".tag":"string_value",string_value:t[n]}}})))}const A="amp_client";var j;function J(e,t,n,s){n("samples_sink/submitted_spans",e.submittedSpans),n("samples_sink/submitted_samples",e.submittedSamples),n("samples_sink/overflow_spans",e.overflowSpans),n("samples_sink/overflow_samples",e.overflowSamples);for(const[t,s]of Object.entries(e.submittedSamplesByNs))n("samples_sink/submitted_samples_by_ns",s,{namespace:t});n("samples_sink/retained_spans",e.retainedSpans),n("samples_sink/retained_samples",e.retainedSamples);for(const[t,s]of Object.entries(e.retainedSamplesByNs))n("samples_sink/retained_samples_by_ns",s,{namespace:t});n("samples_sink/request/dropped_samples",e.requestDroppedSamples),n("samples_sink/request/dropped_spans",e.requestDroppedSpans),n("samples_sink/request/attempts",e.requestAttempts),n("samples_sink/request/latency",t),n("samples_sink/submitted_set_observations",e.setObservations);for(const[t,s]of Object.entries(e.setObservationsByNs))n("samples_sink/submitted_set_observations_by_ns",s,{namespace:t});n("samples_sink/request/dropped_set_observations",e.requestDroppedSetObservations),s("samples_sink/reporting_hosts")}!function(e){function t(e,t){var n;const s=Object.assign({},e);for(const[e,i]of Object.entries(t))s[e]=(null!==(n=s[e])&&void 0!==n?n:0)+i;return s}e.empty=function(){return{submittedSpans:0,submittedSamples:0,submittedSamplesByNs:{},overflowSpans:0,overflowSamples:0,retainedSpans:0,retainedSamples:0,retainedSamplesByNs:{},requestDroppedSamples:0,requestDroppedSpans:0,requestAttempts:0,setObservations:0,setObservationsByNs:{},requestDroppedSetObservations:0}},e.incrementSubmittedSamples=function(e,t,n){e.submittedSamples+=n;const s=e.submittedSamplesByNs[t];e.submittedSamplesByNs[t]=(null!=s?s:0)+n},e.incrementSetObservations=function(e,t,n){e.setObservations+=n;const s=e.setObservationsByNs[t];e.setObservationsByNs[t]=(null!=s?s:0)+n},e.incrementRetainedSamples=function(e,t,n){e.retainedSamples+=n;const s=e.retainedSamplesByNs[t];e.retainedSamplesByNs[t]=(null!=s?s:0)+n},e.report=function(t,n,s,i,r){if(0===t.retainedSamples)return t.requestAttempts=0,t;const o=n.child({client_version:i.toString(),origin_kind:r});return J(t,s,((e,t,n)=>{o.createStats({ns:A,name:e},n).record(t)}),(e=>{o.createSet({ns:A,name:e}).observeOriginId()})),e.empty()},e.toScope=function(e,t,n,s){const i=[];return J(e,n,((e,t,n)=>{i.push({tags:n?L(n):[],metrics:[{name:{value:{".tag":"string_value",string_value:e}},data:{".tag":"numerical_data",samples:[t]}}]})}),(e=>{i.push({metrics:[{name:{value:{".tag":"string_value",string_value:e}},data:{".tag":"set_data",samples:[O(t)]}}]})})),{metric_namespace:A,timestamp_sec:Math.floor(Date.now()/1e3),tags:L(s),descendants:i}},e.merge=function(e,n){var s,i,r,o,a,c,l,u,d,p,m,h,f,g;return{submittedSpans:e.submittedSpans+(null!==(s=n.submittedSpans)&&void 0!==s?s:0),submittedSamples:e.submittedSamples+(null!==(i=n.submittedSamples)&&void 0!==i?i:0),submittedSamplesByNs:t(e.submittedSamplesByNs,null!==(r=n.submittedSamplesByNs)&&void 0!==r?r:{}),overflowSpans:e.overflowSpans+(null!==(o=n.overflowSpans)&&void 0!==o?o:0),overflowSamples:e.overflowSamples+(null!==(a=n.overflowSamples)&&void 0!==a?a:0),retainedSpans:e.retainedSpans+(null!==(c=n.retainedSpans)&&void 0!==c?c:0),retainedSamples:e.retainedSamples+(null!==(l=n.retainedSamples)&&void 0!==l?l:0),retainedSamplesByNs:t(e.retainedSamplesByNs,null!==(u=n.retainedSamplesByNs)&&void 0!==u?u:{}),requestDroppedSamples:e.requestDroppedSamples+(null!==(d=n.requestDroppedSamples)&&void 0!==d?d:0),requestDroppedSpans:e.requestDroppedSpans+(null!==(p=n.requestDroppedSpans)&&void 0!==p?p:0),requestAttempts:e.requestAttempts+(null!==(m=n.requestAttempts)&&void 0!==m?m:0),setObservations:e.setObservations+(null!==(h=n.setObservations)&&void 0!==h?h:0),setObservationsByNs:t(e.setObservationsByNs,null!==(f=n.setObservationsByNs)&&void 0!==f?f:{}),requestDroppedSetObservations:e.requestDroppedSetObservations+(null!==(g=n.requestDroppedSetObservations)&&void 0!==g?g:0)}}}(j||(j={}));const U="apexMetrics",z=6,K="spans",V="set_spans",Z="namespace",H="controlValues",G="lastPublishTime",$="selfInstrumentation",Y="instrumentation";function W(e,t){return new Promise(((n,s)=>{const i=e.index(Z).getKey(IDBKeyRange.lowerBound(t,!0));i.addEventListener("success",(()=>{if(i.result){const e=i.result[0];n(IDBKeyRange.bound([t],[e],!1,!0))}else n(IDBKeyRange.lowerBound([t]))})),i.addEventListener("error",(e=>{s(e)}))}))}function X(e,t,n){const s=e.result,i=e=>{s.removeEventListener("error",i),n(e)};s.addEventListener("error",i),e.transaction.addEventListener("complete",(()=>{s.removeEventListener("error",i)})),e.transaction.addEventListener("error",(e=>{s.removeEventListener("error",i),n(e)}));const r=(e,t)=>e.oldVersion=t);if(r(t,1))try{s.createObjectStore(K,{keyPath:["namespace","tagNames","tagValues"]}).createIndex(Z,"namespace",{unique:!1}),s.createObjectStore(H,{keyPath:"name"})}catch(e){return void i(e)}if(r(t,2)){const t=e.transaction.objectStore(K).openCursor();t.addEventListener("success",(()=>{const e=t.result;if(!e)return;let n=!1;for(const t in e.value.spans)e.value.spans.hasOwnProperty(t)&&(n=!0,e.value.spans[t]={spanCount:0,samples:e.value.spans[t]});n&&e.update(e.value),e.continue()}))}if(r(t,3))try{s.createObjectStore($,{keyPath:"name"})}catch(e){return void i(e)}if(r(t,4))try{e.transaction.objectStore(K).clear();e.transaction.objectStore($).clear()}catch(e){return void i(e)}if(r(t,5))try{s.createObjectStore(V,{keyPath:["namespace","tagNames","tagValues"]}).createIndex(Z,"namespace",{unique:!1})}catch(e){return void i(e)}if(r(t,6))try{e.transaction.objectStore(K).clear();e.transaction.objectStore(V).clear();e.transaction.objectStore($).clear()}catch(e){return void i(e)}}async function Q(e=z){let t=null;if("undefined"==typeof indexedDB)return t;try{t=await new Promise(((t,n)=>{indexedDB.open("unused",1);const s=indexedDB.open(U,e);s.addEventListener("success",(()=>{t(s.result)})),s.addEventListener("error",(e=>{n(e)})),s.addEventListener("upgradeneeded",(e=>{try{X(s,e,n)}catch(e){n(e)}}))}))}catch(n){n.target&&n.target.error&&n.target.error.name&&"VersionError"===n.target.error.name&&(await new Promise(((e,t)=>{const n=indexedDB.deleteDatabase(U);n.addEventListener("success",(()=>e())),n.addEventListener("error",(e=>t(e)))})),t=await new Promise(((t,n)=>{const s=indexedDB.open(U,e);s.addEventListener("success",(()=>t(s.result))),s.addEventListener("error",(e=>n(e))),s.addEventListener("upgradeneeded",(e=>{try{X(s,e,n)}catch(e){n(e)}}))})))}return t}function ee(e,t){return ne(e,t,K,(e=>(e.sort(),e)))}function te(e,t){return ne(e,t,V,(e=>{const t={};return e.filter((e=>!t[e]&&(t[e]=!0,!0)))}))}function ne(e,t,n,s){return Promise.all(t.map((t=>new Promise(((i,r)=>{let o;try{o=e.transaction(n,"readwrite")}catch(e){if(e instanceof DOMException&&("InvalidStateError"===e.name||11===e.code))return void i();throw e}const a=o.objectStore(n);o.addEventListener("complete",(e=>i())),o.addEventListener("error",(e=>r(e)));const c=[],l=[];for(const e in t.tags)t.tags.hasOwnProperty(e)&&(c.push(e),l.push(t.tags[e]));const u=a.get([t.namespace,c,l]);u.addEventListener("success",(()=>{const e=u.result?u.result:{namespace:t.namespace,tagNames:c,tagValues:l,spans:{}};e.spans[t.metricName]||(e.spans[t.metricName]={spanCount:0,samples:[]}),e.spans[t.metricName].spanCount++,e.spans[t.metricName].samples=s(e.spans[t.metricName].samples.concat(t.samples)),a.put(e)}))})))))}function se(e,t){return new Promise((async(n,s)=>{var i,r;const o=re(e,$,"readwrite");if(null===o)return void n();const a=o.objectStore($);o.addEventListener("complete",(()=>{n()})),o.addEventListener("error",s);const c=null!==(r=null===(i=await oe(a,Y))||void 0===i?void 0:i.value)&&void 0!==r?r:j.empty(),l=j.merge(t,c);await function(e,t){return new Promise(((n,s)=>{const i=e.put(t);i.addEventListener("success",(()=>{n()})),i.addEventListener("error",(e=>{s(e)}))}))}(a,{name:Y,value:l})}))}function ie(e,t){return new Promise((async(n,s)=>{var i,r;const o=re(e,$,"readwrite");if(null===o)return void n(t);o.addEventListener("error",s);const a=o.objectStore($),c=null!==(r=null===(i=await oe(a,Y))||void 0===i?void 0:i.value)&&void 0!==r?r:j.empty();o.addEventListener("complete",(()=>{n(j.merge(t,c))})),function(e,t){new Promise(((n,s)=>{const i=e.delete(t);i.addEventListener("success",(()=>{n()})),i.addEventListener("error",(e=>{s(e)}))}))}(a,Y)}))}function re(e,t,n){try{return e.transaction(t,n)}catch(e){if(e instanceof DOMException&&("InvalidStateError"===e.name||11===e.code))return null;throw e}}function oe(e,t){return new Promise(((n,s)=>{const i=e.get(t);i.addEventListener("success",(()=>{n(i.result)})),i.addEventListener("error",(e=>{s(e)}))}))}class ae extends s.Message{constructor(e){super(),s.proto3.util.initPartial(e,this)}static fromBinary(e,t){return(new ae).fromBinary(e,t)}static fromJson(e,t){return(new ae).fromJson(e,t)}static fromJsonString(e,t){return(new ae).fromJsonString(e,t)}static equals(e,t){return s.proto3.util.equals(ae,e,t)}}ae.runtime=s.proto3,ae.typeName="apex_metrics_web.RecordNamespace",ae.fields=s.proto3.util.newFieldList((()=>[]));class ce extends s.Message{constructor(e){super(),this.metricNamespace="",this.maxTimeUntilRefreshSeconds=0,this.stopPublicationForSeconds=0,this.dropFractionOfHostsPerMetric=0,this.aggregationIntervalSeconds=0,s.proto3.util.initPartial(e,this)}static fromBinary(e,t){return(new ce).fromBinary(e,t)}static fromJson(e,t){return(new ce).fromJson(e,t)}static fromJsonString(e,t){return(new ce).fromJsonString(e,t)}static equals(e,t){return s.proto3.util.equals(ce,e,t)}}ce.runtime=s.proto3,ce.typeName="apex_metrics_web.RecordNamespace.MetricReportingConfigV2",ce.fields=s.proto3.util.newFieldList((()=>[{no:1,name:"metric_namespace",kind:"scalar",T:9},{no:2,name:"max_time_until_refresh_seconds",kind:"scalar",T:13},{no:3,name:"stop_publication_for_seconds",kind:"scalar",T:13},{no:4,name:"drop_samples",kind:"message",T:le},{no:5,name:"drop_periods",kind:"message",T:le},{no:6,name:"drop_fraction_of_hosts_per_metric",kind:"scalar",T:1},{no:7,name:"aggregation_interval_seconds",kind:"scalar",T:13}]));class le extends s.Message{constructor(e){super(),this.fraction=0,s.proto3.util.initPartial(e,this)}static fromBinary(e,t){return(new le).fromBinary(e,t)}static fromJson(e,t){return(new le).fromJson(e,t)}static fromJsonString(e,t){return(new le).fromJsonString(e,t)}static equals(e,t){return s.proto3.util.equals(le,e,t)}}le.runtime=s.proto3,le.typeName="apex_metrics_web.RecordNamespace.StickyBiasedCoinV2",le.fields=s.proto3.util.newFieldList((()=>[{no:1,name:"fraction",kind:"scalar",T:1},{no:2,name:"stickiness",kind:"message",T:ue}]));class ue extends s.Message{constructor(e){super(),this.limit={case:void 0},s.proto3.util.initPartial(e,this)}static fromBinary(e,t){return(new ue).fromBinary(e,t)}static fromJson(e,t){return(new ue).fromJson(e,t)}static fromJsonString(e,t){return(new ue).fromJsonString(e,t)}static equals(e,t){return s.proto3.util.equals(ue,e,t)}}ue.runtime=s.proto3,ue.typeName="apex_metrics_web.RecordNamespace.StickinessV2",ue.fields=s.proto3.util.newFieldList((()=>[{no:1,name:"independent",kind:"message",T:c,oneof:"limit"},{no:2,name:"permanent",kind:"message",T:c,oneof:"limit"},{no:3,name:"n_results",kind:"scalar",T:13,oneof:"limit"},{no:4,name:"n_seconds",kind:"scalar",T:2,oneof:"limit"}]));class de extends s.Message{constructor(e){super(),this.reportingConfigs=[],this.publicationIntervalSeconds=0,this.maxScopesPerRequest=0,this.stopPublicationForSeconds=0,this.debugInfos=[],s.proto3.util.initPartial(e,this)}static fromBinary(e,t){return(new de).fromBinary(e,t)}static fromJson(e,t){return(new de).fromJson(e,t)}static fromJsonString(e,t){return(new de).fromJsonString(e,t)}static equals(e,t){return s.proto3.util.equals(de,e,t)}}de.runtime=s.proto3,de.typeName="apex_metrics_web.RecordNamespace.RecordResponse",de.fields=s.proto3.util.newFieldList((()=>[{no:1,name:"reporting_configs",kind:"message",T:ce,repeated:!0},{no:3,name:"publication_interval_seconds",kind:"scalar",T:13},{no:4,name:"max_scopes_per_request",kind:"scalar",T:13},{no:5,name:"stop_publication_for_seconds",kind:"scalar",T:13},{no:6,name:"debug_infos",kind:"scalar",T:9,repeated:!0}]));class pe extends s.Message{constructor(e){super(),s.proto3.util.initPartial(e,this)}static fromBinary(e,t){return(new pe).fromBinary(e,t)}static fromJson(e,t){return(new pe).fromJson(e,t)}static fromJsonString(e,t){return(new pe).fromJsonString(e,t)}static equals(e,t){return s.proto3.util.equals(pe,e,t)}}pe.runtime=s.proto3,pe.typeName="apex_metrics_web.ApexMetricsCacheData",pe.fields=s.proto3.util.newFieldList((()=>[{no:1,name:"config",kind:"message",T:de},{no:2,name:"timeStored",kind:"message",T:a},{no:3,name:"state",kind:"message",T:fe}]));class me extends s.Message{constructor(e){super(),this.lastResult=!1,this.numTimesChecked=0,s.proto3.util.initPartial(e,this)}static fromBinary(e,t){return(new me).fromBinary(e,t)}static fromJson(e,t){return(new me).fromJson(e,t)}static fromJsonString(e,t){return(new me).fromJsonString(e,t)}static equals(e,t){return s.proto3.util.equals(me,e,t)}}me.runtime=s.proto3,me.typeName="apex_metrics_web.ApexMetricsCacheData.CoinState",me.fields=s.proto3.util.newFieldList((()=>[{no:1,name:"lastFlipTime",kind:"message",T:a},{no:2,name:"lastResult",kind:"scalar",T:8},{no:3,name:"numTimesChecked",kind:"scalar",T:13}]));class he extends s.Message{constructor(e){super(),s.proto3.util.initPartial(e,this)}static fromBinary(e,t){return(new he).fromBinary(e,t)}static fromJson(e,t){return(new he).fromJson(e,t)}static fromJsonString(e,t){return(new he).fromJsonString(e,t)}static equals(e,t){return s.proto3.util.equals(he,e,t)}}he.runtime=s.proto3,he.typeName="apex_metrics_web.ApexMetricsCacheData.NamespaceCoinState",he.fields=s.proto3.util.newFieldList((()=>[{no:1,name:"dropPeriodCoin",kind:"message",T:me},{no:2,name:"dropSamplesCoin",kind:"message",T:me}]));class fe extends s.Message{constructor(e){super(),this.filterID=0,this.namespaceCoinState={},s.proto3.util.initPartial(e,this)}static fromBinary(e,t){return(new fe).fromBinary(e,t)}static fromJson(e,t){return(new fe).fromJson(e,t)}static fromJsonString(e,t){return(new fe).fromJsonString(e,t)}static equals(e,t){return s.proto3.util.equals(fe,e,t)}}function ge(){return new me({lastFlipTime:void 0,lastResult:!1,numTimesChecked:0})}function ve(e){let t;if(e.stickiness&&e.stickiness.limit)switch(e.stickiness.limit.case){case"independent":t={".tag":"independent"};break;case"permanent":t={".tag":"permanent"};break;case"nResults":t={".tag":"n_results",n_results:e.stickiness.limit.value};break;case"nSeconds":t={".tag":"n_seconds",n_seconds:e.stickiness.limit.value}}return{fraction:null!==e.fraction?e.fraction:void 0,stickiness:t?{limit:t}:void 0}}fe.runtime=s.proto3,fe.typeName="apex_metrics_web.ApexMetricsCacheData.FilterState",fe.fields=s.proto3.util.newFieldList((()=>[{no:1,name:"filterID",kind:"scalar",T:13},{no:2,name:"namespaceCoinState",kind:"map",K:9,V:{kind:"message",T:he}}]));function we(e){let t;if(e.stickiness&&e.stickiness.limit)switch(e.stickiness.limit[".tag"]){case"independent":t={limit:{case:"independent",value:new c}};break;case"permanent":t={limit:{case:"permanent",value:new c}};break;case"n_results":t={limit:{case:"nResults",value:e.stickiness.limit.n_results}};break;case"n_seconds":t={limit:{case:"nSeconds",value:e.stickiness.limit.n_seconds}}}return new le({fraction:e.fraction,stickiness:t?new ue(t):void 0})}function Se(e,t,s){if(!t.stickiness||!t.stickiness.limit)return{nextState:s,result:!1};const i=Date.now()/1e3,{lastFlipTime:r=a.fromDate(new Date(0)),lastResult:o,numTimesChecked:c=0}=s;let l=!1;switch(t.stickiness.limit[".tag"]){case"n_results":l=null===c||c%t.stickiness.limit.n_results==0;break;case"n_seconds":if(!r){l=!0;break}l=u.toMilliseconds({value:i-(d=r.seconds,Number(d.toString())),unit:n.TimeUnit.SECONDS})>u.toMilliseconds({value:t.stickiness.limit.n_seconds,unit:n.TimeUnit.SECONDS});break;case"permanent":l=0===c;break;case"independent":l=!0;break;default:return{nextState:s,result:!1}}var d;if(l){const n=e()<(t.fraction||0);return{nextState:new me({lastFlipTime:a.fromDate(new Date(1e3*i)),lastResult:n,numTimesChecked:c?c+1:1}),result:n}}return{nextState:new me(Object.assign(Object.assign({},s),{numTimesChecked:c?c+1:1})),result:!!o}}async function _e(e,t){let n=null;if("undefined"!=typeof crypto&&crypto.subtle&&"undefined"!=typeof TextEncoder){const e=new TextEncoder,s=await crypto.subtle.digest("SHA-256",e.encode(t));n=new Uint32Array(s).reduce(((e,t)=>e^t))}return null===n?0:((n^e)>>>0)/4294967296}class be{constructor(e,t,n,s,i,r){this.filterID=e,this.randomEngine=t,this.clock=n,this.maxScopes=s,this.namespaceMap=i,this.configuredNamespaces=r}extend(e,t,n){return new be(this.filterID,this.randomEngine,this.clock,e||this.maxScopes,Object.assign(Object.assign({},this.namespaceMap),t),n)}getState(){const e={filterID:this.filterID,namespaceCoinState:{}};for(const t in this.namespaceMap)this.namespaceMap.hasOwnProperty(t)&&(e.namespaceCoinState[t]=new he({dropPeriodCoin:this.namespaceMap[t].dropPeriodCoin?new me(Object.assign({},this.namespaceMap[t].dropPeriodCoin.state)):void 0,dropSamplesCoin:this.namespaceMap[t].dropSamplesCoin?new me(Object.assign({},this.namespaceMap[t].dropSamplesCoin.state)):void 0}));return new fe(e)}getConfiguredNamespaces(){return this.configuredNamespaces}async partitionAndSerializeSpans(e,t,n,s){return new Promise(((i,r)=>{const o=[];let a=0;const c=new Map;let l,u=0;const d=new Set;try{l=e.transaction([K,V],"readwrite")}catch(e){if(e instanceof DOMException&&("InvalidStateError"===e.name||11===e.code))return void i({scopes:[],storedNamespaces:d,spansRetained:0,samplesRetainedByNs:new Map,observationsRetained:0});throw e}const p=new Map,m=new Set;l.addEventListener("complete",(()=>i({scopes:o,storedNamespaces:d,spansRetained:a,samplesRetainedByNs:c,observationsRetained:u}))),l.addEventListener("error",(e=>r(e)));const h=[{storeName:K,serializeSamplesFunc:(e,t,n,i,r)=>{var o;s.includes(i)||(a+=r,c.set(i,(null!==(o=c.get(i))&&void 0!==o?o:0)+n.length)),function(e,t,n){t.metrics.push({name:{value:{".tag":"string_value",string_value:e}},data:{".tag":"numerical_data",samples:n}})}(e,t,n)}},{storeName:V,serializeSamplesFunc:(e,t,n,i,r)=>{s.includes(i)||(u+=n.length),function(e,t,n){n.length>80?t.metrics.push({name:{value:{".tag":"string_value",string_value:e}},data:{".tag":"set_data",hyperloglog:{registers:new C(n).compressed()}}}):t.metrics.push({name:{value:{".tag":"string_value",string_value:e}},data:{".tag":"set_data",samples:n}})}(e,t,n)}}];for(const{storeName:e,serializeSamplesFunc:s}of h){const i=l.objectStore(e);let a;try{a=i.index(Z)}catch(e){return void r(e)}const c=a.count();c.addEventListener("success",(()=>{if(0===c.result)return;const e=a.openKeyCursor(null,"nextunique");e.addEventListener("success",(async()=>{var a;const c=e.result;if(!c)return;const l=c.key;if(0!==this.maxScopes&&o.length===this.maxScopes&&!m.has(l))return;if(d.add(l),!this.configuredNamespaces.has(l))return void c.continue();const{dropPeriodCoin:u,dropSamplesCoin:h,dropFractionOfHostsPerMetric:f}=this.namespaceMap[l]||{};let g;try{g=await W(i,l)}catch(e){return void r(e)}if(u){const{result:e,nextState:t}=Se(this.randomEngine,u.config,u.state);if(u.state=t,e)return i.delete(g),void c.continue()}const v=null!==(a=p.get(l))&&void 0!==a?a:{metric_namespace:l,timestamp_sec:n,tags:L(t),descendants:[]};p.set(l,v);const w=i.openCursor(g);w.addEventListener("success",(async()=>{const e=w.result;if(!e)return v.descendants.length>0&&!m.has(l)&&(o.push(v),m.add(l)),void c.continue();const t={tags:q(e.value.tagNames,e.value.tagValues),metrics:[],user_id_association:{".tag":"fs_v2_unknown"}},n=e.value.spans;for(const e in n){if(!n.hasOwnProperty(e))continue;if(f){if(await _e(this.filterID,e){const{result:t,nextState:n}=Se(this.randomEngine,h.config,h.state);return h.state=n,!t}))),0===i.length)continue;const r=n[e].spanCount;s(e,t,i,l,r)}t.metrics.length>0&&v.descendants.push(t),e.delete(),e.continue()}))}))}))}}))}}var ye;!function(e){e.ALLOWED="allowed",e.DENIED="denied"}(ye||(ye={}));const ke={".tag":"trigger_heartbeat"},Ee={".tag":"trigger_publish"},xe=5e3,Ne=e=>Number(e.toString()),Oe=["Fetch network failure","invalid_csrf_token","invalid_logged_out_cookie","request canceled","user_not_logged_in","AdGuard","Adguard","AdBlocker","Detected and blocked","too_many_requests"],Ce=30,De="UNCONFIGURED";function Te(e,t,n,s,i){const r=[];return t.forEach((e=>r.push(e))),{scopes:e,known_namespaces:r,environment:"prod",artifact_name:"dropbox-web",artifact_version:"0000000000000000000000000000000000000000",client_metadata:{client_version:Ce,implementation:{".tag":"typescript"}},trigger:n,os:s,origin_identifier:i}}function Me(e,t,n){return async(i,r)=>{var o;let a=[];if(i){const e=function(e,t){const n=e.getItem(Ie);if(null===n)return null;const i=Date.now()/1e3;let r,o=[];try{r=function(e,t){const n=s.protoBase64.dec(e);return t.fromBinary(n)}(n,pe)}catch(e){return t.reportException({err:e,tags:["js:web:amp-sink","js:web:amp-sink/local-storage"],severity:"non-critical"}),null}if(!r.config||!r.state||!r.timeStored)return t.reportStack("Sink cache was missing data",{tags:["js:web:amp-sink","js:web:amp-sink/local-storage"]}),null;const a=i-Ne(r.timeStored.seconds);if(a<0)return t.reportStack("Sink cache was stored in the future instead of the past",{tags:["js:web:amp-sink","js:web:amp-sink/local-storage"],exc_extra:{cacheDataAge:a}}),null;const c={};r.config&&(o=r.config.reportingConfigs.map((e=>e.metricNamespace)),c.reporting_configs=r.config.reportingConfigs?r.config.reportingConfigs.filter((e=>a({metric_namespace:e.metricNamespace,max_time_until_refresh_seconds:e.maxTimeUntilRefreshSeconds,stop_publication_for_seconds:e.stopPublicationForSeconds,drop_samples:e.dropSamples?ve(e.dropSamples):void 0,drop_periods:e.dropPeriods?ve(e.dropPeriods):void 0,drop_fraction_of_hosts_per_metric:e.dropFractionOfHostsPerMetric,aggregation_interval_seconds:e.aggregationIntervalSeconds}))):[],c.publication_interval_seconds=r.config.publicationIntervalSeconds,c.max_scopes_per_request=r.config.maxScopesPerRequest,c.stop_publication_for_seconds=r.config.stopPublicationForSeconds,c.debug_infos=r.config.debugInfos);return{config:c,state:r.state,knownNamespaces:o}}(i,n);if(e){a=e.knownNamespaces;const t=new Set;e.config.reporting_configs.forEach((e=>t.add(e.metric_namespace)));if(!a.some((e=>!t.has(e))))return e}}const c=new Set;a.forEach((e=>c.add(e)));const l=t.detectOS(),u=await e();let d=null;try{d=await u.clientMetricsRecord(Te([],c,ke,l,r))}catch(e){const t=e;Oe.some((e=>{var n;return null===(n=null==t?void 0:t.message)||void 0===n?void 0:n.includes(e)}))||n.reportException({err:t,tags:["js:web:amp-sink"],severity:"operational"})}const p=null!==(o=null==d?void 0:d.result)&&void 0!==o?o:null,m=Math.floor(4294967296*Math.random())>>>0;return{knownNamespaces:a,config:p,state:new fe({filterID:m,namespaceCoinState:{}})}}}const Ie="amp-sink-cache";function Pe(){return()=>{try{return window.localStorage||null}catch(e){return null}}}const Fe="amp-sink-origin-id";function Re(e,t,n){try{const r=Math.floor(Date.now()/1e3),o=new pe({config:new de({reportingConfigs:t.reporting_configs?t.reporting_configs.map((e=>new ce({metricNamespace:e.metric_namespace,maxTimeUntilRefreshSeconds:e.max_time_until_refresh_seconds,stopPublicationForSeconds:e.stop_publication_for_seconds,dropSamples:e.drop_samples?we(e.drop_samples):void 0,dropPeriods:e.drop_periods?we(e.drop_periods):void 0,dropFractionOfHostsPerMetric:e.drop_fraction_of_hosts_per_metric,aggregationIntervalSeconds:e.aggregation_interval_seconds}))):[],publicationIntervalSeconds:t.publication_interval_seconds,maxScopesPerRequest:t.max_scopes_per_request,stopPublicationForSeconds:t.stop_publication_for_seconds,debugInfos:t.debug_infos||[]}),timeStored:a.fromDate(new Date(1e3*r)),state:n});e.setItem(Ie,(i=o,s.protoBase64.enc(i.toBinary())))}catch(e){}var i}function Be(e){return{clientMetricsRecord:t=>{return(n=e,n.ns("client_metrics")).rpc("record",t,{}).then((e=>({result:e})));var n}}}function Le(e){return{clientMetricsRecord:t=>e("/api/2/client_metrics/record",{method:"POST",body:JSON.stringify(t)}).then((e=>{if(e.ok)return e.json().then((e=>e));throw new Error(e.statusText)}))}}function qe(e){return{clientMetricsRecord:t=>e.clientMetricsRecord(t).then((e=>({result:e.result})))}}class Ae{emit(e,...t){return!0}}class je{constructor(e,t,n,s,i,r,o,a,c,l,u,d=new Ae){this.clientFactory=e,this.clock=t,this.initializer=n,this.cacheFactory=s,this.executor=i,this.randomEngine=r,this.databaseFactory=o,this.platformDetector=a,this.excReporter=c,this.originKind=l,this.eventEmitter=d,this.nextRequest=null,this.spanGroupFilter=null,this.knownNamespaces=new Set,this.bufferedSpans=[],this.bufferedSetSpans=[],this.instrumentation=j.empty(),this.blackoutCallback=null,this.publishTimer=null,this.database=null,this.initializationFailed=!1,this.cache=this.cacheFactory(),this.originIdentifier=function(e,t){if(e){let n=e.getItem(Fe);return null===n&&(n=t(),e.setItem(Fe,n)),n}return""}(this.cache,u),this.currentRequest=this.initializer(this.cache,this.originIdentifier).then((e=>(null==e?void 0:e.config)?(this.updateConfiguration(e.config,e.state),this.eventEmitter.emit("initialized"),e.config):(this.initializationFailed=!0,null)))}getOriginId(){return this.originIdentifier}updateConfiguration(e,t){const{reporting_configs:s=[],stop_publication_for_seconds:i,publication_interval_seconds:r}=e,o=new Set;s.forEach((e=>{this.knownNamespaces.add(e.metric_namespace),o.add(e.metric_namespace)})),this.updateBlackoutCallback({value:i,unit:n.TimeUnit.SECONDS}),this.updatePublishTimer({value:r,unit:n.TimeUnit.SECONDS}),this.updateSpanGroupFilter(e,t,o),this.cache&&Re(this.cache,e,t)}updateSpanGroupFilter(e,t,n){const{reporting_configs:s=[],max_scopes_per_request:i}=e,r=new Set,o=n.values();for(let e=o.next();!e.done;e=o.next())r.add(e.value);const a=function(e,t){const n={};for(const s of e){const e=s.metric_namespace;n[e]={dropFractionOfHostsPerMetric:s.drop_fraction_of_hosts_per_metric||null,dropPeriodCoin:s.drop_periods?{config:s.drop_periods,state:t.namespaceCoinState&&t.namespaceCoinState[e]&&t.namespaceCoinState[e].dropPeriodCoin||ge()}:null,dropSamplesCoin:s.drop_samples?{config:s.drop_samples,state:t.namespaceCoinState&&t.namespaceCoinState[e]&&t.namespaceCoinState[e].dropSamplesCoin||ge()}:null}}return n}(s,t);this.spanGroupFilter=this.spanGroupFilter?this.spanGroupFilter.extend(i,a,r):new be(t.filterID,this.randomEngine,this.clock,i,a,r)}updateBlackoutCallback(e){0!==e.value?(this.blackoutCallback=()=>(this.blackoutCallback=null,this.eventEmitter.emit("publicationResumed"),!1),this.eventEmitter.emit("publicationPaused"),this.executor.executeEvery(e,this.blackoutCallback)):this.blackoutCallback=null}updatePublishTimer(e){const t=e.unit===n.TimeUnit.SECONDS?e.value:u.toMilliseconds(e)/1e3;if(0===e.value)return void(this.publishTimer=null);if(this.publishTimer&&u.toMilliseconds(this.publishTimer.period)===u.toMilliseconds(e))return;const s={period:e,callback:()=>this.publishTimer===s&&(this.nextRequest=this.currentRequest.then((async()=>{this.nextRequest=null;const e=Math.floor(Date.now()/1e3),n=await this.getDB();if(n)try{const s=await function(e,t,n){return new Promise((async(s,i)=>{let r;try{r=e.transaction(H,"readwrite").objectStore(H)}catch(e){if(e instanceof DOMException&&("InvalidStateError"===e.name||11===e.code))return void s(!1);throw e}const o=r.get(G);o.addEventListener("success",(()=>{const e=o.result;if(e&&t-+e.value{s(!0)})),a.addEventListener("error",(e=>{i(e)}))})),o.addEventListener("error",(e=>{i(e)}))}))}(n,e,t);s&&(this.currentRequest=this.send())}catch(e){this.excReporter.reportException({err:e,tags:["js:web:amp-sink"],severity:"operational"})}})),!0)};this.publishTimer=s,this.executor.executeEvery(this.publishTimer.period,this.publishTimer.callback)}async send(){var e;if(this.blackoutCallback)return this.eventEmitter.emit("publish",ye.DENIED),null;const t=Math.floor(Date.now()/1e3),n={browser:this.platformDetector.detectBrowser()},s=await this.getDB();if(!s)return null;let i,r,o,a,c;try{({scopes:i,storedNamespaces:r,spansRetained:o,samplesRetainedByNs:a,observationsRetained:c}=await this.spanGroupFilter.partitionAndSerializeSpans(s,n,t,[A]))}catch(e){return this.excReporter.reportException({err:e,tags:["js:web:amp-sink"],severity:"operational"}),null}let l=j.empty();l.retainedSpans+=o;let u=0;a.forEach(((e,t)=>{j.incrementRetainedSamples(l,t,e),u+=e}));let d=i.length>0;if(this.knownNamespaces.forEach((e=>r.add(e))),!d){const e=this.spanGroupFilter.getConfiguredNamespaces(),t=r.values();for(let n=t.next();!n.done;n=t.next())if(!e.has(n.value)){d=!0;break}}let p=null;if(d){l=await ie(s,l);const t=this.platformDetector.detectOS(),a=Te(i,r,Ee,t,this.originIdentifier),d=this.clock.now();l.requestAttempts++;try{const s=await this.clientFactory();p=(null===(e=await s.clientMetricsRecord(a))||void 0===e?void 0:e.result)||null,l=await this.reportInstrumentation(t,l,d,n)}catch(e){l.requestDroppedSpans+=o,l.requestDroppedSamples+=u,l.requestDroppedSetObservations+=c}p&&this.updateConfiguration(p,this.spanGroupFilter.getState())}return await se(s,l),this.eventEmitter.emit("publish",ye.ALLOWED),p}async reportInstrumentation(e,t,n,s){const i=u.toMilliseconds(this.clock.now())-u.toMilliseconds(n);if(function(e){return!!e.name&&("android"===e.name[".tag"]||"ios"===e.name[".tag"])}(e))try{const n=Object.assign({client_version:Ce.toString(),origin_kind:this.originKind},s),r=j.toScope(t,this.originIdentifier,i,n),o=Te([r],new Set([A]),Ee,e,this.originIdentifier),a=await this.clientFactory();return await a.clientMetricsRecord(o),j.empty()}catch(e){return t}return j.report(t,T.root(this,this.clock,this.originIdentifier),i,Ce,this.originKind)}async getDB(){return this.database||(this.database=await this.databaseFactory()),this.database}recordSpan(e){if(this.initializationFailed)return;if(e.namespace!==A){let t=De;this.spanGroupFilter&&this.spanGroupFilter.getConfiguredNamespaces().has(e.namespace)&&(t=e.namespace),this.instrumentation.submittedSpans++,j.incrementSubmittedSamples(this.instrumentation,t,e.samples.length)}this.knownNamespaces.add(e.namespace);this.bufferedSpans.length>=xe?(console.warn("bufferedSpans hit limit of BUFFERED_SPANS_MAX (5000), dropping incoming until buffer is below limit"),this.instrumentation.overflowSpans++,this.instrumentation.overflowSamples+=e.samples.length):this.bufferedSpans.push(e),this.maybeScheduleNextRequest()}recordSetSpan(e){if(this.initializationFailed)return;if(e.namespace!==A){let t=De;this.spanGroupFilter&&this.spanGroupFilter.getConfiguredNamespaces().has(e.namespace)&&(t=e.namespace),j.incrementSetObservations(this.instrumentation,t,e.samples.length)}this.knownNamespaces.add(e.namespace);this.bufferedSetSpans.length>=xe?console.warn("bufferedSetSpans hit limit of BUFFERED_SPANS_MAX (5000), dropping incoming until buffer is below limit"):this.bufferedSetSpans.push(e),this.maybeScheduleNextRequest()}cloneInstrumentation(){return j.merge(this.instrumentation,j.empty())}maybeScheduleNextRequest(){this.nextRequest||(this.nextRequest=this.currentRequest.then((async()=>{if(this.initializationFailed)return;const e=await this.getDB();if(!e)return;const t=this.bufferedSpans,n=this.bufferedSetSpans;this.bufferedSpans=[],this.bufferedSetSpans=[];const s=this.instrumentation;this.instrumentation=j.empty();try{await Promise.all([ee(e,t),te(e,n),se(e,s)])}catch(e){this.excReporter.reportException({err:e,tags:["js:web:amp-sink"],severity:"operational"})}this.publishTimer||(this.currentRequest=this.send()),this.nextRequest=null})))}}function Je(){return n.mac?{name:{".tag":"mac"},version:"unknown"}:n.windows?{name:{".tag":"windows"},version:(e=n.windowsInfo,e.windowsXP||e.windowsXPx64?"XP":e.windowsVista?"Vista":e.windows7?"7":e.windows8?"8":e.windows8_1?"8.1":e.windows10?"10 Unknown":"unknown")}:n.is_android()?{name:{".tag":"android"},version:"unknown"}:n.iOS?{name:{".tag":"ios"},version:"unknown"}:{name:{".tag":"unknown_os"},version:"unknown"};var e}function Ue(){return new l}const ze=Pe(),Ke=new B;function Ve(e){var t;const s="undefined"!=typeof window?window:globalThis;let i;i="clientFactory"in e?e.clientFactory:"client"in e?()=>Promise.resolve(Be(e.client)):"sdk"in e?()=>Promise.resolve(qe(e.sdk)):()=>Promise.resolve(Le(e.fetch));let{exceptionReporter:r,identifierFactory:o,originKind:a}=e;const c=null===(t=s.sinkSingleton)||void 0===t?void 0:t.clientFactory;if(void 0!==c&&(i=c),void 0===r&&(r={reportException:e=>{},reportStack:(e,t)=>{}}),void 0===o&&(o=()=>""),void 0===a&&(a="unknown"),s.sinkSingleton)return s.sinkSingleton.clientFactory=i,s.sinkSingleton;const l={detectBrowser:n.getBrowserShortName,detectOS:Je},u=new je(i,Ue(),Me(i,l,r),ze,new d((()=>({value:5*Math.random(),unit:n.TimeUnit.SECONDS}))),Math.random,Q,l,r,a,o);return s.sinkSingleton=u,u}var Ze={exports:{}};!function(e){var t=Object.prototype.hasOwnProperty,n="~";function s(){}function i(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function r(e,t,s,r,o){if("function"!=typeof s)throw new TypeError("The listener must be a function");var a=new i(s,r||e,o),c=n?n+t:t;return e._events[c]?e._events[c].fn?e._events[c]=[e._events[c],a]:e._events[c].push(a):(e._events[c]=a,e._eventsCount++),e}function o(e,t){0==--e._eventsCount?e._events=new s:delete e._events[t]}function a(){this._events=new s,this._eventsCount=0}Object.create&&(s.prototype=Object.create(null),(new s).__proto__||(n=!1)),a.prototype.eventNames=function(){var e,s,i=[];if(0===this._eventsCount)return i;for(s in e=this._events)t.call(e,s)&&i.push(n?s.slice(1):s);return Object.getOwnPropertySymbols?i.concat(Object.getOwnPropertySymbols(e)):i},a.prototype.listeners=function(e){var t=n?n+e:e,s=this._events[t];if(!s)return[];if(s.fn)return[s.fn];for(var i=0,r=s.length,o=new Array(r);i{this.isUnload()||this.flushToInner()},this.persistor=new We(this.cacheFactory()),this.listener=new Ye(this.onUnloadChange),this.onUnloadChange()}flushToInner(){this.persistor.getAllAndClear().forEach((e=>{this.recordSpanToInner(e)}))}isUnload(){return Boolean(this.listener.isUnload)}recordSpan(e){if(this.isUnload())return this.persistor.persistSpans([e]),void this.eventEmitter.emit("spansPersistedInUnload");this.recordSpanToInner(e)}recordSetSpan(e){}recordSpanToInner(e){const t={...e,fromUnloadSink:!0};this.innerSink.recordSpan(t)}}class Ye{constructor(e){this.onUnloadChange=e,this._isUnload=!1,this.listenForNavigationChanges()}get isUnload(){return this._isUnload}set isUnload(e){this._isUnload!==e&&(this._isUnload=e,this.onUnloadChange())}listenForNavigationChanges(){if("undefined"!=typeof window&&"function"==typeof window.addEventListener&&"function"==typeof document.addEventListener){const e=()=>{"hidden"===document.visibilityState?this.isUnload=!0:"visible"===document.visibilityState&&(this.isUnload=!1)},t=()=>{this.isUnload=!0,window.removeEventListener("pagehide",t),document.removeEventListener("visibilitychange",e)};window.addEventListener("pagehide",t),document.addEventListener("visibilitychange",e)}}}class We{constructor(e){this.cache=e,this.CACHE_KEY="amp-persisted-spans-v2",this.OLD_CACHE_KEY="amp-persisted-spans"}getAllAndClear(){if(!this.cache)return[];const e=this.retrieveSpans();try{this.cache.setItem(this.CACHE_KEY,JSON.stringify([])),this.cache.removeItem(this.OLD_CACHE_KEY)}catch(e){}return e}persistSpans(e){if(!this.cache||!e)return;const t=this.retrieveSpans();t.push(...e);try{this.cache.setItem(this.CACHE_KEY,JSON.stringify(t))}catch(e){}}retrieveSpans(){let e=[];try{e=JSON.parse(this.cache.getItem(this.CACHE_KEY))}catch(e){}return e||[]}}const Xe=(()=>{let e,t;const n=[];for(t=0,e=t;t<=255;t++,e=t)n.push((e+256).toString(16).substr(1));return n})();class Qe{static bytesToHex(e){return e.map((e=>Xe[e])).join("")}static toByte(e){return 255&e}static bytesToUUIDString(e){return[e.slice(0,4),e.slice(4,6),e.slice(6,8),e.slice(8,10),e.slice(10,16)].map((e=>this.bytesToHex(e))).join("-")}static getRandomBytes(){const e=new Array(16);return this.getInsecureRandomValues(e),e.map((e=>this.toByte(e)))}static getInsecureRandomValues(e){const t=Math.pow(2,8);for(let n=0;n{var e;const t=await o.getFenixWindow();return"function"!=typeof(null===(e=null==t?void 0:t.controller)||void 0===e?void 0:e.logAmisEvent)?null:{logAmisEvent:t.controller.logAmisEvent}},tt=async(e,t)=>{e.logAmisEvent(t)};const nt=new class{recordSpan(e){et().then((t=>{t&&tt(t,e)}))}recordSetSpan(e){}};function st(){return new l}async function it(){const{UnAuthedApiV2Client:t}=await new Promise((function(t,n){e(["./c_api_v2_unauthed_client"],t,n)}));return Be(new t)}function rt(){return()=>Qe.v4()}const ot=Pe(),at="metaserver";const ct=new class{constructor(){this.spans=[],this.bridgeInitialized=!1}recordSpan(e){this.spans.push(e),this.bridgeInitialized||this.initializeBridgeSink()}recordSetSpan(e){}async initializeBridgeSink(){this.bridgeInitialized=!0;const t=await new Promise((function(t,n){e(["./c_server_side_client_view_bridge"],t,n)}));await t.IsBridgeFunctionSupported("reportMetricsV2")?(setInterval((()=>{this.spans.length>0&&(t.ReportMetrics(this.spans),this.spans=[])}),5e3),window.addEventListener("beforeunload",(()=>{this.spans.length>0&&(console.log(`Attempting to send ${this.spans.length} pending AMP spans`),t.ReportMetrics(this.spans),this.spans=[])}))):setInterval((function(){this.spans=[]}),6e4)}},lt=new B;function ut(){const e=Ve({clientFactory:it,exceptionReporter:r.JSException,identifierFactory:rt(),originKind:at});return"undefined"!=typeof window&&(null===window||void 0===window?void 0:window.EDISON_LOCALMODE)?T.root(lt,st(),e.getOriginId()):void 0!==window._clientBridge?T.root(ct,st(),e.getOriginId()):void 0!==window.fenixInitializationComplete?T.root(nt,st(),e.getOriginId()):T.root(e,st(),e.getOriginId())}function dt(){const e=Ve({clientFactory:it,exceptionReporter:r.JSException,identifierFactory:rt(),originKind:at}),t=function(e){void 0===e&&(e=it);const t=Ve({clientFactory:e,originKind:at});if(window.unloadSinkSingleton)return window.unloadSinkSingleton;const n=new $e(ot,t);return window.unloadSinkSingleton=n,n}();return T.root(t,st(),e.getOriginId())}var pt=Object.freeze({__proto__:null,getMetricsReporter:ut,getUnloadMetricsReporter:dt});t.BrowserPerformanceClock=l,t.Empty=c,t.EventEmitter=Ge,t.InsecureUUID=Qe,t.Instant=u,t.Timestamp=a,t.clientBaseAdaptor=Be,t.clientFetchAdaptor=Le,t.clientSDKAdaptor=qe,t.getFenixAmisEnvironment=et,t.getFenixLoggingEnvironment=async()=>{var e;const t=await o.getFenixWindow();return"function"!=typeof(null===(e=null==t?void 0:t.controller)||void 0===e?void 0:e.logEvent)?null:{logEvent:t.controller.logEvent}},t.getFenixPAPEnvironment=async()=>{var e;const t=await o.getFenixWindow();return"function"!=typeof(null===(e=null==t?void 0:t.controller)||void 0===e?void 0:e.logPAPEvent)?null:{logPAPEvent:t.controller.logPAPEvent}},t.getMetricsReporter=ut,t.getMetricsReporter$1=function(e){const t=Ve(e),n="undefined"!=typeof window&&(null===window||void 0===window?void 0:window.EDISON_LOCALMODE)?Ke:t;return T.root(n,Ue(),t.getOriginId())},t.getUnloadMetricsReporter=dt,t.index_esnext=pt,t.logAmisEventToDesktop=tt,t.logEventToDesktop=async(e,t,n)=>{e.logEvent(t,n)},t.logPAPEventToDesktop=async(e,t)=>{e.logPAPEvent(t)}})); //# sourceMappingURL=c_src_sink_index.js-vfl-CyQoy.map //# debugId=9f2db6ad-60cb-39ae-9f83-28a9b53da1f4