@sailfish-ai/sf-veritas 0.2.7 → 0.2.9

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 (40) hide show
  1. package/dist/contextManager-CEPhVu9T.js +197 -0
  2. package/dist/contextManager-CGINtRN5.cjs +1 -0
  3. package/dist/funcSpanTransformer-B9WWl-g1.cjs +1 -0
  4. package/dist/funcSpanTransformer-CWNEWRxq.js +225 -0
  5. package/dist/plugins/funcspanEsbuildPlugin.cjs +1 -1
  6. package/dist/plugins/funcspanEsbuildPlugin.mjs +17 -11
  7. package/dist/plugins/funcspanRollupPlugin.cjs +1 -1
  8. package/dist/plugins/funcspanRollupPlugin.mjs +13 -8
  9. package/dist/plugins/funcspanTscPlugin.cjs +1 -1
  10. package/dist/plugins/funcspanTscPlugin.mjs +19 -14
  11. package/dist/plugins/funcspanVitePlugin.cjs +1 -1
  12. package/dist/plugins/funcspanVitePlugin.mjs +15 -10
  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 +22 -17
  17. package/dist/runtime/funcspanRegister.cjs +276 -0
  18. package/dist/runtimeConfig-CpQ27dZD.cjs +8 -0
  19. package/dist/runtimeConfig-emBNO3lJ.js +350 -0
  20. package/dist/sf-veritas.cjs +18 -18
  21. package/dist/sf-veritas.mjs +417 -619
  22. package/dist/source-map-Cr6YkjTd.js +631 -0
  23. package/dist/source-map-rHHEdpre.cjs +1 -0
  24. package/dist/types/dataTransmitter.d.ts +1 -0
  25. package/dist/types/funcSpanConfigLoader.d.ts +10 -0
  26. package/dist/types/index.d.ts +3 -1
  27. package/dist/types/logHandler.d.ts +5 -0
  28. package/dist/types/plugins/funcSpanTransformer.d.ts +13 -0
  29. package/dist/types/runtime/instrumentationDetector.d.ts +33 -0
  30. package/dist/types/runtime/runtimeConfig.d.ts +48 -0
  31. package/dist/types/sourceLocation.d.ts +30 -0
  32. package/dist/worker-pool-capture.cjs +1 -1
  33. package/dist/worker-pool-capture.mjs +1 -1
  34. package/dist/workerPoolSpanCapture-B5KN-q4b.js +528 -0
  35. package/dist/workerPoolSpanCapture-Dg_WGjmO.cjs +86 -0
  36. package/package.json +5 -2
  37. package/dist/funcSpanTransformer-BLhIRZqX.js +0 -765
  38. package/dist/funcSpanTransformer-BpWuHXKT.cjs +0 -1
  39. package/dist/workerPoolSpanCapture-D0-0Z0Jw.js +0 -718
  40. package/dist/workerPoolSpanCapture-DEwlTq0a.cjs +0 -86
