@sailfish-ai/sf-veritas 0.2.11 → 0.2.13
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/dist/contextManager-BkETRITg.cjs +1 -0
- package/dist/plugins/funcspanEsbuildPlugin.cjs +1 -1
- package/dist/plugins/funcspanEsbuildPlugin.mjs +1 -1
- package/dist/plugins/funcspanRollupPlugin.cjs +1 -1
- package/dist/plugins/funcspanRollupPlugin.mjs +1 -1
- package/dist/plugins/funcspanTscPlugin.cjs +1 -1
- package/dist/plugins/funcspanTscPlugin.mjs +1 -1
- package/dist/plugins/funcspanVitePlugin.cjs +1 -1
- package/dist/plugins/funcspanVitePlugin.mjs +1 -1
- package/dist/plugins/funcspanWebpackPlugin.cjs +1 -1
- package/dist/plugins/funcspanWebpackPlugin.mjs +1 -1
- package/dist/{runtimeConfig-emBNO3lJ.js → runtimeConfig-CgLfwL3X.js} +2 -2
- package/dist/{runtimeConfig-CpQ27dZD.cjs → runtimeConfig-DIsq-KCn.cjs} +6 -6
- package/dist/sf-veritas.cjs +11 -11
- package/dist/sf-veritas.mjs +28 -29
- package/dist/worker-pool-capture.cjs +1 -1
- package/dist/worker-pool-capture.mjs +1 -1
- package/dist/{workerPoolSpanCapture-B5KN-q4b.js → workerPoolSpanCapture-BYaf3NOr.js} +138 -151
- package/dist/workerPoolSpanCapture-D85i6nhQ.cjs +83 -0
- package/package.json +6 -2
- package/dist/contextManager-CGINtRN5.cjs +0 -1
- package/dist/workerPoolSpanCapture-Dg_WGjmO.cjs +0 -86
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var m=Object.defineProperty;var U=(n,e,t)=>e in n?m(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var r=(n,e,t)=>U(n,typeof e!="symbol"?e+"":e,t);const x=require("async_hooks"),a=[];for(let n=0;n<256;++n)a.push((n+256).toString(16).slice(1));let I;const b=new Uint8Array(16),D={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function g(n,e,t){if(D.randomUUID&&!n)return D.randomUUID();const i=(n=n||{}).random??n.rng?.()??(function(){if(!I){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");I=crypto.getRandomValues.bind(crypto)}return I(b)})();if(i.length<16)throw new Error("Random bytes length must be >= 16");return i[6]=15&i[6]|64,i[8]=63&i[8]|128,(function(o,s=0){return(a[o[s+0]]+a[o[s+1]]+a[o[s+2]]+a[o[s+3]]+"-"+a[o[s+4]]+a[o[s+5]]+"-"+a[o[s+6]]+a[o[s+7]]+"-"+a[o[s+8]]+a[o[s+9]]+"-"+a[o[s+10]]+a[o[s+11]]+a[o[s+12]]+a[o[s+13]]+a[o[s+14]]+a[o[s+15]]).toLowerCase()})(i)}class y{constructor(e){r(this,"apiKey");r(this,"apiGraphqlEndpoint");r(this,"sfDebug");r(this,"serviceIdentifier");r(this,"serviceVersion");r(this,"serviceUUID");r(this,"serviceAdditionalMetadata");r(this,"profilingModeEnabled");r(this,"profilingMaxDepth");r(this,"profilingMaxVariableSizeKb");r(this,"domainsToNotPropagateHeadersTo");r(this,"nodeModulesToCollectLocalVariablesOn");r(this,"printConfigurationStatuses");r(this,"logLevel");r(this,"stackDepthLocals");r(this,"stackDepthCodeTraceDepth");r(this,"packageLibraryType");r(this,"version");r(this,"gitSha");r(this,"_serviceIdentificationReceived",!1);this.apiKey=e.apiKey,this.apiGraphqlEndpoint=e?.apiGraphqlEndpoint||process.env.SAILFISH_GRAPHQL_ENDPOINT||"https://api-service.sailfishqa.com/graphql/",this.sfDebug=e?.debug===!0||process.env.SF_DEBUG==="true",this.serviceIdentifier=e?.serviceIdentifier||process.env.SERVICE_IDENTIFIER,this.serviceUUID=g(),this.serviceVersion=e?.serviceVersion||process.env.SERVICE_VERSION,this.gitSha=e?.gitSha||process.env.GIT_SHA||process.env.VERCEL_GIT_COMMIT_SHA,this.serviceAdditionalMetadata=e?.serviceAdditionalMetadata||{},this.profilingModeEnabled=e?.profilingModeEnabled??!1,this.profilingMaxDepth=e?.profilingMaxDepth??5,this.profilingMaxVariableSizeKb=e?.profilingMaxVariableSizeKb??25,this.domainsToNotPropagateHeadersTo=e?.domainsToNotPropagateHeadersTo||[],this.nodeModulesToCollectLocalVariablesOn=e?.nodeModulesToCollectLocalVariablesOn||["_all_"],this.printConfigurationStatuses=process.env.PRINT_CONFIGURATION_STATUSES||"true",this.logLevel=process.env.LOG_LEVEL||"INFO",this.stackDepthLocals=process.env.SAILFISH_EXCEPTION_STACK_DEPTH_LOCALS!==void 0?parseInt(process.env.SAILFISH_EXCEPTION_STACK_DEPTH_LOCALS,10):5,isNaN(this.stackDepthLocals)&&(this.stackDepthLocals=-1),this.stackDepthCodeTraceDepth=process.env.SAILFISH_EXCEPTION_STACK_DEPTH_CODE_TRACE_DEPTH!==void 0?parseInt(process.env.SAILFISH_EXCEPTION_STACK_DEPTH_CODE_TRACE_DEPTH,10):-1,isNaN(this.stackDepthCodeTraceDepth)&&(this.stackDepthCodeTraceDepth=-1),this.packageLibraryType="JS/TS BACKEND",this.version=this.getPackageVersion()}getPackageVersion(){return"0.1.15"}get serviceIdentificationReceived(){return this._serviceIdentificationReceived}setServiceIdentificationReceived(e){this._serviceIdentificationReceived=e}}const A=Symbol.for("sailfish.sf_config");function f(){return globalThis[A]}function C(){const n=f();if(!n)throw new Error("Configuration has not been initialized. Call getOrCreateConfig(options) first.");return n}const E=Symbol.for("sf.ctx.storeAls"),c=globalThis,S=c[E]??(c[E]=new x.AsyncLocalStorage),L=["identitytoolkit.googleapis.com","t.co","*.twitter.com","*.gravatar.com","*.googleapis.com","*.amazonaws.com","*.smooch.io","*.zendesk.com"],v=Symbol.for("sf.ctx.als"),p=c[v]??(c[v]=new x.AsyncLocalStorage),T=Symbol.for("sf.ctx.sessionRegistry"),u=c[T]??(c[T]=new Map),h={handledExceptions:new Set,reentrancyGuardLoggingActive:!1,reentrancyGuardLoggingPreActive:!1,reentrancyGuardPrintActive:!1,reentrancyGuardPrintPreActive:!1,reentrancyGuardExceptionActive:!1,reentrancyGuardExceptionPreActive:!1,excludedDomains:new Set(L),supportedDomains:new Set},d=class d{constructor(){}current(){return S.getStore()}ensureStore(){const e=this.current();if(e)return e;const t=new Map;return S.enterWith(t),t}runWith(e,t){const i=this.current()??new Map,o=new Map(i);for(const[s,_]of Object.entries(e))o.set(s,_);return S.run(o,t)}static getInstance(){return c[d.GLOBAL_MANAGER_SYMBOL]||(c[d.GLOBAL_MANAGER_SYMBOL]=new d),c[d.GLOBAL_MANAGER_SYMBOL]}getCurrentContext(){return p.getStore()||h}setCurrentContext(e){const t=p.getStore()||h;p.enterWith({...t,...e})}ensureSession(e){let t=u.get(e);return t||(t={...h},u.set(e,t)),t}getContextFor(e){return u.get(e)??h}updateContextFor(e,t){const i=this.ensureSession(e);u.set(e,{...i,...t})}runWithSession(e,t){const i={...this.ensureSession(e)};return p.run(i,t)}deleteSession(e){u.delete(e)}getTraceId(){return this.getCurrentContext().traceId}getPageVisitUUID(){return this.getCurrentContext().pageVisitUUID}setTraceId(e){this.setCurrentContext({traceId:e})}setPageVisitUUID(e){this.setCurrentContext({pageVisitUUID:e})}getCurrentFunctionSpanId(){return this.getCurrentContext().currentFunctionSpanId}setCurrentFunctionSpanId(e){this.setCurrentContext({currentFunctionSpanId:e})}clearCurrentFunctionSpanId(){this.setCurrentContext({currentFunctionSpanId:void 0})}getOrSetSfTraceId(e,t=!1){let i=this.getTraceId();return i||(i=e||(t?g():`nonsession-applogs-v3/${C().apiKey}/${g()}`),this.setTraceId(i),C().sfDebug&&console.log(" Created new trace ID:",i),i)}getOrSetPageVisitUUID(){let e=this.getPageVisitUUID();return e||(e=g(),this.setPageVisitUUID(e),C().sfDebug&&console.log(" Created new page visit UUID:",e),e)}getHandledExceptions(){return this.getCurrentContext().handledExceptions}markExceptionHandled(e){const t=this.getHandledExceptions();t.add(e),this.setCurrentContext({handledExceptions:t})}hasHandledException(e){return this.getHandledExceptions().has(e)}resetHandledExceptions(){this.setCurrentContext({handledExceptions:new Set})}getExcludedDomains(){return this.getCurrentContext().excludedDomains}getSupportedDomains(){return this.getCurrentContext().supportedDomains}addSupportedDomains(e){this.getCurrentContext().supportedDomains.add(e.toLowerCase().trim())}setTraceIdFor(e,t){this.updateContextFor(e,{traceId:t})}setPageVisitUUIDFor(e,t){this.updateContextFor(e,{pageVisitUUID:t})}};r(d,"GLOBAL_MANAGER_SYMBOL",Symbol.for("sf.ctx.manager"));let l=d;exports.ContextManager=l,exports.DEFAULT_DOMAINS_TO_EXCLUDE=L,exports.getConfig=C,exports.getCurrentFunctionSpanId=function(){return l.getInstance().getCurrentFunctionSpanId()},exports.getGlobalConfigUnsafe=f,exports.getOrCreateConfig=function(n){const e=f();if(e)return{config:e};const t=new y(n);return(function(i){globalThis[A]=i})(t),t.sfDebug&&console.log("[[getOrCreateConfig]] Created global config:",t),{config:t}},exports.runWithContext=function(n){const e={...l.getInstance().getCurrentContext()};p.run(e,()=>{n()})},exports.v4=g;
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";var K=Object.defineProperty;var V=(n,t,o)=>t in n?K(n,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[t]=o;var S=(n,t,o)=>V(n,typeof t!="symbol"?t+"":t,o);const M=require("async_hooks"),J=require("fs"),F=require("worker_threads"),l=require("./contextManager-CGINtRN5.cjs");class W{constructor(){S(this,"apiKey");S(this,"endpoint");S(this,"queryType","mutation");S(this,"operationName","");S(this,"serviceUUID",l.getConfig().serviceUUID);S(this,"contextManager");this.apiKey=l.getConfig().apiKey,this.endpoint=l.getConfig().apiGraphqlEndpoint,this.contextManager=l.ContextManager.getInstance()}get queryName(){return this.operationName?this.operationName.charAt(0).toLowerCase()+this.operationName.slice(1):""}getDefaultVariables(){const t=Date.now().toString(),o=this.contextManager.getOrSetSfTraceId(),s=this.contextManager.getCurrentFunctionSpanId();return{apiKey:this.apiKey,serviceUuid:this.serviceUUID,sessionId:o,timestampMs:t,parentSpanId:s}}getVariables(t={}){return{...this.getDefaultVariables(),...t}}setOperationName(t){this.operationName=t}setEndpoint(t){this.endpoint=t}setServiceUUID(t){this.serviceUUID=t}}const x=fetch;let $=!1;async function C(n,t,o,s){try{const a=l.getConfig();let i;try{i=JSON.stringify({query:o,variables:s,operationName:t})}catch{i=JSON.stringify({query:o,operationName:t})}$=!0,x(n,{method:"POST",headers:{"Content-Type":"application/json"},body:i}).then(async e=>{if($=!1,!e.ok)return void(a.sfDebug&&console.error(`GraphQL request failed with status ${e.status} for ${t}`));const r=await e.json();r.errors?.length?(function(u,g,c){const d=u&&typeof u=="object"&&!Array.isArray(u)?Object.keys(u)[0]:void 0;console.error(d==="identifyServiceDetails"?`IdentifyServiceDetails NOT sent successfully for service: UUID=${c.serviceUUID}`:`GraphQL request failed with errors: ${JSON.stringify(g)} for operation key ${d}`)})(r.data,r.errors,a):a.sfDebug&&(function(u,g,c){const d=u&&typeof u=="object"&&!Array.isArray(u)?Object.keys(u)[0]:void 0,p=u[d]||!1;d==="identifyServiceDetails"&&(c.setServiceIdentificationReceived(p),l.getConfig().sfDebug&&console.log(`IdentifyServiceDetails sent successfully for service: UUID=${c.serviceUUID}; serviceIdentificationReceived=${d==="identifyServiceDetails"?p:"N/A"}`))})(r.data,0,a)}).catch(e=>{$=!1,a.sfDebug&&(console.error(`[RequestUtils] Fetch error for ${t} to ${n}:`,e),e.cause&&console.error("[RequestUtils] Error cause:",e.cause))})}catch(a){$=!1,l.getConfig().sfDebug&&console.error("Error sending data to GraphQL server:",a)}}function h(n,t){if(!n)return t;const o=n.toLowerCase();return o==="true"||o==="1"||o==="yes"}const v=new M.AsyncLocalStorage;let T=!1;function A(n,t){try{const o=JSON.stringify(n).length/1048576;return o<=t?n:{_truncated:!0,_originalSizeMB:o.toFixed(2),_limitMB:t,_preview:JSON.stringify(n).substring(0,500)+"..."}}catch{return{_error:"Failed to serialize data",_type:typeof n}}}function y(n,t){const o=process.env[n];return o===void 0?t:o==="true"||o==="1"}function D(n,t){const o=process.env[n];if(o===void 0)return t;const s=parseFloat(o);return isNaN(s)?t:s}function k(){return{enabled:y("SF_WORKER_POOL_ENABLED",!0),trackFs:y("SF_WORKER_POOL_TRACK_FS",!1),trackDns:y("SF_WORKER_POOL_TRACK_DNS",!0),trackCrypto:y("SF_WORKER_POOL_TRACK_CRYPTO",!1),trackZlib:y("SF_WORKER_POOL_TRACK_ZLIB",!1),captureArguments:y("SF_WORKER_POOL_CAPTURE_ARGUMENTS",!0),captureReturnValue:y("SF_WORKER_POOL_CAPTURE_RETURN_VALUE",!0),argLimitMb:D("SF_WORKER_POOL_ARG_LIMIT_MB",1),returnLimitMb:D("SF_WORKER_POOL_RETURN_LIMIT_MB",1)}}function L(n,t,o,s){let a;try{switch(n){case"fs":a=(function(i,e){const r={};switch(i){case"readFile":case"writeFile":case"appendFile":r.path=String(e[0]||""),e[1]&&typeof e[1]=="object"?(r.encoding=e[1].encoding||null,r.flag=e[1].flag||null):typeof e[1]=="string"&&(r.encoding=e[1]),i!=="writeFile"&&i!=="appendFile"||(Buffer.isBuffer(e[1])?(r.dataType="Buffer",r.dataSize=e[1].length):typeof e[1]=="string"&&(r.dataType="string",r.dataSize=e[1].length));break;case"readdir":case"stat":case"lstat":case"access":case"chmod":case"mkdir":case"rmdir":case"unlink":r.path=String(e[0]||""),e[1]&&typeof e[1]=="object"&&(r.options={...e[1]},delete r.options.callback);break;case"rename":r.oldPath=String(e[0]||""),r.newPath=String(e[1]||"");break;case"open":r.path=String(e[0]||""),r.flags=e[1],r.mode=e[2];break;case"close":case"fstat":r.fd=e[0];break;case"read":case"write":r.fd=e[0],Buffer.isBuffer(e[1])&&(r.bufferSize=e[1].length),r.offset=e[2],r.length=e[3],r.position=e[4];break;default:r.argsCount=e.length-1}return r})(t,o);break;case"dns":a=(function(i,e){const r={};switch(i){case"lookup":r.hostname=String(e[0]||""),typeof e[1]=="object"?(r.family=e[1].family,r.all=e[1].all):typeof e[1]=="number"&&(r.family=e[1]);break;case"resolve":case"resolve4":case"resolve6":case"resolveAny":case"resolveMx":case"resolveNs":case"resolveTxt":r.hostname=String(e[0]||"");break;case"reverse":r.ip=String(e[0]||"");break;default:r.argsCount=e.length-1}return r})(t,o);break;case"crypto":a=(function(i,e){const r={};switch(i){case"pbkdf2":r.passwordType=typeof e[0],r.saltType=typeof e[1],r.iterations=e[2],r.keylen=e[3],r.digest=e[4];break;case"scrypt":r.passwordType=typeof e[0],r.saltType=typeof e[1],r.keylen=e[2],typeof e[3]=="object"&&(r.N=e[3].N,r.r=e[3].r,r.p=e[3].p);break;case"randomBytes":r.size=e[0];break;case"generateKeyPair":r.type=e[0],typeof e[1]=="object"&&(r.modulusLength=e[1].modulusLength,r.namedCurve=e[1].namedCurve);break;default:r.argsCount=e.length-1}return r})(t,o);break;case"zlib":a=(function(i,e){const r={};return Buffer.isBuffer(e[0])?(r.inputType="Buffer",r.inputSize=e[0].length):typeof e[0]=="string"?(r.inputType="string",r.inputSize=e[0].length):r.inputType=typeof e[0],e[1]&&typeof e[1]=="object"&&typeof e[1]!="function"&&(r.options={...e[1]}),r})(0,o);break;default:return null}return s>0?A(a,s):a}catch{return{error:"Failed to capture arguments",argsCount:o.length-1}}}function w(n,t,o,s){let a;try{switch(n){case"fs":a=(function(i,e){if(!e)return null;switch(i){case"readFile":return Buffer.isBuffer(e)?{type:"Buffer",size:e.length}:typeof e=="string"?{type:"string",size:e.length}:{type:typeof e};case"readdir":return{count:Array.isArray(e)?e.length:0,items:e};case"stat":case"lstat":case"fstat":return{size:e.size,mode:e.mode,isFile:e.isFile(),isDirectory:e.isDirectory()};case"open":return{fd:e};case"read":return{bytesRead:e};case"write":return{bytesWritten:e};default:return e}})(t,o);break;case"dns":a=(function(i,e){if(!e)return null;switch(i){case"lookup":return Array.isArray(e)?{count:e.length,addresses:e}:e;case"resolve":case"resolve4":case"resolve6":case"resolveAny":case"resolveMx":case"resolveNs":case"resolveTxt":return{count:Array.isArray(e)?e.length:0,records:e};case"reverse":return{hostnames:e};default:return e}})(t,o);break;case"crypto":a=(function(i,e){if(!e)return null;switch(i){case"pbkdf2":case"scrypt":case"randomBytes":return Buffer.isBuffer(e)?{type:"Buffer",size:e.length}:{type:typeof e};case"generateKeyPair":return{hasPublicKey:!!e?.publicKey,hasPrivateKey:!!e?.privateKey};default:return e}})(t,o);break;case"zlib":a=(function(i,e){return e?Buffer.isBuffer(e)?{type:"Buffer",size:e.length}:typeof e=="string"?{type:"string",size:e.length}:{type:typeof e}:null})(0,o);break;default:return null}return s>0?A(a,s):a}catch{return{error:"Failed to capture result",type:typeof o}}}function z(n){return n.operationType==="worker_pool"}class B extends W{constructor(){super(),this.operationName="CollectFunctionSpans"}send(t){const o=l.getConfig().sfDebug;o&&console.log(`[FunctionSpanTransmitter] Preparing to send ${t.length} function span(s)`);for(const s of t)try{if(z(s)){this.sendWorkerPoolSpan(s,o);continue}const a=s;let i;if(a.result!==void 0&&a.result!==null){const r=typeof a.result;i=JSON.stringify({type:r,has_value:!0,value:a.result})}else i=a.result===null?JSON.stringify({type:"null",has_value:!0,value:null}):JSON.stringify({type:"undefined",has_value:!1,value:null});const e=this.getVariables({library:"JS/TS BACKEND",version:l.getConfig().version,spanId:a.spanId,parentSpanId:a.parentSpanId,filePath:a.filePath,lineNumber:a.metadata.line,columnNumber:a.metadata.column,functionName:a.functionName,arguments:JSON.stringify(a.args||{}),returnValue:i,startTimeNs:(1e6*Date.now()-1e6*a.duration).toString(),durationNs:(1e6*a.duration).toString()});o&&(console.log(`[FunctionSpanTransmitter] Sending GraphQL mutation to ${this.endpoint}`),console.log("[FunctionSpanTransmitter] Variables:",JSON.stringify(e,null,2))),C(this.endpoint,this.operationName,this.getQuery(),e),o&&console.log(`[FunctionSpanTransmitter] Queued function span for ${a.functionName}`)}catch(a){console.error(`[FunctionSpanTransmitter] Error preparing function span for ${s.functionName}:`,a)}}sendWorkerPoolSpan(t,o){try{let s;if(t.result!==void 0&&t.result!==null){const i=typeof t.result;s=JSON.stringify({type:i,has_value:!0,value:t.result})}else s=t.result===null?JSON.stringify({type:"null",has_value:!0,value:null}):JSON.stringify({type:"undefined",has_value:!1,value:null});const a=this.getVariables({library:"JS/TS BACKEND",version:l.getConfig().version,spanId:t.spanId,operationName:t.operationName,moduleName:t.moduleName,methodName:t.methodName,startTimeNs:t.startTimeNs,durationNs:t.durationNs,arguments:JSON.stringify(t.args||{}),returnValue:s,error:t.error,pid:t.pid,threadId:t.threadId});o&&(console.log(`[FunctionSpanTransmitter] Sending worker pool span: ${t.operationName}`),console.log("[FunctionSpanTransmitter] Variables:",JSON.stringify(a,null,2))),C(this.endpoint,"CollectWorkerPoolSpans",this.getWorkerPoolQuery(),a),o&&console.log(`[FunctionSpanTransmitter] Queued worker pool span for ${t.operationName}`)}catch(s){console.error(`[FunctionSpanTransmitter] Error preparing worker pool span for ${t.operationName}:`,s)}}getWorkerPoolQuery(){return`
|
|
2
|
-
mutation CollectWorkerPoolSpans(
|
|
3
|
-
$apiKey: String!,
|
|
4
|
-
$serviceUuid: String!,
|
|
5
|
-
$sessionId: String!,
|
|
6
|
-
$timestampMs: String!,
|
|
7
|
-
$library: String!,
|
|
8
|
-
$version: String!,
|
|
9
|
-
$spanId: String!,
|
|
10
|
-
$operationName: String!,
|
|
11
|
-
$moduleName: String!,
|
|
12
|
-
$methodName: String!,
|
|
13
|
-
$startTimeNs: String!,
|
|
14
|
-
$durationNs: String!,
|
|
15
|
-
$parentSpanId: String,
|
|
16
|
-
$arguments: String,
|
|
17
|
-
$returnValue: String,
|
|
18
|
-
$error: String,
|
|
19
|
-
$pid: Int,
|
|
20
|
-
$threadId: Int
|
|
21
|
-
) {
|
|
22
|
-
collectWorkerPoolSpans(
|
|
23
|
-
apiKey: $apiKey,
|
|
24
|
-
serviceUuid: $serviceUuid,
|
|
25
|
-
sessionId: $sessionId,
|
|
26
|
-
timestampMs: $timestampMs,
|
|
27
|
-
library: $library,
|
|
28
|
-
version: $version,
|
|
29
|
-
spanId: $spanId,
|
|
30
|
-
operationName: $operationName,
|
|
31
|
-
moduleName: $moduleName,
|
|
32
|
-
methodName: $methodName,
|
|
33
|
-
startTimeNs: $startTimeNs,
|
|
34
|
-
durationNs: $durationNs,
|
|
35
|
-
parentSpanId: $parentSpanId,
|
|
36
|
-
arguments: $arguments,
|
|
37
|
-
returnValue: $returnValue,
|
|
38
|
-
error: $error,
|
|
39
|
-
pid: $pid,
|
|
40
|
-
threadId: $threadId
|
|
41
|
-
)
|
|
42
|
-
}
|
|
43
|
-
`}getQuery(){return`
|
|
44
|
-
${this.queryType} ${this.operationName}(
|
|
45
|
-
$apiKey: String!,
|
|
46
|
-
$serviceUuid: String!,
|
|
47
|
-
$sessionId: String!,
|
|
48
|
-
$timestampMs: String!,
|
|
49
|
-
$parentSpanId: String,
|
|
50
|
-
$library: String!,
|
|
51
|
-
$version: String!,
|
|
52
|
-
$spanId: String!,
|
|
53
|
-
$filePath: String!,
|
|
54
|
-
$lineNumber: Int!,
|
|
55
|
-
$columnNumber: Int!,
|
|
56
|
-
$functionName: String!,
|
|
57
|
-
$arguments: String!,
|
|
58
|
-
$returnValue: String,
|
|
59
|
-
$startTimeNs: String!,
|
|
60
|
-
$durationNs: String!
|
|
61
|
-
) {
|
|
62
|
-
${this.queryName}(
|
|
63
|
-
apiKey: $apiKey,
|
|
64
|
-
serviceUuid: $serviceUuid,
|
|
65
|
-
sessionId: $sessionId,
|
|
66
|
-
timestampMs: $timestampMs,
|
|
67
|
-
parentSpanId: $parentSpanId,
|
|
68
|
-
library: $library,
|
|
69
|
-
version: $version,
|
|
70
|
-
spanId: $spanId,
|
|
71
|
-
filePath: $filePath,
|
|
72
|
-
lineNumber: $lineNumber,
|
|
73
|
-
columnNumber: $columnNumber,
|
|
74
|
-
functionName: $functionName,
|
|
75
|
-
arguments: $arguments,
|
|
76
|
-
returnValue: $returnValue,
|
|
77
|
-
startTimeNs: $startTimeNs,
|
|
78
|
-
durationNs: $durationNs
|
|
79
|
-
)
|
|
80
|
-
}
|
|
81
|
-
`}}let P=null;function O(n){const t=l.getGlobalConfigUnsafe(),o=t?.sfDebug||!1;o&&console.log("[WorkerPool] Capturing span:",{operation:n.operationName,duration:`${n.duration}ms`,error:n.error,spanId:n.spanId,parentSpanId:n.parentSpanId}),process.env.SF_FUNCSPAN_CONSOLE_OUTPUT==="true"&&console.log(`
|
|
82
|
-
⚙️ Worker Pool Operation:`,{operation:n.operationName,duration:`${n.duration.toFixed(2)}ms`,arguments:n.args,result:n.error?`Error: ${n.error}`:n.result,spanId:n.spanId,parentSpanId:n.parentSpanId||"none"});const s=process.env.SF_FUNCSPAN_JSONL_FILE;if(s)try{const a=s==="true"||s==="1"?"funcspans.jsonl":s,i=Date.now(),e=process.hrtime.bigint(),r=BigInt(n.startTimeNs),u=Number(e-r)/1e6,g=new Date(i-u).toISOString(),c=JSON.stringify({timestamp:g,operationType:n.operationType,operationName:n.operationName,moduleName:n.moduleName,methodName:n.methodName,duration:n.duration,durationNs:n.durationNs,startTimeNs:n.startTimeNs,arguments:n.args,returnValue:n.error?{error:String(n.error)}:n.result,spanId:n.spanId,parentSpanId:n.parentSpanId,pid:n.pid,threadId:n.threadId})+`
|
|
83
|
-
`;J.appendFileSync(a,c,"utf-8")}catch(a){console.error("[WorkerPool] Error writing to JSONL file:",a)}if(o&&console.log("[WorkerPool] Sending span to transmitter"),process.env.SF_FUNCSPAN_SKIP_BACKEND!=="true")try{(P||(P=new B),P).send([n]),o&&console.log("[WorkerPool] Span sent successfully")}catch(a){o&&console.error("[WorkerPool] Error sending span:",a)}}exports.BaseTransmitter=W,exports.FunctionSpanTransmitter=B,exports.captureWorkerPoolOperation=function(n,t,o,s,a){const i=l.getGlobalConfigUnsafe(),e=i?.sfDebug||!1;e&&console.log(`[WorkerPool] Capturing ${n}.${t}`);const r=k(),u=l.ContextManager.getInstance().getCurrentFunctionSpanId(),g=l.v4();e&&console.log(`[WorkerPool] Span ID: ${g}, Parent: ${u||"none"}`);const c=new M.AsyncResource("WorkerPoolOperation"),d=process.hrtime.bigint();let p=null;r.captureArguments&&(p=L(n,t,s,r.argLimitMb));const f=s.findIndex(N=>typeof N=="function");if(f===-1)return e&&console.log(`[WorkerPool] No callback found for ${n}.${t}`),o.apply(a,s);const m=s[f],_=[...s];return _[f]=function(N,...b){const I=process.hrtime.bigint()-d,U=Number(I)/1e6;m(N,...b),c.runInAsyncScope(()=>{e&&console.log(`[WorkerPool] ${n}.${t} completed in ${U.toFixed(3)}ms (${I}ns)`);let R=null,E=null;N?E=N?.message||String(N):r.captureReturnValue&&b.length>0&&(R=w(n,t,b[0],r.returnLimitMb)),O({operationType:"worker_pool",operationName:`${n}.${t}`,moduleName:n,methodName:t,duration:U,durationNs:I.toString(),startTimeNs:d.toString(),args:p,result:R,error:E,spanId:g,parentSpanId:u,pid:process.pid,threadId:F.threadId})}),c.emitDestroy()},o.apply(a,_)},exports.captureWorkerPoolPromiseOperation=function(n,t,o,s,a){const i=l.getGlobalConfigUnsafe(),e=i?.sfDebug||!1;e&&console.log(`[WorkerPool] Capturing ${n}.${t} (Promise)`);const r=k(),u=l.ContextManager.getInstance().getCurrentFunctionSpanId(),g=l.v4();e&&console.log(`[WorkerPool] Span ID: ${g}, Parent: ${u||"none"}`);const c=process.hrtime.bigint();let d=null;return r.captureArguments&&(d=L(n,t,s,r.argLimitMb)),o.apply(a,s).then(p=>{const f=process.hrtime.bigint()-c,m=Number(f)/1e6;e&&console.log(`[WorkerPool] ${n}.${t} completed in ${m.toFixed(3)}ms (${f}ns)`);let _=null;return r.captureReturnValue&&(_=w(n,t,p,r.returnLimitMb)),O({operationType:"worker_pool",operationName:`${n}.${t}`,moduleName:n,methodName:t,duration:m,durationNs:f.toString(),startTimeNs:c.toString(),args:d,result:_,error:null,spanId:g,parentSpanId:u,pid:process.pid,threadId:F.threadId}),p},p=>{const f=process.hrtime.bigint()-c,m=Number(f)/1e6;throw e&&console.log(`[WorkerPool] ${n}.${t} failed in ${m.toFixed(3)}ms: ${p?.message||p}`),O({operationType:"worker_pool",operationName:`${n}.${t}`,moduleName:n,methodName:t,duration:m,durationNs:f.toString(),startTimeNs:c.toString(),args:d,result:null,error:p?.message||String(p),spanId:g,parentSpanId:u,pid:process.pid,threadId:F.threadId}),p})},exports.clearFuncspanOverride=function(){},exports.funcspanOverrideStorage=v,exports.getDefaultConfig=function(){return{capture_arguments:!1,capture_return_value:!1,arg_limit_mb:1,return_limit_mb:1,autocapture_all_child_functions:!1,sample_rate:0,enable_sampling:!1,capture_sf_veritas:!1,parse_json_strings:!1}},exports.getEnvConfig=function(){return{capture_arguments:h(process.env.SF_FUNCSPAN_CAPTURE_ARGUMENTS,!0),capture_return_value:h(process.env.SF_FUNCSPAN_CAPTURE_RETURN_VALUE,!0),arg_limit_mb:parseInt(process.env.SF_FUNCSPAN_ARG_LIMIT_MB||"1",10),return_limit_mb:parseInt(process.env.SF_FUNCSPAN_RETURN_LIMIT_MB||"1",10),autocapture_all_child_functions:h(process.env.SF_FUNCSPAN_AUTOCAPTURE_ALL_CHILD_FUNCTIONS,!1),sample_rate:parseFloat(process.env.SF_FUNCSPAN_SAMPLE_RATE||"1.0"),enable_sampling:h(process.env.SF_FUNCSPAN_ENABLE_SAMPLING,!1),capture_sf_veritas:h(process.env.SF_FUNCSPAN_CAPTURE_SF_VERITAS,!1),parse_json_strings:h(process.env.SF_FUNCSPAN_PARSE_JSON_STRINGS,!1)}},exports.getFuncspanOverride=function(){if(T)return v.getStore();try{T=!0;const n=v.getStore(),t=new Error().stack?.split(`
|
|
84
|
-
`).slice(1,4).join(`
|
|
85
|
-
`);return console.log(`[getFuncspanOverride] Called from:
|
|
86
|
-
${t}`),console.log("[getFuncspanOverride] Returned value:",n),n}catch(n){return void console.error("[getFuncspanOverride] ❌ Error:",n)}finally{T=!1}},exports.isModuleTrackingEnabled=function(n){const t=k();if(!t.enabled)return!1;switch(n){case"fs":return t.trackFs;case"dns":return t.trackDns;case"crypto":return t.trackCrypto;case"zlib":return t.trackZlib;default:return!1}},exports.mergeConfigs=function(...n){const t={};for(const o of n)for(const s in o)o[s]!==void 0&&(t[s]=o[s]);return t},exports.nonBlockingPost=C,exports.parseHeaderOverride=function(n){try{const t=n.split("-");return t.length!==9?(console.error(`[FuncSpan] Invalid header format: expected 9 parts, got ${t.length}`),null):{capture_arguments:t[0]==="1",capture_return_value:t[1]==="1",arg_limit_mb:parseInt(t[2],10),return_limit_mb:parseInt(t[3],10),autocapture_all_child_functions:t[4]==="1",sample_rate:parseFloat(t[5]),enable_sampling:t[6]==="1",capture_sf_veritas:t[7]==="1",parse_json_strings:t[8]==="1"}}catch(t){return console.error(`[FuncSpan] Failed to parse header override "${n}":`,t),null}},exports.setFuncspanOverride=function(n){v.enterWith(n)},exports.truncateToLimit=A;
|