@grafana/faro-core 2.4.0 → 2.5.0
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/README.md +13 -1
- package/dist/bundle/faro-core.iife.js +1 -1
- package/dist/bundle/types/api/exceptions/types.d.ts +2 -0
- package/dist/bundle/types/api/index.d.ts +1 -0
- package/dist/bundle/types/api/noop.d.ts +2 -0
- package/dist/bundle/types/api/userActions/userAction.d.ts +1 -0
- package/dist/bundle/types/index.d.ts +2 -2
- package/dist/bundle/types/metas/index.d.ts +1 -1
- package/dist/bundle/types/metas/types.d.ts +19 -2
- package/dist/bundle/types/testUtils/mockTransport.d.ts +1 -1
- package/dist/bundle/types/utils/date.d.ts +18 -0
- package/dist/bundle/types/utils/index.d.ts +1 -1
- package/dist/bundle/types/version.d.ts +1 -1
- package/dist/cjs/api/exceptions/initialize.js +6 -4
- package/dist/cjs/api/exceptions/initialize.js.map +1 -1
- package/dist/cjs/api/exceptions/types.js.map +1 -1
- package/dist/cjs/api/index.js +3 -1
- package/dist/cjs/api/index.js.map +1 -1
- package/dist/cjs/api/noop.js +30 -0
- package/dist/cjs/api/noop.js.map +1 -0
- package/dist/cjs/api/userActions/userAction.js +10 -1
- package/dist/cjs/api/userActions/userAction.js.map +1 -1
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/metas/index.js.map +1 -1
- package/dist/cjs/metas/types.js.map +1 -1
- package/dist/cjs/sdk/registerFaro.js +2 -1
- package/dist/cjs/sdk/registerFaro.js.map +1 -1
- package/dist/cjs/utils/date.js +24 -0
- package/dist/cjs/utils/date.js.map +1 -1
- package/dist/cjs/utils/index.js +2 -1
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/api/exceptions/initialize.js +6 -4
- package/dist/esm/api/exceptions/initialize.js.map +1 -1
- package/dist/esm/api/exceptions/types.js.map +1 -1
- package/dist/esm/api/index.js +1 -0
- package/dist/esm/api/index.js.map +1 -1
- package/dist/esm/api/noop.js +27 -0
- package/dist/esm/api/noop.js.map +1 -0
- package/dist/esm/api/userActions/userAction.js +11 -2
- package/dist/esm/api/userActions/userAction.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/metas/index.js.map +1 -1
- package/dist/esm/metas/types.js.map +1 -1
- package/dist/esm/sdk/registerFaro.js +2 -1
- package/dist/esm/sdk/registerFaro.js.map +1 -1
- package/dist/esm/utils/date.js +23 -0
- package/dist/esm/utils/date.js.map +1 -1
- package/dist/esm/utils/index.js +1 -1
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/types/api/exceptions/types.d.ts +2 -0
- package/dist/types/api/index.d.ts +1 -0
- package/dist/types/api/noop.d.ts +2 -0
- package/dist/types/api/userActions/userAction.d.ts +1 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/metas/index.d.ts +1 -1
- package/dist/types/metas/types.d.ts +19 -2
- package/dist/types/testUtils/mockTransport.d.ts +1 -1
- package/dist/types/utils/date.d.ts +18 -0
- package/dist/types/utils/index.d.ts +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -75,11 +75,19 @@ The `api` property on the Faro instance contains all the necessary methods to pu
|
|
|
75
75
|
|
|
76
76
|
## Errors
|
|
77
77
|
|
|
78
|
-
- `pushError` - is a method to push an error/exception to the Faro instance. It accepts a mandatory `
|
|
78
|
+
- `pushError` - is a method to push an error/exception to the Faro instance. It accepts a mandatory `error` parameter
|
|
79
79
|
and an optional one where you can set:
|
|
80
80
|
- `skipDedupe` - a flag for enforcing error push even if the error is identical to the previous one.
|
|
81
81
|
- `stackFrames` - an array of stack frames. Defaults to parsing `error.stack` if present.
|
|
82
82
|
- `type` - the type of exception. Default value: `error.name` or `"error"`.
|
|
83
|
+
- `context` - a key-value object of additional context attached to the exception.
|
|
84
|
+
- `fingerprint` - a custom grouping fingerprint used for error aggregation.
|
|
85
|
+
- `fatal` - boolean flag marking the exception as fatal (e.g. crash / ANR). Participates in dedupe so a fatal
|
|
86
|
+
and non-fatal error with otherwise identical payload are reported as separate events.
|
|
87
|
+
- `spanContext` - `{ traceId, spanId }` to attach the exception to an explicit trace/span. Defaults to the
|
|
88
|
+
currently active trace context.
|
|
89
|
+
- `timestampOverwriteMs` - override the exception timestamp (milliseconds since epoch). Defaults to now.
|
|
90
|
+
- `originalError` - internal option for advanced use cases; most users should not set this.
|
|
83
91
|
|
|
84
92
|
```ts
|
|
85
93
|
faro.api.pushError(new Error('This is an error'));
|
|
@@ -105,6 +113,10 @@ The `api` property on the Faro instance contains all the necessary methods to pu
|
|
|
105
113
|
componentStackTrace: {...}
|
|
106
114
|
},
|
|
107
115
|
});
|
|
116
|
+
|
|
117
|
+
faro.api.pushError(new Error('Custom grouping'), { fingerprint: 'login-network-failure' });
|
|
118
|
+
|
|
119
|
+
faro.api.pushError(new Error('App crashed'), { fatal: true });
|
|
108
120
|
```
|
|
109
121
|
|
|
110
122
|
## Events
|
|
@@ -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,b="undefined"!=typeof Error,h=e=>b&&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 I(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(!I(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(!I(e[r],t[r]))return!1;return!0}return!1}function O(){return Date.now()}function T(){return(new Date).toISOString()}function S(e){return new Date(e).toISOString()}var A;e.LogLevel=void 0,(A=e.LogLevel||(e.LogLevel={})).TRACE="trace",A.DEBUG="debug",A.INFO="info",A.LOG="log",A.WARN="warn",A.ERROR="error";const L=e.LogLevel.LOG,j=[e.LogLevel.TRACE,e.LogLevel.DEBUG,e.LogLevel.INFO,e.LogLevel.LOG,e.LogLevel.WARN,e.LogLevel.ERROR];function _(){}const x="abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ0123456789";function N(e=10){return Array.from(Array(e)).map(()=>x[Math.floor(59*Math.random())]).join("")}const w="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:"undefined"!=typeof self?self:void 0;function R(){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 U(e={}){return JSON.stringify(null!=e?e:{},R())}function k(e={}){const t={};for(const[n,r]of Object.entries(e))t[n]=g(r)&&null!==r?U(r):String(r);return t}class C{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 C,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 C,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 C,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 C,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 B;e.InternalLoggerLevel=void 0,(B=e.InternalLoggerLevel||(e.InternalLoggerLevel={}))[B.OFF=0]="OFF",B[B.ERROR=1]="ERROR",B[B.WARN=2]="WARN",B[B.INFO=3]="INFO",B[B.VERBOSE=4]="VERBOSE";const P={debug:_,error:_,info:_,prefix:"Faro",warn:_},M=e.InternalLoggerLevel.ERROR,F=Object.assign({},console);let D=F;function V(e){var t;return D=null!==(t=e.unpatchedConsole)&&void 0!==t?t:D,D}function $(t=F,n=M){const r=P;return n>e.InternalLoggerLevel.OFF&&(r.error=n>=e.InternalLoggerLevel.ERROR?function(...e){t.error(`${r.prefix}\n`,...e)}:_,r.warn=n>=e.InternalLoggerLevel.WARN?function(...e){t.warn(`${r.prefix}\n`,...e)}:_,r.info=n>=e.InternalLoggerLevel.INFO?function(...e){t.info(`${r.prefix}\n`,...e)}:_,r.debug=n>=e.InternalLoggerLevel.VERBOSE?function(...e){t.debug(`${r.prefix}\n`,...e)}:_),r}let z=P;function G(e,t){return z=$(e,t.internalLoggerLevel),z}class H{constructor(){this.unpatchedConsole=F,this.internalLogger=P,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 K(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 W={Normal:"normal",Critical:"critical"};var X;e.UserActionState=void 0,(X=e.UserActionState||(e.UserActionState={}))[X.Started=0]="Started",X[X.Halted=1]="Halted",X[X.Cancelled=2]="Cancelled",X[X.Ended=3]="Ended";class J{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 q extends C{constructor({name:t,parentId:n,trigger:r,transports:i,attributes:s,trackUserActionsExcludeItem:a,importance:o=W.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 J,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())}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=t-this.startTime;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},k(this.attributes)),void 0,{timestampOverwriteMs:this.startTime,customPayloadTransformer:e=>(e.action={id:this.id,name:this.name},e)})}getState(){return this._state}}const Q=new C;function Y(t,n){if(!t)return!1;return(null==t?void 0:t.getState())===e.UserActionState.Started&&(t.addItem(n),!0)}const Z="Error";let ee;function te({internalLogger:t,config:n,metas:r,transports:i,tracesApi:s,userActionsApi:a}){var o;t.debug("Initializing exceptions API");let u=null;ee=null!==(o=n.parseStacktrace)&&void 0!==o?o:ee;const d=e=>{t.debug("Changing stacktrace parser"),ee=null!=e?e:ee},{ignoreErrors:p=[],preserveOriginalError:m}=n;return d(n.parseStacktrace),{changeStacktraceParser:d,getStacktraceParser:()=>ee,pushError:(o,{skipDedupe:d,stackFrames:b,type:v,context:E,spanContext:O,timestampOverwriteMs:A,originalError:L,fingerprint:j}={})=>{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=k(Object.assign(Object.assign({},function(e){let t=e.cause;h(t)?t=e.cause.toString():null!==t&&(g(e.cause)||f(e.cause))?t=U(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({type:v||o.name||Z,value:o.message,timestamp:A?S(A):T(),trace:O?{trace_id:O.traceId,span_id:O.spanId}:s.getTraceContext()},y(l)?{}:{context:l}),m?{originalError:L}:{}),j?{fingerprint:j}:{}),type:e.TransportItemType.EXCEPTION};(null==(b=null!=b?b:o.stack?null==ee?void 0:ee(o).frames:void 0)?void 0:b.length)&&(p.payload.stacktrace={frames:b});const _={type:p.payload.type,value:p.payload.value,stackTrace:p.payload.stacktrace,context:p.payload.context,fingerprint:p.payload.fingerprint};if(!d&&n.dedupe&&!c(u)&&I(_,u))return void t.debug("Skipping error push because it is the same as the last one\n",p.payload);u=_,t.debug("Pushing exception\n",p),Y(a.getActiveUserAction(),p)||i.execute(p)}catch(e){t.error("Error pushing event",e)}}}}const ne=e=>e.map(e=>{try{return String(e)}catch(e){return""}}).join(" ");function re(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 q({name:r,transports:t,attributes:s,trigger:(null==c?void 0:c.triggerName)||"faroApiCall",importance:(null==c?void 0:c.importance)||W.Normal,trackUserActionsExcludeItem:a,pushEvent:i});return n.filter(t=>[e.UserActionState.Ended,e.UserActionState.Cancelled].includes(t)).first().subscribe(()=>{o=void 0}),Q.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 b=k(l),h={meta:r.value,payload:m({name:u,domain:null!=d?d:n.eventDomain,attributes:y(b)?void 0:b,timestamp:f?S(f):T(),trace:p?{trace_id:p.traceId,span_id:p.spanId}:s.getTraceContext()}),type:e.TransportItemType.EVENT},v={name:h.payload.name,attributes:h.payload.attributes,domain:h.payload.domain};if(!g&&n.dedupe&&!c(o)&&I(v,o))return void t.debug("Skipping event push because it is the same as the last one\n",h.payload);o=v,t.debug("Pushing event\n",h),Y(a.getActiveUserAction(),h)||i.execute(h)}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),te(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:ne;return{pushLog:(o,{context:d,level:g,skipDedupe:p,spanContext:f,timestampOverwriteMs:m}={})=>{try{const b=k(d),h={type:e.TransportItemType.LOG,payload:{message:l(o),level:null!=g?g:L,context:y(b)?void 0:b,timestamp:m?S(m):T(),trace:f?{trace_id:f.traceId,span_id:f.spanId}:s.getTraceContext()},meta:r.value},v={message:h.payload.message,level:h.payload.level,context:h.payload.context};if(!p&&n.dedupe&&!c(u)&&I(v,u))return void t.debug("Skipping log push because it is the same as the last one\n",h.payload);u=v,t.debug("Pushing log\n",h),Y(a.getActiveUserAction(),h)||i.execute(h)}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=k(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?S(p):T(),context:y(f)?void 0:f}),meta:r.value},b={type:m.payload.type,values:m.payload.values,context:m.payload.context};if(!l&&n.dedupe&&!c(o)&&I(b,o))return void t.debug("Skipping measurement push because it is the same as the last one\n",m.payload);o=b,t.debug("Pushing measurement\n",m),Y(a.getActiveUserAction(),m)||i.execute(m)}catch(e){t.error("Error pushing measurement\n",e)}}}}(d)),g),o)}const ie="2.4.0";const se="_faroInternal";function ae(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(w,se,{configurable:!1,enumerable:!1,writable:!1,value:e}))}function oe(){return se in w}function ue(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},ae(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 w)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(w,e.config.globalObjectKey,{configurable:!1,writable:!1,value:e})}}(e.faro),e.faro}e.faro={};return e.BaseExtension=H,e.BaseInstrumentation=class extends H{constructor(){super(...arguments),this.api={},this.transports={}}},e.BaseTransport=class extends H{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=C,e.UserActionImportance=W,e.VERSION=ie,e.allLogLevels=j,e.clampSamplingRate=function(e){return Math.min(1,Math.max(0,e))},e.createInternalLogger=$,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=I,e.defaultBatchingConfig={enabled:!0,sendTimeout:250,itemLimit:50},e.defaultErrorArgsSerializer=e=>e.map(e=>g(e)?U(e):String(e)).join(" "),e.defaultExceptionType=Z,e.defaultGlobalObjectKey="faro",e.defaultInternalLoggerLevel=M,e.defaultLogArgsSerializer=ne,e.defaultLogLevel=L,e.defaultUnpatchedConsole=F,e.genShortID=N,e.getCircularDependencyReplacer=R,e.getCurrentTimestamp=T,e.getInternalFaroFromGlobalObject=function(){return w[se]},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:K(n.traces,t.payload.resourceSpans)})}}),n},e.globalObject=w,e.initializeFaro=function(e){const t=V(e),n=G(t,e);if(oe()&&!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=re(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=ue(t,n,e,r,s,a,o);return function(e){var t,n;const r={sdk:{version:ie,name:"faro"},app:{bundleId:e.config.app.name&&(i=e.config.app.name,null==w?void 0:w[`__faroBundleId_${i}`])}};var i;const s=null===(t=e.config.sessionTracking)||void 0===t?void 0:t.session;s&&e.api.setSession(s),e.config.app&&(r.app=Object.assign(Object.assign({},e.config.app),r.app)),e.config.user&&(r.user=e.config.user),e.config.view&&(r.view=e.config.view),e.metas.add(r,...null!==(n=e.config.metas)&&void 0!==n?n:[])}(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=se,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=h,e.isErrorDefined=b,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=oe,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.noop=_,e.setInternalFaroOnGlobalObject=ae,e.stringifyExternalJson=U,e.stringifyObjectValues=k,e.transportItemTypeToBodyKey=r,e.unknownString="unknown",e.userActionsMessageBus=Q,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.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 s(e,n,r,s){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=i(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=s,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,s;if((null===(t=r.batching)||void 0===t?void 0:t.enabled)&&o.every(e=>e.isBatched()))return;const[i]=l([e]);if(void 0!==i)for(const e of o)n.debug(`Transporting item using ${e.name}\n`,i),e.isBatched()?(null===(s=r.batching)||void 0===s?void 0:s.enabled)||e.send([i]):e.send(i)})(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 i(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 s=g(e),i=g(t);if(s!==i)return!1;if(e&&t&&s&&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(!T(e[r],t[r]))return!1;return!0}return!1}function I(){return Date.now()}function O(){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 j=e.LogLevel.LOG,_=[e.LogLevel.TRACE,e.LogLevel.DEBUG,e.LogLevel.INFO,e.LogLevel.LOG,e.LogLevel.WARN,e.LogLevel.ERROR];function x(){}const w="abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ0123456789";function N(e=10){return Array.from(Array(e)).map(()=>w[Math.floor(59*Math.random())]).join("")}const R="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:"undefined"!=typeof self?self:void 0;function U(){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 k(e={}){return JSON.stringify(null!=e?e:{},U())}function C(e={}){const t={};for(const[n,r]of Object.entries(e))t[n]=g(r)&&null!==r?k(r):String(r);return t}class B{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 B,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 B,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 B,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 B,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 P;e.InternalLoggerLevel=void 0,(P=e.InternalLoggerLevel||(e.InternalLoggerLevel={}))[P.OFF=0]="OFF",P[P.ERROR=1]="ERROR",P[P.WARN=2]="WARN",P[P.INFO=3]="INFO",P[P.VERBOSE=4]="VERBOSE";const M={debug:x,error:x,info:x,prefix:"Faro",warn:x},D=e.InternalLoggerLevel.ERROR,F=Object.assign({},console);let V=F;function z(e){var t;return V=null!==(t=e.unpatchedConsole)&&void 0!==t?t:V,V}function $(t=F,n=D){const r=M;return n>e.InternalLoggerLevel.OFF&&(r.error=n>=e.InternalLoggerLevel.ERROR?function(...e){t.error(`${r.prefix}\n`,...e)}:x,r.warn=n>=e.InternalLoggerLevel.WARN?function(...e){t.warn(`${r.prefix}\n`,...e)}:x,r.info=n>=e.InternalLoggerLevel.INFO?function(...e){t.info(`${r.prefix}\n`,...e)}:x,r.debug=n>=e.InternalLoggerLevel.VERBOSE?function(...e){t.debug(`${r.prefix}\n`,...e)}:x),r}let G=M;function H(e,t){return G=$(e,t.internalLoggerLevel),G}class K{constructor(){this.unpatchedConsole=F,this.internalLogger=M,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 W(e,t){var n,r;if(void 0===t)return e;if(void 0===e)return{resourceSpans:t};const s=null===(n=e.resourceSpans)||void 0===n?void 0:n[0];if(void 0===s)return e;const i=(null==s?void 0:s.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({},s),{scopeSpans:[...i,...a]})]})}const X={Normal:"normal",Critical:"critical"};var J;e.UserActionState=void 0,(J=e.UserActionState||(e.UserActionState={}))[J.Started=0]="Started",J[J.Halted=1]="Halted",J[J.Cancelled=2]="Cancelled",J[J.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 Q extends B{constructor({name:t,parentId:n,trigger:r,transports:s,attributes:i,trackUserActionsExcludeItem:a,importance:o=X.Normal,pushEvent:u}){super(),this.name=t,this.attributes=i,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=s,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=I(),this._startTimeMono=O())}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=I(),n=O()-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},C(this.attributes)),void 0,{timestampOverwriteMs:this.startTime,customPayloadTransformer:e=>(e.action={id:this.id,name:this.name},e)})}getState(){return this._state}}const Y=new B;function Z(t,n){if(!t)return!1;return(null==t?void 0:t.getState())===e.UserActionState.Started&&(t.addItem(n),!0)}const ee="Error";let te;function ne({internalLogger:t,config:n,metas:r,transports:s,tracesApi:i,userActionsApi:a}){var o;t.debug("Initializing exceptions API");let u=null;te=null!==(o=n.parseStacktrace)&&void 0!==o?o:te;const d=e=>{t.debug("Changing stacktrace parser"),te=null!=e?e:te},{ignoreErrors:p=[],preserveOriginalError:m}=n;return d(n.parseStacktrace),{changeStacktraceParser:d,getStacktraceParser:()=>te,pushError:(o,{skipDedupe:d,stackFrames:h,type:v,context:E,spanContext:I,timestampOverwriteMs:O,originalError:L,fingerprint:j,fatal:_}={})=>{var x;if(!function(e,t){const{message:n,name:r,stack:s}=t;return i=e,a=n+" "+r+" "+s,i.some(e=>l(e)?a.includes(e):!!a.match(e));var i,a}(p,null!=L?L:o))try{const l=C(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=k(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||ee,value:o.message,timestamp:O?A(O):S(),trace:I?{trace_id:I.traceId,span_id:I.spanId}:i.getTraceContext()},y(l)?{}:{context:l}),m?{originalError:L}:{}),j?{fingerprint:j}:{}),void 0!==_?{fatal:_}:{}),type:e.TransportItemType.EXCEPTION};(null==(h=null!=h?h:o.stack?null==te?void 0:te(o).frames:void 0)?void 0:h.length)&&(p.payload.stacktrace={frames:h});const w={type:p.payload.type,value:p.payload.value,stacktrace:p.payload.stacktrace,context:p.payload.context,fingerprint:p.payload.fingerprint,fatal:null!==(x=p.payload.fatal)&&void 0!==x&&x};if(!d&&n.dedupe&&!c(u)&&T(w,u))return void t.debug("Skipping error push because it is the same as the last one\n",p.payload);u=w,t.debug("Pushing exception\n",p),Z(a.getActiveUserAction(),p)||s.execute(p)}catch(e){t.error("Error pushing event",e)}}}}const re=e=>e.map(e=>{try{return String(e)}catch(e){return""}}).join(" ");function se(t,n,r,s,i){n.debug("Initializing API");let a=null;const o=function({transports:t,internalLogger:n,config:r,pushEvent:s}){var i;const a=null===(i=r.userActionsInstrumentation)||void 0===i?void 0:i.excludeItem;let o;const u=()=>o;return{startUserAction:(r,i,c)=>{if(void 0===u()){const n=new Q({name:r,transports:t,attributes:i,trigger:(null==c?void 0:c.triggerName)||"faroApiCall",importance:(null==c?void 0:c.importance)||X.Normal,trackUserActionsExcludeItem:a,pushEvent:s});return n.filter(t=>[e.UserActionState.Ended,e.UserActionState.Cancelled].includes(t)).first().subscribe(()=>{o=void 0}),Y.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:i,config:r,internalLogger:n,pushEvent:(e,t,r,s)=>{a?a(e,t,r,s):n.warn("pushEventImpl is not initialized. Event dropped:",{name:e,attributes:t,domain:r,options:s})}}),u=function(t,n,r,s,i){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:s.value};n.debug("Pushing trace\n",r),i.execute(r)}catch(e){n.error("Error pushing trace\n",e)}}}}(0,n,0,s,i),d={internalLogger:n,userActionsApi:o,config:r,metas:s,transports:i,tracesApi:u},g=function({internalLogger:t,config:n,metas:r,transports:s,tracesApi:i,userActionsApi:a}){let o=null;return{pushEvent:(u,l,d,{skipDedupe:g,spanContext:p,timestampOverwriteMs:f,customPayloadTransformer:m=e=>e}={})=>{try{const h=C(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}:i.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),Z(a.getActiveUserAction(),b)||s.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),ne(d)),function({internalLogger:e,metas:t}){let n,r,s,i;e.debug("Initializing meta API");const a=e=>{r&&t.remove(r),r={user:e},t.add(r)},o=(e,r)=>{var s;const i=null==r?void 0:r.overrides,a=i?{overrides:Object.assign(Object.assign({},null===(s=null==n?void 0:n.session)||void 0===s?void 0:s.overrides),i)}:{};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==s?void 0:s.view)||void 0===r?void 0:r.name)===(null==e?void 0:e.name))return;const i=s;s={view:e},t.add(s),i&&t.remove(i)},getView:()=>t.value.view,setPage:e=>{var n;const r=l(e)?Object.assign(Object.assign({},null!==(n=null==i?void 0:i.page)&&void 0!==n?n:c()),{id:e}):e;i&&t.remove(i),i={page:r},t.add(i)},getPage:c}}(d)),function({internalLogger:t,config:n,metas:r,transports:s,tracesApi:i,userActionsApi:a}){var o;t.debug("Initializing logs API");let u=null;const l=null!==(o=n.logArgsSerializer)&&void 0!==o?o:re;return{pushLog:(o,{context:d,level:g,skipDedupe:p,spanContext:f,timestampOverwriteMs:m}={})=>{try{const h=C(d),b={type:e.TransportItemType.LOG,payload:{message:l(o),level:null!=g?g:j,context:y(h)?void 0:h,timestamp:m?A(m):S(),trace:f?{trace_id:f.traceId,span_id:f.spanId}:i.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),Z(a.getActiveUserAction(),b)||s.execute(b)}catch(e){t.error("Error pushing log\n",e)}}}}(d)),function({internalLogger:t,config:n,metas:r,transports:s,tracesApi:i,userActionsApi:a}){t.debug("Initializing measurements API");let o=null;return{pushMeasurement:(u,{skipDedupe:l,context:d,spanContext:g,timestampOverwriteMs:p}={})=>{try{const f=C(d),m={type:e.TransportItemType.MEASUREMENT,payload:Object.assign(Object.assign({},u),{trace:g?{trace_id:g.traceId,span_id:g.spanId}:i.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),Z(a.getActiveUserAction(),m)||s.execute(m)}catch(e){t.error("Error pushing measurement\n",e)}}}}(d)),g),o)}const ie="2.5.0";const ae="_faroInternal";function oe(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,ae,{configurable:!1,enumerable:!1,writable:!1,value:e}))}function ue(){return ae in R}function ce(t,n,r,s,i,a,o){return n.debug("Initializing Faro"),e.faro={api:a,config:r,instrumentations:o,internalLogger:n,metas:s,pause:i.pause,transports:i,unpatchedConsole:t,unpause:i.unpause},oe(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=K,e.BaseInstrumentation=class extends K{constructor(){super(...arguments),this.api={},this.transports={}}},e.BaseTransport=class extends K{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=B,e.UserActionImportance=X,e.VERSION=ie,e.allLogLevels=_,e.clampSamplingRate=function(e){return Math.min(1,Math.max(0,e))},e.createInternalLogger=$,e.createPromiseBuffer=function(e){const{size:t,concurrency:n}=e,r=[];let s=0;const i=()=>{if(s<n&&r.length){const{producer:e,resolve:t,reject:n}=r.shift();s++,e().then(e=>{s--,i(),t(e)},e=>{s--,i(),n(e)})}};return{add:e=>{if(r.length+s>=t)throw new Error("Task buffer full");return new Promise((t,n)=>{r.push({producer:e,resolve:t,reject:n}),i()})}}},e.dateNow=I,e.deepEqual=T,e.defaultBatchingConfig={enabled:!0,sendTimeout:250,itemLimit:50},e.defaultErrorArgsSerializer=e=>e.map(e=>g(e)?k(e):String(e)).join(" "),e.defaultExceptionType=ee,e.defaultGlobalObjectKey="faro",e.defaultInternalLoggerLevel=D,e.defaultLogArgsSerializer=re,e.defaultLogLevel=j,e.defaultUnpatchedConsole=F,e.genShortID=N,e.getCircularDependencyReplacer=U,e.getCurrentTimestamp=S,e.getInternalFaroFromGlobalObject=function(){return R[ae]},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],s=n[e];n=Object.assign(Object.assign({},n),{[e]:void 0===s?[t.payload]:[...s,t.payload]});break}case e.TransportItemType.TRACE:n=Object.assign(Object.assign({},n),{traces:W(n.traces,t.payload.resourceSpans)})}}),n},e.globalObject=R,e.initializeFaro=function(e){const t=z(e),n=H(t,e);if(ue()&&!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 s=()=>n.reduce((e,t)=>Object.assign(e,p(t)?t():t),{}),i=()=>{if(r.length){const e=s();r.forEach(t=>t(e))}};return{add:(...e)=>{t.debug("Adding metas\n",e),n.push(...e),i()},remove:(...e)=>{t.debug("Removing metas\n",e),n=n.filter(t=>!e.includes(t)),i()},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 s()}}}(0,n),i=s(t,n,e,r),a=se(0,n,e,r,i),o=function(e,t,n,r,s,i){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=s,o.api=i,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 s=a.reduce((t,n,r)=>null===t&&n.name===e.name?r:null,null);null!==s?(null===(r=(n=a[s]).destroy)||void 0===r||r.call(n),a.splice(s,1)):t.warn(`Instrumentation "${e.name}" is not added`)})}}}(t,n,e,r,i,a),u=ce(t,n,e,r,i,a,o);return function(e){var t,n;const r={sdk:{version:ie,name:"faro"},app:{bundleId:e.config.app.name&&(s=e.config.app.name,null==R?void 0:R[`__faroBundleId_${s}`])}};var s;const i=null===(t=e.config.sessionTracking)||void 0===t?void 0:t.session;i&&e.api.setSession(i),e.config.app&&(r.app=Object.assign(Object.assign({},e.config.app),r.app)),e.config.user&&(r.user=e.config.user),e.config.view&&(r.view=e.config.view),e.metas.add(r,...null!==(n=e.config.metas)&&void 0!==n?n:[])}(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=ae,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=ue,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=O,e.noop=x,e.setInternalFaroOnGlobalObject=oe,e.stringifyExternalJson=k,e.stringifyObjectValues=C,e.transportItemTypeToBodyKey=r,e.unknownString="unknown",e.userActionsMessageBus=Y,e}({});
|
|
@@ -21,6 +21,7 @@ export interface ExceptionEventDefault {
|
|
|
21
21
|
timestamp: string;
|
|
22
22
|
type: string;
|
|
23
23
|
value: string;
|
|
24
|
+
fatal?: boolean;
|
|
24
25
|
fingerprint?: string;
|
|
25
26
|
stacktrace?: Stacktrace;
|
|
26
27
|
trace?: TraceContext;
|
|
@@ -37,6 +38,7 @@ export type ExceptionEventExtended = ExceptionEventDefault & {
|
|
|
37
38
|
};
|
|
38
39
|
export type ExceptionEvent<EXTENDED = ExceptionEventDefault> = EXTENDED extends boolean ? ExceptionEventExtended : ExceptionEventDefault;
|
|
39
40
|
export interface PushErrorOptions {
|
|
41
|
+
fatal?: boolean;
|
|
40
42
|
fingerprint?: string;
|
|
41
43
|
skipDedupe?: boolean;
|
|
42
44
|
stackFrames?: ExceptionStackFrame[];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { initializeAPI } from './initialize';
|
|
2
|
+
export { getNoopAPI } from './noop';
|
|
2
3
|
export type { API, APIEvent, UserAction } from './types';
|
|
3
4
|
export type { EventAttributes, EventEvent, EventsAPI, PushEventOptions } from './events';
|
|
4
5
|
export { defaultExceptionType, defaultErrorArgsSerializer } from './exceptions';
|
|
@@ -12,6 +12,7 @@ export default class UserAction extends Observable implements UserActionInternal
|
|
|
12
12
|
trigger: string;
|
|
13
13
|
importance: UserActionImportanceType;
|
|
14
14
|
startTime?: number;
|
|
15
|
+
private _startTimeMono?;
|
|
15
16
|
trackUserActionsExcludeItem?: (item: TransportItem<APIEvent>) => boolean;
|
|
16
17
|
private _state;
|
|
17
18
|
private _itemBuffer;
|
|
@@ -11,7 +11,7 @@ export { BaseInstrumentation } from './instrumentations';
|
|
|
11
11
|
export type { Instrumentation, Instrumentations } from './instrumentations';
|
|
12
12
|
export { createInternalLogger, defaultInternalLoggerLevel, InternalLoggerLevel } from './internalLogger';
|
|
13
13
|
export type { InternalLogger } from './internalLogger';
|
|
14
|
-
export type { Meta, MetaApp, MetaAttributes, MetaBrowser, MetaGetter, MetaItem, MetaPage, Metas, MetaSDK, MetaSDKIntegration, MetaSession, MetaUser, MetaView, MetaOverrides, } from './metas';
|
|
14
|
+
export type { Meta, MetaApp, MetaAttributes, MetaBrowser, MetaDevice, MetaGetter, MetaItem, MetaOS, MetaPage, Metas, MetaSDK, MetaSDKIntegration, MetaSession, MetaUser, MetaView, MetaOverrides, } from './metas';
|
|
15
15
|
export { faro, getInternalFaroFromGlobalObject, internalGlobalObjectKey, isInternalFaroOnGlobalObject, setInternalFaroOnGlobalObject, } from './sdk';
|
|
16
16
|
export type { Faro } from './sdk';
|
|
17
17
|
export * from './semantic';
|
|
@@ -19,7 +19,7 @@ export { BaseTransport, getTransportBody, TransportItemType, transportItemTypeTo
|
|
|
19
19
|
export type { BeforeSendHook, SendFn, Transport, TransportBody, TransportItem, TransportItemPayload, Transports, } from './transports';
|
|
20
20
|
export { defaultUnpatchedConsole } from './unpatchedConsole';
|
|
21
21
|
export type { UnpatchedConsole } from './unpatchedConsole';
|
|
22
|
-
export { allLogLevels, clampSamplingRate, createPromiseBuffer, deepEqual, defaultLogLevel, genShortID, getCurrentTimestamp, isArray, isBoolean, isDomError, isDomException, isElement, isElementDefined, isError, isErrorDefined, isErrorEvent, isEvent, isEventDefined, isFunction, isInstanceOf, isInt, isMap, isMapDefined, isNull, isNumber, isObject, isPrimitive, isRegExp, isString, isSymbol, isSyntheticEvent, isThenable, isToString, isTypeof, isUndefined, LogLevel, noop, dateNow, isEmpty, getCircularDependencyReplacer, stringifyExternalJson, stringifyObjectValues, Observable, } from './utils';
|
|
22
|
+
export { allLogLevels, clampSamplingRate, createPromiseBuffer, deepEqual, defaultLogLevel, genShortID, getCurrentTimestamp, isArray, isBoolean, isDomError, isDomException, isElement, isElementDefined, isError, isErrorDefined, isErrorEvent, isEvent, isEventDefined, isFunction, isInstanceOf, isInt, isMap, isMapDefined, isNull, isNumber, isObject, isPrimitive, isRegExp, isString, isSymbol, isSyntheticEvent, isThenable, isToString, isTypeof, isUndefined, LogLevel, noop, dateNow, monoNow, isEmpty, getCircularDependencyReplacer, stringifyExternalJson, stringifyObjectValues, Observable, } from './utils';
|
|
23
23
|
export type { BaseObject, BaseObjectKey, BaseObjectPrimitiveValue, BaseObjectValue, BufferItem, PromiseBuffer, PromiseBufferOptions, PromiseProducer, Subscription, } from './utils';
|
|
24
24
|
export { VERSION } from './version';
|
|
25
25
|
export { unknownString } from './consts';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { initializeMetas } from './initialize';
|
|
2
2
|
export { registerInitialMetas } from './registerInitial';
|
|
3
|
-
export type { Meta, MetaApp, MetaAttributes, MetaBrowser, MetaGetter, MetaItem, MetaK6, MetaPage, MetaSDK, MetaSDKIntegration, MetaSession, MetaUser, MetaView, Metas, MetaOverrides, } from './types';
|
|
3
|
+
export type { Meta, MetaApp, MetaAttributes, MetaBrowser, MetaDevice, MetaGetter, MetaItem, MetaK6, MetaOS, MetaPage, MetaSDK, MetaSDKIntegration, MetaSession, MetaUser, MetaView, Metas, MetaOverrides, } from './types';
|
|
@@ -19,12 +19,13 @@ export interface MetaSDK {
|
|
|
19
19
|
integrations?: MetaSDKIntegration[];
|
|
20
20
|
}
|
|
21
21
|
export interface MetaApp {
|
|
22
|
+
bundleId?: string;
|
|
23
|
+
environment?: string;
|
|
24
|
+
installationId?: string;
|
|
22
25
|
name?: string;
|
|
23
26
|
namespace?: string;
|
|
24
27
|
release?: string;
|
|
25
28
|
version?: string;
|
|
26
|
-
environment?: string;
|
|
27
|
-
bundleId?: string;
|
|
28
29
|
}
|
|
29
30
|
export interface MetaUser {
|
|
30
31
|
/**
|
|
@@ -88,6 +89,20 @@ export interface MetaK6 {
|
|
|
88
89
|
isK6Browser?: boolean;
|
|
89
90
|
testRunId?: string;
|
|
90
91
|
}
|
|
92
|
+
export interface MetaOS {
|
|
93
|
+
name?: string;
|
|
94
|
+
version?: string;
|
|
95
|
+
build_id?: string;
|
|
96
|
+
detail?: string;
|
|
97
|
+
}
|
|
98
|
+
export interface MetaDevice {
|
|
99
|
+
manufacturer?: string;
|
|
100
|
+
model_identifier?: string;
|
|
101
|
+
model_name?: string;
|
|
102
|
+
brand?: string;
|
|
103
|
+
is_physical?: boolean;
|
|
104
|
+
type?: string;
|
|
105
|
+
}
|
|
91
106
|
export interface Meta {
|
|
92
107
|
sdk?: MetaSDK;
|
|
93
108
|
app?: MetaApp;
|
|
@@ -97,6 +112,8 @@ export interface Meta {
|
|
|
97
112
|
browser?: MetaBrowser;
|
|
98
113
|
view?: MetaView;
|
|
99
114
|
k6?: MetaK6;
|
|
115
|
+
os?: MetaOS;
|
|
116
|
+
device?: MetaDevice;
|
|
100
117
|
}
|
|
101
118
|
/**
|
|
102
119
|
* MetaOverrides are instructions that allow the receiver to override certain properties (Grafana Cloud only).
|
|
@@ -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.5.0";
|
|
8
8
|
items: TransportItem[];
|
|
9
9
|
constructor(ignoreURLs?: Patterns);
|
|
10
10
|
send(items: TransportItem[]): void | Promise<void>;
|
|
@@ -1,3 +1,21 @@
|
|
|
1
1
|
export declare function dateNow(): number;
|
|
2
|
+
/**
|
|
3
|
+
* Returns a high-resolution, monotonic timestamp in milliseconds.
|
|
4
|
+
*
|
|
5
|
+
* Use this for measuring elapsed time / durations. Unlike {@link dateNow} (which is
|
|
6
|
+
* derived from the system wall clock and is therefore subject to NTP adjustments,
|
|
7
|
+
* manual clock changes, daylight-savings transitions, etc.), `monoNow` is backed by
|
|
8
|
+
* `performance.now()`, which is guaranteed never to decrease and is unaffected by
|
|
9
|
+
* such adjustments.
|
|
10
|
+
*
|
|
11
|
+
* Do NOT use this for absolute event timestamps that need to be correlated with
|
|
12
|
+
* other systems or persisted across page loads — use {@link dateNow} or
|
|
13
|
+
* {@link getCurrentTimestamp} for that.
|
|
14
|
+
*
|
|
15
|
+
* Falls back to {@link dateNow} in environments where `performance.now` is
|
|
16
|
+
* unavailable (very old runtimes, unusual SSR setups). The fallback re-introduces
|
|
17
|
+
* wall-clock susceptibility but preserves the API contract.
|
|
18
|
+
*/
|
|
19
|
+
export declare function monoNow(): number;
|
|
2
20
|
export declare function getCurrentTimestamp(): string;
|
|
3
21
|
export declare function timestampToIsoString(value: number): string;
|
|
@@ -10,7 +10,7 @@ export { createPromiseBuffer } from './promiseBuffer';
|
|
|
10
10
|
export type { BufferItem, PromiseBuffer, PromiseBufferOptions, PromiseProducer } from './promiseBuffer';
|
|
11
11
|
export { genShortID } from './shortId';
|
|
12
12
|
export { getBundleId } from './sourceMaps';
|
|
13
|
-
export { dateNow } from './date';
|
|
13
|
+
export { dateNow, monoNow } from './date';
|
|
14
14
|
export { getCircularDependencyReplacer, stringifyExternalJson, stringifyObjectValues } from './json';
|
|
15
15
|
export { Observable } from './reactive';
|
|
16
16
|
export type { Subscription } from './reactive';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "2.
|
|
1
|
+
export declare const VERSION = "2.5.0";
|
|
@@ -19,7 +19,8 @@ function initializeExceptionsAPI({ internalLogger, config, metas, transports, tr
|
|
|
19
19
|
};
|
|
20
20
|
const getStacktraceParser = () => stacktraceParser;
|
|
21
21
|
const { ignoreErrors = [], preserveOriginalError } = config;
|
|
22
|
-
const pushError = (error, { skipDedupe, stackFrames, type, context, spanContext, timestampOverwriteMs, originalError, fingerprint } = {}) => {
|
|
22
|
+
const pushError = (error, { skipDedupe, stackFrames, type, context, spanContext, timestampOverwriteMs, originalError, fingerprint, fatal, } = {}) => {
|
|
23
|
+
var _a;
|
|
23
24
|
if (isErrorIgnored(ignoreErrors, originalError !== null && originalError !== void 0 ? originalError : error)) {
|
|
24
25
|
return;
|
|
25
26
|
}
|
|
@@ -27,12 +28,12 @@ function initializeExceptionsAPI({ internalLogger, config, metas, transports, tr
|
|
|
27
28
|
const ctx = (0, utils_1.stringifyObjectValues)(Object.assign(Object.assign({}, parseCause(originalError !== null && originalError !== void 0 ? originalError : error)), (context !== null && context !== void 0 ? context : {})));
|
|
28
29
|
const item = {
|
|
29
30
|
meta: metas.value,
|
|
30
|
-
payload: Object.assign(Object.assign(Object.assign({ type: type || error.name || const_1.defaultExceptionType, value: error.message, timestamp: timestampOverwriteMs ? (0, date_1.timestampToIsoString)(timestampOverwriteMs) : (0, utils_1.getCurrentTimestamp)(), trace: spanContext
|
|
31
|
+
payload: Object.assign(Object.assign(Object.assign(Object.assign({ type: type || error.name || const_1.defaultExceptionType, value: error.message, timestamp: timestampOverwriteMs ? (0, date_1.timestampToIsoString)(timestampOverwriteMs) : (0, utils_1.getCurrentTimestamp)(), trace: spanContext
|
|
31
32
|
? {
|
|
32
33
|
trace_id: spanContext.traceId,
|
|
33
34
|
span_id: spanContext.spanId,
|
|
34
35
|
}
|
|
35
|
-
: tracesApi.getTraceContext() }, ((0, utils_1.isEmpty)(ctx) ? {} : { context: ctx })), (preserveOriginalError ? { originalError } : {})), (fingerprint ? { fingerprint } : {})),
|
|
36
|
+
: tracesApi.getTraceContext() }, ((0, utils_1.isEmpty)(ctx) ? {} : { context: ctx })), (preserveOriginalError ? { originalError } : {})), (fingerprint ? { fingerprint } : {})), (fatal !== undefined ? { fatal } : {})),
|
|
36
37
|
type: transports_1.TransportItemType.EXCEPTION,
|
|
37
38
|
};
|
|
38
39
|
stackFrames = stackFrames !== null && stackFrames !== void 0 ? stackFrames : (error.stack ? stacktraceParser === null || stacktraceParser === void 0 ? void 0 : stacktraceParser(error).frames : undefined);
|
|
@@ -44,9 +45,10 @@ function initializeExceptionsAPI({ internalLogger, config, metas, transports, tr
|
|
|
44
45
|
const testingPayload = {
|
|
45
46
|
type: item.payload.type,
|
|
46
47
|
value: item.payload.value,
|
|
47
|
-
|
|
48
|
+
stacktrace: item.payload.stacktrace,
|
|
48
49
|
context: item.payload.context,
|
|
49
50
|
fingerprint: item.payload.fingerprint,
|
|
51
|
+
fatal: (_a = item.payload.fatal) !== null && _a !== void 0 ? _a : false,
|
|
50
52
|
};
|
|
51
53
|
if (!skipDedupe && config.dedupe && !(0, utils_1.isNull)(lastPayload) && (0, utils_1.deepEqual)(testingPayload, lastPayload)) {
|
|
52
54
|
internalLogger.debug('Skipping error push because it is the same as the last one\n', item.payload);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../src/api/exceptions/initialize.ts"],"names":[],"mappings":";;AA4BA,
|
|
1
|
+
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../src/api/exceptions/initialize.ts"],"names":[],"mappings":";;AA4BA,0DAsHC;AA/ID,iDAAqD;AAGrD,uCAUqB;AACrB,2CAAwD;AAGxD,0DAAsE;AACtE,oCAA6C;AAE7C,mCAA+C;AAG/C,IAAI,gBAA8C,CAAC;AAEnD,SAAgB,uBAAuB,CAAC,EACtC,cAAc,EACd,MAAM,EACN,KAAK,EACL,UAAU,EACV,SAAS,EACT,cAAc,GASf;;IACC,cAAc,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC;IAEpD,IAAI,WAAW,GACb,IAAI,CAAC;IAEP,gBAAgB,GAAG,MAAA,MAAM,CAAC,eAAe,mCAAI,gBAAgB,CAAC;IAE9D,MAAM,sBAAsB,GAA4C,CAAC,mBAAmB,EAAE,EAAE;QAC9F,cAAc,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAEnD,gBAAgB,GAAG,mBAAmB,aAAnB,mBAAmB,cAAnB,mBAAmB,GAAI,gBAAgB,CAAC;IAC7D,CAAC,CAAC;IAEF,MAAM,mBAAmB,GAAyC,GAAG,EAAE,CAAC,gBAAgB,CAAC;IAEzF,MAAM,EAAE,YAAY,GAAG,EAAE,EAAE,qBAAqB,EAAE,GAAG,MAAM,CAAC;IAE5D,MAAM,SAAS,GAA+B,CAC5C,KAAK,EACL,EACE,UAAU,EACV,WAAW,EACX,IAAI,EACJ,OAAO,EACP,WAAW,EACX,oBAAoB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esContent":["import type { Config, Patterns } from '../../config';\nimport type { InternalLogger } from '../../internalLogger';\nimport type { Metas } from '../../metas';\nimport { TransportItemType } from '../../transports';\nimport type { TransportItem, Transports } from '../../transports';\nimport type { UnpatchedConsole } from '../../unpatchedConsole';\nimport {\n deepEqual,\n getCurrentTimestamp,\n isArray,\n isEmpty,\n isError,\n isNull,\n isObject,\n stringifyExternalJson,\n stringifyObjectValues,\n} from '../../utils';\nimport { timestampToIsoString } from '../../utils/date';\nimport type { TracesAPI } from '../traces';\nimport type { UserActionsAPI } from '../userActions';\nimport { addItemToUserActionBuffer } from '../userActions/initialize';\nimport { shouldIgnoreEvent } from '../utils';\n\nimport { defaultExceptionType } from './const';\nimport type { ErrorWithIndexProperties, ExceptionEvent, ExceptionsAPI, StacktraceParser } from './types';\n\nlet stacktraceParser: StacktraceParser | undefined;\n\nexport function initializeExceptionsAPI({\n internalLogger,\n config,\n metas,\n transports,\n tracesApi,\n userActionsApi,\n}: {\n unpatchedConsole: UnpatchedConsole;\n internalLogger: InternalLogger;\n config: Config;\n metas: Metas;\n transports: Transports;\n tracesApi: TracesAPI;\n userActionsApi: UserActionsAPI;\n}): ExceptionsAPI {\n internalLogger.debug('Initializing exceptions API');\n\n let lastPayload: Pick<ExceptionEvent, 'type' | 'value' | 'stacktrace' | 'context' | 'fingerprint' | 'fatal'> | null =\n null;\n\n stacktraceParser = config.parseStacktrace ?? stacktraceParser;\n\n const changeStacktraceParser: ExceptionsAPI['changeStacktraceParser'] = (newStacktraceParser) => {\n internalLogger.debug('Changing stacktrace parser');\n\n stacktraceParser = newStacktraceParser ?? stacktraceParser;\n };\n\n const getStacktraceParser: ExceptionsAPI['getStacktraceParser'] = () => stacktraceParser;\n\n const { ignoreErrors = [], preserveOriginalError } = config;\n\n const pushError: ExceptionsAPI['pushError'] = (\n error,\n {\n skipDedupe,\n stackFrames,\n type,\n context,\n spanContext,\n timestampOverwriteMs,\n originalError,\n fingerprint,\n fatal,\n } = {}\n ) => {\n if (isErrorIgnored(ignoreErrors, originalError ?? error)) {\n return;\n }\n try {\n const ctx = stringifyObjectValues({\n ...parseCause(originalError ?? error),\n ...(context ?? {}),\n });\n\n const item: TransportItem<ExceptionEvent<typeof preserveOriginalError>> = {\n meta: metas.value,\n payload: {\n type: type || error.name || defaultExceptionType,\n value: error.message,\n timestamp: timestampOverwriteMs ? timestampToIsoString(timestampOverwriteMs) : getCurrentTimestamp(),\n trace: spanContext\n ? {\n trace_id: spanContext.traceId,\n span_id: spanContext.spanId,\n }\n : tracesApi.getTraceContext(),\n ...(isEmpty(ctx) ? {} : { context: ctx }),\n ...(preserveOriginalError ? { originalError } : {}),\n ...(fingerprint ? { fingerprint } : {}),\n ...(fatal !== undefined ? { fatal } : {}),\n },\n type: TransportItemType.EXCEPTION,\n };\n\n stackFrames = stackFrames ?? (error.stack ? stacktraceParser?.(error).frames : undefined);\n\n if (stackFrames?.length) {\n item.payload.stacktrace = {\n frames: stackFrames,\n };\n }\n\n const testingPayload = {\n type: item.payload.type,\n value: item.payload.value,\n stacktrace: item.payload.stacktrace,\n context: item.payload.context,\n fingerprint: item.payload.fingerprint,\n fatal: item.payload.fatal ?? false,\n };\n\n if (!skipDedupe && config.dedupe && !isNull(lastPayload) && deepEqual(testingPayload, lastPayload)) {\n internalLogger.debug('Skipping error 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 exception\\n', item);\n\n if (!addItemToUserActionBuffer(userActionsApi.getActiveUserAction(), item)) {\n transports.execute(item);\n }\n } catch (err) {\n internalLogger.error('Error pushing event', err);\n }\n };\n\n changeStacktraceParser(config.parseStacktrace);\n\n return {\n changeStacktraceParser,\n getStacktraceParser,\n pushError,\n };\n}\n\nfunction parseCause(error: ErrorWithIndexProperties): {} | { cause: string } {\n let cause = error.cause;\n\n if (isError(cause)) {\n cause = error.cause.toString();\n // typeof operator on null returns \"object\". This is a well-known quirk in JavaScript and is considered a bug that cannot be fixed due to backward compatibility issues.\n // MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof#typeof_null\n } else if (cause !== null && (isObject(error.cause) || isArray(error.cause))) {\n cause = stringifyExternalJson(error.cause);\n } else if (cause != null) {\n cause = error.cause.toString();\n }\n\n return cause == null ? {} : { cause };\n}\n\nfunction isErrorIgnored(ignoreErrors: Patterns, error: ErrorWithIndexProperties): boolean {\n const { message, name, stack } = error;\n return shouldIgnoreEvent(ignoreErrors, message + ' ' + name + ' ' + stack);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/api/exceptions/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { SpanContext } from '@opentelemetry/api';\n\nimport type { TraceContext } from '../traces';\nimport type { UserAction } from '../types';\n\nexport type StacktraceParser = (err: ExtendedError) => Stacktrace;\n\nexport interface ExceptionStackFrame {\n filename: string;\n function: string;\n\n colno?: number;\n lineno?: number;\n\n bundleid?: string;\n}\n\nexport interface ExtendedError extends Error {\n columnNumber?: number;\n stacktrace?: Error['stack'];\n}\n\nexport interface Stacktrace {\n frames: ExceptionStackFrame[];\n}\n\nexport type ExceptionContext = Record<string, string>;\n\nexport interface ExceptionEventDefault {\n timestamp: string;\n type: string;\n value: string;\n\n fingerprint?: string;\n stacktrace?: Stacktrace;\n trace?: TraceContext;\n context?: ExceptionContext;\n\n action?: UserAction;\n}\n\n/**\n * The ExceptionEventExtended type is used to represent an exception event with an additional error\n * property and is only meant for client side use. The additional property is removed by Faro before\n * sending the event to the transport.\n */\nexport type ExceptionEventExtended = ExceptionEventDefault & {\n originalError?: Error;\n};\n\nexport type ExceptionEvent<EXTENDED = ExceptionEventDefault> = EXTENDED extends boolean\n ? ExceptionEventExtended\n : ExceptionEventDefault;\n\nexport interface PushErrorOptions {\n fingerprint?: string;\n skipDedupe?: boolean;\n stackFrames?: ExceptionStackFrame[];\n type?: string;\n context?: ExceptionContext;\n spanContext?: Pick<SpanContext, 'traceId' | 'spanId'>;\n timestampOverwriteMs?: number;\n /**\n * Retains the original error object in the payload after parsing.\n * This is primarily for internal, advanced use cases.\n * Faro users should not need to use this option.\n */\n originalError?: Error;\n}\n\n// ts type is missing the cause property\nexport type ErrorWithIndexProperties = Error & {\n cause?: any;\n};\n\nexport interface ExceptionsAPI {\n changeStacktraceParser: (stacktraceParser: StacktraceParser) => void;\n getStacktraceParser: () => StacktraceParser | undefined;\n pushError: (value: ErrorWithIndexProperties, options?: PushErrorOptions) => void;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/api/exceptions/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { SpanContext } from '@opentelemetry/api';\n\nimport type { TraceContext } from '../traces';\nimport type { UserAction } from '../types';\n\nexport type StacktraceParser = (err: ExtendedError) => Stacktrace;\n\nexport interface ExceptionStackFrame {\n filename: string;\n function: string;\n\n colno?: number;\n lineno?: number;\n\n bundleid?: string;\n}\n\nexport interface ExtendedError extends Error {\n columnNumber?: number;\n stacktrace?: Error['stack'];\n}\n\nexport interface Stacktrace {\n frames: ExceptionStackFrame[];\n}\n\nexport type ExceptionContext = Record<string, string>;\n\nexport interface ExceptionEventDefault {\n timestamp: string;\n type: string;\n value: string;\n\n fatal?: boolean;\n fingerprint?: string;\n stacktrace?: Stacktrace;\n trace?: TraceContext;\n context?: ExceptionContext;\n\n action?: UserAction;\n}\n\n/**\n * The ExceptionEventExtended type is used to represent an exception event with an additional error\n * property and is only meant for client side use. The additional property is removed by Faro before\n * sending the event to the transport.\n */\nexport type ExceptionEventExtended = ExceptionEventDefault & {\n originalError?: Error;\n};\n\nexport type ExceptionEvent<EXTENDED = ExceptionEventDefault> = EXTENDED extends boolean\n ? ExceptionEventExtended\n : ExceptionEventDefault;\n\nexport interface PushErrorOptions {\n fatal?: boolean;\n fingerprint?: string;\n skipDedupe?: boolean;\n stackFrames?: ExceptionStackFrame[];\n type?: string;\n context?: ExceptionContext;\n spanContext?: Pick<SpanContext, 'traceId' | 'spanId'>;\n timestampOverwriteMs?: number;\n /**\n * Retains the original error object in the payload after parsing.\n * This is primarily for internal, advanced use cases.\n * Faro users should not need to use this option.\n */\n originalError?: Error;\n}\n\n// ts type is missing the cause property\nexport type ErrorWithIndexProperties = Error & {\n cause?: any;\n};\n\nexport interface ExceptionsAPI {\n changeStacktraceParser: (stacktraceParser: StacktraceParser) => void;\n getStacktraceParser: () => StacktraceParser | undefined;\n pushError: (value: ErrorWithIndexProperties, options?: PushErrorOptions) => void;\n}\n"]}
|
package/dist/cjs/api/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.userActionsMessageBus = exports.UserActionState = exports.UserActionImportance = exports.defaultLogArgsSerializer = exports.defaultErrorArgsSerializer = exports.defaultExceptionType = exports.initializeAPI = void 0;
|
|
3
|
+
exports.userActionsMessageBus = exports.UserActionState = exports.UserActionImportance = exports.defaultLogArgsSerializer = exports.defaultErrorArgsSerializer = exports.defaultExceptionType = exports.getNoopAPI = exports.initializeAPI = void 0;
|
|
4
4
|
var initialize_1 = require("./initialize");
|
|
5
5
|
Object.defineProperty(exports, "initializeAPI", { enumerable: true, get: function () { return initialize_1.initializeAPI; } });
|
|
6
|
+
var noop_1 = require("./noop");
|
|
7
|
+
Object.defineProperty(exports, "getNoopAPI", { enumerable: true, get: function () { return noop_1.getNoopAPI; } });
|
|
6
8
|
var exceptions_1 = require("./exceptions");
|
|
7
9
|
Object.defineProperty(exports, "defaultExceptionType", { enumerable: true, get: function () { return exceptions_1.defaultExceptionType; } });
|
|
8
10
|
Object.defineProperty(exports, "defaultErrorArgsSerializer", { enumerable: true, get: function () { return exceptions_1.defaultErrorArgsSerializer; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/index.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAApC,2GAAA,aAAa,OAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/index.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAApC,2GAAA,aAAa,OAAA;AACtB,+BAAoC;AAA3B,kGAAA,UAAU,OAAA;AAKnB,2CAAgF;AAAvE,kHAAA,oBAAoB,OAAA;AAAE,wHAAA,0BAA0B,OAAA;AAYzD,+BAAkD;AAAzC,gHAAA,wBAAwB,OAAA;AAOjC,6CAQuB;AAPrB,mHAAA,oBAAoB,OAAA;AAEpB,8GAAA,eAAe,OAAA;AAIf,oHAAA,qBAAqB,OAAA","sourcesContent":["export { initializeAPI } from './initialize';\nexport { getNoopAPI } from './noop';\nexport type { API, APIEvent, UserAction } from './types';\n\nexport type { EventAttributes, EventEvent, EventsAPI, PushEventOptions } from './events';\n\nexport { defaultExceptionType, defaultErrorArgsSerializer } from './exceptions';\nexport type {\n ExceptionEvent,\n ExceptionStackFrame,\n ExceptionsAPI,\n ExtendedError,\n PushErrorOptions,\n Stacktrace,\n StacktraceParser,\n ExceptionEventExtended,\n} from './exceptions';\n\nexport { defaultLogArgsSerializer } from './logs';\nexport type { LogContext, LogEvent, LogArgsSerializer, LogsAPI, PushLogOptions } from './logs';\n\nexport type { MeasurementEvent, MeasurementsAPI, PushMeasurementOptions } from './measurements';\n\nexport type { MetaAPI } from './meta';\n\nexport {\n UserActionImportance,\n type UserActionImportanceType,\n UserActionState,\n type UserActionInterface,\n type UserActionInternalInterface,\n type UserActionsAPI,\n userActionsMessageBus,\n} from './userActions';\n\nexport type { OTELApi, TraceContext, TraceEvent, TracesAPI } from './traces';\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getNoopAPI = getNoopAPI;
|
|
4
|
+
function getNoopAPI() {
|
|
5
|
+
return {
|
|
6
|
+
pushLog: () => { },
|
|
7
|
+
pushError: () => { },
|
|
8
|
+
changeStacktraceParser: () => { },
|
|
9
|
+
getStacktraceParser: () => undefined,
|
|
10
|
+
pushMeasurement: () => { },
|
|
11
|
+
pushTraces: () => { },
|
|
12
|
+
getOTEL: () => undefined,
|
|
13
|
+
getTraceContext: () => undefined,
|
|
14
|
+
initOTEL: () => { },
|
|
15
|
+
isOTELInitialized: () => false,
|
|
16
|
+
setUser: () => { },
|
|
17
|
+
resetUser: () => { },
|
|
18
|
+
setSession: () => { },
|
|
19
|
+
resetSession: () => { },
|
|
20
|
+
getSession: () => undefined,
|
|
21
|
+
setView: () => { },
|
|
22
|
+
getView: () => undefined,
|
|
23
|
+
setPage: () => { },
|
|
24
|
+
getPage: () => undefined,
|
|
25
|
+
pushEvent: () => { },
|
|
26
|
+
startUserAction: () => undefined,
|
|
27
|
+
getActiveUserAction: () => undefined,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=noop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"noop.js","sourceRoot":"","sources":["../../../src/api/noop.ts"],"names":[],"mappings":";;AAEA,gCAyBC;AAzBD,SAAgB,UAAU;IACxB,OAAO;QACL,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC;QACjB,SAAS,EAAE,GAAG,EAAE,GAAE,CAAC;QACnB,sBAAsB,EAAE,GAAG,EAAE,GAAE,CAAC;QAChC,mBAAmB,EAAE,GAAG,EAAE,CAAC,SAAS;QACpC,eAAe,EAAE,GAAG,EAAE,GAAE,CAAC;QACzB,UAAU,EAAE,GAAG,EAAE,GAAE,CAAC;QACpB,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS;QACxB,eAAe,EAAE,GAAG,EAAE,CAAC,SAAS;QAChC,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC;QAClB,iBAAiB,EAAE,GAAG,EAAE,CAAC,KAAK;QAC9B,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC;QACjB,SAAS,EAAE,GAAG,EAAE,GAAE,CAAC;QACnB,UAAU,EAAE,GAAG,EAAE,GAAE,CAAC;QACpB,YAAY,EAAE,GAAG,EAAE,GAAE,CAAC;QACtB,UAAU,EAAE,GAAG,EAAE,CAAC,SAAS;QAC3B,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC;QACjB,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS;QACxB,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC;QACjB,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS;QACxB,SAAS,EAAE,GAAG,EAAE,GAAE,CAAC;QACnB,eAAe,EAAE,GAAG,EAAE,CAAC,SAAS;QAChC,mBAAmB,EAAE,GAAG,EAAE,CAAC,SAAS;KACrC,CAAC;AACJ,CAAC","sourcesContent":["import type { API } from './types';\n\nexport function getNoopAPI(): API {\n return {\n pushLog: () => {},\n pushError: () => {},\n changeStacktraceParser: () => {},\n getStacktraceParser: () => undefined,\n pushMeasurement: () => {},\n pushTraces: () => {},\n getOTEL: () => undefined,\n getTraceContext: () => undefined,\n initOTEL: () => {},\n isOTELInitialized: () => false,\n setUser: () => {},\n resetUser: () => {},\n setSession: () => {},\n resetSession: () => {},\n getSession: () => undefined,\n setView: () => {},\n getView: () => undefined,\n setPage: () => {},\n getPage: () => undefined,\n pushEvent: () => {},\n startUserAction: () => undefined,\n getActiveUserAction: () => undefined,\n };\n}\n"]}
|
|
@@ -31,7 +31,12 @@ class UserAction extends utils_1.Observable {
|
|
|
31
31
|
_start() {
|
|
32
32
|
this._state = types_1.UserActionState.Started;
|
|
33
33
|
if (this._state === types_1.UserActionState.Started) {
|
|
34
|
+
// `startTime` is wall-clock (Unix-epoch ms) so it can be used as the event's
|
|
35
|
+
// `timestampOverwriteMs` and emitted as `userActionStartTime` for consumers that
|
|
36
|
+
// correlate with other systems. `_startTimeMono` is the monotonic anchor used
|
|
37
|
+
// for the duration calculation in `end()`.
|
|
34
38
|
this.startTime = (0, utils_1.dateNow)();
|
|
39
|
+
this._startTimeMono = (0, utils_1.monoNow)();
|
|
35
40
|
}
|
|
36
41
|
}
|
|
37
42
|
halt() {
|
|
@@ -56,7 +61,11 @@ class UserAction extends utils_1.Observable {
|
|
|
56
61
|
return;
|
|
57
62
|
}
|
|
58
63
|
const endTime = (0, utils_1.dateNow)();
|
|
59
|
-
|
|
64
|
+
// Compute duration from the monotonic clock so it is unaffected by wall-clock
|
|
65
|
+
// adjustments during the action. Note: `endTime - startTime` (both wall-clock) may
|
|
66
|
+
// disagree with `duration` if the system clock was adjusted between start and end;
|
|
67
|
+
// `duration` is authoritative.
|
|
68
|
+
const duration = (0, utils_1.monoNow)() - this._startTimeMono;
|
|
60
69
|
this._state = types_1.UserActionState.Ended;
|
|
61
70
|
this._itemBuffer.flushBuffer((item) => {
|
|
62
71
|
if (isExcludeFromUserAction(item, this.trackUserActionsExcludeItem)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userAction.js","sourceRoot":"","sources":["../../../../src/api/userActions/userAction.ts"],"names":[],"mappings":";;AAAA,iDAA0F;AAC1F,
|
|
1
|
+
{"version":3,"file":"userAction.js","sourceRoot":"","sources":["../../../../src/api/userActions/userAction.ts"],"names":[],"mappings":";;AAAA,iDAA0F;AAC1F,uCAA8F;AAE9F,8CAA2C;AAI3C,mCAAmG;AACnG,mCAAgH;AAEhH,MAAqB,UACnB,SAAQ,kBAAU;IAoBlB,YAAY,EACV,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,UAAU,EACV,UAAU,EACV,2BAA2B,EAC3B,UAAU,GAAG,4BAAoB,CAAC,MAAM,EACxC,SAAS,GAUV;QACC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,EAAE,GAAG,IAAA,kBAAU,GAAE,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,QAA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AC;QACpC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAEzB,IAAI,CAAC,UAAU,CACb,2BAAmB,kBAEjB,cAAc,EAAE,IAAI,CAAC,IAAI,EACzB,mBAAmB,EAAE,IAAI,CAAC,SAAU,CAAC,QAAQ,EAAE,EAC/C,iBAAiB,EAAE,OAAO,CAAC,QAAQ,EAAE,EACrC,kBAAkB,EAAE,QAAQ,CAAC,QAAQ,EAAE,EACvC,iBAAiB,EAAE,IAAI,CAAC,OAAQ,EAChC,oBAAoB,EAAE,IAAI,CAAC,UAAU,IAClC,IAAA,6BAAqB,EAAC,IAAI,CAAC,UAAU,CAAC,GAE3C,SAAS,EACT;YACE,oBAAoB,EAAE,IAAI,CAAC,SAAS;YACpC,wBAAwB,EAAE,CAAC,OAAO,EAAE,EAAE;gBACpC,OAAO,CAAC,MAAM,GAAG;oBACf,EAAE,EAAE,IAAI,CAAC,EAAE;oBACX,IAAI,EAAE,IAAI,CAAC,IAAI;iBAChB,CAAC;gBAEF,OAAO,OAAO,CAAC;YACjB,CAAC;SACF,CACF,CAAC;IACJ,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF;AAhKD,6BAgKC;AAED,SAAS,uBAAuB,CAC9B,IAA6B,EAC7B,2BAAqF;IAErF,OAAO,CACL,CAAA,2BAA2B,aAA3B,2BAA2B,uBAA3B,2BAA2B,CAAG,IAAI,CAAC;QACnC,CAAC,IAAI,CAAC,IAAI,KAAK,8BAAiB,CAAC,WAAW,IAAK,IAAI,CAAC,OAA4B,CAAC,IAAI,KAAK,YAAY,CAAC,CAC1G,CAAC;AACJ,CAAC","sourcesContent":["import { type TransportItem, TransportItemType, type Transports } from '../../transports';\nimport { dateNow, genShortID, monoNow, Observable, stringifyObjectValues } from '../../utils';\nimport type { EventsAPI } from '../events/types';\nimport { ItemBuffer } from '../ItemBuffer';\nimport { type MeasurementEvent } from '../measurements/types';\nimport { type APIEvent } from '../types';\n\nimport { userActionEventName, UserActionImportance, type UserActionImportanceType } from './const';\nimport { type UserActionInternalInterface, UserActionState, type UserActionTransportItemBuffer } from './types';\n\nexport default class UserAction\n extends Observable\n implements UserActionInternalInterface, UserActionTransportItemBuffer\n{\n name: string;\n id: string;\n attributes?: Record<string, string>;\n parentId: string;\n trigger: string;\n importance: UserActionImportanceType;\n startTime?: number;\n // Monotonic counterpart to `startTime`, used to compute `duration` immune to wall-clock\n // adjustments (NTP step, manual clock change, DST). Not exposed in telemetry — see `end()`.\n private _startTimeMono?: number;\n trackUserActionsExcludeItem?: (item: TransportItem<APIEvent>) => boolean;\n\n private _state: UserActionState;\n private _itemBuffer: ItemBuffer<TransportItem>;\n private _transports: Transports;\n private _pushEvent: EventsAPI['pushEvent'];\n\n constructor({\n name,\n parentId,\n trigger,\n transports,\n attributes,\n trackUserActionsExcludeItem,\n importance = UserActionImportance.Normal,\n pushEvent,\n }: {\n name: string;\n transports: Transports;\n parentId?: string;\n trigger: string;\n attributes?: Record<string, string>;\n trackUserActionsExcludeItem?: (item: TransportItem<APIEvent>) => boolean;\n importance?: UserActionImportanceType;\n pushEvent: EventsAPI['pushEvent'];\n }) {\n super();\n this.name = name;\n this.attributes = attributes;\n this.id = genShortID();\n this.trigger = trigger;\n this.parentId = parentId ?? this.id;\n this.trackUserActionsExcludeItem = trackUserActionsExcludeItem;\n this.importance = importance;\n this._pushEvent = pushEvent;\n\n this._itemBuffer = new ItemBuffer<TransportItem>();\n this._transports = transports;\n this._state = UserActionState.Started;\n this._start();\n }\n\n addItem(item: TransportItem): boolean {\n if (this._state === UserActionState.Started) {\n this._itemBuffer.addItem(item);\n return true;\n }\n return false;\n }\n\n private _start(): void {\n this._state = UserActionState.Started;\n if (this._state === UserActionState.Started) {\n // `startTime` is wall-clock (Unix-epoch ms) so it can be used as the event's\n // `timestampOverwriteMs` and emitted as `userActionStartTime` for consumers that\n // correlate with other systems. `_startTimeMono` is the monotonic anchor used\n // for the duration calculation in `end()`.\n this.startTime = dateNow();\n this._startTimeMono = monoNow();\n }\n }\n\n halt() {\n if (this._state !== UserActionState.Started) {\n return;\n }\n this._state = UserActionState.Halted;\n this.notify(this._state);\n }\n\n cancel() {\n if (this._state === UserActionState.Started) {\n // Empty the buffer\n this._itemBuffer.flushBuffer((item) => {\n this._transports.execute(item);\n });\n }\n\n this._state = UserActionState.Cancelled;\n this.notify(this._state);\n }\n\n end() {\n if (this._state === UserActionState.Cancelled) {\n return;\n }\n\n const endTime = dateNow();\n // Compute duration from the monotonic clock so it is unaffected by wall-clock\n // adjustments during the action. Note: `endTime - startTime` (both wall-clock) may\n // disagree with `duration` if the system clock was adjusted between start and end;\n // `duration` is authoritative.\n const duration = monoNow() - this._startTimeMono!;\n this._state = UserActionState.Ended;\n this._itemBuffer.flushBuffer((item) => {\n if (isExcludeFromUserAction(item, this.trackUserActionsExcludeItem)) {\n this._transports.execute(item);\n return;\n }\n\n const userActionItem = {\n ...item,\n payload: {\n ...item.payload,\n action: {\n parentId: this.id,\n name: this.name,\n },\n },\n } as TransportItem;\n\n this._transports.execute(userActionItem);\n });\n\n this._state = UserActionState.Ended;\n this.notify(this._state);\n\n this._pushEvent(\n userActionEventName,\n {\n userActionName: this.name,\n userActionStartTime: this.startTime!.toString(),\n userActionEndTime: endTime.toString(),\n userActionDuration: duration.toString(),\n userActionTrigger: this.trigger!,\n userActionImportance: this.importance,\n ...stringifyObjectValues(this.attributes),\n },\n undefined,\n {\n timestampOverwriteMs: this.startTime,\n customPayloadTransformer: (payload) => {\n payload.action = {\n id: this.id,\n name: this.name,\n };\n\n return payload;\n },\n }\n );\n }\n\n getState(): UserActionState {\n return this._state;\n }\n}\n\nfunction isExcludeFromUserAction(\n item: TransportItem<APIEvent>,\n trackUserActionsExcludeItem: ((item: TransportItem<APIEvent>) => boolean) | undefined\n) {\n return (\n trackUserActionsExcludeItem?.(item) ||\n (item.type === TransportItemType.MEASUREMENT && (item.payload as MeasurementEvent).type === 'web-vitals')\n );\n}\n"]}
|
package/dist/cjs/index.js
CHANGED
|
@@ -15,7 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.isNumber = exports.isNull = exports.isMapDefined = exports.isMap = exports.isInt = exports.isInstanceOf = exports.isFunction = exports.isEventDefined = exports.isEvent = exports.isErrorEvent = exports.isErrorDefined = exports.isError = exports.isElementDefined = exports.isElement = exports.isDomException = exports.isDomError = exports.isBoolean = exports.isArray = exports.getCurrentTimestamp = exports.genShortID = exports.defaultLogLevel = exports.deepEqual = exports.createPromiseBuffer = exports.clampSamplingRate = exports.allLogLevels = exports.defaultUnpatchedConsole = exports.transportItemTypeToBodyKey = exports.TransportItemType = exports.getTransportBody = exports.BaseTransport = exports.setInternalFaroOnGlobalObject = exports.isInternalFaroOnGlobalObject = exports.internalGlobalObjectKey = exports.getInternalFaroFromGlobalObject = exports.faro = exports.InternalLoggerLevel = exports.defaultInternalLoggerLevel = exports.createInternalLogger = exports.BaseInstrumentation = exports.defaultGlobalObjectKey = exports.defaultBatchingConfig = exports.initializeFaro = exports.globalObject = exports.BaseExtension = exports.userActionsMessageBus = exports.UserActionState = exports.UserActionImportance = exports.defaultErrorArgsSerializer = exports.defaultLogArgsSerializer = exports.defaultExceptionType = void 0;
|
|
18
|
-
exports.unknownString = exports.VERSION = exports.Observable = exports.stringifyObjectValues = exports.stringifyExternalJson = exports.getCircularDependencyReplacer = exports.isEmpty = exports.dateNow = exports.noop = exports.LogLevel = exports.isUndefined = exports.isTypeof = exports.isToString = exports.isThenable = exports.isSyntheticEvent = exports.isSymbol = exports.isString = exports.isRegExp = exports.isPrimitive = exports.isObject = void 0;
|
|
18
|
+
exports.unknownString = exports.VERSION = exports.Observable = exports.stringifyObjectValues = exports.stringifyExternalJson = exports.getCircularDependencyReplacer = exports.isEmpty = exports.monoNow = exports.dateNow = exports.noop = exports.LogLevel = exports.isUndefined = exports.isTypeof = exports.isToString = exports.isThenable = exports.isSyntheticEvent = exports.isSymbol = exports.isString = exports.isRegExp = exports.isPrimitive = exports.isObject = void 0;
|
|
19
19
|
var api_1 = require("./api");
|
|
20
20
|
Object.defineProperty(exports, "defaultExceptionType", { enumerable: true, get: function () { return api_1.defaultExceptionType; } });
|
|
21
21
|
Object.defineProperty(exports, "defaultLogArgsSerializer", { enumerable: true, get: function () { return api_1.defaultLogArgsSerializer; } });
|
|
@@ -91,6 +91,7 @@ Object.defineProperty(exports, "isUndefined", { enumerable: true, get: function
|
|
|
91
91
|
Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function () { return utils_1.LogLevel; } });
|
|
92
92
|
Object.defineProperty(exports, "noop", { enumerable: true, get: function () { return utils_1.noop; } });
|
|
93
93
|
Object.defineProperty(exports, "dateNow", { enumerable: true, get: function () { return utils_1.dateNow; } });
|
|
94
|
+
Object.defineProperty(exports, "monoNow", { enumerable: true, get: function () { return utils_1.monoNow; } });
|
|
94
95
|
Object.defineProperty(exports, "isEmpty", { enumerable: true, get: function () { return utils_1.isEmpty; } });
|
|
95
96
|
Object.defineProperty(exports, "getCircularDependencyReplacer", { enumerable: true, get: function () { return utils_1.getCircularDependencyReplacer; } });
|
|
96
97
|
Object.defineProperty(exports, "stringifyExternalJson", { enumerable: true, get: function () { return utils_1.stringifyExternalJson; } });
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,6BAQe;AAPb,2GAAA,oBAAoB,OAAA;AACpB,+GAAA,wBAAwB,OAAA;AACxB,iHAAA,0BAA0B,OAAA;AAC1B,2GAAA,oBAAoB,OAAA;AAEpB,sGAAA,eAAe,OAAA;AACf,4GAAA,qBAAqB,OAAA;AAmCvB,2CAA6C;AAApC,2GAAA,aAAa,OAAA;AAGtB,+CAA8C;AAArC,4GAA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erializer,\n defaultErrorArgsSerializer,\n UserActionImportance,\n type UserActionImportanceType,\n UserActionState,\n userActionsMessageBus,\n} from './api';\nexport type {\n API,\n APIEvent,\n EventAttributes,\n EventEvent,\n EventsAPI,\n ExceptionEvent,\n ExceptionEventExtended,\n ExceptionStackFrame,\n ExceptionsAPI,\n ExtendedError,\n LogArgsSerializer,\n LogContext,\n LogEvent,\n LogsAPI,\n MeasurementEvent,\n MeasurementsAPI,\n MetaAPI,\n OTELApi,\n PushErrorOptions,\n PushEventOptions,\n PushLogOptions,\n PushMeasurementOptions,\n Stacktrace,\n StacktraceParser,\n TraceContext,\n TraceEvent,\n TracesAPI,\n UserAction,\n UserActionInterface,\n UserActionInternalInterface,\n} from './api';\n\nexport { BaseExtension } from './extensions';\nexport type { Extension } from './extensions';\n\nexport { globalObject } from './globalObject';\nexport type { GlobalObject } from './globalObject';\n\nexport { initializeFaro } from './initialize';\n\nexport { defaultBatchingConfig, defaultGlobalObjectKey } from './config';\nexport type { Config, Patterns } from './config';\n\nexport { BaseInstrumentation } from './instrumentations';\nexport type { Instrumentation, Instrumentations } from './instrumentations';\n\nexport { createInternalLogger, defaultInternalLoggerLevel, InternalLoggerLevel } from './internalLogger';\nexport type { InternalLogger } from './internalLogger';\n\nexport type {\n Meta,\n MetaApp,\n MetaAttributes,\n MetaBrowser,\n MetaDevice,\n MetaGetter,\n MetaItem,\n MetaOS,\n MetaPage,\n Metas,\n MetaSDK,\n MetaSDKIntegration,\n MetaSession,\n MetaUser,\n MetaView,\n MetaOverrides,\n} from './metas';\n\nexport {\n faro,\n getInternalFaroFromGlobalObject,\n internalGlobalObjectKey,\n isInternalFaroOnGlobalObject,\n setInternalFaroOnGlobalObject,\n} from './sdk';\nexport type { Faro } from './sdk';\n\nexport * from './semantic';\n\nexport { BaseTransport, getTransportBody, TransportItemType, transportItemTypeToBodyKey } from './transports';\nexport type {\n BeforeSendHook,\n SendFn,\n Transport,\n TransportBody,\n TransportItem,\n TransportItemPayload,\n Transports,\n} from './transports';\n\nexport { defaultUnpatchedConsole } from './unpatchedConsole';\nexport type { UnpatchedConsole } from './unpatchedConsole';\n\nexport {\n allLogLevels,\n clampSamplingRate,\n createPromiseBuffer,\n deepEqual,\n defaultLogLevel,\n genShortID,\n getCurrentTimestamp,\n isArray,\n isBoolean,\n isDomError,\n isDomException,\n isElement,\n isElementDefined,\n isError,\n isErrorDefined,\n isErrorEvent,\n isEvent,\n isEventDefined,\n isFunction,\n isInstanceOf,\n isInt,\n isMap,\n isMapDefined,\n isNull,\n isNumber,\n isObject,\n isPrimitive,\n isRegExp,\n isString,\n isSymbol,\n isSyntheticEvent,\n isThenable,\n isToString,\n isTypeof,\n isUndefined,\n LogLevel,\n noop,\n dateNow,\n monoNow,\n isEmpty,\n getCircularDependencyReplacer,\n stringifyExternalJson,\n stringifyObjectValues,\n Observable,\n} from './utils';\nexport type {\n BaseObject,\n BaseObjectKey,\n BaseObjectPrimitiveValue,\n BaseObjectValue,\n BufferItem,\n PromiseBuffer,\n PromiseBufferOptions,\n PromiseProducer,\n Subscription,\n} from './utils';\n\nexport { VERSION } from './version';\n\nexport { unknownString } from './consts';\n"]}
|