UNPKG

hud-sdk

Version:

Hud's Node SDK

2 lines 7.47 kB
!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 r in n)("object"==typeof exports?exports:t)[r]=n[r]}}(global,(()=>(()=>{"use strict";var t={290:t=>{t.exports=require("async_hooks")},4403:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.SketchManager=void 0;const r=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 r.SketchData;return n.indexShift=e,n[0]=1,n}add(t,e){const n=this.binIndex(e);let r=n-t.indexShift;r<0?(t.unshift(...new Array(-r).fill(0)),t.indexShift=n,r=n-t.indexShift):r>=t.length&&t.push(...new Array(r-t.length+1).fill(0)),t[r]+=1}zero(t){t.fill(0)}copy(t){const e=new r.SketchData;return e.indexShift=t.indexShift,e.push(...t),e}mergeIntoNoChecks(t,e){const n=e.indexShift-t.indexShift;for(let r=0;r<e.length;r++)t[r+n]+=e[r]}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 r of t)e=Math.min(e,r.indexShift),n=Math.max(n,r.indexShift+r.length-1);const i=new r.SketchData;i.indexShift=e,i.push(...new Array(n-e+1).fill(0));for(const e of t)this.mergeIntoNoChecks(i,e);return i}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 r=n*e;let i,o=0;for(i=0;i<t.length&&(o+=t[i],!(o>=r));i++);const a=this.indexToBinStart(i+t.indexShift),c=(o-r)/t[i];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 r.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 r=this&&this.__createBinding||(Object.create?function(t,e,n,r){void 0===r&&(r=n);var i=Object.getOwnPropertyDescriptor(e,n);i&&!("get"in i?!e.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,i)}:function(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}),i=this&&this.__exportStar||function(t,e){for(var n in t)"default"===n||Object.prototype.hasOwnProperty.call(e,n)||r(e,t,n)};Object.defineProperty(e,"__esModule",{value:!0}),e.fixStack=e.wrapperFinally=e.wrapperCatch=e.wrapperInitial=e.asyncIteratorWrapper=e.getCallsites=e.extractStackTrace=e.extractMessage=e.extractNameOptional=e.extractName=e.investigateError=e.getStorage=e.InvestigationStatus=void 0;const o=new(n(4403).SketchManager)(globalThis.huddBinWidth),a=n(290);var c;!function(t){t[t.Open=1]="Open",t[t.Closed=2]="Closed"}(c||(e.InvestigationStatus=c={}));const s=new a.AsyncLocalStorage;function u(t,e,n){if(!globalThis.hudEnableInvestigation)return;if(void 0===s)return;if(!(n instanceof Error))return;const r=s.getStore();if(void 0===r)return;void 0===r.exceptions&&(r.exceptions=new Map,r.firstException=n);const i=globalThis.hudExceptionMaxLength??100;let o=r.exceptions.get(n);if(void 0===o){if(r.exceptions.size>=i)return;o={exception:n,executionFlow:[]},r.exceptions.set(n,o)}const a=globalThis.hudExecutionFlowMaxLength??100;o.executionFlow.length>=a||o.executionFlow.push({function_id:t,caller_id:e.wrappedCaller})}function l(t){return t instanceof Error?t.constructor?t.constructor.name:t.name?t.name:"Non-Deducible-Name-Exception":"Non-Error-Exception"}e.getStorage=function(){return s},e.investigateError=u,e.extractName=l,e.extractNameOptional=function(t){const e=l(t);if(!["Non-Error-Exception","Non-Deducible-Name-Exception"].includes(e))return e},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.getCallsites=function(t=0){const e=Error.stackTraceLimit,n=Error.prepareStackTrace;let r=[];try{Error.stackTraceLimit=4+t,Error.prepareStackTrace=(e,n)=>{const i=n.slice(1+t);return r=i,i},(new Error).stack}finally{Error.stackTraceLimit=e,Error.prepareStackTrace=n}const i="processTicksAndRejections"!==r[0].getFunctionName()?0:1;let o;r[i]&&(o={name:r[i].getFunctionName(),file:r[i].getFileName(),line:r[i].getLineNumber(),column:r[i].getColumnNumber(),enclosingLine:r[i].getEnclosingLineNumber()});const a=r[i+1]&&"processTicksAndRejections"!==r[i+1].getFunctionName()?i+1:i+2;let c;return r[a]&&(c={name:r[a].getFunctionName(),file:r[a].getFileName(),line:r[a].getLineNumber(),column:r[a].getColumnNumber(),enclosingLine:r[a].getEnclosingLineNumber()}),[o,c]};class h{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 h.AsyncFromSyncIteratorContinuation(this.n.call(this.iterator,...t))}return(t){const e=this.iterator.return;return void 0===e?Promise.resolve({value:t,done:!0}):h.AsyncFromSyncIteratorContinuation(e.call(this.iterator,t))}throw(t){const e=this.iterator.throw;return void 0===e?Promise.reject(t):h.AsyncFromSyncIteratorContinuation(e.call(this.iterator,t))}[Symbol.asyncIterator](){return this}}e.asyncIteratorWrapper=function(t){if(t&&t[Symbol.asyncIterator])return t[Symbol.asyncIterator]();if(t&&t[Symbol.iterator])return new h(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")},e.wrapperInitial=function(t,e){const n=e.wrappedCaller=_hud_S[_hud_SI.value],r=hudCalls[t]??={},i=r[n]??={},o=i[_hud_F]??={count:0,lastSentCounter:0,sampledCount:0,sum:0,exceptions:{},squareSum:0,sketch:null,isLinkedFunction:!1},a=o.count++;(e.sample_flag=2===hudRunningMode&&(a>=5e3?a%103==0:hudSampleTable[a]))&&(e.start=process.hrtime.bigint()),hudShouldLinkFunction&&(hudShouldLinkFunction=!1,o.isLinkedFunction=!0),e.currentFlowId=_hud_F,_hud_S[++_hud_SI.value]=t},e.wrapperCatch=function(t,e,n){const r=l(n),i=hudCalls[t][e.wrappedCaller][e.currentFlowId];i.exceptions[r]??=0,i.exceptions[r]++,u(t,e,n)},e.wrapperFinally=function(t,e){if(e.ff||_hud_SI.value--,e.sample_flag){const n=process.hrtime.bigint(),r=Number(n-e.start);if(r>0){const n=hudCalls[t][e.wrappedCaller][e.currentFlowId];n.sampledCount++,n.sum+=r,n.squareSum+=r*r,null===n.sketch?n.sketch=o.newSketchDataWithValue(r):o.add(n.sketch,r)}}},e.fixStack=function(t,e){e.ff&&(_hud_S[++_hud_SI.value]=t,_hud_F=e.currentFlowId,e.ff=!1)},i(n(4602),e),i(n(4403),e)}},e={};return function n(r){var i=e[r];if(void 0!==i)return i.exports;var o=e[r]={exports:{}};return t[r].call(o.exports,o,o.exports,n),o.exports}(6042)})())); //# sourceMappingURL=wrap.js.map