@grafana/faro-core 1.0.0 → 1.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.
@@ -1 +1 @@
1
- var GrafanaFaroCore=function(e){"use strict";function n(e,n){return typeof e===n}function t(e,n){return Object.prototype.toString.call(e)===`[object ${n}]`}function r(e,n){try{return e instanceof n}catch(e){return!1}}const o=e=>n(e,"undefined"),a=e=>n(e,"null"),i=e=>n(e,"string"),s=e=>n(e,"number")&&!isNaN(e)||n(e,"bigint"),u=e=>!a(e)&&n(e,"object"),l=e=>n(e,"function"),g=e=>t(e,"Array"),c=!o(Event),d="undefined"!=typeof Error,p="undefined"!=typeof Element,f="undefined"!=typeof Map;function m(e,t){if(e===t)return!0;if(n(e,"number")&&isNaN(e))return n(t,"number")&&isNaN(t);const r=g(e),o=g(t);if(r!==o)return!1;if(r&&o){const n=e.length;if(n!==t.length)return!1;for(let r=n;0!=r--;)if(!m(e[r],t[r]))return!1;return!0}const a=u(e),i=u(t);if(a!==i)return!1;if(e&&t&&a&&i){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(!m(e[r],t[r]))return!1;return!0}return!1}function b(){return(new Date).toISOString()}var v;e.LogLevel=void 0,(v=e.LogLevel||(e.LogLevel={})).TRACE="trace",v.DEBUG="debug",v.INFO="info",v.LOG="log",v.WARN="warn",v.ERROR="error";const y=e.LogLevel.LOG,E=[e.LogLevel.TRACE,e.LogLevel.DEBUG,e.LogLevel.INFO,e.LogLevel.LOG,e.LogLevel.WARN,e.LogLevel.ERROR];function h(){}const I="abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ0123456789";var L;e.TransportItemType=void 0,(L=e.TransportItemType||(e.TransportItemType={})).EXCEPTION="exception",L.LOG="log",L.MEASUREMENT="measurement",L.TRACE="trace",L.EVENT="event";const T={[e.TransportItemType.EXCEPTION]:"exceptions",[e.TransportItemType.LOG]:"logs",[e.TransportItemType.MEASUREMENT]:"measurements",[e.TransportItemType.TRACE]:"traces",[e.TransportItemType.EVENT]:"events"};function O(n){return t=>{if(t.type===e.TransportItemType.EXCEPTION&&t.payload){const e=t.payload,r=`${e.type}: ${e.value}`;if(function(e,n){return e.some((e=>i(e)?n.includes(e):!!n.match(e)))}(n,r))return null}return t}}var R;e.InternalLoggerLevel=void 0,(R=e.InternalLoggerLevel||(e.InternalLoggerLevel={}))[R.OFF=0]="OFF",R[R.ERROR=1]="ERROR",R[R.WARN=2]="WARN",R[R.INFO=3]="INFO",R[R.VERBOSE=4]="VERBOSE";const S={debug:h,error:h,info:h,prefix:"Faro",warn:h},x=e.InternalLoggerLevel.ERROR,A=Object.assign({},console);let j=A;function N(e){var n;return j=null!==(n=e.unpatchedConsole)&&void 0!==n?n:j,j}function k(n=A,t=x){const r=S;return t>e.InternalLoggerLevel.OFF&&(r.error=t>=e.InternalLoggerLevel.ERROR?function(...e){n.error(`${r.prefix}\n`,...e)}:h,r.warn=t>=e.InternalLoggerLevel.WARN?function(...e){n.warn(`${r.prefix}\n`,...e)}:h,r.info=t>=e.InternalLoggerLevel.INFO?function(...e){n.info(`${r.prefix}\n`,...e)}:h,r.debug=t>=e.InternalLoggerLevel.VERBOSE?function(...e){n.debug(`${r.prefix}\n`,...e)}:h),r}let C=S;function P(e,n){return C=k(e,n.internalLoggerLevel),C}class w{constructor(){this.unpatchedConsole=A,this.internalLogger=S,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)}}const F="Error";let $;function D(n,t,r,o,i){t.debug("Initializing API");const s=function(n,t,r,o,a){let i;return t.debug("Initializing traces API"),{getOTEL:()=>i,getTraceContext:()=>{const e=null==i?void 0:i.trace.getSpanContext(i.context.active());return e?{trace_id:e.traceId,span_id:e.spanId}:void 0},initOTEL:(e,n)=>{t.debug("Initializing OpenTelemetry"),i={trace:e,context:n}},isOTELInitialized:()=>!!i,pushTraces:n=>{try{const r={type:e.TransportItemType.TRACE,payload:n,meta:o.value};t.debug("Pushing trace\n",r),a.execute(r)}catch(e){t.error("Error pushing trace\n",e)}}}}(0,t,0,o,i);return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},s),function(n,t,r,o,i,s){var u;t.debug("Initializing exceptions API");let l=null;$=null!==(u=r.parseStacktrace)&&void 0!==u?u:$;const g=e=>{t.debug("Changing stacktrace parser"),$=null!=e?e:$};return g(r.parseStacktrace),{changeStacktraceParser:g,getStacktraceParser:()=>$,pushError:(n,{skipDedupe:u,stackFrames:g,type:c}={})=>{c=c||n.name||F;const d={meta:o.value,payload:{type:c,value:n.message,timestamp:b(),trace:s.getTraceContext()},type:e.TransportItemType.EXCEPTION};(null==(g=null!=g?g:n.stack?null==$?void 0:$(n).frames:void 0)?void 0:g.length)&&(d.payload.stacktrace={frames:g});const p={type:d.payload.type,value:d.payload.value,stackTrace:d.payload.stacktrace};u||!r.dedupe||a(l)||!m(p,l)?(l=p,t.debug("Pushing exception\n",d),i.execute(d)):t.debug("Skipping error push because it is the same as the last one\n",d.payload)}}}(0,t,r,o,i,s)),function(e,n,t,r,o){let a,i,s;n.debug("Initializing meta API");const u=e=>{i&&r.remove(i),i={user:e},r.add(i)},l=e=>{a&&r.remove(a),a={session:e},r.add(a)};return{setUser:u,resetUser:u,setSession:l,resetSession:l,getSession:()=>r.value.session,setView:e=>{s&&r.remove(s),s={view:e},r.add(s)},getView:()=>r.value.view}}(0,t,0,o)),function(n,t,r,o,i,s){t.debug("Initializing logs API");let u=null;return{pushLog:(n,{context:l,level:g,skipDedupe:c}={})=>{try{const d={type:e.TransportItemType.LOG,payload:{message:n.map((e=>{try{return String(e)}catch(e){return""}})).join(" "),level:null!=g?g:y,context:null!=l?l:{},timestamp:b(),trace:s.getTraceContext()},meta:o.value},p={message:d.payload.message,level:d.payload.level,context:d.payload.context};if(!c&&r.dedupe&&!a(u)&&m(p,u))return void t.debug("Skipping log push because it is the same as the last one\n",d.payload);u=p,t.debug("Pushing log\n",d),i.execute(d)}catch(e){t.error("Error pushing log\n",e)}}}}(0,t,r,o,i,s)),function(n,t,r,o,i,s){t.debug("Initializing measurements API");let u=null;return{pushMeasurement:(n,{skipDedupe:l}={})=>{try{const g={type:e.TransportItemType.MEASUREMENT,payload:Object.assign(Object.assign({},n),{trace:s.getTraceContext()}),meta:o.value},c={type:g.payload.type,values:g.payload.values};if(!l&&r.dedupe&&!a(u)&&m(c,u))return void t.debug("Skipping measurement push because it is the same as the last one\n",g.payload);u=c,t.debug("Pushing measurement\n",g),i.execute(g)}catch(e){t.error("Error pushing measurement\n",e)}}}}(0,t,r,o,i,s)),function(n,t,r,o,i,s){let u=null;return{pushEvent:(n,l,g,{skipDedupe:c}={})=>{try{const d={meta:o.value,payload:{name:n,domain:null!=g?g:r.eventDomain,attributes:l,timestamp:b(),trace:s.getTraceContext()},type:e.TransportItemType.EVENT},p={name:d.payload.name,attributes:d.payload.attributes,domain:d.payload.domain};if(!c&&r.dedupe&&!a(u)&&m(p,u))return void t.debug("Skipping event push because it is the same as the last one\n",d.payload);u=p,t.debug("Pushing event\n",d),i.execute(d)}catch(e){t.error("Error pushing event",e)}}}}(0,t,r,o,i,s))}const G="undefined"==typeof window?global:window;const B="1.0.0";const z="_faroInternal";function M(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(G,z,{configurable:!1,enumerable:!1,writable:!1,value:e}))}function U(){return z in G}function V(n,t,r,o,a,i,s){return t.debug("Initializing Faro"),e.faro={api:i,config:r,instrumentations:s,internalLogger:t,metas:o,pause:a.pause,transports:a,unpatchedConsole:n,unpause:a.unpause},M(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 G)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(G,e.config.globalObjectKey,{configurable:!1,writable:!1,value:e})}}(e.faro),e.faro}e.faro={};return e.BaseExtension=w,e.BaseInstrumentation=class extends w{constructor(){super(...arguments),this.api={},this.transports={}}},e.BaseTransport=class extends w{getIgnoreUrls(){return[]}},e.Conventions={EventNames:{CLICK:"click",NAVIGATION:"navigation",SESSION_START:"session_start",VIEW_CHANGED:"view_changed"}},e.VERSION=B,e.allLogLevels=E,e.createInternalLogger=k,e.createPromiseBuffer=function(e){const{size:n,concurrency:t}=e,r=[];let o=0;const a=()=>{if(o<t&&r.length){const{producer:e,resolve:n,reject:t}=r.shift();o++,e().then((e=>{o--,a(),n(e)}),(e=>{o--,a(),t(e)}))}};return{add:e=>{if(r.length+o>=n)throw new Error("Task buffer full");return new Promise(((n,t)=>{r.push({producer:e,resolve:n,reject:t}),a()}))}}},e.deepEqual=m,e.defaultExceptionType=F,e.defaultGlobalObjectKey="faro",e.defaultInternalLoggerLevel=x,e.defaultLogLevel=y,e.defaultUnpatchedConsole=A,e.genShortID=function(e=10){return Array.from(Array(e)).map((()=>I[Math.floor(Math.random()*I.length)])).join("")},e.getCurrentTimestamp=b,e.getInternalFaroFromGlobalObject=function(){return G[z]},e.getTransportBody=function(n){return{[T[n.type]]:n.type===e.TransportItemType.TRACE?n.payload:[n.payload],meta:n.meta}},e.globalObject=G,e.initializeFaro=function(e){const n=N(e),t=P(n,e);if(U()&&!e.isolate)return void t.error('Faro is already registered. Either add instrumentations, transports etc. to the global faro instance or use the "isolate" property');t.debug("Initializing");const r=function(e,n,t){let r=[],o=[];const a=()=>r.reduce(((e,n)=>Object.assign(e,l(n)?n():n)),{}),i=()=>{if(o.length){const e=a();o.forEach((n=>n(e)))}};return{add:(...e)=>{n.debug("Adding metas\n",e),r.push(...e),i()},remove:(...e)=>{n.debug("Removing metas\n",e),r=r.filter((n=>!e.includes(n))),i()},addListener:e=>{n.debug("Adding metas listener\n",e),o.push(e)},removeListener:e=>{n.debug("Removing metas listener\n",e),o=o.filter((n=>n!==e))},get value(){return a()}}}(0,t),o=function(e,n,t,r){n.debug("Initializing transports");const o=[];let a=t.paused,i=[];return{add:(...a)=>{n.debug("Adding transports"),a.forEach((a=>{n.debug(`Adding "${a.name}" transport`),o.some((e=>e===a))?n.warn(`Transport ${a.name} is already added`):(a.unpatchedConsole=e,a.internalLogger=n,a.config=t,a.metas=r,o.push(a))}))},addBeforeSendHooks:(...e)=>{n.debug("Adding beforeSendHooks\n",i),e.forEach((e=>{e&&i.push(e)}))},addIgnoreErrorsPatterns:(...e)=>{n.debug("Adding ignoreErrorsPatterns\n",e),e.forEach((e=>{e&&i.push(O(e))}))},getBeforeSendHooks:()=>[...i],execute:e=>{if(!a){let t=e;for(const e of i){const n=e(t);if(null===n)return;t=n}for(const e of o)n.debug(`Transporting item using ${e.name}\n`,t),e.send(t)}},isPaused:()=>a,pause:()=>{n.debug("Pausing transports"),a=!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)=>{i.filter((n=>!e.includes(n)))},get transports(){return[...o]},unpause:()=>{n.debug("Unpausing transports"),a=!1}}}(n,t,e,r),a=D(0,t,e,r,o),i=function(e,n,t,r,o,a){n.debug("Initializing instrumentations");const i=[];return{add:(...s)=>{n.debug("Adding instrumentations"),s.forEach((s=>{n.debug(`Adding "${s.name}" instrumentation`),i.some((e=>e.name===s.name))?n.warn(`Instrumentation ${s.name} is already added`):(s.unpatchedConsole=e,s.internalLogger=n,s.config=t,s.metas=r,s.transports=o,s.api=a,i.push(s),s.initialize())}))},get instrumentations(){return[...i]},remove:(...e)=>{n.debug("Removing instrumentations"),e.forEach((e=>{var t,r;n.debug(`Removing "${e.name}" instrumentation`);const o=i.reduce(((n,t,r)=>null===n&&t.name===e.name?r:null),null);o?(null===(r=(t=i[o]).destroy)||void 0===r||r.call(t),i.splice(o,1)):n.warn(`Instrumentation "${e.name}" is not added`)}))}}}(n,t,e,r,o,a),s=V(n,t,e,r,o,a,i);return function(e){var n;const t={sdk:{name:"@grafana/faro-core",version:B,integrations:e.config.instrumentations.map((({name:e,version:n})=>({name:e,version:n})))}};e.config.session&&e.api.setSession(e.config.session),e.config.app&&(t.app=e.config.app),e.config.user&&(t.user=e.config.user),e.config.view&&(t.view=e.config.view),e.metas.add(t,...null!==(n=e.config.metas)&&void 0!==n?n:[])}(s),function(e){e.transports.add(...e.config.transports),e.transports.addBeforeSendHooks(e.config.beforeSend),e.transports.addIgnoreErrorsPatterns(e.config.ignoreErrors)}(s),function(e){e.instrumentations.add(...e.config.instrumentations)}(s),s},e.internalGlobalObjectKey=z,e.isArray=g,e.isBoolean=e=>n(e,"boolean"),e.isDomError=e=>t(e,"DOMError"),e.isDomException=e=>t(e,"DOMException"),e.isElement=e=>p&&r(e,Element),e.isElementDefined=p,e.isError=e=>d&&r(e,Error),e.isErrorDefined=d,e.isErrorEvent=e=>t(e,"ErrorEvent"),e.isEvent=e=>c&&r(e,Event),e.isEventDefined=c,e.isFunction=l,e.isInstanceOf=r,e.isInt=e=>s(e)&&Number.isInteger(e),e.isInternalFaroOnGlobalObject=U,e.isMap=e=>f&&r(e,Map),e.isMapDefined=f,e.isNull=a,e.isNumber=s,e.isObject=u,e.isPrimitive=e=>!u(e)&&!l(e),e.isRegExp=e=>t(e,"RegExp"),e.isString=i,e.isSymbol=e=>n(e,"symbol"),e.isSyntheticEvent=e=>u(e)&&"nativeEvent"in e&&"preventDefault"in e&&"stopPropagation"in e,e.isThenable=e=>l(null==e?void 0:e.then),e.isToString=t,e.isTypeof=n,e.isUndefined=o,e.noop=h,e.setInternalFaroOnGlobalObject=M,e.transportItemTypeToBodyKey=T,e}({});
1
+ var GrafanaFaroCore=function(e){"use strict";function n(e,n){return typeof e===n}function t(e,n){return Object.prototype.toString.call(e)===`[object ${n}]`}function r(e,n){try{return e instanceof n}catch(e){return!1}}const o=e=>n(e,"undefined"),a=e=>n(e,"null"),i=e=>n(e,"string"),s=e=>n(e,"number")&&!isNaN(e)||n(e,"bigint"),u=e=>!a(e)&&n(e,"object"),l=e=>n(e,"function"),g=e=>t(e,"Array"),c=!o(Event),d="undefined"!=typeof Error,p="undefined"!=typeof Element,f="undefined"!=typeof Map;function m(e,t){if(e===t)return!0;if(n(e,"number")&&isNaN(e))return n(t,"number")&&isNaN(t);const r=g(e),o=g(t);if(r!==o)return!1;if(r&&o){const n=e.length;if(n!==t.length)return!1;for(let r=n;0!=r--;)if(!m(e[r],t[r]))return!1;return!0}const a=u(e),i=u(t);if(a!==i)return!1;if(e&&t&&a&&i){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(!m(e[r],t[r]))return!1;return!0}return!1}function b(){return(new Date).toISOString()}var v;e.LogLevel=void 0,(v=e.LogLevel||(e.LogLevel={})).TRACE="trace",v.DEBUG="debug",v.INFO="info",v.LOG="log",v.WARN="warn",v.ERROR="error";const y=e.LogLevel.LOG,E=[e.LogLevel.TRACE,e.LogLevel.DEBUG,e.LogLevel.INFO,e.LogLevel.LOG,e.LogLevel.WARN,e.LogLevel.ERROR];function h(){}const I="abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ0123456789";var L;e.TransportItemType=void 0,(L=e.TransportItemType||(e.TransportItemType={})).EXCEPTION="exception",L.LOG="log",L.MEASUREMENT="measurement",L.TRACE="trace",L.EVENT="event";const T={[e.TransportItemType.EXCEPTION]:"exceptions",[e.TransportItemType.LOG]:"logs",[e.TransportItemType.MEASUREMENT]:"measurements",[e.TransportItemType.TRACE]:"traces",[e.TransportItemType.EVENT]:"events"};function O(n){return t=>{if(t.type===e.TransportItemType.EXCEPTION&&t.payload){const e=t.payload,r=`${e.type}: ${e.value}`;if(function(e,n){return e.some((e=>i(e)?n.includes(e):!!n.match(e)))}(n,r))return null}return t}}var R;e.InternalLoggerLevel=void 0,(R=e.InternalLoggerLevel||(e.InternalLoggerLevel={}))[R.OFF=0]="OFF",R[R.ERROR=1]="ERROR",R[R.WARN=2]="WARN",R[R.INFO=3]="INFO",R[R.VERBOSE=4]="VERBOSE";const S={debug:h,error:h,info:h,prefix:"Faro",warn:h},x=e.InternalLoggerLevel.ERROR,A=Object.assign({},console);let j=A;function N(e){var n;return j=null!==(n=e.unpatchedConsole)&&void 0!==n?n:j,j}function k(n=A,t=x){const r=S;return t>e.InternalLoggerLevel.OFF&&(r.error=t>=e.InternalLoggerLevel.ERROR?function(...e){n.error(`${r.prefix}\n`,...e)}:h,r.warn=t>=e.InternalLoggerLevel.WARN?function(...e){n.warn(`${r.prefix}\n`,...e)}:h,r.info=t>=e.InternalLoggerLevel.INFO?function(...e){n.info(`${r.prefix}\n`,...e)}:h,r.debug=t>=e.InternalLoggerLevel.VERBOSE?function(...e){n.debug(`${r.prefix}\n`,...e)}:h),r}let C=S;function P(e,n){return C=k(e,n.internalLoggerLevel),C}class w{constructor(){this.unpatchedConsole=A,this.internalLogger=S,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)}}const F="Error";let $;function D(n,t,r,o,i){t.debug("Initializing API");const s=function(n,t,r,o,a){let i;return t.debug("Initializing traces API"),{getOTEL:()=>i,getTraceContext:()=>{const e=null==i?void 0:i.trace.getSpanContext(i.context.active());return e?{trace_id:e.traceId,span_id:e.spanId}:void 0},initOTEL:(e,n)=>{t.debug("Initializing OpenTelemetry"),i={trace:e,context:n}},isOTELInitialized:()=>!!i,pushTraces:n=>{try{const r={type:e.TransportItemType.TRACE,payload:n,meta:o.value};t.debug("Pushing trace\n",r),a.execute(r)}catch(e){t.error("Error pushing trace\n",e)}}}}(0,t,0,o,i);return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},s),function(n,t,r,o,i,s){var u;t.debug("Initializing exceptions API");let l=null;$=null!==(u=r.parseStacktrace)&&void 0!==u?u:$;const g=e=>{t.debug("Changing stacktrace parser"),$=null!=e?e:$};return g(r.parseStacktrace),{changeStacktraceParser:g,getStacktraceParser:()=>$,pushError:(n,{skipDedupe:u,stackFrames:g,type:c}={})=>{c=c||n.name||F;const d={meta:o.value,payload:{type:c,value:n.message,timestamp:b(),trace:s.getTraceContext()},type:e.TransportItemType.EXCEPTION};(null==(g=null!=g?g:n.stack?null==$?void 0:$(n).frames:void 0)?void 0:g.length)&&(d.payload.stacktrace={frames:g});const p={type:d.payload.type,value:d.payload.value,stackTrace:d.payload.stacktrace};u||!r.dedupe||a(l)||!m(p,l)?(l=p,t.debug("Pushing exception\n",d),i.execute(d)):t.debug("Skipping error push because it is the same as the last one\n",d.payload)}}}(0,t,r,o,i,s)),function(e,n,t,r,o){let a,i,s;n.debug("Initializing meta API");const u=e=>{i&&r.remove(i),i={user:e},r.add(i)},l=e=>{a&&r.remove(a),a={session:e},r.add(a)};return{setUser:u,resetUser:u,setSession:l,resetSession:l,getSession:()=>r.value.session,setView:e=>{s&&r.remove(s),s={view:e},r.add(s)},getView:()=>r.value.view}}(0,t,0,o)),function(n,t,r,o,i,s){t.debug("Initializing logs API");let u=null;return{pushLog:(n,{context:l,level:g,skipDedupe:c}={})=>{try{const d={type:e.TransportItemType.LOG,payload:{message:n.map((e=>{try{return String(e)}catch(e){return""}})).join(" "),level:null!=g?g:y,context:null!=l?l:{},timestamp:b(),trace:s.getTraceContext()},meta:o.value},p={message:d.payload.message,level:d.payload.level,context:d.payload.context};if(!c&&r.dedupe&&!a(u)&&m(p,u))return void t.debug("Skipping log push because it is the same as the last one\n",d.payload);u=p,t.debug("Pushing log\n",d),i.execute(d)}catch(e){t.error("Error pushing log\n",e)}}}}(0,t,r,o,i,s)),function(n,t,r,o,i,s){t.debug("Initializing measurements API");let u=null;return{pushMeasurement:(n,{skipDedupe:l}={})=>{var g;try{const c={type:e.TransportItemType.MEASUREMENT,payload:Object.assign(Object.assign({},n),{trace:s.getTraceContext(),timestamp:null!==(g=n.timestamp)&&void 0!==g?g:b()}),meta:o.value},d={type:c.payload.type,values:c.payload.values};if(!l&&r.dedupe&&!a(u)&&m(d,u))return void t.debug("Skipping measurement push because it is the same as the last one\n",c.payload);u=d,t.debug("Pushing measurement\n",c),i.execute(c)}catch(e){t.error("Error pushing measurement\n",e)}}}}(0,t,r,o,i,s)),function(n,t,r,o,i,s){let u=null;return{pushEvent:(n,l,g,{skipDedupe:c}={})=>{try{const d={meta:o.value,payload:{name:n,domain:null!=g?g:r.eventDomain,attributes:l,timestamp:b(),trace:s.getTraceContext()},type:e.TransportItemType.EVENT},p={name:d.payload.name,attributes:d.payload.attributes,domain:d.payload.domain};if(!c&&r.dedupe&&!a(u)&&m(p,u))return void t.debug("Skipping event push because it is the same as the last one\n",d.payload);u=p,t.debug("Pushing event\n",d),i.execute(d)}catch(e){t.error("Error pushing event",e)}}}}(0,t,r,o,i,s))}const G="undefined"==typeof window?global:window;const B="1.0.1";const z="_faroInternal";function M(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(G,z,{configurable:!1,enumerable:!1,writable:!1,value:e}))}function U(){return z in G}function V(n,t,r,o,a,i,s){return t.debug("Initializing Faro"),e.faro={api:i,config:r,instrumentations:s,internalLogger:t,metas:o,pause:a.pause,transports:a,unpatchedConsole:n,unpause:a.unpause},M(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 G)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(G,e.config.globalObjectKey,{configurable:!1,writable:!1,value:e})}}(e.faro),e.faro}e.faro={};return e.BaseExtension=w,e.BaseInstrumentation=class extends w{constructor(){super(...arguments),this.api={},this.transports={}}},e.BaseTransport=class extends w{getIgnoreUrls(){return[]}},e.Conventions={EventNames:{CLICK:"click",NAVIGATION:"navigation",SESSION_START:"session_start",VIEW_CHANGED:"view_changed"}},e.VERSION=B,e.allLogLevels=E,e.createInternalLogger=k,e.createPromiseBuffer=function(e){const{size:n,concurrency:t}=e,r=[];let o=0;const a=()=>{if(o<t&&r.length){const{producer:e,resolve:n,reject:t}=r.shift();o++,e().then((e=>{o--,a(),n(e)}),(e=>{o--,a(),t(e)}))}};return{add:e=>{if(r.length+o>=n)throw new Error("Task buffer full");return new Promise(((n,t)=>{r.push({producer:e,resolve:n,reject:t}),a()}))}}},e.deepEqual=m,e.defaultExceptionType=F,e.defaultGlobalObjectKey="faro",e.defaultInternalLoggerLevel=x,e.defaultLogLevel=y,e.defaultUnpatchedConsole=A,e.genShortID=function(e=10){return Array.from(Array(e)).map((()=>I[Math.floor(Math.random()*I.length)])).join("")},e.getCurrentTimestamp=b,e.getInternalFaroFromGlobalObject=function(){return G[z]},e.getTransportBody=function(n){return{[T[n.type]]:n.type===e.TransportItemType.TRACE?n.payload:[n.payload],meta:n.meta}},e.globalObject=G,e.initializeFaro=function(e){const n=N(e),t=P(n,e);if(U()&&!e.isolate)return void t.error('Faro is already registered. Either add instrumentations, transports etc. to the global faro instance or use the "isolate" property');t.debug("Initializing");const r=function(e,n,t){let r=[],o=[];const a=()=>r.reduce(((e,n)=>Object.assign(e,l(n)?n():n)),{}),i=()=>{if(o.length){const e=a();o.forEach((n=>n(e)))}};return{add:(...e)=>{n.debug("Adding metas\n",e),r.push(...e),i()},remove:(...e)=>{n.debug("Removing metas\n",e),r=r.filter((n=>!e.includes(n))),i()},addListener:e=>{n.debug("Adding metas listener\n",e),o.push(e)},removeListener:e=>{n.debug("Removing metas listener\n",e),o=o.filter((n=>n!==e))},get value(){return a()}}}(0,t),o=function(e,n,t,r){n.debug("Initializing transports");const o=[];let a=t.paused,i=[];return{add:(...a)=>{n.debug("Adding transports"),a.forEach((a=>{n.debug(`Adding "${a.name}" transport`),o.some((e=>e===a))?n.warn(`Transport ${a.name} is already added`):(a.unpatchedConsole=e,a.internalLogger=n,a.config=t,a.metas=r,o.push(a))}))},addBeforeSendHooks:(...e)=>{n.debug("Adding beforeSendHooks\n",i),e.forEach((e=>{e&&i.push(e)}))},addIgnoreErrorsPatterns:(...e)=>{n.debug("Adding ignoreErrorsPatterns\n",e),e.forEach((e=>{e&&i.push(O(e))}))},getBeforeSendHooks:()=>[...i],execute:e=>{if(!a){let t=e;for(const e of i){const n=e(t);if(null===n)return;t=n}for(const e of o)n.debug(`Transporting item using ${e.name}\n`,t),e.send(t)}},isPaused:()=>a,pause:()=>{n.debug("Pausing transports"),a=!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)=>{i.filter((n=>!e.includes(n)))},get transports(){return[...o]},unpause:()=>{n.debug("Unpausing transports"),a=!1}}}(n,t,e,r),a=D(0,t,e,r,o),i=function(e,n,t,r,o,a){n.debug("Initializing instrumentations");const i=[];return{add:(...s)=>{n.debug("Adding instrumentations"),s.forEach((s=>{n.debug(`Adding "${s.name}" instrumentation`),i.some((e=>e.name===s.name))?n.warn(`Instrumentation ${s.name} is already added`):(s.unpatchedConsole=e,s.internalLogger=n,s.config=t,s.metas=r,s.transports=o,s.api=a,i.push(s),s.initialize())}))},get instrumentations(){return[...i]},remove:(...e)=>{n.debug("Removing instrumentations"),e.forEach((e=>{var t,r;n.debug(`Removing "${e.name}" instrumentation`);const o=i.reduce(((n,t,r)=>null===n&&t.name===e.name?r:null),null);o?(null===(r=(t=i[o]).destroy)||void 0===r||r.call(t),i.splice(o,1)):n.warn(`Instrumentation "${e.name}" is not added`)}))}}}(n,t,e,r,o,a),s=V(n,t,e,r,o,a,i);return function(e){var n;const t={sdk:{name:"@grafana/faro-core",version:B,integrations:e.config.instrumentations.map((({name:e,version:n})=>({name:e,version:n})))}};e.config.session&&e.api.setSession(e.config.session),e.config.app&&(t.app=e.config.app),e.config.user&&(t.user=e.config.user),e.config.view&&(t.view=e.config.view),e.metas.add(t,...null!==(n=e.config.metas)&&void 0!==n?n:[])}(s),function(e){e.transports.add(...e.config.transports),e.transports.addBeforeSendHooks(e.config.beforeSend),e.transports.addIgnoreErrorsPatterns(e.config.ignoreErrors)}(s),function(e){e.instrumentations.add(...e.config.instrumentations)}(s),s},e.internalGlobalObjectKey=z,e.isArray=g,e.isBoolean=e=>n(e,"boolean"),e.isDomError=e=>t(e,"DOMError"),e.isDomException=e=>t(e,"DOMException"),e.isElement=e=>p&&r(e,Element),e.isElementDefined=p,e.isError=e=>d&&r(e,Error),e.isErrorDefined=d,e.isErrorEvent=e=>t(e,"ErrorEvent"),e.isEvent=e=>c&&r(e,Event),e.isEventDefined=c,e.isFunction=l,e.isInstanceOf=r,e.isInt=e=>s(e)&&Number.isInteger(e),e.isInternalFaroOnGlobalObject=U,e.isMap=e=>f&&r(e,Map),e.isMapDefined=f,e.isNull=a,e.isNumber=s,e.isObject=u,e.isPrimitive=e=>!u(e)&&!l(e),e.isRegExp=e=>t(e,"RegExp"),e.isString=i,e.isSymbol=e=>n(e,"symbol"),e.isSyntheticEvent=e=>u(e)&&"nativeEvent"in e&&"preventDefault"in e&&"stopPropagation"in e,e.isThenable=e=>l(null==e?void 0:e.then),e.isToString=t,e.isTypeof=n,e.isUndefined=o,e.noop=h,e.setInternalFaroOnGlobalObject=M,e.transportItemTypeToBodyKey=T,e}({});
@@ -18,11 +18,12 @@ function initializeMeasurementsAPI(_unpatchedConsole, internalLogger, config, me
18
18
  internalLogger.debug('Initializing measurements API');
19
19
  var lastPayload = null;
20
20
  var pushMeasurement = function (payload, _a) {
21
- var _b = _a === void 0 ? {} : _a, skipDedupe = _b.skipDedupe;
21
+ var _b;
22
+ var _c = _a === void 0 ? {} : _a, skipDedupe = _c.skipDedupe;
22
23
  try {
23
24
  var item = {
24
25
  type: transports_1.TransportItemType.MEASUREMENT,
25
- payload: __assign(__assign({}, payload), { trace: tracesApi.getTraceContext() }),
26
+ payload: __assign(__assign({}, payload), { trace: tracesApi.getTraceContext(), timestamp: (_b = payload.timestamp) !== null && _b !== void 0 ? _b : (0, utils_1.getCurrentTimestamp)() }),
26
27
  meta: metas.value,
27
28
  };
28
29
  var testingPayload = {
@@ -1 +1 @@
1
- {"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../src/api/measurements/initialize.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAGA,+CAAoE;AAGpE,qCAAgD;AAKhD,SAAgB,yBAAyB,CACvC,iBAAmC,EACnC,cAA8B,EAC9B,MAAc,EACd,KAAY,EACZ,UAAsB,EACtB,SAAoB;IAEpB,cAAc,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;IAEtD,IAAI,WAAW,GAAqD,IAAI,CAAC;IAEzE,IAAM,eAAe,GAAuC,UAAC,OAAO,EAAE,EAAmB;YAAnB,qBAAiB,EAAE,KAAA,EAAjB,UAAU,gBAAA;QAChF,IAAI;YACF,IAAM,IAAI,GAAoC;gBAC5C,IAAI,EAAE,8BAAiB,CAAC,WAAW;gBACnC,OAAO,wBACF,OAAO,KACV,KAAK,EAAE,SAAS,CAAC,eAAe,EAAE,GACnC;gBACD,IAAI,EAAE,KAAK,CAAC,KAAK;aAClB,CAAC;YAEF,IAAM,cAAc,GAAG;gBACrB,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI;gBACvB,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM;aAC5B,CAAC;YAEF,IAAI,CAAC,UAAU,IAAI,MAAM,CAAC,MAAM,IAAI,CAAC,IAAA,cAAM,EAAC,WAAW,CAAC,IAAI,IAAA,iBAAS,EAAC,cAAc,EAAE,WAAW,CAAC,EAAE;gBAClG,cAAc,CAAC,KAAK,CAAC,oEAAoE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;gBAEzG,OAAO;aACR;YAED,WAAW,GAAG,cAAc,CAAC;YAE7B,cAAc,CAAC,KAAK,CAAC,uBAAuB,EAAE,IAAI,CAAC,CAAC;YAEpD,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;SAC1B;QAAC,OAAO,GAAG,EAAE;YACZ,cAAc,CAAC,KAAK,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAC;SAC1D;IACH,CAAC,CAAC;IAEF,OAAO;QACL,eAAe,iBAAA;KAChB,CAAC;AACJ,CAAC;AA/CD,8DA+CC","sourcesContent":["import type { Config } from '../../config';\nimport type { InternalLogger } from '../../internalLogger';\nimport type { Metas } from '../../metas';\nimport { TransportItem, TransportItemType } from '../../transports';\nimport type { Transports } from '../../transports';\nimport type { UnpatchedConsole } from '../../unpatchedConsole';\nimport { deepEqual, isNull } from '../../utils';\nimport type { TracesAPI } from '../traces';\n\nimport type { MeasurementEvent, MeasurementsAPI } from './types';\n\nexport function initializeMeasurementsAPI(\n _unpatchedConsole: UnpatchedConsole,\n internalLogger: InternalLogger,\n config: Config,\n metas: Metas,\n transports: Transports,\n tracesApi: TracesAPI\n): MeasurementsAPI {\n internalLogger.debug('Initializing measurements API');\n\n let lastPayload: Pick<MeasurementEvent, 'type' | 'values'> | null = null;\n\n const pushMeasurement: MeasurementsAPI['pushMeasurement'] = (payload, { skipDedupe } = {}) => {\n try {\n const item: TransportItem<MeasurementEvent> = {\n type: TransportItemType.MEASUREMENT,\n payload: {\n ...payload,\n trace: tracesApi.getTraceContext(),\n },\n meta: metas.value,\n };\n\n const testingPayload = {\n type: item.payload.type,\n values: item.payload.values,\n };\n\n if (!skipDedupe && config.dedupe && !isNull(lastPayload) && deepEqual(testingPayload, lastPayload)) {\n internalLogger.debug('Skipping measurement push because it is the same as the last one\\n', item.payload);\n\n return;\n }\n\n lastPayload = testingPayload;\n\n internalLogger.debug('Pushing measurement\\n', item);\n\n transports.execute(item);\n } catch (err) {\n internalLogger.error('Error pushing measurement\\n', err);\n }\n };\n\n return {\n pushMeasurement,\n };\n}\n"]}
1
+ {"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../src/api/measurements/initialize.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAGA,+CAAoE;AAGpE,qCAAqE;AAKrE,SAAgB,yBAAyB,CACvC,iBAAmC,EACnC,cAA8B,EAC9B,MAAc,EACd,KAAY,EACZ,UAAsB,EACtB,SAAoB;IAEpB,cAAc,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;IAEtD,IAAI,WAAW,GAAqD,IAAI,CAAC;IAEzE,IAAM,eAAe,GAAuC,UAAC,OAAO,EAAE,EAAmB;;YAAnB,qBAAiB,EAAE,KAAA,EAAjB,UAAU,gBAAA;QAChF,IAAI;YACF,IAAM,IAAI,GAAoC;gBAC5C,IAAI,EAAE,8BAAiB,CAAC,WAAW;gBACnC,OAAO,wBACF,OAAO,KACV,KAAK,EAAE,SAAS,CAAC,eAAe,EAAE,EAClC,SAAS,EAAE,MAAA,OAAO,CAAC,SAAS,mCAAI,IAAA,2BAAmB,GAAE,GACtD;gBACD,IAAI,EAAE,KAAK,CAAC,KAAK;aAClB,CAAC;YAEF,IAAM,cAAc,GAAG;gBACrB,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI;gBACvB,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM;aAC5B,CAAC;YAEF,IAAI,CAAC,UAAU,IAAI,MAAM,CAAC,MAAM,IAAI,CAAC,IAAA,cAAM,EAAC,WAAW,CAAC,IAAI,IAAA,iBAAS,EAAC,cAAc,EAAE,WAAW,CAAC,EAAE;gBAClG,cAAc,CAAC,KAAK,CAAC,oEAAoE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;gBAEzG,OAAO;aACR;YAED,WAAW,GAAG,cAAc,CAAC;YAE7B,cAAc,CAAC,KAAK,CAAC,uBAAuB,EAAE,IAAI,CAAC,CAAC;YAEpD,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;SAC1B;QAAC,OAAO,GAAG,EAAE;YACZ,cAAc,CAAC,KAAK,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAC;SAC1D;IACH,CAAC,CAAC;IAEF,OAAO;QACL,eAAe,iBAAA;KAChB,CAAC;AACJ,CAAC;AAhDD,8DAgDC","sourcesContent":["import type { Config } from '../../config';\nimport type { InternalLogger } from '../../internalLogger';\nimport type { Metas } from '../../metas';\nimport { TransportItem, TransportItemType } from '../../transports';\nimport type { Transports } from '../../transports';\nimport type { UnpatchedConsole } from '../../unpatchedConsole';\nimport { deepEqual, getCurrentTimestamp, isNull } from '../../utils';\nimport type { TracesAPI } from '../traces';\n\nimport type { MeasurementEvent, MeasurementsAPI } from './types';\n\nexport function initializeMeasurementsAPI(\n _unpatchedConsole: UnpatchedConsole,\n internalLogger: InternalLogger,\n config: Config,\n metas: Metas,\n transports: Transports,\n tracesApi: TracesAPI\n): MeasurementsAPI {\n internalLogger.debug('Initializing measurements API');\n\n let lastPayload: Pick<MeasurementEvent, 'type' | 'values'> | null = null;\n\n const pushMeasurement: MeasurementsAPI['pushMeasurement'] = (payload, { skipDedupe } = {}) => {\n try {\n const item: TransportItem<MeasurementEvent> = {\n type: TransportItemType.MEASUREMENT,\n payload: {\n ...payload,\n trace: tracesApi.getTraceContext(),\n timestamp: payload.timestamp ?? getCurrentTimestamp(),\n },\n meta: metas.value,\n };\n\n const testingPayload = {\n type: item.payload.type,\n values: item.payload.values,\n };\n\n if (!skipDedupe && config.dedupe && !isNull(lastPayload) && deepEqual(testingPayload, lastPayload)) {\n internalLogger.debug('Skipping measurement push because it is the same as the last one\\n', item.payload);\n\n return;\n }\n\n lastPayload = testingPayload;\n\n internalLogger.debug('Pushing measurement\\n', item);\n\n transports.execute(item);\n } catch (err) {\n internalLogger.error('Error pushing measurement\\n', err);\n }\n };\n\n return {\n pushMeasurement,\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/api/measurements/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { TraceContext } from '../traces';\n\nexport interface MeasurementEvent<V extends { [label: string]: number } = { [label: string]: number }> {\n type: string;\n values: V;\n\n trace?: TraceContext;\n}\n\nexport interface PushMeasurementOptions {\n skipDedupe?: boolean;\n}\n\nexport interface MeasurementsAPI {\n pushMeasurement: (payload: MeasurementEvent, options?: PushMeasurementOptions) => void;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/api/measurements/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { TraceContext } from '../traces';\n\nexport interface MeasurementEvent<V extends { [label: string]: number } = { [label: string]: number }> {\n type: string;\n values: V;\n\n timestamp: string;\n trace?: TraceContext;\n}\n\nexport interface PushMeasurementOptions {\n skipDedupe?: boolean;\n}\n\nexport interface MeasurementsAPI {\n pushMeasurement: (\n // TODO: change this back once we have aligned the measurement event types: See: https://github.com/grafana/faro-web-sdk/issues/110\n payload: Omit<MeasurementEvent, 'timestamp'> & Partial<Pick<MeasurementEvent, 'timestamp'>>,\n options?: PushMeasurementOptions\n ) => void;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/metas/types.ts"],"names":[],"mappings":"","sourcesContent":["export type MetaGetter<P = Partial<Meta>> = () => P;\n\nexport type MetaItem<P = Partial<Meta>> = P | MetaGetter<P>;\n\nexport type MetasListener = (value: Meta) => void;\n\nexport interface Metas {\n add: (...getters: MetaItem[]) => void;\n remove: (...getters: MetaItem[]) => void;\n addListener: (listener: MetasListener) => void;\n removeListener: (listener: MetasListener) => void;\n value: Meta;\n}\n\nexport type MetaAttributes = Record<string, string>;\n\nexport interface MetaSDKIntegration {\n name?: string;\n version?: string;\n}\n\nexport interface MetaSDK {\n name?: string;\n version?: string;\n integrations?: MetaSDKIntegration[];\n}\n\nexport interface MetaApp {\n name?: string;\n release?: string;\n version?: string;\n environment?: string;\n}\n\nexport interface MetaUser {\n email?: string;\n id?: string;\n username?: string;\n attributes?: MetaAttributes;\n}\n\nexport interface MetaSession {\n id?: string;\n attributes?: MetaAttributes;\n}\n\nexport interface MetaPage {\n id?: string;\n url?: string;\n attributes?: MetaAttributes;\n}\n\nexport interface MetaBrowser {\n name?: string;\n version?: string;\n os?: string;\n mobile?: boolean;\n}\n\nexport interface MetaView {\n name: string;\n}\n\nexport interface Meta {\n sdk?: MetaSDK;\n app?: MetaApp;\n user?: MetaUser;\n session?: MetaSession;\n page?: MetaPage;\n browser?: MetaBrowser;\n view?: MetaView;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/metas/types.ts"],"names":[],"mappings":"","sourcesContent":["export type MetaGetter<P = Partial<Meta>> = () => P;\n\nexport type MetaItem<P = Partial<Meta>> = P | MetaGetter<P>;\n\nexport type MetasListener = (value: Meta) => void;\n\nexport interface Metas {\n add: (...getters: MetaItem[]) => void;\n remove: (...getters: MetaItem[]) => void;\n addListener: (listener: MetasListener) => void;\n removeListener: (listener: MetasListener) => void;\n value: Meta;\n}\n\nexport type MetaAttributes = Record<string, string>;\n\nexport interface MetaSDKIntegration {\n name?: string;\n version?: string;\n}\n\nexport interface MetaSDK {\n name?: string;\n version?: string;\n integrations?: MetaSDKIntegration[];\n}\n\nexport interface MetaApp {\n name?: string;\n release?: string;\n version?: string;\n environment?: string;\n}\n\nexport interface MetaUser {\n email?: string;\n id?: string;\n username?: string;\n attributes?: MetaAttributes;\n}\n\nexport interface MetaSession {\n id?: string;\n attributes?: MetaAttributes;\n}\n\nexport interface MetaPage {\n id?: string;\n url?: string;\n attributes?: MetaAttributes;\n}\n\nexport interface MetaBrowser {\n name?: string;\n version?: string;\n os?: string;\n mobile?: boolean;\n userAgent?: string;\n language?: string;\n}\n\nexport interface MetaView {\n name: string;\n}\n\nexport interface Meta {\n sdk?: MetaSDK;\n app?: MetaApp;\n user?: MetaUser;\n session?: MetaSession;\n page?: MetaPage;\n browser?: MetaBrowser;\n view?: MetaView;\n}\n"]}
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
4
  // auto-generated by bin/genVersion.ts
5
- exports.VERSION = '1.0.0';
5
+ exports.VERSION = '1.0.1';
6
6
  //# sourceMappingURL=version.js.map
@@ -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 = '1.0.0';\n"]}
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 = '1.0.1';\n"]}
@@ -1,13 +1,14 @@
1
1
  import { TransportItemType } from '../../transports';
2
- import { deepEqual, isNull } from '../../utils';
2
+ import { deepEqual, getCurrentTimestamp, isNull } from '../../utils';
3
3
  export function initializeMeasurementsAPI(_unpatchedConsole, internalLogger, config, metas, transports, tracesApi) {
4
4
  internalLogger.debug('Initializing measurements API');
5
5
  let lastPayload = null;
6
6
  const pushMeasurement = (payload, { skipDedupe } = {}) => {
7
+ var _a;
7
8
  try {
8
9
  const item = {
9
10
  type: TransportItemType.MEASUREMENT,
10
- payload: Object.assign(Object.assign({}, payload), { trace: tracesApi.getTraceContext() }),
11
+ payload: Object.assign(Object.assign({}, payload), { trace: tracesApi.getTraceContext(), timestamp: (_a = payload.timestamp) !== null && _a !== void 0 ? _a : getCurrentTimestamp() }),
11
12
  meta: metas.value,
12
13
  };
13
14
  const testingPayload = {
@@ -1 +1 @@
1
- {"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../src/api/measurements/initialize.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiB,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGpE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAKhD,MAAM,UAAU,yBAAyB,CACvC,iBAAmC,EACnC,cAA8B,EAC9B,MAAc,EACd,KAAY,EACZ,UAAsB,EACtB,SAAoB;IAEpB,cAAc,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;IAEtD,IAAI,WAAW,GAAqD,IAAI,CAAC;IAEzE,MAAM,eAAe,GAAuC,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,EAAE,EAAE;QAC3F,IAAI;YACF,MAAM,IAAI,GAAoC;gBAC5C,IAAI,EAAE,iBAAiB,CAAC,WAAW;gBACnC,OAAO,kCACF,OAAO,KACV,KAAK,EAAE,SAAS,CAAC,eAAe,EAAE,GACnC;gBACD,IAAI,EAAE,KAAK,CAAC,KAAK;aAClB,CAAC;YAEF,MAAM,cAAc,GAAG;gBACrB,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI;gBACvB,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM;aAC5B,CAAC;YAEF,IAAI,CAAC,UAAU,IAAI,MAAM,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,SAAS,CAAC,cAAc,EAAE,WAAW,CAAC,EAAE;gBAClG,cAAc,CAAC,KAAK,CAAC,oEAAoE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;gBAEzG,OAAO;aACR;YAED,WAAW,GAAG,cAAc,CAAC;YAE7B,cAAc,CAAC,KAAK,CAAC,uBAAuB,EAAE,IAAI,CAAC,CAAC;YAEpD,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;SAC1B;QAAC,OAAO,GAAG,EAAE;YACZ,cAAc,CAAC,KAAK,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAC;SAC1D;IACH,CAAC,CAAC;IAEF,OAAO;QACL,eAAe;KAChB,CAAC;AACJ,CAAC","sourcesContent":["import type { Config } from '../../config';\nimport type { InternalLogger } from '../../internalLogger';\nimport type { Metas } from '../../metas';\nimport { TransportItem, TransportItemType } from '../../transports';\nimport type { Transports } from '../../transports';\nimport type { UnpatchedConsole } from '../../unpatchedConsole';\nimport { deepEqual, isNull } from '../../utils';\nimport type { TracesAPI } from '../traces';\n\nimport type { MeasurementEvent, MeasurementsAPI } from './types';\n\nexport function initializeMeasurementsAPI(\n _unpatchedConsole: UnpatchedConsole,\n internalLogger: InternalLogger,\n config: Config,\n metas: Metas,\n transports: Transports,\n tracesApi: TracesAPI\n): MeasurementsAPI {\n internalLogger.debug('Initializing measurements API');\n\n let lastPayload: Pick<MeasurementEvent, 'type' | 'values'> | null = null;\n\n const pushMeasurement: MeasurementsAPI['pushMeasurement'] = (payload, { skipDedupe } = {}) => {\n try {\n const item: TransportItem<MeasurementEvent> = {\n type: TransportItemType.MEASUREMENT,\n payload: {\n ...payload,\n trace: tracesApi.getTraceContext(),\n },\n meta: metas.value,\n };\n\n const testingPayload = {\n type: item.payload.type,\n values: item.payload.values,\n };\n\n if (!skipDedupe && config.dedupe && !isNull(lastPayload) && deepEqual(testingPayload, lastPayload)) {\n internalLogger.debug('Skipping measurement push because it is the same as the last one\\n', item.payload);\n\n return;\n }\n\n lastPayload = testingPayload;\n\n internalLogger.debug('Pushing measurement\\n', item);\n\n transports.execute(item);\n } catch (err) {\n internalLogger.error('Error pushing measurement\\n', err);\n }\n };\n\n return {\n pushMeasurement,\n };\n}\n"]}
1
+ {"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../src/api/measurements/initialize.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiB,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGpE,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAKrE,MAAM,UAAU,yBAAyB,CACvC,iBAAmC,EACnC,cAA8B,EAC9B,MAAc,EACd,KAAY,EACZ,UAAsB,EACtB,SAAoB;IAEpB,cAAc,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;IAEtD,IAAI,WAAW,GAAqD,IAAI,CAAC;IAEzE,MAAM,eAAe,GAAuC,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,EAAE,EAAE;;QAC3F,IAAI;YACF,MAAM,IAAI,GAAoC;gBAC5C,IAAI,EAAE,iBAAiB,CAAC,WAAW;gBACnC,OAAO,kCACF,OAAO,KACV,KAAK,EAAE,SAAS,CAAC,eAAe,EAAE,EAClC,SAAS,EAAE,MAAA,OAAO,CAAC,SAAS,mCAAI,mBAAmB,EAAE,GACtD;gBACD,IAAI,EAAE,KAAK,CAAC,KAAK;aAClB,CAAC;YAEF,MAAM,cAAc,GAAG;gBACrB,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI;gBACvB,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM;aAC5B,CAAC;YAEF,IAAI,CAAC,UAAU,IAAI,MAAM,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,SAAS,CAAC,cAAc,EAAE,WAAW,CAAC,EAAE;gBAClG,cAAc,CAAC,KAAK,CAAC,oEAAoE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;gBAEzG,OAAO;aACR;YAED,WAAW,GAAG,cAAc,CAAC;YAE7B,cAAc,CAAC,KAAK,CAAC,uBAAuB,EAAE,IAAI,CAAC,CAAC;YAEpD,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;SAC1B;QAAC,OAAO,GAAG,EAAE;YACZ,cAAc,CAAC,KAAK,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAC;SAC1D;IACH,CAAC,CAAC;IAEF,OAAO;QACL,eAAe;KAChB,CAAC;AACJ,CAAC","sourcesContent":["import type { Config } from '../../config';\nimport type { InternalLogger } from '../../internalLogger';\nimport type { Metas } from '../../metas';\nimport { TransportItem, TransportItemType } from '../../transports';\nimport type { Transports } from '../../transports';\nimport type { UnpatchedConsole } from '../../unpatchedConsole';\nimport { deepEqual, getCurrentTimestamp, isNull } from '../../utils';\nimport type { TracesAPI } from '../traces';\n\nimport type { MeasurementEvent, MeasurementsAPI } from './types';\n\nexport function initializeMeasurementsAPI(\n _unpatchedConsole: UnpatchedConsole,\n internalLogger: InternalLogger,\n config: Config,\n metas: Metas,\n transports: Transports,\n tracesApi: TracesAPI\n): MeasurementsAPI {\n internalLogger.debug('Initializing measurements API');\n\n let lastPayload: Pick<MeasurementEvent, 'type' | 'values'> | null = null;\n\n const pushMeasurement: MeasurementsAPI['pushMeasurement'] = (payload, { skipDedupe } = {}) => {\n try {\n const item: TransportItem<MeasurementEvent> = {\n type: TransportItemType.MEASUREMENT,\n payload: {\n ...payload,\n trace: tracesApi.getTraceContext(),\n timestamp: payload.timestamp ?? getCurrentTimestamp(),\n },\n meta: metas.value,\n };\n\n const testingPayload = {\n type: item.payload.type,\n values: item.payload.values,\n };\n\n if (!skipDedupe && config.dedupe && !isNull(lastPayload) && deepEqual(testingPayload, lastPayload)) {\n internalLogger.debug('Skipping measurement push because it is the same as the last one\\n', item.payload);\n\n return;\n }\n\n lastPayload = testingPayload;\n\n internalLogger.debug('Pushing measurement\\n', item);\n\n transports.execute(item);\n } catch (err) {\n internalLogger.error('Error pushing measurement\\n', err);\n }\n };\n\n return {\n pushMeasurement,\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/api/measurements/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { TraceContext } from '../traces';\n\nexport interface MeasurementEvent<V extends { [label: string]: number } = { [label: string]: number }> {\n type: string;\n values: V;\n\n trace?: TraceContext;\n}\n\nexport interface PushMeasurementOptions {\n skipDedupe?: boolean;\n}\n\nexport interface MeasurementsAPI {\n pushMeasurement: (payload: MeasurementEvent, options?: PushMeasurementOptions) => void;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/api/measurements/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { TraceContext } from '../traces';\n\nexport interface MeasurementEvent<V extends { [label: string]: number } = { [label: string]: number }> {\n type: string;\n values: V;\n\n timestamp: string;\n trace?: TraceContext;\n}\n\nexport interface PushMeasurementOptions {\n skipDedupe?: boolean;\n}\n\nexport interface MeasurementsAPI {\n pushMeasurement: (\n // TODO: change this back once we have aligned the measurement event types: See: https://github.com/grafana/faro-web-sdk/issues/110\n payload: Omit<MeasurementEvent, 'timestamp'> & Partial<Pick<MeasurementEvent, 'timestamp'>>,\n options?: PushMeasurementOptions\n ) => void;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/metas/types.ts"],"names":[],"mappings":"","sourcesContent":["export type MetaGetter<P = Partial<Meta>> = () => P;\n\nexport type MetaItem<P = Partial<Meta>> = P | MetaGetter<P>;\n\nexport type MetasListener = (value: Meta) => void;\n\nexport interface Metas {\n add: (...getters: MetaItem[]) => void;\n remove: (...getters: MetaItem[]) => void;\n addListener: (listener: MetasListener) => void;\n removeListener: (listener: MetasListener) => void;\n value: Meta;\n}\n\nexport type MetaAttributes = Record<string, string>;\n\nexport interface MetaSDKIntegration {\n name?: string;\n version?: string;\n}\n\nexport interface MetaSDK {\n name?: string;\n version?: string;\n integrations?: MetaSDKIntegration[];\n}\n\nexport interface MetaApp {\n name?: string;\n release?: string;\n version?: string;\n environment?: string;\n}\n\nexport interface MetaUser {\n email?: string;\n id?: string;\n username?: string;\n attributes?: MetaAttributes;\n}\n\nexport interface MetaSession {\n id?: string;\n attributes?: MetaAttributes;\n}\n\nexport interface MetaPage {\n id?: string;\n url?: string;\n attributes?: MetaAttributes;\n}\n\nexport interface MetaBrowser {\n name?: string;\n version?: string;\n os?: string;\n mobile?: boolean;\n}\n\nexport interface MetaView {\n name: string;\n}\n\nexport interface Meta {\n sdk?: MetaSDK;\n app?: MetaApp;\n user?: MetaUser;\n session?: MetaSession;\n page?: MetaPage;\n browser?: MetaBrowser;\n view?: MetaView;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/metas/types.ts"],"names":[],"mappings":"","sourcesContent":["export type MetaGetter<P = Partial<Meta>> = () => P;\n\nexport type MetaItem<P = Partial<Meta>> = P | MetaGetter<P>;\n\nexport type MetasListener = (value: Meta) => void;\n\nexport interface Metas {\n add: (...getters: MetaItem[]) => void;\n remove: (...getters: MetaItem[]) => void;\n addListener: (listener: MetasListener) => void;\n removeListener: (listener: MetasListener) => void;\n value: Meta;\n}\n\nexport type MetaAttributes = Record<string, string>;\n\nexport interface MetaSDKIntegration {\n name?: string;\n version?: string;\n}\n\nexport interface MetaSDK {\n name?: string;\n version?: string;\n integrations?: MetaSDKIntegration[];\n}\n\nexport interface MetaApp {\n name?: string;\n release?: string;\n version?: string;\n environment?: string;\n}\n\nexport interface MetaUser {\n email?: string;\n id?: string;\n username?: string;\n attributes?: MetaAttributes;\n}\n\nexport interface MetaSession {\n id?: string;\n attributes?: MetaAttributes;\n}\n\nexport interface MetaPage {\n id?: string;\n url?: string;\n attributes?: MetaAttributes;\n}\n\nexport interface MetaBrowser {\n name?: string;\n version?: string;\n os?: string;\n mobile?: boolean;\n userAgent?: string;\n language?: string;\n}\n\nexport interface MetaView {\n name: string;\n}\n\nexport interface Meta {\n sdk?: MetaSDK;\n app?: MetaApp;\n user?: MetaUser;\n session?: MetaSession;\n page?: MetaPage;\n browser?: MetaBrowser;\n view?: MetaView;\n}\n"]}
@@ -1,3 +1,3 @@
1
1
  // auto-generated by bin/genVersion.ts
2
- export const VERSION = '1.0.0';
2
+ export const VERSION = '1.0.1';
3
3
  //# sourceMappingURL=version.js.map
@@ -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 = '1.0.0';\n"]}
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 = '1.0.1';\n"]}
@@ -6,11 +6,12 @@ export interface MeasurementEvent<V extends {
6
6
  }> {
7
7
  type: string;
8
8
  values: V;
9
+ timestamp: string;
9
10
  trace?: TraceContext;
10
11
  }
11
12
  export interface PushMeasurementOptions {
12
13
  skipDedupe?: boolean;
13
14
  }
14
15
  export interface MeasurementsAPI {
15
- pushMeasurement: (payload: MeasurementEvent, options?: PushMeasurementOptions) => void;
16
+ pushMeasurement: (payload: Omit<MeasurementEvent, 'timestamp'> & Partial<Pick<MeasurementEvent, 'timestamp'>>, options?: PushMeasurementOptions) => void;
16
17
  }
@@ -44,6 +44,8 @@ export interface MetaBrowser {
44
44
  version?: string;
45
45
  os?: string;
46
46
  mobile?: boolean;
47
+ userAgent?: string;
48
+ language?: string;
47
49
  }
48
50
  export interface MetaView {
49
51
  name: string;
@@ -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 = "1.0.0";
7
+ readonly version = "1.0.1";
8
8
  items: TransportItem[];
9
9
  constructor(ignoreURLs?: Patterns);
10
10
  send(item: TransportItem): void | Promise<void>;
@@ -1 +1 @@
1
- export declare const VERSION = "1.0.0";
1
+ export declare const VERSION = "1.0.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grafana/faro-core",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Core package of Faro.",
5
5
  "keywords": [
6
6
  "observability",
@@ -57,5 +57,5 @@
57
57
  "publishConfig": {
58
58
  "access": "public"
59
59
  },
60
- "gitHead": "afd9cbdff2b0665006e081bb72360301916e5e56"
60
+ "gitHead": "c5c93f2e33748e9dc1778a764f72a5a3f7d0221e"
61
61
  }