@sailfish-ai/sf-veritas 0.2.16 → 0.2.17
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 +2 -2
- package/dist/sf-veritas.mjs +149 -149
- package/dist/worker-pool-capture.cjs +1 -1
- package/dist/worker-pool-capture.mjs +1 -1
- package/dist/{workerPoolSpanCapture-COwiNikM.cjs → workerPoolSpanCapture-BUdAamcg.cjs} +2 -2
- package/dist/{workerPoolSpanCapture-d-8ExI18.js → workerPoolSpanCapture-DEW40aIL.js} +25 -21
- package/package.json +1 -1
package/dist/sf-veritas.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./contextManager-CxQqBCEA.cjs"),p=require("./workerPoolSpanCapture-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./contextManager-CxQqBCEA.cjs"),p=require("./workerPoolSpanCapture-BUdAamcg.cjs"),h=require("./runtimeConfig-TWzqPe1S.cjs"),ae=require("node:module"),x=require("fs"),ce=require("./source-map-rHHEdpre.cjs"),de=require("path"),ue=require("glob"),E=require("worker_threads"),O=require("./funcSpanTransformer-CDh0o-AP.cjs");function ie(r){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const t in r)if(t!=="default"){const i=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,i.get?i:{enumerable:!0,get:()=>r[t]})}}return e.default=r,Object.freeze(e)}const L=ie(x),F=ie(de);class P extends p.BaseTransmitter{constructor(){super(),this.setOperationName("IdentifyServiceDetails")}async doSend(e){if(!c.getConfig().serviceIdentificationReceived)try{this.send()}catch(t){c.getConfig().sfDebug&&console.error(" Error during service identification:",t)}}async send(){const e=`
|
|
2
2
|
${this.queryType} ${this.operationName}(
|
|
3
3
|
$apiKey: String!,
|
|
4
4
|
$timestampMs: String!,
|
|
@@ -166,7 +166,7 @@
|
|
|
166
166
|
setupInterceptorsLine: $setupInterceptorsLine,
|
|
167
167
|
)
|
|
168
168
|
}
|
|
169
|
-
`,t=c.getConfig(),i=this.getVariables({serviceIdentifier:t.serviceIdentifier,serviceVersion:t.serviceVersion,serviceAdditionalMetadata:t.serviceAdditionalMetadata,gitSha:t.gitSha||"",gitOrg:t.gitOrg||void 0,gitRepo:t.gitRepo||void 0,gitProvider:t.gitProvider||void 0,serviceDisplayName:t.serviceDisplayName||void 0,infrastructureType:t.infrastructureType||void 0,infrastructureDetails:t.infrastructureDetails||void 0,setupInterceptorsFile:t.setupInterceptorsFile||void 0,setupInterceptorsLine:t.setupInterceptorsLine||void 0});p.nonBlockingPost(this.endpoint,this.operationName,e,i)}}class _e{rootPaths;fileConfigs=new Map;functionConfigs=new Map;directoryConfigs=new Map;hasSailfishFiles=!1;runtimeModeEnabled=!1;debug;constructor(e=[process.cwd()],t=!1){this.rootPaths=e,this.debug=t||process.env.SF_DEBUG==="true"}async loadAllConfigs(){this.debug&&console.log("[FuncSpan ConfigLoader] Scanning for .sailfish files in:",this.rootPaths);const e=[];for(const t of this.rootPaths)L.existsSync(t)?await this._walkDirectory(t,e):this.debug&&console.log(`[FuncSpan ConfigLoader] Root path does not exist: ${t}`);e.length>0?(this.hasSailfishFiles=!0,this.debug&&(console.log(`[FuncSpan ConfigLoader] Found ${e.length} .sailfish files:`),e.forEach(t=>console.log(`[FuncSpan ConfigLoader] - ${t}`)))):this.debug&&console.log("[FuncSpan ConfigLoader] No .sailfish files found - function spans disabled by default");for(const t of e)await this._loadConfigFile(t);await this._resolveInheritance(),this.debug&&console.log(`[FuncSpan ConfigLoader] Loaded ${this.fileConfigs.size} file configs, ${this.functionConfigs.size} function configs`)}getConfig(e,t){const i=this.hasSailfishFiles?p.getEnvConfig():p.getDefaultConfig(),n=this._getDirectoryConfig(e),s=F.normalize(e),u=this.fileConfigs.get(s)||{};let o={};if(t){const d=this.functionConfigs.get(s);d&&(o=d.get(t)||{})}return p.mergeConfigs(i,n,u,o)}hasRuntimeMode(){return this.runtimeModeEnabled}async _walkDirectory(e,t){try{const i=L.readdirSync(e,{withFileTypes:!0});for(const n of i){const s=F.join(e,n.name);n.isFile()&&n.name===".sailfish"?t.push(s):n.name==="node_modules"||n.isDirectory()&&n.name.startsWith(".")&&n.name!==".sailfish"||n.isDirectory()&&await this._walkDirectory(s,t)}}catch(i){this.debug&&console.error(`[FuncSpan ConfigLoader] Error walking directory ${e}:`,i)}}async _loadConfigFile(e){try{const t=L.readFileSync(e,"utf-8"),i=F.dirname(e);let n=null;try{n=JSON.parse(t)}catch{try{n=require("toml").parse(t)}catch{try{n=require("js-yaml").load(t)}catch(s){return void(this.debug&&console.error(`[FuncSpan ConfigLoader] Failed to parse ${e} as JSON, TOML, or YAML:`,s))}}}if(!n)return;n.runtime_mode===!0&&(this.runtimeModeEnabled=!0,this.debug&&console.log(`[FuncSpan ConfigLoader] Runtime mode ENABLED in ${e}`)),n.default&&this.directoryConfigs.set(i,n.default),n.files&&await this._expandFileGlobs(i,n.files,n.default||{}),n.functions&&this._storeFunctionConfigs(i,n.functions,n.default||{}),this.debug&&(console.log(`[FuncSpan ConfigLoader] Loaded config from ${e}`),console.log(`[FuncSpan ConfigLoader] Directory: ${i}`),console.log(`[FuncSpan ConfigLoader] Has default: ${!!n.default}`),console.log(`[FuncSpan ConfigLoader] File patterns: ${Object.keys(n.files||{}).length}`),console.log(`[FuncSpan ConfigLoader] Functions: ${Object.keys(n.functions||{}).length}`))}catch(t){this.debug&&console.error(`[FuncSpan ConfigLoader] Error loading ${e}:`,t)}}async _expandFileGlobs(e,t,i){for(const[n,s]of Object.entries(t))try{const u=F.join(e,n),o=await ue.glob(u,{absolute:!0,nodir:!0,ignore:["**/node_modules/**","**/.git/**"]});this.debug&&console.log(`[FuncSpan ConfigLoader] Pattern '${n}' matched ${o.length} files`);for(const d of o){const a=F.normalize(d),l=p.mergeConfigs(i,s);this.fileConfigs.set(a,l),this.debug&&o.length<=5&&console.log(`[FuncSpan ConfigLoader] - ${d}`)}}catch(u){this.debug&&console.error(`[FuncSpan ConfigLoader] Error expanding glob '${n}':`,u)}}_storeFunctionConfigs(e,t,i){for(const[n,s]of Object.entries(t)){const u=n.split("::");if(u.length!==2){this.debug&&console.warn(`[FuncSpan ConfigLoader] Invalid function pattern '${n}' (expected format: 'file.ts::functionName')`);continue}const[o,d]=u,a=F.normalize(F.join(e,o));this.functionConfigs.has(a)||this.functionConfigs.set(a,new Map);const l=this.functionConfigs.get(a),f=p.mergeConfigs(i,s);l.set(d,f),this.debug&&console.log(`[FuncSpan ConfigLoader] Function config: ${a}::${d}`)}}async _resolveInheritance(){}_getDirectoryConfig(e){let t=F.dirname(F.normalize(e));const i=[];for(;t&&t!==F.dirname(t);){const n=this.directoryConfigs.get(t);n&&i.unshift(n),t=F.dirname(t)}return i.reduce((n,s)=>p.mergeConfigs(n,s),{})}}const oe="__sf_globalConfigLoader";function se(){return globalThis[oe]??null}async function z(r,e){const t=new _e(r,e);(function(i){globalThis[oe]=i})(t),await t.loadAllConfigs()}function J(r,e){const t=se();return t?t.getConfig(r,e):(process.env.SF_DEBUG==="true"&&console.log("[FuncSpan ConfigLoader] Config loader not initialized, using default config (disabled)"),p.getDefaultConfig())}function V(){return se()!==null}const $e=["readFile","writeFile","appendFile","readdir","stat","lstat","fstat","access","open","close","read","write","chmod","mkdir","rmdir","unlink","rename"],Q=["lookup","resolve","resolve4","resolve6","resolveAny","resolveMx","resolveNs","resolveTxt","reverse"],be=["pbkdf2","randomBytes","scrypt","generateKeyPair"],Ce=["gzip","gunzip","deflate","inflate","deflateRaw","inflateRaw","brotliCompress","brotliDecompress"];let X=!1;function Fe(r){if(typeof r!="string")return!1;const e=process.env.SF_FUNCSPAN_JSONL_FILE;if(e&&r.includes(e))return!0;const t=process.env.SF_WORKER_POOL_JSONL_FILE;return!(!t||!r.includes(t))}let Y=!1;function Z(r){if(typeof r!="string")return!1;if(r==="localhost"||r==="127.0.0.1"||r==="::1")return!0;try{const e=process.env.API_GRAPHQL_ENDPOINT;if(e&&r===new URL(e).hostname)return!0}catch{}return!1}function Ne(){if(!Y)try{let r;if(typeof require>"u")return void(process.env.SF_DEBUG==="true"&&console.log("[WorkerPool] Skipping dns patching in pure ESM environment (require unavailable)"));try{r=require("node:dns")}catch(e){return void(process.env.SF_DEBUG==="true"&&console.log("[WorkerPool] Failed to require dns module:",e))}if(r.__sf_worker_pool_patched__)return;Object.defineProperty(r,"__sf_worker_pool_patched__",{value:!0,enumerable:!1,writable:!1,configurable:!1});for(const e of Q)if(typeof r[e]=="function"){const t=r[e];r[e]=function(...i){return Z(i[0])?t.apply(this,i):typeof i[i.length-1]=="function"?p.captureWorkerPoolOperation("dns",e,t,i,this):t.apply(this,i)},Object.defineProperty(r[e],"name",{value:e,writable:!1})}(function(e){if(!e.promises)return void(process.env.SF_DEBUG==="true"&&console.log("[WorkerPool] dns.promises not available, skipping"));if(!e.promises.__sf_worker_pool_patched__){Object.defineProperty(e.promises,"__sf_worker_pool_patched__",{value:!0,enumerable:!1,writable:!1,configurable:!1});for(const t of Q)if(typeof e.promises[t]=="function"){const i=e.promises[t];e.promises[t]=function(...n){return Z(n[0])?i.apply(this,n):p.captureWorkerPoolPromiseOperation("dns",t,i,n,this)},Object.defineProperty(e.promises[t],"name",{value:t,writable:!1})}process.env.SF_DEBUG==="true"&&console.log("[WorkerPool] dns.promises module patched successfully")}})(r),Y=!0,process.env.SF_DEBUG==="true"&&console.log("[WorkerPool] dns module patched successfully")}catch(r){console.error("[WorkerPool] Error patching dns module:",r)}}let ee=!1,te=!1,H=!1;function ne(){if(H)return;const r=process.env.SF_DEBUG==="true";r&&console.log("[WorkerPool] Initializing worker pool patching..."),p.isModuleTrackingEnabled("fs")&&(r&&console.log("[WorkerPool] Patching fs module..."),(function(){if(!X)try{const e=require("node:fs");if(e.__sf_worker_pool_patched__)return;Object.defineProperty(e,"__sf_worker_pool_patched__",{value:!0,enumerable:!1,writable:!1,configurable:!1});for(const t of $e)if(typeof e[t]=="function"){const i=e[t];e[t]=function(...n){return Fe(n[0])?i.apply(this,n):typeof n[n.length-1]=="function"?p.captureWorkerPoolOperation("fs",t,i,n,this):i.apply(this,n)},Object.defineProperty(e[t],"name",{value:t,writable:!1})}X=!0,process.env.SF_DEBUG==="true"&&console.log("[WorkerPool] fs module patched successfully")}catch(e){console.error("[WorkerPool] Error patching fs module:",e)}})()),p.isModuleTrackingEnabled("dns")&&(r&&console.log("[WorkerPool] Patching dns module..."),Ne()),p.isModuleTrackingEnabled("crypto")&&(r&&console.log("[WorkerPool] Patching crypto module..."),(function(){if(!ee)try{const e=require("node:crypto");if(e.__sf_worker_pool_patched__)return;Object.defineProperty(e,"__sf_worker_pool_patched__",{value:!0,enumerable:!1,writable:!1,configurable:!1});for(const t of be)if(typeof e[t]=="function"){const i=e[t];e[t]=function(...n){return typeof n[n.length-1]=="function"?p.captureWorkerPoolOperation("crypto",t,i,n,this):i.apply(this,n)},Object.defineProperty(e[t],"name",{value:t,writable:!1})}ee=!0,process.env.SF_DEBUG==="true"&&console.log("[WorkerPool] crypto module patched successfully")}catch(e){console.error("[WorkerPool] Error patching crypto module:",e)}})()),p.isModuleTrackingEnabled("zlib")&&(r&&console.log("[WorkerPool] Patching zlib module..."),(function(){if(!te)try{const e=require("node:zlib");if(e.__sf_worker_pool_patched__)return;Object.defineProperty(e,"__sf_worker_pool_patched__",{value:!0,enumerable:!1,writable:!1,configurable:!1});for(const t of Ce)if(typeof e[t]=="function"){const i=e[t];e[t]=function(...n){return typeof n[n.length-1]=="function"?p.captureWorkerPoolOperation("zlib",t,i,n,this):i.apply(this,n)},Object.defineProperty(e[t],"name",{value:t,writable:!1})}te=!0,process.env.SF_DEBUG==="true"&&console.log("[WorkerPool] zlib module patched successfully")}catch(e){console.error("[WorkerPool] Error patching zlib module:",e)}})()),H=!0,r&&console.log("[WorkerPool] Worker pool patching initialized")}function re(){return H}let q=!1,A=!1,M=null;function T(r){const e=c.getGlobalConfigUnsafe(),t=e?.sfDebug||!1;t&&console.log("[FuncSpan] captureSpanData called for:",{function:r.functionName,file:r.filePath,duration:`${r.duration}ms`,async:r.async,error:r.error,spanId:r.spanId});const i={functionName:r.functionName,filePath:r.filePath,metadata:r.metadata,args:r.args,result:r.result,error:r.error,duration:r.duration,durationNs:r.durationNs,async:r.async,spanId:r.spanId,parentSpanId:r.parentSpanId};process.env.SF_FUNCSPAN_CONSOLE_OUTPUT==="true"&&console.log(`
|
|
169
|
+
`,t=c.getConfig(),i=this.getVariables({serviceIdentifier:t.serviceIdentifier,serviceVersion:t.serviceVersion,serviceAdditionalMetadata:t.serviceAdditionalMetadata,gitSha:t.gitSha||"",gitOrg:t.gitOrg||void 0,gitRepo:t.gitRepo||void 0,gitProvider:t.gitProvider||void 0,serviceDisplayName:t.serviceDisplayName||void 0,infrastructureType:t.infrastructureType||void 0,infrastructureDetails:t.infrastructureDetails||void 0,setupInterceptorsFile:t.setupInterceptorsFile||void 0,setupInterceptorsLine:t.setupInterceptorsLine||void 0});p.nonBlockingPost(this.endpoint,this.operationName,e,i)}}class _e{rootPaths;fileConfigs=new Map;functionConfigs=new Map;directoryConfigs=new Map;hasSailfishFiles=!1;runtimeModeEnabled=!1;debug;constructor(e=[process.cwd()],t=!1){this.rootPaths=e,this.debug=t||process.env.SF_DEBUG==="true"}async loadAllConfigs(){this.debug&&console.log("[FuncSpan ConfigLoader] Scanning for .sailfish files in:",this.rootPaths);const e=[];for(const t of this.rootPaths)L.existsSync(t)?await this._walkDirectory(t,e):this.debug&&console.log(`[FuncSpan ConfigLoader] Root path does not exist: ${t}`);e.length>0?(this.hasSailfishFiles=!0,this.debug&&(console.log(`[FuncSpan ConfigLoader] Found ${e.length} .sailfish files:`),e.forEach(t=>console.log(`[FuncSpan ConfigLoader] - ${t}`)))):this.debug&&console.log("[FuncSpan ConfigLoader] No .sailfish files found - function spans disabled by default");for(const t of e)await this._loadConfigFile(t);await this._resolveInheritance(),this.debug&&console.log(`[FuncSpan ConfigLoader] Loaded ${this.fileConfigs.size} file configs, ${this.functionConfigs.size} function configs`)}getConfig(e,t){const i=this.hasSailfishFiles?p.getEnvConfig():p.getDefaultConfig(),n=this._getDirectoryConfig(e),s=F.normalize(e),u=this.fileConfigs.get(s)||{};let o={};if(t){const d=this.functionConfigs.get(s);d&&(o=d.get(t)||{})}return p.mergeConfigs(i,n,u,o)}hasRuntimeMode(){return this.runtimeModeEnabled}async _walkDirectory(e,t){try{const i=L.readdirSync(e,{withFileTypes:!0});for(const n of i){const s=F.join(e,n.name);n.isFile()&&n.name===".sailfish"?t.push(s):n.name==="node_modules"||n.isDirectory()&&n.name.startsWith(".")&&n.name!==".sailfish"||n.isDirectory()&&await this._walkDirectory(s,t)}}catch(i){this.debug&&console.error(`[FuncSpan ConfigLoader] Error walking directory ${e}:`,i)}}async _loadConfigFile(e){try{const t=L.readFileSync(e,"utf-8"),i=F.dirname(e);let n=null;try{n=JSON.parse(t)}catch{try{n=require("toml").parse(t)}catch{try{n=require("js-yaml").load(t)}catch(s){return void(this.debug&&console.error(`[FuncSpan ConfigLoader] Failed to parse ${e} as JSON, TOML, or YAML:`,s))}}}if(!n)return;n.runtime_mode===!0&&(this.runtimeModeEnabled=!0,this.debug&&console.log(`[FuncSpan ConfigLoader] Runtime mode ENABLED in ${e}`)),n.default&&this.directoryConfigs.set(i,n.default),n.files&&await this._expandFileGlobs(i,n.files,n.default||{}),n.functions&&this._storeFunctionConfigs(i,n.functions,n.default||{}),this.debug&&(console.log(`[FuncSpan ConfigLoader] Loaded config from ${e}`),console.log(`[FuncSpan ConfigLoader] Directory: ${i}`),console.log(`[FuncSpan ConfigLoader] Has default: ${!!n.default}`),console.log(`[FuncSpan ConfigLoader] File patterns: ${Object.keys(n.files||{}).length}`),console.log(`[FuncSpan ConfigLoader] Functions: ${Object.keys(n.functions||{}).length}`))}catch(t){this.debug&&console.error(`[FuncSpan ConfigLoader] Error loading ${e}:`,t)}}async _expandFileGlobs(e,t,i){for(const[n,s]of Object.entries(t))try{const u=F.join(e,n),o=await ue.glob(u,{absolute:!0,nodir:!0,ignore:["**/node_modules/**","**/.git/**"]});this.debug&&console.log(`[FuncSpan ConfigLoader] Pattern '${n}' matched ${o.length} files`);for(const d of o){const a=F.normalize(d),l=p.mergeConfigs(i,s);this.fileConfigs.set(a,l),this.debug&&o.length<=5&&console.log(`[FuncSpan ConfigLoader] - ${d}`)}}catch(u){this.debug&&console.error(`[FuncSpan ConfigLoader] Error expanding glob '${n}':`,u)}}_storeFunctionConfigs(e,t,i){for(const[n,s]of Object.entries(t)){const u=n.split("::");if(u.length!==2){this.debug&&console.warn(`[FuncSpan ConfigLoader] Invalid function pattern '${n}' (expected format: 'file.ts::functionName')`);continue}const[o,d]=u,a=F.normalize(F.join(e,o));this.functionConfigs.has(a)||this.functionConfigs.set(a,new Map);const l=this.functionConfigs.get(a),f=p.mergeConfigs(i,s);l.set(d,f),this.debug&&console.log(`[FuncSpan ConfigLoader] Function config: ${a}::${d}`)}}async _resolveInheritance(){}_getDirectoryConfig(e){let t=F.dirname(F.normalize(e));const i=[];for(;t&&t!==F.dirname(t);){const n=this.directoryConfigs.get(t);n&&i.unshift(n),t=F.dirname(t)}return i.reduce((n,s)=>p.mergeConfigs(n,s),{})}}const oe="__sf_globalConfigLoader";function se(){return globalThis[oe]??null}async function z(r,e){const t=new _e(r,e);(function(i){globalThis[oe]=i})(t),await t.loadAllConfigs()}function J(r,e){const t=se();return t?t.getConfig(r,e):(process.env.SF_DEBUG==="true"&&console.log("[FuncSpan ConfigLoader] Config loader not initialized, using default config (disabled)"),p.getDefaultConfig())}function V(){return se()!==null}const $e=["readFile","writeFile","appendFile","readdir","stat","lstat","fstat","access","open","close","read","write","chmod","mkdir","rmdir","unlink","rename"],Q=["lookup","resolve","resolve4","resolve6","resolveAny","resolveMx","resolveNs","resolveTxt","reverse"],be=["pbkdf2","randomBytes","scrypt","generateKeyPair"],Ce=["gzip","gunzip","deflate","inflate","deflateRaw","inflateRaw","brotliCompress","brotliDecompress"];let X=!1;function Fe(r){if(typeof r!="string")return!1;const e=process.env.SF_FUNCSPAN_JSONL_FILE;if(e&&r.includes(e))return!0;const t=process.env.SF_WORKER_POOL_JSONL_FILE;return!(!t||!r.includes(t))}let Y=!1;function Z(r){if(typeof r!="string")return!1;if(r==="localhost"||r==="127.0.0.1"||r==="::1")return!0;try{const e=process.env.API_GRAPHQL_ENDPOINT;if(e&&r===new URL(e).hostname)return!0}catch{}return!1}function Ne(){if(!Y)try{let r;if(typeof require>"u")return void(process.env.SF_DEBUG==="true"&&console.log("[WorkerPool] Skipping dns patching in pure ESM environment (require unavailable)"));try{r=require("node:dns")}catch(e){return void(process.env.SF_DEBUG==="true"&&console.log("[WorkerPool] Failed to require dns module:",e))}if(r.__sf_worker_pool_patched__)return;Object.defineProperty(r,"__sf_worker_pool_patched__",{value:!0,enumerable:!1,writable:!1,configurable:!1});for(const e of Q)if(typeof r[e]=="function"){const t=r[e];r[e]=function(...i){return p.isSendingInternalTelemetry()?t.apply(this,i):Z(i[0])?t.apply(this,i):typeof i[i.length-1]=="function"?p.captureWorkerPoolOperation("dns",e,t,i,this):t.apply(this,i)},Object.defineProperty(r[e],"name",{value:e,writable:!1})}(function(e){if(!e.promises)return void(process.env.SF_DEBUG==="true"&&console.log("[WorkerPool] dns.promises not available, skipping"));if(!e.promises.__sf_worker_pool_patched__){Object.defineProperty(e.promises,"__sf_worker_pool_patched__",{value:!0,enumerable:!1,writable:!1,configurable:!1});for(const t of Q)if(typeof e.promises[t]=="function"){const i=e.promises[t];e.promises[t]=function(...n){return p.isSendingInternalTelemetry()?i.apply(this,n):Z(n[0])?i.apply(this,n):p.captureWorkerPoolPromiseOperation("dns",t,i,n,this)},Object.defineProperty(e.promises[t],"name",{value:t,writable:!1})}process.env.SF_DEBUG==="true"&&console.log("[WorkerPool] dns.promises module patched successfully")}})(r),Y=!0,process.env.SF_DEBUG==="true"&&console.log("[WorkerPool] dns module patched successfully")}catch(r){console.error("[WorkerPool] Error patching dns module:",r)}}let ee=!1,te=!1,H=!1;function ne(){if(H)return;const r=process.env.SF_DEBUG==="true";r&&console.log("[WorkerPool] Initializing worker pool patching..."),p.isModuleTrackingEnabled("fs")&&(r&&console.log("[WorkerPool] Patching fs module..."),(function(){if(!X)try{const e=require("node:fs");if(e.__sf_worker_pool_patched__)return;Object.defineProperty(e,"__sf_worker_pool_patched__",{value:!0,enumerable:!1,writable:!1,configurable:!1});for(const t of $e)if(typeof e[t]=="function"){const i=e[t];e[t]=function(...n){return Fe(n[0])?i.apply(this,n):typeof n[n.length-1]=="function"?p.captureWorkerPoolOperation("fs",t,i,n,this):i.apply(this,n)},Object.defineProperty(e[t],"name",{value:t,writable:!1})}X=!0,process.env.SF_DEBUG==="true"&&console.log("[WorkerPool] fs module patched successfully")}catch(e){console.error("[WorkerPool] Error patching fs module:",e)}})()),p.isModuleTrackingEnabled("dns")&&(r&&console.log("[WorkerPool] Patching dns module..."),Ne()),p.isModuleTrackingEnabled("crypto")&&(r&&console.log("[WorkerPool] Patching crypto module..."),(function(){if(!ee)try{const e=require("node:crypto");if(e.__sf_worker_pool_patched__)return;Object.defineProperty(e,"__sf_worker_pool_patched__",{value:!0,enumerable:!1,writable:!1,configurable:!1});for(const t of be)if(typeof e[t]=="function"){const i=e[t];e[t]=function(...n){return typeof n[n.length-1]=="function"?p.captureWorkerPoolOperation("crypto",t,i,n,this):i.apply(this,n)},Object.defineProperty(e[t],"name",{value:t,writable:!1})}ee=!0,process.env.SF_DEBUG==="true"&&console.log("[WorkerPool] crypto module patched successfully")}catch(e){console.error("[WorkerPool] Error patching crypto module:",e)}})()),p.isModuleTrackingEnabled("zlib")&&(r&&console.log("[WorkerPool] Patching zlib module..."),(function(){if(!te)try{const e=require("node:zlib");if(e.__sf_worker_pool_patched__)return;Object.defineProperty(e,"__sf_worker_pool_patched__",{value:!0,enumerable:!1,writable:!1,configurable:!1});for(const t of Ce)if(typeof e[t]=="function"){const i=e[t];e[t]=function(...n){return typeof n[n.length-1]=="function"?p.captureWorkerPoolOperation("zlib",t,i,n,this):i.apply(this,n)},Object.defineProperty(e[t],"name",{value:t,writable:!1})}te=!0,process.env.SF_DEBUG==="true"&&console.log("[WorkerPool] zlib module patched successfully")}catch(e){console.error("[WorkerPool] Error patching zlib module:",e)}})()),H=!0,r&&console.log("[WorkerPool] Worker pool patching initialized")}function re(){return H}let q=!1,A=!1,M=null;function T(r){const e=c.getGlobalConfigUnsafe(),t=e?.sfDebug||!1;t&&console.log("[FuncSpan] captureSpanData called for:",{function:r.functionName,file:r.filePath,duration:`${r.duration}ms`,async:r.async,error:r.error,spanId:r.spanId});const i={functionName:r.functionName,filePath:r.filePath,metadata:r.metadata,args:r.args,result:r.result,error:r.error,duration:r.duration,durationNs:r.durationNs,async:r.async,spanId:r.spanId,parentSpanId:r.parentSpanId};process.env.SF_FUNCSPAN_CONSOLE_OUTPUT==="true"&&console.log(`
|
|
170
170
|
📊 Function Span:`,{function:`${r.functionName} (${r.filePath}:${r.metadata.line}:${r.metadata.column})`,duration:`${r.duration.toFixed(2)}ms`,arguments:r.args,result:r.error?`Error: ${r.error}`:r.result,spanId:r.spanId,parentSpanId:r.parentSpanId||"none"});const n=process.env.SF_FUNCSPAN_JSONL_FILE;if(n)try{const s=n==="true"||n==="1"?"funcspans.jsonl":n,u=Date.now(),o=process.hrtime.bigint(),d=BigInt(r.startTimeNs),a=Number(o-d)/1e6,l=new Date(u-a).toISOString(),f=JSON.stringify({timestamp:l,functionName:r.functionName,filePath:r.filePath,line:r.metadata.line,column:r.metadata.column,duration:r.duration,durationNs:r.durationNs,startTimeNs:r.startTimeNs,arguments:r.args,returnValue:r.error?{error:String(r.error)}:r.result,spanId:r.spanId,parentSpanId:r.parentSpanId,async:r.async,pid:r.pid,threadId:r.threadId})+`
|
|
171
171
|
`;x.appendFileSync(s,f,"utf-8")}catch(s){console.error("[FuncSpan] Error writing to JSONL file:",s)}if(t&&console.log("[FuncSpan] Sending function span to transmitter:",i),process.env.SF_FUNCSPAN_SKIP_BACKEND!=="true")try{(M||(M=new p.FunctionSpanTransmitter),M).send([i]),t&&console.log("[FuncSpan] Function span sent successfully")}catch(s){t&&console.error("[FuncSpan] Error sending function span:",s)}}exports.ContextManager=c.ContextManager,exports.getCurrentFunctionSpanId=c.getCurrentFunctionSpanId,exports.runWithContext=c.runWithContext,exports.clearFuncspanOverride=p.clearFuncspanOverride,exports.getDefaultConfig=p.getDefaultConfig,exports.getEnvConfig=p.getEnvConfig,exports.getFuncspanOverride=p.getFuncspanOverride,exports.parseHeaderOverride=p.parseHeaderOverride,exports.setFuncspanOverride=p.setFuncspanOverride,exports.isProductionEnvironment=h.isProductionEnvironment,exports.isRuntimeModeEnabled=h.isRuntimeModeEnabled,exports.shouldEnableRuntimeHooks=h.shouldEnableRuntimeHooks,exports.setSkipTypeScriptPlugin=O.setSkipTypeScriptPlugin,exports.transformFunctionSpans=O.transformFunctionSpans,exports.transformFunctionSpansSync=O.transformFunctionSpansSync,exports.addOrUpdateMetadata=function(r,e={},t,i=!1){const n=c.getConfig();new W(n.apiKey).addOrUpdateMetadata(r,e,t,i)},exports.captureFunctionSpan=function(r,e,t,i){const n=function(...s){const u=c.getGlobalConfigUnsafe(),o=u?.sfDebug||!1;o&&console.log(`[FuncSpan] captureFunctionSpan wrapper called for ${t}::${e}`);const d=(function(y,v){const _=p.getFuncspanOverride();if(_){const N=p.parseHeaderOverride(_);if(N)return process.env.SF_DEBUG==="true"&&console.log(`[FuncSpan] Using HTTP header override for ${y}::${v}`),N}try{return J(y,v)}catch{return{sample_rate:process.env.SF_FUNCSPAN_SAMPLE_RATE?parseFloat(process.env.SF_FUNCSPAN_SAMPLE_RATE):1,capture_arguments:!0,capture_return_value:!0,arg_limit_mb:1,return_limit_mb:1,enable_sampling:!1,autocapture_all_child_functions:!1,capture_sf_veritas:!1,parse_json_strings:!1}}})(t,e);if(o&&console.log(`[FuncSpan] Config for ${t}::${e}:`,d),d.enable_sampling&&d.sample_rate<1&&Math.random()>d.sample_rate)return o&&console.log(`[FuncSpan] Skipping ${e} due to sampling`),r.apply(this,s);if(d.sample_rate===0)return o&&console.log(`[FuncSpan] Skipping ${e} - sample_rate is 0.0`),r.apply(this,s);o&&console.log(`[FuncSpan] Capturing function span for ${e}`);const a=c.ContextManager.getInstance(),l=a.getCurrentFunctionSpanId(),f=c.v4();a.setCurrentFunctionSpanId(f);const m=process.hrtime.bigint(),S=Date.now();let g=null;d.capture_arguments&&(g={},i.paramNames.forEach((y,v)=>{v<s.length&&(g[y]=s[v])}),g&&d.arg_limit_mb>0&&(g=p.truncateToLimit(g,d.arg_limit_mb)));try{const y=r.apply(this,s);if(y&&typeof y.then=="function")return l?a.setCurrentFunctionSpanId(l):a.clearCurrentFunctionSpanId(),y.then(b=>{const I=process.hrtime.bigint(),C=Date.now(),D=Number(I-m);let G=null;return d.capture_return_value&&d.return_limit_mb>0&&(G=p.truncateToLimit(b,d.return_limit_mb)),T({functionName:e,filePath:t,metadata:i,args:g,result:G,error:null,duration:C-S,durationNs:D,startTimeNs:m.toString(),async:!0,spanId:f,parentSpanId:l,pid:process.pid,threadId:E.threadId}),b},b=>{const I=process.hrtime.bigint(),C=Date.now(),D=Number(I-m);throw T({functionName:e,filePath:t,metadata:i,args:g,result:null,error:b?.message||String(b),duration:C-S,durationNs:D,startTimeNs:m.toString(),async:!0,spanId:f,parentSpanId:l,pid:process.pid,threadId:E.threadId}),b});const v=process.hrtime.bigint(),_=Date.now(),N=Number(v-m);let $=null;return d.capture_return_value&&d.return_limit_mb>0&&($=p.truncateToLimit(y,d.return_limit_mb)),T({functionName:e,filePath:t,metadata:i,args:g,result:$,error:null,duration:_-S,durationNs:N,startTimeNs:m.toString(),async:!1,spanId:f,parentSpanId:l,pid:process.pid,threadId:E.threadId}),l?a.setCurrentFunctionSpanId(l):a.clearCurrentFunctionSpanId(),y}catch(y){const v=process.hrtime.bigint(),_=Date.now(),N=Number(v-m);throw T({functionName:e,filePath:t,metadata:i,args:g,result:null,error:y?.message||String(y),duration:_-S,durationNs:N,startTimeNs:m.toString(),async:!1,spanId:f,parentSpanId:l,pid:process.pid,threadId:E.threadId}),l?a.setCurrentFunctionSpanId(l):a.clearCurrentFunctionSpanId(),y}};Object.defineProperty(n,"name",{value:e,writable:!1});for(const s in r)r.hasOwnProperty(s)&&(n[s]=r[s]);return n},exports.getGlobalConfig=J,exports.identify=function(r,e,t,i=!1){const n=c.getConfig();new W(n.apiKey).identify(r,e,t,i)},exports.initializeConfigLoader=z,exports.initializeWorkerPoolPatching=ne,exports.isAlreadyInstrumented=function(r){return!!r.includes("captureFunctionSpan(")||!!r.includes("@sailfish-ai/sf-veritas")||!(!r.includes("/* @sailfish-instrumented */")&&!r.includes("// @sailfish-instrumented"))},exports.isConfigLoaderInitialized=V,exports.isSetupInterceptorsInitialized=function(){return q},exports.isWorkerPoolInitialized=re,exports.setupInterceptors=function(r){if(A)console.warn("[setupInterceptors] ⚠️ Recursive call detected and blocked!");else if(!q){A=!0;try{let e,t;const i=new Error().stack;if(i){const o=i.split(`
|
|
172
172
|
`)[2]||"",d=o.match(/\((.+):(\d+):\d+\)/)||o.match(/at (.+):(\d+):\d+/);d&&(e=d[1],t=parseInt(d[2],10))}if(!r||!r.apiKey){const o=`The required API Key is not provided: ${JSON.stringify(r)}`;console.error(o)}const{config:n}=c.getOrCreateConfig(r);if(e&&(n.setupInterceptorsFile=e),t&&(n.setupInterceptorsLine=t),n.sfDebug&&console.log("Updated configuration after applying options:",n),!n.apiKey||!n.apiGraphqlEndpoint){const o=`The required config is not provided: ${JSON.stringify(n)}`;throw console.error(o),new Error(o)}V()||z(void 0,n.sfDebug).catch(o=>{n.sfDebug&&console.error("[FuncSpan] Failed to initialize config loader:",o)}),process.env.SF_WORKER_POOL_DISABLED==="true"?n.sfDebug&&console.log("[setupInterceptors] Worker pool patching DISABLED (SF_WORKER_POOL_DISABLED=true)"):re()||(ne(),n.sfDebug&&console.log("[setupInterceptors] Worker pool patching initialized (DNS tracking enabled)"));const s=new B;s.setServiceUUID(n.serviceUUID),h.initializeLogInterceptor(s),(function(o=[]){const d=new Ie(o);new me().doSend(d.getExcludedDomains());const a=new ye,l=new Se;d.patchFetch(a,l),d.patchHttp(a,l)})(n.domainsToNotPropagateHeadersTo);const u=new ge;u.setServiceUUID(n.serviceUUID),h.initializeExceptionInterceptor(u),he(),new ve().send(),q=!0,n.sfDebug&&console.log("[setupInterceptors] ✅ Initialization complete")}finally{A=!1}}};
|
package/dist/sf-veritas.mjs
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var y = (r, t, e) =>
|
|
4
|
-
import { g as u, C as j, D as
|
|
5
|
-
import { r as
|
|
6
|
-
import { B as T, n as E, f as
|
|
7
|
-
import {
|
|
8
|
-
import { C as
|
|
9
|
-
import { d as
|
|
10
|
-
import { createRequire as
|
|
1
|
+
var fe = Object.defineProperty;
|
|
2
|
+
var he = (r, t, e) => t in r ? fe(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
|
|
3
|
+
var y = (r, t, e) => he(r, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
import { g as u, C as j, D as me, v as oe, b as q, c as ye, a as ae } from "./contextManager-Cx03mw7l.js";
|
|
5
|
+
import { r as ht } from "./contextManager-Cx03mw7l.js";
|
|
6
|
+
import { B as T, n as E, f as Se, g as ce, p as de, a as ue, b as Ie, m as U, c as A, i as X, d as ve, e as R, t as H, F as $e } from "./workerPoolSpanCapture-DEW40aIL.js";
|
|
7
|
+
import { h as yt, s as St } from "./workerPoolSpanCapture-DEW40aIL.js";
|
|
8
|
+
import { C as _e, i as _, a as be, h as P, b as Fe, c as Ne } from "./runtimeConfig-DndXTWki.js";
|
|
9
|
+
import { d as vt, e as $t, s as _t } from "./runtimeConfig-DndXTWki.js";
|
|
10
|
+
import { createRequire as De } from "node:module";
|
|
11
11
|
import * as M from "fs";
|
|
12
|
-
import { readFileSync as
|
|
13
|
-
import { s as
|
|
14
|
-
import * as
|
|
15
|
-
import { glob as
|
|
12
|
+
import { readFileSync as Pe, appendFileSync as Ee } from "fs";
|
|
13
|
+
import { s as we } from "./source-map-Cr6YkjTd.js";
|
|
14
|
+
import * as N from "path";
|
|
15
|
+
import { glob as Te } from "glob";
|
|
16
16
|
import { threadId as O } from "worker_threads";
|
|
17
|
-
import { s as
|
|
17
|
+
import { s as Ft, t as Nt, a as Dt } from "./funcSpanTransformer-Byqzu4B1.js";
|
|
18
18
|
class C extends T {
|
|
19
19
|
constructor() {
|
|
20
20
|
super(), this.setOperationName("IdentifyServiceDetails");
|
|
@@ -63,14 +63,14 @@ class C extends T {
|
|
|
63
63
|
E(this.endpoint, this.operationName, t, e);
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
function
|
|
66
|
+
function Ce(r) {
|
|
67
67
|
try {
|
|
68
68
|
return JSON.stringify(r), !0;
|
|
69
69
|
} catch {
|
|
70
70
|
return !1;
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
|
-
class
|
|
73
|
+
class Ue extends T {
|
|
74
74
|
constructor() {
|
|
75
75
|
super();
|
|
76
76
|
y(this, "serviceIdentifier", new C());
|
|
@@ -88,7 +88,7 @@ class Ce extends T {
|
|
|
88
88
|
if (!o) {
|
|
89
89
|
const c = (function(a) {
|
|
90
90
|
const l = {}, g = [];
|
|
91
|
-
if (a) for (const [f, h] of Object.entries(a))
|
|
91
|
+
if (a) for (const [f, h] of Object.entries(a)) Ce(h) ? l[f] = h : g.push(f);
|
|
92
92
|
return { traitsJson: JSON.stringify(l), excludedFields: g };
|
|
93
93
|
})(i);
|
|
94
94
|
o = c.traitsJson, d = c.excludedFields;
|
|
@@ -104,10 +104,10 @@ class Ce extends T {
|
|
|
104
104
|
`;
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
|
-
class
|
|
107
|
+
class le {
|
|
108
108
|
constructor(t) {
|
|
109
109
|
y(this, "metadataTransmitter");
|
|
110
|
-
this.apiKey = t, this.metadataTransmitter = new
|
|
110
|
+
this.apiKey = t, this.metadataTransmitter = new Ue();
|
|
111
111
|
}
|
|
112
112
|
identify(t, e, i, n = !1) {
|
|
113
113
|
e || i ? this.addOrUpdateMetadata(t, e, i, n) : this.addOrUpdateMetadata(t, {}, void 0, n);
|
|
@@ -164,7 +164,7 @@ class V extends T {
|
|
|
164
164
|
`;
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
|
-
class
|
|
167
|
+
class Re extends T {
|
|
168
168
|
constructor() {
|
|
169
169
|
super();
|
|
170
170
|
y(this, "serviceIdentifier", new C());
|
|
@@ -186,7 +186,7 @@ class Ue extends T {
|
|
|
186
186
|
}
|
|
187
187
|
async send(e, i) {
|
|
188
188
|
u().sfDebug && console.log(" SENDING EXCEPTION...");
|
|
189
|
-
const n = JSON.stringify(
|
|
189
|
+
const n = JSON.stringify(_e.encode(i)), o = this.normalizedSupplementalForGraphQL(), d = this.getVariables({ exceptionMessage: e, traceJson: n, reentrancyGuardPreactive: !1, library: u().packageLibraryType, version: u().version, ...o });
|
|
190
190
|
E(this.endpoint, this.operationName, this.getQuery(), d);
|
|
191
191
|
}
|
|
192
192
|
getQuery() {
|
|
@@ -221,19 +221,19 @@ class Ue extends T {
|
|
|
221
221
|
`;
|
|
222
222
|
}
|
|
223
223
|
}
|
|
224
|
-
const
|
|
224
|
+
const Y = "getting request source code";
|
|
225
225
|
var k = ((r) => (r.UNKNOWN = "unknown", r.ANONYMOUS = "anonymous", r.NOT_CAPTURED = "not captured", r))(k || {});
|
|
226
|
-
const x = "http:", G = "https:",
|
|
227
|
-
let
|
|
228
|
-
function
|
|
226
|
+
const x = "http:", G = "https:", Oe = De(import.meta.url);
|
|
227
|
+
let Z = !1;
|
|
228
|
+
function Le() {
|
|
229
229
|
const r = u().sfDebug;
|
|
230
|
-
if (
|
|
230
|
+
if (Z) return void (r && _("[patchNodeHttpInbound] Already installed, skipping."));
|
|
231
231
|
let t;
|
|
232
|
-
|
|
232
|
+
Z = !0;
|
|
233
233
|
try {
|
|
234
|
-
t =
|
|
234
|
+
t = Oe("node:http"), r && _("[patchNodeHttpInbound] node:http required successfully.");
|
|
235
235
|
} catch (n) {
|
|
236
|
-
return void
|
|
236
|
+
return void be("Failed to require node:http:", n);
|
|
237
237
|
}
|
|
238
238
|
if (!t?.Server?.prototype) return void (r && _("[patchNodeHttpInbound] http.Server.prototype not found."));
|
|
239
239
|
const e = t.Server.prototype, i = e.emit;
|
|
@@ -259,13 +259,13 @@ function Oe() {
|
|
|
259
259
|
});
|
|
260
260
|
if (!l) return h();
|
|
261
261
|
try {
|
|
262
|
-
return
|
|
262
|
+
return Se.run(l, () => h());
|
|
263
263
|
} catch {
|
|
264
264
|
return h();
|
|
265
265
|
}
|
|
266
266
|
}) : r && _("[patchNodeHttpInbound] Already patched, skipping.");
|
|
267
267
|
}
|
|
268
|
-
class
|
|
268
|
+
class Ae extends V {
|
|
269
269
|
constructor() {
|
|
270
270
|
super(), this.setOperationName("DomainsToNotPassHeaderTo");
|
|
271
271
|
}
|
|
@@ -289,7 +289,7 @@ class Le extends V {
|
|
|
289
289
|
E(this.endpoint, this.operationName, e, i);
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
|
-
class
|
|
292
|
+
class ke extends T {
|
|
293
293
|
constructor() {
|
|
294
294
|
super();
|
|
295
295
|
y(this, "serviceIdentifier", new C());
|
|
@@ -333,7 +333,7 @@ class Ae extends T {
|
|
|
333
333
|
`;
|
|
334
334
|
}
|
|
335
335
|
}
|
|
336
|
-
class
|
|
336
|
+
class qe extends T {
|
|
337
337
|
constructor() {
|
|
338
338
|
super();
|
|
339
339
|
y(this, "serviceIdentifier", new C());
|
|
@@ -361,7 +361,7 @@ class ke extends T {
|
|
|
361
361
|
}
|
|
362
362
|
}
|
|
363
363
|
const K = [400, 403];
|
|
364
|
-
class
|
|
364
|
+
class He {
|
|
365
365
|
constructor(t = []) {
|
|
366
366
|
y(this, "HEADER_TRACING", "X-Sf3-Rid");
|
|
367
367
|
y(this, "HEADER_LOG_GUARD", "reentrancy_guard_logging_preactive");
|
|
@@ -397,8 +397,8 @@ class qe {
|
|
|
397
397
|
if (t.includes("://")) return { originalPos: n };
|
|
398
398
|
const o = t + ".map";
|
|
399
399
|
try {
|
|
400
|
-
const d = JSON.parse(
|
|
401
|
-
let s = (await new
|
|
400
|
+
const d = JSON.parse(Pe(o, "utf-8"));
|
|
401
|
+
let s = (await new we.SourceMapConsumer(d)).originalPositionFor({ line: e, column: i });
|
|
402
402
|
s.source && (n = s);
|
|
403
403
|
} catch (d) {
|
|
404
404
|
u().sfDebug && console.error(`Could not read/parse map file at ${o}:`, d);
|
|
@@ -408,8 +408,8 @@ class qe {
|
|
|
408
408
|
captureFirstUserLines(t, e = 10, i = !1) {
|
|
409
409
|
const n = u().sfDebug ? 10 : e, o = Error.stackTraceLimit;
|
|
410
410
|
Error.stackTraceLimit = Math.max(o, n);
|
|
411
|
-
const d = new Error(
|
|
412
|
-
|
|
411
|
+
const d = new Error(Y);
|
|
412
|
+
Y in Error && Error.captureStackTrace(d, this.captureFirstUserLines);
|
|
413
413
|
const s = d.stack || "";
|
|
414
414
|
Error.stackTraceLimit = o;
|
|
415
415
|
const c = s.split(`
|
|
@@ -432,19 +432,19 @@ class qe {
|
|
|
432
432
|
t.set(this.HEADER_LOG_GUARD, "true"), t.set(this.HEADER_PRINT_GUARD, "true"), t.set(this.HEADER_EXCEPTION_GUARD, "true");
|
|
433
433
|
}
|
|
434
434
|
shouldPropagateHeaders(t) {
|
|
435
|
-
return !
|
|
435
|
+
return !me.some((e) => new RegExp(`^${e.replace(/\*/g, ".*")}$`).test(t));
|
|
436
436
|
}
|
|
437
437
|
addTracingHeaders(t, e) {
|
|
438
438
|
const i = new URL(e).hostname, n = this.shouldPropagateHeaders(i);
|
|
439
439
|
return n ? this.addTracingHeader(t, e) : u().sfDebug && console.error(`[RequestInterceptor] Excluded domain: ${i}`), n;
|
|
440
440
|
}
|
|
441
441
|
addTracingHeader(t, e) {
|
|
442
|
-
const i =
|
|
442
|
+
const i = ce();
|
|
443
443
|
if (i) {
|
|
444
|
-
const s =
|
|
444
|
+
const s = de(i);
|
|
445
445
|
if (s && s.sample_rate === 0) return void (u().sfDebug && console.log(`[RequestInterceptor] Function span tracking disabled (sample_rate=0), skipping tracing header for ${e}`));
|
|
446
446
|
}
|
|
447
|
-
const n = this.contextManager.getOrSetSfTraceId(), o = this.contextManager.getOrSetPageVisitUUID(), d =
|
|
447
|
+
const n = this.contextManager.getOrSetSfTraceId(), o = this.contextManager.getOrSetPageVisitUUID(), d = oe();
|
|
448
448
|
t.set(this.HEADER_TRACING, `${n}/${o}/${d}`), u().sfDebug && console.log(`[RequestInterceptor] Added tracing header for ${e}`);
|
|
449
449
|
}
|
|
450
450
|
patchFetch(t, e) {
|
|
@@ -468,14 +468,14 @@ class qe {
|
|
|
468
468
|
const { sessionId: I, pageVisitId: v, requestId: D } = this.extractIdsFromTraceHeader(d), $ = u(), b = { apiKey: $.apiKey, requestId: D, pageVisitId: v, recordingSessionId: I, serviceUuid: $.serviceUUID, timestampStart: s.toString(), timestampEnd: m.toString(), responseCode: h.status, success: !0, error: null, url: c, method: f.method || "GET", retryWithoutTraceId: p, parentSpanId: q() };
|
|
469
469
|
if ($.captureRequestHeaders) {
|
|
470
470
|
const S = {};
|
|
471
|
-
d.forEach((
|
|
472
|
-
S[w] =
|
|
471
|
+
d.forEach((F, w) => {
|
|
472
|
+
S[w] = F;
|
|
473
473
|
}), b.requestHeaders = S;
|
|
474
474
|
}
|
|
475
475
|
if ($.captureResponseHeaders) {
|
|
476
476
|
const S = {};
|
|
477
|
-
h.headers.forEach((
|
|
478
|
-
S[w] =
|
|
477
|
+
h.headers.forEach((F, w) => {
|
|
478
|
+
S[w] = F;
|
|
479
479
|
}), b.responseHeaders = S;
|
|
480
480
|
}
|
|
481
481
|
if ($.captureRequestBody && o?.body) try {
|
|
@@ -484,8 +484,8 @@ class qe {
|
|
|
484
484
|
} catch {
|
|
485
485
|
}
|
|
486
486
|
if ($.captureResponseBody) try {
|
|
487
|
-
const S = h.clone(),
|
|
488
|
-
b.responseBody =
|
|
487
|
+
const S = h.clone(), F = await S.text();
|
|
488
|
+
b.responseBody = F.length > $.responseBodyLimitBytes ? F.substring(0, $.responseBodyLimitBytes) + "...[truncated]" : F;
|
|
489
489
|
} catch {
|
|
490
490
|
}
|
|
491
491
|
return e.doSend(b), h;
|
|
@@ -559,7 +559,7 @@ class qe {
|
|
|
559
559
|
return [...this.contextManager.getExcludedDomains()];
|
|
560
560
|
}
|
|
561
561
|
}
|
|
562
|
-
class
|
|
562
|
+
class Me extends V {
|
|
563
563
|
constructor() {
|
|
564
564
|
super(), this.setOperationName("UpdateServiceDetails");
|
|
565
565
|
}
|
|
@@ -607,7 +607,7 @@ class He extends V {
|
|
|
607
607
|
E(this.endpoint, this.operationName, t, i);
|
|
608
608
|
}
|
|
609
609
|
}
|
|
610
|
-
class
|
|
610
|
+
class xe {
|
|
611
611
|
constructor(t = [process.cwd()], e = !1) {
|
|
612
612
|
y(this, "rootPaths");
|
|
613
613
|
y(this, "fileConfigs", /* @__PURE__ */ new Map());
|
|
@@ -627,7 +627,7 @@ class Me {
|
|
|
627
627
|
await this._resolveInheritance(), this.debug && console.log(`[FuncSpan ConfigLoader] Loaded ${this.fileConfigs.size} file configs, ${this.functionConfigs.size} function configs`);
|
|
628
628
|
}
|
|
629
629
|
getConfig(t, e) {
|
|
630
|
-
const i = this.hasSailfishFiles ?
|
|
630
|
+
const i = this.hasSailfishFiles ? Ie() : ue(), n = this._getDirectoryConfig(t), o = N.normalize(t), d = this.fileConfigs.get(o) || {};
|
|
631
631
|
let s = {};
|
|
632
632
|
if (e) {
|
|
633
633
|
const c = this.functionConfigs.get(o);
|
|
@@ -642,7 +642,7 @@ class Me {
|
|
|
642
642
|
try {
|
|
643
643
|
const i = M.readdirSync(t, { withFileTypes: !0 });
|
|
644
644
|
for (const n of i) {
|
|
645
|
-
const o =
|
|
645
|
+
const o = N.join(t, n.name);
|
|
646
646
|
n.isFile() && n.name === ".sailfish" ? e.push(o) : n.name === "node_modules" || n.isDirectory() && n.name.startsWith(".") && n.name !== ".sailfish" || n.isDirectory() && await this._walkDirectory(o, e);
|
|
647
647
|
}
|
|
648
648
|
} catch (i) {
|
|
@@ -651,7 +651,7 @@ class Me {
|
|
|
651
651
|
}
|
|
652
652
|
async _loadConfigFile(t) {
|
|
653
653
|
try {
|
|
654
|
-
const e = M.readFileSync(t, "utf-8"), i =
|
|
654
|
+
const e = M.readFileSync(t, "utf-8"), i = N.dirname(t);
|
|
655
655
|
let n = null;
|
|
656
656
|
try {
|
|
657
657
|
n = JSON.parse(e);
|
|
@@ -674,10 +674,10 @@ class Me {
|
|
|
674
674
|
}
|
|
675
675
|
async _expandFileGlobs(t, e, i) {
|
|
676
676
|
for (const [n, o] of Object.entries(e)) try {
|
|
677
|
-
const d =
|
|
677
|
+
const d = N.join(t, n), s = await Te(d, { absolute: !0, nodir: !0, ignore: ["**/node_modules/**", "**/.git/**"] });
|
|
678
678
|
this.debug && console.log(`[FuncSpan ConfigLoader] Pattern '${n}' matched ${s.length} files`);
|
|
679
679
|
for (const c of s) {
|
|
680
|
-
const a =
|
|
680
|
+
const a = N.normalize(c), l = U(i, o);
|
|
681
681
|
this.fileConfigs.set(a, l), this.debug && s.length <= 5 && console.log(`[FuncSpan ConfigLoader] - ${c}`);
|
|
682
682
|
}
|
|
683
683
|
} catch (d) {
|
|
@@ -691,7 +691,7 @@ class Me {
|
|
|
691
691
|
this.debug && console.warn(`[FuncSpan ConfigLoader] Invalid function pattern '${n}' (expected format: 'file.ts::functionName')`);
|
|
692
692
|
continue;
|
|
693
693
|
}
|
|
694
|
-
const [s, c] = d, a =
|
|
694
|
+
const [s, c] = d, a = N.normalize(N.join(t, s));
|
|
695
695
|
this.functionConfigs.has(a) || this.functionConfigs.set(a, /* @__PURE__ */ new Map());
|
|
696
696
|
const l = this.functionConfigs.get(a), g = U(i, o);
|
|
697
697
|
l.set(c, g), this.debug && console.log(`[FuncSpan ConfigLoader] Function config: ${a}::${c}`);
|
|
@@ -700,43 +700,43 @@ class Me {
|
|
|
700
700
|
async _resolveInheritance() {
|
|
701
701
|
}
|
|
702
702
|
_getDirectoryConfig(t) {
|
|
703
|
-
let e =
|
|
703
|
+
let e = N.dirname(N.normalize(t));
|
|
704
704
|
const i = [];
|
|
705
|
-
for (; e && e !==
|
|
705
|
+
for (; e && e !== N.dirname(e); ) {
|
|
706
706
|
const n = this.directoryConfigs.get(e);
|
|
707
|
-
n && i.unshift(n), e =
|
|
707
|
+
n && i.unshift(n), e = N.dirname(e);
|
|
708
708
|
}
|
|
709
709
|
return i.reduce((n, o) => U(n, o), {});
|
|
710
710
|
}
|
|
711
711
|
}
|
|
712
|
-
const
|
|
713
|
-
function
|
|
714
|
-
return globalThis[
|
|
712
|
+
const pe = "__sf_globalConfigLoader";
|
|
713
|
+
function ge() {
|
|
714
|
+
return globalThis[pe] ?? null;
|
|
715
715
|
}
|
|
716
|
-
async function
|
|
717
|
-
const e = new
|
|
716
|
+
async function Ge(r, t) {
|
|
717
|
+
const e = new xe(r, t);
|
|
718
718
|
(function(i) {
|
|
719
|
-
globalThis[
|
|
719
|
+
globalThis[pe] = i;
|
|
720
720
|
})(e), await e.loadAllConfigs();
|
|
721
721
|
}
|
|
722
|
-
function
|
|
723
|
-
const e =
|
|
724
|
-
return e ? e.getConfig(r, t) : (process.env.SF_DEBUG === "true" && console.log("[FuncSpan ConfigLoader] Config loader not initialized, using default config (disabled)"),
|
|
722
|
+
function Ke(r, t) {
|
|
723
|
+
const e = ge();
|
|
724
|
+
return e ? e.getConfig(r, t) : (process.env.SF_DEBUG === "true" && console.log("[FuncSpan ConfigLoader] Config loader not initialized, using default config (disabled)"), ue());
|
|
725
725
|
}
|
|
726
|
-
function
|
|
727
|
-
return
|
|
726
|
+
function We() {
|
|
727
|
+
return ge() !== null;
|
|
728
728
|
}
|
|
729
|
-
const
|
|
730
|
-
let
|
|
731
|
-
function
|
|
729
|
+
const Be = ["readFile", "writeFile", "appendFile", "readdir", "stat", "lstat", "fstat", "access", "open", "close", "read", "write", "chmod", "mkdir", "rmdir", "unlink", "rename"], ee = ["lookup", "resolve", "resolve4", "resolve6", "resolveAny", "resolveMx", "resolveNs", "resolveTxt", "reverse"], ze = ["pbkdf2", "randomBytes", "scrypt", "generateKeyPair"], Je = ["gzip", "gunzip", "deflate", "inflate", "deflateRaw", "inflateRaw", "brotliCompress", "brotliDecompress"];
|
|
730
|
+
let te = !1;
|
|
731
|
+
function je(r) {
|
|
732
732
|
if (typeof r != "string") return !1;
|
|
733
733
|
const t = process.env.SF_FUNCSPAN_JSONL_FILE;
|
|
734
734
|
if (t && r.includes(t)) return !0;
|
|
735
735
|
const e = process.env.SF_WORKER_POOL_JSONL_FILE;
|
|
736
736
|
return !(!e || !r.includes(e));
|
|
737
737
|
}
|
|
738
|
-
let
|
|
739
|
-
function
|
|
738
|
+
let ne = !1;
|
|
739
|
+
function re(r) {
|
|
740
740
|
if (typeof r != "string") return !1;
|
|
741
741
|
if (r === "localhost" || r === "127.0.0.1" || r === "::1") return !0;
|
|
742
742
|
try {
|
|
@@ -747,8 +747,8 @@ function ne(r) {
|
|
|
747
747
|
}
|
|
748
748
|
return !1;
|
|
749
749
|
}
|
|
750
|
-
function
|
|
751
|
-
if (!
|
|
750
|
+
function Ve() {
|
|
751
|
+
if (!ne) try {
|
|
752
752
|
let r;
|
|
753
753
|
if (typeof require > "u") return void (process.env.SF_DEBUG === "true" && console.log("[WorkerPool] Skipping dns patching in pure ESM environment (require unavailable)"));
|
|
754
754
|
try {
|
|
@@ -758,85 +758,85 @@ function je() {
|
|
|
758
758
|
}
|
|
759
759
|
if (r.__sf_worker_pool_patched__) return;
|
|
760
760
|
Object.defineProperty(r, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
761
|
-
for (const t of
|
|
761
|
+
for (const t of ee) if (typeof r[t] == "function") {
|
|
762
762
|
const e = r[t];
|
|
763
763
|
r[t] = function(...i) {
|
|
764
|
-
return
|
|
764
|
+
return X() ? e.apply(this, i) : re(i[0]) ? e.apply(this, i) : typeof i[i.length - 1] == "function" ? A("dns", t, e, i, this) : e.apply(this, i);
|
|
765
765
|
}, Object.defineProperty(r[t], "name", { value: t, writable: !1 });
|
|
766
766
|
}
|
|
767
767
|
(function(t) {
|
|
768
768
|
if (!t.promises) return void (process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns.promises not available, skipping"));
|
|
769
769
|
if (!t.promises.__sf_worker_pool_patched__) {
|
|
770
770
|
Object.defineProperty(t.promises, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
771
|
-
for (const e of
|
|
771
|
+
for (const e of ee) if (typeof t.promises[e] == "function") {
|
|
772
772
|
const i = t.promises[e];
|
|
773
773
|
t.promises[e] = function(...n) {
|
|
774
|
-
return
|
|
774
|
+
return X() ? i.apply(this, n) : re(n[0]) ? i.apply(this, n) : ve("dns", e, i, n, this);
|
|
775
775
|
}, Object.defineProperty(t.promises[e], "name", { value: e, writable: !1 });
|
|
776
776
|
}
|
|
777
777
|
process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns.promises module patched successfully");
|
|
778
778
|
}
|
|
779
|
-
})(r),
|
|
779
|
+
})(r), ne = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns module patched successfully");
|
|
780
780
|
} catch (r) {
|
|
781
781
|
console.error("[WorkerPool] Error patching dns module:", r);
|
|
782
782
|
}
|
|
783
783
|
}
|
|
784
|
-
let
|
|
785
|
-
function
|
|
784
|
+
let ie = !1, se = !1, z = !1;
|
|
785
|
+
function Qe() {
|
|
786
786
|
if (z) return;
|
|
787
787
|
const r = process.env.SF_DEBUG === "true";
|
|
788
788
|
r && console.log("[WorkerPool] Initializing worker pool patching..."), R("fs") && (r && console.log("[WorkerPool] Patching fs module..."), (function() {
|
|
789
|
-
if (!
|
|
789
|
+
if (!te) try {
|
|
790
790
|
const t = require("node:fs");
|
|
791
791
|
if (t.__sf_worker_pool_patched__) return;
|
|
792
792
|
Object.defineProperty(t, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
793
|
-
for (const e of
|
|
793
|
+
for (const e of Be) if (typeof t[e] == "function") {
|
|
794
794
|
const i = t[e];
|
|
795
795
|
t[e] = function(...n) {
|
|
796
|
-
return
|
|
796
|
+
return je(n[0]) ? i.apply(this, n) : typeof n[n.length - 1] == "function" ? A("fs", e, i, n, this) : i.apply(this, n);
|
|
797
797
|
}, Object.defineProperty(t[e], "name", { value: e, writable: !1 });
|
|
798
798
|
}
|
|
799
|
-
|
|
799
|
+
te = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] fs module patched successfully");
|
|
800
800
|
} catch (t) {
|
|
801
801
|
console.error("[WorkerPool] Error patching fs module:", t);
|
|
802
802
|
}
|
|
803
|
-
})()), R("dns") && (r && console.log("[WorkerPool] Patching dns module..."),
|
|
804
|
-
if (!
|
|
803
|
+
})()), R("dns") && (r && console.log("[WorkerPool] Patching dns module..."), Ve()), R("crypto") && (r && console.log("[WorkerPool] Patching crypto module..."), (function() {
|
|
804
|
+
if (!ie) try {
|
|
805
805
|
const t = require("node:crypto");
|
|
806
806
|
if (t.__sf_worker_pool_patched__) return;
|
|
807
807
|
Object.defineProperty(t, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
808
|
-
for (const e of
|
|
808
|
+
for (const e of ze) if (typeof t[e] == "function") {
|
|
809
809
|
const i = t[e];
|
|
810
810
|
t[e] = function(...n) {
|
|
811
811
|
return typeof n[n.length - 1] == "function" ? A("crypto", e, i, n, this) : i.apply(this, n);
|
|
812
812
|
}, Object.defineProperty(t[e], "name", { value: e, writable: !1 });
|
|
813
813
|
}
|
|
814
|
-
|
|
814
|
+
ie = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] crypto module patched successfully");
|
|
815
815
|
} catch (t) {
|
|
816
816
|
console.error("[WorkerPool] Error patching crypto module:", t);
|
|
817
817
|
}
|
|
818
818
|
})()), R("zlib") && (r && console.log("[WorkerPool] Patching zlib module..."), (function() {
|
|
819
|
-
if (!
|
|
819
|
+
if (!se) try {
|
|
820
820
|
const t = require("node:zlib");
|
|
821
821
|
if (t.__sf_worker_pool_patched__) return;
|
|
822
822
|
Object.defineProperty(t, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
823
|
-
for (const e of
|
|
823
|
+
for (const e of Je) if (typeof t[e] == "function") {
|
|
824
824
|
const i = t[e];
|
|
825
825
|
t[e] = function(...n) {
|
|
826
826
|
return typeof n[n.length - 1] == "function" ? A("zlib", e, i, n, this) : i.apply(this, n);
|
|
827
827
|
}, Object.defineProperty(t[e], "name", { value: e, writable: !1 });
|
|
828
828
|
}
|
|
829
|
-
|
|
829
|
+
se = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] zlib module patched successfully");
|
|
830
830
|
} catch (t) {
|
|
831
831
|
console.error("[WorkerPool] Error patching zlib module:", t);
|
|
832
832
|
}
|
|
833
833
|
})()), z = !0, r && console.log("[WorkerPool] Worker pool patching initialized");
|
|
834
834
|
}
|
|
835
|
-
function
|
|
835
|
+
function Xe() {
|
|
836
836
|
return z;
|
|
837
837
|
}
|
|
838
838
|
let J = !1, W = !1;
|
|
839
|
-
function
|
|
839
|
+
function at(r) {
|
|
840
840
|
if (W) console.warn("[setupInterceptors] ⚠️ Recursive call detected and blocked!");
|
|
841
841
|
else if (!J) {
|
|
842
842
|
W = !0;
|
|
@@ -852,52 +852,52 @@ function ot(r) {
|
|
|
852
852
|
const s = `The required API Key is not provided: ${JSON.stringify(r)}`;
|
|
853
853
|
console.error(s);
|
|
854
854
|
}
|
|
855
|
-
const { config: n } =
|
|
855
|
+
const { config: n } = ye(r);
|
|
856
856
|
if (t && (n.setupInterceptorsFile = t), e && (n.setupInterceptorsLine = e), n.sfDebug && console.log("Updated configuration after applying options:", n), !n.apiKey || !n.apiGraphqlEndpoint) {
|
|
857
857
|
const s = `The required config is not provided: ${JSON.stringify(n)}`;
|
|
858
858
|
throw console.error(s), new Error(s);
|
|
859
859
|
}
|
|
860
|
-
|
|
860
|
+
We() || Ge(void 0, n.sfDebug).catch((s) => {
|
|
861
861
|
n.sfDebug && console.error("[FuncSpan] Failed to initialize config loader:", s);
|
|
862
|
-
}), process.env.SF_WORKER_POOL_DISABLED === "true" ? n.sfDebug && console.log("[setupInterceptors] Worker pool patching DISABLED (SF_WORKER_POOL_DISABLED=true)") :
|
|
862
|
+
}), process.env.SF_WORKER_POOL_DISABLED === "true" ? n.sfDebug && console.log("[setupInterceptors] Worker pool patching DISABLED (SF_WORKER_POOL_DISABLED=true)") : Xe() || (Qe(), n.sfDebug && console.log("[setupInterceptors] Worker pool patching initialized (DNS tracking enabled)"));
|
|
863
863
|
const o = new V();
|
|
864
|
-
o.setServiceUUID(n.serviceUUID),
|
|
865
|
-
const c = new
|
|
866
|
-
new
|
|
867
|
-
const a = new
|
|
864
|
+
o.setServiceUUID(n.serviceUUID), Fe(o), (function(s = []) {
|
|
865
|
+
const c = new He(s);
|
|
866
|
+
new Ae().doSend(c.getExcludedDomains());
|
|
867
|
+
const a = new ke(), l = new qe();
|
|
868
868
|
c.patchFetch(a, l), c.patchHttp(a, l);
|
|
869
869
|
})(n.domainsToNotPropagateHeadersTo);
|
|
870
|
-
const d = new
|
|
871
|
-
d.setServiceUUID(n.serviceUUID), Ne(d),
|
|
870
|
+
const d = new Re();
|
|
871
|
+
d.setServiceUUID(n.serviceUUID), Ne(d), Le(), new Me().send(), J = !0, n.sfDebug && console.log("[setupInterceptors] ✅ Initialization complete");
|
|
872
872
|
} finally {
|
|
873
873
|
W = !1;
|
|
874
874
|
}
|
|
875
875
|
}
|
|
876
876
|
}
|
|
877
|
-
function
|
|
877
|
+
function ct() {
|
|
878
878
|
return J;
|
|
879
879
|
}
|
|
880
|
-
function
|
|
880
|
+
function dt(r, t, e, i = !1) {
|
|
881
881
|
const n = u();
|
|
882
|
-
new
|
|
882
|
+
new le(n.apiKey).identify(r, t, e, i);
|
|
883
883
|
}
|
|
884
|
-
function
|
|
884
|
+
function ut(r, t = {}, e, i = !1) {
|
|
885
885
|
const n = u();
|
|
886
|
-
new
|
|
886
|
+
new le(n.apiKey).addOrUpdateMetadata(r, t, e, i);
|
|
887
887
|
}
|
|
888
888
|
let B = null;
|
|
889
|
-
function
|
|
889
|
+
function lt(r, t, e, i) {
|
|
890
890
|
const n = function(...o) {
|
|
891
|
-
const d =
|
|
891
|
+
const d = ae(), s = d?.sfDebug || !1;
|
|
892
892
|
s && console.log(`[FuncSpan] captureFunctionSpan wrapper called for ${e}::${t}`);
|
|
893
893
|
const c = (function(m, I) {
|
|
894
|
-
const v =
|
|
894
|
+
const v = ce();
|
|
895
895
|
if (v) {
|
|
896
|
-
const D =
|
|
896
|
+
const D = de(v);
|
|
897
897
|
if (D) return process.env.SF_DEBUG === "true" && console.log(`[FuncSpan] Using HTTP header override for ${m}::${I}`), D;
|
|
898
898
|
}
|
|
899
899
|
try {
|
|
900
|
-
return
|
|
900
|
+
return Ke(m, I);
|
|
901
901
|
} catch {
|
|
902
902
|
return { sample_rate: process.env.SF_FUNCSPAN_SAMPLE_RATE ? parseFloat(process.env.SF_FUNCSPAN_SAMPLE_RATE) : 1, capture_arguments: !0, capture_return_value: !0, arg_limit_mb: 1, return_limit_mb: 1, enable_sampling: !1, autocapture_all_child_functions: !1, capture_sf_veritas: !1, parse_json_strings: !1 };
|
|
903
903
|
}
|
|
@@ -905,7 +905,7 @@ function ut(r, t, e, i) {
|
|
|
905
905
|
if (s && console.log(`[FuncSpan] Config for ${e}::${t}:`, c), c.enable_sampling && c.sample_rate < 1 && Math.random() > c.sample_rate) return s && console.log(`[FuncSpan] Skipping ${t} due to sampling`), r.apply(this, o);
|
|
906
906
|
if (c.sample_rate === 0) return s && console.log(`[FuncSpan] Skipping ${t} - sample_rate is 0.0`), r.apply(this, o);
|
|
907
907
|
s && console.log(`[FuncSpan] Capturing function span for ${t}`);
|
|
908
|
-
const a = j.getInstance(), l = a.getCurrentFunctionSpanId(), g =
|
|
908
|
+
const a = j.getInstance(), l = a.getCurrentFunctionSpanId(), g = oe();
|
|
909
909
|
a.setCurrentFunctionSpanId(g);
|
|
910
910
|
const f = process.hrtime.bigint(), h = Date.now();
|
|
911
911
|
let p = null;
|
|
@@ -915,12 +915,12 @@ function ut(r, t, e, i) {
|
|
|
915
915
|
try {
|
|
916
916
|
const m = r.apply(this, o);
|
|
917
917
|
if (m && typeof m.then == "function") return l ? a.setCurrentFunctionSpanId(l) : a.clearCurrentFunctionSpanId(), m.then((b) => {
|
|
918
|
-
const S = process.hrtime.bigint(),
|
|
918
|
+
const S = process.hrtime.bigint(), F = Date.now(), w = Number(S - f);
|
|
919
919
|
let Q = null;
|
|
920
|
-
return c.capture_return_value && c.return_limit_mb > 0 && (Q = H(b, c.return_limit_mb)), L({ functionName: t, filePath: e, metadata: i, args: p, result: Q, error: null, duration:
|
|
920
|
+
return c.capture_return_value && c.return_limit_mb > 0 && (Q = H(b, c.return_limit_mb)), L({ functionName: t, filePath: e, metadata: i, args: p, result: Q, error: null, duration: F - h, durationNs: w, startTimeNs: f.toString(), async: !0, spanId: g, parentSpanId: l, pid: process.pid, threadId: O }), b;
|
|
921
921
|
}, (b) => {
|
|
922
|
-
const S = process.hrtime.bigint(),
|
|
923
|
-
throw L({ functionName: t, filePath: e, metadata: i, args: p, result: null, error: b?.message || String(b), duration:
|
|
922
|
+
const S = process.hrtime.bigint(), F = Date.now(), w = Number(S - f);
|
|
923
|
+
throw L({ functionName: t, filePath: e, metadata: i, args: p, result: null, error: b?.message || String(b), duration: F - h, durationNs: w, startTimeNs: f.toString(), async: !0, spanId: g, parentSpanId: l, pid: process.pid, threadId: O }), b;
|
|
924
924
|
});
|
|
925
925
|
const I = process.hrtime.bigint(), v = Date.now(), D = Number(I - f);
|
|
926
926
|
let $ = null;
|
|
@@ -935,7 +935,7 @@ function ut(r, t, e, i) {
|
|
|
935
935
|
return n;
|
|
936
936
|
}
|
|
937
937
|
function L(r) {
|
|
938
|
-
const t =
|
|
938
|
+
const t = ae(), e = t?.sfDebug || !1;
|
|
939
939
|
e && console.log("[FuncSpan] captureSpanData called for:", { function: r.functionName, file: r.filePath, duration: `${r.duration}ms`, async: r.async, error: r.error, spanId: r.spanId });
|
|
940
940
|
const i = { functionName: r.functionName, filePath: r.filePath, metadata: r.metadata, args: r.args, result: r.result, error: r.error, duration: r.duration, durationNs: r.durationNs, async: r.async, spanId: r.spanId, parentSpanId: r.parentSpanId };
|
|
941
941
|
process.env.SF_FUNCSPAN_CONSOLE_OUTPUT === "true" && console.log(`
|
|
@@ -944,44 +944,44 @@ function L(r) {
|
|
|
944
944
|
if (n) try {
|
|
945
945
|
const o = n === "true" || n === "1" ? "funcspans.jsonl" : n, d = Date.now(), s = process.hrtime.bigint(), c = BigInt(r.startTimeNs), a = Number(s - c) / 1e6, l = new Date(d - a).toISOString(), g = JSON.stringify({ timestamp: l, functionName: r.functionName, filePath: r.filePath, line: r.metadata.line, column: r.metadata.column, duration: r.duration, durationNs: r.durationNs, startTimeNs: r.startTimeNs, arguments: r.args, returnValue: r.error ? { error: String(r.error) } : r.result, spanId: r.spanId, parentSpanId: r.parentSpanId, async: r.async, pid: r.pid, threadId: r.threadId }) + `
|
|
946
946
|
`;
|
|
947
|
-
|
|
947
|
+
Ee(o, g, "utf-8");
|
|
948
948
|
} catch (o) {
|
|
949
949
|
console.error("[FuncSpan] Error writing to JSONL file:", o);
|
|
950
950
|
}
|
|
951
951
|
if (e && console.log("[FuncSpan] Sending function span to transmitter:", i), process.env.SF_FUNCSPAN_SKIP_BACKEND !== "true") try {
|
|
952
|
-
(B || (B = new
|
|
952
|
+
(B || (B = new $e()), B).send([i]), e && console.log("[FuncSpan] Function span sent successfully");
|
|
953
953
|
} catch (o) {
|
|
954
954
|
e && console.error("[FuncSpan] Error sending function span:", o);
|
|
955
955
|
}
|
|
956
956
|
}
|
|
957
|
-
function
|
|
957
|
+
function pt(r) {
|
|
958
958
|
return !!r.includes("captureFunctionSpan(") || !!r.includes("@sailfish-ai/sf-veritas") || !(!r.includes("/* @sailfish-instrumented */") && !r.includes("// @sailfish-instrumented"));
|
|
959
959
|
}
|
|
960
960
|
export {
|
|
961
961
|
j as ContextManager,
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
962
|
+
ut as addOrUpdateMetadata,
|
|
963
|
+
lt as captureFunctionSpan,
|
|
964
|
+
yt as clearFuncspanOverride,
|
|
965
965
|
q as getCurrentFunctionSpanId,
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
966
|
+
ue as getDefaultConfig,
|
|
967
|
+
Ie as getEnvConfig,
|
|
968
|
+
ce as getFuncspanOverride,
|
|
969
|
+
Ke as getGlobalConfig,
|
|
970
|
+
dt as identify,
|
|
971
|
+
Ge as initializeConfigLoader,
|
|
972
|
+
Qe as initializeWorkerPoolPatching,
|
|
973
|
+
pt as isAlreadyInstrumented,
|
|
974
|
+
We as isConfigLoaderInitialized,
|
|
975
|
+
vt as isProductionEnvironment,
|
|
976
|
+
$t as isRuntimeModeEnabled,
|
|
977
|
+
ct as isSetupInterceptorsInitialized,
|
|
978
|
+
Xe as isWorkerPoolInitialized,
|
|
979
|
+
de as parseHeaderOverride,
|
|
980
|
+
ht as runWithContext,
|
|
981
|
+
St as setFuncspanOverride,
|
|
982
|
+
Ft as setSkipTypeScriptPlugin,
|
|
983
|
+
at as setupInterceptors,
|
|
984
|
+
_t as shouldEnableRuntimeHooks,
|
|
985
985
|
Nt as transformFunctionSpans,
|
|
986
|
-
|
|
986
|
+
Dt as transformFunctionSpansSync
|
|
987
987
|
};
|
|
@@ -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-BUdAamcg.cjs");exports.captureWorkerPoolOperation=e.captureWorkerPoolOperation;
|
|
@@ -1,4 +1,4 @@
|
|
|
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",!
|
|
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",!1),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
|
-
`;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;
|
|
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.isSendingInternalTelemetry=function(){return _},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;
|
|
@@ -37,6 +37,9 @@ class j {
|
|
|
37
37
|
}
|
|
38
38
|
const q = fetch;
|
|
39
39
|
let $ = !1;
|
|
40
|
+
function te() {
|
|
41
|
+
return $;
|
|
42
|
+
}
|
|
40
43
|
async function E(n, t, a, o) {
|
|
41
44
|
try {
|
|
42
45
|
const s = f();
|
|
@@ -63,13 +66,13 @@ async function E(n, t, a, o) {
|
|
|
63
66
|
$ = !1, f().sfDebug && console.error("Error sending data to GraphQL server:", s);
|
|
64
67
|
}
|
|
65
68
|
}
|
|
66
|
-
function
|
|
69
|
+
function ne() {
|
|
67
70
|
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
71
|
}
|
|
69
|
-
function
|
|
72
|
+
function re() {
|
|
70
73
|
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
74
|
}
|
|
72
|
-
function
|
|
75
|
+
function ae(n) {
|
|
73
76
|
try {
|
|
74
77
|
const t = n.split("-");
|
|
75
78
|
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" };
|
|
@@ -85,15 +88,15 @@ function _(n, t) {
|
|
|
85
88
|
const F = "__sf_funcspanOverrideStorage";
|
|
86
89
|
globalThis[F] || (globalThis[F] = new J());
|
|
87
90
|
const w = globalThis[F];
|
|
88
|
-
function
|
|
91
|
+
function se(n) {
|
|
89
92
|
w.enterWith(n);
|
|
90
93
|
}
|
|
91
|
-
function
|
|
94
|
+
function oe() {
|
|
92
95
|
return w.getStore();
|
|
93
96
|
}
|
|
94
|
-
function
|
|
97
|
+
function ie() {
|
|
95
98
|
}
|
|
96
|
-
function
|
|
99
|
+
function ue(...n) {
|
|
97
100
|
const t = {};
|
|
98
101
|
for (const a of n) for (const o in a) a[o] !== void 0 && (t[o] = a[o]);
|
|
99
102
|
return t;
|
|
@@ -117,9 +120,9 @@ function D(n, t) {
|
|
|
117
120
|
return isNaN(o) ? t : o;
|
|
118
121
|
}
|
|
119
122
|
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", !
|
|
123
|
+
return { enabled: y("SF_WORKER_POOL_ENABLED", !0), trackFs: y("SF_WORKER_POOL_TRACK_FS", !1), trackDns: y("SF_WORKER_POOL_TRACK_DNS", !1), 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) };
|
|
121
124
|
}
|
|
122
|
-
function
|
|
125
|
+
function le(n) {
|
|
123
126
|
const t = A();
|
|
124
127
|
if (!t.enabled) return !1;
|
|
125
128
|
switch (n) {
|
|
@@ -443,7 +446,7 @@ class Q extends j {
|
|
|
443
446
|
}
|
|
444
447
|
}
|
|
445
448
|
let v = null;
|
|
446
|
-
function
|
|
449
|
+
function ce(n, t, a, o, s) {
|
|
447
450
|
const i = O(), e = i?.sfDebug || !1;
|
|
448
451
|
e && console.log(`[WorkerPool] Capturing ${n}.${t}`);
|
|
449
452
|
const r = A(), u = P.getInstance().getCurrentFunctionSpanId(), d = L();
|
|
@@ -463,7 +466,7 @@ function le(n, t, a, o, s) {
|
|
|
463
466
|
}), l.emitDestroy();
|
|
464
467
|
}, a.apply(s, h);
|
|
465
468
|
}
|
|
466
|
-
function
|
|
469
|
+
function pe(n, t, a, o, s) {
|
|
467
470
|
const i = O(), e = i?.sfDebug || !1;
|
|
468
471
|
e && console.log(`[WorkerPool] Capturing ${n}.${t} (Promise)`);
|
|
469
472
|
const r = A(), u = P.getInstance().getCurrentFunctionSpanId(), d = L();
|
|
@@ -501,17 +504,18 @@ function k(n) {
|
|
|
501
504
|
export {
|
|
502
505
|
j as B,
|
|
503
506
|
Q as F,
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
507
|
+
re as a,
|
|
508
|
+
ne as b,
|
|
509
|
+
ce as c,
|
|
510
|
+
pe as d,
|
|
511
|
+
le as e,
|
|
509
512
|
w as f,
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
+
oe as g,
|
|
514
|
+
ie as h,
|
|
515
|
+
te as i,
|
|
516
|
+
ue as m,
|
|
513
517
|
E as n,
|
|
514
|
-
|
|
515
|
-
|
|
518
|
+
ae as p,
|
|
519
|
+
se as s,
|
|
516
520
|
K as t
|
|
517
521
|
};
|
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.17",
|
|
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",
|