@@ -0,0 +1,528 @@
1
+ var W = Object.defineProperty;
2
+ var V = (n, t, s) => t in n ? W(n, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : n[t] = s;
3
+ var S = (n, t, s) => V(n, typeof t != "symbol" ? t + "" : t, s);
4
+ import { AsyncLocalStorage as J, AsyncResource as z } from "async_hooks";
5
+ import { appendFileSync as j } from "fs";
6
+ import { threadId as T } from "worker_threads";
7
+ import { g as f, C as O, a as A, v as w } from "./contextManager-CEPhVu9T.js";
8
+ class x {
9
+ constructor() {
10
+ S(this, "apiKey");
11
+ S(this, "endpoint");
12
+ S(this, "queryType", "mutation");
13
+ S(this, "operationName", "");
14
+ S(this, "serviceUUID", f().serviceUUID);
15
+ S(this, "contextManager");
16
+ this.apiKey = f().apiKey, this.endpoint = f().apiGraphqlEndpoint, this.contextManager = O.getInstance();
17
+ }
18
+ get queryName() {
19
+ return this.operationName ? this.operationName.charAt(0).toLowerCase() + this.operationName.slice(1) : "";
20
+ }
21
+ getDefaultVariables() {
22
+ const t = Date.now().toString(), s = this.contextManager.getOrSetSfTraceId(), o = this.contextManager.getCurrentFunctionSpanId();
23
+ return { apiKey: this.apiKey, serviceUuid: this.serviceUUID, sessionId: s, timestampMs: t, parentSpanId: o };
24
+ }
25
+ getVariables(t = {}) {
26
+ return { ...this.getDefaultVariables(), ...t };
27
+ }
28
+ setOperationName(t) {
29
+ this.operationName = t;
30
+ }
31
+ setEndpoint(t) {
32
+ this.endpoint = t;
33
+ }
34
+ setServiceUUID(t) {
35
+ this.serviceUUID = t;
36
+ }
37
+ }
38
+ const q = fetch;
39
+ let $ = !1;
40
+ async function D(n, t, s, o) {
41
+ try {
42
+ const a = f();
43
+ let i;
44
+ try {
45
+ i = JSON.stringify({ query: s, variables: o, operationName: t });
46
+ } catch {
47
+ i = JSON.stringify({ query: s, operationName: t });
48
+ }
49
+ $ = !0, q(n, { method: "POST", headers: { "Content-Type": "application/json" }, body: i }).then(async (e) => {
50
+ if ($ = !1, !e.ok) return void (a.sfDebug && console.error(`GraphQL request failed with status ${e.status} for ${t}`));
51
+ const r = await e.json();
52
+ r.errors?.length ? (function(u, d, l) {
53
+ const p = u && typeof u == "object" && !Array.isArray(u) ? Object.keys(u)[0] : void 0;
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
+ })(r.data, r.errors, a) : a.sfDebug && (function(u, d, l) {
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), f().sfDebug && console.log(`IdentifyServiceDetails sent successfully for service: UUID=${l.serviceUUID}; serviceIdentificationReceived=${p === "identifyServiceDetails" ? c : "N/A"}`));
58
+ })(r.data, 0, a);
59
+ }).catch((e) => {
60
+ $ = !1, a.sfDebug && (console.error(`[RequestUtils] Fetch error for ${t} to ${n}:`, e), e.cause && console.error("[RequestUtils] Error cause:", e.cause));
61
+ });
62
+ } catch (a) {
63
+ $ = !1, f().sfDebug && console.error("Error sending data to GraphQL server:", a);
64
+ }
65
+ }
66
+ function te() {
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
+ }
69
+ function ne() {
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
+ }
72
+ function re(n) {
73
+ try {
74
+ const t = n.split("-");
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" };
76
+ } catch (t) {
77
+ return console.error(`[FuncSpan] Failed to parse header override "${n}":`, t), null;
78
+ }
79
+ }
80
+ function _(n, t) {
81
+ if (!n) return t;
82
+ const s = n.toLowerCase();
83
+ return s === "true" || s === "1" || s === "yes";
84
+ }
85
+ const k = new J();
86
+ let I = !1;
87
+ function se(n) {
88
+ k.enterWith(n);
89
+ }
90
+ function ae() {
91
+ if (I) return k.getStore();
92
+ try {
93
+ I = !0;
94
+ const n = k.getStore(), t = new Error().stack?.split(`
95
+ `).slice(1, 4).join(`
96
+ `);
97
+ return console.log(`[getFuncspanOverride] Called from:
98
+ ${t}`), console.log("[getFuncspanOverride] Returned value:", n), n;
99
+ } catch (n) {
100
+ return void console.error("[getFuncspanOverride] ❌ Error:", n);
101
+ } finally {
102
+ I = !1;
103
+ }
104
+ }
105
+ function oe() {
106
+ }
107
+ function ie(...n) {
108
+ const t = {};
109
+ for (const s of n) for (const o in s) s[o] !== void 0 && (t[o] = s[o]);
110
+ return t;
111
+ }
112
+ function K(n, t) {
113
+ try {
114
+ const s = JSON.stringify(n).length / 1048576;
115
+ return s <= t ? n : { _truncated: !0, _originalSizeMB: s.toFixed(2), _limitMB: t, _preview: JSON.stringify(n).substring(0, 500) + "..." };
116
+ } catch {
117
+ return { _error: "Failed to serialize data", _type: typeof n };
118
+ }
119
+ }
120
+ function y(n, t) {
121
+ const s = process.env[n];
122
+ return s === void 0 ? t : s === "true" || s === "1";
123
+ }
124
+ function L(n, t) {
125
+ const s = process.env[n];
126
+ if (s === void 0) return t;
127
+ const o = parseFloat(s);
128
+ return isNaN(o) ? t : o;
129
+ }
130
+ function U() {
131
+ 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: L("SF_WORKER_POOL_ARG_LIMIT_MB", 1), returnLimitMb: L("SF_WORKER_POOL_RETURN_LIMIT_MB", 1) };
132
+ }
133
+ function ue(n) {
134
+ const t = U();
135
+ if (!t.enabled) return !1;
136
+ switch (n) {
137
+ case "fs":
138
+ return t.trackFs;
139
+ case "dns":
140
+ return t.trackDns;
141
+ case "crypto":
142
+ return t.trackCrypto;
143
+ case "zlib":
144
+ return t.trackZlib;
145
+ default:
146
+ return !1;
147
+ }
148
+ }
149
+ function B(n, t, s, o) {
150
+ let a;
151
+ try {
152
+ switch (n) {
153
+ case "fs":
154
+ a = (function(i, e) {
155
+ const r = {};
156
+ switch (i) {
157
+ case "readFile":
158
+ case "writeFile":
159
+ case "appendFile":
160
+ 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));
161
+ break;
162
+ case "readdir":
163
+ case "stat":
164
+ case "lstat":
165
+ case "access":
166
+ case "chmod":
167
+ case "mkdir":
168
+ case "rmdir":
169
+ case "unlink":
170
+ r.path = String(e[0] || ""), e[1] && typeof e[1] == "object" && (r.options = { ...e[1] }, delete r.options.callback);
171
+ break;
172
+ case "rename":
173
+ r.oldPath = String(e[0] || ""), r.newPath = String(e[1] || "");
174
+ break;
175
+ case "open":
176
+ r.path = String(e[0] || ""), r.flags = e[1], r.mode = e[2];
177
+ break;
178
+ case "close":
179
+ case "fstat":
180
+ r.fd = e[0];
181
+ break;
182
+ case "read":
183
+ case "write":
184
+ 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];
185
+ break;
186
+ default:
187
+ r.argsCount = e.length - 1;
188
+ }
189
+ return r;
190
+ })(t, s);
191
+ break;
192
+ case "dns":
193
+ a = (function(i, e) {
194
+ const r = {};
195
+ switch (i) {
196
+ case "lookup":
197
+ 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]);
198
+ break;
199
+ case "resolve":
200
+ case "resolve4":
201
+ case "resolve6":
202
+ case "resolveAny":
203
+ case "resolveMx":
204
+ case "resolveNs":
205
+ case "resolveTxt":
206
+ r.hostname = String(e[0] || "");
207
+ break;
208
+ case "reverse":
209
+ r.ip = String(e[0] || "");
210
+ break;
211
+ default:
212
+ r.argsCount = e.length - 1;
213
+ }
214
+ return r;
215
+ })(t, s);
216
+ break;
217
+ case "crypto":
218
+ a = (function(i, e) {
219
+ const r = {};
220
+ switch (i) {
221
+ case "pbkdf2":
222
+ r.passwordType = typeof e[0], r.saltType = typeof e[1], r.iterations = e[2], r.keylen = e[3], r.digest = e[4];
223
+ break;
224
+ case "scrypt":
225
+ 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);
226
+ break;
227
+ case "randomBytes":
228
+ r.size = e[0];
229
+ break;
230
+ case "generateKeyPair":
231
+ r.type = e[0], typeof e[1] == "object" && (r.modulusLength = e[1].modulusLength, r.namedCurve = e[1].namedCurve);
232
+ break;
233
+ default:
234
+ r.argsCount = e.length - 1;
235
+ }
236
+ return r;
237
+ })(t, s);
238
+ break;
239
+ case "zlib":
240
+ a = (function(i, e) {
241
+ const r = {};
242
+ 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;
243
+ })(0, s);
244
+ break;
245
+ default:
246
+ return null;
247
+ }
248
+ return o > 0 ? K(a, o) : a;
249
+ } catch {
250
+ return { error: "Failed to capture arguments", argsCount: s.length - 1 };
251
+ }
252
+ }
253
+ function M(n, t, s, o) {
254
+ let a;
255
+ try {
256
+ switch (n) {
257
+ case "fs":
258
+ a = (function(i, e) {
259
+ if (!e) return null;
260
+ switch (i) {
261
+ case "readFile":
262
+ return Buffer.isBuffer(e) ? { type: "Buffer", size: e.length } : typeof e == "string" ? { type: "string", size: e.length } : { type: typeof e };
263
+ case "readdir":
264
+ return { count: Array.isArray(e) ? e.length : 0, items: e };
265
+ case "stat":
266
+ case "lstat":
267
+ case "fstat":
268
+ return { size: e.size, mode: e.mode, isFile: e.isFile(), isDirectory: e.isDirectory() };
269
+ case "open":
270
+ return { fd: e };
271
+ case "read":
272
+ return { bytesRead: e };
273
+ case "write":
274
+ return { bytesWritten: e };
275
+ default:
276
+ return e;
277
+ }
278
+ })(t, s);
279
+ break;
280
+ case "dns":
281
+ a = (function(i, e) {
282
+ if (!e) return null;
283
+ switch (i) {
284
+ case "lookup":
285
+ return Array.isArray(e) ? { count: e.length, addresses: e } : e;
286
+ case "resolve":
287
+ case "resolve4":
288
+ case "resolve6":
289
+ case "resolveAny":
290
+ case "resolveMx":
291
+ case "resolveNs":
292
+ case "resolveTxt":
293
+ return { count: Array.isArray(e) ? e.length : 0, records: e };
294
+ case "reverse":
295
+ return { hostnames: e };
296
+ default:
297
+ return e;
298
+ }
299
+ })(t, s);
300
+ break;
301
+ case "crypto":
302
+ a = (function(i, e) {
303
+ if (!e) return null;
304
+ switch (i) {
305
+ case "pbkdf2":
306
+ case "scrypt":
307
+ case "randomBytes":
308
+ return Buffer.isBuffer(e) ? { type: "Buffer", size: e.length } : { type: typeof e };
309
+ case "generateKeyPair":
310
+ return { hasPublicKey: !!e?.publicKey, hasPrivateKey: !!e?.privateKey };
311
+ default:
312
+ return e;
313
+ }
314
+ })(t, s);
315
+ break;
316
+ case "zlib":
317
+ a = (function(i, e) {
318
+ return e ? Buffer.isBuffer(e) ? { type: "Buffer", size: e.length } : typeof e == "string" ? { type: "string", size: e.length } : { type: typeof e } : null;
319
+ })(0, s);
320
+ break;
321
+ default:
322
+ return null;
323
+ }
324
+ return o > 0 ? K(a, o) : a;
325
+ } catch {
326
+ return { error: "Failed to capture result", type: typeof s };
327
+ }
328
+ }
329
+ function G(n) {
330
+ return n.operationType === "worker_pool";
331
+ }
332
+ class Q extends x {
333
+ constructor() {
334
+ super(), this.operationName = "CollectFunctionSpans";
335
+ }
336
+ send(t) {
337
+ const s = f().sfDebug;
338
+ s && console.log(`[FunctionSpanTransmitter] Preparing to send ${t.length} function span(s)`);
339
+ for (const o of t) try {
340
+ if (G(o)) {
341
+ this.sendWorkerPoolSpan(o, s);
342
+ continue;
343
+ }
344
+ const a = o;
345
+ let i;
346
+ if (a.result !== void 0 && a.result !== null) {
347
+ const r = typeof a.result;
348
+ i = JSON.stringify({ type: r, has_value: !0, value: a.result });
349
+ } else i = a.result === null ? JSON.stringify({ type: "null", has_value: !0, value: null }) : JSON.stringify({ type: "undefined", has_value: !1, value: null });
350
+ const e = this.getVariables({ library: "JS/TS BACKEND", version: f().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() });
351
+ s && (console.log(`[FunctionSpanTransmitter] Sending GraphQL mutation to ${this.endpoint}`), console.log("[FunctionSpanTransmitter] Variables:", JSON.stringify(e, null, 2))), D(this.endpoint, this.operationName, this.getQuery(), e), s && console.log(`[FunctionSpanTransmitter] Queued function span for ${a.functionName}`);
352
+ } catch (a) {
353
+ console.error(`[FunctionSpanTransmitter] Error preparing function span for ${o.functionName}:`, a);
354
+ }
355
+ }
356
+ sendWorkerPoolSpan(t, s) {
357
+ try {
358
+ let o;
359
+ if (t.result !== void 0 && t.result !== null) {
360
+ const i = typeof t.result;
361
+ o = JSON.stringify({ type: i, has_value: !0, value: t.result });
362
+ } else o = t.result === null ? JSON.stringify({ type: "null", has_value: !0, value: null }) : JSON.stringify({ type: "undefined", has_value: !1, value: null });
363
+ const a = 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 });
364
+ s && (console.log(`[FunctionSpanTransmitter] Sending worker pool span: ${t.operationName}`), console.log("[FunctionSpanTransmitter] Variables:", JSON.stringify(a, null, 2))), D(this.endpoint, "CollectWorkerPoolSpans", this.getWorkerPoolQuery(), a), s && console.log(`[FunctionSpanTransmitter] Queued worker pool span for ${t.operationName}`);
365
+ } catch (o) {
366
+ console.error(`[FunctionSpanTransmitter] Error preparing worker pool span for ${t.operationName}:`, o);
367
+ }
368
+ }
369
+ getWorkerPoolQuery() {
370
+ return `
371
+ mutation CollectWorkerPoolSpans(
372
+ $apiKey: String!,
373
+ $serviceUuid: String!,
374
+ $sessionId: String!,
375
+ $timestampMs: String!,
376
+ $library: String!,
377
+ $version: String!,
378
+ $spanId: String!,
379
+ $operationName: String!,
380
+ $moduleName: String!,
381
+ $methodName: String!,
382
+ $startTimeNs: String!,
383
+ $durationNs: String!,
384
+ $parentSpanId: String,
385
+ $arguments: String,
386
+ $returnValue: String,
387
+ $error: String,
388
+ $pid: Int,
389
+ $threadId: Int
390
+ ) {
391
+ collectWorkerPoolSpans(
392
+ apiKey: $apiKey,
393
+ serviceUuid: $serviceUuid,
394
+ sessionId: $sessionId,
395
+ timestampMs: $timestampMs,
396
+ library: $library,
397
+ version: $version,
398
+ spanId: $spanId,
399
+ operationName: $operationName,
400
+ moduleName: $moduleName,
401
+ methodName: $methodName,
402
+ startTimeNs: $startTimeNs,
403
+ durationNs: $durationNs,
404
+ parentSpanId: $parentSpanId,
405
+ arguments: $arguments,
406
+ returnValue: $returnValue,
407
+ error: $error,
408
+ pid: $pid,
409
+ threadId: $threadId
410
+ )
411
+ }
412
+ `;
413
+ }
414
+ getQuery() {
415
+ return `
416
+ ${this.queryType} ${this.operationName}(
417
+ $apiKey: String!,
418
+ $serviceUuid: String!,
419
+ $sessionId: String!,
420
+ $timestampMs: String!,
421
+ $parentSpanId: String,
422
+ $library: String!,
423
+ $version: String!,
424
+ $spanId: String!,
425
+ $filePath: String!,
426
+ $lineNumber: Int!,
427
+ $columnNumber: Int!,
428
+ $functionName: String!,
429
+ $arguments: String!,
430
+ $returnValue: String,
431
+ $startTimeNs: String!,
432
+ $durationNs: String!
433
+ ) {
434
+ ${this.queryName}(
435
+ apiKey: $apiKey,
436
+ serviceUuid: $serviceUuid,
437
+ sessionId: $sessionId,
438
+ timestampMs: $timestampMs,
439
+ parentSpanId: $parentSpanId,
440
+ library: $library,
441
+ version: $version,
442
+ spanId: $spanId,
443
+ filePath: $filePath,
444
+ lineNumber: $lineNumber,
445
+ columnNumber: $columnNumber,
446
+ functionName: $functionName,
447
+ arguments: $arguments,
448
+ returnValue: $returnValue,
449
+ startTimeNs: $startTimeNs,
450
+ durationNs: $durationNs
451
+ )
452
+ }
453
+ `;
454
+ }
455
+ }
456
+ let F = null;
457
+ function le(n, t, s, o, a) {
458
+ const i = A(), e = i?.sfDebug || !1;
459
+ e && console.log(`[WorkerPool] Capturing ${n}.${t}`);
460
+ const r = U(), u = O.getInstance().getCurrentFunctionSpanId(), d = w();
461
+ e && console.log(`[WorkerPool] Span ID: ${d}, Parent: ${u || "none"}`);
462
+ const l = new z("WorkerPoolOperation"), p = process.hrtime.bigint();
463
+ let c = null;
464
+ r.captureArguments && (c = B(n, t, o, r.argLimitMb));
465
+ const g = o.findIndex((N) => typeof N == "function");
466
+ if (g === -1) return e && console.log(`[WorkerPool] No callback found for ${n}.${t}`), s.apply(a, o);
467
+ const m = o[g], h = [...o];
468
+ return h[g] = function(N, ...b) {
469
+ const v = process.hrtime.bigint() - p, R = Number(v) / 1e6;
470
+ m(N, ...b), l.runInAsyncScope(() => {
471
+ e && console.log(`[WorkerPool] ${n}.${t} completed in ${R.toFixed(3)}ms (${v}ns)`);
472
+ let C = null, E = null;
473
+ N ? E = N?.message || String(N) : r.captureReturnValue && b.length > 0 && (C = M(n, t, b[0], r.returnLimitMb)), P({ operationType: "worker_pool", operationName: `${n}.${t}`, moduleName: n, methodName: t, duration: R, durationNs: v.toString(), startTimeNs: p.toString(), args: c, result: C, error: E, spanId: d, parentSpanId: u, pid: process.pid, threadId: T });
474
+ }), l.emitDestroy();
475
+ }, s.apply(a, h);
476
+ }
477
+ function ce(n, t, s, o, a) {
478
+ const i = A(), e = i?.sfDebug || !1;
479
+ e && console.log(`[WorkerPool] Capturing ${n}.${t} (Promise)`);
480
+ const r = U(), u = O.getInstance().getCurrentFunctionSpanId(), d = w();
481
+ e && console.log(`[WorkerPool] Span ID: ${d}, Parent: ${u || "none"}`);
482
+ const l = process.hrtime.bigint();
483
+ let p = null;
484
+ return r.captureArguments && (p = B(n, t, o, r.argLimitMb)), s.apply(a, o).then((c) => {
485
+ const g = process.hrtime.bigint() - l, m = Number(g) / 1e6;
486
+ e && console.log(`[WorkerPool] ${n}.${t} completed in ${m.toFixed(3)}ms (${g}ns)`);
487
+ let h = null;
488
+ return r.captureReturnValue && (h = M(n, t, c, r.returnLimitMb)), P({ 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;
489
+ }, (c) => {
490
+ const g = process.hrtime.bigint() - l, m = Number(g) / 1e6;
491
+ throw e && console.log(`[WorkerPool] ${n}.${t} failed in ${m.toFixed(3)}ms: ${c?.message || c}`), P({ 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;
492
+ });
493
+ }
494
+ function P(n) {
495
+ const t = A(), s = t?.sfDebug || !1;
496
+ s && 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(`
497
+ ⚙️ 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" });
498
+ const o = process.env.SF_FUNCSPAN_JSONL_FILE;
499
+ if (o) try {
500
+ const a = 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 }) + `
501
+ `;
502
+ j(a, l, "utf-8");
503
+ } catch (a) {
504
+ console.error("[WorkerPool] Error writing to JSONL file:", a);
505
+ }
506
+ if (s && console.log("[WorkerPool] Sending span to transmitter"), process.env.SF_FUNCSPAN_SKIP_BACKEND !== "true") try {
507
+ (F || (F = new Q()), F).send([n]), s && console.log("[WorkerPool] Span sent successfully");
508
+ } catch (a) {
509
+ s && console.error("[WorkerPool] Error sending span:", a);
510
+ }
511
+ }
512
+ export {
513
+ x as B,
514
+ Q as F,
515
+ te as a,
516
+ ne as b,
517
+ le as c,
518
+ ce as d,
519
+ oe as e,
520
+ k as f,
521
+ ae as g,
522
+ ue as i,
523
+ ie as m,
524
+ D as n,
525
+ re as p,
526
+ se as s,
527
+ K as t
528
+ };
@@ -0,0 +1,86 @@
1
+ "use strict";var K=Object.defineProperty;var V=(n,t,o)=>t in n?K(n,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[t]=o;var S=(n,t,o)=>V(n,typeof t!="symbol"?t+"":t,o);const M=require("async_hooks"),J=require("fs"),F=require("worker_threads"),l=require("./contextManager-CGINtRN5.cjs");class W{constructor(){S(this,"apiKey");S(this,"endpoint");S(this,"queryType","mutation");S(this,"operationName","");S(this,"serviceUUID",l.getConfig().serviceUUID);S(this,"contextManager");this.apiKey=l.getConfig().apiKey,this.endpoint=l.getConfig().apiGraphqlEndpoint,this.contextManager=l.ContextManager.getInstance()}get queryName(){return this.operationName?this.operationName.charAt(0).toLowerCase()+this.operationName.slice(1):""}getDefaultVariables(){const t=Date.now().toString(),o=this.contextManager.getOrSetSfTraceId(),s=this.contextManager.getCurrentFunctionSpanId();return{apiKey:this.apiKey,serviceUuid:this.serviceUUID,sessionId:o,timestampMs:t,parentSpanId:s}}getVariables(t={}){return{...this.getDefaultVariables(),...t}}setOperationName(t){this.operationName=t}setEndpoint(t){this.endpoint=t}setServiceUUID(t){this.serviceUUID=t}}const x=fetch;let $=!1;async function C(n,t,o,s){try{const a=l.getConfig();let i;try{i=JSON.stringify({query:o,variables:s,operationName:t})}catch{i=JSON.stringify({query:o,operationName:t})}$=!0,x(n,{method:"POST",headers:{"Content-Type":"application/json"},body:i}).then(async e=>{if($=!1,!e.ok)return void(a.sfDebug&&console.error(`GraphQL request failed with status ${e.status} for ${t}`));const r=await e.json();r.errors?.length?(function(u,g,c){const d=u&&typeof u=="object"&&!Array.isArray(u)?Object.keys(u)[0]:void 0;console.error(d==="identifyServiceDetails"?`IdentifyServiceDetails NOT sent successfully for service: UUID=${c.serviceUUID}`:`GraphQL request failed with errors: ${JSON.stringify(g)} for operation key ${d}`)})(r.data,r.errors,a):a.sfDebug&&(function(u,g,c){const d=u&&typeof u=="object"&&!Array.isArray(u)?Object.keys(u)[0]:void 0,p=u[d]||!1;d==="identifyServiceDetails"&&(c.setServiceIdentificationReceived(p),l.getConfig().sfDebug&&console.log(`IdentifyServiceDetails sent successfully for service: UUID=${c.serviceUUID}; serviceIdentificationReceived=${d==="identifyServiceDetails"?p:"N/A"}`))})(r.data,0,a)}).catch(e=>{$=!1,a.sfDebug&&(console.error(`[RequestUtils] Fetch error for ${t} to ${n}:`,e),e.cause&&console.error("[RequestUtils] Error cause:",e.cause))})}catch(a){$=!1,l.getConfig().sfDebug&&console.error("Error sending data to GraphQL server:",a)}}function h(n,t){if(!n)return t;const o=n.toLowerCase();return o==="true"||o==="1"||o==="yes"}const v=new M.AsyncLocalStorage;let T=!1;function A(n,t){try{const o=JSON.stringify(n).length/1048576;return o<=t?n:{_truncated:!0,_originalSizeMB:o.toFixed(2),_limitMB:t,_preview:JSON.stringify(n).substring(0,500)+"..."}}catch{return{_error:"Failed to serialize data",_type:typeof n}}}function y(n,t){const o=process.env[n];return o===void 0?t:o==="true"||o==="1"}function D(n,t){const o=process.env[n];if(o===void 0)return t;const s=parseFloat(o);return isNaN(s)?t:s}function k(){return{enabled:y("SF_WORKER_POOL_ENABLED",!0),trackFs:y("SF_WORKER_POOL_TRACK_FS",!1),trackDns:y("SF_WORKER_POOL_TRACK_DNS",!0),trackCrypto:y("SF_WORKER_POOL_TRACK_CRYPTO",!1),trackZlib:y("SF_WORKER_POOL_TRACK_ZLIB",!1),captureArguments:y("SF_WORKER_POOL_CAPTURE_ARGUMENTS",!0),captureReturnValue:y("SF_WORKER_POOL_CAPTURE_RETURN_VALUE",!0),argLimitMb:D("SF_WORKER_POOL_ARG_LIMIT_MB",1),returnLimitMb:D("SF_WORKER_POOL_RETURN_LIMIT_MB",1)}}function L(n,t,o,s){let a;try{switch(n){case"fs":a=(function(i,e){const r={};switch(i){case"readFile":case"writeFile":case"appendFile":r.path=String(e[0]||""),e[1]&&typeof e[1]=="object"?(r.encoding=e[1].encoding||null,r.flag=e[1].flag||null):typeof e[1]=="string"&&(r.encoding=e[1]),i!=="writeFile"&&i!=="appendFile"||(Buffer.isBuffer(e[1])?(r.dataType="Buffer",r.dataSize=e[1].length):typeof e[1]=="string"&&(r.dataType="string",r.dataSize=e[1].length));break;case"readdir":case"stat":case"lstat":case"access":case"chmod":case"mkdir":case"rmdir":case"unlink":r.path=String(e[0]||""),e[1]&&typeof e[1]=="object"&&(r.options={...e[1]},delete r.options.callback);break;case"rename":r.oldPath=String(e[0]||""),r.newPath=String(e[1]||"");break;case"open":r.path=String(e[0]||""),r.flags=e[1],r.mode=e[2];break;case"close":case"fstat":r.fd=e[0];break;case"read":case"write":r.fd=e[0],Buffer.isBuffer(e[1])&&(r.bufferSize=e[1].length),r.offset=e[2],r.length=e[3],r.position=e[4];break;default:r.argsCount=e.length-1}return r})(t,o);break;case"dns":a=(function(i,e){const r={};switch(i){case"lookup":r.hostname=String(e[0]||""),typeof e[1]=="object"?(r.family=e[1].family,r.all=e[1].all):typeof e[1]=="number"&&(r.family=e[1]);break;case"resolve":case"resolve4":case"resolve6":case"resolveAny":case"resolveMx":case"resolveNs":case"resolveTxt":r.hostname=String(e[0]||"");break;case"reverse":r.ip=String(e[0]||"");break;default:r.argsCount=e.length-1}return r})(t,o);break;case"crypto":a=(function(i,e){const r={};switch(i){case"pbkdf2":r.passwordType=typeof e[0],r.saltType=typeof e[1],r.iterations=e[2],r.keylen=e[3],r.digest=e[4];break;case"scrypt":r.passwordType=typeof e[0],r.saltType=typeof e[1],r.keylen=e[2],typeof e[3]=="object"&&(r.N=e[3].N,r.r=e[3].r,r.p=e[3].p);break;case"randomBytes":r.size=e[0];break;case"generateKeyPair":r.type=e[0],typeof e[1]=="object"&&(r.modulusLength=e[1].modulusLength,r.namedCurve=e[1].namedCurve);break;default:r.argsCount=e.length-1}return r})(t,o);break;case"zlib":a=(function(i,e){const r={};return Buffer.isBuffer(e[0])?(r.inputType="Buffer",r.inputSize=e[0].length):typeof e[0]=="string"?(r.inputType="string",r.inputSize=e[0].length):r.inputType=typeof e[0],e[1]&&typeof e[1]=="object"&&typeof e[1]!="function"&&(r.options={...e[1]}),r})(0,o);break;default:return null}return s>0?A(a,s):a}catch{return{error:"Failed to capture arguments",argsCount:o.length-1}}}function w(n,t,o,s){let a;try{switch(n){case"fs":a=(function(i,e){if(!e)return null;switch(i){case"readFile":return Buffer.isBuffer(e)?{type:"Buffer",size:e.length}:typeof e=="string"?{type:"string",size:e.length}:{type:typeof e};case"readdir":return{count:Array.isArray(e)?e.length:0,items:e};case"stat":case"lstat":case"fstat":return{size:e.size,mode:e.mode,isFile:e.isFile(),isDirectory:e.isDirectory()};case"open":return{fd:e};case"read":return{bytesRead:e};case"write":return{bytesWritten:e};default:return e}})(t,o);break;case"dns":a=(function(i,e){if(!e)return null;switch(i){case"lookup":return Array.isArray(e)?{count:e.length,addresses:e}:e;case"resolve":case"resolve4":case"resolve6":case"resolveAny":case"resolveMx":case"resolveNs":case"resolveTxt":return{count:Array.isArray(e)?e.length:0,records:e};case"reverse":return{hostnames:e};default:return e}})(t,o);break;case"crypto":a=(function(i,e){if(!e)return null;switch(i){case"pbkdf2":case"scrypt":case"randomBytes":return Buffer.isBuffer(e)?{type:"Buffer",size:e.length}:{type:typeof e};case"generateKeyPair":return{hasPublicKey:!!e?.publicKey,hasPrivateKey:!!e?.privateKey};default:return e}})(t,o);break;case"zlib":a=(function(i,e){return e?Buffer.isBuffer(e)?{type:"Buffer",size:e.length}:typeof e=="string"?{type:"string",size:e.length}:{type:typeof e}:null})(0,o);break;default:return null}return s>0?A(a,s):a}catch{return{error:"Failed to capture result",type:typeof o}}}function z(n){return n.operationType==="worker_pool"}class B extends W{constructor(){super(),this.operationName="CollectFunctionSpans"}send(t){const o=l.getConfig().sfDebug;o&&console.log(`[FunctionSpanTransmitter] Preparing to send ${t.length} function span(s)`);for(const s of t)try{if(z(s)){this.sendWorkerPoolSpan(s,o);continue}const a=s;let i;if(a.result!==void 0&&a.result!==null){const r=typeof a.result;i=JSON.stringify({type:r,has_value:!0,value:a.result})}else i=a.result===null?JSON.stringify({type:"null",has_value:!0,value:null}):JSON.stringify({type:"undefined",has_value:!1,value:null});const e=this.getVariables({library:"JS/TS BACKEND",version:l.getConfig().version,spanId:a.spanId,parentSpanId:a.parentSpanId,filePath:a.filePath,lineNumber:a.metadata.line,columnNumber:a.metadata.column,functionName:a.functionName,arguments:JSON.stringify(a.args||{}),returnValue:i,startTimeNs:(1e6*Date.now()-1e6*a.duration).toString(),durationNs:(1e6*a.duration).toString()});o&&(console.log(`[FunctionSpanTransmitter] Sending GraphQL mutation to ${this.endpoint}`),console.log("[FunctionSpanTransmitter] Variables:",JSON.stringify(e,null,2))),C(this.endpoint,this.operationName,this.getQuery(),e),o&&console.log(`[FunctionSpanTransmitter] Queued function span for ${a.functionName}`)}catch(a){console.error(`[FunctionSpanTransmitter] Error preparing function span for ${s.functionName}:`,a)}}sendWorkerPoolSpan(t,o){try{let s;if(t.result!==void 0&&t.result!==null){const i=typeof t.result;s=JSON.stringify({type:i,has_value:!0,value:t.result})}else s=t.result===null?JSON.stringify({type:"null",has_value:!0,value:null}):JSON.stringify({type:"undefined",has_value:!1,value:null});const a=this.getVariables({library:"JS/TS BACKEND",version:l.getConfig().version,spanId:t.spanId,operationName:t.operationName,moduleName:t.moduleName,methodName:t.methodName,startTimeNs:t.startTimeNs,durationNs:t.durationNs,arguments:JSON.stringify(t.args||{}),returnValue:s,error:t.error,pid:t.pid,threadId:t.threadId});o&&(console.log(`[FunctionSpanTransmitter] Sending worker pool span: ${t.operationName}`),console.log("[FunctionSpanTransmitter] Variables:",JSON.stringify(a,null,2))),C(this.endpoint,"CollectWorkerPoolSpans",this.getWorkerPoolQuery(),a),o&&console.log(`[FunctionSpanTransmitter] Queued worker pool span for ${t.operationName}`)}catch(s){console.error(`[FunctionSpanTransmitter] Error preparing worker pool span for ${t.operationName}:`,s)}}getWorkerPoolQuery(){return`
2
+ mutation CollectWorkerPoolSpans(
3
+ $apiKey: String!,
4
+ $serviceUuid: String!,
5
+ $sessionId: String!,
6
+ $timestampMs: String!,
7
+ $library: String!,
8
+ $version: String!,
9
+ $spanId: String!,
10
+ $operationName: String!,
11
+ $moduleName: String!,
12
+ $methodName: String!,
13
+ $startTimeNs: String!,
14
+ $durationNs: String!,
15
+ $parentSpanId: String,
16
+ $arguments: String,
17
+ $returnValue: String,
18
+ $error: String,
19
+ $pid: Int,
20
+ $threadId: Int
21
+ ) {
22
+ collectWorkerPoolSpans(
23
+ apiKey: $apiKey,
24
+ serviceUuid: $serviceUuid,
25
+ sessionId: $sessionId,
26
+ timestampMs: $timestampMs,
27
+ library: $library,
28
+ version: $version,
29
+ spanId: $spanId,
30
+ operationName: $operationName,
31
+ moduleName: $moduleName,
32
+ methodName: $methodName,
33
+ startTimeNs: $startTimeNs,
34
+ durationNs: $durationNs,
35
+ parentSpanId: $parentSpanId,
36
+ arguments: $arguments,
37
+ returnValue: $returnValue,
38
+ error: $error,
39
+ pid: $pid,
40
+ threadId: $threadId
41
+ )
42
+ }
43
+ `}getQuery(){return`
44
+ ${this.queryType} ${this.operationName}(
45
+ $apiKey: String!,
46
+ $serviceUuid: String!,
47
+ $sessionId: String!,
48
+ $timestampMs: String!,
49
+ $parentSpanId: String,
50
+ $library: String!,
51
+ $version: String!,
52
+ $spanId: String!,
53
+ $filePath: String!,
54
+ $lineNumber: Int!,
55
+ $columnNumber: Int!,
56
+ $functionName: String!,
57
+ $arguments: String!,
58
+ $returnValue: String,
59
+ $startTimeNs: String!,
60
+ $durationNs: String!
61
+ ) {
62
+ ${this.queryName}(
63
+ apiKey: $apiKey,
64
+ serviceUuid: $serviceUuid,
65
+ sessionId: $sessionId,
66
+ timestampMs: $timestampMs,
67
+ parentSpanId: $parentSpanId,
68
+ library: $library,
69
+ version: $version,
70
+ spanId: $spanId,
71
+ filePath: $filePath,
72
+ lineNumber: $lineNumber,
73
+ columnNumber: $columnNumber,
74
+ functionName: $functionName,
75
+ arguments: $arguments,
76
+ returnValue: $returnValue,
77
+ startTimeNs: $startTimeNs,
78
+ durationNs: $durationNs
79
+ )
80
+ }
81
+ `}}let P=null;function O(n){const t=l.getGlobalConfigUnsafe(),o=t?.sfDebug||!1;o&&console.log("[WorkerPool] Capturing span:",{operation:n.operationName,duration:`${n.duration}ms`,error:n.error,spanId:n.spanId,parentSpanId:n.parentSpanId}),process.env.SF_FUNCSPAN_CONSOLE_OUTPUT==="true"&&console.log(`
82
+ ⚙️ Worker Pool Operation:`,{operation:n.operationName,duration:`${n.duration.toFixed(2)}ms`,arguments:n.args,result:n.error?`Error: ${n.error}`:n.result,spanId:n.spanId,parentSpanId:n.parentSpanId||"none"});const s=process.env.SF_FUNCSPAN_JSONL_FILE;if(s)try{const a=s==="true"||s==="1"?"funcspans.jsonl":s,i=Date.now(),e=process.hrtime.bigint(),r=BigInt(n.startTimeNs),u=Number(e-r)/1e6,g=new Date(i-u).toISOString(),c=JSON.stringify({timestamp:g,operationType:n.operationType,operationName:n.operationName,moduleName:n.moduleName,methodName:n.methodName,duration:n.duration,durationNs:n.durationNs,startTimeNs:n.startTimeNs,arguments:n.args,returnValue:n.error?{error:String(n.error)}:n.result,spanId:n.spanId,parentSpanId:n.parentSpanId,pid:n.pid,threadId:n.threadId})+`
83
+ `;J.appendFileSync(a,c,"utf-8")}catch(a){console.error("[WorkerPool] Error writing to JSONL file:",a)}if(o&&console.log("[WorkerPool] Sending span to transmitter"),process.env.SF_FUNCSPAN_SKIP_BACKEND!=="true")try{(P||(P=new B),P).send([n]),o&&console.log("[WorkerPool] Span sent successfully")}catch(a){o&&console.error("[WorkerPool] Error sending span:",a)}}exports.BaseTransmitter=W,exports.FunctionSpanTransmitter=B,exports.captureWorkerPoolOperation=function(n,t,o,s,a){const i=l.getGlobalConfigUnsafe(),e=i?.sfDebug||!1;e&&console.log(`[WorkerPool] Capturing ${n}.${t}`);const r=k(),u=l.ContextManager.getInstance().getCurrentFunctionSpanId(),g=l.v4();e&&console.log(`[WorkerPool] Span ID: ${g}, Parent: ${u||"none"}`);const c=new M.AsyncResource("WorkerPoolOperation"),d=process.hrtime.bigint();let p=null;r.captureArguments&&(p=L(n,t,s,r.argLimitMb));const f=s.findIndex(N=>typeof N=="function");if(f===-1)return e&&console.log(`[WorkerPool] No callback found for ${n}.${t}`),o.apply(a,s);const m=s[f],_=[...s];return _[f]=function(N,...b){const I=process.hrtime.bigint()-d,U=Number(I)/1e6;m(N,...b),c.runInAsyncScope(()=>{e&&console.log(`[WorkerPool] ${n}.${t} completed in ${U.toFixed(3)}ms (${I}ns)`);let R=null,E=null;N?E=N?.message||String(N):r.captureReturnValue&&b.length>0&&(R=w(n,t,b[0],r.returnLimitMb)),O({operationType:"worker_pool",operationName:`${n}.${t}`,moduleName:n,methodName:t,duration:U,durationNs:I.toString(),startTimeNs:d.toString(),args:p,result:R,error:E,spanId:g,parentSpanId:u,pid:process.pid,threadId:F.threadId})}),c.emitDestroy()},o.apply(a,_)},exports.captureWorkerPoolPromiseOperation=function(n,t,o,s,a){const i=l.getGlobalConfigUnsafe(),e=i?.sfDebug||!1;e&&console.log(`[WorkerPool] Capturing ${n}.${t} (Promise)`);const r=k(),u=l.ContextManager.getInstance().getCurrentFunctionSpanId(),g=l.v4();e&&console.log(`[WorkerPool] Span ID: ${g}, Parent: ${u||"none"}`);const c=process.hrtime.bigint();let d=null;return r.captureArguments&&(d=L(n,t,s,r.argLimitMb)),o.apply(a,s).then(p=>{const f=process.hrtime.bigint()-c,m=Number(f)/1e6;e&&console.log(`[WorkerPool] ${n}.${t} completed in ${m.toFixed(3)}ms (${f}ns)`);let _=null;return r.captureReturnValue&&(_=w(n,t,p,r.returnLimitMb)),O({operationType:"worker_pool",operationName:`${n}.${t}`,moduleName:n,methodName:t,duration:m,durationNs:f.toString(),startTimeNs:c.toString(),args:d,result:_,error:null,spanId:g,parentSpanId:u,pid:process.pid,threadId:F.threadId}),p},p=>{const f=process.hrtime.bigint()-c,m=Number(f)/1e6;throw e&&console.log(`[WorkerPool] ${n}.${t} failed in ${m.toFixed(3)}ms: ${p?.message||p}`),O({operationType:"worker_pool",operationName:`${n}.${t}`,moduleName:n,methodName:t,duration:m,durationNs:f.toString(),startTimeNs:c.toString(),args:d,result:null,error:p?.message||String(p),spanId:g,parentSpanId:u,pid:process.pid,threadId:F.threadId}),p})},exports.clearFuncspanOverride=function(){},exports.funcspanOverrideStorage=v,exports.getDefaultConfig=function(){return{capture_arguments:!1,capture_return_value:!1,arg_limit_mb:1,return_limit_mb:1,autocapture_all_child_functions:!1,sample_rate:0,enable_sampling:!1,capture_sf_veritas:!1,parse_json_strings:!1}},exports.getEnvConfig=function(){return{capture_arguments:h(process.env.SF_FUNCSPAN_CAPTURE_ARGUMENTS,!0),capture_return_value:h(process.env.SF_FUNCSPAN_CAPTURE_RETURN_VALUE,!0),arg_limit_mb:parseInt(process.env.SF_FUNCSPAN_ARG_LIMIT_MB||"1",10),return_limit_mb:parseInt(process.env.SF_FUNCSPAN_RETURN_LIMIT_MB||"1",10),autocapture_all_child_functions:h(process.env.SF_FUNCSPAN_AUTOCAPTURE_ALL_CHILD_FUNCTIONS,!1),sample_rate:parseFloat(process.env.SF_FUNCSPAN_SAMPLE_RATE||"1.0"),enable_sampling:h(process.env.SF_FUNCSPAN_ENABLE_SAMPLING,!1),capture_sf_veritas:h(process.env.SF_FUNCSPAN_CAPTURE_SF_VERITAS,!1),parse_json_strings:h(process.env.SF_FUNCSPAN_PARSE_JSON_STRINGS,!1)}},exports.getFuncspanOverride=function(){if(T)return v.getStore();try{T=!0;const n=v.getStore(),t=new Error().stack?.split(`
84
+ `).slice(1,4).join(`
85
+ `);return console.log(`[getFuncspanOverride] Called from:
86
+ ${t}`),console.log("[getFuncspanOverride] Returned value:",n),n}catch(n){return void console.error("[getFuncspanOverride] ❌ Error:",n)}finally{T=!1}},exports.isModuleTrackingEnabled=function(n){const t=k();if(!t.enabled)return!1;switch(n){case"fs":return t.trackFs;case"dns":return t.trackDns;case"crypto":return t.trackCrypto;case"zlib":return t.trackZlib;default:return!1}},exports.mergeConfigs=function(...n){const t={};for(const o of n)for(const s in o)o[s]!==void 0&&(t[s]=o[s]);return t},exports.nonBlockingPost=C,exports.parseHeaderOverride=function(n){try{const t=n.split("-");return t.length!==9?(console.error(`[FuncSpan] Invalid header format: expected 9 parts, got ${t.length}`),null):{capture_arguments:t[0]==="1",capture_return_value:t[1]==="1",arg_limit_mb:parseInt(t[2],10),return_limit_mb:parseInt(t[3],10),autocapture_all_child_functions:t[4]==="1",sample_rate:parseFloat(t[5]),enable_sampling:t[6]==="1",capture_sf_veritas:t[7]==="1",parse_json_strings:t[8]==="1"}}catch(t){return console.error(`[FuncSpan] Failed to parse header override "${n}":`,t),null}},exports.setFuncspanOverride=function(n){v.enterWith(n)},exports.truncateToLimit=A;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sailfish-ai/sf-veritas",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
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",
@@ -44,6 +44,9 @@
44
44
  "./runtime/commonjs-hook": {
45
45
  "require": "./dist/runtime/funcspanRegister.cjs"
46
46
  },
47
+ "./runtime/register-hooks": {
48
+ "import": "./dist/runtime/funcspanRegisterHooks.mjs"
49
+ },
47
50
  "./runtime/register": {
48
51
  "import": "./dist/runtime/register.mjs",
49
52
  "require": "./dist/runtime/register.cjs",
@@ -80,7 +83,7 @@
80
83
  "@babel/parser": "^7.26.0",
81
84
  "@babel/traverse": "^7.26.0",
82
85
  "@babel/types": "^7.26.0",
83
- "glob": "^11.0.0",
86
+ "glob": "^11.1.0",
84
87
  "js-yaml": "^4.1.0",
85
88
  "next": "^15.1.7",
86
89
  "source-map-js": "^1.2.1",