@grafana/faro-core 2.7.1 → 2.8.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/bundle/faro-core.iife.js +1 -1
- package/dist/bundle/types/testUtils/mockTransport.d.ts +1 -1
- package/dist/bundle/types/transports/batchExecutor.d.ts +1 -1
- package/dist/bundle/types/version.d.ts +1 -1
- package/dist/cjs/transports/batchExecutor.js +8 -7
- package/dist/cjs/transports/batchExecutor.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/transports/batchExecutor.js +8 -7
- package/dist/esm/transports/batchExecutor.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/types/testUtils/mockTransport.d.ts +1 -1
- package/dist/types/transports/batchExecutor.d.ts +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
var GrafanaFaroCore=function(e){"use strict";class t{constructor(e,t){var n,r;this.signalBuffer=[],this.itemLimit=null!==(n=null==t?void 0:t.itemLimit)&&void 0!==n?n:50,this.sendTimeout=null!==(r=null==t?void 0:t.sendTimeout)&&void 0!==r?r:250,this.paused=(null==t?void 0:t.paused)||!1,this.sendFn=e,this.flushInterval=-1,this.paused||this.start(),document.addEventListener("visibilitychange",()=>{"hidden"===document.visibilityState&&this.flush()})}addItem(e){this.paused||(this.signalBuffer.push(e),this.signalBuffer.length>=this.itemLimit&&this.flush())}start(){this.paused=!1,this.sendTimeout>0&&(this.flushInterval=window.setInterval(()=>this.flush(),this.sendTimeout))}pause(){this.paused=!0,clearInterval(this.flushInterval)}groupItems(e){const t=new Map;return e.forEach(e=>{const n=JSON.stringify(e.meta);let r=t.get(n);r=void 0===r?[e]:[...r,e],t.set(n,r)}),Array.from(t.values())}flush(){if(this.paused||0===this.signalBuffer.length)return;this.groupItems(this.signalBuffer).forEach(this.sendFn),this.signalBuffer=[]}}var n;e.TransportItemType=void 0,(n=e.TransportItemType||(e.TransportItemType={})).EXCEPTION="exception",n.LOG="log",n.MEASUREMENT="measurement",n.TRACE="trace",n.EVENT="event";const r={[e.TransportItemType.EXCEPTION]:"exceptions",[e.TransportItemType.LOG]:"logs",[e.TransportItemType.MEASUREMENT]:"measurements",[e.TransportItemType.TRACE]:"traces",[e.TransportItemType.EVENT]:"events"};function i(e,n,r,i){var a;n.debug("Initializing transports");const o=[];let u=r.paused,c=[];const l=e=>{let t=e;for(const e of c){const n=t.map(e).filter(Boolean);if(0===n.length)return[];t=s(n,r)}return t},d=e=>{const t=l(e);if(0!==t.length)for(const e of o)n.debug(`Transporting item using ${e.name}\n`,t),e.isBatched()&&e.send(t)};let g;(null===(a=r.batching)||void 0===a?void 0:a.enabled)&&(g=new t(d,{sendTimeout:r.batching.sendTimeout,itemLimit:r.batching.itemLimit,paused:u}));return{add:(...t)=>{n.debug("Adding transports"),t.forEach(t=>{n.debug(`Adding "${t.name}" transport`);o.some(e=>e===t)?n.warn(`Transport ${t.name} is already added`):(t.unpatchedConsole=e,t.internalLogger=n,t.config=r,t.metas=i,o.push(t))})},addBeforeSendHooks:(...e)=>{n.debug("Adding beforeSendHooks\n",c),e.forEach(e=>{e&&c.push(e)})},getBeforeSendHooks:()=>[...c],execute:e=>{var t;u||((null===(t=r.batching)||void 0===t?void 0:t.enabled)&&(null==g||g.addItem(e)),(e=>{var t,i;if((null===(t=r.batching)||void 0===t?void 0:t.enabled)&&o.every(e=>e.isBatched()))return;const[s]=l([e]);if(void 0!==s)for(const e of o)n.debug(`Transporting item using ${e.name}\n`,s),e.isBatched()?(null===(i=r.batching)||void 0===i?void 0:i.enabled)||e.send([s]):e.send(s)})(e))},isPaused:()=>u,pause:()=>{n.debug("Pausing transports"),null==g||g.pause(),u=!0},remove:(...e)=>{n.debug("Removing transports"),e.forEach(e=>{n.debug(`Removing "${e.name}" transport`);const t=o.indexOf(e);-1!==t?o.splice(t,1):n.warn(`Transport "${e.name}" is not added`)})},removeBeforeSendHooks:(...e)=>{c.filter(t=>!e.includes(t))},get transports(){return[...o]},unpause:()=>{n.debug("Unpausing transports"),null==g||g.start(),u=!1}}}function s(t,n){if(n.preserveOriginalError)for(const n of t)n.type===e.TransportItemType.EXCEPTION&&delete n.payload.originalError;return t}function a(e,t){return typeof e===t}function o(e,t){return Object.prototype.toString.call(e)===`[object ${t}]`}function u(e,t){try{return e instanceof t}catch(e){return!1}}const c=e=>a(e,"null"),l=e=>a(e,"string"),d=e=>a(e,"number")&&!isNaN(e)||a(e,"bigint"),g=e=>!c(e)&&a(e,"object"),p=e=>a(e,"function"),f=e=>o(e,"Array"),m="undefined"!=typeof Event,h="undefined"!=typeof Error,b=e=>h&&u(e,Error),v="undefined"!=typeof Element,E="undefined"!=typeof Map;function y(e){return null==e||(f(e)||l(e)?0===e.length:!!g(e)&&0===Object.keys(e).length)}function T(e,t){if(e===t)return!0;if(a(e,"number")&&isNaN(e))return a(t,"number")&&isNaN(t);const n=f(e),r=f(t);if(n!==r)return!1;if(n&&r){const n=e.length;if(n!==t.length)return!1;for(let r=n;0!==r--;)if(!T(e[r],t[r]))return!1;return!0}const i=g(e),s=g(t);if(i!==s)return!1;if(e&&t&&i&&s){const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let e of n)if(!r.includes(e))return!1;for(let r of n)if(!T(e[r],t[r]))return!1;return!0}return!1}function O(){return Date.now()}function I(){return"undefined"!=typeof performance&&"function"==typeof performance.now?performance.now():Date.now()}function S(){return(new Date).toISOString()}function A(e){return new Date(e).toISOString()}var L;e.LogLevel=void 0,(L=e.LogLevel||(e.LogLevel={})).TRACE="trace",L.DEBUG="debug",L.INFO="info",L.LOG="log",L.WARN="warn",L.ERROR="error";const _=e.LogLevel.LOG,j=[e.LogLevel.TRACE,e.LogLevel.DEBUG,e.LogLevel.INFO,e.LogLevel.LOG,e.LogLevel.WARN,e.LogLevel.ERROR];function w(){}const x="abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ0123456789";function N(e=10){const t=new Uint32Array(e),n="undefined"!=typeof globalThis?globalThis.crypto:void 0;if(null==n?void 0:n.getRandomValues)n.getRandomValues(t);else for(let n=0;n<e;n++)t[n]=Math.floor(4294967296*Math.random());let r="";for(let n=0;n<e;n++)r+=x[t[n]%59];return r}const R="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:"undefined"!=typeof self?self:void 0;function U(e){const t=`__faroBundleId_${e}`,n=null==R?void 0:R[t];if("string"==typeof n&&""!==n)return n;const r="undefined"!=typeof window?window[t]:void 0;return"string"==typeof r&&""!==r?r:void 0}function k(){const e=new WeakSet;return function(t,n){if(g(n)&&null!==n){if(e.has(n))return null;e.add(n)}return n}}function C(e={}){return JSON.stringify(null!=e?e:{},k())}function B(e={}){const t={};for(const[n,r]of Object.entries(e))t[n]=g(r)&&null!==r?C(r):String(r);return t}class P{constructor(){this.subscribers=[]}subscribe(e){return this.subscribers.push(e),{unsubscribe:()=>this.unsubscribe(e)}}unsubscribe(e){this.subscribers=this.subscribers.filter(t=>t!==e)}notify(e){this.subscribers.forEach(t=>t(e))}first(){const e=new P,t=t=>{e.notify(t),n.unsubscribe()},n=this.subscribe(t),r=e.unsubscribe.bind(e);return this.withUnsubscribeOverride(e,r,t)}takeWhile(e){const t=new P,n=r=>{e(r)?t.notify(r):t.unsubscribe(n)};this.subscribe(n);const r=t.unsubscribe.bind(t);return this.withUnsubscribeOverride(t,r,n)}filter(e){const t=new P,n=n=>{e(n)&&t.notify(n)};this.subscribe(n);const r=t.unsubscribe.bind(t);return this.withUnsubscribeOverride(t,r,n)}merge(...e){const t=new P,n=[];e.forEach(e=>{const r=e.subscribe(e=>{t.notify(e)});n.push(r)});const r=t.unsubscribeAll.bind(t);return t.unsubscribe=()=>{n.forEach(e=>e.unsubscribe()),r()},t}withUnsubscribeOverride(e,t,n){return e.unsubscribe=e=>{t(e),this.unsubscribe(n)},e}unsubscribeAll(){this.subscribers=[]}}var M;e.InternalLoggerLevel=void 0,(M=e.InternalLoggerLevel||(e.InternalLoggerLevel={}))[M.OFF=0]="OFF",M[M.ERROR=1]="ERROR",M[M.WARN=2]="WARN",M[M.INFO=3]="INFO",M[M.VERBOSE=4]="VERBOSE";const D={debug:w,error:w,info:w,prefix:"Faro",warn:w},F=e.InternalLoggerLevel.ERROR,V=Object.assign({},console);let $=V;function z(e){var t;return $=null!==(t=e.unpatchedConsole)&&void 0!==t?t:$,$}function G(t=V,n=F){const r=D;return n>e.InternalLoggerLevel.OFF&&(r.error=n>=e.InternalLoggerLevel.ERROR?function(...e){t.error(`${r.prefix}\n`,...e)}:w,r.warn=n>=e.InternalLoggerLevel.WARN?function(...e){t.warn(`${r.prefix}\n`,...e)}:w,r.info=n>=e.InternalLoggerLevel.INFO?function(...e){t.info(`${r.prefix}\n`,...e)}:w,r.debug=n>=e.InternalLoggerLevel.VERBOSE?function(...e){t.debug(`${r.prefix}\n`,...e)}:w),r}let H=D;function K(e,t){return H=G(e,t.internalLoggerLevel),H}class W{constructor(){this.unpatchedConsole=V,this.internalLogger=D,this.config={},this.metas={}}logDebug(...e){this.internalLogger.debug(`${this.name}\n`,...e)}logInfo(...e){this.internalLogger.info(`${this.name}\n`,...e)}logWarn(...e){this.internalLogger.warn(`${this.name}\n`,...e)}logError(...e){this.internalLogger.error(`${this.name}\n`,...e)}}function X(e,t){var n,r;if(void 0===t)return e;if(void 0===e)return{resourceSpans:t};const i=null===(n=e.resourceSpans)||void 0===n?void 0:n[0];if(void 0===i)return e;const s=(null==i?void 0:i.scopeSpans)||[],a=(null===(r=null==t?void 0:t[0])||void 0===r?void 0:r.scopeSpans)||[];return Object.assign(Object.assign({},e),{resourceSpans:[Object.assign(Object.assign({},i),{scopeSpans:[...s,...a]})]})}const J={Normal:"normal",Critical:"critical"};var q;e.UserActionState=void 0,(q=e.UserActionState||(e.UserActionState={}))[q.Started=0]="Started",q[q.Halted=1]="Halted",q[q.Cancelled=2]="Cancelled",q[q.Ended=3]="Ended";class Q{constructor(){this.buffer=[]}addItem(e){this.buffer.push(e)}flushBuffer(e){if(p(e))for(const t of this.buffer)e(t);this.buffer.length=0}size(){return this.buffer.length}}class Y extends P{constructor({name:t,parentId:n,trigger:r,transports:i,attributes:s,trackUserActionsExcludeItem:a,importance:o=J.Normal,pushEvent:u}){super(),this.name=t,this.attributes=s,this.id=N(),this.trigger=r,this.parentId=null!=n?n:this.id,this.trackUserActionsExcludeItem=a,this.importance=o,this._pushEvent=u,this._itemBuffer=new Q,this._transports=i,this._state=e.UserActionState.Started,this._start()}addItem(t){return this._state===e.UserActionState.Started&&(this._itemBuffer.addItem(t),!0)}_start(){this._state=e.UserActionState.Started,this._state===e.UserActionState.Started&&(this.startTime=O(),this._startTimeMono=I())}halt(){this._state===e.UserActionState.Started&&(this._state=e.UserActionState.Halted,this.notify(this._state))}cancel(){this._state===e.UserActionState.Started&&this._itemBuffer.flushBuffer(e=>{this._transports.execute(e)}),this._state=e.UserActionState.Cancelled,this.notify(this._state)}end(){if(this._state===e.UserActionState.Cancelled)return;const t=O(),n=I()-this._startTimeMono;this._state=e.UserActionState.Ended,this._itemBuffer.flushBuffer(t=>{if(function(t,n){return(null==n?void 0:n(t))||t.type===e.TransportItemType.MEASUREMENT&&"web-vitals"===t.payload.type}(t,this.trackUserActionsExcludeItem))return void this._transports.execute(t);const n=Object.assign(Object.assign({},t),{payload:Object.assign(Object.assign({},t.payload),{action:{parentId:this.id,name:this.name}})});this._transports.execute(n)}),this._state=e.UserActionState.Ended,this.notify(this._state),this._pushEvent("faro.user.action",Object.assign({userActionName:this.name,userActionStartTime:this.startTime.toString(),userActionEndTime:t.toString(),userActionDuration:n.toString(),userActionTrigger:this.trigger,userActionImportance:this.importance},B(this.attributes)),void 0,{timestampOverwriteMs:this.startTime,customPayloadTransformer:e=>(e.action={id:this.id,name:this.name},e)})}getState(){return this._state}}const Z=new P;function ee(t,n){if(!t)return!1;return(null==t?void 0:t.getState())===e.UserActionState.Started&&(t.addItem(n),!0)}const te="Error";let ne;function re({internalLogger:t,config:n,metas:r,transports:i,tracesApi:s,userActionsApi:a}){var o;t.debug("Initializing exceptions API");let u=null;ne=null!==(o=n.parseStacktrace)&&void 0!==o?o:ne;const d=e=>{t.debug("Changing stacktrace parser"),ne=null!=e?e:ne},{ignoreErrors:p=[],preserveOriginalError:m}=n;return d(n.parseStacktrace),{changeStacktraceParser:d,getStacktraceParser:()=>ne,pushError:(o,{skipDedupe:d,stackFrames:h,type:v,context:E,spanContext:O,timestampOverwriteMs:I,originalError:L,fingerprint:_,fatal:j}={})=>{var w;if(!function(e,t){const{message:n,name:r,stack:i}=t;return s=e,a=n+" "+r+" "+i,s.some(e=>l(e)?a.includes(e):!!a.match(e));var s,a}(p,null!=L?L:o))try{const l=B(Object.assign(Object.assign({},function(e){let t=e.cause;b(t)?t=e.cause.toString():null!==t&&(g(e.cause)||f(e.cause))?t=C(e.cause):null!=t&&(t=e.cause.toString());return null==t?{}:{cause:t}}(null!=L?L:o)),null!=E?E:{})),p={meta:r.value,payload:Object.assign(Object.assign(Object.assign(Object.assign({type:v||o.name||te,value:o.message,timestamp:I?A(I):S(),trace:O?{trace_id:O.traceId,span_id:O.spanId}:s.getTraceContext()},y(l)?{}:{context:l}),m?{originalError:L}:{}),_?{fingerprint:_}:{}),void 0!==j?{fatal:j}:{}),type:e.TransportItemType.EXCEPTION};(null==(h=null!=h?h:o.stack?null==ne?void 0:ne(o).frames:void 0)?void 0:h.length)&&(p.payload.stacktrace={frames:h});const x={type:p.payload.type,value:p.payload.value,stacktrace:p.payload.stacktrace,context:p.payload.context,fingerprint:p.payload.fingerprint,fatal:null!==(w=p.payload.fatal)&&void 0!==w&&w};if(!d&&n.dedupe&&!c(u)&&T(x,u))return void t.debug("Skipping error push because it is the same as the last one\n",p.payload);u=x,t.debug("Pushing exception\n",p),ee(a.getActiveUserAction(),p)||i.execute(p)}catch(e){t.error("Error pushing event",e)}}}}const ie=e=>e.map(e=>{try{return String(e)}catch(e){return""}}).join(" ");function se(t,n,r,i,s){n.debug("Initializing API");let a=null;const o=function({transports:t,internalLogger:n,config:r,pushEvent:i}){var s;const a=null===(s=r.userActionsInstrumentation)||void 0===s?void 0:s.excludeItem;let o;const u=()=>o;return{startUserAction:(r,s,c)=>{if(void 0===u()){const n=new Y({name:r,transports:t,attributes:s,trigger:(null==c?void 0:c.triggerName)||"faroApiCall",importance:(null==c?void 0:c.importance)||J.Normal,trackUserActionsExcludeItem:a,pushEvent:i});return n.filter(t=>[e.UserActionState.Ended,e.UserActionState.Cancelled].includes(t)).first().subscribe(()=>{o=void 0}),Z.notify({type:"user_action_start",userAction:n}),o=n,o}n.error("Attempted to create a new user action while one is already running. This is not possible.")},getActiveUserAction:u}}({transports:s,config:r,internalLogger:n,pushEvent:(e,t,r,i)=>{a?a(e,t,r,i):n.warn("pushEventImpl is not initialized. Event dropped:",{name:e,attributes:t,domain:r,options:i})}}),u=function(t,n,r,i,s){let a;return n.debug("Initializing traces API"),{getOTEL:()=>a,getTraceContext:()=>{const e=null==a?void 0:a.trace.getSpanContext(a.context.active());return e?{trace_id:e.traceId,span_id:e.spanId}:void 0},initOTEL:(e,t)=>{n.debug("Initializing OpenTelemetry"),a={trace:e,context:t}},isOTELInitialized:()=>!!a,pushTraces:t=>{try{const r={type:e.TransportItemType.TRACE,payload:t,meta:i.value};n.debug("Pushing trace\n",r),s.execute(r)}catch(e){n.error("Error pushing trace\n",e)}}}}(0,n,0,i,s),d={internalLogger:n,userActionsApi:o,config:r,metas:i,transports:s,tracesApi:u},g=function({internalLogger:t,config:n,metas:r,transports:i,tracesApi:s,userActionsApi:a}){let o=null;return{pushEvent:(u,l,d,{skipDedupe:g,spanContext:p,timestampOverwriteMs:f,customPayloadTransformer:m=e=>e}={})=>{try{const h=B(l),b={meta:r.value,payload:m({name:u,domain:null!=d?d:n.eventDomain,attributes:y(h)?void 0:h,timestamp:f?A(f):S(),trace:p?{trace_id:p.traceId,span_id:p.spanId}:s.getTraceContext()}),type:e.TransportItemType.EVENT},v={name:b.payload.name,attributes:b.payload.attributes,domain:b.payload.domain};if(!g&&n.dedupe&&!c(o)&&T(v,o))return void t.debug("Skipping event push because it is the same as the last one\n",b.payload);o=v,t.debug("Pushing event\n",b),ee(a.getActiveUserAction(),b)||i.execute(b)}catch(e){t.error("Error pushing event",e)}}}}(d);return a=g.pushEvent,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},u),re(d)),function({internalLogger:e,metas:t}){let n,r,i,s;e.debug("Initializing meta API");const a=e=>{r&&t.remove(r),r={user:e},t.add(r)},o=(e,r)=>{var i;const s=null==r?void 0:r.overrides,a=s?{overrides:Object.assign(Object.assign({},null===(i=null==n?void 0:n.session)||void 0===i?void 0:i.overrides),s)}:{};n&&t.remove(n),n={session:Object.assign(Object.assign({},y(e)?void 0:e),a)},t.add(n)},u=()=>t.value.session,c=()=>t.value.page;return{setUser:a,resetUser:a,setSession:o,resetSession:o,getSession:u,setView:(e,n)=>{var r;if((null==n?void 0:n.overrides)&&o(u(),{overrides:n.overrides}),(null===(r=null==i?void 0:i.view)||void 0===r?void 0:r.name)===(null==e?void 0:e.name))return;const s=i;i={view:e},t.add(i),s&&t.remove(s)},getView:()=>t.value.view,setPage:e=>{var n;const r=l(e)?Object.assign(Object.assign({},null!==(n=null==s?void 0:s.page)&&void 0!==n?n:c()),{id:e}):e;s&&t.remove(s),s={page:r},t.add(s)},getPage:c}}(d)),function({internalLogger:t,config:n,metas:r,transports:i,tracesApi:s,userActionsApi:a}){var o;t.debug("Initializing logs API");let u=null;const l=null!==(o=n.logArgsSerializer)&&void 0!==o?o:ie;return{pushLog:(o,{context:d,level:g,skipDedupe:p,spanContext:f,timestampOverwriteMs:m}={})=>{try{const h=B(d),b={type:e.TransportItemType.LOG,payload:{message:l(o),level:null!=g?g:_,context:y(h)?void 0:h,timestamp:m?A(m):S(),trace:f?{trace_id:f.traceId,span_id:f.spanId}:s.getTraceContext()},meta:r.value},v={message:b.payload.message,level:b.payload.level,context:b.payload.context};if(!p&&n.dedupe&&!c(u)&&T(v,u))return void t.debug("Skipping log push because it is the same as the last one\n",b.payload);u=v,t.debug("Pushing log\n",b),ee(a.getActiveUserAction(),b)||i.execute(b)}catch(e){t.error("Error pushing log\n",e)}}}}(d)),function({internalLogger:t,config:n,metas:r,transports:i,tracesApi:s,userActionsApi:a}){t.debug("Initializing measurements API");let o=null;return{pushMeasurement:(u,{skipDedupe:l,context:d,spanContext:g,timestampOverwriteMs:p}={})=>{try{const f=B(d),m={type:e.TransportItemType.MEASUREMENT,payload:Object.assign(Object.assign({},u),{trace:g?{trace_id:g.traceId,span_id:g.spanId}:s.getTraceContext(),timestamp:p?A(p):S(),context:y(f)?void 0:f}),meta:r.value},h={type:m.payload.type,values:m.payload.values,context:m.payload.context};if(!l&&n.dedupe&&!c(o)&&T(h,o))return void t.debug("Skipping measurement push because it is the same as the last one\n",m.payload);o=h,t.debug("Pushing measurement\n",m),ee(a.getActiveUserAction(),m)||i.execute(m)}catch(e){t.error("Error pushing measurement\n",e)}}}}(d)),g),o)}const ae="2.7.1";function oe(e){var t,n;const r=e.config.app.name,i=r?function(e){return null==R?void 0:R[`__faroGitHash_${e}`]}(r):void 0,s={sdk:{version:ae,name:"faro"},app:Object.assign({bundleId:r&&U(r)},void 0!==i?{gitHash:i}:{})},a=null===(t=e.config.sessionTracking)||void 0===t?void 0:t.session;a&&e.api.setSession(a),e.config.app&&(s.app=Object.assign(Object.assign({},e.config.app),s.app)),e.config.user&&(s.user=e.config.user),e.config.view&&(s.view=e.config.view),e.metas.add(s,...null!==(n=e.config.metas)&&void 0!==n?n:[])}const ue="_faroInternal";function ce(e){e.config.isolate?e.internalLogger.debug("Skipping registering internal Faro instance on global object"):(e.internalLogger.debug("Registering internal Faro instance on global object"),Object.defineProperty(R,ue,{configurable:!1,enumerable:!1,writable:!1,value:e}))}function le(){return ue in R}function de(t,n,r,i,s,a,o){return n.debug("Initializing Faro"),e.faro={api:a,config:r,instrumentations:o,internalLogger:n,metas:i,pause:s.pause,transports:s,unpatchedConsole:t,unpause:s.unpause},ce(e.faro),function(e){if(e.config.preventGlobalExposure)e.internalLogger.debug("Skipping registering public Faro instance in the global scope");else{if(e.internalLogger.debug(`Registering public faro reference in the global scope using "${e.config.globalObjectKey}" key`),e.config.globalObjectKey in R)return void e.internalLogger.warn(`Skipping global registration due to key "${e.config.globalObjectKey}" being used already. Please set "globalObjectKey" to something else or set "preventGlobalExposure" to "true"`);Object.defineProperty(R,e.config.globalObjectKey,{configurable:!1,writable:!1,value:e})}}(e.faro),e.faro}e.faro={api:{pushLog:()=>{},pushError:()=>{},changeStacktraceParser:()=>{},getStacktraceParser:()=>{},pushMeasurement:()=>{},pushTraces:()=>{},getOTEL:()=>{},getTraceContext:()=>{},initOTEL:()=>{},isOTELInitialized:()=>!1,setUser:()=>{},resetUser:()=>{},setSession:()=>{},resetSession:()=>{},getSession:()=>{},setView:()=>{},getView:()=>{},setPage:()=>{},getPage:()=>{},pushEvent:()=>{},startUserAction:()=>{},getActiveUserAction:()=>{}}};return e.BaseExtension=W,e.BaseInstrumentation=class extends W{constructor(){super(...arguments),this.api={},this.transports={}}},e.BaseTransport=class extends W{isBatched(){return!1}getIgnoreUrls(){return[]}},e.EVENT_CLICK="click",e.EVENT_NAVIGATION="navigation",e.EVENT_OVERRIDES_SERVICE_NAME="service_name_override",e.EVENT_ROUTE_CHANGE="route_change",e.EVENT_SESSION_EXTEND="session_extend",e.EVENT_SESSION_RESUME="session_resume",e.EVENT_SESSION_START="session_start",e.EVENT_VIEW_CHANGED="view_changed",e.Observable=P,e.UserActionImportance=J,e.VERSION=ae,e.allLogLevels=j,e.clampSamplingRate=function(e){return Math.min(1,Math.max(0,e))},e.createInternalLogger=G,e.createPromiseBuffer=function(e){const{size:t,concurrency:n}=e,r=[];let i=0;const s=()=>{if(i<n&&r.length){const{producer:e,resolve:t,reject:n}=r.shift();i++,e().then(e=>{i--,s(),t(e)},e=>{i--,s(),n(e)})}};return{add:e=>{if(r.length+i>=t)throw new Error("Task buffer full");return new Promise((t,n)=>{r.push({producer:e,resolve:t,reject:n}),s()})}}},e.dateNow=O,e.deepEqual=T,e.defaultBatchingConfig={enabled:!0,sendTimeout:250,itemLimit:50},e.defaultErrorArgsSerializer=e=>e.map(e=>g(e)?C(e):String(e)).join(" "),e.defaultExceptionType=te,e.defaultGlobalObjectKey="faro",e.defaultInternalLoggerLevel=F,e.defaultLogArgsSerializer=ie,e.defaultLogLevel=_,e.defaultUnpatchedConsole=V,e.genShortID=N,e.getCircularDependencyReplacer=k,e.getCurrentTimestamp=S,e.getInternalFaroFromGlobalObject=function(){return R[ue]},e.getTransportBody=function(t){let n={meta:{}};return void 0!==t[0]&&(n.meta=t[0].meta),t.forEach(t=>{switch(t.type){case e.TransportItemType.LOG:case e.TransportItemType.EVENT:case e.TransportItemType.EXCEPTION:case e.TransportItemType.MEASUREMENT:{const e=r[t.type],i=n[e];n=Object.assign(Object.assign({},n),{[e]:void 0===i?[t.payload]:[...i,t.payload]});break}case e.TransportItemType.TRACE:n=Object.assign(Object.assign({},n),{traces:X(n.traces,t.payload.resourceSpans)})}}),n},e.globalObject=R,e.initializeFaro=function(e){const t=z(e),n=K(t,e);if(le()&&!e.isolate)return void n.error('Faro is already registered. Either add instrumentations, transports etc. to the global faro instance or use the "isolate" property');n.debug("Initializing");const r=function(e,t){let n=[],r=[];const i=()=>n.reduce((e,t)=>Object.assign(e,p(t)?t():t),{}),s=()=>{if(r.length){const e=i();r.forEach(t=>t(e))}};return{add:(...e)=>{t.debug("Adding metas\n",e),n.push(...e),s()},remove:(...e)=>{t.debug("Removing metas\n",e),n=n.filter(t=>!e.includes(t)),s()},addListener:e=>{t.debug("Adding metas listener\n",e),r.push(e)},removeListener:e=>{t.debug("Removing metas listener\n",e),r=r.filter(t=>t!==e)},get value(){return i()}}}(0,n),s=i(t,n,e,r),a=se(0,n,e,r,s),o=function(e,t,n,r,i,s){t.debug("Initializing instrumentations");const a=[];return{add:(...o)=>{t.debug("Adding instrumentations"),o.forEach(o=>{t.debug(`Adding "${o.name}" instrumentation`),a.some(e=>e.name===o.name)?t.warn(`Instrumentation ${o.name} is already added`):(o.unpatchedConsole=e,o.internalLogger=t,o.config=n,o.metas=r,o.transports=i,o.api=s,a.push(o),o.initialize())})},get instrumentations(){return[...a]},remove:(...e)=>{t.debug("Removing instrumentations"),e.forEach(e=>{var n,r;t.debug(`Removing "${e.name}" instrumentation`);const i=a.reduce((t,n,r)=>null===t&&n.name===e.name?r:null,null);null!==i?(null===(r=(n=a[i]).destroy)||void 0===r||r.call(n),a.splice(i,1)):t.warn(`Instrumentation "${e.name}" is not added`)})}}}(t,n,e,r,s,a),u=de(t,n,e,r,s,a,o);return oe(u),function(e){e.transports.add(...e.config.transports),e.transports.addBeforeSendHooks(e.config.beforeSend)}(u),function(e){e.instrumentations.add(...e.config.instrumentations)}(u),u},e.internalGlobalObjectKey=ue,e.isArray=f,e.isBoolean=e=>a(e,"boolean"),e.isDomError=e=>o(e,"DOMError"),e.isDomException=e=>o(e,"DOMException"),e.isElement=e=>v&&u(e,Element),e.isElementDefined=v,e.isEmpty=y,e.isError=b,e.isErrorDefined=h,e.isErrorEvent=e=>o(e,"ErrorEvent"),e.isEvent=e=>m&&u(e,Event),e.isEventDefined=m,e.isFunction=p,e.isInstanceOf=u,e.isInt=e=>d(e)&&Number.isInteger(e),e.isInternalFaroOnGlobalObject=le,e.isMap=e=>E&&u(e,Map),e.isMapDefined=E,e.isNull=c,e.isNumber=d,e.isObject=g,e.isPrimitive=e=>!g(e)&&!p(e),e.isRegExp=e=>o(e,"RegExp"),e.isString=l,e.isSymbol=e=>a(e,"symbol"),e.isSyntheticEvent=e=>g(e)&&"nativeEvent"in e&&"preventDefault"in e&&"stopPropagation"in e,e.isThenable=e=>p(null==e?void 0:e.then),e.isToString=o,e.isTypeof=a,e.isUndefined=e=>a(e,"undefined"),e.monoNow=I,e.noop=w,e.setInternalFaroOnGlobalObject=ce,e.stringifyExternalJson=C,e.stringifyObjectValues=B,e.transportItemTypeToBodyKey=r,e.unknownString="unknown",e.userActionsMessageBus=Z,e}({});
|
|
1
|
+
var GrafanaFaroCore=function(e){"use strict";class t{constructor(e,t){var n,r;this.signalBuffer=[],this.itemLimit=null!==(n=null==t?void 0:t.itemLimit)&&void 0!==n?n:50,this.sendTimeout=null!==(r=null==t?void 0:t.sendTimeout)&&void 0!==r?r:250,this.paused=(null==t?void 0:t.paused)||!1,this.sendFn=e,this.paused||this.start(),"undefined"!=typeof document&&document.addEventListener("visibilitychange",()=>{"hidden"===document.visibilityState&&this.flush()})}addItem(e){this.paused||(this.signalBuffer.push(e),this.signalBuffer.length>=this.itemLimit&&this.flush())}start(){this.paused=!1,this.sendTimeout>0&&(this.flushInterval=setInterval(()=>this.flush(),this.sendTimeout))}pause(){this.paused=!0,clearInterval(this.flushInterval)}groupItems(e){const t=new Map;return e.forEach(e=>{const n=JSON.stringify(e.meta);let r=t.get(n);r=void 0===r?[e]:[...r,e],t.set(n,r)}),Array.from(t.values())}flush(){if(this.paused||0===this.signalBuffer.length)return;this.groupItems(this.signalBuffer).forEach(this.sendFn),this.signalBuffer=[]}}var n;e.TransportItemType=void 0,(n=e.TransportItemType||(e.TransportItemType={})).EXCEPTION="exception",n.LOG="log",n.MEASUREMENT="measurement",n.TRACE="trace",n.EVENT="event";const r={[e.TransportItemType.EXCEPTION]:"exceptions",[e.TransportItemType.LOG]:"logs",[e.TransportItemType.MEASUREMENT]:"measurements",[e.TransportItemType.TRACE]:"traces",[e.TransportItemType.EVENT]:"events"};function i(e,n,r,i){var a;n.debug("Initializing transports");const o=[];let u=r.paused,c=[];const l=e=>{let t=e;for(const e of c){const n=t.map(e).filter(Boolean);if(0===n.length)return[];t=s(n,r)}return t},d=e=>{const t=l(e);if(0!==t.length)for(const e of o)n.debug(`Transporting item using ${e.name}\n`,t),e.isBatched()&&e.send(t)};let g;(null===(a=r.batching)||void 0===a?void 0:a.enabled)&&(g=new t(d,{sendTimeout:r.batching.sendTimeout,itemLimit:r.batching.itemLimit,paused:u}));return{add:(...t)=>{n.debug("Adding transports"),t.forEach(t=>{n.debug(`Adding "${t.name}" transport`);o.some(e=>e===t)?n.warn(`Transport ${t.name} is already added`):(t.unpatchedConsole=e,t.internalLogger=n,t.config=r,t.metas=i,o.push(t))})},addBeforeSendHooks:(...e)=>{n.debug("Adding beforeSendHooks\n",c),e.forEach(e=>{e&&c.push(e)})},getBeforeSendHooks:()=>[...c],execute:e=>{var t;u||((null===(t=r.batching)||void 0===t?void 0:t.enabled)&&(null==g||g.addItem(e)),(e=>{var t,i;if((null===(t=r.batching)||void 0===t?void 0:t.enabled)&&o.every(e=>e.isBatched()))return;const[s]=l([e]);if(void 0!==s)for(const e of o)n.debug(`Transporting item using ${e.name}\n`,s),e.isBatched()?(null===(i=r.batching)||void 0===i?void 0:i.enabled)||e.send([s]):e.send(s)})(e))},isPaused:()=>u,pause:()=>{n.debug("Pausing transports"),null==g||g.pause(),u=!0},remove:(...e)=>{n.debug("Removing transports"),e.forEach(e=>{n.debug(`Removing "${e.name}" transport`);const t=o.indexOf(e);-1!==t?o.splice(t,1):n.warn(`Transport "${e.name}" is not added`)})},removeBeforeSendHooks:(...e)=>{c.filter(t=>!e.includes(t))},get transports(){return[...o]},unpause:()=>{n.debug("Unpausing transports"),null==g||g.start(),u=!1}}}function s(t,n){if(n.preserveOriginalError)for(const n of t)n.type===e.TransportItemType.EXCEPTION&&delete n.payload.originalError;return t}function a(e,t){return typeof e===t}function o(e,t){return Object.prototype.toString.call(e)===`[object ${t}]`}function u(e,t){try{return e instanceof t}catch(e){return!1}}const c=e=>a(e,"null"),l=e=>a(e,"string"),d=e=>a(e,"number")&&!isNaN(e)||a(e,"bigint"),g=e=>!c(e)&&a(e,"object"),p=e=>a(e,"function"),f=e=>o(e,"Array"),m="undefined"!=typeof Event,h="undefined"!=typeof Error,b=e=>h&&u(e,Error),v="undefined"!=typeof Element,E="undefined"!=typeof Map;function y(e){return null==e||(f(e)||l(e)?0===e.length:!!g(e)&&0===Object.keys(e).length)}function T(e,t){if(e===t)return!0;if(a(e,"number")&&isNaN(e))return a(t,"number")&&isNaN(t);const n=f(e),r=f(t);if(n!==r)return!1;if(n&&r){const n=e.length;if(n!==t.length)return!1;for(let r=n;0!==r--;)if(!T(e[r],t[r]))return!1;return!0}const i=g(e),s=g(t);if(i!==s)return!1;if(e&&t&&i&&s){const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let e of n)if(!r.includes(e))return!1;for(let r of n)if(!T(e[r],t[r]))return!1;return!0}return!1}function O(){return Date.now()}function I(){return"undefined"!=typeof performance&&"function"==typeof performance.now?performance.now():Date.now()}function S(){return(new Date).toISOString()}function A(e){return new Date(e).toISOString()}var L;e.LogLevel=void 0,(L=e.LogLevel||(e.LogLevel={})).TRACE="trace",L.DEBUG="debug",L.INFO="info",L.LOG="log",L.WARN="warn",L.ERROR="error";const _=e.LogLevel.LOG,j=[e.LogLevel.TRACE,e.LogLevel.DEBUG,e.LogLevel.INFO,e.LogLevel.LOG,e.LogLevel.WARN,e.LogLevel.ERROR];function w(){}const x="abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ0123456789";function N(e=10){const t=new Uint32Array(e),n="undefined"!=typeof globalThis?globalThis.crypto:void 0;if(null==n?void 0:n.getRandomValues)n.getRandomValues(t);else for(let n=0;n<e;n++)t[n]=Math.floor(4294967296*Math.random());let r="";for(let n=0;n<e;n++)r+=x[t[n]%59];return r}const R="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:"undefined"!=typeof self?self:void 0;function U(e){const t=`__faroBundleId_${e}`,n=null==R?void 0:R[t];if("string"==typeof n&&""!==n)return n;const r="undefined"!=typeof window?window[t]:void 0;return"string"==typeof r&&""!==r?r:void 0}function k(){const e=new WeakSet;return function(t,n){if(g(n)&&null!==n){if(e.has(n))return null;e.add(n)}return n}}function C(e={}){return JSON.stringify(null!=e?e:{},k())}function B(e={}){const t={};for(const[n,r]of Object.entries(e))t[n]=g(r)&&null!==r?C(r):String(r);return t}class P{constructor(){this.subscribers=[]}subscribe(e){return this.subscribers.push(e),{unsubscribe:()=>this.unsubscribe(e)}}unsubscribe(e){this.subscribers=this.subscribers.filter(t=>t!==e)}notify(e){this.subscribers.forEach(t=>t(e))}first(){const e=new P,t=t=>{e.notify(t),n.unsubscribe()},n=this.subscribe(t),r=e.unsubscribe.bind(e);return this.withUnsubscribeOverride(e,r,t)}takeWhile(e){const t=new P,n=r=>{e(r)?t.notify(r):t.unsubscribe(n)};this.subscribe(n);const r=t.unsubscribe.bind(t);return this.withUnsubscribeOverride(t,r,n)}filter(e){const t=new P,n=n=>{e(n)&&t.notify(n)};this.subscribe(n);const r=t.unsubscribe.bind(t);return this.withUnsubscribeOverride(t,r,n)}merge(...e){const t=new P,n=[];e.forEach(e=>{const r=e.subscribe(e=>{t.notify(e)});n.push(r)});const r=t.unsubscribeAll.bind(t);return t.unsubscribe=()=>{n.forEach(e=>e.unsubscribe()),r()},t}withUnsubscribeOverride(e,t,n){return e.unsubscribe=e=>{t(e),this.unsubscribe(n)},e}unsubscribeAll(){this.subscribers=[]}}var M;e.InternalLoggerLevel=void 0,(M=e.InternalLoggerLevel||(e.InternalLoggerLevel={}))[M.OFF=0]="OFF",M[M.ERROR=1]="ERROR",M[M.WARN=2]="WARN",M[M.INFO=3]="INFO",M[M.VERBOSE=4]="VERBOSE";const D={debug:w,error:w,info:w,prefix:"Faro",warn:w},F=e.InternalLoggerLevel.ERROR,V=Object.assign({},console);let $=V;function z(e){var t;return $=null!==(t=e.unpatchedConsole)&&void 0!==t?t:$,$}function G(t=V,n=F){const r=D;return n>e.InternalLoggerLevel.OFF&&(r.error=n>=e.InternalLoggerLevel.ERROR?function(...e){t.error(`${r.prefix}\n`,...e)}:w,r.warn=n>=e.InternalLoggerLevel.WARN?function(...e){t.warn(`${r.prefix}\n`,...e)}:w,r.info=n>=e.InternalLoggerLevel.INFO?function(...e){t.info(`${r.prefix}\n`,...e)}:w,r.debug=n>=e.InternalLoggerLevel.VERBOSE?function(...e){t.debug(`${r.prefix}\n`,...e)}:w),r}let H=D;function K(e,t){return H=G(e,t.internalLoggerLevel),H}class W{constructor(){this.unpatchedConsole=V,this.internalLogger=D,this.config={},this.metas={}}logDebug(...e){this.internalLogger.debug(`${this.name}\n`,...e)}logInfo(...e){this.internalLogger.info(`${this.name}\n`,...e)}logWarn(...e){this.internalLogger.warn(`${this.name}\n`,...e)}logError(...e){this.internalLogger.error(`${this.name}\n`,...e)}}function X(e,t){var n,r;if(void 0===t)return e;if(void 0===e)return{resourceSpans:t};const i=null===(n=e.resourceSpans)||void 0===n?void 0:n[0];if(void 0===i)return e;const s=(null==i?void 0:i.scopeSpans)||[],a=(null===(r=null==t?void 0:t[0])||void 0===r?void 0:r.scopeSpans)||[];return Object.assign(Object.assign({},e),{resourceSpans:[Object.assign(Object.assign({},i),{scopeSpans:[...s,...a]})]})}const J={Normal:"normal",Critical:"critical"};var q;e.UserActionState=void 0,(q=e.UserActionState||(e.UserActionState={}))[q.Started=0]="Started",q[q.Halted=1]="Halted",q[q.Cancelled=2]="Cancelled",q[q.Ended=3]="Ended";class Q{constructor(){this.buffer=[]}addItem(e){this.buffer.push(e)}flushBuffer(e){if(p(e))for(const t of this.buffer)e(t);this.buffer.length=0}size(){return this.buffer.length}}class Y extends P{constructor({name:t,parentId:n,trigger:r,transports:i,attributes:s,trackUserActionsExcludeItem:a,importance:o=J.Normal,pushEvent:u}){super(),this.name=t,this.attributes=s,this.id=N(),this.trigger=r,this.parentId=null!=n?n:this.id,this.trackUserActionsExcludeItem=a,this.importance=o,this._pushEvent=u,this._itemBuffer=new Q,this._transports=i,this._state=e.UserActionState.Started,this._start()}addItem(t){return this._state===e.UserActionState.Started&&(this._itemBuffer.addItem(t),!0)}_start(){this._state=e.UserActionState.Started,this._state===e.UserActionState.Started&&(this.startTime=O(),this._startTimeMono=I())}halt(){this._state===e.UserActionState.Started&&(this._state=e.UserActionState.Halted,this.notify(this._state))}cancel(){this._state===e.UserActionState.Started&&this._itemBuffer.flushBuffer(e=>{this._transports.execute(e)}),this._state=e.UserActionState.Cancelled,this.notify(this._state)}end(){if(this._state===e.UserActionState.Cancelled)return;const t=O(),n=I()-this._startTimeMono;this._state=e.UserActionState.Ended,this._itemBuffer.flushBuffer(t=>{if(function(t,n){return(null==n?void 0:n(t))||t.type===e.TransportItemType.MEASUREMENT&&"web-vitals"===t.payload.type}(t,this.trackUserActionsExcludeItem))return void this._transports.execute(t);const n=Object.assign(Object.assign({},t),{payload:Object.assign(Object.assign({},t.payload),{action:{parentId:this.id,name:this.name}})});this._transports.execute(n)}),this._state=e.UserActionState.Ended,this.notify(this._state),this._pushEvent("faro.user.action",Object.assign({userActionName:this.name,userActionStartTime:this.startTime.toString(),userActionEndTime:t.toString(),userActionDuration:n.toString(),userActionTrigger:this.trigger,userActionImportance:this.importance},B(this.attributes)),void 0,{timestampOverwriteMs:this.startTime,customPayloadTransformer:e=>(e.action={id:this.id,name:this.name},e)})}getState(){return this._state}}const Z=new P;function ee(t,n){if(!t)return!1;return(null==t?void 0:t.getState())===e.UserActionState.Started&&(t.addItem(n),!0)}const te="Error";let ne;function re({internalLogger:t,config:n,metas:r,transports:i,tracesApi:s,userActionsApi:a}){var o;t.debug("Initializing exceptions API");let u=null;ne=null!==(o=n.parseStacktrace)&&void 0!==o?o:ne;const d=e=>{t.debug("Changing stacktrace parser"),ne=null!=e?e:ne},{ignoreErrors:p=[],preserveOriginalError:m}=n;return d(n.parseStacktrace),{changeStacktraceParser:d,getStacktraceParser:()=>ne,pushError:(o,{skipDedupe:d,stackFrames:h,type:v,context:E,spanContext:O,timestampOverwriteMs:I,originalError:L,fingerprint:_,fatal:j}={})=>{var w;if(!function(e,t){const{message:n,name:r,stack:i}=t;return s=e,a=n+" "+r+" "+i,s.some(e=>l(e)?a.includes(e):!!a.match(e));var s,a}(p,null!=L?L:o))try{const l=B(Object.assign(Object.assign({},function(e){let t=e.cause;b(t)?t=e.cause.toString():null!==t&&(g(e.cause)||f(e.cause))?t=C(e.cause):null!=t&&(t=e.cause.toString());return null==t?{}:{cause:t}}(null!=L?L:o)),null!=E?E:{})),p={meta:r.value,payload:Object.assign(Object.assign(Object.assign(Object.assign({type:v||o.name||te,value:o.message,timestamp:I?A(I):S(),trace:O?{trace_id:O.traceId,span_id:O.spanId}:s.getTraceContext()},y(l)?{}:{context:l}),m?{originalError:L}:{}),_?{fingerprint:_}:{}),void 0!==j?{fatal:j}:{}),type:e.TransportItemType.EXCEPTION};(null==(h=null!=h?h:o.stack?null==ne?void 0:ne(o).frames:void 0)?void 0:h.length)&&(p.payload.stacktrace={frames:h});const x={type:p.payload.type,value:p.payload.value,stacktrace:p.payload.stacktrace,context:p.payload.context,fingerprint:p.payload.fingerprint,fatal:null!==(w=p.payload.fatal)&&void 0!==w&&w};if(!d&&n.dedupe&&!c(u)&&T(x,u))return void t.debug("Skipping error push because it is the same as the last one\n",p.payload);u=x,t.debug("Pushing exception\n",p),ee(a.getActiveUserAction(),p)||i.execute(p)}catch(e){t.error("Error pushing event",e)}}}}const ie=e=>e.map(e=>{try{return String(e)}catch(e){return""}}).join(" ");function se(t,n,r,i,s){n.debug("Initializing API");let a=null;const o=function({transports:t,internalLogger:n,config:r,pushEvent:i}){var s;const a=null===(s=r.userActionsInstrumentation)||void 0===s?void 0:s.excludeItem;let o;const u=()=>o;return{startUserAction:(r,s,c)=>{if(void 0===u()){const n=new Y({name:r,transports:t,attributes:s,trigger:(null==c?void 0:c.triggerName)||"faroApiCall",importance:(null==c?void 0:c.importance)||J.Normal,trackUserActionsExcludeItem:a,pushEvent:i});return n.filter(t=>[e.UserActionState.Ended,e.UserActionState.Cancelled].includes(t)).first().subscribe(()=>{o=void 0}),Z.notify({type:"user_action_start",userAction:n}),o=n,o}n.error("Attempted to create a new user action while one is already running. This is not possible.")},getActiveUserAction:u}}({transports:s,config:r,internalLogger:n,pushEvent:(e,t,r,i)=>{a?a(e,t,r,i):n.warn("pushEventImpl is not initialized. Event dropped:",{name:e,attributes:t,domain:r,options:i})}}),u=function(t,n,r,i,s){let a;return n.debug("Initializing traces API"),{getOTEL:()=>a,getTraceContext:()=>{const e=null==a?void 0:a.trace.getSpanContext(a.context.active());return e?{trace_id:e.traceId,span_id:e.spanId}:void 0},initOTEL:(e,t)=>{n.debug("Initializing OpenTelemetry"),a={trace:e,context:t}},isOTELInitialized:()=>!!a,pushTraces:t=>{try{const r={type:e.TransportItemType.TRACE,payload:t,meta:i.value};n.debug("Pushing trace\n",r),s.execute(r)}catch(e){n.error("Error pushing trace\n",e)}}}}(0,n,0,i,s),d={internalLogger:n,userActionsApi:o,config:r,metas:i,transports:s,tracesApi:u},g=function({internalLogger:t,config:n,metas:r,transports:i,tracesApi:s,userActionsApi:a}){let o=null;return{pushEvent:(u,l,d,{skipDedupe:g,spanContext:p,timestampOverwriteMs:f,customPayloadTransformer:m=e=>e}={})=>{try{const h=B(l),b={meta:r.value,payload:m({name:u,domain:null!=d?d:n.eventDomain,attributes:y(h)?void 0:h,timestamp:f?A(f):S(),trace:p?{trace_id:p.traceId,span_id:p.spanId}:s.getTraceContext()}),type:e.TransportItemType.EVENT},v={name:b.payload.name,attributes:b.payload.attributes,domain:b.payload.domain};if(!g&&n.dedupe&&!c(o)&&T(v,o))return void t.debug("Skipping event push because it is the same as the last one\n",b.payload);o=v,t.debug("Pushing event\n",b),ee(a.getActiveUserAction(),b)||i.execute(b)}catch(e){t.error("Error pushing event",e)}}}}(d);return a=g.pushEvent,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},u),re(d)),function({internalLogger:e,metas:t}){let n,r,i,s;e.debug("Initializing meta API");const a=e=>{r&&t.remove(r),r={user:e},t.add(r)},o=(e,r)=>{var i;const s=null==r?void 0:r.overrides,a=s?{overrides:Object.assign(Object.assign({},null===(i=null==n?void 0:n.session)||void 0===i?void 0:i.overrides),s)}:{};n&&t.remove(n),n={session:Object.assign(Object.assign({},y(e)?void 0:e),a)},t.add(n)},u=()=>t.value.session,c=()=>t.value.page;return{setUser:a,resetUser:a,setSession:o,resetSession:o,getSession:u,setView:(e,n)=>{var r;if((null==n?void 0:n.overrides)&&o(u(),{overrides:n.overrides}),(null===(r=null==i?void 0:i.view)||void 0===r?void 0:r.name)===(null==e?void 0:e.name))return;const s=i;i={view:e},t.add(i),s&&t.remove(s)},getView:()=>t.value.view,setPage:e=>{var n;const r=l(e)?Object.assign(Object.assign({},null!==(n=null==s?void 0:s.page)&&void 0!==n?n:c()),{id:e}):e;s&&t.remove(s),s={page:r},t.add(s)},getPage:c}}(d)),function({internalLogger:t,config:n,metas:r,transports:i,tracesApi:s,userActionsApi:a}){var o;t.debug("Initializing logs API");let u=null;const l=null!==(o=n.logArgsSerializer)&&void 0!==o?o:ie;return{pushLog:(o,{context:d,level:g,skipDedupe:p,spanContext:f,timestampOverwriteMs:m}={})=>{try{const h=B(d),b={type:e.TransportItemType.LOG,payload:{message:l(o),level:null!=g?g:_,context:y(h)?void 0:h,timestamp:m?A(m):S(),trace:f?{trace_id:f.traceId,span_id:f.spanId}:s.getTraceContext()},meta:r.value},v={message:b.payload.message,level:b.payload.level,context:b.payload.context};if(!p&&n.dedupe&&!c(u)&&T(v,u))return void t.debug("Skipping log push because it is the same as the last one\n",b.payload);u=v,t.debug("Pushing log\n",b),ee(a.getActiveUserAction(),b)||i.execute(b)}catch(e){t.error("Error pushing log\n",e)}}}}(d)),function({internalLogger:t,config:n,metas:r,transports:i,tracesApi:s,userActionsApi:a}){t.debug("Initializing measurements API");let o=null;return{pushMeasurement:(u,{skipDedupe:l,context:d,spanContext:g,timestampOverwriteMs:p}={})=>{try{const f=B(d),m={type:e.TransportItemType.MEASUREMENT,payload:Object.assign(Object.assign({},u),{trace:g?{trace_id:g.traceId,span_id:g.spanId}:s.getTraceContext(),timestamp:p?A(p):S(),context:y(f)?void 0:f}),meta:r.value},h={type:m.payload.type,values:m.payload.values,context:m.payload.context};if(!l&&n.dedupe&&!c(o)&&T(h,o))return void t.debug("Skipping measurement push because it is the same as the last one\n",m.payload);o=h,t.debug("Pushing measurement\n",m),ee(a.getActiveUserAction(),m)||i.execute(m)}catch(e){t.error("Error pushing measurement\n",e)}}}}(d)),g),o)}const ae="2.8.1";function oe(e){var t,n;const r=e.config.app.name,i=r?function(e){return null==R?void 0:R[`__faroGitHash_${e}`]}(r):void 0,s={sdk:{version:ae,name:"faro"},app:Object.assign({bundleId:r&&U(r)},void 0!==i?{gitHash:i}:{})},a=null===(t=e.config.sessionTracking)||void 0===t?void 0:t.session;a&&e.api.setSession(a),e.config.app&&(s.app=Object.assign(Object.assign({},e.config.app),s.app)),e.config.user&&(s.user=e.config.user),e.config.view&&(s.view=e.config.view),e.metas.add(s,...null!==(n=e.config.metas)&&void 0!==n?n:[])}const ue="_faroInternal";function ce(e){e.config.isolate?e.internalLogger.debug("Skipping registering internal Faro instance on global object"):(e.internalLogger.debug("Registering internal Faro instance on global object"),Object.defineProperty(R,ue,{configurable:!1,enumerable:!1,writable:!1,value:e}))}function le(){return ue in R}function de(t,n,r,i,s,a,o){return n.debug("Initializing Faro"),e.faro={api:a,config:r,instrumentations:o,internalLogger:n,metas:i,pause:s.pause,transports:s,unpatchedConsole:t,unpause:s.unpause},ce(e.faro),function(e){if(e.config.preventGlobalExposure)e.internalLogger.debug("Skipping registering public Faro instance in the global scope");else{if(e.internalLogger.debug(`Registering public faro reference in the global scope using "${e.config.globalObjectKey}" key`),e.config.globalObjectKey in R)return void e.internalLogger.warn(`Skipping global registration due to key "${e.config.globalObjectKey}" being used already. Please set "globalObjectKey" to something else or set "preventGlobalExposure" to "true"`);Object.defineProperty(R,e.config.globalObjectKey,{configurable:!1,writable:!1,value:e})}}(e.faro),e.faro}e.faro={api:{pushLog:()=>{},pushError:()=>{},changeStacktraceParser:()=>{},getStacktraceParser:()=>{},pushMeasurement:()=>{},pushTraces:()=>{},getOTEL:()=>{},getTraceContext:()=>{},initOTEL:()=>{},isOTELInitialized:()=>!1,setUser:()=>{},resetUser:()=>{},setSession:()=>{},resetSession:()=>{},getSession:()=>{},setView:()=>{},getView:()=>{},setPage:()=>{},getPage:()=>{},pushEvent:()=>{},startUserAction:()=>{},getActiveUserAction:()=>{}}};return e.BaseExtension=W,e.BaseInstrumentation=class extends W{constructor(){super(...arguments),this.api={},this.transports={}}},e.BaseTransport=class extends W{isBatched(){return!1}getIgnoreUrls(){return[]}},e.EVENT_CLICK="click",e.EVENT_NAVIGATION="navigation",e.EVENT_OVERRIDES_SERVICE_NAME="service_name_override",e.EVENT_ROUTE_CHANGE="route_change",e.EVENT_SESSION_EXTEND="session_extend",e.EVENT_SESSION_RESUME="session_resume",e.EVENT_SESSION_START="session_start",e.EVENT_VIEW_CHANGED="view_changed",e.Observable=P,e.UserActionImportance=J,e.VERSION=ae,e.allLogLevels=j,e.clampSamplingRate=function(e){return Math.min(1,Math.max(0,e))},e.createInternalLogger=G,e.createPromiseBuffer=function(e){const{size:t,concurrency:n}=e,r=[];let i=0;const s=()=>{if(i<n&&r.length){const{producer:e,resolve:t,reject:n}=r.shift();i++,e().then(e=>{i--,s(),t(e)},e=>{i--,s(),n(e)})}};return{add:e=>{if(r.length+i>=t)throw new Error("Task buffer full");return new Promise((t,n)=>{r.push({producer:e,resolve:t,reject:n}),s()})}}},e.dateNow=O,e.deepEqual=T,e.defaultBatchingConfig={enabled:!0,sendTimeout:250,itemLimit:50},e.defaultErrorArgsSerializer=e=>e.map(e=>g(e)?C(e):String(e)).join(" "),e.defaultExceptionType=te,e.defaultGlobalObjectKey="faro",e.defaultInternalLoggerLevel=F,e.defaultLogArgsSerializer=ie,e.defaultLogLevel=_,e.defaultUnpatchedConsole=V,e.genShortID=N,e.getCircularDependencyReplacer=k,e.getCurrentTimestamp=S,e.getInternalFaroFromGlobalObject=function(){return R[ue]},e.getTransportBody=function(t){let n={meta:{}};return void 0!==t[0]&&(n.meta=t[0].meta),t.forEach(t=>{switch(t.type){case e.TransportItemType.LOG:case e.TransportItemType.EVENT:case e.TransportItemType.EXCEPTION:case e.TransportItemType.MEASUREMENT:{const e=r[t.type],i=n[e];n=Object.assign(Object.assign({},n),{[e]:void 0===i?[t.payload]:[...i,t.payload]});break}case e.TransportItemType.TRACE:n=Object.assign(Object.assign({},n),{traces:X(n.traces,t.payload.resourceSpans)})}}),n},e.globalObject=R,e.initializeFaro=function(e){const t=z(e),n=K(t,e);if(le()&&!e.isolate)return void n.error('Faro is already registered. Either add instrumentations, transports etc. to the global faro instance or use the "isolate" property');n.debug("Initializing");const r=function(e,t){let n=[],r=[];const i=()=>n.reduce((e,t)=>Object.assign(e,p(t)?t():t),{}),s=()=>{if(r.length){const e=i();r.forEach(t=>t(e))}};return{add:(...e)=>{t.debug("Adding metas\n",e),n.push(...e),s()},remove:(...e)=>{t.debug("Removing metas\n",e),n=n.filter(t=>!e.includes(t)),s()},addListener:e=>{t.debug("Adding metas listener\n",e),r.push(e)},removeListener:e=>{t.debug("Removing metas listener\n",e),r=r.filter(t=>t!==e)},get value(){return i()}}}(0,n),s=i(t,n,e,r),a=se(0,n,e,r,s),o=function(e,t,n,r,i,s){t.debug("Initializing instrumentations");const a=[];return{add:(...o)=>{t.debug("Adding instrumentations"),o.forEach(o=>{t.debug(`Adding "${o.name}" instrumentation`),a.some(e=>e.name===o.name)?t.warn(`Instrumentation ${o.name} is already added`):(o.unpatchedConsole=e,o.internalLogger=t,o.config=n,o.metas=r,o.transports=i,o.api=s,a.push(o),o.initialize())})},get instrumentations(){return[...a]},remove:(...e)=>{t.debug("Removing instrumentations"),e.forEach(e=>{var n,r;t.debug(`Removing "${e.name}" instrumentation`);const i=a.reduce((t,n,r)=>null===t&&n.name===e.name?r:null,null);null!==i?(null===(r=(n=a[i]).destroy)||void 0===r||r.call(n),a.splice(i,1)):t.warn(`Instrumentation "${e.name}" is not added`)})}}}(t,n,e,r,s,a),u=de(t,n,e,r,s,a,o);return oe(u),function(e){e.transports.add(...e.config.transports),e.transports.addBeforeSendHooks(e.config.beforeSend)}(u),function(e){e.instrumentations.add(...e.config.instrumentations)}(u),u},e.internalGlobalObjectKey=ue,e.isArray=f,e.isBoolean=e=>a(e,"boolean"),e.isDomError=e=>o(e,"DOMError"),e.isDomException=e=>o(e,"DOMException"),e.isElement=e=>v&&u(e,Element),e.isElementDefined=v,e.isEmpty=y,e.isError=b,e.isErrorDefined=h,e.isErrorEvent=e=>o(e,"ErrorEvent"),e.isEvent=e=>m&&u(e,Event),e.isEventDefined=m,e.isFunction=p,e.isInstanceOf=u,e.isInt=e=>d(e)&&Number.isInteger(e),e.isInternalFaroOnGlobalObject=le,e.isMap=e=>E&&u(e,Map),e.isMapDefined=E,e.isNull=c,e.isNumber=d,e.isObject=g,e.isPrimitive=e=>!g(e)&&!p(e),e.isRegExp=e=>o(e,"RegExp"),e.isString=l,e.isSymbol=e=>a(e,"symbol"),e.isSyntheticEvent=e=>g(e)&&"nativeEvent"in e&&"preventDefault"in e&&"stopPropagation"in e,e.isThenable=e=>p(null==e?void 0:e.then),e.isToString=o,e.isTypeof=a,e.isUndefined=e=>a(e,"undefined"),e.monoNow=I,e.noop=w,e.setInternalFaroOnGlobalObject=ce,e.stringifyExternalJson=C,e.stringifyObjectValues=B,e.transportItemTypeToBodyKey=r,e.unknownString="unknown",e.userActionsMessageBus=Z,e}({});
|
|
@@ -4,7 +4,7 @@ import type { Transport, TransportItem } from '../transports';
|
|
|
4
4
|
export declare class MockTransport extends BaseTransport implements Transport {
|
|
5
5
|
private ignoreURLs;
|
|
6
6
|
readonly name = "@grafana/transport-mock";
|
|
7
|
-
readonly version = "2.
|
|
7
|
+
readonly version = "2.8.1";
|
|
8
8
|
items: TransportItem[];
|
|
9
9
|
constructor(ignoreURLs?: Patterns);
|
|
10
10
|
send(items: TransportItem[]): void | Promise<void>;
|
|
@@ -6,7 +6,7 @@ export declare class BatchExecutor {
|
|
|
6
6
|
private signalBuffer;
|
|
7
7
|
private sendFn;
|
|
8
8
|
private paused;
|
|
9
|
-
private flushInterval
|
|
9
|
+
private flushInterval?;
|
|
10
10
|
constructor(sendFn: SendFn, options?: BatchExecutorOptions);
|
|
11
11
|
addItem(item: TransportItem): void;
|
|
12
12
|
start(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "2.
|
|
1
|
+
export declare const VERSION = "2.8.1";
|
|
@@ -11,17 +11,18 @@ class BatchExecutor {
|
|
|
11
11
|
this.sendTimeout = (_b = options === null || options === void 0 ? void 0 : options.sendTimeout) !== null && _b !== void 0 ? _b : DEFAULT_SEND_TIMEOUT_MS;
|
|
12
12
|
this.paused = (options === null || options === void 0 ? void 0 : options.paused) || false;
|
|
13
13
|
this.sendFn = sendFn;
|
|
14
|
-
this.flushInterval = -1;
|
|
15
14
|
if (!this.paused) {
|
|
16
15
|
this.start();
|
|
17
16
|
}
|
|
18
17
|
// Send batched/buffered data when user navigates to new page, switches or closes the tab, minimizes or closes the browser.
|
|
19
18
|
// If on mobile, it also sends data if user switches from the browser to a different app.
|
|
20
|
-
document
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
if (typeof document !== 'undefined') {
|
|
20
|
+
document.addEventListener('visibilitychange', () => {
|
|
21
|
+
if (document.visibilityState === 'hidden') {
|
|
22
|
+
this.flush();
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
25
26
|
}
|
|
26
27
|
addItem(item) {
|
|
27
28
|
if (this.paused) {
|
|
@@ -35,7 +36,7 @@ class BatchExecutor {
|
|
|
35
36
|
start() {
|
|
36
37
|
this.paused = false;
|
|
37
38
|
if (this.sendTimeout > 0) {
|
|
38
|
-
this.flushInterval =
|
|
39
|
+
this.flushInterval = setInterval(() => this.flush(), this.sendTimeout);
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
pause() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batchExecutor.js","sourceRoot":"","sources":["../../../src/transports/batchExecutor.ts"],"names":[],"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,YAAY,GAAG,CAAC,IAAI,CAAC,CAAC;YACxB,CAAC;iBAAM,CAAC;gBACN,YAAY,GAAG,CAAC,GAAG,YAAY,EAAE,IAAI,CAAC,CAAC;YACzC,CAAC;YAED,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;QACH,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACtC,CAAC;IAEO,KAAK;QACX,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAClD,OAAO;QACT,CAAC;QAED,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACtD,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAChC,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC;IACzB,CAAC;CACF;AAhFD,sCAgFC","sourcesContent":["import type { TransportItem } from '../';\n\nimport type { BatchExecutorOptions, SendFn } from './types';\n\nconst DEFAULT_SEND_TIMEOUT_MS = 250;\nconst DEFAULT_BATCH_ITEM_LIMIT = 50;\n\nexport class BatchExecutor {\n private readonly itemLimit: number;\n private readonly sendTimeout: number;\n\n private signalBuffer: TransportItem[] = [];\n private sendFn: SendFn;\n private paused: boolean;\n private flushInterval?: ReturnType<typeof setInterval>;\n\n constructor(sendFn: SendFn, options?: BatchExecutorOptions) {\n this.itemLimit = options?.itemLimit ?? DEFAULT_BATCH_ITEM_LIMIT;\n this.sendTimeout = options?.sendTimeout ?? DEFAULT_SEND_TIMEOUT_MS;\n this.paused = options?.paused || false;\n this.sendFn = sendFn;\n\n if (!this.paused) {\n this.start();\n }\n\n // Send batched/buffered data when user navigates to new page, switches or closes the tab, minimizes or closes the browser.\n // If on mobile, it also sends data if user switches from the browser to a different app.\n if (typeof document !== 'undefined') {\n document.addEventListener('visibilitychange', () => {\n if (document.visibilityState === 'hidden') {\n this.flush();\n }\n });\n }\n }\n\n addItem(item: TransportItem): void {\n if (this.paused) {\n return;\n }\n\n this.signalBuffer.push(item);\n\n if (this.signalBuffer.length >= this.itemLimit) {\n this.flush();\n }\n }\n\n start(): void {\n this.paused = false;\n if (this.sendTimeout > 0) {\n this.flushInterval = setInterval(() => this.flush(), this.sendTimeout);\n }\n }\n\n pause(): void {\n this.paused = true;\n clearInterval(this.flushInterval);\n }\n\n groupItems(items: TransportItem[]): TransportItem[][] {\n const itemMap = new Map<string, TransportItem[]>();\n items.forEach((item) => {\n const metaKey = JSON.stringify(item.meta);\n\n let currentItems = itemMap.get(metaKey);\n if (currentItems === undefined) {\n currentItems = [item];\n } else {\n currentItems = [...currentItems, item];\n }\n\n itemMap.set(metaKey, currentItems);\n });\n return Array.from(itemMap.values());\n }\n\n private flush() {\n if (this.paused || this.signalBuffer.length === 0) {\n return;\n }\n\n const itemGroups = this.groupItems(this.signalBuffer);\n itemGroups.forEach(this.sendFn);\n this.signalBuffer = [];\n }\n}\n"]}
|
package/dist/cjs/version.js
CHANGED
package/dist/cjs/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAA,sCAAsC;AACzB,QAAA,OAAO,GAAG,OAAO,CAAC","sourcesContent":["// auto-generated by bin/genVersion.ts\nexport const VERSION = '2.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAA,sCAAsC;AACzB,QAAA,OAAO,GAAG,OAAO,CAAC","sourcesContent":["// auto-generated by bin/genVersion.ts\nexport const VERSION = '2.8.1';\n"]}
|
|
@@ -8,17 +8,18 @@ export class BatchExecutor {
|
|
|
8
8
|
this.sendTimeout = (_b = options === null || options === void 0 ? void 0 : options.sendTimeout) !== null && _b !== void 0 ? _b : DEFAULT_SEND_TIMEOUT_MS;
|
|
9
9
|
this.paused = (options === null || options === void 0 ? void 0 : options.paused) || false;
|
|
10
10
|
this.sendFn = sendFn;
|
|
11
|
-
this.flushInterval = -1;
|
|
12
11
|
if (!this.paused) {
|
|
13
12
|
this.start();
|
|
14
13
|
}
|
|
15
14
|
// Send batched/buffered data when user navigates to new page, switches or closes the tab, minimizes or closes the browser.
|
|
16
15
|
// If on mobile, it also sends data if user switches from the browser to a different app.
|
|
17
|
-
document
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
if (typeof document !== 'undefined') {
|
|
17
|
+
document.addEventListener('visibilitychange', () => {
|
|
18
|
+
if (document.visibilityState === 'hidden') {
|
|
19
|
+
this.flush();
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
22
23
|
}
|
|
23
24
|
addItem(item) {
|
|
24
25
|
if (this.paused) {
|
|
@@ -32,7 +33,7 @@ export class BatchExecutor {
|
|
|
32
33
|
start() {
|
|
33
34
|
this.paused = false;
|
|
34
35
|
if (this.sendTimeout > 0) {
|
|
35
|
-
this.flushInterval =
|
|
36
|
+
this.flushInterval = setInterval(() => this.flush(), this.sendTimeout);
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
pause() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batchExecutor.js","sourceRoot":"","sources":["../../../src/transports/batchExecutor.ts"],"names":[],"mappings":"AAIA,MAAM,uBAAuB,GAAG,GAAG,CAAC;AACpC,MAAM,wBAAwB,GAAG,EAAE,CAAC;AAEpC,MAAM,OAAO,aAAa;IASxB,YAAY,MAAc,EAAE,OAA8B;;QALlD,iBAAY,GAAoB,EAAE,CAAC;QAMzC,IAAI,CAAC,SAAS,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,mCAAI,wBAAwB,CAAC;QAChE,IAAI,CAAC,WAAW,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE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,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAClD,OAAO;QACT,CAAC;QAED,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACtD,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAChC,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC;IACzB,CAAC;CACF","sourcesContent":["import type { TransportItem } from '../';\n\nimport type { BatchExecutorOptions, SendFn } from './types';\n\nconst DEFAULT_SEND_TIMEOUT_MS = 250;\nconst DEFAULT_BATCH_ITEM_LIMIT = 50;\n\nexport class BatchExecutor {\n private readonly itemLimit: number;\n private readonly sendTimeout: number;\n\n private signalBuffer: TransportItem[] = [];\n private sendFn: SendFn;\n private paused: boolean;\n private flushInterval?: ReturnType<typeof setInterval>;\n\n constructor(sendFn: SendFn, options?: BatchExecutorOptions) {\n this.itemLimit = options?.itemLimit ?? DEFAULT_BATCH_ITEM_LIMIT;\n this.sendTimeout = options?.sendTimeout ?? DEFAULT_SEND_TIMEOUT_MS;\n this.paused = options?.paused || false;\n this.sendFn = sendFn;\n\n if (!this.paused) {\n this.start();\n }\n\n // Send batched/buffered data when user navigates to new page, switches or closes the tab, minimizes or closes the browser.\n // If on mobile, it also sends data if user switches from the browser to a different app.\n if (typeof document !== 'undefined') {\n document.addEventListener('visibilitychange', () => {\n if (document.visibilityState === 'hidden') {\n this.flush();\n }\n });\n }\n }\n\n addItem(item: TransportItem): void {\n if (this.paused) {\n return;\n }\n\n this.signalBuffer.push(item);\n\n if (this.signalBuffer.length >= this.itemLimit) {\n this.flush();\n }\n }\n\n start(): void {\n this.paused = false;\n if (this.sendTimeout > 0) {\n this.flushInterval = setInterval(() => this.flush(), this.sendTimeout);\n }\n }\n\n pause(): void {\n this.paused = true;\n clearInterval(this.flushInterval);\n }\n\n groupItems(items: TransportItem[]): TransportItem[][] {\n const itemMap = new Map<string, TransportItem[]>();\n items.forEach((item) => {\n const metaKey = JSON.stringify(item.meta);\n\n let currentItems = itemMap.get(metaKey);\n if (currentItems === undefined) {\n currentItems = [item];\n } else {\n currentItems = [...currentItems, item];\n }\n\n itemMap.set(metaKey, currentItems);\n });\n return Array.from(itemMap.values());\n }\n\n private flush() {\n if (this.paused || this.signalBuffer.length === 0) {\n return;\n }\n\n const itemGroups = this.groupItems(this.signalBuffer);\n itemGroups.forEach(this.sendFn);\n this.signalBuffer = [];\n }\n}\n"]}
|
package/dist/esm/version.js
CHANGED
package/dist/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC","sourcesContent":["// auto-generated by bin/genVersion.ts\nexport const VERSION = '2.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC","sourcesContent":["// auto-generated by bin/genVersion.ts\nexport const VERSION = '2.8.1';\n"]}
|
|
@@ -4,7 +4,7 @@ import type { Transport, TransportItem } from '../transports';
|
|
|
4
4
|
export declare class MockTransport extends BaseTransport implements Transport {
|
|
5
5
|
private ignoreURLs;
|
|
6
6
|
readonly name = "@grafana/transport-mock";
|
|
7
|
-
readonly version = "2.
|
|
7
|
+
readonly version = "2.8.1";
|
|
8
8
|
items: TransportItem[];
|
|
9
9
|
constructor(ignoreURLs?: Patterns);
|
|
10
10
|
send(items: TransportItem[]): void | Promise<void>;
|
|
@@ -6,7 +6,7 @@ export declare class BatchExecutor {
|
|
|
6
6
|
private signalBuffer;
|
|
7
7
|
private sendFn;
|
|
8
8
|
private paused;
|
|
9
|
-
private flushInterval
|
|
9
|
+
private flushInterval?;
|
|
10
10
|
constructor(sendFn: SendFn, options?: BatchExecutorOptions);
|
|
11
11
|
addItem(item: TransportItem): void;
|
|
12
12
|
start(): void;
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "2.
|
|
1
|
+
export declare const VERSION = "2.8.1";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grafana/faro-core",
|
|
3
|
-
"packageManager": "yarn@4.
|
|
4
|
-
"version": "2.
|
|
3
|
+
"packageManager": "yarn@4.17.0",
|
|
4
|
+
"version": "2.8.1",
|
|
5
5
|
"description": "Core package of Faro.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"observability",
|
|
@@ -57,13 +57,13 @@
|
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@opentelemetry/api": "^1.9.0",
|
|
60
|
-
"@opentelemetry/otlp-transformer": "^0.
|
|
60
|
+
"@opentelemetry/otlp-transformer": "^0.219.0"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@types/node": "24.
|
|
63
|
+
"@types/node": "24.13.2"
|
|
64
64
|
},
|
|
65
65
|
"publishConfig": {
|
|
66
66
|
"access": "public"
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "8efae53b855f9924cc730a7e198796f886875ca0"
|
|
69
69
|
}
|