@sailfish-ai/sf-veritas 0.2.13 → 0.2.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/dist/contextManager-Cx03mw7l.js +258 -0
  2. package/dist/contextManager-CxQqBCEA.cjs +1 -0
  3. package/dist/funcSpanTransformer-Byqzu4B1.js +231 -0
  4. package/dist/funcSpanTransformer-CDh0o-AP.cjs +1 -0
  5. package/dist/plugins/funcspanEsbuildPlugin.cjs +1 -1
  6. package/dist/plugins/funcspanEsbuildPlugin.mjs +2 -2
  7. package/dist/plugins/funcspanRollupPlugin.cjs +1 -1
  8. package/dist/plugins/funcspanRollupPlugin.mjs +2 -2
  9. package/dist/plugins/funcspanTscPlugin.cjs +1 -1
  10. package/dist/plugins/funcspanTscPlugin.mjs +2 -2
  11. package/dist/plugins/funcspanVitePlugin.cjs +1 -1
  12. package/dist/plugins/funcspanVitePlugin.mjs +2 -2
  13. package/dist/plugins/funcspanWebpackLoader.cjs +1 -1
  14. package/dist/plugins/funcspanWebpackLoader.mjs +1 -1
  15. package/dist/plugins/funcspanWebpackPlugin.cjs +1 -1
  16. package/dist/plugins/funcspanWebpackPlugin.mjs +1 -1
  17. package/dist/{runtimeConfig-CgLfwL3X.js → runtimeConfig-DndXTWki.js} +130 -127
  18. package/dist/{runtimeConfig-DIsq-KCn.cjs → runtimeConfig-TWzqPe1S.cjs} +7 -7
  19. package/dist/sf-veritas.cjs +37 -12
  20. package/dist/sf-veritas.mjs +574 -509
  21. package/dist/types/funcSpanConfig.d.ts +0 -4
  22. package/dist/types/funcSpanConfigLoader.d.ts +1 -1
  23. package/dist/types/networkRequestTransmitter.d.ts +4 -0
  24. package/dist/types/setupConfig.d.ts +35 -0
  25. package/dist/worker-pool-capture.cjs +1 -1
  26. package/dist/worker-pool-capture.mjs +1 -1
  27. package/dist/{workerPoolSpanCapture-D85i6nhQ.cjs → workerPoolSpanCapture-COwiNikM.cjs} +2 -2
  28. package/dist/{workerPoolSpanCapture-BYaf3NOr.js → workerPoolSpanCapture-d-8ExI18.js} +84 -82
  29. package/package.json +2 -1
  30. package/dist/contextManager-BkETRITg.cjs +0 -1
  31. package/dist/contextManager-CEPhVu9T.js +0 -197
  32. package/dist/funcSpanTransformer-B9WWl-g1.cjs +0 -1
  33. package/dist/funcSpanTransformer-CWNEWRxq.js +0 -225
@@ -58,10 +58,6 @@ export declare function getDefaultConfig(): FuncspanConfig;
58
58
  * Example: "1-1-10-10-1-1.0-1-0-0"
59
59
  */
60
60
  export declare function parseHeaderOverride(header: string): FuncspanHeaderOverride | null;
61
- /**
62
- * AsyncLocalStorage for per-request funcspan override
63
- * Exported to allow direct .run() usage in patchhttpInbound.ts
64
- */
65
61
  export declare const funcspanOverrideStorage: AsyncLocalStorage<string>;
66
62
  /**
67
63
  * Set funcspan override from HTTP header (per-request)
@@ -67,7 +67,7 @@ export declare class FuncspanConfigLoader {
67
67
  export declare function initializeConfigLoader(rootPaths?: string[], debug?: boolean): Promise<void>;
68
68
  /**
69
69
  * Get configuration for a file and function
70
- * In worker processes where config loader isn't initialized, returns env config
70
+ * In worker processes where config loader isn't initialized, returns default config (disabled)
71
71
  */
72
72
  export declare function getGlobalConfig(filePath: string, functionName?: string): FuncspanConfig;
73
73
  /**
@@ -14,6 +14,10 @@ export interface NetworkRequestData {
14
14
  method: string;
15
15
  retryWithoutTraceId?: boolean;
16
16
  parentSpanId?: string | null;
17
+ requestHeaders?: Record<string, string>;
18
+ responseHeaders?: Record<string, string>;
19
+ requestBody?: string;
20
+ responseBody?: string;
17
21
  }
18
22
  export declare class NetworkRequestTransmitter extends BaseTransmitter {
19
23
  private serviceIdentifier;
@@ -23,6 +23,26 @@ export interface SetupOptions {
23
23
  * Optional Git commit SHA of the running build.
24
24
  */
25
25
  gitSha?: string;
26
+ /**
27
+ * Optional git organization/owner (e.g. "myorg").
28
+ * Override via GIT_ORG or VERCEL_GIT_REPO_OWNER env var.
29
+ */
30
+ gitOrg?: string;
31
+ /**
32
+ * Optional git repository name (e.g. "myrepo").
33
+ * Override via GIT_REPO or VERCEL_GIT_REPO_SLUG env var.
34
+ */
35
+ gitRepo?: string;
36
+ /**
37
+ * Optional git hosting provider (e.g. "github", "gitlab", "bitbucket").
38
+ * Override via GIT_PROVIDER env var.
39
+ */
40
+ gitProvider?: string;
41
+ /**
42
+ * Optional human-readable display name for this service.
43
+ * Override via SERVICE_DISPLAY_NAME env var.
44
+ */
45
+ serviceDisplayName?: string;
26
46
  /**
27
47
  * Optional the depth of exception locals.
28
48
  */
@@ -80,6 +100,21 @@ declare class AppConfig {
80
100
  packageLibraryType: string;
81
101
  version: string;
82
102
  gitSha?: string;
103
+ gitOrg?: string;
104
+ gitRepo?: string;
105
+ gitProvider?: string;
106
+ serviceDisplayName?: string;
107
+ infrastructureType?: string;
108
+ infrastructureDetails?: Record<string, string>;
109
+ setupInterceptorsFile?: string;
110
+ setupInterceptorsLine?: number;
111
+ logIgnoreRegex?: RegExp;
112
+ captureRequestHeaders: boolean;
113
+ captureResponseHeaders: boolean;
114
+ captureRequestBody: boolean;
115
+ captureResponseBody: boolean;
116
+ requestBodyLimitBytes: number;
117
+ responseBodyLimitBytes: number;
83
118
  private _serviceIdentificationReceived;
84
119
  constructor(options: SetupOptions);
85
120
  private getPackageVersion;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./workerPoolSpanCapture-D85i6nhQ.cjs");exports.captureWorkerPoolOperation=e.captureWorkerPoolOperation;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./workerPoolSpanCapture-COwiNikM.cjs");exports.captureWorkerPoolOperation=e.captureWorkerPoolOperation;
@@ -1,4 +1,4 @@
1
- import { c as e } from "./workerPoolSpanCapture-BYaf3NOr.js";
1
+ import { c as e } from "./workerPoolSpanCapture-d-8ExI18.js";
2
2
  export {
3
3
  e as captureWorkerPoolOperation
4
4
  };
