hud-sdk
Version:
Hud's Node SDK
2 lines • 7.48 kB
JavaScript
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n=e();for(var i in n)("object"==typeof exports?exports:t)[i]=n[i]}}(global,()=>(()=>{"use strict";var t={4403:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.SketchManager=void 0;const i=n(4602);e.SketchManager=class{binWidth;logBinWidth;constructor(t){this.binWidth=t,this.logBinWidth=Math.log(t)}binIndex(t){return Math.floor(Math.log(t)/this.logBinWidth)}indexToBinStart(t){return this.binWidth**t}newSketchDataWithValue(t){const e=this.binIndex(t),n=new i.SketchData;return n.indexShift=e,n[0]=1,n}add(t,e){const n=this.binIndex(e);let i=n-t.indexShift;i<0?(t.unshift(...new Array(-i).fill(0)),t.indexShift=n,i=n-t.indexShift):i>=t.length&&t.push(...new Array(i-t.length+1).fill(0)),t[i]+=1}zero(t){t.fill(0)}copy(t){const e=new i.SketchData;return e.indexShift=t.indexShift,e.push(...t),e}mergeIntoNoChecks(t,e){const n=e.indexShift-t.indexShift;for(let i=0;i<e.length;i++)t[i+n]+=e[i]}mergeInto(t,e){e.indexShift<t.indexShift&&(t.unshift(...new Array(t.indexShift-e.indexShift).fill(0)),t.indexShift=e.indexShift),e.indexShift+e.length>t.indexShift+t.length&&t.push(...new Array(e.indexShift+e.length-(t.indexShift+t.length)).fill(0)),this.mergeIntoNoChecks(t,e)}mergeMany(t){if(0===t.length)throw new Error("Cannot merge empty list of SketchData.");if(1===t.length)return this.copy(t[0]);let e=1/0,n=-1/0;for(const i of t)e=Math.min(e,i.indexShift),n=Math.max(n,i.indexShift+i.length-1);const r=new i.SketchData;r.indexShift=e,r.push(...new Array(n-e+1).fill(0));for(const e of t)this.mergeIntoNoChecks(r,e);return r}getQuantile(t,e){const n=t.reduce((t,e)=>t+e,0);if(0===n)throw new Error("Cannot get quantile of empty SketchData.");const i=n*e;let r,o=0;for(r=0;r<t.length&&(o+=t[r],!(o>=i));r++);const a=this.indexToBinStart(r+t.indexShift),c=(o-i)/t[r];return a*this.binWidth**(1-c)}encode(t){return{binWidth:this.binWidth,indexShift:t.indexShift,data:Array.from(t)}}decode(t){if(t.binWidth!==this.binWidth)throw new Error(`Should not decode sketch data with bin width ${t.binWidth} using SketchManager with bin width ${this.binWidth}.`);const e=new i.SketchData;return e.indexShift=t.indexShift,e.push(...t.data),e}}},4602:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.SketchData=void 0,e.SketchData=class extends Array{indexShift=0;constructor(){super()}}},6042:function(t,e,n){var i=this&&this.__createBinding||(Object.create?function(t,e,n,i){void 0===i&&(i=n);var r=Object.getOwnPropertyDescriptor(e,n);r&&!("get"in r?!e.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,i,r)}:function(t,e,n,i){void 0===i&&(i=n),t[i]=e[n]}),r=this&&this.__exportStar||function(t,e){for(var n in t)"default"===n||Object.prototype.hasOwnProperty.call(e,n)||i(e,t,n)};Object.defineProperty(e,"__esModule",{value:!0}),e._hudVersion=e.afterYield=e.beforeYield=e.wrapperUserCatch=e.fixStack=e.wrapperFinally=e.wrapperCatch=e.wrapperInitial=e.InvestigationStatus=void 0,e.setFlowStateStorage=function(t){void 0===s&&(s=t)},e.getFlowStateStorage=l,e.getHttpMetricFromFlowState=function(){return s?.getStore()?.httpMetric},e.setInvestigationStorage=function(t){void 0===h&&(h=t)},e.getInvestigationStorage=function(){return h},e.investigateError=d,e.extractName=f,e.extractMessage=function(t){if(t instanceof Error)return t.message?t.message:void 0},e.extractStackTrace=function(t){if(t instanceof Error)return t.stack?t.stack:void 0},e.asyncIteratorWrapper=function(t){if(t&&t[Symbol.asyncIterator])return t[Symbol.asyncIterator]();if(t&&t[Symbol.iterator])return new g(t[Symbol.iterator]());if(t&&t["@@asyncIterator"])return t["@@asyncIterator"]();if(t&&t["@@iterator"])return t["@@iterator"]();throw new TypeError("Object is not async iterable")};const o=n(4403),a=n(7830),c=new o.SketchManager(1.2);let s;function l(){return s}var u;let h;function d(t,e,n,i){if(!globalThis.hudEnableInvestigation)return;if(void 0===h)return;const r=h.getStore();if(void 0===r)return;const o=globalThis.hudExceptionMaxLength??20;let a=r.exceptions.get(i);if(void 0===a){if(r.exceptions.size>=o)return;a={exception:i,executionFlow:[],caught:e},r.exceptions.set(i,a)}a.caught=e,r.caught=e;const c=globalThis.hudExecutionFlowMaxLength??20;a.executionFlow.length>=c||a.executionFlow.push({function_id:t.functionId,caller_id:t.wrappedCaller,args:globalThis.hudEnableInvestigationArgsSending?n:void 0,is_outbound_function:t.io??!1})}function f(t){return t instanceof Error?t.constructor?t.constructor.name:t.name?t.name:"Non-Deducible-Name-Exception":"Non-Error-Exception"}function S(t){if(!t.initFailed&&t.fixFlag){const e=t.functionId;hudStack[++hudStackIndex.value]=e,t.fixFlag=!1}}!function(t){t[t.Open=1]="Open",t[t.Closed=2]="Closed"}(u||(e.InvestigationStatus=u={})),globalThis.hudStackIndex=globalThis.hudStackIndex??{value:0},globalThis.hudStack=globalThis.hudStack??new Array(1e3).fill(""),globalThis.hudCalls=globalThis.hudCalls??[];class g{iterator;n;constructor(t){this.iterator=t,this.n=t.next}static AsyncFromSyncIteratorContinuation(t){if(Object(t)!==t)return Promise.reject(new TypeError(t+" is not an object."));const e=t.done;return Promise.resolve(t.value).then(function(t){return{value:t,done:e}})}next(...t){return g.AsyncFromSyncIteratorContinuation(this.n.call(this.iterator,...t))}return(t){const e=this.iterator.return;return void 0===e?Promise.resolve({value:t,done:!0}):g.AsyncFromSyncIteratorContinuation(e.call(this.iterator,t))}throw(t){const e=this.iterator.throw;return void 0===e?Promise.reject(t):g.AsyncFromSyncIteratorContinuation(e.call(this.iterator,t))}[Symbol.asyncIterator](){return this}}e.wrapperInitial=function(t,e){const n={};try{n.functionId=t,n.io=e??!1;const i=n.wrappedCaller=hudStack[hudStackIndex.value],r=hudCalls[t]??={},o=r[i]??={},a=l()?.getStore(),c=n.call_obj=o[n.currentFlowId=a?.flowId||""]??={count:0,samplingCounter:0,sampledCount:0,sum:0,exceptions:{},squareSum:0,sketch:null,isLinkedFunction:!1},s=c.samplingCounter++;(n.sample_flag=2===hudRunningMode&&(!!n.io||(s>=5e3?s%103==0:hudSampleTable[s])))&&(n.start=process.hrtime.bigint()),a?.shouldLinkFunction&&(a.shouldLinkFunction=!1,c.isLinkedFunction=!0),hudStack[++hudStackIndex.value]=t}catch{n.initFailed=!0}return n},e.wrapperCatch=function(t,e,n){if(e.initFailed)return;const i=e.functionId,r=f(t),o=hudCalls[i][e.wrappedCaller][e.currentFlowId];o.exceptions[r]??=0,o.exceptions[r]++,d(e,!1,n,t)},e.wrapperFinally=function(t){if(t.initFailed)return;t.fixFlag||hudStackIndex.value--;const e=t.call_obj;if(e.count++,t.sample_flag){const n=process.hrtime.bigint(),i=Number(n-t.start);i>0&&(e.sampledCount++,e.sum+=i,e.squareSum+=i*i,null===e.sketch?e.sketch=c.newSketchDataWithValue(i):c.add(e.sketch,i))}},e.fixStack=S,e.wrapperUserCatch=function(t,e,n){e.initFailed||(S(e),d(e,!0,n,t))},e.beforeYield=function(t){t.initFailed||(globalThis.hudStackIndex.value--,t.fixFlag=!0)},e.afterYield=function(t){t.initFailed||(globalThis.hudStack[++globalThis.hudStackIndex.value]=t.functionId,t.fixFlag=!1)},e._hudVersion=a.SDK_VERSION,r(n(4602),e),r(n(4403),e)},7830:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.SDK_VERSION=void 0,e.SDK_VERSION="1.7.1"}},e={};return function n(i){var r=e[i];if(void 0!==r)return r.exports;var o=e[i]={exports:{}};return t[i].call(o.exports,o,o.exports,n),o.exports}(6042)})());
//# sourceMappingURL=wrap.js.map