hud-sdk
Version:
Hud's Node SDK
2 lines • 5.07 kB
JavaScript
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(global,(()=>(()=>{"use strict";var e={290:e=>{e.exports=require("async_hooks")}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return e[n](i,i.exports,r),i.exports}var n={};return(()=>{var e=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.closeInvestigation=e.createNewInvestigation=e._getStorage=e.InvestigationStatus=void 0;const t=r(290);var o;!function(e){e[e.Open=1]="Open",e[e.Closed=2]="Closed"}(o||(e.InvestigationStatus=o={}));const i=new t.AsyncLocalStorage;function a(e,t,r){if(!globalThis.hudEnableInvestigation)return;if(void 0===i)return;if(!(r instanceof Error))return;const n=i.getStore();if(void 0===n)return;void 0===n.exceptions&&(n.exceptions=new Map,n.firstException=r);const o=globalThis.hudExceptionMaxLength??100;let a=n.exceptions.get(r);if(void 0===a){if(n.exceptions.size>=o)return;a={exception:r,executionFlow:[]},n.exceptions.set(r,a)}const c=globalThis.hudExecutionFlowMaxLength??100;a.executionFlow.length>=c||a.executionFlow.push({function_id:e,caller_id:t.wrappedCaller})}function c(e){return e instanceof Error?e.constructor?e.constructor.name:e.name?e.name:"Non-Deducible-Name-Exception":"Non-Error-Exception"}e._getStorage=function(){return i},e.createNewInvestigation=function(){globalThis.hudEnableInvestigation&&i.enterWith({status:o.Open})},e.closeInvestigation=function(){if(!globalThis.hudEnableInvestigation)return;const e=i.getStore();return void 0!==e&&e.status===o.Open?(e.status=o.Closed,e):void 0},e.investigateError=a,e.extractName=c,e.extractNameOptional=function(e){const t=c(e);if(!["Non-Error-Exception","Non-Deducible-Name-Exception"].includes(t))return t},e.extractMessage=function(e){if(e instanceof Error)return e.message?e.message:void 0},e.extractStackTrace=function(e){if(e instanceof Error)return e.stack?e.stack:void 0},e.getCallsites=function(e=0){const t=Error.stackTraceLimit,r=Error.prepareStackTrace;let n=[];try{Error.stackTraceLimit=4+e,Error.prepareStackTrace=(t,r)=>{const o=r.slice(1+e);return n=o,o},(new Error).stack}finally{Error.stackTraceLimit=t,Error.prepareStackTrace=r}const o="processTicksAndRejections"!==n[0].getFunctionName()?0:1;let i;n[o]&&(i={name:n[o].getFunctionName(),file:n[o].getFileName(),line:n[o].getLineNumber(),column:n[o].getColumnNumber(),enclosingLine:n[o].getEnclosingLineNumber()});const a=n[o+1]&&"processTicksAndRejections"!==n[o+1].getFunctionName()?o+1:o+2;let c;return n[a]&&(c={name:n[a].getFunctionName(),file:n[a].getFileName(),line:n[a].getLineNumber(),column:n[a].getColumnNumber(),enclosingLine:n[a].getEnclosingLineNumber()}),[i,c]};class s{iterator;n;constructor(e){this.iterator=e,this.n=e.next}static AsyncFromSyncIteratorContinuation(e){if(Object(e)!==e)return Promise.reject(new TypeError(e+" is not an object."));const t=e.done;return Promise.resolve(e.value).then((function(e){return{value:e,done:t}}))}next(...e){return s.AsyncFromSyncIteratorContinuation(this.n.call(this.iterator,...e))}return(e){const t=this.iterator.return;return void 0===t?Promise.resolve({value:e,done:!0}):s.AsyncFromSyncIteratorContinuation(t.call(this.iterator,e))}throw(e){const t=this.iterator.throw;return void 0===t?Promise.reject(e):s.AsyncFromSyncIteratorContinuation(t.call(this.iterator,e))}[Symbol.asyncIterator](){return this}}e.asyncIteratorWrapper=function(e){if(e&&e[Symbol.asyncIterator])return e[Symbol.asyncIterator]();if(e&&e[Symbol.iterator])return new s(e[Symbol.iterator]());if(e&&e["@@asyncIterator"])return e["@@asyncIterator"]();if(e&&e["@@iterator"])return e["@@iterator"]();throw new TypeError("Object is not async iterable")},e.wrapperInitial=function(e,t){const r=t.wrappedCaller=_hud_S[_hud_SI.value],n=hudCalls[e]??={},o=n[r]??={},i=o[_hud_F]??={count:0,lastSentCounter:0,sampledCount:0,sum:0,exceptions:{},squareSum:0,sketch:null,isLinkedFunction:!1},a=i.count++;(t.sample_flag=2===hudRunningMode&&(a>=5e3?a%103==0:hudSampleTable[a]))&&(t.start=process.hrtime.bigint()),hudShouldLinkFunction&&(hudShouldLinkFunction=!1,i.isLinkedFunction=!0),t.currentFlowId=_hud_F,_hud_S[++_hud_SI.value]=e},e.wrapperCatch=function(e,t,r){const n=c(r),o=hudCalls[e][t.wrappedCaller][t.currentFlowId];o.exceptions[n]??=0,o.exceptions[n]++,a(e,t,r)},e.wrapperFinally=function(e,t){if(t.ff||_hud_SI.value--,t.sample_flag){const r=process.hrtime.bigint(),n=Number(r-t.start);if(n>0){const r=hudCalls[e][t.wrappedCaller][t.currentFlowId];r.sampledCount++,r.sum+=n,r.squareSum+=n*n,null===r.sketch?r.sketch=hudManager.newSketchDataWithValue(n):hudManager.add(r.sketch,n)}}},e.fixStack=function(e,t){t.ff&&(_hud_S[++_hud_SI.value]=e,_hud_F=t.currentFlowId,t.ff=!1)}})(),n})()));
//# sourceMappingURL=wrap.js.map