o11y 2.1.2 → 236.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/modules/o11y/client/client.js +1 -1
- package/dist/modules/o11y/client/client.js.map +1 -1
- package/dist/modules/o11y/client/library/AppInstrumentationImpl.d.ts +2 -0
- package/dist/modules/o11y/client/library/InstrumentationImpl.d.ts +3 -0
- package/dist/modules/o11y/client/library/MetricsImpl.d.ts +2 -2
- package/dist/modules/o11y/collectors/collectors.js +1 -1
- package/dist/modules/o11y/collectors/collectors.js.map +1 -1
- package/dist/modules/o11y/collectors/library/AppInstrumentationImpl.d.ts +2 -0
- package/dist/modules/o11y/collectors/library/InstrumentationImpl.d.ts +3 -0
- package/dist/modules/o11y/collectors/library/MetricsImpl.d.ts +2 -2
- package/dist/modules/o11y/shared/library/AppInstrumentationImpl.d.ts +2 -0
- package/dist/modules/o11y/shared/library/InstrumentationImpl.d.ts +3 -0
- package/dist/modules/o11y/shared/library/MetricsImpl.d.ts +2 -2
- package/package.json +2 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{utility as t,schemaUtil as e}from"o11y/shared";class PublicSafety{constructor(t){this._errorCounter=t,this._safeCatchMode=!1}tryCatch(t){try{t()}catch(t){this._prodSafeCatch(t)}}tryCatchReturn(e,r){try{return t.requireArgument(r,"noopValue"),e()}catch(t){return this._prodSafeCatch(t),r}}_prodSafeCatch(e){let r;try{if(r=!t.isProduction,r)throw e;if(this._safeCatchMode)throw this._safeCatchMode=!1,new Error("Internal error in prodSafeCatch.");if(this._safeCatchMode=!0,this._errorCounter&&this._errorCounter.increment(),!(e instanceof Error)){const t=e&&e.message||("function"==typeof e.toString?e.toString():"");e=new Error(t)}this._safeCatchMode=!1}catch(t){if(r)throw t;if(t&&console&&"function"==typeof console.error)try{console.error(t)}catch(t){}this._safeCatchMode=!1}}}class Tracing{constructor(e){this.instr=e,t.requireArgument(e,"instr","object")}static _getB3CompactFormat(t,e,r,i){let s=`${t}-${e}`;return void 0===r&&void 0===i||(s+=r?"-1":"-0",void 0!==i&&(s+=`-${i}`)),s}static _getW3CompactFormat(t,e,r){return`00-${t}-${e}-${r?"01":"00"}`}static _conformTextAsId(t,e){const r=(t=t.toLowerCase()).length;for(let e=0;e<r;e+=1){const r=t[e];if(!(r>="a"&&r<="f"||r>="0"&&r<="9"))throw new Error(`The text '${t}' has an invalid character at index #${e}`)}return r>e?t.substr(r-e):r<e?t.padStart(e,"0"):t}static getHeaders(e,r,i,s){t.requireArgument(e,"traceId","string"),t.requireArgument(r,"spanId","string");const n=s&&s.useB3Headers;e=this._conformTextAsId(e,s&&void 0!==s.traceIdEffectiveLength?s.traceIdEffectiveLength:n?16:32),r=this._conformTextAsId(r,16);const o=s&&void 0!==s.parentSpanId&&this._conformTextAsId(s.parentSpanId,16)||void 0,a={};if(n){s&&s.useCompactHeader?a.b3=this._getB3CompactFormat(e,r,i,o):(a["X-B3-TraceId"]=e,a["X-B3-SpanId"]=r,void 0!==o&&(a["X-B3-ParentSpanId"]=o),void 0!==i&&(a["X-B3-Sampled"]=i?"1":"0"))}else a.traceparent=this._getW3CompactFormat(e,r,i);return a}_disableNetworkInstrumentation(){Tracing._isNetworkInstrumentationEnabled&&(Tracing._originalFetch&&(Tracing._global.fetch=Tracing._originalFetch,Tracing._originalFetch=void 0),Tracing._originalXhr&&(Tracing._global.XMLHttpRequest=Tracing._originalXhr,Tracing._originalXhr=void 0),Tracing._originalXhrSend&&(Tracing._global.XMLHttpRequest.prototype.send=Tracing._originalXhrSend,Tracing._originalXhrSend=void 0),Tracing._isNetworkInstrumentationEnabled=!1)}_enableNetworkInstrumentation(t,e,r,i,s){"function"==typeof Tracing._global.fetch&&(this._overrideFetch(t,e,r,i,s),Tracing._isNetworkInstrumentationEnabled=!0),"function"==typeof Tracing._global.XMLHttpRequest&&(this._overrideXhr(t,e,r,i,s),Tracing._isNetworkInstrumentationEnabled=!0)}_overrideFetch(t,e,r,i,s){Tracing._originalFetch=Tracing._global.fetch;Tracing._global.fetch=async(n,o,...a)=>{let c;try{if(c=t.startActivity(r||"fetch"),i){o=o||{};const t=c.getTraceHeaders(s);o.headers=Object.assign(o.headers||{},t)}return await Tracing._originalFetch.call(Tracing._global,n,o,...a)}catch(r){throw e&&(c?c.error(r):t.error(r)),r}finally{c&&c.stop()}}}_overrideXhr(t,e,r,i,s){Tracing._originalXhr=Tracing._global.XMLHttpRequest,Tracing._originalXhrSend=Tracing._originalXhr.prototype.send,Tracing._originalXhr.prototype.send=function(...n){let o;const a=this;try{if(a._o11yActivity=o=t.startActivity(r||"xhr_send"),i){const t=o.getTraceHeaders(s);Object.entries(t).forEach((t=>{a.setRequestHeader(t[0],t[1])}))}Tracing._originalXhrSend.call(this,...n)}catch(r){throw e&&(o?o.error(r):t.error(r)),o&&o.stop(),r}};const n=new Proxy(Tracing._originalXhr,{construct(r){const i=new r;return i.addEventListener("load",(()=>{const t=i._o11yActivity;t&&t.stop()})),i.addEventListener("error",(r=>{const s=new Error("XHR Network-Level Error"),n=i._o11yActivity;n?(e&&n.error(s),n.stop()):e&&t.error(s)})),i.addEventListener("abort",(()=>{const t=i._o11yActivity;t&&t.discard()})),i}});Tracing._global.XMLHttpRequest=n}networkInstrumentation(e){if(t.requireArgument(e,"options",["boolean","object"]),e){this._disableNetworkInstrumentation();const r="object"==typeof e?e:{};this._enableNetworkInstrumentation(t.definedValueOrDefault(r.instrumentation,this.instr),t.definedValueOrDefault(r.logErrors,!0),r.activityName,t.definedValueOrDefault(r.useTracing,!0),r.tracingHeadersOptions)}else this._disableNetworkInstrumentation()}}Tracing._global=t.getGlobal(),Tracing._isNetworkInstrumentationEnabled=!1;const r="timedout",i="terminated",s="discarded";class ActivityImpl{constructor(e,i,s,n,o,a,c){this._name=e,this._rootId=i,this._onStopped=s,this._onError=n,this._isSampled=c,this._errorCount=0;const{tsNow:l,perfNow:h}=t.time();if(ActivityImpl._count+=1,this._id=a||t.generateUniqueId(),this._usePerf="undefined"!=typeof performance&&"function"==typeof performance.mark&&"function"==typeof performance.measure,this._usePerf){this._perfName=`${this._name}__${ActivityImpl._count}`,this._perfId=`${this._name}__${this.id}`;try{performance.mark(this._perfId)}catch(t){this._usePerf=!1}}this._startTimestamp=l,this._startPerfTime=h,o>0&&(this._timer=setTimeout((()=>{this._stopReason=this._stopReason||r,this.stop()}),o)),this._safety=new PublicSafety}get id(){return this._id}getId(){return this.id}getRootId(){return this._rootId}get stopReason(){return this._stopReason}error(t,e,r){this._safety.tryCatch((()=>{this._errorCount+=1,"string"==typeof t&&(t=new Error(t)),this._onError(t,this._getDetail(e,r))}))}stop(t,e){this._safety.tryCatch((()=>this._stopInternal(t,e)))}_stopInternal(e,r){const i=t.perfNow();if(this._usePerf)try{performance.measure(this._perfName,this._perfId),performance.clearMarks(this._perfId),performance.clearMeasures(this._perfName)}catch(t){}if(this._timer&&(clearTimeout(this._timer),this._timer=void 0),this.isStopped)return;this._stopPerfTime=i;const s=this._getDetail(e,r);this._onStopped(s)}get isStopped(){return void 0!==this._stopPerfTime}discard(){this._safety.tryCatch((()=>{this._stopReason=this._stopReason||s,this.stop()}))}terminate(){this._safety.tryCatch((()=>{this._stopReason=this._stopReason||i,this.stop()}))}getIsSampled(){return this._isSampled||!1}_getDetail(t,e){return{id:this._id,rootId:this._rootId,name:this._name,userSchemaOrText:t,userData:e,stopReason:this._stopReason,startTimestamp:this._startTimestamp,startPerfTime:this._startPerfTime,stopPerfTime:this._stopPerfTime,errorCount:this._errorCount,isSampled:this.getIsSampled()}}getTraceHeaders(t){const e=this.id,r=this._rootId||e;return Tracing.getHeaders(r,e,this.getIsSampled(),t)}getStartTimestamp(){return this._startTimestamp}getStartPerfTime(){return this._startPerfTime}getStopPerfTime(){return this._stopPerfTime}}ActivityImpl._count=0;const n={namespace:"sf.instrumentation",name:"Activity",pbjsSchema:{nested:{sf:{nested:{instrumentation:{nested:{Activity:{reserved:[[5,5],[7,7]],fields:{duration:{options:{},id:3,type:"double"},stopReason:{options:{},id:6,type:"string"},isRoot:{options:{},id:8,type:"bool"},name:{options:{"(meta.max_length)":25},id:2,type:"string"},isSampled:{options:{},id:11,type:"bool"},preRootId:{options:{},id:9,type:"string"},id:{options:{},id:1,type:"string"},userPayload:{options:{},id:4,type:"Payload"},errorCount:{options:{},id:10,type:"uint32"}}},Payload:{fields:{payload:{options:{},id:2,type:"bytes"},schemaName:{options:{},id:1,type:"string"}}}}}}}}}},o={namespace:"sf.instrumentation",name:"Error",pbjsSchema:{nested:{sf:{nested:{instrumentation:{nested:{Error:{reserved:[[5,5],[7,7]],fields:{activityId:{options:{},id:6,type:"string"},stack:{options:{},id:3,type:"string"},name:{options:{},id:1,type:"string"},message:{options:{"(meta.max_length)":200},id:2,type:"string"},userPayload:{options:{},id:4,type:"Payload"}}},Payload:{fields:{payload:{options:{},id:2,type:"bytes"},schemaName:{options:{},id:1,type:"string"}}}}}}}}}},a={namespace:"sf.instrumentation",name:"InstrumentedEvent",pbjsSchema:{nested:{sf:{nested:{instrumentation:{nested:{MouseEvent:{fields:{cancelable:{options:{},id:5,type:"bool"},ctrlKey:{options:{},id:9,type:"bool"},type:{options:{},id:25,type:"string"},button:{options:{},id:3,type:"uint32"},offsetX:{options:{},id:17,type:"uint32"},eventPhase:{options:{},id:12,type:"uint32"},shiftKey:{options:{},id:23,type:"bool"},offsetY:{options:{},id:18,type:"uint32"},composed:{options:{},id:8,type:"bool"},altKey:{options:{},id:1,type:"bool"},isTrusted:{options:{},id:13,type:"bool"},buttons:{options:{},id:4,type:"uint32"},movementY:{options:{},id:16,type:"uint32"},clientY:{options:{},id:7,type:"uint32"},clientX:{options:{},id:6,type:"uint32"},movementX:{options:{},id:15,type:"uint32"},defaultPrevented:{options:{},id:10,type:"bool"},metaKey:{options:{},id:14,type:"bool"},timeStamp:{options:{},id:24,type:"double"},bubbles:{options:{},id:2,type:"bool"},detail:{options:{},id:11,type:"int64"},pageY:{options:{},id:20,type:"uint32"},pageX:{options:{},id:19,type:"uint32"},screenX:{options:{},id:21,type:"uint32"},screenY:{options:{},id:22,type:"uint32"}}},InstrumentedEvent:{oneofs:{event:{oneof:["mouseEvent"]}},reserved:[[4,4],"xpath",[6,6],[8,8]],fields:{mouseEvent:{options:{},id:7,type:"MouseEvent"},auto:{options:{},id:3,type:"bool"},parentComponent:{options:{},id:2,type:"string"},ownerComponent:{options:{},id:1,type:"string"},userPayload:{options:{},id:5,type:"Payload"},simplePath:{options:{},id:9,type:"string"}}},Payload:{fields:{payload:{options:{},id:2,type:"bytes"},schemaName:{options:{},id:1,type:"string"}}}}}}}}}},c={namespace:"sf.instrumentation",name:"Simple",pbjsSchema:{nested:{sf:{nested:{instrumentation:{nested:{Simple:{options:{"(meta.msg.desc)":"This message is used internally to allow convenient logging of simple text via the API without requiring a schema."},fields:{text:{options:{"(meta.max_length)":25},id:1,type:"string"}}}}}}}}}},l=new Array(16).fill(0).join("");const h=Object.freeze(new class{getId(){return l}getRootId(){}error(){}stop(){}discard(){}terminate(){}getIsSampled(){return!1}getTraceHeaders(t){return{}}getStartTimestamp(){}getStartPerfTime(){}getStopPerfTime(){}});const d=new class{getInstrumentedEventData(r,i,s){const n={ownerComponent:i.tagName,parentComponent:i.parentElement&&i.parentElement.tagName||void 0,event:r,simplePath:t.getXpath(i)};return s&&(n.userPayload=e.makePayload(s.schema,s.payload,!0)),n}getMouseEventData(t){return{altKey:t.altKey,bubbles:t.bubbles,button:t.button,buttons:t.buttons,cancelable:t.cancelable,clientX:t.clientX,clientY:t.clientY,composed:t.composed,defaultPrevented:t.defaultPrevented,detail:t.detail,eventPhase:t.eventPhase,isTrusted:t.isTrusted,timeStamp:t.timeStamp,type:t.type,ctrlKey:t.ctrlKey,metaKey:t.metaKey,movementX:t.movementX,movementY:t.movementY,offsetX:t.offsetX,offsetY:t.offsetY,pageX:t.pageX,pageY:t.pageY,screenX:t.screenX,screenY:t.screenY,shiftKey:t.shiftKey}}};const u=new class{validate(r,i){const s=e.checkSchema(r);t.requireArgument(i,"data","object");const n=e.getTypes(r),o=this.validateFields(i,n[s.message],n,e.getSchemaId(r));if(o)throw new Error(o)}validateFields(t,e,r,i){const s=e.oneofs||{},n=e.fields||{};let o;for(const e in t){const a=t[e];if(this.isNullOrUndefinedOrEmpty(a)||(s[e]?o=this.matchFieldTypes(a,s[e].oneof[0],r,i,e):n[e]&&(o=this.matchFieldTypes(a,n[e].type,r,i,e,n[e].rule))),o)return o}}isNullOrUndefinedOrEmpty(t){return null==t||""===t}matchFieldTypes(t,e,r,i,s,n){let o,a;if("repeated"===n){let n;if(Array.isArray(t)){for(const o in t)if(n=this.matchFieldTypes(t[o],e,r,i,s),n)break}else n=`Schema ${i} on field: ${s}, repeated field should be an array`;return n}switch(e){case"string":o="string";break;case"bytes":o="object",t instanceof Uint8Array||(a=`Schema ${i} on field: ${s}, bytes array is malformed`);break;case"bool":o="boolean";break;case"uint32":o="number",a=this.checkNumberRange(t,4294967295,0,i,s);break;case"int32":case"sint32":case"fixed32":case"sfixed32":o="number",a=this.checkNumberRange(t,2147483647,-2147483648,i,s);break;case"uint64":o="number",a=this.checkNumberRange(t,0x10000000000000000,0,i,s);break;case"fixed64":case"sfixed64":case"int64":case"sint64":o="number",a=this.checkNumberRange(t,0x8000000000000000,-0x8000000000000000,i,s);break;case"double":case"float":o="number",Number.isFinite(t)||(a=`Schema ${i} on field: ${s}. Value must be finite`);break;default:const n={},c=Object.keys(r);for(const t in c)n[c[t].toLowerCase()]=c[t];n[e.toLowerCase()]&&(a=this.validateFields(t,r[n[e.toLowerCase()]],r,i),o="object")}const c=(t+"").length;return typeof t!==o?`Schema ${i} on field: ${s}. Expected type ${e} but received type ${typeof t}`:c<0||c>1e4?`Schema ${i} on field: ${s}, exceeded maximum or minimum field length`:a||void 0}checkNumberRange(t,e,r,i,s){if(t>e||t<r)return`Schema ${i} on field: ${s}, number value is too large or small`}};class UpCounterImpl{constructor(e,r,i,s){this._name=e,this._ownerName=r,this._ownerAppName=i,this._tags=s,this._value=0,this._createdOn=t.time().tsNow}getName(){return this._name}getCreatedOn(){return this._createdOn}getLastUpdatedOn(){return this._lastUpdatedOn}getData(){return this._value}increment(e=1){if("number"==typeof e&&e>0)return this._value+=Math.round(e),void(this._lastUpdatedOn=t.time().tsNow);throw new Error("UpCounter can only increment positive numbers.")}reset(){this._lastUpdatedOn=void 0,this._value=0}getOwnerName(){return this._ownerName}getOwnerAppName(){return this._ownerAppName}getTags(){return this._tags}}class ValueRecorderImpl{constructor(e,r,i,s){this._name=e,this._ownerName=r,this._ownerAppName=i,this._tags=s,this._values=new Array,this._createdOn=t.time().tsNow}getName(){return this._name}getCreatedOn(){return this._createdOn}getLastUpdatedOn(){return this._lastUpdatedOn}getData(){return this.values}get values(){return this._values.slice(0,this._values.length)}record(e){if("number"==typeof e)return this._values.push(e),void(this._lastUpdatedOn=t.time().tsNow);throw new Error("ValueRecorder can only record numbers.")}reset(){this._lastUpdatedOn=void 0,this._values=[]}getOwnerName(){return this._ownerName}getOwnerAppName(){return this._ownerAppName}getTags(){return this._tags}}class SizeLimitedMap{constructor(t){if(this._map=new Map,!("number"==typeof t&&t>0))throw new Error("maxSize must be a positive number");this._maxSize=Math.ceil(t)}get maxSize(){return this._maxSize}get(t){return this._map.get(t)}has(t){return this._map.has(t)}set(t,e){return!!(this.has(t)||this._map.size<this.maxSize)&&(this._map.set(t,e),!0)}getElements(){return Array.from(this._map.values())}clear(){this._map.clear()}}var p;!function(t){t[t.Counter=0]="Counter",t[t.Percentile=1]="Percentile"}(p||(p={}));class MetricsImpl{constructor(t,e){this._ownerName=t,this._ownerAppName=e,this._upCounters=new SizeLimitedMap(1e3),this._valueRecorders=new SizeLimitedMap(500)}incrementCounter(t,e,r=!1,i={}){this._tagError(i,r),this._upCounter(t,i).increment(e)}trackValue(t,e,r=!1,i={}){this._tagError(i,r),this._valueRecorder(t,i).record(e)}_upCounter(t,e){const{key:r,sortedTags:i}=this._getKeyAndSortedTags(t,e,p.Counter);let s=this._upCounters.get(r);if(!s&&(s=new UpCounterImpl(t,this._ownerName,this._ownerAppName,i),!this._upCounters.set(r,s)))throw new Error("Max size of 1000 exceeeded for UpCounters");return s}_valueRecorder(t,e){const{key:r,sortedTags:i}=this._getKeyAndSortedTags(t,e,p.Percentile);let s=this._valueRecorders.get(r);if(!s&&(s=new ValueRecorderImpl(t,this._ownerName,this._ownerAppName,i),!this._valueRecorders.set(r,s)))throw new Error("Max size of 500 exceeeded for ValueRecorders");return s}getUpCounters(){return this._upCounters.getElements()}getValueRecorders(){return this._valueRecorders.getElements()}_tagError(t,e){t.status=!0===e?"error":"success"}_getKeyAndSortedTags(t,e,r){const i=Object.keys(e).sort().reduce(((t,r)=>(t[r]=e[r],t)),{});return{key:`${p[r]}:${t}${JSON.stringify(i)}`,sortedTags:i}}}class MockEvent{constructor(t,e,r){this.type=t,this.composed=e,this._composedPaths=r}composedPath(){return this._composedPaths}}const m=["`"],g={internalError:"o11y-error"},_=Object.freeze(Array.from(Object.values(g)));class InstrumentationImpl{constructor(t,r){this._nextGen=t,this._name=r,this._onActivityStoppedCallback=this._handleActivityStop.bind(this),this._onActivityErrorCallback=this._handleActivityError.bind(this);for(const t of m)if(this._name.indexOf(t)>=0)throw new Error(`Name cannot include the reserved character "${t}"`);this._safety=new PublicSafety({increment:t=>this._incrementError(t)}),this._metrics=new MetricsImpl(this.name,this._nextGen.appName);const i=e.getOptions(c,"Simple","text");this._simpleTextMaxLength=i?i["(meta.max_length)"]:Number.MAX_VALUE}_incrementError(t=1){this._metrics.incrementCounter(g.internalError,t,!1)}get name(){return this._name}_wrapUserPayload(t,r,i=!1){let s;return"string"==typeof t?(s=c,r=t?{text:t.substr(0,this._simpleTextMaxLength)}:void 0):s=t,e.makePayload(s,r,i)}log(e,r){this._safety.tryCatch((()=>{const i=t.time().tsNow;t.requireArgument(e,"userSchemaOrText",["object","string"]);const s=this._wrapUserPayload(e,r);s&&s.payload&&this._logInternal(this.name,s.schema,s.payload,i,this._nextGen.getRootActivityId())}))}_logInternal(t,e,r,i,s){this._checkInputs(e,r);const n=this._getPayloadFromProvider(this._nextGen.appPayloadProvider),o=this._getPayloadFromProvider(this._nextGen.pagePayloadProvider);return this._nextGen.addLog(t,e,r,i,s,o,n)}error(t,e,r){return this._safety.tryCatch((()=>this._errorInternal(t,e,r)))}_errorInternal(e,r,i,s){const n=t.time().tsNow;this._incrementError(),t.requireArgument(e,"error",[Error,"string"]),"string"==typeof e&&(e=new Error(e));const a=this._wrapUserPayload(r,i,!0),c={name:e.name,message:e.message,stack:e.stack,userPayload:a,activityId:s};return this._logInternal(this.name,o,c,n,this._nextGen.getRootActivityId())}startActivity(e){return this._safety.tryCatchReturn((()=>{t.requireArgument(e,"name");return new ActivityImpl(e,this._nextGen.getRootActivityId(),this._onActivityStoppedCallback,this._onActivityErrorCallback,3e4,void 0,this._nextGen.isRootActivitySampled())}),h)}_getActivityData(t){const e=this._wrapUserPayload(t.userSchemaOrText,t.userData,!0);return{id:t.id,name:t.name,duration:t.stopPerfTime-t.startPerfTime,stopReason:t.stopReason,userPayload:e,errorCount:t.errorCount,isSampled:t.isSampled}}_handleActivityStop(t){if("discarded"===t.stopReason)return;const e=this._getActivityData(t);this._logActivity(e,t.startTimestamp,t.rootId)}_logActivity(t,e,r){this._logInternal(this.name,n,t,e,r)}_handleActivityError(t,e){this._errorInternal(t,e.userSchemaOrText,e.userData,e.id)}_getPayloadFromProvider(t){if(t){const e=t.getPayload();if(e)return this._checkInputs(e.schema,e.payload),e}}domEvent(e,r,i,s,n){this._safety.tryCatch((()=>{const o=t.time().tsNow;let c;t.requireArgument(e,"event",[Event,MockEvent]),t.requireArgument(r,"handledBy",[HTMLElement,"object"]),r instanceof HTMLElement?c=r:(r=r).template&&r.template.host instanceof HTMLElement?c=r.template.host:t.requireArgument(void 0,"handledBy");const l=this._wrapUserPayload(i,s,!0);switch(e.type){case"click":{const t=e,r=this._nextGen.getClickTracker();r&&r.markEventHandled(t);const i=d.getMouseEventData(t),s=d.getInstrumentedEventData(i,c,l);s.auto=n,this._logInternal(this.name,a,s,o,this._nextGen.getRootActivityId());break}default:throw new Error(t.notImplemented)}}))}incrementCounter(e,r=1,i=!1,s={}){this._safety.tryCatch((()=>{t.requireArgument(e,"operation","string"),t.checkForDenyListedValues(e,"operation",_),t.checkForReservedCharacters(e,"operation",m),t.requireArgument(r,"increment","number"),t.requireArgument(i,"hasError","boolean"),t.requireArgument(s,"tags","object"),Object.entries(s).forEach((e=>{t.requireArgument(e[1],`Tag value for '${e[0]}'`,["string","number","boolean"])})),this._metrics.incrementCounter(e,r,i,s)}))}trackValue(e,r,i=!1,s={}){this._safety.tryCatch((()=>{t.requireArgument(e,"operation","string"),t.checkForDenyListedValues(e,"operation",_),t.checkForReservedCharacters(e,"operation",m),t.requireArgument(r,"value","number"),t.requireArgument(i,"hasError","boolean"),t.requireArgument(s,"tags","object"),Object.entries(s).forEach((e=>{t.requireArgument(e[1],`Tag value for '${e[0]}'`,["string","number","boolean"])})),this._metrics.trackValue(e,r,i,s)}))}_checkInputs(r,i){let s;e.checkSchema(r),t.requireArgument(i,"data","object"),void 0!==i.userPayload&&e.isInternal(r)&&(s=i.userPayload,u.validate(s.schema,s.payload),i.userPayload=void 0),u.validate(r,i),void 0!==s&&(i.userPayload=s)}getUpCounters(){return this._metrics.getUpCounters().filter((t=>t.getLastUpdatedOn()))}getValueRecorders(){return this._metrics.getValueRecorders().filter((t=>t.getLastUpdatedOn()))}}class RootActivityImpl extends ActivityImpl{constructor(e,r,i,s,n){super(e,void 0,r,i,void 0,s||t.generateUniqueId(32),n)}get preRootId(){return this._preRootId}set preRootId(t){this._preRootId=t}_getDetail(t,e){const r=super._getDetail(t,e);return r.isRoot=!0,r.preRootId=this.preRootId,r}}const y=new Array(32).fill(0).join("");const f=Object.freeze(new class{getId(){return y}getRootId(){}error(){}stop(){}discard(){}terminate(){}getIsSampled(){return!1}getTraceHeaders(t){return{}}getStartTimestamp(){}getStartPerfTime(){}getStopPerfTime(){}});class AppInstrumentationImpl extends InstrumentationImpl{constructor(){super(...arguments),this._onRootActivityStoppedCallback=this.handleRootActivityStop.bind(this)}startRootActivity(e,r,i){return this._safety.tryCatchReturn((()=>{t.requireArgument(e,"name");const s=new RootActivityImpl(e,this._onRootActivityStoppedCallback,this._onActivityErrorCallback,r,i);if(this.rootActivity&&!this.rootActivity.isStopped){const t=this.rootActivity.getId();this.rootActivity.terminate(),s.preRootId=t}return this.rootActivity=s,this.rootActivity}),f)}handleRootActivityStop(t){if("discarded"===t.stopReason)return;const e=this._getActivityData(t);this._logActivity(e,t.startTimestamp),this.rootActivity=void 0}_getActivityData(t){const e=super._getActivityData(t);return e.isRoot=t.isRoot,e.preRootId=t.preRootId,e}getRootActivityId(){return this.rootActivity&&this.rootActivity.getId()}isRootActivitySampled(){return this.rootActivity&&this.rootActivity.getIsSampled()}}class AutomaticClickTracker{constructor(e,r){this.isActive=!1,this._boundClickListener=this.clickListener.bind(this),t.requireArgument(e,"instrumentation"),t.requireArgument(r,"document"),this.instr=e,this.document=r}activate(){this.isActive||(this.document.addEventListener("click",this._boundClickListener,!0),this.isActive=!0)}deactivate(){this.isActive&&(this.document.removeEventListener("click",this._boundClickListener,!0),this.isActive=!1)}markEventHandled(t){this.ignoredEvent=t}clickListener(t){let e=t.composedPath&&t.composedPath();e&&e.length||(e=t.path);const r=this.getClickableElement(e);r&&setTimeout((()=>{t!==this.ignoredEvent&&this.instr.domEvent(t,r,void 0,void 0,!0)}))}getClickableElement(t){const e=t?Math.min(t.length,5):0;for(let r=0;r<e;r+=1){const e=t[r],i=e.tagName&&e.tagName.toLowerCase();if("a"===i||"button"===i)return e;if("input"===i){const t=e;if(t.type&&"button"===t.type.toLowerCase())return t}}}}const v=80-"_CUT".length;class NextgenImpl{constructor(){this._logCollectors=new Set,this._instruments=new Map,this._sequence=0,this._forceDisabledLogCollectors=new Set,this._logCollectorFailures=new Map,this._isBufferingEnabled=!1,this._buffer=[]}get pagePayloadProvider(){return this._pagePayloadProvider}set pagePayloadProvider(t){this._pagePayloadProvider=t}get appPayloadProvider(){return this._appPayloadProvider}set appPayloadProvider(t){this._appPayloadProvider=t}registerApp(e,r){if(t.requireArgument(e,"name","string"),this._appInstr)throw new Error("An app has already been registered with instrumentation.");if(this._instruments.get(e))throw new Error(`The instrumentation name ${e} is already taken`);this._appInstr=new AppInstrumentationImpl(this,e),this._instruments.set(e,this._appInstr),this._isBufferingEnabled=r;const i=new Tracing(this._appInstr);return{log:this._appInstr.log.bind(this._appInstr),error:this._appInstr.error.bind(this._appInstr),startActivity:this._appInstr.startActivity.bind(this._appInstr),domEvent:this._appInstr.domEvent.bind(this._appInstr),incrementCounter:this._appInstr.incrementCounter.bind(this._appInstr),trackValue:this._appInstr.trackValue.bind(this._appInstr),networkInstrumentation:i.networkInstrumentation.bind(i),startRootActivity:this._appInstr.startRootActivity.bind(this._appInstr),registerLogCollector:this.registerLogCollector.bind(this),registerMetricsCollector:this.registerMetricsCollector.bind(this),activateClickTracker:this.activateClickTracker.bind(this),deactivateClickTracker:this.deactivateClickTracker.bind(this),disableBuffering:this.disableBuffering.bind(this)}}getInstrumentation(e){t.requireArgument(e,"name","string"),e.length>80&&(e=e.substr(0,v)+"_CUT");let r=this._instruments.get(e);if(r){if(r===this._appInstr)throw new Error(`The instrumentation name ${e} is being used by the app.`)}else r=new InstrumentationImpl(this,e),this._instruments.set(e,r);return r}get appName(){return this._appInstr&&this._appInstr.name}addLog(e,r,i,s,n,o,a){this._sequence+=1;const c={timestamp:s,rootId:n,sequence:this._sequence,loggerName:e,pagePayload:o,appPayload:a,loggerAppName:this.appName,connectionType:t.getConnectionType()};this._isBufferingEnabled&&this._buffer.push({schema:r,data:t.clone(i),logMeta:c});for(const e of this._logCollectors){const s=t.clone(i),n=this._logCollectorFailures.get(e);try{this._forceDisabledLogCollectors.has(e)||e.getIsCollectDisabled&&e.getIsCollectDisabled()||(e.collect(r,s,c),n>0&&this._logCollectorFailures.set(e,n-1))}catch(t){n>=NextgenImpl._collectorFailureLimit&&!this._forceDisabledLogCollectors.has(e)?this._forceDisabledLogCollectors.add(e):this._logCollectorFailures.set(e,n+1)}}return this._sequence}getBuffer(){return this._buffer}disableBuffering(){this._isBufferingEnabled=!1,this._buffer=[]}getClickTracker(){return this._autoClickTracker}getRootActivityId(){return this._appInstr&&this._appInstr.getRootActivityId()}isRootActivitySampled(){return this._appInstr&&this._appInstr.isRootActivitySampled()}activateClickTracker(){this._autoClickTracker||(this._autoClickTracker=new AutomaticClickTracker(this._appInstr,window.document)),this._autoClickTracker.activate()}deactivateClickTracker(){this._autoClickTracker&&(this._autoClickTracker.deactivate(),this._autoClickTracker=void 0)}registerLogCollector(e,r){if(t.requireArgument(e,"collector"),this._logCollectors.add(e),this._logCollectorFailures.set(e,0),(!e.getIsCollectDisabled||!e.getIsCollectDisabled())&&r&&r.retroactive)for(const t of this._buffer)e.collect(t.schema,t.data,t.logMeta)}registerMetricsCollector(e){if(t.requireArgument(e,"collector"),this._metricsCollector)throw new Error("A metrics Collector is already registered.");this._metricsCollector=e,this._metricsCollector.receiveMetricsExtractors({getAllUpCounters:this.getAllUpCounters.bind(this),getAllValueRecorders:this.getAllValueRecorders.bind(this)})}getAllUpCounters(){return Array.from(this._instruments.values()).map((t=>t.getUpCounters())).reduce(((t,e)=>t.concat(e)),[])}getAllValueRecorders(){return Array.from(this._instruments.values()).map((t=>t.getValueRecorders())).reduce(((t,e)=>t.concat(e)),[])}}NextgenImpl._collectorFailureLimit=5;const b=new class{get _lazyNextGen(){return this._nextgen||(this._nextgen=new NextgenImpl),this._nextgen}registerInstrumentedApp(e,r){r&&r.isProduction&&t.markProduction();const i=this._lazyNextGen.registerApp(e,r&&r.enableBuffering);return r&&(this._nextgen.appPayloadProvider=r.appPayloadProvider,this._nextgen.pagePayloadProvider=r.pagePayloadProvider),i}getInstrumentation(t){return this._lazyNextGen.getInstrumentation(t)}},I=b.registerInstrumentedApp.bind(b),C=b.getInstrumentation.bind(b),A=t.time.bind(t);class TaskerImpl{constructor(t,e,r,i){this.name=t,this._doneCallback=r,this._overDoneCallback=i,this._busyCount=0,this._isOk=!0,this._busyCount=e}get isBusy(){return this._isOk?this._busyCount>0:void 0}add(){this._isOk&&(this._busyCount+=1)}done(){this._isOk&&(this._busyCount>0?(this._busyCount-=1,this._busyCount||this._doneCallback()):(this._isOk=!1,this._overDoneCallback()))}}const k={Error:"Crimson",Activity:"CadetBlue",InstrumentedEvent:"DarkOliveGreen",O11ySample:"BlueViolet"},w={Error:"white",Activity:"white",InstrumentedEvent:"white",O11ySample:"white"};class ConsoleCollector{constructor(t){t&&this._log("ConsoleCollector",t)}collect(t,r,i){let s,n,o;"sf.instrumentation"===t.namespace?(s=t.name,n=w[t.name]||"black",o=k[t.name]||"Gainsboro"):s=e.getSchemaId(t),this._log(s,r,i,n,o)}_log(t,e,r,i="black",s="Gainsboro"){const n=`color:${i};background-color:${s}`;console.log(`%cO11Y%c ${t}`,"color:white;background-color:#FF6600;font-weight:bold",n,e||"",r||"")}}const T=new class{constructor(){this._instr=C("IdleDetector"),this._taskers=new Set,this._listeners=new Set,this._busyCheckers=new Map,this._timerCheckQueued=0}requestIdleDetectedCallback(e){t.requireArgument(e,"callback","function"),this._listeners.add(e),this.checkIfLoaded()}declareNotifierTaskSingle(e){t.requireArgument(e,"name","string");const r=this.addTasker(e,1);return{get isBusy(){return r.isBusy},done:()=>{r.done(),this._taskers.delete(r)}}}declareNotifierTaskMulti(e,r=0){if(t.requireArgument(e,"name","string"),void 0!==r&&(t.requireArgument(r,"existingBusyCount","number"),r<0||parseInt(r.toString(),10)!==r))throw new Error("existingBusyCount accepts only non-negative integers");return this.addTasker(e,r)}declarePollableTaskMulti(e,r){t.requireArgument(e,"name","string"),t.requireArgument(r,"isBusyChecker","function"),this._busyCheckers.set(r,e)}addTasker(t,e){const r=new TaskerImpl(t,e,(()=>{this.checkIfLoaded()}),(()=>{throw new Error(`Tasker '${r.name}' is done too many times.`)}));return this._taskers.add(r),r}areAllNotifiersIdle(){return!Array.from(this._taskers.values()).some((t=>t.isBusy))}areAllPollablesIdle(){return!Array.from(this._busyCheckers.keys()).some(((t,e)=>{try{return t()}catch(t){return this._instr.error(t,`BusyChecker #${e}`),!1}}))}checkIfLoaded(){this._listeners.size&&(this._timerCheckQueued&&window.clearTimeout(this._timerCheckQueued),this.areAllNotifiersIdle()&&(this._timerCheckQueued=window.setTimeout((()=>{this._timerCheckQueued=window.setTimeout((()=>{this.doubleCheck()}),40)}),0)))}doubleCheck(){if(this._timerCheckQueued=0,this.areAllNotifiersIdle())if(this.areAllPollablesIdle()){const t=Array.from(this._listeners.values());this._listeners.clear(),this.notify(t)}else this._timerCheckQueued=window.setTimeout((()=>{this.doubleCheck()}),15)}notify(e){const r=t.time().tsNow;for(const[t,i]of e.entries())try{i(r)}catch(e){this._instr.error(e,`Listener #${t}`)}}};export{ConsoleCollector,C as getInstrumentation,T as idleDetector,I as registerInstrumentedApp,A as time};
|
|
1
|
+
import{utility as t,schemaUtil as e}from"o11y/shared";class PublicSafety{constructor(t){this._errorCounter=t,this._safeCatchMode=!1}tryCatch(t){try{t()}catch(t){this._prodSafeCatch(t)}}tryCatchReturn(e,r){try{return t.requireArgument(r,"noopValue"),e()}catch(t){return this._prodSafeCatch(t),r}}_prodSafeCatch(e){let r;try{if(r=!t.isProduction,r)throw e;if(this._safeCatchMode)throw this._safeCatchMode=!1,new Error("Internal error in prodSafeCatch.");if(this._safeCatchMode=!0,this._errorCounter&&this._errorCounter.increment(),!(e instanceof Error)){const t=e&&e.message||("function"==typeof e.toString?e.toString():"");e=new Error(t)}this._safeCatchMode=!1}catch(t){if(r)throw t;if(t&&console&&"function"==typeof console.error)try{console.error(t)}catch(t){}this._safeCatchMode=!1}}}class Tracing{constructor(e){this.instr=e,t.requireArgument(e,"instr","object")}static _getB3CompactFormat(t,e,r,i){let s=`${t}-${e}`;return void 0===r&&void 0===i||(s+=r?"-1":"-0",void 0!==i&&(s+=`-${i}`)),s}static _getW3CompactFormat(t,e,r){return`00-${t}-${e}-${r?"01":"00"}`}static _conformTextAsId(t,e){const r=(t=t.toLowerCase()).length;for(let e=0;e<r;e+=1){const r=t[e];if(!(r>="a"&&r<="f"||r>="0"&&r<="9"))throw new Error(`The text '${t}' has an invalid character at index #${e}`)}return r>e?t.substr(r-e):r<e?t.padStart(e,"0"):t}static getHeaders(e,r,i,s){t.requireArgument(e,"traceId","string"),t.requireArgument(r,"spanId","string");const n=s&&s.useB3Headers;e=this._conformTextAsId(e,s&&void 0!==s.traceIdEffectiveLength?s.traceIdEffectiveLength:n?16:32),r=this._conformTextAsId(r,16);const o=s&&void 0!==s.parentSpanId&&this._conformTextAsId(s.parentSpanId,16)||void 0,a={};if(n){s&&s.useCompactHeader?a.b3=this._getB3CompactFormat(e,r,i,o):(a["X-B3-TraceId"]=e,a["X-B3-SpanId"]=r,void 0!==o&&(a["X-B3-ParentSpanId"]=o),void 0!==i&&(a["X-B3-Sampled"]=i?"1":"0"))}else a.traceparent=this._getW3CompactFormat(e,r,i);return a}_disableNetworkInstrumentation(){Tracing._isNetworkInstrumentationEnabled&&(Tracing._originalFetch&&(Tracing._global.fetch=Tracing._originalFetch,Tracing._originalFetch=void 0),Tracing._originalXhr&&(Tracing._global.XMLHttpRequest=Tracing._originalXhr,Tracing._originalXhr=void 0),Tracing._originalXhrSend&&(Tracing._global.XMLHttpRequest.prototype.send=Tracing._originalXhrSend,Tracing._originalXhrSend=void 0),Tracing._isNetworkInstrumentationEnabled=!1)}_enableNetworkInstrumentation(t,e,r,i,s){"function"==typeof Tracing._global.fetch&&(this._overrideFetch(t,e,r,i,s),Tracing._isNetworkInstrumentationEnabled=!0),"function"==typeof Tracing._global.XMLHttpRequest&&(this._overrideXhr(t,e,r,i,s),Tracing._isNetworkInstrumentationEnabled=!0)}_overrideFetch(t,e,r,i,s){Tracing._originalFetch=Tracing._global.fetch;Tracing._global.fetch=async(n,o,...a)=>{let c;try{if(c=t.startActivity(r||"fetch"),i){o=o||{};const t=c.getTraceHeaders(s);o.headers=Object.assign(o.headers||{},t)}return await Tracing._originalFetch.call(Tracing._global,n,o,...a)}catch(r){throw e&&(c?c.error(r):t.error(r)),r}finally{c&&c.stop()}}}_overrideXhr(t,e,r,i,s){Tracing._originalXhr=Tracing._global.XMLHttpRequest,Tracing._originalXhrSend=Tracing._originalXhr.prototype.send,Tracing._originalXhr.prototype.send=function(...n){let o;const a=this;try{if(a._o11yActivity=o=t.startActivity(r||"xhr_send"),i){const t=o.getTraceHeaders(s);Object.entries(t).forEach((t=>{a.setRequestHeader(t[0],t[1])}))}Tracing._originalXhrSend.call(this,...n)}catch(r){throw e&&(o?o.error(r):t.error(r)),o&&o.stop(),r}};const n=new Proxy(Tracing._originalXhr,{construct(r){const i=new r;return i.addEventListener("load",(()=>{const t=i._o11yActivity;t&&t.stop()})),i.addEventListener("error",(r=>{const s=new Error("XHR Network-Level Error"),n=i._o11yActivity;n?(e&&n.error(s),n.stop()):e&&t.error(s)})),i.addEventListener("abort",(()=>{const t=i._o11yActivity;t&&t.discard()})),i}});Tracing._global.XMLHttpRequest=n}networkInstrumentation(e){if(t.requireArgument(e,"options",["boolean","object"]),e){this._disableNetworkInstrumentation();const r="object"==typeof e?e:{};this._enableNetworkInstrumentation(t.definedValueOrDefault(r.instrumentation,this.instr),t.definedValueOrDefault(r.logErrors,!0),r.activityName,t.definedValueOrDefault(r.useTracing,!0),r.tracingHeadersOptions)}else this._disableNetworkInstrumentation()}}Tracing._global=t.getGlobal(),Tracing._isNetworkInstrumentationEnabled=!1;const r="timedout",i="terminated",s="discarded";class ActivityImpl{constructor(e,i,s,n,o,a,c){this._name=e,this._rootId=i,this._onStopped=s,this._onError=n,this._isSampled=c,this._errorCount=0;const{tsNow:l,perfNow:d}=t.time();if(ActivityImpl._count+=1,this._id=a||t.generateUniqueId(),this._usePerf="undefined"!=typeof performance&&"function"==typeof performance.mark&&"function"==typeof performance.measure,this._usePerf){this._perfName=`${this._name}__${ActivityImpl._count}`,this._perfId=`${this._name}__${this.id}`;try{performance.mark(this._perfId)}catch(t){this._usePerf=!1}}this._startTimestamp=l,this._startPerfTime=d,o>0&&(this._timer=setTimeout((()=>{this._stopReason=this._stopReason||r,this.stop()}),o)),this._safety=new PublicSafety}get id(){return this._id}getId(){return this.id}getRootId(){return this._rootId}get stopReason(){return this._stopReason}error(t,e,r){this._safety.tryCatch((()=>{this._errorCount+=1,"string"==typeof t&&(t=new Error(t)),this._onError(t,this._getDetail(e,r))}))}stop(t,e){this._safety.tryCatch((()=>this._stopInternal(t,e)))}_stopInternal(e,r){const i=t.perfNow();if(this._usePerf)try{performance.measure(this._perfName,this._perfId),performance.clearMarks(this._perfId),performance.clearMeasures(this._perfName)}catch(t){}if(this._timer&&(clearTimeout(this._timer),this._timer=void 0),this.isStopped)return;this._stopPerfTime=i;const s=this._getDetail(e,r);this._onStopped(s)}get isStopped(){return void 0!==this._stopPerfTime}discard(){this._safety.tryCatch((()=>{this._stopReason=this._stopReason||s,this.stop()}))}terminate(){this._safety.tryCatch((()=>{this._stopReason=this._stopReason||i,this.stop()}))}getIsSampled(){return this._isSampled||!1}_getDetail(t,e){return{id:this._id,rootId:this._rootId,name:this._name,userSchemaOrText:t,userData:e,stopReason:this._stopReason,startTimestamp:this._startTimestamp,startPerfTime:this._startPerfTime,stopPerfTime:this._stopPerfTime,errorCount:this._errorCount,isSampled:this.getIsSampled()}}getTraceHeaders(t){const e=this.id,r=this._rootId||e;return Tracing.getHeaders(r,e,this.getIsSampled(),t)}getStartTimestamp(){return this._startTimestamp}getStartPerfTime(){return this._startPerfTime}getStopPerfTime(){return this._stopPerfTime}}ActivityImpl._count=0;const n={namespace:"sf.instrumentation",name:"Activity",pbjsSchema:{nested:{sf:{nested:{instrumentation:{nested:{Activity:{reserved:[[5,5],[7,7]],fields:{duration:{options:{},id:3,type:"double"},stopReason:{options:{},id:6,type:"string"},isRoot:{options:{},id:8,type:"bool"},name:{options:{"(meta.max_length)":25},id:2,type:"string"},isSampled:{options:{},id:11,type:"bool"},preRootId:{options:{},id:9,type:"string"},id:{options:{},id:1,type:"string"},userPayload:{options:{},id:4,type:"Payload"},errorCount:{options:{},id:10,type:"uint32"}}},Payload:{fields:{payload:{options:{},id:2,type:"bytes"},schemaName:{options:{},id:1,type:"string"}}}}}}}}}},o={namespace:"sf.instrumentation",name:"Error",pbjsSchema:{nested:{sf:{nested:{instrumentation:{nested:{Error:{reserved:[[5,5],[7,7]],fields:{activityId:{options:{},id:6,type:"string"},stack:{options:{},id:3,type:"string"},name:{options:{},id:1,type:"string"},message:{options:{"(meta.max_length)":200},id:2,type:"string"},userPayload:{options:{},id:4,type:"Payload"}}},Payload:{fields:{payload:{options:{},id:2,type:"bytes"},schemaName:{options:{},id:1,type:"string"}}}}}}}}}},a={namespace:"sf.instrumentation",name:"InstrumentedEvent",pbjsSchema:{nested:{sf:{nested:{instrumentation:{nested:{MouseEvent:{fields:{cancelable:{options:{},id:5,type:"bool"},ctrlKey:{options:{},id:9,type:"bool"},type:{options:{},id:25,type:"string"},button:{options:{},id:3,type:"uint32"},offsetX:{options:{},id:17,type:"uint32"},eventPhase:{options:{},id:12,type:"uint32"},shiftKey:{options:{},id:23,type:"bool"},offsetY:{options:{},id:18,type:"uint32"},composed:{options:{},id:8,type:"bool"},altKey:{options:{},id:1,type:"bool"},isTrusted:{options:{},id:13,type:"bool"},buttons:{options:{},id:4,type:"uint32"},movementY:{options:{},id:16,type:"uint32"},clientY:{options:{},id:7,type:"uint32"},clientX:{options:{},id:6,type:"uint32"},movementX:{options:{},id:15,type:"uint32"},defaultPrevented:{options:{},id:10,type:"bool"},metaKey:{options:{},id:14,type:"bool"},timeStamp:{options:{},id:24,type:"double"},bubbles:{options:{},id:2,type:"bool"},detail:{options:{},id:11,type:"int64"},pageY:{options:{},id:20,type:"uint32"},pageX:{options:{},id:19,type:"uint32"},screenX:{options:{},id:21,type:"uint32"},screenY:{options:{},id:22,type:"uint32"}}},InstrumentedEvent:{oneofs:{event:{oneof:["mouseEvent"]}},reserved:[[4,4],"xpath",[6,6],[8,8]],fields:{mouseEvent:{options:{},id:7,type:"MouseEvent"},auto:{options:{},id:3,type:"bool"},parentComponent:{options:{},id:2,type:"string"},ownerComponent:{options:{},id:1,type:"string"},userPayload:{options:{},id:5,type:"Payload"},simplePath:{options:{},id:9,type:"string"}}},Payload:{fields:{payload:{options:{},id:2,type:"bytes"},schemaName:{options:{},id:1,type:"string"}}}}}}}}}},c={namespace:"sf.instrumentation",name:"Simple",pbjsSchema:{nested:{sf:{nested:{instrumentation:{nested:{Simple:{options:{"(meta.msg.desc)":"This message is used internally to allow convenient logging of simple text via the API without requiring a schema."},fields:{text:{options:{"(meta.max_length)":25},id:1,type:"string"}}}}}}}}}},l=new Array(16).fill(0).join("");const d=Object.freeze(new class{getId(){return l}getRootId(){}error(){}stop(){}discard(){}terminate(){}getIsSampled(){return!1}getTraceHeaders(t){return{}}getStartTimestamp(){}getStartPerfTime(){}getStopPerfTime(){}});const h=new class{getInstrumentedEventData(r,i,s){const n={ownerComponent:i.tagName,parentComponent:i.parentElement&&i.parentElement.tagName||void 0,event:r,simplePath:t.getXpath(i)};return s&&(n.userPayload=e.makePayload(s.schema,s.payload,!0)),n}getMouseEventData(t){return{altKey:t.altKey,bubbles:t.bubbles,button:t.button,buttons:t.buttons,cancelable:t.cancelable,clientX:t.clientX,clientY:t.clientY,composed:t.composed,defaultPrevented:t.defaultPrevented,detail:t.detail,eventPhase:t.eventPhase,isTrusted:t.isTrusted,timeStamp:t.timeStamp,type:t.type,ctrlKey:t.ctrlKey,metaKey:t.metaKey,movementX:t.movementX,movementY:t.movementY,offsetX:t.offsetX,offsetY:t.offsetY,pageX:t.pageX,pageY:t.pageY,screenX:t.screenX,screenY:t.screenY,shiftKey:t.shiftKey}}};const u=new class{validate(r,i){const s=e.checkSchema(r);t.requireArgument(i,"data","object");const n=e.getTypes(r),o=this.validateFields(i,n[s.message],n,e.getSchemaId(r));if(o)throw new Error(o)}validateFields(t,e,r,i){const s=e.oneofs||{},n=e.fields||{};let o;for(const e in t){const a=t[e];if(this.isNullOrUndefinedOrEmpty(a)||(s[e]?o=this.matchFieldTypes(a,s[e].oneof[0],r,i,e):n[e]&&(o=this.matchFieldTypes(a,n[e].type,r,i,e,n[e].rule))),o)return o}}isNullOrUndefinedOrEmpty(t){return null==t||""===t}matchFieldTypes(t,e,r,i,s,n){let o,a;if("repeated"===n){let n;if(Array.isArray(t)){for(const o in t)if(n=this.matchFieldTypes(t[o],e,r,i,s),n)break}else n=`Schema ${i} on field: ${s}, repeated field should be an array`;return n}switch(e){case"string":o="string";break;case"bytes":o="object",t instanceof Uint8Array||(a=`Schema ${i} on field: ${s}, bytes array is malformed`);break;case"bool":o="boolean";break;case"uint32":o="number",a=this.checkNumberRange(t,4294967295,0,i,s);break;case"int32":case"sint32":case"fixed32":case"sfixed32":o="number",a=this.checkNumberRange(t,2147483647,-2147483648,i,s);break;case"uint64":o="number",a=this.checkNumberRange(t,0x10000000000000000,0,i,s);break;case"fixed64":case"sfixed64":case"int64":case"sint64":o="number",a=this.checkNumberRange(t,0x8000000000000000,-0x8000000000000000,i,s);break;case"double":case"float":o="number",Number.isFinite(t)||(a=`Schema ${i} on field: ${s}. Value must be finite`);break;default:const n={},c=Object.keys(r);for(const t in c)n[c[t].toLowerCase()]=c[t];n[e.toLowerCase()]&&(a=this.validateFields(t,r[n[e.toLowerCase()]],r,i),o="object")}const c=(t+"").length;return typeof t!==o?`Schema ${i} on field: ${s}. Expected type ${e} but received type ${typeof t}`:c<0||c>1e4?`Schema ${i} on field: ${s}, exceeded maximum or minimum field length`:a||void 0}checkNumberRange(t,e,r,i,s){if(t>e||t<r)return`Schema ${i} on field: ${s}, number value is too large or small`}};class UpCounterImpl{constructor(e,r,i,s){this._name=e,this._ownerName=r,this._ownerAppName=i,this._tags=s,this._value=0,this._createdOn=t.time().tsNow}getName(){return this._name}getCreatedOn(){return this._createdOn}getLastUpdatedOn(){return this._lastUpdatedOn}getData(){return this._value}increment(e=1){if("number"==typeof e&&e>0)return this._value+=Math.round(e),void(this._lastUpdatedOn=t.time().tsNow);throw new Error("UpCounter can only increment positive numbers.")}reset(){this._lastUpdatedOn=void 0,this._value=0}getOwnerName(){return this._ownerName}getOwnerAppName(){return this._ownerAppName}getTags(){return this._tags}}class ValueRecorderImpl{constructor(e,r,i,s){this._name=e,this._ownerName=r,this._ownerAppName=i,this._tags=s,this._values=new Array,this._createdOn=t.time().tsNow}getName(){return this._name}getCreatedOn(){return this._createdOn}getLastUpdatedOn(){return this._lastUpdatedOn}getData(){return this.values}get values(){return this._values.slice(0,this._values.length)}record(e){if("number"==typeof e)return this._values.push(e),void(this._lastUpdatedOn=t.time().tsNow);throw new Error("ValueRecorder can only record numbers.")}reset(){this._lastUpdatedOn=void 0,this._values=[]}getOwnerName(){return this._ownerName}getOwnerAppName(){return this._ownerAppName}getTags(){return this._tags}}class SizeLimitedMap{constructor(t){if(this._map=new Map,!("number"==typeof t&&t>0))throw new Error("maxSize must be a positive number");this._maxSize=Math.ceil(t)}get maxSize(){return this._maxSize}get(t){return this._map.get(t)}has(t){return this._map.has(t)}set(t,e){return!!(this.has(t)||this._map.size<this.maxSize)&&(this._map.set(t,e),!0)}getElements(){return Array.from(this._map.values())}clear(){this._map.clear()}}var p;!function(t){t[t.Counter=0]="Counter",t[t.Percentile=1]="Percentile"}(p||(p={}));class MetricsImpl{constructor(t,e){this._ownerName=t,this._getOwnerAppName=e,this._upCounters=new SizeLimitedMap(1e3),this._valueRecorders=new SizeLimitedMap(500)}incrementCounter(t,e,r=!1,i={}){this._tagError(i,r),this._upCounter(t,i).increment(e)}trackValue(t,e,r=!1,i={}){this._tagError(i,r),this._valueRecorder(t,i).record(e)}_upCounter(t,e){const{key:r,sortedTags:i}=this._getKeyAndSortedTags(t,e,p.Counter);let s=this._upCounters.get(r);if(!s&&(s=new UpCounterImpl(t,this._ownerName,this._getOwnerAppName(),i),!this._upCounters.set(r,s)))throw new Error("Max size of 1000 exceeeded for UpCounters");return s}_valueRecorder(t,e){const{key:r,sortedTags:i}=this._getKeyAndSortedTags(t,e,p.Percentile);let s=this._valueRecorders.get(r);if(!s&&(s=new ValueRecorderImpl(t,this._ownerName,this._getOwnerAppName(),i),!this._valueRecorders.set(r,s)))throw new Error("Max size of 500 exceeeded for ValueRecorders");return s}getUpCounters(){return this._upCounters.getElements()}getValueRecorders(){return this._valueRecorders.getElements()}_tagError(t,e){t.status=!0===e?"error":"success"}_getKeyAndSortedTags(t,e,r){const i=Object.keys(e).sort().reduce(((t,r)=>(t[r]=e[r],t)),{});return{key:`${p[r]}:${t}${JSON.stringify(i)}`,sortedTags:i}}}class MockEvent{constructor(t,e,r){this.type=t,this.composed=e,this._composedPaths=r}composedPath(){return this._composedPaths}}const m=["`"],g={internalError:"o11y-error"},_=Object.freeze(Array.from(Object.values(g)));class InstrumentationImpl{constructor(t,r){this._nextGen=t,this._name=r,this._onActivityStoppedCallback=this._handleActivityStop.bind(this),this._onActivityErrorCallback=this._handleActivityError.bind(this);for(const t of m)if(this._name.indexOf(t)>=0)throw new Error(`Name cannot include the reserved character "${t}"`);this._safety=new PublicSafety({increment:t=>this._incrementError(t)}),this._metrics=this._initMetrics();const i=e.getOptions(c,"Simple","text");this._simpleTextMaxLength=i?i["(meta.max_length)"]:Number.MAX_VALUE}_initMetrics(){return new MetricsImpl(this.name,(()=>this._nextGen.appName||InstrumentationImpl.defaultAppName))}_incrementError(t=1){this._metrics.incrementCounter(g.internalError,t,!1)}get name(){return this._name}_wrapUserPayload(t,r,i=!1){let s;return"string"==typeof t?(s=c,r=t?{text:t.substr(0,this._simpleTextMaxLength)}:void 0):s=t,e.makePayload(s,r,i)}log(e,r){this._safety.tryCatch((()=>{const i=t.time().tsNow;t.requireArgument(e,"userSchemaOrText",["object","string"]);const s=this._wrapUserPayload(e,r);s&&s.payload&&this._logInternal(this.name,s.schema,s.payload,i,this._nextGen.getRootActivityId())}))}_logInternal(t,e,r,i,s){this._checkInputs(e,r);const n=this._getPayloadFromProvider(this._nextGen.appPayloadProvider),o=this._getPayloadFromProvider(this._nextGen.pagePayloadProvider);return this._nextGen.addLog(t,e,r,i,s,o,n)}error(t,e,r){return this._safety.tryCatch((()=>this._errorInternal(t,e,r,void 0)))}_errorInternal(e,r,i,s){const n=t.time().tsNow;t.requireArgument(e,"error",[Error,"string"]),"string"==typeof e&&(e=new Error(e));const a=this._wrapUserPayload(r,i,!0),c={name:e.name,message:e.message,stack:e.stack,userPayload:a,activityId:s};return this._logInternal(this.name,o,c,n,this._nextGen.getRootActivityId())}startActivity(e){return this._safety.tryCatchReturn((()=>{t.requireArgument(e,"name");return new ActivityImpl(e,this._nextGen.getRootActivityId(),this._onActivityStoppedCallback,this._onActivityErrorCallback,undefined,void 0,this._nextGen.isRootActivitySampled())}),d)}_getActivityData(t){const e=this._wrapUserPayload(t.userSchemaOrText,t.userData,!0);return{id:t.id,name:t.name,duration:t.stopPerfTime-t.startPerfTime,stopReason:t.stopReason,userPayload:e,errorCount:t.errorCount,isSampled:t.isSampled}}_handleActivityStop(t){if("discarded"===t.stopReason)return;const e=this._getActivityData(t);this._logActivity(e,t.startTimestamp,t.rootId)}_logActivity(t,e,r){this._logInternal(this.name,n,t,e,r)}_handleActivityError(t,e){this._errorInternal(t,e.userSchemaOrText,e.userData,e.id)}_getPayloadFromProvider(t){if(t){const e=t.getPayload();if(e)return this._checkInputs(e.schema,e.payload),e}}domEvent(e,r,i,s,n){this._safety.tryCatch((()=>{const o=t.time().tsNow;let c;t.requireArgument(e,"event",[Event,MockEvent]),t.requireArgument(r,"handledBy",[HTMLElement,"object"]),r instanceof HTMLElement?c=r:(r=r).template&&r.template.host instanceof HTMLElement?c=r.template.host:t.requireArgument(void 0,"handledBy");const l=this._wrapUserPayload(i,s,!0);switch(e.type){case"click":{const t=e,r=this._nextGen.getClickTracker();r&&r.markEventHandled(t);const i=h.getMouseEventData(t),s=h.getInstrumentedEventData(i,c,l);s.auto=n,this._logInternal(this.name,a,s,o,this._nextGen.getRootActivityId());break}default:throw new Error(t.notImplemented)}}))}incrementCounter(e,r=1,i=!1,s={}){this._safety.tryCatch((()=>{t.requireArgument(e,"operation","string"),t.checkForDenyListedValues(e,"operation",_),t.checkForReservedCharacters(e,"operation",m),t.requireArgument(r,"increment","number"),t.requireArgument(i,"hasError","boolean"),t.requireArgument(s,"tags","object"),Object.entries(s).forEach((e=>{t.requireArgument(e[1],`Tag value for '${e[0]}'`,["string","number","boolean"])})),this._metrics.incrementCounter(e,r,i,s)}))}trackValue(e,r,i=!1,s={}){this._safety.tryCatch((()=>{t.requireArgument(e,"operation","string"),t.checkForDenyListedValues(e,"operation",_),t.checkForReservedCharacters(e,"operation",m),t.requireArgument(r,"value","number"),t.requireArgument(i,"hasError","boolean"),t.requireArgument(s,"tags","object"),Object.entries(s).forEach((e=>{t.requireArgument(e[1],`Tag value for '${e[0]}'`,["string","number","boolean"])})),this._metrics.trackValue(e,r,i,s)}))}_checkInputs(r,i){let s;e.checkSchema(r),t.requireArgument(i,"data","object"),void 0!==i.userPayload&&e.isInternal(r)&&(s=i.userPayload,u.validate(s.schema,s.payload),i.userPayload=void 0),u.validate(r,i),void 0!==s&&(i.userPayload=s)}getUpCounters(){return this._metrics.getUpCounters().filter((t=>t.getLastUpdatedOn()))}getValueRecorders(){return this._metrics.getValueRecorders().filter((t=>t.getLastUpdatedOn()))}}InstrumentationImpl.defaultAppName="APP_NOT_REGISTERED";class RootActivityImpl extends ActivityImpl{constructor(e,r,i,s,n){super(e,void 0,r,i,void 0,s||t.generateUniqueId(32),n)}get preRootId(){return this._preRootId}set preRootId(t){this._preRootId=t}_getDetail(t,e){const r=super._getDetail(t,e);return r.isRoot=!0,r.preRootId=this.preRootId,r}}const y=new Array(32).fill(0).join("");const f=Object.freeze(new class{getId(){return y}getRootId(){}error(){}stop(){}discard(){}terminate(){}getIsSampled(){return!1}getTraceHeaders(t){return{}}getStartTimestamp(){}getStartPerfTime(){}getStopPerfTime(){}});class AppInstrumentationImpl extends InstrumentationImpl{constructor(){super(...arguments),this._onRootActivityStoppedCallback=this.handleRootActivityStop.bind(this)}startRootActivity(e,r,i){return this._safety.tryCatchReturn((()=>{t.requireArgument(e,"name");const s=new RootActivityImpl(e,this._onRootActivityStoppedCallback,this._onActivityErrorCallback,r,i);if(this.rootActivity&&!this.rootActivity.isStopped){const t=this.rootActivity.getId();this.rootActivity.terminate(),s.preRootId=t}return this.rootActivity=s,this.rootActivity}),f)}handleRootActivityStop(t){if("discarded"===t.stopReason)return;const e=this._getActivityData(t);this._logActivity(e,t.startTimestamp),this.rootActivity=void 0}_getActivityData(t){const e=super._getActivityData(t);return e.isRoot=t.isRoot,e.preRootId=t.preRootId,e}getRootActivityId(){return this.rootActivity&&this.rootActivity.getId()}isRootActivitySampled(){return this.rootActivity&&this.rootActivity.getIsSampled()}_initMetrics(){return new MetricsImpl(this.name,(()=>this.name))}}class AutomaticClickTracker{constructor(e,r){this.isActive=!1,this._boundClickListener=this.clickListener.bind(this),t.requireArgument(e,"instrumentation"),t.requireArgument(r,"document"),this.instr=e,this.document=r}activate(){this.isActive||(this.document.addEventListener("click",this._boundClickListener,!0),this.isActive=!0)}deactivate(){this.isActive&&(this.document.removeEventListener("click",this._boundClickListener,!0),this.isActive=!1)}markEventHandled(t){this.ignoredEvent=t}clickListener(t){let e=t.composedPath&&t.composedPath();e&&e.length||(e=t.path);const r=this.getClickableElement(e);r&&setTimeout((()=>{t!==this.ignoredEvent&&this.instr.domEvent(t,r,void 0,void 0,!0)}))}getClickableElement(t){const e=t?Math.min(t.length,5):0;for(let r=0;r<e;r+=1){const e=t[r],i=e.tagName&&e.tagName.toLowerCase();if("a"===i||"button"===i)return e;if("input"===i){const t=e;if(t.type&&"button"===t.type.toLowerCase())return t}}}}const v=80-"_CUT".length;class NextgenImpl{constructor(){this._logCollectors=new Set,this._instruments=new Map,this._sequence=0,this._forceDisabledLogCollectors=new Set,this._logCollectorFailures=new Map,this._isBufferingEnabled=!1,this._buffer=[]}get pagePayloadProvider(){return this._pagePayloadProvider}set pagePayloadProvider(t){this._pagePayloadProvider=t}get appPayloadProvider(){return this._appPayloadProvider}set appPayloadProvider(t){this._appPayloadProvider=t}registerApp(e,r){if(t.requireArgument(e,"name","string"),this._appInstr)throw new Error("An app has already been registered with instrumentation.");if(this._instruments.get(e))throw new Error(`The instrumentation name ${e} is already taken`);this._appInstr=new AppInstrumentationImpl(this,e),this._instruments.set(e,this._appInstr),this._isBufferingEnabled=r;const i=new Tracing(this._appInstr);return{log:this._appInstr.log.bind(this._appInstr),error:this._appInstr.error.bind(this._appInstr),startActivity:this._appInstr.startActivity.bind(this._appInstr),domEvent:this._appInstr.domEvent.bind(this._appInstr),incrementCounter:this._appInstr.incrementCounter.bind(this._appInstr),trackValue:this._appInstr.trackValue.bind(this._appInstr),networkInstrumentation:i.networkInstrumentation.bind(i),startRootActivity:this._appInstr.startRootActivity.bind(this._appInstr),registerLogCollector:this.registerLogCollector.bind(this),registerMetricsCollector:this.registerMetricsCollector.bind(this),activateClickTracker:this.activateClickTracker.bind(this),deactivateClickTracker:this.deactivateClickTracker.bind(this),disableBuffering:this.disableBuffering.bind(this)}}getInstrumentation(e){t.requireArgument(e,"name","string"),e.length>80&&(e=e.substr(0,v)+"_CUT");let r=this._instruments.get(e);if(r){if(r===this._appInstr)throw new Error(`The instrumentation name ${e} is being used by the app.`)}else r=new InstrumentationImpl(this,e),this._instruments.set(e,r);return r}get appName(){return this._appInstr&&this._appInstr.name}addLog(e,r,i,s,n,o,a){this._sequence+=1;const c={timestamp:s,rootId:n,sequence:this._sequence,loggerName:e,pagePayload:o,appPayload:a,loggerAppName:this.appName,connectionType:t.getConnectionType()};this._isBufferingEnabled&&this._buffer.push({schema:r,data:t.clone(i),logMeta:c});for(const e of this._logCollectors){const s=t.clone(i),n=this._logCollectorFailures.get(e);try{this._forceDisabledLogCollectors.has(e)||e.getIsCollectDisabled&&e.getIsCollectDisabled()||(e.collect(r,s,c),n>0&&this._logCollectorFailures.set(e,n-1))}catch(t){n>=NextgenImpl._collectorFailureLimit&&!this._forceDisabledLogCollectors.has(e)?this._forceDisabledLogCollectors.add(e):this._logCollectorFailures.set(e,n+1)}}return this._sequence}getBuffer(){return this._buffer}disableBuffering(){this._isBufferingEnabled=!1,this._buffer=[]}getClickTracker(){return this._autoClickTracker}getRootActivityId(){return this._appInstr&&this._appInstr.getRootActivityId()}isRootActivitySampled(){return this._appInstr&&this._appInstr.isRootActivitySampled()}activateClickTracker(){this._autoClickTracker||(this._autoClickTracker=new AutomaticClickTracker(this._appInstr,window.document)),this._autoClickTracker.activate()}deactivateClickTracker(){this._autoClickTracker&&(this._autoClickTracker.deactivate(),this._autoClickTracker=void 0)}registerLogCollector(e,r){if(t.requireArgument(e,"collector"),this._logCollectors.add(e),this._logCollectorFailures.set(e,0),(!e.getIsCollectDisabled||!e.getIsCollectDisabled())&&r&&r.retroactive)for(const t of this._buffer)e.collect(t.schema,t.data,t.logMeta)}registerMetricsCollector(e){if(t.requireArgument(e,"collector"),this._metricsCollector)throw new Error("A metrics Collector is already registered.");this._metricsCollector=e,this._metricsCollector.receiveMetricsExtractors({getAllUpCounters:this.getAllUpCounters.bind(this),getAllValueRecorders:this.getAllValueRecorders.bind(this)})}getAllUpCounters(){return Array.from(this._instruments.values()).map((t=>t.getUpCounters())).reduce(((t,e)=>t.concat(e)),[])}getAllValueRecorders(){return Array.from(this._instruments.values()).map((t=>t.getValueRecorders())).reduce(((t,e)=>t.concat(e)),[])}}NextgenImpl._collectorFailureLimit=5;const b=new class{get _lazyNextGen(){return this._nextgen||(this._nextgen=new NextgenImpl),this._nextgen}registerInstrumentedApp(e,r){r&&r.isProduction&&t.markProduction();const i=this._lazyNextGen.registerApp(e,r&&r.enableBuffering);return r&&(this._nextgen.appPayloadProvider=r.appPayloadProvider,this._nextgen.pagePayloadProvider=r.pagePayloadProvider),i}getInstrumentation(t){return this._lazyNextGen.getInstrumentation(t)}},I=b.registerInstrumentedApp.bind(b),C=b.getInstrumentation.bind(b),A=t.time.bind(t);class TaskerImpl{constructor(t,e,r,i){this.name=t,this._doneCallback=r,this._overDoneCallback=i,this._busyCount=0,this._isOk=!0,this._busyCount=e}get isBusy(){return this._isOk?this._busyCount>0:void 0}add(){this._isOk&&(this._busyCount+=1)}done(){this._isOk&&(this._busyCount>0?(this._busyCount-=1,this._busyCount||this._doneCallback()):(this._isOk=!1,this._overDoneCallback()))}}const k={Error:"Crimson",Activity:"CadetBlue",InstrumentedEvent:"DarkOliveGreen",O11ySample:"BlueViolet"},w={Error:"white",Activity:"white",InstrumentedEvent:"white",O11ySample:"white"};class ConsoleCollector{constructor(t){t&&this._log("ConsoleCollector",t)}collect(t,r,i){let s,n,o;"sf.instrumentation"===t.namespace?(s=t.name,n=w[t.name]||"black",o=k[t.name]||"Gainsboro"):s=e.getSchemaId(t),this._log(s,r,i,n,o)}_log(t,e,r,i="black",s="Gainsboro"){const n=`color:${i};background-color:${s}`;console.log(`%cO11Y%c ${t}`,"color:white;background-color:#FF6600;font-weight:bold",n,e||"",r||"")}}const T=new class{constructor(){this._instr=C("IdleDetector"),this._taskers=new Set,this._listeners=new Set,this._busyCheckers=new Map,this._timerCheckQueued=0}requestIdleDetectedCallback(e){t.requireArgument(e,"callback","function"),this._listeners.add(e),this.checkIfLoaded()}declareNotifierTaskSingle(e){t.requireArgument(e,"name","string");const r=this.addTasker(e,1);return{get isBusy(){return r.isBusy},done:()=>{r.done(),this._taskers.delete(r)}}}declareNotifierTaskMulti(e,r=0){if(t.requireArgument(e,"name","string"),void 0!==r&&(t.requireArgument(r,"existingBusyCount","number"),r<0||parseInt(r.toString(),10)!==r))throw new Error("existingBusyCount accepts only non-negative integers");return this.addTasker(e,r)}declarePollableTaskMulti(e,r){t.requireArgument(e,"name","string"),t.requireArgument(r,"isBusyChecker","function"),this._busyCheckers.set(r,e)}addTasker(t,e){const r=new TaskerImpl(t,e,(()=>{this.checkIfLoaded()}),(()=>{throw new Error(`Tasker '${r.name}' is done too many times.`)}));return this._taskers.add(r),r}areAllNotifiersIdle(){return!Array.from(this._taskers.values()).some((t=>t.isBusy))}areAllPollablesIdle(){return!Array.from(this._busyCheckers.keys()).some(((t,e)=>{try{return t()}catch(t){return this._instr.error(t,`BusyChecker #${e}`),!1}}))}checkIfLoaded(){this._listeners.size&&(this._timerCheckQueued&&window.clearTimeout(this._timerCheckQueued),this.areAllNotifiersIdle()&&(this._timerCheckQueued=window.setTimeout((()=>{this._timerCheckQueued=window.setTimeout((()=>{this.doubleCheck()}),40)}),0)))}doubleCheck(){if(this._timerCheckQueued=0,this.areAllNotifiersIdle())if(this.areAllPollablesIdle()){const t=Array.from(this._listeners.values());this._listeners.clear(),this.notify(t)}else this._timerCheckQueued=window.setTimeout((()=>{this.doubleCheck()}),15)}notify(e){const r=t.time().tsNow;for(const[t,i]of e.entries())try{i(r)}catch(e){this._instr.error(e,`Listener #${t}`)}}};export{ConsoleCollector,C as getInstrumentation,T as idleDetector,I as registerInstrumentedApp,A as time};
|
|
2
2
|
//# sourceMappingURL=client.js.map
|