@grafana/faro-core 1.18.2 → 2.0.0-beta
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 +0 -4
- package/dist/bundle/faro-core.iife.js +1 -1
- package/dist/bundle/types/api/apiTestHelpers.d.ts +2 -0
- package/dist/bundle/types/api/events/initialize.d.ts +4 -6
- package/dist/bundle/types/api/exceptions/initialize.d.ts +4 -6
- package/dist/bundle/types/api/index.d.ts +2 -3
- package/dist/bundle/types/api/initialize.d.ts +1 -3
- package/dist/bundle/types/api/logs/initialize.d.ts +4 -6
- package/dist/bundle/types/api/measurements/initialize.d.ts +4 -6
- package/dist/bundle/types/api/meta/initialize.d.ts +1 -5
- package/dist/bundle/types/api/types.d.ts +3 -44
- package/dist/bundle/types/api/userActions/const.d.ts +6 -0
- package/dist/bundle/types/api/userActions/index.d.ts +3 -0
- package/dist/bundle/types/api/userActions/initialize.d.ts +10 -0
- package/dist/bundle/types/api/userActions/types.d.ts +45 -0
- package/dist/bundle/types/api/userActions/userAction.d.ts +41 -0
- package/dist/bundle/types/index.d.ts +2 -2
- package/dist/bundle/types/semantic.d.ts +0 -14
- package/dist/bundle/types/testUtils/mockTransport.d.ts +1 -1
- package/dist/bundle/types/version.d.ts +1 -1
- package/dist/cjs/api/apiTestHelpers.js +5 -1
- package/dist/cjs/api/apiTestHelpers.js.map +1 -1
- package/dist/cjs/api/events/initialize.js +4 -5
- package/dist/cjs/api/events/initialize.js.map +1 -1
- package/dist/cjs/api/exceptions/initialize.js +6 -7
- package/dist/cjs/api/exceptions/initialize.js.map +1 -1
- package/dist/cjs/api/index.js +5 -8
- package/dist/cjs/api/index.js.map +1 -1
- package/dist/cjs/api/initialize.js +8 -8
- package/dist/cjs/api/initialize.js.map +1 -1
- package/dist/cjs/api/logs/initialize.js +6 -7
- package/dist/cjs/api/logs/initialize.js.map +1 -1
- package/dist/cjs/api/measurements/initialize.js +4 -5
- package/dist/cjs/api/measurements/initialize.js.map +1 -1
- package/dist/cjs/api/meta/initialize.js.map +1 -1
- package/dist/cjs/api/types.js.map +1 -1
- package/dist/cjs/api/userActions/const.js +11 -0
- package/dist/cjs/api/userActions/const.js.map +1 -0
- package/dist/cjs/api/userActions/index.js +11 -0
- package/dist/cjs/api/userActions/index.js.map +1 -0
- package/dist/cjs/api/userActions/initialize.js +57 -0
- package/dist/cjs/api/userActions/initialize.js.map +1 -0
- package/dist/cjs/api/userActions/types.js +11 -0
- package/dist/cjs/api/userActions/types.js.map +1 -0
- package/dist/cjs/api/userActions/userAction.js +165 -0
- package/dist/cjs/api/userActions/userAction.js.map +1 -0
- package/dist/cjs/index.js +5 -7
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/instrumentations/initialize.js +1 -1
- package/dist/cjs/instrumentations/initialize.js.map +1 -1
- package/dist/cjs/semantic.js +1 -15
- package/dist/cjs/semantic.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/api/apiTestHelpers.js +4 -0
- package/dist/esm/api/apiTestHelpers.js.map +1 -1
- package/dist/esm/api/events/initialize.js +4 -5
- package/dist/esm/api/events/initialize.js.map +1 -1
- package/dist/esm/api/exceptions/initialize.js +4 -5
- package/dist/esm/api/exceptions/initialize.js.map +1 -1
- package/dist/esm/api/index.js +1 -2
- package/dist/esm/api/index.js.map +1 -1
- package/dist/esm/api/initialize.js +8 -7
- package/dist/esm/api/initialize.js.map +1 -1
- package/dist/esm/api/logs/initialize.js +4 -5
- package/dist/esm/api/logs/initialize.js.map +1 -1
- package/dist/esm/api/measurements/initialize.js +4 -5
- package/dist/esm/api/measurements/initialize.js.map +1 -1
- package/dist/esm/api/meta/initialize.js.map +1 -1
- package/dist/esm/api/types.js.map +1 -1
- package/dist/esm/api/userActions/const.js +8 -0
- package/dist/esm/api/userActions/const.js.map +1 -0
- package/dist/esm/api/userActions/index.js +4 -0
- package/dist/esm/api/userActions/index.js.map +1 -0
- package/dist/esm/api/userActions/initialize.js +50 -0
- package/dist/esm/api/userActions/initialize.js.map +1 -0
- package/dist/esm/api/userActions/types.js +10 -0
- package/dist/esm/api/userActions/types.js.map +1 -0
- package/dist/esm/api/userActions/userAction.js +132 -0
- package/dist/esm/api/userActions/userAction.js.map +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/instrumentations/initialize.js +1 -1
- package/dist/esm/instrumentations/initialize.js.map +1 -1
- package/dist/esm/semantic.js +0 -14
- package/dist/esm/semantic.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/spec/core/src/api/apiTestHelpers.js +5 -1
- package/dist/spec/core/src/api/apiTestHelpers.js.map +1 -1
- package/dist/spec/core/src/api/events/initialize.js +4 -5
- package/dist/spec/core/src/api/events/initialize.js.map +1 -1
- package/dist/spec/core/src/api/events/initialize.test.js +11 -33
- package/dist/spec/core/src/api/events/initialize.test.js.map +1 -1
- package/dist/spec/core/src/api/exceptions/initialize.js +6 -7
- package/dist/spec/core/src/api/exceptions/initialize.js.map +1 -1
- package/dist/spec/core/src/api/exceptions/initialize.test.js +24 -52
- package/dist/spec/core/src/api/exceptions/initialize.test.js.map +1 -1
- package/dist/spec/core/src/api/index.js +5 -8
- package/dist/spec/core/src/api/index.js.map +1 -1
- package/dist/spec/core/src/api/initialize.js +8 -8
- package/dist/spec/core/src/api/initialize.js.map +1 -1
- package/dist/spec/core/src/api/initialize.test.js +0 -50
- package/dist/spec/core/src/api/initialize.test.js.map +1 -1
- package/dist/spec/core/src/api/logs/initialize.js +6 -7
- package/dist/spec/core/src/api/logs/initialize.js.map +1 -1
- package/dist/spec/core/src/api/logs/initialize.test.js +12 -73
- package/dist/spec/core/src/api/logs/initialize.test.js.map +1 -1
- package/dist/spec/core/src/api/measurements/initialize.js +4 -5
- package/dist/spec/core/src/api/measurements/initialize.js.map +1 -1
- package/dist/spec/core/src/api/measurements/initialize.test.js +10 -72
- package/dist/spec/core/src/api/measurements/initialize.test.js.map +1 -1
- package/dist/spec/core/src/api/meta/initialize.js.map +1 -1
- package/dist/spec/core/src/api/types.js.map +1 -1
- package/dist/spec/core/src/api/userActions/const.js +11 -0
- package/dist/spec/core/src/api/userActions/const.js.map +1 -0
- package/dist/spec/core/src/api/userActions/index.js +11 -0
- package/dist/spec/core/src/api/userActions/index.js.map +1 -0
- package/dist/spec/core/src/api/userActions/initialize.js +57 -0
- package/dist/spec/core/src/api/userActions/initialize.js.map +1 -0
- package/dist/spec/core/src/api/userActions/initialize.test.js +62 -0
- package/dist/spec/core/src/api/userActions/initialize.test.js.map +1 -0
- package/dist/spec/core/src/api/userActions/types.js +11 -0
- package/dist/spec/core/src/api/userActions/types.js.map +1 -0
- package/dist/spec/core/src/api/userActions/userAction.js +165 -0
- package/dist/spec/core/src/api/userActions/userAction.js.map +1 -0
- package/dist/spec/core/src/api/userActions/userAction.test.js +75 -0
- package/dist/spec/core/src/api/userActions/userAction.test.js.map +1 -0
- package/dist/spec/core/src/index.js +5 -7
- package/dist/spec/core/src/index.js.map +1 -1
- package/dist/spec/core/src/instrumentations/initialize.js +1 -1
- package/dist/spec/core/src/instrumentations/initialize.js.map +1 -1
- package/dist/spec/core/src/semantic.js +1 -15
- package/dist/spec/core/src/semantic.js.map +1 -1
- package/dist/spec/core/src/transports/batchExecutor.test.js +10 -10
- package/dist/spec/core/src/transports/batchExecutor.test.js.map +1 -1
- package/dist/spec/core/src/version.js +1 -1
- package/dist/spec/core/src/version.js.map +1 -1
- package/dist/types/api/apiTestHelpers.d.ts +2 -0
- package/dist/types/api/events/initialize.d.ts +4 -6
- package/dist/types/api/exceptions/initialize.d.ts +4 -6
- package/dist/types/api/index.d.ts +2 -3
- package/dist/types/api/initialize.d.ts +1 -3
- package/dist/types/api/logs/initialize.d.ts +4 -6
- package/dist/types/api/measurements/initialize.d.ts +4 -6
- package/dist/types/api/meta/initialize.d.ts +1 -5
- package/dist/types/api/types.d.ts +3 -44
- package/dist/types/api/userActions/const.d.ts +6 -0
- package/dist/types/api/userActions/index.d.ts +3 -0
- package/dist/types/api/userActions/initialize.d.ts +10 -0
- package/dist/types/api/userActions/types.d.ts +45 -0
- package/dist/types/api/userActions/userAction.d.ts +41 -0
- package/dist/types/core/src/api/apiTestHelpers.d.ts +2 -0
- package/dist/types/core/src/api/events/initialize.d.ts +4 -6
- package/dist/types/core/src/api/exceptions/initialize.d.ts +4 -6
- package/dist/types/core/src/api/index.d.ts +2 -3
- package/dist/types/core/src/api/initialize.d.ts +1 -3
- package/dist/types/core/src/api/logs/initialize.d.ts +4 -6
- package/dist/types/core/src/api/measurements/initialize.d.ts +4 -6
- package/dist/types/core/src/api/meta/initialize.d.ts +1 -5
- package/dist/types/core/src/api/types.d.ts +3 -44
- package/dist/types/core/src/api/userActions/const.d.ts +6 -0
- package/dist/types/core/src/api/userActions/index.d.ts +3 -0
- package/dist/types/core/src/api/userActions/initialize.d.ts +10 -0
- package/dist/types/core/src/api/userActions/types.d.ts +45 -0
- package/dist/types/core/src/api/userActions/userAction.d.ts +41 -0
- package/dist/types/core/src/api/userActions/userAction.test.d.ts +1 -0
- package/dist/types/core/src/index.d.ts +2 -2
- package/dist/types/core/src/semantic.d.ts +0 -14
- package/dist/types/core/src/testUtils/mockTransport.d.ts +1 -1
- package/dist/types/core/src/version.d.ts +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/semantic.d.ts +0 -14
- package/dist/types/testUtils/mockTransport.d.ts +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +9 -9
- package/dist/bundle/types/api/const.d.ts +0 -4
- package/dist/bundle/types/api/userActionLifecycleHandler.d.ts +0 -13
- package/dist/cjs/api/const.js +0 -8
- package/dist/cjs/api/const.js.map +0 -1
- package/dist/cjs/api/userActionLifecycleHandler.js +0 -58
- package/dist/cjs/api/userActionLifecycleHandler.js.map +0 -1
- package/dist/esm/api/const.js +0 -5
- package/dist/esm/api/const.js.map +0 -1
- package/dist/esm/api/userActionLifecycleHandler.js +0 -43
- package/dist/esm/api/userActionLifecycleHandler.js.map +0 -1
- package/dist/spec/core/src/api/const.js +0 -8
- package/dist/spec/core/src/api/const.js.map +0 -1
- package/dist/spec/core/src/api/userActionLifecycleHandler.js +0 -58
- package/dist/spec/core/src/api/userActionLifecycleHandler.js.map +0 -1
- package/dist/spec/core/src/api/userActionLifecycleHandler.test.js +0 -169
- package/dist/spec/core/src/api/userActionLifecycleHandler.test.js.map +0 -1
- package/dist/types/api/const.d.ts +0 -4
- package/dist/types/api/userActionLifecycleHandler.d.ts +0 -13
- package/dist/types/core/src/api/const.d.ts +0 -4
- package/dist/types/core/src/api/userActionLifecycleHandler.d.ts +0 -13
- /package/dist/types/core/src/api/{userActionLifecycleHandler.test.d.ts → userActions/initialize.test.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -77,7 +77,6 @@ The `api` property on the Faro instance contains all the necessary methods to pu
|
|
|
77
77
|
|
|
78
78
|
- `pushError` - is a method to push an error/exception to the Faro instance. It accepts a mandatory `message` parameter
|
|
79
79
|
and an optional one where you can set:
|
|
80
|
-
|
|
81
80
|
- `skipDedupe` - a flag for enforcing error push even if the error is identical to the previous one.
|
|
82
81
|
- `stackFrames` - an array of stack frames. Defaults to parsing `error.stack` if present.
|
|
83
82
|
- `type` - the type of exception. Default value: `error.name` or `"error"`.
|
|
@@ -119,7 +118,6 @@ The `api` property on the Faro instance contains all the necessary methods to pu
|
|
|
119
118
|
The second optional parameter is called `domain` and it is a string that's used to group events together.
|
|
120
119
|
|
|
121
120
|
The third optional parameter is an optional `options` object where you can set:
|
|
122
|
-
|
|
123
121
|
- `skipDedupe` - a flag for enforcing event push even if the event is identical to the previous one.
|
|
124
122
|
|
|
125
123
|
```ts
|
|
@@ -136,7 +134,6 @@ The `api` property on the Faro instance contains all the necessary methods to pu
|
|
|
136
134
|
|
|
137
135
|
- `pushLog` - is a method to register a log event. The method accepts a mandatory `args` parameter which is an array of
|
|
138
136
|
arguments that will be stringified and sent to the transports and an optional one where you can set:
|
|
139
|
-
|
|
140
137
|
- `skipDedupe` - a flag for enforcing log push even if the log is identical to the previous one.
|
|
141
138
|
- `logLevel` - the type of message that we register.
|
|
142
139
|
- `context` - a plain object containing primitive values that will be recorded along with the message.
|
|
@@ -159,7 +156,6 @@ The `api` property on the Faro instance contains all the necessary methods to pu
|
|
|
159
156
|
|
|
160
157
|
- `pushMeasurement` - is a method for registering metrics. The method accepts a mandatory `payload` parameter and an
|
|
161
158
|
optional parameter for passing additional options:
|
|
162
|
-
|
|
163
159
|
- `skipDedupe` - a flag for enforcing measurement push even if the measurement is identical to the previous one.
|
|
164
160
|
|
|
165
161
|
```ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var GrafanaFaroCore=function(e){"use strict";function n(e,n){return typeof e===n}function t(e,n){return Object.prototype.toString.call(e)===`[object ${n}]`}function r(e,n){try{return e instanceof n}catch(e){return!1}}const s=e=>n(e,"null"),i=e=>n(e,"string"),a=e=>n(e,"number")&&!isNaN(e)||n(e,"bigint"),o=e=>!s(e)&&n(e,"object"),u=e=>n(e,"function"),l=e=>t(e,"Array"),c="undefined"!=typeof Event,g="undefined"!=typeof Error,d=e=>g&&r(e,Error),p="undefined"!=typeof Element,f="undefined"!=typeof Map;function b(e){return null==e||(l(e)||i(e)?0===e.length:!!o(e)&&0===Object.keys(e).length)}function m(e,t){if(e===t)return!0;if(n(e,"number")&&isNaN(e))return n(t,"number")&&isNaN(t);const r=l(e),s=l(t);if(r!==s)return!1;if(r&&s){const n=e.length;if(n!==t.length)return!1;for(let r=n;0!=r--;)if(!m(e[r],t[r]))return!1;return!0}const i=o(e),a=o(t);if(i!==a)return!1;if(e&&t&&i&&a){const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let e of n)if(!r.includes(e))return!1;for(let r of n)if(!m(e[r],t[r]))return!1;return!0}return!1}function v(){return(new Date).toISOString()}function h(e){return new Date(e).toISOString()}var E;e.LogLevel=void 0,(E=e.LogLevel||(e.LogLevel={})).TRACE="trace",E.DEBUG="debug",E.INFO="info",E.LOG="log",E.WARN="warn",E.ERROR="error";const y=e.LogLevel.LOG,I=[e.LogLevel.TRACE,e.LogLevel.DEBUG,e.LogLevel.INFO,e.LogLevel.LOG,e.LogLevel.WARN,e.LogLevel.ERROR];function O(){}const T="abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ0123456789";const L="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:"undefined"!=typeof self?self:void 0;function S(){const e=new WeakSet;return function(n,t){if(o(t)&&null!==t){if(e.has(t))return null;e.add(t)}return t}}function N(e={}){return JSON.stringify(null!=e?e:{},S())}function j(e={}){const n={};for(const[t,r]of Object.entries(e))n[t]=o(r)&&null!==r?N(r):String(r);return n}class A{constructor(){this.subscribers=[]}subscribe(e){return this.subscribers.push(e),{unsubscribe:()=>this.unsubscribe(e)}}unsubscribe(e){this.subscribers=this.subscribers.filter((n=>n!==e))}notify(e){this.subscribers.forEach((n=>n(e)))}first(){const e=new A,n=n=>{e.notify(n),t.unsubscribe()},t=this.subscribe(n),r=e.unsubscribe.bind(e);return this.withUnsubscribeOverride(e,r,n)}takeWhile(e){const n=new A,t=r=>{e(r)?n.notify(r):n.unsubscribe(t)};this.subscribe(t);const r=n.unsubscribe.bind(n);return this.withUnsubscribeOverride(n,r,t)}filter(e){const n=new A,t=t=>{e(t)&&n.notify(t)};this.subscribe(t);const r=n.unsubscribe.bind(n);return this.withUnsubscribeOverride(n,r,t)}merge(...e){const n=new A,t=[];e.forEach((e=>{const r=e.subscribe((e=>{n.notify(e)}));t.push(r)}));const r=n.unsubscribeAll.bind(n);return n.unsubscribe=()=>{t.forEach((e=>e.unsubscribe())),r()},n}withUnsubscribeOverride(e,n,t){return e.unsubscribe=e=>{n(e),this.unsubscribe(t)},e}unsubscribeAll(){this.subscribers=[]}}class R{constructor(e,n){var t,r;this.signalBuffer=[],this.itemLimit=null!==(t=null==n?void 0:n.itemLimit)&&void 0!==t?t:50,this.sendTimeout=null!==(r=null==n?void 0:n.sendTimeout)&&void 0!==r?r:250,this.paused=(null==n?void 0:n.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 n=new Map;return e.forEach((e=>{const t=JSON.stringify(e.meta);let r=n.get(t);r=void 0===r?[e]:[...r,e],n.set(t,r)})),Array.from(n.values())}flush(){if(this.paused||0===this.signalBuffer.length)return;this.groupItems(this.signalBuffer).forEach(this.sendFn),this.signalBuffer=[]}}var x;e.TransportItemType=void 0,(x=e.TransportItemType||(e.TransportItemType={})).EXCEPTION="exception",x.LOG="log",x.MEASUREMENT="measurement",x.TRACE="trace",x.EVENT="event";const w={[e.TransportItemType.EXCEPTION]:"exceptions",[e.TransportItemType.LOG]:"logs",[e.TransportItemType.MEASUREMENT]:"measurements",[e.TransportItemType.TRACE]:"traces",[e.TransportItemType.EVENT]:"events"};function C(e,n,t,r){var s;n.debug("Initializing transports");const i=[];let a=t.paused,o=[];const u=e=>{let n=e;for(const e of o){const r=n.map(e).filter(Boolean);if(0===r.length)return[];n=_(r,t)}return n},l=e=>{const t=u(e);if(0!==t.length)for(const e of i)n.debug(`Transporting item using ${e.name}\n`,t),e.isBatched()&&e.send(t)};let c;(null===(s=t.batching)||void 0===s?void 0:s.enabled)&&(c=new R(l,{sendTimeout:t.batching.sendTimeout,itemLimit:t.batching.itemLimit,paused:a}));return{add:(...s)=>{n.debug("Adding transports"),s.forEach((s=>{n.debug(`Adding "${s.name}" transport`);i.some((e=>e===s))?n.warn(`Transport ${s.name} is already added`):(s.unpatchedConsole=e,s.internalLogger=n,s.config=t,s.metas=r,i.push(s))}))},addBeforeSendHooks:(...e)=>{n.debug("Adding beforeSendHooks\n",o),e.forEach((e=>{e&&o.push(e)}))},getBeforeSendHooks:()=>[...o],execute:e=>{var r;a||((null===(r=t.batching)||void 0===r?void 0:r.enabled)&&(null==c||c.addItem(e)),(e=>{var r,s;if((null===(r=t.batching)||void 0===r?void 0:r.enabled)&&i.every((e=>e.isBatched())))return;const[a]=u([e]);if(void 0!==a)for(const e of i)n.debug(`Transporting item using ${e.name}\n`,a),e.isBatched()?(null===(s=t.batching)||void 0===s?void 0:s.enabled)||e.send([a]):e.send(a)})(e))},isPaused:()=>a,pause:()=>{n.debug("Pausing transports"),null==c||c.pause(),a=!0},remove:(...e)=>{n.debug("Removing transports"),e.forEach((e=>{n.debug(`Removing "${e.name}" transport`);const t=i.indexOf(e);-1!==t?i.splice(t,1):n.warn(`Transport "${e.name}" is not added`)}))},removeBeforeSendHooks:(...e)=>{o.filter((n=>!e.includes(n)))},get transports(){return[...i]},unpause:()=>{n.debug("Unpausing transports"),null==c||c.start(),a=!1}}}function _(n,t){if(t.preserveOriginalError)for(const t of n)t.type===e.TransportItemType.EXCEPTION&&delete t.payload.originalError;return n}var k;e.InternalLoggerLevel=void 0,(k=e.InternalLoggerLevel||(e.InternalLoggerLevel={}))[k.OFF=0]="OFF",k[k.ERROR=1]="ERROR",k[k.WARN=2]="WARN",k[k.INFO=3]="INFO",k[k.VERBOSE=4]="VERBOSE";const B={debug:O,error:O,info:O,prefix:"Faro",warn:O},M=e.InternalLoggerLevel.ERROR,P=Object.assign({},console);let D=P;function F(e){var n;return D=null!==(n=e.unpatchedConsole)&&void 0!==n?n:D,D}function V(n=P,t=M){const r=B;return t>e.InternalLoggerLevel.OFF&&(r.error=t>=e.InternalLoggerLevel.ERROR?function(...e){n.error(`${r.prefix}\n`,...e)}:O,r.warn=t>=e.InternalLoggerLevel.WARN?function(...e){n.warn(`${r.prefix}\n`,...e)}:O,r.info=t>=e.InternalLoggerLevel.INFO?function(...e){n.info(`${r.prefix}\n`,...e)}:O,r.debug=t>=e.InternalLoggerLevel.VERBOSE?function(...e){n.debug(`${r.prefix}\n`,...e)}:O),r}let U=B;function G(e,n){return U=V(e,n.internalLoggerLevel),U}class ${constructor(){this.unpatchedConsole=P,this.internalLogger=B,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 z(e,n){var t,r;if(void 0===n)return e;if(void 0===e)return{resourceSpans:n};const s=null===(t=e.resourceSpans)||void 0===t?void 0:t[0];if(void 0===s)return e;const i=(null==s?void 0:s.scopeSpans)||[],a=(null===(r=null==n?void 0:n[0])||void 0===r?void 0:r.scopeSpans)||[];return Object.assign(Object.assign({},e),{resourceSpans:[Object.assign(Object.assign({},s),{scopeSpans:[...i,...a]})]})}const K="user-action-start",W="user-action-end",H="user-action-cancel",X="user-action-halt";const J="Error";let q;function Q({internalLogger:n,config:t,metas:r,transports:a,tracesApi:u,actionBuffer:c,getMessage:g}){var p;n.debug("Initializing exceptions API");let f=null;q=null!==(p=t.parseStacktrace)&&void 0!==p?p:q;const E=e=>{n.debug("Changing stacktrace parser"),q=null!=e?e:q},{ignoreErrors:y=[],preserveOriginalError:I}=t;return E(t.parseStacktrace),{changeStacktraceParser:E,getStacktraceParser:()=>q,pushError:(p,{skipDedupe:E,stackFrames:O,type:T,context:L,spanContext:S,timestampOverwriteMs:A,originalError:R}={})=>{if(!function(e,n){const{message:t,name:r,stack:s}=n;return a=e,o=t+" "+r+" "+s,a.some((e=>i(e)?o.includes(e):!!o.match(e)));var a,o}(y,null!=R?R:p))try{const i=j(Object.assign(Object.assign({},function(e){let n=e.cause;d(n)?n=e.cause.toString():null!==n&&(o(e.cause)||l(e.cause))?n=N(e.cause):null!=n&&(n=e.cause.toString());return null==n?{}:{cause:n}}(null!=R?R:p)),null!=L?L:{})),y={meta:r.value,payload:Object.assign(Object.assign({type:T||p.name||J,value:p.message,timestamp:A?h(A):v(),trace:S?{trace_id:S.traceId,span_id:S.spanId}:u.getTraceContext()},b(i)?{}:{context:i}),I?{originalError:R}:{}),type:e.TransportItemType.EXCEPTION};(null==(O=null!=O?O:p.stack?null==q?void 0:q(p).frames:void 0)?void 0:O.length)&&(y.payload.stacktrace={frames:O});const x={type:y.payload.type,value:y.payload.value,stackTrace:y.payload.stacktrace,context:y.payload.context};if(!E&&t.dedupe&&!s(f)&&m(x,f))return void n.debug("Skipping error push because it is the same as the last one\n",y.payload);f=x,n.debug("Pushing exception\n",y);const w=g();w&&w.type===K?c.addItem(y):a.execute(y)}catch(e){n.error("Error pushing event",e)}}}}const Y=e=>e.map((e=>{try{return String(e)}catch(e){return""}})).join(" ");class Z{constructor(){this.buffer=[]}addItem(e){this.buffer.push(e)}flushBuffer(e){if(u(e))for(const n of this.buffer)e(n);this.buffer.length=0}size(){return this.buffer.length}}function ee({apiMessageBus:n,transports:t,config:r}){const s=new Z,i=r.trackUserActionsExcludeItem;let a;n.subscribe((n=>{if(K!==n.type&&X!==n.type){if(n.type===W){const{id:r,name:o}=n;return s.flushBuffer((n=>{if(function(n,t){return(null==t?void 0:t(n))||n.type===e.TransportItemType.MEASUREMENT&&"web-vitals"===n.payload.type}(n,i))return void t.execute(n);const s=Object.assign(Object.assign({},n),{payload:Object.assign(Object.assign({},n.payload),{action:{parentId:r,name:o}})});t.execute(s)})),void(a=void 0)}n.type===H&&(a=void 0,s.flushBuffer((e=>{t.execute(e)})))}else a=n}));return{actionBuffer:s,getMessage:()=>a}}const ne=new A;function te(n,t,r,a,o){t.debug("Initializing API");const{actionBuffer:u,getMessage:l}=ee({apiMessageBus:ne,transports:o,config:r}),c=function(n,t,r,s,i){let a;return t.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,n)=>{t.debug("Initializing OpenTelemetry"),a={trace:e,context:n}},isOTELInitialized:()=>!!a,pushTraces:n=>{try{const r={type:e.TransportItemType.TRACE,payload:n,meta:s.value};t.debug("Pushing trace\n",r),i.execute(r)}catch(e){t.error("Error pushing trace\n",e)}}}}(0,t,0,a,o),g={unpatchedConsole:n,internalLogger:t,config:r,metas:a,transports:o,tracesApi:c,actionBuffer:u,getMessage:l};return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},c),Q(g)),function({internalLogger:e,metas:n}){let t,r,s,a;e.debug("Initializing meta API");const o=e=>{r&&n.remove(r),r={user:e},n.add(r)},u=(e,r)=>{var s;const i=null==r?void 0:r.overrides,a=i?{overrides:Object.assign(Object.assign({},null===(s=null==t?void 0:t.session)||void 0===s?void 0:s.overrides),i)}:{};t&&n.remove(t),t={session:Object.assign(Object.assign({},b(e)?void 0:e),a)},n.add(t)},l=()=>n.value.session,c=()=>n.value.page;return{setUser:o,resetUser:o,setSession:u,resetSession:u,getSession:l,setView:(e,t)=>{var r;if((null==t?void 0:t.overrides)&&u(l(),{overrides:t.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},n.add(s),i&&n.remove(i)},getView:()=>n.value.view,setPage:e=>{var t;const r=i(e)?Object.assign(Object.assign({},null!==(t=null==a?void 0:a.page)&&void 0!==t?t:c()),{id:e}):e;a&&n.remove(a),a={page:r},n.add(a)},getPage:c}}(g)),function({internalLogger:n,config:t,metas:r,transports:i,tracesApi:a,actionBuffer:o,getMessage:u}){var l;n.debug("Initializing logs API");let c=null;const g=null!==(l=t.logArgsSerializer)&&void 0!==l?l:Y;return{pushLog:(l,{context:d,level:p,skipDedupe:f,spanContext:E,timestampOverwriteMs:I}={})=>{try{const O=j(d),T={type:e.TransportItemType.LOG,payload:{message:g(l),level:null!=p?p:y,context:b(O)?void 0:O,timestamp:I?h(I):v(),trace:E?{trace_id:E.traceId,span_id:E.spanId}:a.getTraceContext()},meta:r.value},L={message:T.payload.message,level:T.payload.level,context:T.payload.context};if(!f&&t.dedupe&&!s(c)&&m(L,c))return void n.debug("Skipping log push because it is the same as the last one\n",T.payload);c=L,n.debug("Pushing log\n",T);const S=u();S&&S.type===K?o.addItem(T):i.execute(T)}catch(e){n.error("Error pushing log\n",e)}}}}(g)),function({internalLogger:n,config:t,metas:r,transports:i,tracesApi:a,actionBuffer:o,getMessage:u}){n.debug("Initializing measurements API");let l=null;return{pushMeasurement:(c,{skipDedupe:g,context:d,spanContext:p,timestampOverwriteMs:f}={})=>{try{const E=j(d),y={type:e.TransportItemType.MEASUREMENT,payload:Object.assign(Object.assign({},c),{trace:p?{trace_id:p.traceId,span_id:p.spanId}:a.getTraceContext(),timestamp:f?h(f):v(),context:b(E)?void 0:E}),meta:r.value},I={type:y.payload.type,values:y.payload.values,context:y.payload.context};if(!g&&t.dedupe&&!s(l)&&m(I,l))return void n.debug("Skipping measurement push because it is the same as the last one\n",y.payload);l=I,n.debug("Pushing measurement\n",y);const O=u();O&&O.type===K?o.addItem(y):i.execute(y)}catch(e){n.error("Error pushing measurement\n",e)}}}}(g)),function({internalLogger:n,config:t,metas:r,transports:i,tracesApi:a,actionBuffer:o,getMessage:u}){let l=null;return{pushEvent:(c,g,d,{skipDedupe:p,spanContext:f,timestampOverwriteMs:E,customPayloadTransformer:y=e=>e}={})=>{try{const I=j(g),O={meta:r.value,payload:y({name:c,domain:null!=d?d:t.eventDomain,attributes:b(I)?void 0:I,timestamp:E?h(E):v(),trace:f?{trace_id:f.traceId,span_id:f.spanId}:a.getTraceContext()}),type:e.TransportItemType.EVENT},T={name:O.payload.name,attributes:O.payload.attributes,domain:O.payload.domain};if(!p&&t.dedupe&&!s(l)&&m(T,l))return void n.debug("Skipping event push because it is the same as the last one\n",O.payload);l=T,n.debug("Pushing event\n",O);const L=u();L&&L.type===K?o.addItem(O):i.execute(O)}catch(e){n.error("Error pushing event",e)}}}}(g))}const re="1.18.2";const se="_faroInternal";function ie(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(L,se,{configurable:!1,enumerable:!1,writable:!1,value:e}))}function ae(){return se in L}function oe(n,t,r,s,i,a,o){return t.debug("Initializing Faro"),e.faro={api:a,config:r,instrumentations:o,internalLogger:t,metas:s,pause:i.pause,transports:i,unpatchedConsole:n,unpause:i.unpause},ie(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 L)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(L,e.config.globalObjectKey,{configurable:!1,writable:!1,value:e})}}(e.faro),e.faro}e.faro={};return e.BaseExtension=$,e.BaseInstrumentation=class extends ${constructor(){super(...arguments),this.api={},this.transports={}}},e.BaseTransport=class extends ${isBatched(){return!1}getIgnoreUrls(){return[]}},e.Conventions={EventNames:{CLICK:"click",NAVIGATION:"navigation",SESSION_START:"session_start",VIEW_CHANGED:"view_changed"}},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=A,e.USER_ACTION_CANCEL=H,e.USER_ACTION_END=W,e.USER_ACTION_HALT=X,e.USER_ACTION_START=K,e.VERSION=re,e.allLogLevels=I,e.apiMessageBus=ne,e.createInternalLogger=V,e.createPromiseBuffer=function(e){const{size:n,concurrency:t}=e,r=[];let s=0;const i=()=>{if(s<t&&r.length){const{producer:e,resolve:n,reject:t}=r.shift();s++,e().then((e=>{s--,i(),n(e)}),(e=>{s--,i(),t(e)}))}};return{add:e=>{if(r.length+s>=n)throw new Error("Task buffer full");return new Promise(((n,t)=>{r.push({producer:e,resolve:n,reject:t}),i()}))}}},e.dateNow=function(){return Date.now()},e.deepEqual=m,e.defaultBatchingConfig={enabled:!0,sendTimeout:250,itemLimit:50},e.defaultErrorArgsSerializer=e=>e.map((e=>o(e)?N(e):String(e))).join(" "),e.defaultExceptionType=J,e.defaultGlobalObjectKey="faro",e.defaultInternalLoggerLevel=M,e.defaultLogArgsSerializer=Y,e.defaultLogLevel=y,e.defaultUnpatchedConsole=P,e.genShortID=function(e=10){return Array.from(Array(e)).map((()=>T[Math.floor(59*Math.random())])).join("")},e.getCircularDependencyReplacer=S,e.getCurrentTimestamp=v,e.getInternalFaroFromGlobalObject=function(){return L[se]},e.getTransportBody=function(n){let t={meta:{}};return void 0!==n[0]&&(t.meta=n[0].meta),n.forEach((n=>{switch(n.type){case e.TransportItemType.LOG:case e.TransportItemType.EVENT:case e.TransportItemType.EXCEPTION:case e.TransportItemType.MEASUREMENT:const r=w[n.type],s=t[r];t=Object.assign(Object.assign({},t),{[r]:void 0===s?[n.payload]:[...s,n.payload]});break;case e.TransportItemType.TRACE:t=Object.assign(Object.assign({},t),{traces:z(t.traces,n.payload.resourceSpans)})}})),t},e.globalObject=L,e.initializeFaro=function(e){const n=F(e),t=G(n,e);if(ae()&&!e.isolate)return void t.error('Faro is already registered. Either add instrumentations, transports etc. to the global faro instance or use the "isolate" property');t.debug("Initializing");const r=function(e,n){let t=[],r=[];const s=()=>t.reduce(((e,n)=>Object.assign(e,u(n)?n():n)),{}),i=()=>{if(r.length){const e=s();r.forEach((n=>n(e)))}};return{add:(...e)=>{n.debug("Adding metas\n",e),t.push(...e),i()},remove:(...e)=>{n.debug("Removing metas\n",e),t=t.filter((n=>!e.includes(n))),i()},addListener:e=>{n.debug("Adding metas listener\n",e),r.push(e)},removeListener:e=>{n.debug("Removing metas listener\n",e),r=r.filter((n=>n!==e))},get value(){return s()}}}(0,t),s=C(n,t,e,r),i=te(n,t,e,r,s),a=function(e,n,t,r,s,i){n.debug("Initializing instrumentations");const a=[];return{add:(...o)=>{n.debug("Adding instrumentations"),o.forEach((o=>{n.debug(`Adding "${o.name}" instrumentation`),a.some((e=>e.name===o.name))?n.warn(`Instrumentation ${o.name} is already added`):(o.unpatchedConsole=e,o.internalLogger=n,o.config=t,o.metas=r,o.transports=s,o.api=i,a.push(o),o.initialize())}))},get instrumentations(){return[...a]},remove:(...e)=>{n.debug("Removing instrumentations"),e.forEach((e=>{var t,r;n.debug(`Removing "${e.name}" instrumentation`);const s=a.reduce(((n,t,r)=>null===n&&t.name===e.name?r:null),null);s?(null===(r=(t=a[s]).destroy)||void 0===r||r.call(t),a.splice(s,1)):n.warn(`Instrumentation "${e.name}" is not added`)}))}}}(n,t,e,r,s,i),o=oe(n,t,e,r,s,i,a);return function(e){var n,t;const r={sdk:{version:re},app:{bundleId:e.config.app.name&&(s=e.config.app.name,null==L?void 0:L[`__faroBundleId_${s}`])}};var s;const i=null===(n=e.config.sessionTracking)||void 0===n?void 0:n.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!==(t=e.config.metas)&&void 0!==t?t:[])}(o),function(e){e.transports.add(...e.config.transports),e.transports.addBeforeSendHooks(e.config.beforeSend)}(o),function(e){e.instrumentations.add(...e.config.instrumentations)}(o),o},e.internalGlobalObjectKey=se,e.isArray=l,e.isBoolean=e=>n(e,"boolean"),e.isDomError=e=>t(e,"DOMError"),e.isDomException=e=>t(e,"DOMException"),e.isElement=e=>p&&r(e,Element),e.isElementDefined=p,e.isEmpty=b,e.isError=d,e.isErrorDefined=g,e.isErrorEvent=e=>t(e,"ErrorEvent"),e.isEvent=e=>c&&r(e,Event),e.isEventDefined=c,e.isFunction=u,e.isInstanceOf=r,e.isInt=e=>a(e)&&Number.isInteger(e),e.isInternalFaroOnGlobalObject=ae,e.isMap=e=>f&&r(e,Map),e.isMapDefined=f,e.isNull=s,e.isNumber=a,e.isObject=o,e.isPrimitive=e=>!o(e)&&!u(e),e.isRegExp=e=>t(e,"RegExp"),e.isString=i,e.isSymbol=e=>n(e,"symbol"),e.isSyntheticEvent=e=>o(e)&&"nativeEvent"in e&&"preventDefault"in e&&"stopPropagation"in e,e.isThenable=e=>u(null==e?void 0:e.then),e.isToString=t,e.isTypeof=n,e.isUndefined=e=>n(e,"undefined"),e.noop=O,e.setInternalFaroOnGlobalObject=ie,e.stringifyExternalJson=N,e.stringifyObjectValues=j,e.transportItemTypeToBodyKey=w,e.unknownString="unknown",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 i(e,n,r,i){var a;n.debug("Initializing transports");const o=[];let u=r.paused,c=[];const l=e=>{let t=e;for(const e of c){const n=t.map(e).filter(Boolean);if(0===n.length)return[];t=s(n,r)}return t},d=e=>{const t=l(e);if(0!==t.length)for(const e of o)n.debug(`Transporting item using ${e.name}\n`,t),e.isBatched()&&e.send(t)};let g;(null===(a=r.batching)||void 0===a?void 0:a.enabled)&&(g=new t(d,{sendTimeout:r.batching.sendTimeout,itemLimit:r.batching.itemLimit,paused:u}));return{add:(...t)=>{n.debug("Adding transports"),t.forEach(t=>{n.debug(`Adding "${t.name}" transport`);o.some(e=>e===t)?n.warn(`Transport ${t.name} is already added`):(t.unpatchedConsole=e,t.internalLogger=n,t.config=r,t.metas=i,o.push(t))})},addBeforeSendHooks:(...e)=>{n.debug("Adding beforeSendHooks\n",c),e.forEach(e=>{e&&c.push(e)})},getBeforeSendHooks:()=>[...c],execute:e=>{var t;u||((null===(t=r.batching)||void 0===t?void 0:t.enabled)&&(null==g||g.addItem(e)),(e=>{var t,i;if((null===(t=r.batching)||void 0===t?void 0:t.enabled)&&o.every(e=>e.isBatched()))return;const[s]=l([e]);if(void 0!==s)for(const e of o)n.debug(`Transporting item using ${e.name}\n`,s),e.isBatched()?(null===(i=r.batching)||void 0===i?void 0:i.enabled)||e.send([s]):e.send(s)})(e))},isPaused:()=>u,pause:()=>{n.debug("Pausing transports"),null==g||g.pause(),u=!0},remove:(...e)=>{n.debug("Removing transports"),e.forEach(e=>{n.debug(`Removing "${e.name}" transport`);const t=o.indexOf(e);-1!==t?o.splice(t,1):n.warn(`Transport "${e.name}" is not added`)})},removeBeforeSendHooks:(...e)=>{c.filter(t=>!e.includes(t))},get transports(){return[...o]},unpause:()=>{n.debug("Unpausing transports"),null==g||g.start(),u=!1}}}function s(t,n){if(n.preserveOriginalError)for(const n of t)n.type===e.TransportItemType.EXCEPTION&&delete n.payload.originalError;return t}function a(e,t){return typeof e===t}function o(e,t){return Object.prototype.toString.call(e)===`[object ${t}]`}function u(e,t){try{return e instanceof t}catch(e){return!1}}const c=e=>a(e,"null"),l=e=>a(e,"string"),d=e=>a(e,"number")&&!isNaN(e)||a(e,"bigint"),g=e=>!c(e)&&a(e,"object"),p=e=>a(e,"function"),f=e=>o(e,"Array"),m="undefined"!=typeof Event,h="undefined"!=typeof Error,b=e=>h&&u(e,Error),v="undefined"!=typeof Element,E="undefined"!=typeof Map;function y(e){return null==e||(f(e)||l(e)?0===e.length:!!g(e)&&0===Object.keys(e).length)}function T(e,t){if(e===t)return!0;if(a(e,"number")&&isNaN(e))return a(t,"number")&&isNaN(t);const n=f(e),r=f(t);if(n!==r)return!1;if(n&&r){const n=e.length;if(n!==t.length)return!1;for(let r=n;0!==r--;)if(!T(e[r],t[r]))return!1;return!0}const i=g(e),s=g(t);if(i!==s)return!1;if(e&&t&&i&&s){const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let e of n)if(!r.includes(e))return!1;for(let r of n)if(!T(e[r],t[r]))return!1;return!0}return!1}function I(){return Date.now()}function O(){return(new Date).toISOString()}function A(e){return new Date(e).toISOString()}var S;e.LogLevel=void 0,(S=e.LogLevel||(e.LogLevel={})).TRACE="trace",S.DEBUG="debug",S.INFO="info",S.LOG="log",S.WARN="warn",S.ERROR="error";const L=e.LogLevel.LOG,_=[e.LogLevel.TRACE,e.LogLevel.DEBUG,e.LogLevel.INFO,e.LogLevel.LOG,e.LogLevel.WARN,e.LogLevel.ERROR];function j(){}const x="abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ0123456789";function w(e=10){return Array.from(Array(e)).map(()=>x[Math.floor(59*Math.random())]).join("")}const N="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:j,error:j,info:j,prefix:"Faro",warn:j},F=e.InternalLoggerLevel.ERROR,M=Object.assign({},console);let V=M;function D(e){var t;return V=null!==(t=e.unpatchedConsole)&&void 0!==t?t:V,V}function $(t=M,n=F){const r=P;return n>e.InternalLoggerLevel.OFF&&(r.error=n>=e.InternalLoggerLevel.ERROR?function(...e){t.error(`${r.prefix}\n`,...e)}:j,r.warn=n>=e.InternalLoggerLevel.WARN?function(...e){t.warn(`${r.prefix}\n`,...e)}:j,r.info=n>=e.InternalLoggerLevel.INFO?function(...e){t.info(`${r.prefix}\n`,...e)}:j,r.debug=n>=e.InternalLoggerLevel.VERBOSE?function(...e){t.debug(`${r.prefix}\n`,...e)}:j),r}let G=P;function z(e,t){return G=$(e,t.internalLoggerLevel),G}class H{constructor(){this.unpatchedConsole=M,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="Error";let X;function J({internalLogger:t,config:n,metas:r,transports:i,tracesApi:s,userActionsApi:a}){var o;t.debug("Initializing exceptions API");let u=null;X=null!==(o=n.parseStacktrace)&&void 0!==o?o:X;const d=e=>{t.debug("Changing stacktrace parser"),X=null!=e?e:X},{ignoreErrors:p=[],preserveOriginalError:m}=n;return d(n.parseStacktrace),{changeStacktraceParser:d,getStacktraceParser:()=>X,pushError:(o,{skipDedupe:d,stackFrames:h,type:v,context:E,spanContext:I,timestampOverwriteMs:S,originalError:L}={})=>{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;b(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({type:v||o.name||W,value:o.message,timestamp:S?A(S):O(),trace:I?{trace_id:I.traceId,span_id:I.spanId}:s.getTraceContext()},y(l)?{}:{context:l}),m?{originalError:L}:{}),type:e.TransportItemType.EXCEPTION};(null==(h=null!=h?h:o.stack?null==X?void 0:X(o).frames:void 0)?void 0:h.length)&&(p.payload.stacktrace={frames:h});const _={type:p.payload.type,value:p.payload.value,stackTrace:p.payload.stacktrace,context:p.payload.context};if(!d&&n.dedupe&&!c(u)&&T(_,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);const j=a.getActiveUserAction();j?j.addItem(p):i.execute(p)}catch(e){t.error("Error pushing event",e)}}}}const q=e=>e.map(e=>{try{return String(e)}catch(e){return""}}).join(" ");var Q,Y;e.UserActionSeverity=void 0,(Q=e.UserActionSeverity||(e.UserActionSeverity={})).Normal="normal",Q.Critical="critical",e.UserActionState=void 0,(Y=e.UserActionState||(e.UserActionState={}))[Y.Started=0]="Started",Y[Y.Halted=1]="Halted",Y[Y.Cancelled=2]="Cancelled",Y[Y.Ended=3]="Ended";const Z="_faroInternal";function ee(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(N,Z,{configurable:!1,enumerable:!1,writable:!1,value:e}))}function te(){return Z in N}function ne(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},ee(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 N)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(N,e.config.globalObjectKey,{configurable:!1,writable:!1,value:e})}}(e.faro),e.faro}e.faro={};class re{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 ie extends C{constructor({name:t,parentId:n,haltTimeout:r,trigger:i,transports:s,attributes:a,trackUserActionsExcludeItem:o,severity:u=e.UserActionSeverity.Normal}){super(),this.name=t,this.attributes=a,this.id=w(),this.trigger=i,this.cancelTimeout=100,this.haltTimeout=null!=r?r:1e4,this.parentId=null!=n?n:this.id,this.trackUserActionsExcludeItem=o,this.severity=u,this._itemBuffer=new re,this._transports=s,this._haltTimeoutId=-1,this._state=e.UserActionState.Started,this._isValid=!1,this._start()}addItem(e){this._itemBuffer.addItem(e)}extend(e){this._isValid||(this._isValid=!0),this._setFollowupActionTimeout(e)}_setFollowupActionTimeout(t){this._timeoutId=function(e,t,n){e&&clearTimeout(e);return e=setTimeout(()=>{t()},n)}(this._timeoutId,()=>{this._state===e.UserActionState.Started&&(null==t?void 0:t())?this.halt():this._isValid?this.end():this.cancel()},100)}_start(){this._state=e.UserActionState.Started,this._state===e.UserActionState.Started&&(this.startTime=I()),this._setFollowupActionTimeout()}halt(){this._state===e.UserActionState.Started&&(this._state=e.UserActionState.Halted,this._haltTimeoutId=setTimeout(()=>{this.end()},this.haltTimeout),this.notify(this._state))}cancel(){this._state===e.UserActionState.Started&&this._itemBuffer.flushBuffer(),this._state=e.UserActionState.Cancelled,this.notify(this._state)}end(){if(this._state===e.UserActionState.Cancelled)return;clearTimeout(this._haltTimeoutId),clearTimeout(this._timeoutId);const t=I(),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),e.faro.api.pushEvent(this.name,Object.assign({userActionStartTime:this.startTime.toString(),userActionEndTime:t.toString(),userActionDuration:n.toString(),userActionTrigger:this.trigger,userActionSeverity:this.severity},k(this.attributes)),void 0,{timestampOverwriteMs:this.startTime,customPayloadTransformer:e=>(e.action={id:this.id,name:this.name},e)})}getState(){return this._state}}const se=new C;function ae(t,n,r,i,s){n.debug("Initializing API");const a=function({transports:t,internalLogger:n,config:r}){const i=r.trackUserActionsExcludeItem;let s;const a=()=>s;return{startUserAction:(r,o,u)=>{if(void 0===a()){const n=new ie({name:r,transports:t,attributes:o,trigger:(null==u?void 0:u.triggerName)||"faroApiCall",trackUserActionsExcludeItem:i});return n.filter(t=>[e.UserActionState.Ended,e.UserActionState.Cancelled].includes(t)).first().subscribe(()=>{s=void 0}),se.notify({type:"user_action_start",userAction:n}),s=n,s}n.error("Attempted to create a new user action while one is already running. This is not possible.")},getActiveUserAction:a}}({transports:s,config:r,internalLogger:n}),o=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),u={internalLogger:n,userActionsApi:a,config:r,metas:i,transports:s,tracesApi:o};return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},o),J(u)),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}}(u)),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:q;return{pushLog:(o,{context:d,level:g,skipDedupe:p,spanContext:f,timestampOverwriteMs:m}={})=>{try{const h=k(d),b={type:e.TransportItemType.LOG,payload:{message:l(o),level:null!=g?g:L,context:y(h)?void 0:h,timestamp:m?A(m):O(),trace:f?{trace_id:f.traceId,span_id:f.spanId}:s.getTraceContext()},meta:r.value},v={message:b.payload.message,level:b.payload.level,context:b.payload.context};if(!p&&n.dedupe&&!c(u)&&T(v,u))return void t.debug("Skipping log push because it is the same as the last one\n",b.payload);u=v,t.debug("Pushing log\n",b);const E=a.getActiveUserAction();E?E.addItem(b):i.execute(b)}catch(e){t.error("Error pushing log\n",e)}}}}(u)),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?A(p):O(),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);const b=a.getActiveUserAction();b?b.addItem(m):i.execute(m)}catch(e){t.error("Error pushing measurement\n",e)}}}}(u)),function({internalLogger:t,config:n,metas:r,transports:i,tracesApi:s,userActionsApi:a}){let o=null;return{pushEvent:(u,l,d,{skipDedupe:g,spanContext:p,timestampOverwriteMs:f,customPayloadTransformer:m=e=>e}={})=>{try{const h=k(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):O(),trace:p?{trace_id:p.traceId,span_id:p.spanId}:s.getTraceContext()}),type:e.TransportItemType.EVENT},v={name:b.payload.name,attributes:b.payload.attributes,domain:b.payload.domain};if(!g&&n.dedupe&&!c(o)&&T(v,o))return void t.debug("Skipping event push because it is the same as the last one\n",b.payload);o=v,t.debug("Pushing event\n",b);const E=a.getActiveUserAction();E?E.addItem(b):i.execute(b)}catch(e){t.error("Error pushing event",e)}}}}(u)),a)}const oe="2.0.0-beta";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.VERSION=oe,e.allLogLevels=_,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=I,e.deepEqual=T,e.defaultBatchingConfig={enabled:!0,sendTimeout:250,itemLimit:50},e.defaultErrorArgsSerializer=e=>e.map(e=>g(e)?U(e):String(e)).join(" "),e.defaultExceptionType=W,e.defaultGlobalObjectKey="faro",e.defaultInternalLoggerLevel=F,e.defaultLogArgsSerializer=q,e.defaultLogLevel=L,e.defaultUnpatchedConsole=M,e.genShortID=w,e.getCircularDependencyReplacer=R,e.getCurrentTimestamp=O,e.getInternalFaroFromGlobalObject=function(){return N[Z]},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 i=r[t.type],s=n[i];n=Object.assign(Object.assign({},n),{[i]:void 0===s?[t.payload]:[...s,t.payload]});break;case e.TransportItemType.TRACE:n=Object.assign(Object.assign({},n),{traces:K(n.traces,t.payload.resourceSpans)})}}),n},e.globalObject=N,e.initializeFaro=function(e){const t=D(e),n=z(t,e);if(te()&&!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=ae(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=ne(t,n,e,r,s,a,o);return function(e){var t,n;const r={sdk:{version:oe},app:{bundleId:e.config.app.name&&(i=e.config.app.name,null==N?void 0:N[`__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=Z,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=te,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=j,e.setInternalFaroOnGlobalObject=ee,e.stringifyExternalJson=U,e.stringifyObjectValues=k,e.transportItemTypeToBodyKey=r,e.unknownString="unknown",e.userActionsMessageBus=se,e}({});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Transports } from '../transports';
|
|
2
2
|
import type { TracesAPI } from './traces/types';
|
|
3
|
+
import type { UserActionsAPI } from './userActions/types';
|
|
3
4
|
export declare const mockMetas: {
|
|
4
5
|
add: jest.Mock<any, any, any>;
|
|
5
6
|
remove: jest.Mock<any, any, any>;
|
|
@@ -9,3 +10,4 @@ export declare const mockMetas: {
|
|
|
9
10
|
};
|
|
10
11
|
export declare const mockTransports: Transports;
|
|
11
12
|
export declare const mockTracesApi: TracesAPI;
|
|
13
|
+
export declare const mockUserActionsApi: UserActionsAPI;
|
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
import type { Config } from '../../config';
|
|
2
2
|
import type { InternalLogger } from '../../internalLogger';
|
|
3
3
|
import type { Metas } from '../../metas';
|
|
4
|
-
import type {
|
|
4
|
+
import type { Transports } from '../../transports';
|
|
5
5
|
import type { UnpatchedConsole } from '../../unpatchedConsole';
|
|
6
|
-
import type { ItemBuffer } from '../ItemBuffer';
|
|
7
6
|
import type { TracesAPI } from '../traces';
|
|
8
|
-
import type {
|
|
7
|
+
import type { UserActionsAPI } from '../userActions';
|
|
9
8
|
import type { EventsAPI } from './types';
|
|
10
|
-
export declare function initializeEventsAPI({ internalLogger, config, metas, transports, tracesApi,
|
|
9
|
+
export declare function initializeEventsAPI({ internalLogger, config, metas, transports, tracesApi, userActionsApi, }: {
|
|
11
10
|
unpatchedConsole: UnpatchedConsole;
|
|
12
11
|
internalLogger: InternalLogger;
|
|
13
12
|
config: Config;
|
|
14
13
|
metas: Metas;
|
|
15
14
|
transports: Transports;
|
|
16
15
|
tracesApi: TracesAPI;
|
|
17
|
-
|
|
18
|
-
getMessage: () => ApiMessageBusMessages | undefined;
|
|
16
|
+
userActionsApi: UserActionsAPI;
|
|
19
17
|
}): EventsAPI;
|
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
import type { Config } from '../../config';
|
|
2
2
|
import type { InternalLogger } from '../../internalLogger';
|
|
3
3
|
import type { Metas } from '../../metas';
|
|
4
|
-
import type {
|
|
4
|
+
import type { Transports } from '../../transports';
|
|
5
5
|
import type { UnpatchedConsole } from '../../unpatchedConsole';
|
|
6
|
-
import type { ItemBuffer } from '../ItemBuffer';
|
|
7
6
|
import type { TracesAPI } from '../traces';
|
|
8
|
-
import type {
|
|
7
|
+
import type { UserActionsAPI } from '../userActions';
|
|
9
8
|
import type { ExceptionsAPI } from './types';
|
|
10
|
-
export declare function initializeExceptionsAPI({ internalLogger, config, metas, transports, tracesApi,
|
|
9
|
+
export declare function initializeExceptionsAPI({ internalLogger, config, metas, transports, tracesApi, userActionsApi, }: {
|
|
11
10
|
unpatchedConsole: UnpatchedConsole;
|
|
12
11
|
internalLogger: InternalLogger;
|
|
13
12
|
config: Config;
|
|
14
13
|
metas: Metas;
|
|
15
14
|
transports: Transports;
|
|
16
15
|
tracesApi: TracesAPI;
|
|
17
|
-
|
|
18
|
-
getMessage: () => ApiMessageBusMessages | undefined;
|
|
16
|
+
userActionsApi: UserActionsAPI;
|
|
19
17
|
}): ExceptionsAPI;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { initializeAPI } from './initialize';
|
|
2
|
-
export type { API, APIEvent,
|
|
2
|
+
export type { API, APIEvent, UserAction } from './types';
|
|
3
3
|
export type { EventAttributes, EventEvent, EventsAPI, PushEventOptions } from './events';
|
|
4
4
|
export { defaultExceptionType, defaultErrorArgsSerializer } from './exceptions';
|
|
5
5
|
export type { ExceptionEvent, ExceptionStackFrame, ExceptionsAPI, ExtendedError, PushErrorOptions, Stacktrace, StacktraceParser, ExceptionEventExtended, } from './exceptions';
|
|
@@ -7,6 +7,5 @@ export { defaultLogArgsSerializer } from './logs';
|
|
|
7
7
|
export type { LogContext, LogEvent, LogArgsSerializer, LogsAPI, PushLogOptions } from './logs';
|
|
8
8
|
export type { MeasurementEvent, MeasurementsAPI, PushMeasurementOptions } from './measurements';
|
|
9
9
|
export type { MetaAPI } from './meta';
|
|
10
|
+
export { UserActionSeverity, UserActionState, type UserActionInterface, type UserActionsAPI, userActionsMessageBus, } from './userActions';
|
|
10
11
|
export type { OTELApi, TraceContext, TraceEvent, TracesAPI } from './traces';
|
|
11
|
-
export { apiMessageBus } from './initialize';
|
|
12
|
-
export { USER_ACTION_CANCEL, USER_ACTION_END, USER_ACTION_START, USER_ACTION_HALT } from './const';
|
|
@@ -3,7 +3,5 @@ import type { InternalLogger } from '../internalLogger';
|
|
|
3
3
|
import type { Metas } from '../metas';
|
|
4
4
|
import type { Transports } from '../transports';
|
|
5
5
|
import type { UnpatchedConsole } from '../unpatchedConsole';
|
|
6
|
-
import {
|
|
7
|
-
import type { API, ApiMessageBusMessages } from './types';
|
|
8
|
-
export declare const apiMessageBus: Observable<ApiMessageBusMessages>;
|
|
6
|
+
import type { API } from './types';
|
|
9
7
|
export declare function initializeAPI(unpatchedConsole: UnpatchedConsole, internalLogger: InternalLogger, config: Config, metas: Metas, transports: Transports): API;
|
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
import type { Config } from '../../config';
|
|
2
2
|
import type { InternalLogger } from '../../internalLogger';
|
|
3
3
|
import type { Metas } from '../../metas';
|
|
4
|
-
import type {
|
|
4
|
+
import type { Transports } from '../../transports';
|
|
5
5
|
import type { UnpatchedConsole } from '../../unpatchedConsole';
|
|
6
|
-
import type { ItemBuffer } from '../ItemBuffer';
|
|
7
6
|
import type { TracesAPI } from '../traces';
|
|
8
|
-
import type {
|
|
7
|
+
import type { UserActionsAPI } from '../userActions';
|
|
9
8
|
import type { LogsAPI } from './types';
|
|
10
|
-
export declare function initializeLogsAPI({ internalLogger, config, metas, transports, tracesApi,
|
|
9
|
+
export declare function initializeLogsAPI({ internalLogger, config, metas, transports, tracesApi, userActionsApi, }: {
|
|
11
10
|
unpatchedConsole: UnpatchedConsole;
|
|
12
11
|
internalLogger: InternalLogger;
|
|
13
12
|
config: Config;
|
|
14
13
|
metas: Metas;
|
|
15
14
|
transports: Transports;
|
|
16
15
|
tracesApi: TracesAPI;
|
|
17
|
-
|
|
18
|
-
getMessage: () => ApiMessageBusMessages | undefined;
|
|
16
|
+
userActionsApi: UserActionsAPI;
|
|
19
17
|
}): LogsAPI;
|
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
import type { Config } from '../../config';
|
|
2
2
|
import type { InternalLogger } from '../../internalLogger';
|
|
3
3
|
import type { Metas } from '../../metas';
|
|
4
|
-
import type {
|
|
4
|
+
import type { Transports } from '../../transports';
|
|
5
5
|
import type { UnpatchedConsole } from '../../unpatchedConsole';
|
|
6
|
-
import type { ItemBuffer } from '../ItemBuffer';
|
|
7
6
|
import type { TracesAPI } from '../traces';
|
|
8
|
-
import type {
|
|
7
|
+
import type { UserActionsAPI } from '../userActions';
|
|
9
8
|
import type { MeasurementsAPI } from './types';
|
|
10
|
-
export declare function initializeMeasurementsAPI({ internalLogger, config, metas, transports, tracesApi,
|
|
9
|
+
export declare function initializeMeasurementsAPI({ internalLogger, config, metas, transports, tracesApi, userActionsApi, }: {
|
|
11
10
|
unpatchedConsole: UnpatchedConsole;
|
|
12
11
|
internalLogger: InternalLogger;
|
|
13
12
|
config: Config;
|
|
14
13
|
metas: Metas;
|
|
15
14
|
transports: Transports;
|
|
16
15
|
tracesApi: TracesAPI;
|
|
17
|
-
|
|
18
|
-
getMessage: () => ApiMessageBusMessages | undefined;
|
|
16
|
+
userActionsApi: UserActionsAPI;
|
|
19
17
|
}): MeasurementsAPI;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import type { Config } from '../../config';
|
|
2
2
|
import type { InternalLogger } from '../../internalLogger';
|
|
3
3
|
import type { Metas } from '../../metas';
|
|
4
|
-
import type {
|
|
4
|
+
import type { Transports } from '../../transports';
|
|
5
5
|
import type { UnpatchedConsole } from '../../unpatchedConsole';
|
|
6
|
-
import type { ItemBuffer } from '../ItemBuffer';
|
|
7
6
|
import type { TracesAPI } from '../traces';
|
|
8
|
-
import type { ApiMessageBusMessages } from '../types';
|
|
9
7
|
import type { MetaAPI } from './types';
|
|
10
8
|
export declare function initializeMetaAPI({ internalLogger, metas, }: {
|
|
11
9
|
unpatchedConsole: UnpatchedConsole;
|
|
@@ -14,6 +12,4 @@ export declare function initializeMetaAPI({ internalLogger, metas, }: {
|
|
|
14
12
|
metas: Metas;
|
|
15
13
|
transports: Transports;
|
|
16
14
|
tracesApi: TracesAPI;
|
|
17
|
-
actionBuffer: ItemBuffer<TransportItem>;
|
|
18
|
-
getMessage: () => ApiMessageBusMessages | undefined;
|
|
19
15
|
}): MetaAPI;
|
|
@@ -1,55 +1,14 @@
|
|
|
1
|
-
import type { USER_ACTION_CANCEL, USER_ACTION_END, USER_ACTION_HALT, USER_ACTION_START } from './const';
|
|
2
1
|
import type { EventEvent, EventsAPI } from './events';
|
|
3
2
|
import type { ExceptionEvent, ExceptionsAPI } from './exceptions';
|
|
4
3
|
import type { LogEvent, LogsAPI } from './logs';
|
|
5
4
|
import type { MeasurementEvent, MeasurementsAPI } from './measurements';
|
|
6
5
|
import type { MetaAPI } from './meta';
|
|
7
6
|
import type { TraceEvent, TracesAPI } from './traces';
|
|
8
|
-
|
|
9
|
-
export type API = LogsAPI & ExceptionsAPI & MeasurementsAPI & TracesAPI & MetaAPI & EventsAPI;
|
|
10
|
-
export type ApiMessageBusMessages = UserActionStartMessage | UserActionEndMessage | UserActionCancelMessage | UserActionHaltMessage;
|
|
11
|
-
export type UserActionMessageType = typeof USER_ACTION_START | typeof USER_ACTION_END | typeof USER_ACTION_CANCEL | typeof USER_ACTION_HALT;
|
|
12
|
-
export type UserActionStartMessage = {
|
|
13
|
-
type: typeof USER_ACTION_START;
|
|
14
|
-
name: string;
|
|
15
|
-
startTime: number;
|
|
16
|
-
/**
|
|
17
|
-
* Unique identifier of the parent user action to which this action belongs.
|
|
18
|
-
*/
|
|
19
|
-
parentId: string;
|
|
20
|
-
};
|
|
21
|
-
export type UserActionEndMessage = {
|
|
22
|
-
type: typeof USER_ACTION_END;
|
|
23
|
-
name: string;
|
|
24
|
-
startTime: number;
|
|
25
|
-
endTime: number;
|
|
26
|
-
duration: number;
|
|
27
|
-
eventType: string;
|
|
28
|
-
/**
|
|
29
|
-
* Unique identifier for the user action. Will be undefined for messages related to child actions.
|
|
30
|
-
*/
|
|
31
|
-
id: string;
|
|
32
|
-
};
|
|
33
|
-
export type UserActionCancelMessage = {
|
|
34
|
-
type: typeof USER_ACTION_CANCEL;
|
|
35
|
-
name: string;
|
|
36
|
-
/**
|
|
37
|
-
* Unique identifier of the parent user action to which this action belongs.
|
|
38
|
-
*/
|
|
39
|
-
parentId?: string;
|
|
40
|
-
};
|
|
41
|
-
export type UserActionHaltMessage = {
|
|
42
|
-
type: typeof USER_ACTION_HALT;
|
|
43
|
-
name: string;
|
|
44
|
-
reason: 'pending-requests';
|
|
45
|
-
haltTime: number;
|
|
46
|
-
/**
|
|
47
|
-
* Unique identifier of the parent user action to which this action belongs.
|
|
48
|
-
*/
|
|
49
|
-
parentId?: string;
|
|
50
|
-
};
|
|
7
|
+
import type { UserActionsAPI } from './userActions';
|
|
51
8
|
export type UserAction = {
|
|
52
9
|
name: string;
|
|
53
10
|
id?: string;
|
|
54
11
|
parentId?: string;
|
|
55
12
|
};
|
|
13
|
+
export type APIEvent = LogEvent | ExceptionEvent | MeasurementEvent | TraceEvent | EventEvent;
|
|
14
|
+
export type API = LogsAPI & ExceptionsAPI & MeasurementsAPI & TracesAPI & MetaAPI & EventsAPI & UserActionsAPI;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type InternalLogger, type Transports } from '../..';
|
|
2
|
+
import type { Config } from '../../config';
|
|
3
|
+
import { Observable } from '../../utils/reactive';
|
|
4
|
+
import { type UserActionsAPI } from './types';
|
|
5
|
+
export declare const userActionsMessageBus: Observable<import("./types").UserActionStart>;
|
|
6
|
+
export declare function initializeUserActionsAPI({ transports, internalLogger, config, }: {
|
|
7
|
+
transports: Transports;
|
|
8
|
+
config: Config;
|
|
9
|
+
internalLogger: InternalLogger;
|
|
10
|
+
}): UserActionsAPI;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type TransportItem } from '../../transports';
|
|
2
|
+
import { UserActionSeverity, userActionStartByApiCallEventName } from './const';
|
|
3
|
+
export declare enum UserActionState {
|
|
4
|
+
Started = 0,
|
|
5
|
+
Halted = 1,
|
|
6
|
+
Cancelled = 2,
|
|
7
|
+
Ended = 3
|
|
8
|
+
}
|
|
9
|
+
export type HaltPredicate = () => boolean;
|
|
10
|
+
export interface UserActionInterface {
|
|
11
|
+
name: string;
|
|
12
|
+
parentId: string;
|
|
13
|
+
addItem(item: TransportItem): void;
|
|
14
|
+
extend(haltPredicate?: HaltPredicate): void;
|
|
15
|
+
end(attributes?: Record<string, string>): void;
|
|
16
|
+
halt(reason?: string): void;
|
|
17
|
+
cancel(): void;
|
|
18
|
+
getState(): UserActionState;
|
|
19
|
+
}
|
|
20
|
+
export type ApiUserActionEvent = {
|
|
21
|
+
name: string;
|
|
22
|
+
attributes?: Record<string, string>;
|
|
23
|
+
type: typeof userActionStartByApiCallEventName | string;
|
|
24
|
+
};
|
|
25
|
+
export type EndUserActionProps = {
|
|
26
|
+
userActionName: string;
|
|
27
|
+
startTime: number;
|
|
28
|
+
endTime: number;
|
|
29
|
+
actionId: string;
|
|
30
|
+
event: ApiUserActionEvent;
|
|
31
|
+
attributes?: Record<string, string>;
|
|
32
|
+
};
|
|
33
|
+
export type StartUserActionOptions = {
|
|
34
|
+
triggerName?: string;
|
|
35
|
+
severity?: UserActionSeverity;
|
|
36
|
+
};
|
|
37
|
+
export interface UserActionsAPI {
|
|
38
|
+
startUserAction: (name: string, attributes?: Record<string, string>, options?: StartUserActionOptions) => UserActionInterface | undefined;
|
|
39
|
+
getActiveUserAction: () => UserActionInterface | undefined;
|
|
40
|
+
}
|
|
41
|
+
export type UserActionStart = {
|
|
42
|
+
type: 'user_action_start';
|
|
43
|
+
userAction: UserActionInterface;
|
|
44
|
+
};
|
|
45
|
+
export type UserActionMessage = UserActionStart;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type TransportItem, type Transports } from '../../transports';
|
|
2
|
+
import { Observable } from '../../utils';
|
|
3
|
+
import { type APIEvent } from '../types';
|
|
4
|
+
import { UserActionSeverity } from './const';
|
|
5
|
+
import { type HaltPredicate, type UserActionInterface, UserActionState } from './types';
|
|
6
|
+
export default class UserAction extends Observable implements UserActionInterface {
|
|
7
|
+
name: string;
|
|
8
|
+
id: string;
|
|
9
|
+
attributes?: Record<string, string>;
|
|
10
|
+
parentId: string;
|
|
11
|
+
trigger: string;
|
|
12
|
+
severity: UserActionSeverity;
|
|
13
|
+
startTime?: number;
|
|
14
|
+
trackUserActionsExcludeItem?: (item: TransportItem<APIEvent>) => boolean;
|
|
15
|
+
cancelTimeout: number;
|
|
16
|
+
haltTimeout: number;
|
|
17
|
+
private _state;
|
|
18
|
+
private _timeoutId?;
|
|
19
|
+
private _itemBuffer;
|
|
20
|
+
private _transports;
|
|
21
|
+
private _haltTimeoutId;
|
|
22
|
+
private _isValid;
|
|
23
|
+
constructor({ name, parentId, haltTimeout, trigger, transports, attributes, trackUserActionsExcludeItem, severity, }: {
|
|
24
|
+
name: string;
|
|
25
|
+
transports: Transports;
|
|
26
|
+
parentId?: string;
|
|
27
|
+
trigger: string;
|
|
28
|
+
attributes?: Record<string, string>;
|
|
29
|
+
haltTimeout?: number;
|
|
30
|
+
trackUserActionsExcludeItem?: (item: TransportItem<APIEvent>) => boolean;
|
|
31
|
+
severity?: UserActionSeverity;
|
|
32
|
+
});
|
|
33
|
+
addItem(item: TransportItem): void;
|
|
34
|
+
extend(haltPredicate?: HaltPredicate): void;
|
|
35
|
+
private _setFollowupActionTimeout;
|
|
36
|
+
private _start;
|
|
37
|
+
halt(): void;
|
|
38
|
+
cancel(): void;
|
|
39
|
+
end(): void;
|
|
40
|
+
getState(): UserActionState;
|
|
41
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { defaultExceptionType, defaultLogArgsSerializer, defaultErrorArgsSerializer,
|
|
2
|
-
export type { API, APIEvent, EventAttributes, EventEvent, EventsAPI, ExceptionEvent, ExceptionEventExtended, ExceptionStackFrame, ExceptionsAPI, ExtendedError, LogArgsSerializer, LogContext, LogEvent, LogsAPI, MeasurementEvent, MeasurementsAPI, MetaAPI, OTELApi, PushErrorOptions, PushEventOptions, PushLogOptions, PushMeasurementOptions, Stacktrace, StacktraceParser, TraceContext, TraceEvent, TracesAPI,
|
|
1
|
+
export { defaultExceptionType, defaultLogArgsSerializer, defaultErrorArgsSerializer, UserActionSeverity, UserActionState, userActionsMessageBus, } from './api';
|
|
2
|
+
export type { API, APIEvent, EventAttributes, EventEvent, EventsAPI, ExceptionEvent, ExceptionEventExtended, ExceptionStackFrame, ExceptionsAPI, ExtendedError, LogArgsSerializer, LogContext, LogEvent, LogsAPI, MeasurementEvent, MeasurementsAPI, MetaAPI, OTELApi, PushErrorOptions, PushEventOptions, PushLogOptions, PushMeasurementOptions, Stacktrace, StacktraceParser, TraceContext, TraceEvent, TracesAPI, UserAction, UserActionInterface, } from './api';
|
|
3
3
|
export { BaseExtension } from './extensions';
|
|
4
4
|
export type { Extension } from './extensions';
|
|
5
5
|
export { globalObject } from './globalObject';
|
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @deprecated The conventions object will be removed in a future version
|
|
3
|
-
*/
|
|
4
|
-
export declare const Conventions: {
|
|
5
|
-
/**
|
|
6
|
-
* @deprecated The event names object will be removed in a future version
|
|
7
|
-
*/
|
|
8
|
-
readonly EventNames: {
|
|
9
|
-
readonly CLICK: "click";
|
|
10
|
-
readonly NAVIGATION: "navigation";
|
|
11
|
-
readonly SESSION_START: "session_start";
|
|
12
|
-
readonly VIEW_CHANGED: "view_changed";
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
1
|
export declare const EVENT_CLICK = "click";
|
|
16
2
|
export declare const EVENT_NAVIGATION = "navigation";
|
|
17
3
|
export declare const EVENT_VIEW_CHANGED = "view_changed";
|
|
@@ -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 = "
|
|
7
|
+
readonly version = "2.0.0-beta";
|
|
8
8
|
items: TransportItem[];
|
|
9
9
|
constructor(ignoreURLs?: Patterns);
|
|
10
10
|
send(items: TransportItem[]): void | Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "
|
|
1
|
+
export declare const VERSION = "2.0.0-beta";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mockTracesApi = exports.mockTransports = exports.mockMetas = void 0;
|
|
3
|
+
exports.mockUserActionsApi = exports.mockTracesApi = exports.mockTransports = exports.mockMetas = void 0;
|
|
4
4
|
exports.mockMetas = {
|
|
5
5
|
add: jest.fn(),
|
|
6
6
|
remove: jest.fn(),
|
|
@@ -33,4 +33,8 @@ exports.mockTracesApi = {
|
|
|
33
33
|
isOTELInitialized: jest.fn(),
|
|
34
34
|
pushTraces: jest.fn(),
|
|
35
35
|
};
|
|
36
|
+
exports.mockUserActionsApi = {
|
|
37
|
+
startUserAction: jest.fn(),
|
|
38
|
+
getActiveUserAction: jest.fn(),
|
|
39
|
+
};
|
|
36
40
|
//# sourceMappingURL=apiTestHelpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apiTestHelpers.js","sourceRoot":"","sources":["../../../src/api/apiTestHelpers.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"apiTestHelpers.js","sourceRoot":"","sources":["../../../src/api/apiTestHelpers.ts"],"names":[],"mappings":";;;AAKa,QAAA,SAAS,GAAG;IACvB,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE;IACd,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE;IACjB,WAAW,EAAE,IAAI,CAAC,EAAE,EAAE;IACtB,cAAc,EAAE,IAAI,CAAC,EAAE,EAAE;IACzB,KAAK,EAAE,EAAE;CACV,CAAC;AAEW,QAAA,cAAc,GAAe;IACxC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE;IACd,kBAAkB,EAAE,IAAI,CAAC,EAAE,EAAE;IAC7B,OAAO,EAAE,IAAI,CAAC,EAAE,EAAE;IAClB,kBAAkB,EAAE,IAAI,CAAC,EAAE,EAAE;IAC7B,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE;IACjB,qBAAqB,EAAE,IAAI,CAAC,EAAE,EAAE;IAChC,QAAQ,EAAE;QACR,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IAC/C,CAAC;IACD,UAAU,EAAE,EAAE;IACd,KAAK,EAAE;QACL,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,EAAE;QACP,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IAC/C,CAAC;CACF,CAAC;AAEW,QAAA,aAAa,GAAc;IACtC,OAAO,EAAE,IAAI,CAAC,EAAE,EAAE;IAClB,eAAe,EAAE,IAAI,CAAC,EAAE,EAAE;IAC1B,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE;IACnB,iBAAiB,EAAE,IAAI,CAAC,EAAE,EAAE;IAC5B,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE;CACtB,CAAC;AAEW,QAAA,kBAAkB,GAAmB;IAChD,eAAe,EAAE,IAAI,CAAC,EAAE,EAAE;IAC1B,mBAAmB,EAAE,IAAI,CAAC,EAAE,EAAE;CAC/B,CAAC","sourcesContent":["import type { Transports } from '../transports';\n\nimport type { TracesAPI } from './traces/types';\nimport type { UserActionsAPI } from './userActions/types';\n\nexport const mockMetas = {\n add: jest.fn(),\n remove: jest.fn(),\n addListener: jest.fn(),\n removeListener: jest.fn(),\n value: {},\n};\n\nexport const mockTransports: Transports = {\n add: jest.fn(),\n addBeforeSendHooks: jest.fn(),\n execute: jest.fn(),\n getBeforeSendHooks: jest.fn(),\n remove: jest.fn(),\n removeBeforeSendHooks: jest.fn(),\n isPaused: function (): boolean {\n throw new Error('Function not implemented.');\n },\n transports: [],\n pause: function (): void {\n throw new Error('Function not implemented.');\n },\n unpause: function (): void {\n throw new Error('Function not implemented.');\n },\n};\n\nexport const mockTracesApi: TracesAPI = {\n getOTEL: jest.fn(),\n getTraceContext: jest.fn(),\n initOTEL: jest.fn(),\n isOTELInitialized: jest.fn(),\n pushTraces: jest.fn(),\n};\n\nexport const mockUserActionsApi: UserActionsAPI = {\n startUserAction: jest.fn(),\n getActiveUserAction: jest.fn(),\n};\n"]}
|
|
@@ -4,9 +4,8 @@ exports.initializeEventsAPI = initializeEventsAPI;
|
|
|
4
4
|
var transports_1 = require("../../transports");
|
|
5
5
|
var utils_1 = require("../../utils");
|
|
6
6
|
var date_1 = require("../../utils/date");
|
|
7
|
-
var const_1 = require("../const");
|
|
8
7
|
function initializeEventsAPI(_a) {
|
|
9
|
-
var internalLogger = _a.internalLogger, config = _a.config, metas = _a.metas, transports = _a.transports, tracesApi = _a.tracesApi,
|
|
8
|
+
var internalLogger = _a.internalLogger, config = _a.config, metas = _a.metas, transports = _a.transports, tracesApi = _a.tracesApi, userActionsApi = _a.userActionsApi;
|
|
10
9
|
var lastPayload = null;
|
|
11
10
|
var pushEvent = function (name, attributes, domain, _a) {
|
|
12
11
|
var _b = _a === void 0 ? {} : _a, skipDedupe = _b.skipDedupe, spanContext = _b.spanContext, timestampOverwriteMs = _b.timestampOverwriteMs, _c = _b.customPayloadTransformer, customPayloadTransformer = _c === void 0 ? function (payload) { return payload; } : _c;
|
|
@@ -39,9 +38,9 @@ function initializeEventsAPI(_a) {
|
|
|
39
38
|
}
|
|
40
39
|
lastPayload = testingPayload;
|
|
41
40
|
internalLogger.debug('Pushing event\n', item);
|
|
42
|
-
var
|
|
43
|
-
if (
|
|
44
|
-
|
|
41
|
+
var currentUserAction = userActionsApi.getActiveUserAction();
|
|
42
|
+
if (currentUserAction) {
|
|
43
|
+
currentUserAction.addItem(item);
|
|
45
44
|
}
|
|
46
45
|
else {
|
|
47
46
|
transports.execute(item);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../src/api/events/initialize.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../src/api/events/initialize.ts"],"names":[],"mappings":";;AAaA,kDA0EC;AApFD,+CAAqD;AAGrD,qCAAqG;AACrG,yCAAwD;AAMxD,SAAgB,mBAAmB,CAAC,EAenC;QAdC,cAAc,oBAAA,EACd,MAAM,YAAA,EACN,KAAK,WAAA,EACL,UAAU,gBAAA,EACV,SAAS,eAAA,EACT,cAAc,oBAAA;IAUd,IAAI,WAAW,GAA8D,IAAI,CAAC;IAElF,IAAM,SAAS,GAA2B,UACxC,IAAI,EACJ,UAAU,EACV,MAAM,EACN,EAAmH;YAAnH,qBAAiH,EAAE,KAAA,EAAjH,UAAU,gBAAA,EAAE,WAAW,iBAAA,EAAE,oBAAoB,0BAAA,EAAE,gCAA2D,EAA3D,wBAAwB,mBAAG,UAAC,OAAmB,IAAK,OAAA,OAAO,EAAP,CAAO,KAAA;QAE5G,IAAI,CAAC;YACH,IAAM,KAAK,GAAG,IAAA,6BAAqB,EAAC,UAAU,CAAC,CAAC;YAEhD,IAAM,IAAI,GAA8B;gBACtC,IAAI,EAAE,KAAK,CAAC,KAAK;gBACjB,OAAO,EAAE,wBAAwB,CAAC;oBAChC,IAAI,MAAA;oBACJ,MAAM,EAAE,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,MAAM,CAAC,WAAW;oBACpC,UAAU,EAAE,IAAA,eAAO,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK;oBAC9C,SAAS,EAAE,oBAAoB,CAAC,CAAC,CAAC,IAAA,2BAAoB,EAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,IAAA,2BAAmB,GAAE;oBACpG,KAAK,EAAE,WAAW;wBAChB,CAAC,CAAC;4BACE,QAAQ,EAAE,WAAW,CAAC,OAAO;4BAC7B,OAAO,EAAE,WAAW,CAAC,MAAM;yBAC5B;wBACH,CAAC,CAAC,SAAS,CAAC,eAAe,EAAE;iBAChC,CAAC;gBACF,IAAI,EAAE,8BAAiB,CAAC,KAAK;aAC9B,CAAC;YAEF,IAAM,cAAc,GAAG;gBACrB,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI;gBACvB,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU;gBACnC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM;aAC5B,CAAC;YAEF,IAAI,CAAC,UAAU,IAAI,MAAM,CAAC,MAAM,IAAI,CAAC,IAAA,cAAM,EAAC,WAAW,CAAC,IAAI,IAAA,iBAAS,EAAC,cAAc,EAAE,WAAW,CAAC,EAAE,CAAC;gBACnG,cAAc,CAAC,KAAK,CAAC,8DAA8D,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;gBAEnG,OAAO;YACT,CAAC;YAED,WAAW,GAAG,cAAc,CAAC;YAE7B,cAAc,CAAC,KAAK,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC;YAE9C,IAAM,iBAAiB,GAAG,cAAc,CAAC,mBAAmB,EAAE,CAAC;YAC/D,IAAI,iBAAiB,EAAE,CAAC;gBACtB,iBAAiB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAClC,CAAC;iBAAM,CAAC;gBACN,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,cAAc,CAAC,KAAK,CAAC,qBAAqB,EAAE,GAAG,CAAC,CAAC;QACnD,CAAC;IACH,CAAC,CAAC;IAEF,OAAO;QACL,SAAS,WAAA;KACV,CAAC;AACJ,CAAC","sourcesContent":["import type { Config } 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 { deepEqual, getCurrentTimestamp, isEmpty, isNull, stringifyObjectValues } from '../../utils';\nimport { timestampToIsoString } from '../../utils/date';\nimport type { TracesAPI } from '../traces';\nimport type { UserActionsAPI } from '../userActions';\n\nimport type { EventEvent, EventsAPI } from './types';\n\nexport function initializeEventsAPI({\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}): EventsAPI {\n let lastPayload: Pick<EventEvent, 'name' | 'domain' | 'attributes'> | null = null;\n\n const pushEvent: EventsAPI['pushEvent'] = (\n name,\n attributes,\n domain,\n { skipDedupe, spanContext, timestampOverwriteMs, customPayloadTransformer = (payload: EventEvent) => payload } = {}\n ) => {\n try {\n const attrs = stringifyObjectValues(attributes);\n\n const item: TransportItem<EventEvent> = {\n meta: metas.value,\n payload: customPayloadTransformer({\n name,\n domain: domain ?? config.eventDomain,\n attributes: isEmpty(attrs) ? undefined : attrs,\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 }),\n type: TransportItemType.EVENT,\n };\n\n const testingPayload = {\n name: item.payload.name,\n attributes: item.payload.attributes,\n domain: item.payload.domain,\n };\n\n if (!skipDedupe && config.dedupe && !isNull(lastPayload) && deepEqual(testingPayload, lastPayload)) {\n internalLogger.debug('Skipping event 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 event\\n', item);\n\n const currentUserAction = userActionsApi.getActiveUserAction();\n if (currentUserAction) {\n currentUserAction.addItem(item);\n } else {\n transports.execute(item);\n }\n } catch (err) {\n internalLogger.error('Error pushing event', err);\n }\n };\n\n return {\n pushEvent,\n };\n}\n"]}
|