@code-hud/hud-node-sdk
Version:
Hud's Node SDK
2 lines • 4.42 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={};return(()=>{var t=e;function r(e,t,r){if(!globalThis.hudEnableInvestigation)return;if(void 0===hudInvestigationStorage)return;if(!(r instanceof Error))return;const n=hudInvestigationStorage.getStore();if(void 0===n)return;void 0===n.exceptions&&(n.exceptions=new Map,n.firstException=r);const o=globalThis.hudExceptionMaxLength??100;let i=n.exceptions.get(r);if(void 0===i){if(n.exceptions.size>=o)return;i={exception:r,executionFlow:[]},n.exceptions.set(r,i)}const a=globalThis.hudExecutionFlowMaxLength??100;i.executionFlow.length>=a||i.executionFlow.push({function_id:e,caller_id:t.wrappedCaller})}function n(e){return e instanceof Error?e.constructor?e.constructor.name:e.name?e.name:"Non-Deducible-Name-Exception":"Non-Error-Exception"}Object.defineProperty(t,"__esModule",{value:!0}),t.fixStack=t.wrapperFinally=t.wrapperCatch=t.wrapperInitial=t.asyncIteratorWrapper=t.getCallsites=t.extractStackTrace=t.extractMessage=t.extractNameOptional=t.extractName=t.investigateError=void 0,t.investigateError=r,t.extractName=n,t.extractNameOptional=function(e){const t=n(e);if(!["Non-Error-Exception","Non-Deducible-Name-Exception"].includes(t))return t},t.extractMessage=function(e){if(e instanceof Error)return e.message?e.message:void 0},t.extractStackTrace=function(e){if(e instanceof Error)return e.stack?e.stack:void 0},t.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 o{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 o.AsyncFromSyncIteratorContinuation(this.n.call(this.iterator,...e))}return(e){const t=this.iterator.return;return void 0===t?Promise.resolve({value:e,done:!0}):o.AsyncFromSyncIteratorContinuation(t.call(this.iterator,e))}throw(e){const t=this.iterator.throw;return void 0===t?Promise.reject(e):o.AsyncFromSyncIteratorContinuation(t.call(this.iterator,e))}[Symbol.asyncIterator](){return this}}t.asyncIteratorWrapper=function(e){if(e&&e[Symbol.asyncIterator])return e[Symbol.asyncIterator]();if(e&&e[Symbol.iterator])return new o(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")},t.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},t.wrapperCatch=function(e,t,o){const i=n(o),a=hudCalls[e][t.wrappedCaller][t.currentFlowId];a.exceptions[i]??=0,a.exceptions[i]++,r(e,t,o)},t.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)}}},t.fixStack=function(e,t){t.ff&&(_hud_S[++_hud_SI.value]=e,_hud_F=t.currentFlowId,t.ff=!1)}})(),e})()));
//# sourceMappingURL=wrap.js.map