@sailfish-ai/sf-veritas 0.2.14 → 0.2.16
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/sf-veritas.cjs +12 -12
- package/dist/sf-veritas.mjs +201 -193
- package/dist/types/funcSpanConfig.d.ts +0 -4
- package/dist/types/funcSpanConfigLoader.d.ts +1 -1
- package/dist/worker-pool-capture.cjs +1 -1
- package/dist/worker-pool-capture.mjs +1 -1
- package/dist/{workerPoolSpanCapture-Danyb3Qa.cjs → workerPoolSpanCapture-COwiNikM.cjs} +2 -2
- package/dist/{workerPoolSpanCapture-DWS_V0Mn.js → workerPoolSpanCapture-d-8ExI18.js} +84 -82
- package/package.json +1 -1
|
@@ -58,10 +58,6 @@ export declare function getDefaultConfig(): FuncspanConfig;
|
|
|
58
58
|
* Example: "1-1-10-10-1-1.0-1-0-0"
|
|
59
59
|
*/
|
|
60
60
|
export declare function parseHeaderOverride(header: string): FuncspanHeaderOverride | null;
|
|
61
|
-
/**
|
|
62
|
-
* AsyncLocalStorage for per-request funcspan override
|
|
63
|
-
* Exported to allow direct .run() usage in patchhttpInbound.ts
|
|
64
|
-
*/
|
|
65
61
|
export declare const funcspanOverrideStorage: AsyncLocalStorage<string>;
|
|
66
62
|
/**
|
|
67
63
|
* Set funcspan override from HTTP header (per-request)
|
|
@@ -67,7 +67,7 @@ export declare class FuncspanConfigLoader {
|
|
|
67
67
|
export declare function initializeConfigLoader(rootPaths?: string[], debug?: boolean): Promise<void>;
|
|
68
68
|
/**
|
|
69
69
|
* Get configuration for a file and function
|
|
70
|
-
* In worker processes where config loader isn't initialized, returns
|
|
70
|
+
* In worker processes where config loader isn't initialized, returns default config (disabled)
|
|
71
71
|
*/
|
|
72
72
|
export declare function getGlobalConfig(filePath: string, functionName?: string): FuncspanConfig;
|
|
73
73
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./workerPoolSpanCapture-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./workerPoolSpanCapture-COwiNikM.cjs");exports.captureWorkerPoolOperation=e.captureWorkerPoolOperation;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const w=require("async_hooks"),B=require("fs"),v=require("worker_threads"),l=require("./contextManager-CxQqBCEA.cjs");class M{apiKey;endpoint;queryType="mutation";operationName="";serviceUUID=l.getConfig().serviceUUID;contextManager;constructor(){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 K=fetch;let _=!1;async function P(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,K(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 N(n,t){if(!n)return t;const o=n.toLowerCase();return o==="true"||o==="1"||o==="yes"}const O="__sf_funcspanOverrideStorage";globalThis[O]||(globalThis[O]=new w.AsyncLocalStorage);const I=globalThis[O];function C(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 S(n,t){const o=process.env[n];return o===void 0?t:o==="true"||o==="1"}function E(n,t){const o=process.env[n];if(o===void 0)return t;const s=parseFloat(o);return isNaN(s)?t:s}function T(){return{enabled:S("SF_WORKER_POOL_ENABLED",!0),trackFs:S("SF_WORKER_POOL_TRACK_FS",!1),trackDns:S("SF_WORKER_POOL_TRACK_DNS",!0),trackCrypto:S("SF_WORKER_POOL_TRACK_CRYPTO",!1),trackZlib:S("SF_WORKER_POOL_TRACK_ZLIB",!1),captureArguments:S("SF_WORKER_POOL_CAPTURE_ARGUMENTS",!0),captureReturnValue:S("SF_WORKER_POOL_CAPTURE_RETURN_VALUE",!0),argLimitMb:E("SF_WORKER_POOL_ARG_LIMIT_MB",1),returnLimitMb:E("SF_WORKER_POOL_RETURN_LIMIT_MB",1)}}function D(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?C(a,s):a}catch{return{error:"Failed to capture arguments",argsCount:o.length-1}}}function L(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?C(a,s):a}catch{return{error:"Failed to capture result",type:typeof o}}}function V(n){return n.operationType==="worker_pool"}class W extends M{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(V(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))),P(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))),P(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
2
|
mutation CollectWorkerPoolSpans(
|
|
3
3
|
$apiKey: String!,
|
|
4
4
|
$serviceUuid: String!,
|
|
@@ -80,4 +80,4 @@
|
|
|
80
80
|
}
|
|
81
81
|
`}}let F=null;function k(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
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
|
-
`;
|
|
83
|
+
`;B.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{(F||(F=new W),F).send([n]),o&&console.log("[WorkerPool] Span sent successfully")}catch(a){o&&console.error("[WorkerPool] Error sending span:",a)}}exports.BaseTransmitter=M,exports.FunctionSpanTransmitter=W,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=T(),u=l.ContextManager.getInstance().getCurrentFunctionSpanId(),g=l.v4();e&&console.log(`[WorkerPool] Span ID: ${g}, Parent: ${u||"none"}`);const c=new w.AsyncResource("WorkerPoolOperation"),d=process.hrtime.bigint();let p=null;r.captureArguments&&(p=D(n,t,s,r.argLimitMb));const f=s.findIndex(y=>typeof y=="function");if(f===-1)return e&&console.log(`[WorkerPool] No callback found for ${n}.${t}`),o.apply(a,s);const m=s[f],h=[...s];return h[f]=function(y,...$){const b=process.hrtime.bigint()-d,A=Number(b)/1e6;m(y,...$),c.runInAsyncScope(()=>{e&&console.log(`[WorkerPool] ${n}.${t} completed in ${A.toFixed(3)}ms (${b}ns)`);let U=null,R=null;y?R=y?.message||String(y):r.captureReturnValue&&$.length>0&&(U=L(n,t,$[0],r.returnLimitMb)),k({operationType:"worker_pool",operationName:`${n}.${t}`,moduleName:n,methodName:t,duration:A,durationNs:b.toString(),startTimeNs:d.toString(),args:p,result:U,error:R,spanId:g,parentSpanId:u,pid:process.pid,threadId:v.threadId})}),c.emitDestroy()},o.apply(a,h)},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=T(),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=D(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 h=null;return r.captureReturnValue&&(h=L(n,t,p,r.returnLimitMb)),k({operationType:"worker_pool",operationName:`${n}.${t}`,moduleName:n,methodName:t,duration:m,durationNs:f.toString(),startTimeNs:c.toString(),args:d,result:h,error:null,spanId:g,parentSpanId:u,pid:process.pid,threadId:v.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}`),k({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:v.threadId}),p})},exports.clearFuncspanOverride=function(){},exports.funcspanOverrideStorage=I,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:N(process.env.SF_FUNCSPAN_CAPTURE_ARGUMENTS,!0),capture_return_value:N(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:N(process.env.SF_FUNCSPAN_AUTOCAPTURE_ALL_CHILD_FUNCTIONS,!1),sample_rate:parseFloat(process.env.SF_FUNCSPAN_SAMPLE_RATE||"1.0"),enable_sampling:N(process.env.SF_FUNCSPAN_ENABLE_SAMPLING,!1),capture_sf_veritas:N(process.env.SF_FUNCSPAN_CAPTURE_SF_VERITAS,!1),parse_json_strings:N(process.env.SF_FUNCSPAN_PARSE_JSON_STRINGS,!1)}},exports.getFuncspanOverride=function(){return I.getStore()},exports.isModuleTrackingEnabled=function(n){const t=T();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=P,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){I.enterWith(n)},exports.truncateToLimit=C;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var S = (n, t, a) =>
|
|
4
|
-
import { AsyncLocalStorage as
|
|
5
|
-
import { appendFileSync as
|
|
6
|
-
import { threadId as
|
|
7
|
-
import { g as
|
|
8
|
-
class
|
|
1
|
+
var W = Object.defineProperty;
|
|
2
|
+
var V = (n, t, a) => t in n ? W(n, t, { enumerable: !0, configurable: !0, writable: !0, value: a }) : n[t] = a;
|
|
3
|
+
var S = (n, t, a) => V(n, typeof t != "symbol" ? t + "" : t, a);
|
|
4
|
+
import { AsyncLocalStorage as J, AsyncResource as z } from "async_hooks";
|
|
5
|
+
import { appendFileSync as x } from "fs";
|
|
6
|
+
import { threadId as T } from "worker_threads";
|
|
7
|
+
import { g as f, C as P, v as L, a as O } from "./contextManager-Cx03mw7l.js";
|
|
8
|
+
class j {
|
|
9
9
|
constructor() {
|
|
10
10
|
S(this, "apiKey");
|
|
11
11
|
S(this, "endpoint");
|
|
12
12
|
S(this, "queryType", "mutation");
|
|
13
13
|
S(this, "operationName", "");
|
|
14
|
-
S(this, "serviceUUID",
|
|
14
|
+
S(this, "serviceUUID", f().serviceUUID);
|
|
15
15
|
S(this, "contextManager");
|
|
16
|
-
this.apiKey =
|
|
16
|
+
this.apiKey = f().apiKey, this.endpoint = f().apiGraphqlEndpoint, this.contextManager = P.getInstance();
|
|
17
17
|
}
|
|
18
18
|
get queryName() {
|
|
19
19
|
return this.operationName ? this.operationName.charAt(0).toLowerCase() + this.operationName.slice(1) : "";
|
|
@@ -35,18 +35,18 @@ class x {
|
|
|
35
35
|
this.serviceUUID = t;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
const
|
|
38
|
+
const q = fetch;
|
|
39
39
|
let $ = !1;
|
|
40
|
-
async function
|
|
40
|
+
async function E(n, t, a, o) {
|
|
41
41
|
try {
|
|
42
|
-
const s =
|
|
42
|
+
const s = f();
|
|
43
43
|
let i;
|
|
44
44
|
try {
|
|
45
45
|
i = JSON.stringify({ query: a, variables: o, operationName: t });
|
|
46
46
|
} catch {
|
|
47
47
|
i = JSON.stringify({ query: a, operationName: t });
|
|
48
48
|
}
|
|
49
|
-
$ = !0,
|
|
49
|
+
$ = !0, q(n, { method: "POST", headers: { "Content-Type": "application/json" }, body: i }).then(async (e) => {
|
|
50
50
|
if ($ = !1, !e.ok) return void (s.sfDebug && console.error(`GraphQL request failed with status ${e.status} for ${t}`));
|
|
51
51
|
const r = await e.json();
|
|
52
52
|
r.errors?.length ? (function(u, d, l) {
|
|
@@ -54,22 +54,22 @@ async function C(n, t, a, o) {
|
|
|
54
54
|
console.error(p === "identifyServiceDetails" ? `IdentifyServiceDetails NOT sent successfully for service: UUID=${l.serviceUUID}` : `GraphQL request failed with errors: ${JSON.stringify(d)} for operation key ${p}`);
|
|
55
55
|
})(r.data, r.errors, s) : s.sfDebug && (function(u, d, l) {
|
|
56
56
|
const p = u && typeof u == "object" && !Array.isArray(u) ? Object.keys(u)[0] : void 0, c = u[p] || !1;
|
|
57
|
-
p === "identifyServiceDetails" && (l.setServiceIdentificationReceived(c),
|
|
57
|
+
p === "identifyServiceDetails" && (l.setServiceIdentificationReceived(c), f().sfDebug && console.log(`IdentifyServiceDetails sent successfully for service: UUID=${l.serviceUUID}; serviceIdentificationReceived=${p === "identifyServiceDetails" ? c : "N/A"}`));
|
|
58
58
|
})(r.data, 0, s);
|
|
59
59
|
}).catch((e) => {
|
|
60
60
|
$ = !1, s.sfDebug && (console.error(`[RequestUtils] Fetch error for ${t} to ${n}:`, e), e.cause && console.error("[RequestUtils] Error cause:", e.cause));
|
|
61
61
|
});
|
|
62
62
|
} catch (s) {
|
|
63
|
-
$ = !1,
|
|
63
|
+
$ = !1, f().sfDebug && console.error("Error sending data to GraphQL server:", s);
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
function
|
|
66
|
+
function te() {
|
|
67
67
|
return { capture_arguments: _(process.env.SF_FUNCSPAN_CAPTURE_ARGUMENTS, !0), capture_return_value: _(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: _(process.env.SF_FUNCSPAN_AUTOCAPTURE_ALL_CHILD_FUNCTIONS, !1), sample_rate: parseFloat(process.env.SF_FUNCSPAN_SAMPLE_RATE || "1.0"), enable_sampling: _(process.env.SF_FUNCSPAN_ENABLE_SAMPLING, !1), capture_sf_veritas: _(process.env.SF_FUNCSPAN_CAPTURE_SF_VERITAS, !1), parse_json_strings: _(process.env.SF_FUNCSPAN_PARSE_JSON_STRINGS, !1) };
|
|
68
68
|
}
|
|
69
|
-
function
|
|
69
|
+
function ne() {
|
|
70
70
|
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 };
|
|
71
71
|
}
|
|
72
|
-
function
|
|
72
|
+
function re(n) {
|
|
73
73
|
try {
|
|
74
74
|
const t = n.split("-");
|
|
75
75
|
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" };
|
|
@@ -82,21 +82,23 @@ function _(n, t) {
|
|
|
82
82
|
const a = n.toLowerCase();
|
|
83
83
|
return a === "true" || a === "1" || a === "yes";
|
|
84
84
|
}
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return L.getStore();
|
|
85
|
+
const F = "__sf_funcspanOverrideStorage";
|
|
86
|
+
globalThis[F] || (globalThis[F] = new J());
|
|
87
|
+
const w = globalThis[F];
|
|
88
|
+
function ae(n) {
|
|
89
|
+
w.enterWith(n);
|
|
91
90
|
}
|
|
92
91
|
function se() {
|
|
92
|
+
return w.getStore();
|
|
93
93
|
}
|
|
94
|
-
function oe(
|
|
94
|
+
function oe() {
|
|
95
|
+
}
|
|
96
|
+
function ie(...n) {
|
|
95
97
|
const t = {};
|
|
96
98
|
for (const a of n) for (const o in a) a[o] !== void 0 && (t[o] = a[o]);
|
|
97
99
|
return t;
|
|
98
100
|
}
|
|
99
|
-
function
|
|
101
|
+
function K(n, t) {
|
|
100
102
|
try {
|
|
101
103
|
const a = JSON.stringify(n).length / 1048576;
|
|
102
104
|
return a <= t ? n : { _truncated: !0, _originalSizeMB: a.toFixed(2), _limitMB: t, _preview: JSON.stringify(n).substring(0, 500) + "..." };
|
|
@@ -108,17 +110,17 @@ function y(n, t) {
|
|
|
108
110
|
const a = process.env[n];
|
|
109
111
|
return a === void 0 ? t : a === "true" || a === "1";
|
|
110
112
|
}
|
|
111
|
-
function
|
|
113
|
+
function D(n, t) {
|
|
112
114
|
const a = process.env[n];
|
|
113
115
|
if (a === void 0) return t;
|
|
114
116
|
const o = parseFloat(a);
|
|
115
117
|
return isNaN(o) ? t : o;
|
|
116
118
|
}
|
|
117
|
-
function
|
|
118
|
-
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:
|
|
119
|
+
function A() {
|
|
120
|
+
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) };
|
|
119
121
|
}
|
|
120
|
-
function
|
|
121
|
-
const t =
|
|
122
|
+
function ue(n) {
|
|
123
|
+
const t = A();
|
|
122
124
|
if (!t.enabled) return !1;
|
|
123
125
|
switch (n) {
|
|
124
126
|
case "fs":
|
|
@@ -133,7 +135,7 @@ function ie(n) {
|
|
|
133
135
|
return !1;
|
|
134
136
|
}
|
|
135
137
|
}
|
|
136
|
-
function
|
|
138
|
+
function B(n, t, a, o) {
|
|
137
139
|
let s;
|
|
138
140
|
try {
|
|
139
141
|
switch (n) {
|
|
@@ -232,12 +234,12 @@ function K(n, t, a, o) {
|
|
|
232
234
|
default:
|
|
233
235
|
return null;
|
|
234
236
|
}
|
|
235
|
-
return o > 0 ?
|
|
237
|
+
return o > 0 ? K(s, o) : s;
|
|
236
238
|
} catch {
|
|
237
239
|
return { error: "Failed to capture arguments", argsCount: a.length - 1 };
|
|
238
240
|
}
|
|
239
241
|
}
|
|
240
|
-
function
|
|
242
|
+
function M(n, t, a, o) {
|
|
241
243
|
let s;
|
|
242
244
|
try {
|
|
243
245
|
switch (n) {
|
|
@@ -308,23 +310,23 @@ function B(n, t, a, o) {
|
|
|
308
310
|
default:
|
|
309
311
|
return null;
|
|
310
312
|
}
|
|
311
|
-
return o > 0 ?
|
|
313
|
+
return o > 0 ? K(s, o) : s;
|
|
312
314
|
} catch {
|
|
313
315
|
return { error: "Failed to capture result", type: typeof a };
|
|
314
316
|
}
|
|
315
317
|
}
|
|
316
|
-
function
|
|
318
|
+
function G(n) {
|
|
317
319
|
return n.operationType === "worker_pool";
|
|
318
320
|
}
|
|
319
|
-
class
|
|
321
|
+
class Q extends j {
|
|
320
322
|
constructor() {
|
|
321
323
|
super(), this.operationName = "CollectFunctionSpans";
|
|
322
324
|
}
|
|
323
325
|
send(t) {
|
|
324
|
-
const a =
|
|
326
|
+
const a = f().sfDebug;
|
|
325
327
|
a && console.log(`[FunctionSpanTransmitter] Preparing to send ${t.length} function span(s)`);
|
|
326
328
|
for (const o of t) try {
|
|
327
|
-
if (
|
|
329
|
+
if (G(o)) {
|
|
328
330
|
this.sendWorkerPoolSpan(o, a);
|
|
329
331
|
continue;
|
|
330
332
|
}
|
|
@@ -334,8 +336,8 @@ class G extends x {
|
|
|
334
336
|
const r = typeof s.result;
|
|
335
337
|
i = JSON.stringify({ type: r, has_value: !0, value: s.result });
|
|
336
338
|
} else i = s.result === null ? JSON.stringify({ type: "null", has_value: !0, value: null }) : JSON.stringify({ type: "undefined", has_value: !1, value: null });
|
|
337
|
-
const e = this.getVariables({ library: "JS/TS BACKEND", version:
|
|
338
|
-
a && (console.log(`[FunctionSpanTransmitter] Sending GraphQL mutation to ${this.endpoint}`), console.log("[FunctionSpanTransmitter] Variables:", JSON.stringify(e, null, 2))),
|
|
339
|
+
const e = this.getVariables({ library: "JS/TS BACKEND", version: f().version, spanId: s.spanId, parentSpanId: s.parentSpanId, filePath: s.filePath, lineNumber: s.metadata.line, columnNumber: s.metadata.column, functionName: s.functionName, arguments: JSON.stringify(s.args || {}), returnValue: i, startTimeNs: (1e6 * Date.now() - 1e6 * s.duration).toString(), durationNs: (1e6 * s.duration).toString() });
|
|
340
|
+
a && (console.log(`[FunctionSpanTransmitter] Sending GraphQL mutation to ${this.endpoint}`), console.log("[FunctionSpanTransmitter] Variables:", JSON.stringify(e, null, 2))), E(this.endpoint, this.operationName, this.getQuery(), e), a && console.log(`[FunctionSpanTransmitter] Queued function span for ${s.functionName}`);
|
|
339
341
|
} catch (s) {
|
|
340
342
|
console.error(`[FunctionSpanTransmitter] Error preparing function span for ${o.functionName}:`, s);
|
|
341
343
|
}
|
|
@@ -347,8 +349,8 @@ class G extends x {
|
|
|
347
349
|
const i = typeof t.result;
|
|
348
350
|
o = JSON.stringify({ type: i, has_value: !0, value: t.result });
|
|
349
351
|
} else o = t.result === null ? JSON.stringify({ type: "null", has_value: !0, value: null }) : JSON.stringify({ type: "undefined", has_value: !1, value: null });
|
|
350
|
-
const s = this.getVariables({ library: "JS/TS BACKEND", version:
|
|
351
|
-
a && (console.log(`[FunctionSpanTransmitter] Sending worker pool span: ${t.operationName}`), console.log("[FunctionSpanTransmitter] Variables:", JSON.stringify(s, null, 2))),
|
|
352
|
+
const s = this.getVariables({ library: "JS/TS BACKEND", version: f().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: o, error: t.error, pid: t.pid, threadId: t.threadId });
|
|
353
|
+
a && (console.log(`[FunctionSpanTransmitter] Sending worker pool span: ${t.operationName}`), console.log("[FunctionSpanTransmitter] Variables:", JSON.stringify(s, null, 2))), E(this.endpoint, "CollectWorkerPoolSpans", this.getWorkerPoolQuery(), s), a && console.log(`[FunctionSpanTransmitter] Queued worker pool span for ${t.operationName}`);
|
|
352
354
|
} catch (o) {
|
|
353
355
|
console.error(`[FunctionSpanTransmitter] Error preparing worker pool span for ${t.operationName}:`, o);
|
|
354
356
|
}
|
|
@@ -441,75 +443,75 @@ class G extends x {
|
|
|
441
443
|
}
|
|
442
444
|
}
|
|
443
445
|
let v = null;
|
|
444
|
-
function
|
|
445
|
-
const i =
|
|
446
|
+
function le(n, t, a, o, s) {
|
|
447
|
+
const i = O(), e = i?.sfDebug || !1;
|
|
446
448
|
e && console.log(`[WorkerPool] Capturing ${n}.${t}`);
|
|
447
|
-
const r =
|
|
449
|
+
const r = A(), u = P.getInstance().getCurrentFunctionSpanId(), d = L();
|
|
448
450
|
e && console.log(`[WorkerPool] Span ID: ${d}, Parent: ${u || "none"}`);
|
|
449
|
-
const l = new
|
|
451
|
+
const l = new z("WorkerPoolOperation"), p = process.hrtime.bigint();
|
|
450
452
|
let c = null;
|
|
451
|
-
r.captureArguments && (c =
|
|
453
|
+
r.captureArguments && (c = B(n, t, o, r.argLimitMb));
|
|
452
454
|
const g = o.findIndex((N) => typeof N == "function");
|
|
453
455
|
if (g === -1) return e && console.log(`[WorkerPool] No callback found for ${n}.${t}`), a.apply(s, o);
|
|
454
|
-
const
|
|
456
|
+
const m = o[g], h = [...o];
|
|
455
457
|
return h[g] = function(N, ...b) {
|
|
456
|
-
const I = process.hrtime.bigint() - p,
|
|
457
|
-
|
|
458
|
-
e && console.log(`[WorkerPool] ${n}.${t} completed in ${
|
|
459
|
-
let
|
|
460
|
-
N ?
|
|
458
|
+
const I = process.hrtime.bigint() - p, U = Number(I) / 1e6;
|
|
459
|
+
m(N, ...b), l.runInAsyncScope(() => {
|
|
460
|
+
e && console.log(`[WorkerPool] ${n}.${t} completed in ${U.toFixed(3)}ms (${I}ns)`);
|
|
461
|
+
let R = null, C = null;
|
|
462
|
+
N ? C = N?.message || String(N) : r.captureReturnValue && b.length > 0 && (R = M(n, t, b[0], r.returnLimitMb)), k({ operationType: "worker_pool", operationName: `${n}.${t}`, moduleName: n, methodName: t, duration: U, durationNs: I.toString(), startTimeNs: p.toString(), args: c, result: R, error: C, spanId: d, parentSpanId: u, pid: process.pid, threadId: T });
|
|
461
463
|
}), l.emitDestroy();
|
|
462
464
|
}, a.apply(s, h);
|
|
463
465
|
}
|
|
464
|
-
function
|
|
465
|
-
const i =
|
|
466
|
+
function ce(n, t, a, o, s) {
|
|
467
|
+
const i = O(), e = i?.sfDebug || !1;
|
|
466
468
|
e && console.log(`[WorkerPool] Capturing ${n}.${t} (Promise)`);
|
|
467
|
-
const r =
|
|
469
|
+
const r = A(), u = P.getInstance().getCurrentFunctionSpanId(), d = L();
|
|
468
470
|
e && console.log(`[WorkerPool] Span ID: ${d}, Parent: ${u || "none"}`);
|
|
469
471
|
const l = process.hrtime.bigint();
|
|
470
472
|
let p = null;
|
|
471
|
-
return r.captureArguments && (p =
|
|
472
|
-
const g = process.hrtime.bigint() - l,
|
|
473
|
-
e && console.log(`[WorkerPool] ${n}.${t} completed in ${
|
|
473
|
+
return r.captureArguments && (p = B(n, t, o, r.argLimitMb)), a.apply(s, o).then((c) => {
|
|
474
|
+
const g = process.hrtime.bigint() - l, m = Number(g) / 1e6;
|
|
475
|
+
e && console.log(`[WorkerPool] ${n}.${t} completed in ${m.toFixed(3)}ms (${g}ns)`);
|
|
474
476
|
let h = null;
|
|
475
|
-
return r.captureReturnValue && (h =
|
|
477
|
+
return r.captureReturnValue && (h = M(n, t, c, r.returnLimitMb)), k({ operationType: "worker_pool", operationName: `${n}.${t}`, moduleName: n, methodName: t, duration: m, durationNs: g.toString(), startTimeNs: l.toString(), args: p, result: h, error: null, spanId: d, parentSpanId: u, pid: process.pid, threadId: T }), c;
|
|
476
478
|
}, (c) => {
|
|
477
|
-
const g = process.hrtime.bigint() - l,
|
|
478
|
-
throw e && console.log(`[WorkerPool] ${n}.${t} failed in ${
|
|
479
|
+
const g = process.hrtime.bigint() - l, m = Number(g) / 1e6;
|
|
480
|
+
throw e && console.log(`[WorkerPool] ${n}.${t} failed in ${m.toFixed(3)}ms: ${c?.message || c}`), k({ operationType: "worker_pool", operationName: `${n}.${t}`, moduleName: n, methodName: t, duration: m, durationNs: g.toString(), startTimeNs: l.toString(), args: p, result: null, error: c?.message || String(c), spanId: d, parentSpanId: u, pid: process.pid, threadId: T }), c;
|
|
479
481
|
});
|
|
480
482
|
}
|
|
481
|
-
function
|
|
482
|
-
const t =
|
|
483
|
+
function k(n) {
|
|
484
|
+
const t = O(), a = t?.sfDebug || !1;
|
|
483
485
|
a && 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(`
|
|
484
486
|
⚙️ 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" });
|
|
485
487
|
const o = process.env.SF_FUNCSPAN_JSONL_FILE;
|
|
486
488
|
if (o) try {
|
|
487
489
|
const s = o === "true" || o === "1" ? "funcspans.jsonl" : o, i = Date.now(), e = process.hrtime.bigint(), r = BigInt(n.startTimeNs), u = Number(e - r) / 1e6, d = new Date(i - u).toISOString(), l = JSON.stringify({ timestamp: d, 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 }) + `
|
|
488
490
|
`;
|
|
489
|
-
|
|
491
|
+
x(s, l, "utf-8");
|
|
490
492
|
} catch (s) {
|
|
491
493
|
console.error("[WorkerPool] Error writing to JSONL file:", s);
|
|
492
494
|
}
|
|
493
495
|
if (a && console.log("[WorkerPool] Sending span to transmitter"), process.env.SF_FUNCSPAN_SKIP_BACKEND !== "true") try {
|
|
494
|
-
(v || (v = new
|
|
496
|
+
(v || (v = new Q()), v).send([n]), a && console.log("[WorkerPool] Span sent successfully");
|
|
495
497
|
} catch (s) {
|
|
496
498
|
a && console.error("[WorkerPool] Error sending span:", s);
|
|
497
499
|
}
|
|
498
500
|
}
|
|
499
501
|
export {
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
502
|
+
j as B,
|
|
503
|
+
Q as F,
|
|
504
|
+
ne as a,
|
|
503
505
|
te as b,
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
506
|
+
le as c,
|
|
507
|
+
ce as d,
|
|
508
|
+
oe as e,
|
|
509
|
+
w as f,
|
|
510
|
+
se as g,
|
|
511
|
+
ue as i,
|
|
512
|
+
ie as m,
|
|
513
|
+
E as n,
|
|
514
|
+
re as p,
|
|
515
|
+
ae as s,
|
|
516
|
+
K as t
|
|
515
517
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sailfish-ai/sf-veritas",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.16",
|
|
4
4
|
"publishPublicly": true,
|
|
5
5
|
"description": "A versatile Edge Runtime-compatible package for JavaScript and TypeScript backend systems and scripts.",
|
|
6
6
|
"main": "./dist/sf-veritas.cjs",
|