@@ -1,4 +1,4 @@
1
- "use strict";const L=require("async_hooks"),W=require("fs"),v=require("worker_threads"),l=require("./contextManager-BkETRITg.cjs");class w{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 B=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,B(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 I=new L.AsyncLocalStorage;function O(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 R(n,t){const o=process.env[n];if(o===void 0)return t;const s=parseFloat(o);return isNaN(s)?t:s}function T(){return{enabled:S("SF_WORKER_POOL_ENABLED",!0),trackFs:S("SF_WORKER_POOL_TRACK_FS",!1),trackDns:S("SF_WORKER_POOL_TRACK_DNS",!0),trackCrypto:S("SF_WORKER_POOL_TRACK_CRYPTO",!1),trackZlib:S("SF_WORKER_POOL_TRACK_ZLIB",!1),captureArguments:S("SF_WORKER_POOL_CAPTURE_ARGUMENTS",!0),captureReturnValue:S("SF_WORKER_POOL_CAPTURE_RETURN_VALUE",!0),argLimitMb:R("SF_WORKER_POOL_ARG_LIMIT_MB",1),returnLimitMb:R("SF_WORKER_POOL_RETURN_LIMIT_MB",1)}}function E(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?O(a,s):a}catch{return{error:"Failed to capture arguments",argsCount:o.length-1}}}function D(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?O(a,s):a}catch{return{error:"Failed to capture result",type:typeof o}}}function K(n){return n.operationType==="worker_pool"}class M extends w{constructor(){super(),this.operationName="CollectFunctionSpans"}send(t){const o=l.getConfig().sfDebug;o&&console.log(`[FunctionSpanTransmitter] Preparing to send ${t.length} function span(s)`);for(const s of t)try{if(K(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`
1
+ "use strict";const w=require("async_hooks"),B=require("fs"),v=require("worker_threads"),l=require("./contextManager-CxQqBCEA.cjs");class M{apiKey;endpoint;queryType="mutation";operationName="";serviceUUID=l.getConfig().serviceUUID;contextManager;constructor(){this.apiKey=l.getConfig().apiKey,this.endpoint=l.getConfig().apiGraphqlEndpoint,this.contextManager=l.ContextManager.getInstance()}get queryName(){return this.operationName?this.operationName.charAt(0).toLowerCase()+this.operationName.slice(1):""}getDefaultVariables(){const t=Date.now().toString(),o=this.contextManager.getOrSetSfTraceId(),s=this.contextManager.getCurrentFunctionSpanId();return{apiKey:this.apiKey,serviceUuid:this.serviceUUID,sessionId:o,timestampMs:t,parentSpanId:s}}getVariables(t={}){return{...this.getDefaultVariables(),...t}}setOperationName(t){this.operationName=t}setEndpoint(t){this.endpoint=t}setServiceUUID(t){this.serviceUUID=t}}const K=fetch;let _=!1;async function P(n,t,o,s){try{const a=l.getConfig();let i;try{i=JSON.stringify({query:o,variables:s,operationName:t})}catch{i=JSON.stringify({query:o,operationName:t})}_=!0,K(n,{method:"POST",headers:{"Content-Type":"application/json"},body:i}).then(async e=>{if(_=!1,!e.ok)return void(a.sfDebug&&console.error(`GraphQL request failed with status ${e.status} for ${t}`));const r=await e.json();r.errors?.length?(function(u,g,c){const d=u&&typeof u=="object"&&!Array.isArray(u)?Object.keys(u)[0]:void 0;console.error(d==="identifyServiceDetails"?`IdentifyServiceDetails NOT sent successfully for service: UUID=${c.serviceUUID}`:`GraphQL request failed with errors: ${JSON.stringify(g)} for operation key ${d}`)})(r.data,r.errors,a):a.sfDebug&&(function(u,g,c){const d=u&&typeof u=="object"&&!Array.isArray(u)?Object.keys(u)[0]:void 0,p=u[d]||!1;d==="identifyServiceDetails"&&(c.setServiceIdentificationReceived(p),l.getConfig().sfDebug&&console.log(`IdentifyServiceDetails sent successfully for service: UUID=${c.serviceUUID}; serviceIdentificationReceived=${d==="identifyServiceDetails"?p:"N/A"}`))})(r.data,0,a)}).catch(e=>{_=!1,a.sfDebug&&(console.error(`[RequestUtils] Fetch error for ${t} to ${n}:`,e),e.cause&&console.error("[RequestUtils] Error cause:",e.cause))})}catch(a){_=!1,l.getConfig().sfDebug&&console.error("Error sending data to GraphQL server:",a)}}function N(n,t){if(!n)return t;const o=n.toLowerCase();return o==="true"||o==="1"||o==="yes"}const O="__sf_funcspanOverrideStorage";globalThis[O]||(globalThis[O]=new w.AsyncLocalStorage);const I=globalThis[O];function C(n,t){try{const o=JSON.stringify(n).length/1048576;return o<=t?n:{_truncated:!0,_originalSizeMB:o.toFixed(2),_limitMB:t,_preview:JSON.stringify(n).substring(0,500)+"..."}}catch{return{_error:"Failed to serialize data",_type:typeof n}}}function S(n,t){const o=process.env[n];return o===void 0?t:o==="true"||o==="1"}function E(n,t){const o=process.env[n];if(o===void 0)return t;const s=parseFloat(o);return isNaN(s)?t:s}function T(){return{enabled:S("SF_WORKER_POOL_ENABLED",!0),trackFs:S("SF_WORKER_POOL_TRACK_FS",!1),trackDns:S("SF_WORKER_POOL_TRACK_DNS",!0),trackCrypto:S("SF_WORKER_POOL_TRACK_CRYPTO",!1),trackZlib:S("SF_WORKER_POOL_TRACK_ZLIB",!1),captureArguments:S("SF_WORKER_POOL_CAPTURE_ARGUMENTS",!0),captureReturnValue:S("SF_WORKER_POOL_CAPTURE_RETURN_VALUE",!0),argLimitMb:E("SF_WORKER_POOL_ARG_LIMIT_MB",1),returnLimitMb:E("SF_WORKER_POOL_RETURN_LIMIT_MB",1)}}function D(n,t,o,s){let a;try{switch(n){case"fs":a=(function(i,e){const r={};switch(i){case"readFile":case"writeFile":case"appendFile":r.path=String(e[0]||""),e[1]&&typeof e[1]=="object"?(r.encoding=e[1].encoding||null,r.flag=e[1].flag||null):typeof e[1]=="string"&&(r.encoding=e[1]),i!=="writeFile"&&i!=="appendFile"||(Buffer.isBuffer(e[1])?(r.dataType="Buffer",r.dataSize=e[1].length):typeof e[1]=="string"&&(r.dataType="string",r.dataSize=e[1].length));break;case"readdir":case"stat":case"lstat":case"access":case"chmod":case"mkdir":case"rmdir":case"unlink":r.path=String(e[0]||""),e[1]&&typeof e[1]=="object"&&(r.options={...e[1]},delete r.options.callback);break;case"rename":r.oldPath=String(e[0]||""),r.newPath=String(e[1]||"");break;case"open":r.path=String(e[0]||""),r.flags=e[1],r.mode=e[2];break;case"close":case"fstat":r.fd=e[0];break;case"read":case"write":r.fd=e[0],Buffer.isBuffer(e[1])&&(r.bufferSize=e[1].length),r.offset=e[2],r.length=e[3],r.position=e[4];break;default:r.argsCount=e.length-1}return r})(t,o);break;case"dns":a=(function(i,e){const r={};switch(i){case"lookup":r.hostname=String(e[0]||""),typeof e[1]=="object"?(r.family=e[1].family,r.all=e[1].all):typeof e[1]=="number"&&(r.family=e[1]);break;case"resolve":case"resolve4":case"resolve6":case"resolveAny":case"resolveMx":case"resolveNs":case"resolveTxt":r.hostname=String(e[0]||"");break;case"reverse":r.ip=String(e[0]||"");break;default:r.argsCount=e.length-1}return r})(t,o);break;case"crypto":a=(function(i,e){const r={};switch(i){case"pbkdf2":r.passwordType=typeof e[0],r.saltType=typeof e[1],r.iterations=e[2],r.keylen=e[3],r.digest=e[4];break;case"scrypt":r.passwordType=typeof e[0],r.saltType=typeof e[1],r.keylen=e[2],typeof e[3]=="object"&&(r.N=e[3].N,r.r=e[3].r,r.p=e[3].p);break;case"randomBytes":r.size=e[0];break;case"generateKeyPair":r.type=e[0],typeof e[1]=="object"&&(r.modulusLength=e[1].modulusLength,r.namedCurve=e[1].namedCurve);break;default:r.argsCount=e.length-1}return r})(t,o);break;case"zlib":a=(function(i,e){const r={};return Buffer.isBuffer(e[0])?(r.inputType="Buffer",r.inputSize=e[0].length):typeof e[0]=="string"?(r.inputType="string",r.inputSize=e[0].length):r.inputType=typeof e[0],e[1]&&typeof e[1]=="object"&&typeof e[1]!="function"&&(r.options={...e[1]}),r})(0,o);break;default:return null}return s>0?C(a,s):a}catch{return{error:"Failed to capture arguments",argsCount:o.length-1}}}function L(n,t,o,s){let a;try{switch(n){case"fs":a=(function(i,e){if(!e)return null;switch(i){case"readFile":return Buffer.isBuffer(e)?{type:"Buffer",size:e.length}:typeof e=="string"?{type:"string",size:e.length}:{type:typeof e};case"readdir":return{count:Array.isArray(e)?e.length:0,items:e};case"stat":case"lstat":case"fstat":return{size:e.size,mode:e.mode,isFile:e.isFile(),isDirectory:e.isDirectory()};case"open":return{fd:e};case"read":return{bytesRead:e};case"write":return{bytesWritten:e};default:return e}})(t,o);break;case"dns":a=(function(i,e){if(!e)return null;switch(i){case"lookup":return Array.isArray(e)?{count:e.length,addresses:e}:e;case"resolve":case"resolve4":case"resolve6":case"resolveAny":case"resolveMx":case"resolveNs":case"resolveTxt":return{count:Array.isArray(e)?e.length:0,records:e};case"reverse":return{hostnames:e};default:return e}})(t,o);break;case"crypto":a=(function(i,e){if(!e)return null;switch(i){case"pbkdf2":case"scrypt":case"randomBytes":return Buffer.isBuffer(e)?{type:"Buffer",size:e.length}:{type:typeof e};case"generateKeyPair":return{hasPublicKey:!!e?.publicKey,hasPrivateKey:!!e?.privateKey};default:return e}})(t,o);break;case"zlib":a=(function(i,e){return e?Buffer.isBuffer(e)?{type:"Buffer",size:e.length}:typeof e=="string"?{type:"string",size:e.length}:{type:typeof e}:null})(0,o);break;default:return null}return s>0?C(a,s):a}catch{return{error:"Failed to capture result",type:typeof o}}}function V(n){return n.operationType==="worker_pool"}class W extends M{constructor(){super(),this.operationName="CollectFunctionSpans"}send(t){const o=l.getConfig().sfDebug;o&&console.log(`[FunctionSpanTransmitter] Preparing to send ${t.length} function span(s)`);for(const s of t)try{if(V(s)){this.sendWorkerPoolSpan(s,o);continue}const a=s;let i;if(a.result!==void 0&&a.result!==null){const r=typeof a.result;i=JSON.stringify({type:r,has_value:!0,value:a.result})}else i=a.result===null?JSON.stringify({type:"null",has_value:!0,value:null}):JSON.stringify({type:"undefined",has_value:!1,value:null});const e=this.getVariables({library:"JS/TS BACKEND",version:l.getConfig().version,spanId:a.spanId,parentSpanId:a.parentSpanId,filePath:a.filePath,lineNumber:a.metadata.line,columnNumber:a.metadata.column,functionName:a.functionName,arguments:JSON.stringify(a.args||{}),returnValue:i,startTimeNs:(1e6*Date.now()-1e6*a.duration).toString(),durationNs:(1e6*a.duration).toString()});o&&(console.log(`[FunctionSpanTransmitter] Sending GraphQL mutation to ${this.endpoint}`),console.log("[FunctionSpanTransmitter] Variables:",JSON.stringify(e,null,2))),P(this.endpoint,this.operationName,this.getQuery(),e),o&&console.log(`[FunctionSpanTransmitter] Queued function span for ${a.functionName}`)}catch(a){console.error(`[FunctionSpanTransmitter] Error preparing function span for ${s.functionName}:`,a)}}sendWorkerPoolSpan(t,o){try{let s;if(t.result!==void 0&&t.result!==null){const i=typeof t.result;s=JSON.stringify({type:i,has_value:!0,value:t.result})}else s=t.result===null?JSON.stringify({type:"null",has_value:!0,value:null}):JSON.stringify({type:"undefined",has_value:!1,value:null});const a=this.getVariables({library:"JS/TS BACKEND",version:l.getConfig().version,spanId:t.spanId,operationName:t.operationName,moduleName:t.moduleName,methodName:t.methodName,startTimeNs:t.startTimeNs,durationNs:t.durationNs,arguments:JSON.stringify(t.args||{}),returnValue:s,error:t.error,pid:t.pid,threadId:t.threadId});o&&(console.log(`[FunctionSpanTransmitter] Sending worker pool span: ${t.operationName}`),console.log("[FunctionSpanTransmitter] Variables:",JSON.stringify(a,null,2))),P(this.endpoint,"CollectWorkerPoolSpans",this.getWorkerPoolQuery(),a),o&&console.log(`[FunctionSpanTransmitter] Queued worker pool span for ${t.operationName}`)}catch(s){console.error(`[FunctionSpanTransmitter] Error preparing worker pool span for ${t.operationName}:`,s)}}getWorkerPoolQuery(){return`
2
2
  mutation CollectWorkerPoolSpans(
3
3
  $apiKey: String!,
4
4
  $serviceUuid: String!,
@@ -80,4 +80,4 @@
80
80
  }
81
81
  `}}let F=null;function k(n){const t=l.getGlobalConfigUnsafe(),o=t?.sfDebug||!1;o&&console.log("[WorkerPool] Capturing span:",{operation:n.operationName,duration:`${n.duration}ms`,error:n.error,spanId:n.spanId,parentSpanId:n.parentSpanId}),process.env.SF_FUNCSPAN_CONSOLE_OUTPUT==="true"&&console.log(`
82
82
  ⚙️ Worker Pool Operation:`,{operation:n.operationName,duration:`${n.duration.toFixed(2)}ms`,arguments:n.args,result:n.error?`Error: ${n.error}`:n.result,spanId:n.spanId,parentSpanId:n.parentSpanId||"none"});const s=process.env.SF_FUNCSPAN_JSONL_FILE;if(s)try{const a=s==="true"||s==="1"?"funcspans.jsonl":s,i=Date.now(),e=process.hrtime.bigint(),r=BigInt(n.startTimeNs),u=Number(e-r)/1e6,g=new Date(i-u).toISOString(),c=JSON.stringify({timestamp:g,operationType:n.operationType,operationName:n.operationName,moduleName:n.moduleName,methodName:n.methodName,duration:n.duration,durationNs:n.durationNs,startTimeNs:n.startTimeNs,arguments:n.args,returnValue:n.error?{error:String(n.error)}:n.result,spanId:n.spanId,parentSpanId:n.parentSpanId,pid:n.pid,threadId:n.threadId})+`
83
- `;W.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 M),F).send([n]),o&&console.log("[WorkerPool] Span sent successfully")}catch(a){o&&console.error("[WorkerPool] Error sending span:",a)}}exports.BaseTransmitter=w,exports.FunctionSpanTransmitter=M,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 L.AsyncResource("WorkerPoolOperation"),d=process.hrtime.bigint();let p=null;r.captureArguments&&(p=E(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,C=Number(b)/1e6;m(y,...$),c.runInAsyncScope(()=>{e&&console.log(`[WorkerPool] ${n}.${t} completed in ${C.toFixed(3)}ms (${b}ns)`);let A=null,U=null;y?U=y?.message||String(y):r.captureReturnValue&&$.length>0&&(A=D(n,t,$[0],r.returnLimitMb)),k({operationType:"worker_pool",operationName:`${n}.${t}`,moduleName:n,methodName:t,duration:C,durationNs:b.toString(),startTimeNs:d.toString(),args:p,result:A,error:U,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=E(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=D(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=O;
83
+ `;B.appendFileSync(a,c,"utf-8")}catch(a){console.error("[WorkerPool] Error writing to JSONL file:",a)}if(o&&console.log("[WorkerPool] Sending span to transmitter"),process.env.SF_FUNCSPAN_SKIP_BACKEND!=="true")try{(F||(F=new W),F).send([n]),o&&console.log("[WorkerPool] Span sent successfully")}catch(a){o&&console.error("[WorkerPool] Error sending span:",a)}}exports.BaseTransmitter=M,exports.FunctionSpanTransmitter=W,exports.captureWorkerPoolOperation=function(n,t,o,s,a){const i=l.getGlobalConfigUnsafe(),e=i?.sfDebug||!1;e&&console.log(`[WorkerPool] Capturing ${n}.${t}`);const r=T(),u=l.ContextManager.getInstance().getCurrentFunctionSpanId(),g=l.v4();e&&console.log(`[WorkerPool] Span ID: ${g}, Parent: ${u||"none"}`);const c=new w.AsyncResource("WorkerPoolOperation"),d=process.hrtime.bigint();let p=null;r.captureArguments&&(p=D(n,t,s,r.argLimitMb));const f=s.findIndex(y=>typeof y=="function");if(f===-1)return e&&console.log(`[WorkerPool] No callback found for ${n}.${t}`),o.apply(a,s);const m=s[f],h=[...s];return h[f]=function(y,...$){const b=process.hrtime.bigint()-d,A=Number(b)/1e6;m(y,...$),c.runInAsyncScope(()=>{e&&console.log(`[WorkerPool] ${n}.${t} completed in ${A.toFixed(3)}ms (${b}ns)`);let U=null,R=null;y?R=y?.message||String(y):r.captureReturnValue&&$.length>0&&(U=L(n,t,$[0],r.returnLimitMb)),k({operationType:"worker_pool",operationName:`${n}.${t}`,moduleName:n,methodName:t,duration:A,durationNs:b.toString(),startTimeNs:d.toString(),args:p,result:U,error:R,spanId:g,parentSpanId:u,pid:process.pid,threadId:v.threadId})}),c.emitDestroy()},o.apply(a,h)},exports.captureWorkerPoolPromiseOperation=function(n,t,o,s,a){const i=l.getGlobalConfigUnsafe(),e=i?.sfDebug||!1;e&&console.log(`[WorkerPool] Capturing ${n}.${t} (Promise)`);const r=T(),u=l.ContextManager.getInstance().getCurrentFunctionSpanId(),g=l.v4();e&&console.log(`[WorkerPool] Span ID: ${g}, Parent: ${u||"none"}`);const c=process.hrtime.bigint();let d=null;return r.captureArguments&&(d=D(n,t,s,r.argLimitMb)),o.apply(a,s).then(p=>{const f=process.hrtime.bigint()-c,m=Number(f)/1e6;e&&console.log(`[WorkerPool] ${n}.${t} completed in ${m.toFixed(3)}ms (${f}ns)`);let h=null;return r.captureReturnValue&&(h=L(n,t,p,r.returnLimitMb)),k({operationType:"worker_pool",operationName:`${n}.${t}`,moduleName:n,methodName:t,duration:m,durationNs:f.toString(),startTimeNs:c.toString(),args:d,result:h,error:null,spanId:g,parentSpanId:u,pid:process.pid,threadId:v.threadId}),p},p=>{const f=process.hrtime.bigint()-c,m=Number(f)/1e6;throw e&&console.log(`[WorkerPool] ${n}.${t} failed in ${m.toFixed(3)}ms: ${p?.message||p}`),k({operationType:"worker_pool",operationName:`${n}.${t}`,moduleName:n,methodName:t,duration:m,durationNs:f.toString(),startTimeNs:c.toString(),args:d,result:null,error:p?.message||String(p),spanId:g,parentSpanId:u,pid:process.pid,threadId:v.threadId}),p})},exports.clearFuncspanOverride=function(){},exports.funcspanOverrideStorage=I,exports.getDefaultConfig=function(){return{capture_arguments:!1,capture_return_value:!1,arg_limit_mb:1,return_limit_mb:1,autocapture_all_child_functions:!1,sample_rate:0,enable_sampling:!1,capture_sf_veritas:!1,parse_json_strings:!1}},exports.getEnvConfig=function(){return{capture_arguments:N(process.env.SF_FUNCSPAN_CAPTURE_ARGUMENTS,!0),capture_return_value:N(process.env.SF_FUNCSPAN_CAPTURE_RETURN_VALUE,!0),arg_limit_mb:parseInt(process.env.SF_FUNCSPAN_ARG_LIMIT_MB||"1",10),return_limit_mb:parseInt(process.env.SF_FUNCSPAN_RETURN_LIMIT_MB||"1",10),autocapture_all_child_functions:N(process.env.SF_FUNCSPAN_AUTOCAPTURE_ALL_CHILD_FUNCTIONS,!1),sample_rate:parseFloat(process.env.SF_FUNCSPAN_SAMPLE_RATE||"1.0"),enable_sampling:N(process.env.SF_FUNCSPAN_ENABLE_SAMPLING,!1),capture_sf_veritas:N(process.env.SF_FUNCSPAN_CAPTURE_SF_VERITAS,!1),parse_json_strings:N(process.env.SF_FUNCSPAN_PARSE_JSON_STRINGS,!1)}},exports.getFuncspanOverride=function(){return I.getStore()},exports.isModuleTrackingEnabled=function(n){const t=T();if(!t.enabled)return!1;switch(n){case"fs":return t.trackFs;case"dns":return t.trackDns;case"crypto":return t.trackCrypto;case"zlib":return t.trackZlib;default:return!1}},exports.mergeConfigs=function(...n){const t={};for(const o of n)for(const s in o)o[s]!==void 0&&(t[s]=o[s]);return t},exports.nonBlockingPost=P,exports.parseHeaderOverride=function(n){try{const t=n.split("-");return t.length!==9?(console.error(`[FuncSpan] Invalid header format: expected 9 parts, got ${t.length}`),null):{capture_arguments:t[0]==="1",capture_return_value:t[1]==="1",arg_limit_mb:parseInt(t[2],10),return_limit_mb:parseInt(t[3],10),autocapture_all_child_functions:t[4]==="1",sample_rate:parseFloat(t[5]),enable_sampling:t[6]==="1",capture_sf_veritas:t[7]==="1",parse_json_strings:t[8]==="1"}}catch(t){return console.error(`[FuncSpan] Failed to parse header override "${n}":`,t),null}},exports.setFuncspanOverride=function(n){I.enterWith(n)},exports.truncateToLimit=C;
@@ -1,19 +1,19 @@
1
- var M = Object.defineProperty;
2
- var W = (n, t, a) => t in n ? M(n, t, { enumerable: !0, configurable: !0, writable: !0, value: a }) : n[t] = a;
3
- var S = (n, t, a) => W(n, typeof t != "symbol" ? t + "" : t, a);
4
- import { AsyncLocalStorage as V, AsyncResource as J } from "async_hooks";
5
- import { appendFileSync as z } from "fs";
6
- import { threadId as F } from "worker_threads";
7
- import { g as m, C as k, v as D, a as P } from "./contextManager-CEPhVu9T.js";
8
- class x {
1
+ var W = Object.defineProperty;
2
+ var V = (n, t, a) => t in n ? W(n, t, { enumerable: !0, configurable: !0, writable: !0, value: a }) : n[t] = a;
3
+ var S = (n, t, a) => V(n, typeof t != "symbol" ? t + "" : t, a);
4
+ import { AsyncLocalStorage as J, AsyncResource as z } from "async_hooks";
5
+ import { appendFileSync as x } from "fs";
6
+ import { threadId as T } from "worker_threads";
7
+ import { g as f, C as P, v as L, a as O } from "./contextManager-Cx03mw7l.js";
8
+ class j {
9
9
  constructor() {
10
10
  S(this, "apiKey");
11
11
  S(this, "endpoint");
12
12
  S(this, "queryType", "mutation");
13
13
  S(this, "operationName", "");
14
- S(this, "serviceUUID", m().serviceUUID);
14
+ S(this, "serviceUUID", f().serviceUUID);
15
15
  S(this, "contextManager");
16
- this.apiKey = m().apiKey, this.endpoint = m().apiGraphqlEndpoint, this.contextManager = k.getInstance();
16
+ this.apiKey = f().apiKey, this.endpoint = f().apiGraphqlEndpoint, this.contextManager = P.getInstance();
17
17
  }
18
18
  get queryName() {
19
19
  return this.operationName ? this.operationName.charAt(0).toLowerCase() + this.operationName.slice(1) : "";
@@ -35,18 +35,18 @@ class x {
35
35
  this.serviceUUID = t;
36
36
  }
37
37
  }
38
- const j = fetch;
38
+ const q = fetch;
39
39
  let $ = !1;
40
- async function C(n, t, a, o) {
40
+ async function E(n, t, a, o) {
41
41
  try {
42
- const s = m();
42
+ const s = f();
43
43
  let i;
44
44
  try {
45
45
  i = JSON.stringify({ query: a, variables: o, operationName: t });
46
46
  } catch {
47
47
  i = JSON.stringify({ query: a, operationName: t });
48
48
  }
49
- $ = !0, j(n, { method: "POST", headers: { "Content-Type": "application/json" }, body: i }).then(async (e) => {
49
+ $ = !0, q(n, { method: "POST", headers: { "Content-Type": "application/json" }, body: i }).then(async (e) => {
50
50
  if ($ = !1, !e.ok) return void (s.sfDebug && console.error(`GraphQL request failed with status ${e.status} for ${t}`));
51
51
  const r = await e.json();
52
52
  r.errors?.length ? (function(u, d, l) {
@@ -54,22 +54,22 @@ async function C(n, t, a, o) {
54
54
  console.error(p === "identifyServiceDetails" ? `IdentifyServiceDetails NOT sent successfully for service: UUID=${l.serviceUUID}` : `GraphQL request failed with errors: ${JSON.stringify(d)} for operation key ${p}`);
55
55
  })(r.data, r.errors, s) : s.sfDebug && (function(u, d, l) {
56
56
  const p = u && typeof u == "object" && !Array.isArray(u) ? Object.keys(u)[0] : void 0, c = u[p] || !1;
57
- p === "identifyServiceDetails" && (l.setServiceIdentificationReceived(c), m().sfDebug && console.log(`IdentifyServiceDetails sent successfully for service: UUID=${l.serviceUUID}; serviceIdentificationReceived=${p === "identifyServiceDetails" ? c : "N/A"}`));
57
+ p === "identifyServiceDetails" && (l.setServiceIdentificationReceived(c), f().sfDebug && console.log(`IdentifyServiceDetails sent successfully for service: UUID=${l.serviceUUID}; serviceIdentificationReceived=${p === "identifyServiceDetails" ? c : "N/A"}`));
58
58
  })(r.data, 0, s);
59
59
  }).catch((e) => {
60
60
  $ = !1, s.sfDebug && (console.error(`[RequestUtils] Fetch error for ${t} to ${n}:`, e), e.cause && console.error("[RequestUtils] Error cause:", e.cause));
61
61
  });
62
62
  } catch (s) {
63
- $ = !1, m().sfDebug && console.error("Error sending data to GraphQL server:", s);
63
+ $ = !1, f().sfDebug && console.error("Error sending data to GraphQL server:", s);
64
64
  }
65
65
  }
66
- function ee() {
66
+ function te() {
67
67
  return { capture_arguments: _(process.env.SF_FUNCSPAN_CAPTURE_ARGUMENTS, !0), capture_return_value: _(process.env.SF_FUNCSPAN_CAPTURE_RETURN_VALUE, !0), arg_limit_mb: parseInt(process.env.SF_FUNCSPAN_ARG_LIMIT_MB || "1", 10), return_limit_mb: parseInt(process.env.SF_FUNCSPAN_RETURN_LIMIT_MB || "1", 10), autocapture_all_child_functions: _(process.env.SF_FUNCSPAN_AUTOCAPTURE_ALL_CHILD_FUNCTIONS, !1), sample_rate: parseFloat(process.env.SF_FUNCSPAN_SAMPLE_RATE || "1.0"), enable_sampling: _(process.env.SF_FUNCSPAN_ENABLE_SAMPLING, !1), capture_sf_veritas: _(process.env.SF_FUNCSPAN_CAPTURE_SF_VERITAS, !1), parse_json_strings: _(process.env.SF_FUNCSPAN_PARSE_JSON_STRINGS, !1) };
68
68
  }
69
- function te() {
69
+ function ne() {
70
70
  return { capture_arguments: !1, capture_return_value: !1, arg_limit_mb: 1, return_limit_mb: 1, autocapture_all_child_functions: !1, sample_rate: 0, enable_sampling: !1, capture_sf_veritas: !1, parse_json_strings: !1 };
71
71
  }
72
- function ne(n) {
72
+ function re(n) {
73
73
  try {
74
74
  const t = n.split("-");
75
75
  return t.length !== 9 ? (console.error(`[FuncSpan] Invalid header format: expected 9 parts, got ${t.length}`), null) : { capture_arguments: t[0] === "1", capture_return_value: t[1] === "1", arg_limit_mb: parseInt(t[2], 10), return_limit_mb: parseInt(t[3], 10), autocapture_all_child_functions: t[4] === "1", sample_rate: parseFloat(t[5]), enable_sampling: t[6] === "1", capture_sf_veritas: t[7] === "1", parse_json_strings: t[8] === "1" };
@@ -82,21 +82,23 @@ function _(n, t) {
82
82
  const a = n.toLowerCase();
83
83
  return a === "true" || a === "1" || a === "yes";
84
84
  }
85
- const L = new V();
86
- function re(n) {
87
- L.enterWith(n);
88
- }
89
- function ae() {
90
- return L.getStore();
85
+ const F = "__sf_funcspanOverrideStorage";
86
+ globalThis[F] || (globalThis[F] = new J());
87
+ const w = globalThis[F];
88
+ function ae(n) {
89
+ w.enterWith(n);
91
90
  }
92
91
  function se() {
92
+ return w.getStore();
93
93
  }
94
- function oe(...n) {
94
+ function oe() {
95
+ }
96
+ function ie(...n) {
95
97
  const t = {};
96
98
  for (const a of n) for (const o in a) a[o] !== void 0 && (t[o] = a[o]);
97
99
  return t;
98
100
  }
99
- function w(n, t) {
101
+ function K(n, t) {
100
102
  try {
101
103
  const a = JSON.stringify(n).length / 1048576;
102
104
  return a <= t ? n : { _truncated: !0, _originalSizeMB: a.toFixed(2), _limitMB: t, _preview: JSON.stringify(n).substring(0, 500) + "..." };
@@ -108,17 +110,17 @@ function y(n, t) {
108
110
  const a = process.env[n];
109
111
  return a === void 0 ? t : a === "true" || a === "1";
110
112
  }
111
- function E(n, t) {
113
+ function D(n, t) {
112
114
  const a = process.env[n];
113
115
  if (a === void 0) return t;
114
116
  const o = parseFloat(a);
115
117
  return isNaN(o) ? t : o;
116
118
  }
117
- function O() {
118
- return { enabled: y("SF_WORKER_POOL_ENABLED", !0), trackFs: y("SF_WORKER_POOL_TRACK_FS", !1), trackDns: y("SF_WORKER_POOL_TRACK_DNS", !0), trackCrypto: y("SF_WORKER_POOL_TRACK_CRYPTO", !1), trackZlib: y("SF_WORKER_POOL_TRACK_ZLIB", !1), captureArguments: y("SF_WORKER_POOL_CAPTURE_ARGUMENTS", !0), captureReturnValue: y("SF_WORKER_POOL_CAPTURE_RETURN_VALUE", !0), argLimitMb: E("SF_WORKER_POOL_ARG_LIMIT_MB", 1), returnLimitMb: E("SF_WORKER_POOL_RETURN_LIMIT_MB", 1) };
119
+ function A() {
120
+ return { enabled: y("SF_WORKER_POOL_ENABLED", !0), trackFs: y("SF_WORKER_POOL_TRACK_FS", !1), trackDns: y("SF_WORKER_POOL_TRACK_DNS", !0), trackCrypto: y("SF_WORKER_POOL_TRACK_CRYPTO", !1), trackZlib: y("SF_WORKER_POOL_TRACK_ZLIB", !1), captureArguments: y("SF_WORKER_POOL_CAPTURE_ARGUMENTS", !0), captureReturnValue: y("SF_WORKER_POOL_CAPTURE_RETURN_VALUE", !0), argLimitMb: D("SF_WORKER_POOL_ARG_LIMIT_MB", 1), returnLimitMb: D("SF_WORKER_POOL_RETURN_LIMIT_MB", 1) };
119
121
  }
120
- function ie(n) {
121
- const t = O();
122
+ function ue(n) {
123
+ const t = A();
122
124
  if (!t.enabled) return !1;
123
125
  switch (n) {
124
126
  case "fs":
@@ -133,7 +135,7 @@ function ie(n) {
133
135
  return !1;
134
136
  }
135
137
  }
136
- function K(n, t, a, o) {
138
+ function B(n, t, a, o) {
137
139
  let s;
138
140
  try {
139
141
  switch (n) {
@@ -232,12 +234,12 @@ function K(n, t, a, o) {
232
234
  default:
233
235
  return null;
234
236
  }
235
- return o > 0 ? w(s, o) : s;
237
+ return o > 0 ? K(s, o) : s;
236
238
  } catch {
237
239
  return { error: "Failed to capture arguments", argsCount: a.length - 1 };
238
240
  }
239
241
  }
240
- function B(n, t, a, o) {
242
+ function M(n, t, a, o) {
241
243
  let s;
242
244
  try {
243
245
  switch (n) {
@@ -308,23 +310,23 @@ function B(n, t, a, o) {
308
310
  default:
309
311
  return null;
310
312
  }
311
- return o > 0 ? w(s, o) : s;
313
+ return o > 0 ? K(s, o) : s;
312
314
  } catch {
313
315
  return { error: "Failed to capture result", type: typeof a };
314
316
  }
315
317
  }
316
- function q(n) {
318
+ function G(n) {
317
319
  return n.operationType === "worker_pool";
318
320
  }
319
- class G extends x {
321
+ class Q extends j {
320
322
  constructor() {
321
323
  super(), this.operationName = "CollectFunctionSpans";
322
324
  }
323
325
  send(t) {
324
- const a = m().sfDebug;
326
+ const a = f().sfDebug;
325
327
  a && console.log(`[FunctionSpanTransmitter] Preparing to send ${t.length} function span(s)`);
326
328
  for (const o of t) try {
327
- if (q(o)) {
329
+ if (G(o)) {
328
330
  this.sendWorkerPoolSpan(o, a);
329
331
  continue;
330
332
  }
@@ -334,8 +336,8 @@ class G extends x {
334
336
  const r = typeof s.result;
335
337
  i = JSON.stringify({ type: r, has_value: !0, value: s.result });
336
338
  } else i = s.result === null ? JSON.stringify({ type: "null", has_value: !0, value: null }) : JSON.stringify({ type: "undefined", has_value: !1, value: null });
337
- const e = this.getVariables({ library: "JS/TS BACKEND", version: m().version, spanId: s.spanId, parentSpanId: s.parentSpanId, filePath: s.filePath, lineNumber: s.metadata.line, columnNumber: s.metadata.column, functionName: s.functionName, arguments: JSON.stringify(s.args || {}), returnValue: i, startTimeNs: (1e6 * Date.now() - 1e6 * s.duration).toString(), durationNs: (1e6 * s.duration).toString() });
338
- a && (console.log(`[FunctionSpanTransmitter] Sending GraphQL mutation to ${this.endpoint}`), console.log("[FunctionSpanTransmitter] Variables:", JSON.stringify(e, null, 2))), C(this.endpoint, this.operationName, this.getQuery(), e), a && console.log(`[FunctionSpanTransmitter] Queued function span for ${s.functionName}`);
339
+ const e = this.getVariables({ library: "JS/TS BACKEND", version: f().version, spanId: s.spanId, parentSpanId: s.parentSpanId, filePath: s.filePath, lineNumber: s.metadata.line, columnNumber: s.metadata.column, functionName: s.functionName, arguments: JSON.stringify(s.args || {}), returnValue: i, startTimeNs: (1e6 * Date.now() - 1e6 * s.duration).toString(), durationNs: (1e6 * s.duration).toString() });
340
+ a && (console.log(`[FunctionSpanTransmitter] Sending GraphQL mutation to ${this.endpoint}`), console.log("[FunctionSpanTransmitter] Variables:", JSON.stringify(e, null, 2))), E(this.endpoint, this.operationName, this.getQuery(), e), a && console.log(`[FunctionSpanTransmitter] Queued function span for ${s.functionName}`);
339
341
  } catch (s) {
340
342
  console.error(`[FunctionSpanTransmitter] Error preparing function span for ${o.functionName}:`, s);
341
343
  }
@@ -347,8 +349,8 @@ class G extends x {
347
349
  const i = typeof t.result;
348
350
  o = JSON.stringify({ type: i, has_value: !0, value: t.result });
349
351
  } else o = t.result === null ? JSON.stringify({ type: "null", has_value: !0, value: null }) : JSON.stringify({ type: "undefined", has_value: !1, value: null });
350
- const s = this.getVariables({ library: "JS/TS BACKEND", version: m().version, spanId: t.spanId, operationName: t.operationName, moduleName: t.moduleName, methodName: t.methodName, startTimeNs: t.startTimeNs, durationNs: t.durationNs, arguments: JSON.stringify(t.args || {}), returnValue: o, error: t.error, pid: t.pid, threadId: t.threadId });
351
- a && (console.log(`[FunctionSpanTransmitter] Sending worker pool span: ${t.operationName}`), console.log("[FunctionSpanTransmitter] Variables:", JSON.stringify(s, null, 2))), C(this.endpoint, "CollectWorkerPoolSpans", this.getWorkerPoolQuery(), s), a && console.log(`[FunctionSpanTransmitter] Queued worker pool span for ${t.operationName}`);
352
+ const s = this.getVariables({ library: "JS/TS BACKEND", version: f().version, spanId: t.spanId, operationName: t.operationName, moduleName: t.moduleName, methodName: t.methodName, startTimeNs: t.startTimeNs, durationNs: t.durationNs, arguments: JSON.stringify(t.args || {}), returnValue: o, error: t.error, pid: t.pid, threadId: t.threadId });
353
+ a && (console.log(`[FunctionSpanTransmitter] Sending worker pool span: ${t.operationName}`), console.log("[FunctionSpanTransmitter] Variables:", JSON.stringify(s, null, 2))), E(this.endpoint, "CollectWorkerPoolSpans", this.getWorkerPoolQuery(), s), a && console.log(`[FunctionSpanTransmitter] Queued worker pool span for ${t.operationName}`);
352
354
  } catch (o) {
353
355
  console.error(`[FunctionSpanTransmitter] Error preparing worker pool span for ${t.operationName}:`, o);
354
356
  }
@@ -441,75 +443,75 @@ class G extends x {
441
443
  }
442
444
  }
443
445
  let v = null;
444
- function ue(n, t, a, o, s) {
445
- const i = P(), e = i?.sfDebug || !1;
446
+ function le(n, t, a, o, s) {
447
+ const i = O(), e = i?.sfDebug || !1;
446
448
  e && console.log(`[WorkerPool] Capturing ${n}.${t}`);
447
- const r = O(), u = k.getInstance().getCurrentFunctionSpanId(), d = D();
449
+ const r = A(), u = P.getInstance().getCurrentFunctionSpanId(), d = L();
448
450
  e && console.log(`[WorkerPool] Span ID: ${d}, Parent: ${u || "none"}`);
449
- const l = new J("WorkerPoolOperation"), p = process.hrtime.bigint();
451
+ const l = new z("WorkerPoolOperation"), p = process.hrtime.bigint();
450
452
  let c = null;
451
- r.captureArguments && (c = K(n, t, o, r.argLimitMb));
453
+ r.captureArguments && (c = B(n, t, o, r.argLimitMb));
452
454
  const g = o.findIndex((N) => typeof N == "function");
453
455
  if (g === -1) return e && console.log(`[WorkerPool] No callback found for ${n}.${t}`), a.apply(s, o);
454
- const f = o[g], h = [...o];
456
+ const m = o[g], h = [...o];
455
457
  return h[g] = function(N, ...b) {
456
- const I = process.hrtime.bigint() - p, A = Number(I) / 1e6;
457
- f(N, ...b), l.runInAsyncScope(() => {
458
- e && console.log(`[WorkerPool] ${n}.${t} completed in ${A.toFixed(3)}ms (${I}ns)`);
459
- let U = null, R = null;
460
- N ? R = N?.message || String(N) : r.captureReturnValue && b.length > 0 && (U = B(n, t, b[0], r.returnLimitMb)), T({ operationType: "worker_pool", operationName: `${n}.${t}`, moduleName: n, methodName: t, duration: A, durationNs: I.toString(), startTimeNs: p.toString(), args: c, result: U, error: R, spanId: d, parentSpanId: u, pid: process.pid, threadId: F });
458
+ const I = process.hrtime.bigint() - p, U = Number(I) / 1e6;
459
+ m(N, ...b), l.runInAsyncScope(() => {
460
+ e && console.log(`[WorkerPool] ${n}.${t} completed in ${U.toFixed(3)}ms (${I}ns)`);
461
+ let R = null, C = null;
462
+ N ? C = N?.message || String(N) : r.captureReturnValue && b.length > 0 && (R = M(n, t, b[0], r.returnLimitMb)), k({ operationType: "worker_pool", operationName: `${n}.${t}`, moduleName: n, methodName: t, duration: U, durationNs: I.toString(), startTimeNs: p.toString(), args: c, result: R, error: C, spanId: d, parentSpanId: u, pid: process.pid, threadId: T });
461
463
  }), l.emitDestroy();
462
464
  }, a.apply(s, h);
463
465
  }
464
- function le(n, t, a, o, s) {
465
- const i = P(), e = i?.sfDebug || !1;
466
+ function ce(n, t, a, o, s) {
467
+ const i = O(), e = i?.sfDebug || !1;
466
468
  e && console.log(`[WorkerPool] Capturing ${n}.${t} (Promise)`);
467
- const r = O(), u = k.getInstance().getCurrentFunctionSpanId(), d = D();
469
+ const r = A(), u = P.getInstance().getCurrentFunctionSpanId(), d = L();
468
470
  e && console.log(`[WorkerPool] Span ID: ${d}, Parent: ${u || "none"}`);
469
471
  const l = process.hrtime.bigint();
470
472
  let p = null;
471
- return r.captureArguments && (p = K(n, t, o, r.argLimitMb)), a.apply(s, o).then((c) => {
472
- const g = process.hrtime.bigint() - l, f = Number(g) / 1e6;
473
- e && console.log(`[WorkerPool] ${n}.${t} completed in ${f.toFixed(3)}ms (${g}ns)`);
473
+ return r.captureArguments && (p = B(n, t, o, r.argLimitMb)), a.apply(s, o).then((c) => {
474
+ const g = process.hrtime.bigint() - l, m = Number(g) / 1e6;
475
+ e && console.log(`[WorkerPool] ${n}.${t} completed in ${m.toFixed(3)}ms (${g}ns)`);
474
476
  let h = null;
475
- return r.captureReturnValue && (h = B(n, t, c, r.returnLimitMb)), T({ operationType: "worker_pool", operationName: `${n}.${t}`, moduleName: n, methodName: t, duration: f, durationNs: g.toString(), startTimeNs: l.toString(), args: p, result: h, error: null, spanId: d, parentSpanId: u, pid: process.pid, threadId: F }), c;
477
+ return r.captureReturnValue && (h = M(n, t, c, r.returnLimitMb)), k({ operationType: "worker_pool", operationName: `${n}.${t}`, moduleName: n, methodName: t, duration: m, durationNs: g.toString(), startTimeNs: l.toString(), args: p, result: h, error: null, spanId: d, parentSpanId: u, pid: process.pid, threadId: T }), c;
476
478
  }, (c) => {
477
- const g = process.hrtime.bigint() - l, f = Number(g) / 1e6;
478
- throw e && console.log(`[WorkerPool] ${n}.${t} failed in ${f.toFixed(3)}ms: ${c?.message || c}`), T({ operationType: "worker_pool", operationName: `${n}.${t}`, moduleName: n, methodName: t, duration: f, durationNs: g.toString(), startTimeNs: l.toString(), args: p, result: null, error: c?.message || String(c), spanId: d, parentSpanId: u, pid: process.pid, threadId: F }), c;
479
+ const g = process.hrtime.bigint() - l, m = Number(g) / 1e6;
480
+ throw e && console.log(`[WorkerPool] ${n}.${t} failed in ${m.toFixed(3)}ms: ${c?.message || c}`), k({ operationType: "worker_pool", operationName: `${n}.${t}`, moduleName: n, methodName: t, duration: m, durationNs: g.toString(), startTimeNs: l.toString(), args: p, result: null, error: c?.message || String(c), spanId: d, parentSpanId: u, pid: process.pid, threadId: T }), c;
479
481
  });
480
482
  }
481
- function T(n) {
482
- const t = P(), a = t?.sfDebug || !1;
483
+ function k(n) {
484
+ const t = O(), a = t?.sfDebug || !1;
483
485
  a && console.log("[WorkerPool] Capturing span:", { operation: n.operationName, duration: `${n.duration}ms`, error: n.error, spanId: n.spanId, parentSpanId: n.parentSpanId }), process.env.SF_FUNCSPAN_CONSOLE_OUTPUT === "true" && console.log(`
484
486
  ⚙️ Worker Pool Operation:`, { operation: n.operationName, duration: `${n.duration.toFixed(2)}ms`, arguments: n.args, result: n.error ? `Error: ${n.error}` : n.result, spanId: n.spanId, parentSpanId: n.parentSpanId || "none" });
485
487
  const o = process.env.SF_FUNCSPAN_JSONL_FILE;
486
488
  if (o) try {
487
489
  const s = o === "true" || o === "1" ? "funcspans.jsonl" : o, i = Date.now(), e = process.hrtime.bigint(), r = BigInt(n.startTimeNs), u = Number(e - r) / 1e6, d = new Date(i - u).toISOString(), l = JSON.stringify({ timestamp: d, operationType: n.operationType, operationName: n.operationName, moduleName: n.moduleName, methodName: n.methodName, duration: n.duration, durationNs: n.durationNs, startTimeNs: n.startTimeNs, arguments: n.args, returnValue: n.error ? { error: String(n.error) } : n.result, spanId: n.spanId, parentSpanId: n.parentSpanId, pid: n.pid, threadId: n.threadId }) + `
488
490
  `;
489
- z(s, l, "utf-8");
491
+ x(s, l, "utf-8");
490
492
  } catch (s) {
491
493
  console.error("[WorkerPool] Error writing to JSONL file:", s);
492
494
  }
493
495
  if (a && console.log("[WorkerPool] Sending span to transmitter"), process.env.SF_FUNCSPAN_SKIP_BACKEND !== "true") try {
494
- (v || (v = new G()), v).send([n]), a && console.log("[WorkerPool] Span sent successfully");
496
+ (v || (v = new Q()), v).send([n]), a && console.log("[WorkerPool] Span sent successfully");
495
497
  } catch (s) {
496
498
  a && console.error("[WorkerPool] Error sending span:", s);
497
499
  }
498
500
  }
499
501
  export {
500
- x as B,
501
- G as F,
502
- ee as a,
502
+ j as B,
503
+ Q as F,
504
+ ne as a,
503
505
  te as b,
504
- ue as c,
505
- le as d,
506
- se as e,
507
- L as f,
508
- ae as g,
509
- ie as i,
510
- oe as m,
511
- C as n,
512
- ne as p,
513
- re as s,
514
- w as t
506
+ le as c,
507
+ ce as d,
508
+ oe as e,
509
+ w as f,
510
+ se as g,
511
+ ue as i,
512
+ ie as m,
513
+ E as n,
514
+ re as p,
515
+ ae as s,
516
+ K as t
515
517
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sailfish-ai/sf-veritas",
3
- "version": "0.2.13",
3
+ "version": "0.2.16",
4
4
  "publishPublicly": true,
5
5
  "description": "A versatile Edge Runtime-compatible package for JavaScript and TypeScript backend systems and scripts.",
6
6
  "main": "./dist/sf-veritas.cjs",
@@ -89,6 +89,7 @@
89
89
  "@babel/types": "^7.26.0",
90
90
  "glob": "^11.1.0",
91
91
  "js-yaml": "^4.1.0",
92
+ "toml": "^3.0.0",
92
93
  "next": "^15.1.7",
93
94
  "source-map-js": "^1.2.1",
94
95
  "uuid": "^11.1.0"
@@ -1 +0,0 @@
1
- "use strict";const v=require("async_hooks"),o=[];for(let s=0;s<256;++s)o.push((s+256).toString(16).slice(1));let h;const L=new Uint8Array(16),S={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function p(s,e,t){if(S.randomUUID&&!s)return S.randomUUID();const n=(s=s||{}).random??s.rng?.()??(function(){if(!h){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");h=crypto.getRandomValues.bind(crypto)}return h(L)})();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=15&n[6]|64,n[8]=63&n[8]|128,(function(r,i=0){return(o[r[i+0]]+o[r[i+1]]+o[r[i+2]]+o[r[i+3]]+"-"+o[r[i+4]]+o[r[i+5]]+"-"+o[r[i+6]]+o[r[i+7]]+"-"+o[r[i+8]]+o[r[i+9]]+"-"+o[r[i+10]]+o[r[i+11]]+o[r[i+12]]+o[r[i+13]]+o[r[i+14]]+o[r[i+15]]).toLowerCase()})(n)}class _{apiKey;apiGraphqlEndpoint;sfDebug;serviceIdentifier;serviceVersion;serviceUUID;serviceAdditionalMetadata;profilingModeEnabled;profilingMaxDepth;profilingMaxVariableSizeKb;domainsToNotPropagateHeadersTo;nodeModulesToCollectLocalVariablesOn;printConfigurationStatuses;logLevel;stackDepthLocals;stackDepthCodeTraceDepth;packageLibraryType;version;gitSha;_serviceIdentificationReceived=!1;constructor(e){this.apiKey=e.apiKey,this.apiGraphqlEndpoint=e?.apiGraphqlEndpoint||process.env.SAILFISH_GRAPHQL_ENDPOINT||"https://api-service.sailfishqa.com/graphql/",this.sfDebug=e?.debug===!0||process.env.SF_DEBUG==="true",this.serviceIdentifier=e?.serviceIdentifier||process.env.SERVICE_IDENTIFIER,this.serviceUUID=p(),this.serviceVersion=e?.serviceVersion||process.env.SERVICE_VERSION,this.gitSha=e?.gitSha||process.env.GIT_SHA||process.env.VERCEL_GIT_COMMIT_SHA,this.serviceAdditionalMetadata=e?.serviceAdditionalMetadata||{},this.profilingModeEnabled=e?.profilingModeEnabled??!1,this.profilingMaxDepth=e?.profilingMaxDepth??5,this.profilingMaxVariableSizeKb=e?.profilingMaxVariableSizeKb??25,this.domainsToNotPropagateHeadersTo=e?.domainsToNotPropagateHeadersTo||[],this.nodeModulesToCollectLocalVariablesOn=e?.nodeModulesToCollectLocalVariablesOn||["_all_"],this.printConfigurationStatuses=process.env.PRINT_CONFIGURATION_STATUSES||"true",this.logLevel=process.env.LOG_LEVEL||"INFO",this.stackDepthLocals=process.env.SAILFISH_EXCEPTION_STACK_DEPTH_LOCALS!==void 0?parseInt(process.env.SAILFISH_EXCEPTION_STACK_DEPTH_LOCALS,10):5,isNaN(this.stackDepthLocals)&&(this.stackDepthLocals=-1),this.stackDepthCodeTraceDepth=process.env.SAILFISH_EXCEPTION_STACK_DEPTH_CODE_TRACE_DEPTH!==void 0?parseInt(process.env.SAILFISH_EXCEPTION_STACK_DEPTH_CODE_TRACE_DEPTH,10):-1,isNaN(this.stackDepthCodeTraceDepth)&&(this.stackDepthCodeTraceDepth=-1),this.packageLibraryType="JS/TS BACKEND",this.version=this.getPackageVersion()}getPackageVersion(){return"0.1.15"}get serviceIdentificationReceived(){return this._serviceIdentificationReceived}setServiceIdentificationReceived(e){this._serviceIdentificationReceived=e}}const T=Symbol.for("sailfish.sf_config");function I(){return globalThis[T]}function l(){const s=I();if(!s)throw new Error("Configuration has not been initialized. Call getOrCreateConfig(options) first.");return s}const f=Symbol.for("sf.ctx.storeAls"),a=globalThis,C=a[f]??(a[f]=new v.AsyncLocalStorage),x=["identitytoolkit.googleapis.com","t.co","*.twitter.com","*.gravatar.com","*.googleapis.com","*.amazonaws.com","*.smooch.io","*.zendesk.com"],D=Symbol.for("sf.ctx.als"),u=a[D]??(a[D]=new v.AsyncLocalStorage),E=Symbol.for("sf.ctx.sessionRegistry"),d=a[E]??(a[E]=new Map),g={handledExceptions:new Set,reentrancyGuardLoggingActive:!1,reentrancyGuardLoggingPreActive:!1,reentrancyGuardPrintActive:!1,reentrancyGuardPrintPreActive:!1,reentrancyGuardExceptionActive:!1,reentrancyGuardExceptionPreActive:!1,excludedDomains:new Set(x),supportedDomains:new Set};class c{static GLOBAL_MANAGER_SYMBOL=Symbol.for("sf.ctx.manager");constructor(){}current(){return C.getStore()}ensureStore(){const e=this.current();if(e)return e;const t=new Map;return C.enterWith(t),t}runWith(e,t){const n=this.current()??new Map,r=new Map(n);for(const[i,A]of Object.entries(e))r.set(i,A);return C.run(r,t)}static getInstance(){return a[c.GLOBAL_MANAGER_SYMBOL]||(a[c.GLOBAL_MANAGER_SYMBOL]=new c),a[c.GLOBAL_MANAGER_SYMBOL]}getCurrentContext(){return u.getStore()||g}setCurrentContext(e){const t=u.getStore()||g;u.enterWith({...t,...e})}ensureSession(e){let t=d.get(e);return t||(t={...g},d.set(e,t)),t}getContextFor(e){return d.get(e)??g}updateContextFor(e,t){const n=this.ensureSession(e);d.set(e,{...n,...t})}runWithSession(e,t){const n={...this.ensureSession(e)};return u.run(n,t)}deleteSession(e){d.delete(e)}getTraceId(){return this.getCurrentContext().traceId}getPageVisitUUID(){return this.getCurrentContext().pageVisitUUID}setTraceId(e){this.setCurrentContext({traceId:e})}setPageVisitUUID(e){this.setCurrentContext({pageVisitUUID:e})}getCurrentFunctionSpanId(){return this.getCurrentContext().currentFunctionSpanId}setCurrentFunctionSpanId(e){this.setCurrentContext({currentFunctionSpanId:e})}clearCurrentFunctionSpanId(){this.setCurrentContext({currentFunctionSpanId:void 0})}getOrSetSfTraceId(e,t=!1){let n=this.getTraceId();return n||(n=e||(t?p():`nonsession-applogs-v3/${l().apiKey}/${p()}`),this.setTraceId(n),l().sfDebug&&console.log(" Created new trace ID:",n),n)}getOrSetPageVisitUUID(){let e=this.getPageVisitUUID();return e||(e=p(),this.setPageVisitUUID(e),l().sfDebug&&console.log(" Created new page visit UUID:",e),e)}getHandledExceptions(){return this.getCurrentContext().handledExceptions}markExceptionHandled(e){const t=this.getHandledExceptions();t.add(e),this.setCurrentContext({handledExceptions:t})}hasHandledException(e){return this.getHandledExceptions().has(e)}resetHandledExceptions(){this.setCurrentContext({handledExceptions:new Set})}getExcludedDomains(){return this.getCurrentContext().excludedDomains}getSupportedDomains(){return this.getCurrentContext().supportedDomains}addSupportedDomains(e){this.getCurrentContext().supportedDomains.add(e.toLowerCase().trim())}setTraceIdFor(e,t){this.updateContextFor(e,{traceId:t})}setPageVisitUUIDFor(e,t){this.updateContextFor(e,{pageVisitUUID:t})}}exports.ContextManager=c,exports.DEFAULT_DOMAINS_TO_EXCLUDE=x,exports.getConfig=l,exports.getCurrentFunctionSpanId=function(){return c.getInstance().getCurrentFunctionSpanId()},exports.getGlobalConfigUnsafe=I,exports.getOrCreateConfig=function(s){const e=I();if(e)return{config:e};const t=new _(s);return(function(n){globalThis[T]=n})(t),t.sfDebug&&console.log("[[getOrCreateConfig]] Created global config:",t),{config:t}},exports.runWithContext=function(s){const e={...c.getInstance().getCurrentContext()};u.run(e,()=>{s()})},exports.v4=p;