@sailfish-ai/sf-veritas 0.2.16 → 0.2.18

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 (35) hide show
  1. package/dist/contextManager-C-sqFxpi.js +267 -0
  2. package/dist/contextManager-wMuxqwl9.cjs +1 -0
  3. package/dist/funcSpanTransformer-D0W2t41q.cjs +1 -0
  4. package/dist/funcSpanTransformer-S_WeAt_m.js +251 -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-B8LSswM8.cjs +9 -0
  18. package/dist/runtimeConfig-GwWjhV9M.js +379 -0
  19. package/dist/sf-veritas.cjs +13 -13
  20. package/dist/sf-veritas.mjs +277 -286
  21. package/dist/types/debuggerWorker.d.ts +2 -2
  22. package/dist/types/generated/worker-data.d.ts +1 -1
  23. package/dist/types/setupConfig.d.ts +5 -0
  24. package/dist/types/utils.d.ts +7 -0
  25. package/dist/worker-pool-capture.cjs +1 -1
  26. package/dist/worker-pool-capture.mjs +1 -1
  27. package/dist/{workerPoolSpanCapture-COwiNikM.cjs → workerPoolSpanCapture-B3yge78T.cjs} +2 -2
  28. package/dist/{workerPoolSpanCapture-d-8ExI18.js → workerPoolSpanCapture-DqBbNQLv.js} +26 -22
  29. package/package.json +9 -2
  30. package/dist/contextManager-Cx03mw7l.js +0 -258
  31. package/dist/contextManager-CxQqBCEA.cjs +0 -1
  32. package/dist/funcSpanTransformer-Byqzu4B1.js +0 -231
  33. package/dist/funcSpanTransformer-CDh0o-AP.cjs +0 -1
  34. package/dist/runtimeConfig-DndXTWki.js +0 -353
  35. package/dist/runtimeConfig-TWzqPe1S.cjs +0 -8
@@ -1,20 +1,21 @@
1
- var ge = Object.defineProperty;
2
- var fe = (r, t, e) => t in r ? ge(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
- var y = (r, t, e) => fe(r, typeof t != "symbol" ? t + "" : t, e);
4
- import { g as u, C as j, D as he, v as se, b as q, c as me, a as oe } from "./contextManager-Cx03mw7l.js";
5
- import { r as ft } from "./contextManager-Cx03mw7l.js";
6
- import { B as T, n as E, f as ye, g as ae, p as ce, a as de, b as Se, m as U, c as A, d as Ie, i as R, t as H, F as ve } from "./workerPoolSpanCapture-d-8ExI18.js";
7
- import { e as mt, s as yt } from "./workerPoolSpanCapture-d-8ExI18.js";
8
- import { C as $e, i as _, a as _e, h as P, b as be, c as Ne } from "./runtimeConfig-DndXTWki.js";
9
- import { d as It, e as vt, s as $t } from "./runtimeConfig-DndXTWki.js";
10
- import { createRequire as Fe } from "node:module";
11
- import * as M from "fs";
12
- import { readFileSync as De, appendFileSync as Pe } from "fs";
13
- import { s as Ee } from "./source-map-Cr6YkjTd.js";
14
- import * as F from "path";
15
- import { glob as we } from "glob";
16
- import { threadId as O } from "worker_threads";
17
- import { s as bt, t as Nt, a as Ft } from "./funcSpanTransformer-Byqzu4B1.js";
1
+ var he = Object.defineProperty;
2
+ var me = (r, t, e) => t in r ? he(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
+ var y = (r, t, e) => me(r, typeof t != "symbol" ? t + "" : t, e);
4
+ import { g as u, C as j, D as ye, v as oe, b as q, c as Se, d as Ie, a as ae } from "./contextManager-C-sqFxpi.js";
5
+ import { r as St } from "./contextManager-C-sqFxpi.js";
6
+ import { B as T, n as P, f as ve, g as ce, p as de, a as ue, b as $e, m as U, c as A, i as Q, d as _e, e as R, t as H, F as be } from "./workerPoolSpanCapture-DqBbNQLv.js";
7
+ import { h as vt, s as $t } from "./workerPoolSpanCapture-DqBbNQLv.js";
8
+ import { a as Fe, C as Ne, i as _, b as De, c as le, h as w, d as we, e as Pe } from "./runtimeConfig-GwWjhV9M.js";
9
+ import { f as bt, g as Ft, s as Nt } from "./runtimeConfig-GwWjhV9M.js";
10
+ import { createRequire as Ee } from "node:module";
11
+ import * as Te from "fs";
12
+ import { readFileSync as Ce, appendFileSync as Ue } from "fs";
13
+ import { s as Re } from "./source-map-Cr6YkjTd.js";
14
+ import * as X from "fs/promises";
15
+ import * as N from "path";
16
+ import { glob as Le } from "glob";
17
+ import { threadId as L } from "worker_threads";
18
+ import { s as wt, t as Pt, a as Et } from "./funcSpanTransformer-S_WeAt_m.js";
18
19
  class C extends T {
19
20
  constructor() {
20
21
  super(), this.setOperationName("IdentifyServiceDetails");
@@ -60,17 +61,10 @@ class C extends T {
60
61
  )
61
62
  }
62
63
  `, e = this.getVariables({ serviceIdentifier: u().serviceIdentifier, serviceVersion: u().serviceVersion, library: u().packageLibraryType, version: u().version, serviceAdditionalMetadata: u().serviceAdditionalMetadata, gitSha: u().gitSha || "", gitOrg: u().gitOrg || void 0, gitRepo: u().gitRepo || void 0, gitProvider: u().gitProvider || void 0, serviceDisplayName: u().serviceDisplayName || void 0 });
63
- E(this.endpoint, this.operationName, t, e);
64
+ P(this.endpoint, this.operationName, t, e);
64
65
  }
65
66
  }
66
- function Te(r) {
67
- try {
68
- return JSON.stringify(r), !0;
69
- } catch {
70
- return !1;
71
- }
72
- }
73
- class Ce extends T {
67
+ class Oe extends T {
74
68
  constructor() {
75
69
  super();
76
70
  y(this, "serviceIdentifier", new C());
@@ -86,15 +80,11 @@ class Ce extends T {
86
80
  if (!i && !o) throw new Error('Must pass in either traits or traits_json to "add_or_update_traits"');
87
81
  let d = [];
88
82
  if (!o) {
89
- const c = (function(a) {
90
- const l = {}, g = [];
91
- if (a) for (const [f, h] of Object.entries(a)) Te(h) ? l[f] = h : g.push(f);
92
- return { traitsJson: JSON.stringify(l), excludedFields: g };
93
- })(i);
94
- o = c.traitsJson, d = c.excludedFields;
83
+ const a = Fe(i);
84
+ o = a.traitsJson, d = a.excludedFields;
95
85
  }
96
86
  const s = this.getVariables({ userId: e, traitsJson: o, excludedFields: d, override: n, library: u().packageLibraryType, version: u().version });
97
- E(this.endpoint, this.operationName, this.getQuery(), s);
87
+ P(this.endpoint, this.operationName, this.getQuery(), s);
98
88
  }
99
89
  getQuery() {
100
90
  return `
@@ -104,10 +94,10 @@ class Ce extends T {
104
94
  `;
105
95
  }
106
96
  }
107
- class ue {
97
+ class pe {
108
98
  constructor(t) {
109
99
  y(this, "metadataTransmitter");
110
- this.apiKey = t, this.metadataTransmitter = new Ce();
100
+ this.apiKey = t, this.metadataTransmitter = new Oe();
111
101
  }
112
102
  identify(t, e, i, n = !1) {
113
103
  e || i ? this.addOrUpdateMetadata(t, e, i, n) : this.addOrUpdateMetadata(t, {}, void 0, n);
@@ -117,7 +107,7 @@ class ue {
117
107
  u().sfDebug && console.log(" [[DEBUG - addOrUpdateMetadata]] Starting operation"), u().sfDebug && console.log(" addOrUpdateMetadata...SENDING DATA...", t, e, i), this.metadataTransmitter.doSend(t, e, n, i);
118
108
  }
119
109
  }
120
- class V extends T {
110
+ class J extends T {
121
111
  constructor() {
122
112
  super();
123
113
  y(this, "serviceIdentifier", new C());
@@ -131,7 +121,7 @@ class V extends T {
131
121
  async send(e) {
132
122
  try {
133
123
  const i = Array.isArray(e) ? e : [e, "default", null, null], n = this.getVariables({ contents: i[0], level: i[1], sourceFile: i[2] || void 0, sourceLine: i[3] || void 0 });
134
- E(this.endpoint, this.operationName, this.getQuery(), n);
124
+ P(this.endpoint, this.operationName, this.getQuery(), n);
135
125
  } catch (i) {
136
126
  u().sfDebug && console.error("🚨 Error in send():", i);
137
127
  }
@@ -164,7 +154,7 @@ class V extends T {
164
154
  `;
165
155
  }
166
156
  }
167
- class Ue extends T {
157
+ class Ae extends T {
168
158
  constructor() {
169
159
  super();
170
160
  y(this, "serviceIdentifier", new C());
@@ -186,8 +176,8 @@ class Ue extends T {
186
176
  }
187
177
  async send(e, i) {
188
178
  u().sfDebug && console.log(" SENDING EXCEPTION...");
189
- const n = JSON.stringify($e.encode(i)), o = this.normalizedSupplementalForGraphQL(), d = this.getVariables({ exceptionMessage: e, traceJson: n, reentrancyGuardPreactive: !1, library: u().packageLibraryType, version: u().version, ...o });
190
- E(this.endpoint, this.operationName, this.getQuery(), d);
179
+ const n = JSON.stringify(Ne.encode(i)), o = this.normalizedSupplementalForGraphQL(), d = this.getVariables({ exceptionMessage: e, traceJson: n, reentrancyGuardPreactive: !1, library: u().packageLibraryType, version: u().version, ...o });
180
+ P(this.endpoint, this.operationName, this.getQuery(), d);
191
181
  }
192
182
  getQuery() {
193
183
  return `
@@ -221,51 +211,51 @@ class Ue extends T {
221
211
  `;
222
212
  }
223
213
  }
224
- const X = "getting request source code";
214
+ const Y = "getting request source code";
225
215
  var k = ((r) => (r.UNKNOWN = "unknown", r.ANONYMOUS = "anonymous", r.NOT_CAPTURED = "not captured", r))(k || {});
226
- const x = "http:", G = "https:", Re = Fe(import.meta.url);
227
- let Y = !1;
228
- function Oe() {
216
+ const M = "http:", x = "https:", ke = Ee(import.meta.url);
217
+ let Z = !1;
218
+ function qe() {
229
219
  const r = u().sfDebug;
230
- if (Y) return void (r && _("[patchNodeHttpInbound] Already installed, skipping."));
220
+ if (Z) return void (r && _("[patchNodeHttpInbound] Already installed, skipping."));
231
221
  let t;
232
- Y = !0;
222
+ Z = !0;
233
223
  try {
234
- t = Re("node:http"), r && _("[patchNodeHttpInbound] node:http required successfully.");
224
+ t = ke("node:http"), r && _("[patchNodeHttpInbound] node:http required successfully.");
235
225
  } catch (n) {
236
- return void _e("Failed to require node:http:", n);
226
+ return void De("Failed to require node:http:", n);
237
227
  }
238
228
  if (!t?.Server?.prototype) return void (r && _("[patchNodeHttpInbound] http.Server.prototype not found."));
239
229
  const e = t.Server.prototype, i = e.emit;
240
230
  i && !e.__sf_inbound_patched__ ? (Object.defineProperty(e, "__sf_inbound_patched__", { value: !0, enumerable: !1, configurable: !1, writable: !1 }), r && _("[patchNodeHttpInbound] Patching http.Server.prototype.emit."), e.emit = function(n, ...o) {
241
231
  if (n !== "request") return r && _(`[patchNodeHttpInbound] Passing through event: ${n}`), i.call(this, n, ...o);
242
- const d = o[0], s = o[1], c = (function(p) {
243
- const m = {};
244
- if (!p) return m;
245
- for (const [I, v] of Object.entries(p)) v != null && (Array.isArray(v) ? m[I.toLowerCase()] = v.join(", ") : m[I.toLowerCase()] = String(v));
246
- return m;
247
- })(d?.headers), a = c["x-sf3-rid"], l = c["x-sf3-functionspancaptureoverride"];
248
- r && (_("[patchNodeHttpInbound] Intercepted request event."), _("[patchNodeHttpInbound] Inbound headers:", c), _("[patchNodeHttpInbound] Trace header:", a), _("[patchNodeHttpInbound] FuncSpan override header:", l));
232
+ const d = o[0], s = o[1], a = (function(p) {
233
+ const f = {};
234
+ if (!p) return f;
235
+ for (const [I, v] of Object.entries(p)) v != null && (Array.isArray(v) ? f[I.toLowerCase()] = v.join(", ") : f[I.toLowerCase()] = String(v));
236
+ return f;
237
+ })(d?.headers), c = a["x-sf3-rid"], l = a["x-sf3-functionspancaptureoverride"];
238
+ r && (_("[patchNodeHttpInbound] Intercepted request event."), _("[patchNodeHttpInbound] Inbound headers:", a), _("[patchNodeHttpInbound] Trace header:", c), _("[patchNodeHttpInbound] FuncSpan override header:", l));
249
239
  const g = j.getInstance();
250
- g.setTraceId(a);
251
- const f = g.getTraceId();
252
- r && _("[patchNodeHttpInbound] Context traceId set:", f);
253
- const h = () => g.runWith({ inboundHeaders: c, ...a ? { traceId: a } : {} }, () => {
254
- a && g.setTraceId(a), r && _("[patchNodeHttpInbound] Running request handler in context.");
240
+ g.setTraceId(c);
241
+ const h = g.getTraceId();
242
+ r && _("[patchNodeHttpInbound] Context traceId set:", h);
243
+ const m = () => g.runWith({ inboundHeaders: a, ...c ? { traceId: c } : {} }, () => {
244
+ c && g.setTraceId(c), r && _("[patchNodeHttpInbound] Running request handler in context.");
255
245
  const p = () => {
256
246
  r && _("[patchNodeHttpInbound] Response finished/closed for traceId:", g.getTraceId());
257
247
  };
258
248
  return s.on("finish", p), s.on("close", p), i.call(this, n, d, s);
259
249
  });
260
- if (!l) return h();
250
+ if (!l) return m();
261
251
  try {
262
- return ye.run(l, () => h());
252
+ return ve.run(l, () => m());
263
253
  } catch {
264
- return h();
254
+ return m();
265
255
  }
266
256
  }) : r && _("[patchNodeHttpInbound] Already patched, skipping.");
267
257
  }
268
- class Le extends V {
258
+ class He extends J {
269
259
  constructor() {
270
260
  super(), this.setOperationName("DomainsToNotPassHeaderTo");
271
261
  }
@@ -286,10 +276,10 @@ class Le extends V {
286
276
  )
287
277
  }
288
278
  `, i = { apiKey: this.apiKey, serviceUuid: this.serviceUUID, domains: t };
289
- E(this.endpoint, this.operationName, e, i);
279
+ P(this.endpoint, this.operationName, e, i);
290
280
  }
291
281
  }
292
- class Ae extends T {
282
+ class Me extends T {
293
283
  constructor() {
294
284
  super();
295
285
  y(this, "serviceIdentifier", new C());
@@ -302,8 +292,8 @@ class Ae extends T {
302
292
  this.sendAppIdentifier(), this.send(e);
303
293
  }
304
294
  async send(e) {
305
- const { name: i, column: n, line: o, entrypoint: d, retryWithoutTraceId: s } = e, c = this.getVariables({ name: i, column: n, line: o, entrypoint: d, retryWithoutTraceId: s });
306
- E(this.endpoint, this.operationName, this.getQuery(), c);
295
+ const { name: i, column: n, line: o, entrypoint: d, retryWithoutTraceId: s } = e, a = this.getVariables({ name: i, column: n, line: o, entrypoint: d, retryWithoutTraceId: s });
296
+ P(this.endpoint, this.operationName, this.getQuery(), a);
307
297
  }
308
298
  getQuery() {
309
299
  return `
@@ -333,7 +323,7 @@ class Ae extends T {
333
323
  `;
334
324
  }
335
325
  }
336
- class ke extends T {
326
+ class xe extends T {
337
327
  constructor() {
338
328
  super();
339
329
  y(this, "serviceIdentifier", new C());
@@ -357,11 +347,11 @@ class ke extends T {
357
347
  }
358
348
  async send(e) {
359
349
  const i = { data: { ...e } };
360
- await E(this.endpoint, this.operationName, this.getQuery(), i);
350
+ await P(this.endpoint, this.operationName, this.getQuery(), i);
361
351
  }
362
352
  }
363
- const K = [400, 403];
364
- class qe {
353
+ const G = [400, 403];
354
+ class Ge {
365
355
  constructor(t = []) {
366
356
  y(this, "HEADER_TRACING", "X-Sf3-Rid");
367
357
  y(this, "HEADER_LOG_GUARD", "reentrancy_guard_logging_preactive");
@@ -397,8 +387,8 @@ class qe {
397
387
  if (t.includes("://")) return { originalPos: n };
398
388
  const o = t + ".map";
399
389
  try {
400
- const d = JSON.parse(De(o, "utf-8"));
401
- let s = (await new Ee.SourceMapConsumer(d)).originalPositionFor({ line: e, column: i });
390
+ const d = JSON.parse(Ce(o, "utf-8"));
391
+ let s = (await new Re.SourceMapConsumer(d)).originalPositionFor({ line: e, column: i });
402
392
  s.source && (n = s);
403
393
  } catch (d) {
404
394
  u().sfDebug && console.error(`Could not read/parse map file at ${o}:`, d);
@@ -408,22 +398,22 @@ class qe {
408
398
  captureFirstUserLines(t, e = 10, i = !1) {
409
399
  const n = u().sfDebug ? 10 : e, o = Error.stackTraceLimit;
410
400
  Error.stackTraceLimit = Math.max(o, n);
411
- const d = new Error(X);
412
- X in Error && Error.captureStackTrace(d, this.captureFirstUserLines);
413
- const s = d.stack || "";
401
+ const d = new Error(Y);
402
+ Y in Error && Error.captureStackTrace(d, this.captureFirstUserLines);
403
+ const s = le(d.stack);
414
404
  Error.stackTraceLimit = o;
415
- const c = s.split(`
416
- `).slice(1), a = [];
417
- for (const l of c)
418
- if (!(l.includes("node:internal") || l.includes("internal/modules") || l.includes("internal/process") || l.includes("node_modules") || l.includes(".next/server/chunks") || l.includes("RequestInterceptor") || l.includes("contextManager") || l.includes("setupConfig")) && (a.push(l.trim()), a.length >= e)) break;
419
- for (const l of a) {
405
+ const a = s.split(`
406
+ `).slice(1), c = [];
407
+ for (const l of a)
408
+ if (!(l.includes("node:internal") || l.includes("internal/modules") || l.includes("internal/process") || l.includes("node_modules") || l.includes(".next/server/chunks") || l.includes("RequestInterceptor") || l.includes("contextManager") || l.includes("setupConfig")) && (c.push(l.trim()), c.length >= e)) break;
409
+ for (const l of c) {
420
410
  const g = this.parseStackFrame(l);
421
411
  g ? (async () => {
422
- const { originalPos: f } = await this.getOriginalPosition(g.filePath, g.line, g.column);
423
- if (f) {
424
- u().sfDebug && console.log("[RequestInterceptor] First user code line:", f);
425
- const h = { line: f.line?.toString() || k.UNKNOWN, column: f.column?.toString() || k.NOT_CAPTURED, name: f.name || k.NOT_CAPTURED, entrypoint: f.source, retryWithoutTraceId: i };
426
- t.doSend(h);
412
+ const { originalPos: h } = await this.getOriginalPosition(g.filePath, g.line, g.column);
413
+ if (h) {
414
+ u().sfDebug && console.log("[RequestInterceptor] First user code line:", h);
415
+ const m = { line: h.line?.toString() || k.UNKNOWN, column: h.column?.toString() || k.NOT_CAPTURED, name: h.name || k.NOT_CAPTURED, entrypoint: h.source, retryWithoutTraceId: i };
416
+ t.doSend(m);
427
417
  }
428
418
  })() : u().sfDebug && console.error("Could not parse stack line:", l);
429
419
  }
@@ -432,19 +422,19 @@ class qe {
432
422
  t.set(this.HEADER_LOG_GUARD, "true"), t.set(this.HEADER_PRINT_GUARD, "true"), t.set(this.HEADER_EXCEPTION_GUARD, "true");
433
423
  }
434
424
  shouldPropagateHeaders(t) {
435
- return !he.some((e) => new RegExp(`^${e.replace(/\*/g, ".*")}$`).test(t));
425
+ return !ye.some((e) => new RegExp(`^${e.replace(/\*/g, ".*")}$`).test(t));
436
426
  }
437
427
  addTracingHeaders(t, e) {
438
428
  const i = new URL(e).hostname, n = this.shouldPropagateHeaders(i);
439
429
  return n ? this.addTracingHeader(t, e) : u().sfDebug && console.error(`[RequestInterceptor] Excluded domain: ${i}`), n;
440
430
  }
441
431
  addTracingHeader(t, e) {
442
- const i = ae();
432
+ const i = ce();
443
433
  if (i) {
444
- const s = ce(i);
434
+ const s = de(i);
445
435
  if (s && s.sample_rate === 0) return void (u().sfDebug && console.log(`[RequestInterceptor] Function span tracking disabled (sample_rate=0), skipping tracing header for ${e}`));
446
436
  }
447
- const n = this.contextManager.getOrSetSfTraceId(), o = this.contextManager.getOrSetPageVisitUUID(), d = se();
437
+ const n = this.contextManager.getOrSetSfTraceId(), o = this.contextManager.getOrSetPageVisitUUID(), d = oe();
448
438
  t.set(this.HEADER_TRACING, `${n}/${o}/${d}`), u().sfDebug && console.log(`[RequestInterceptor] Added tracing header for ${e}`);
449
439
  }
450
440
  patchFetch(t, e) {
@@ -454,28 +444,28 @@ class qe {
454
444
  if (d.get(this.HEADER_LOG_GUARD) === "true" || d.get(this.HEADER_PRINT_GUARD) === "true" || d.get(this.HEADER_EXCEPTION_GUARD) === "true") return i(n, o);
455
445
  this.captureFirstUserLines(t);
456
446
  const s = Date.now();
457
- let c;
458
- typeof n == "string" || n instanceof URL ? c = n.toString() : n instanceof Request ? (c = n.url, n.headers.forEach((p, m) => {
459
- d.set(m, p);
460
- })) : u().sfDebug && console.error("[Sailfish RequestInterceptor] Invalid fetch input."), u().sfDebug && console.log("[RequestInterceptor] Fetching request to:", c);
461
- const a = new URL(c).hostname, l = new Headers(d), g = this.addTracingHeaders(d, c), f = { ...o, headers: d };
462
- let h;
447
+ let a;
448
+ typeof n == "string" || n instanceof URL ? a = n.toString() : n instanceof Request ? (a = n.url, n.headers.forEach((p, f) => {
449
+ d.set(f, p);
450
+ })) : u().sfDebug && console.error("[Sailfish RequestInterceptor] Invalid fetch input."), u().sfDebug && console.log("[RequestInterceptor] Fetching request to:", a);
451
+ const c = new URL(a).hostname, l = new Headers(d), g = this.addTracingHeaders(d, a), h = { ...o, headers: d };
452
+ let m;
463
453
  try {
464
454
  let p = !1;
465
- this.addTracingHeaders(l, c), h = await i(c, f), g && K.includes(h.status) ? (h = await i(c, { ...o, headers: l }), p = !0, this.captureFirstUserLines(t, 10, p)) : this.contextManager.addSupportedDomains(a);
466
- const m = Date.now();
467
- u().sfDebug && console.log(`[RequestInterceptor] Fetch completed: ${c}, Status: ${h.status}, Duration: ${m - s}ms`);
468
- const { sessionId: I, pageVisitId: v, requestId: D } = this.extractIdsFromTraceHeader(d), $ = u(), b = { apiKey: $.apiKey, requestId: D, pageVisitId: v, recordingSessionId: I, serviceUuid: $.serviceUUID, timestampStart: s.toString(), timestampEnd: m.toString(), responseCode: h.status, success: !0, error: null, url: c, method: f.method || "GET", retryWithoutTraceId: p, parentSpanId: q() };
455
+ this.addTracingHeaders(l, a), m = await i(a, h), g && G.includes(m.status) ? (m = await i(a, { ...o, headers: l }), p = !0, this.captureFirstUserLines(t, 10, p)) : this.contextManager.addSupportedDomains(c);
456
+ const f = Date.now();
457
+ u().sfDebug && console.log(`[RequestInterceptor] Fetch completed: ${a}, Status: ${m.status}, Duration: ${f - s}ms`);
458
+ const { sessionId: I, pageVisitId: v, requestId: D } = this.extractIdsFromTraceHeader(d), $ = u(), b = { apiKey: $.apiKey, requestId: D, pageVisitId: v, recordingSessionId: I, serviceUuid: $.serviceUUID, timestampStart: s.toString(), timestampEnd: f.toString(), responseCode: m.status, success: !0, error: null, url: a, method: h.method || "GET", retryWithoutTraceId: p, parentSpanId: q() };
469
459
  if ($.captureRequestHeaders) {
470
460
  const S = {};
471
- d.forEach((N, w) => {
472
- S[w] = N;
461
+ d.forEach((F, E) => {
462
+ S[E] = F;
473
463
  }), b.requestHeaders = S;
474
464
  }
475
465
  if ($.captureResponseHeaders) {
476
466
  const S = {};
477
- h.headers.forEach((N, w) => {
478
- S[w] = N;
467
+ m.headers.forEach((F, E) => {
468
+ S[E] = F;
479
469
  }), b.responseHeaders = S;
480
470
  }
481
471
  if ($.captureRequestBody && o?.body) try {
@@ -484,68 +474,68 @@ class qe {
484
474
  } catch {
485
475
  }
486
476
  if ($.captureResponseBody) try {
487
- const S = h.clone(), N = await S.text();
488
- b.responseBody = N.length > $.responseBodyLimitBytes ? N.substring(0, $.responseBodyLimitBytes) + "...[truncated]" : N;
477
+ const S = m.clone(), F = await S.text();
478
+ b.responseBody = F.length > $.responseBodyLimitBytes ? F.substring(0, $.responseBodyLimitBytes) + "...[truncated]" : F;
489
479
  } catch {
490
480
  }
491
- return e.doSend(b), h;
481
+ return e.doSend(b), m;
492
482
  } catch (p) {
493
- const m = Date.now();
494
- u().sfDebug && console.error(`[RequestInterceptor] Fetch failed: ${c}, Error: ${p}, Duration: ${m - s}ms`);
483
+ const f = Date.now();
484
+ u().sfDebug && console.error(`[RequestInterceptor] Fetch failed: ${a}, Error: ${p}, Duration: ${f - s}ms`);
495
485
  }
496
486
  } : u().sfDebug && console.error("[RequestInterceptor] Fetch not available.");
497
487
  }
498
488
  patchHttp(t, e) {
499
- if (u().sfDebug && console.log("[RequestInterceptor] Initializing HTTP/HTTPS request patch..."), !P || typeof P.request != "function") return void (u().sfDebug && console.log("[RequestInterceptor] HTTP/HTTPS not available."));
500
- const i = P.request.bind(P), n = P.request.bind(P);
501
- P.request = function(o, d) {
489
+ if (u().sfDebug && console.log("[RequestInterceptor] Initializing HTTP/HTTPS request patch..."), !w || typeof w.request != "function") return void (u().sfDebug && console.log("[RequestInterceptor] HTTP/HTTPS not available."));
490
+ const i = w.request.bind(w), n = w.request.bind(w);
491
+ w.request = function(o, d) {
502
492
  let s;
503
493
  try {
504
494
  if (typeof o == "string") {
505
- const a = new URL(o);
506
- s = { protocol: a.protocol || x, hostname: a.hostname, path: a.pathname + a.search, headers: {} };
507
- } else o instanceof URL ? s = { protocol: o.protocol || x, hostname: o.hostname, path: o.pathname + o.search, headers: {} } : (s = { ...o }, s.protocol || (s.protocol = x));
495
+ const c = new URL(o);
496
+ s = { protocol: c.protocol || M, hostname: c.hostname, path: c.pathname + c.search, headers: {} };
497
+ } else o instanceof URL ? s = { protocol: o.protocol || M, hostname: o.hostname, path: o.pathname + o.search, headers: {} } : (s = { ...o }, s.protocol || (s.protocol = M));
508
498
  if (s.headers) {
509
- const a = `${s.protocol}//${s.hostname}`;
510
- this.addTracingHeaders(s.headers, a), this.captureFirstUserLines(t);
499
+ const c = `${s.protocol}//${s.hostname}`;
500
+ this.addTracingHeaders(s.headers, c), this.captureFirstUserLines(t);
511
501
  } else u().sfDebug && console.warn("[RequestInterceptor] No headers found in HTTP request options. Skipping header addition.");
512
- } catch (a) {
513
- throw u().sfDebug && console.error("[RequestInterceptor] Error while processing HTTP request options:", a), a;
502
+ } catch (c) {
503
+ throw u().sfDebug && console.error("[RequestInterceptor] Error while processing HTTP request options:", c), c;
514
504
  }
515
- let c = !1;
516
- return i(s, (a) => {
505
+ let a = !1;
506
+ return i(s, (c) => {
517
507
  const l = `${s.protocol}//${s.hostname}`;
518
- if (s.headers && this.shouldPropagateHeaders(new URL(l).hostname) && K.includes(a.statusCode || 0)) {
508
+ if (s.headers && this.shouldPropagateHeaders(new URL(l).hostname) && G.includes(c.statusCode || 0)) {
519
509
  s.hostname;
520
510
  const p = { ...s, headers: { ...s.headers } };
521
- delete p.headers[this.HEADER_TRACING], i(p, d), c = !0, this.captureFirstUserLines(t, 10, c);
511
+ delete p.headers[this.HEADER_TRACING], i(p, d), a = !0, this.captureFirstUserLines(t, 10, a);
522
512
  }
523
- const { sessionId: g, pageVisitId: f, requestId: h } = this.extractIdsFromTraceHeader(s.headers);
524
- e.doSend({ apiKey: u().apiKey, requestId: h, pageVisitId: f, recordingSessionId: g, serviceUuid: u().serviceUUID, timestampStart: Date.now().toString(), timestampEnd: Date.now().toString(), responseCode: a.statusCode || 0, success: !!a.statusCode && a.statusCode < 400, error: null, url: l, method: s.method || "GET", retryWithoutTraceId: c, parentSpanId: q() }), d?.(a);
513
+ const { sessionId: g, pageVisitId: h, requestId: m } = this.extractIdsFromTraceHeader(s.headers);
514
+ e.doSend({ apiKey: u().apiKey, requestId: m, pageVisitId: h, recordingSessionId: g, serviceUuid: u().serviceUUID, timestampStart: Date.now().toString(), timestampEnd: Date.now().toString(), responseCode: c.statusCode || 0, success: !!c.statusCode && c.statusCode < 400, error: null, url: l, method: s.method || "GET", retryWithoutTraceId: a, parentSpanId: q() }), d?.(c);
525
515
  });
526
- }, P.request = function(o, d) {
516
+ }, w.request = function(o, d) {
527
517
  let s;
528
518
  try {
529
519
  if (typeof o == "string") {
530
- const a = new URL(o);
531
- s = { protocol: a.protocol || G, hostname: a.hostname, path: a.pathname + a.search, headers: {} };
532
- } else o instanceof URL ? s = { protocol: o.protocol || G, hostname: o.hostname, path: o.pathname + o.search, headers: {} } : (s = { ...o }, s.protocol || (s.protocol = G));
520
+ const c = new URL(o);
521
+ s = { protocol: c.protocol || x, hostname: c.hostname, path: c.pathname + c.search, headers: {} };
522
+ } else o instanceof URL ? s = { protocol: o.protocol || x, hostname: o.hostname, path: o.pathname + o.search, headers: {} } : (s = { ...o }, s.protocol || (s.protocol = x));
533
523
  if (s.headers) {
534
- const a = `${s.protocol}//${s.hostname}`;
535
- this.addTracingHeaders(s.headers, a);
524
+ const c = `${s.protocol}//${s.hostname}`;
525
+ this.addTracingHeaders(s.headers, c);
536
526
  } else u().sfDebug && console.warn("[RequestInterceptor] No headers found in HTTPS request options. Skipping header addition.");
537
- } catch (a) {
538
- throw u().sfDebug && console.error("[RequestInterceptor] Error while processing HTTPS request options:", a), a;
527
+ } catch (c) {
528
+ throw u().sfDebug && console.error("[RequestInterceptor] Error while processing HTTPS request options:", c), c;
539
529
  }
540
- let c = !1;
541
- return n(s, (a) => {
530
+ let a = !1;
531
+ return n(s, (c) => {
542
532
  const l = `${s.protocol}//${s.hostname}`;
543
- if (s.headers && this.shouldPropagateHeaders(new URL(l).hostname) && K.includes(a.statusCode || 0)) {
533
+ if (s.headers && this.shouldPropagateHeaders(new URL(l).hostname) && G.includes(c.statusCode || 0)) {
544
534
  const p = { ...s, headers: { ...s.headers } };
545
- delete p.headers[this.HEADER_TRACING], n(p, d), c = !0, this.captureFirstUserLines(t, 10, c);
535
+ delete p.headers[this.HEADER_TRACING], n(p, d), a = !0, this.captureFirstUserLines(t, 10, a);
546
536
  }
547
- const { sessionId: g, pageVisitId: f, requestId: h } = this.extractIdsFromTraceHeader(s.headers);
548
- e.doSend({ apiKey: u().apiKey, requestId: h, pageVisitId: f, recordingSessionId: g, serviceUuid: u().serviceUUID, timestampStart: Date.now().toString(), timestampEnd: Date.now().toString(), responseCode: a.statusCode || 0, success: !!a.statusCode && a.statusCode < 400, error: null, url: l, method: s.method || "GET", retryWithoutTraceId: c, parentSpanId: q() }), d?.(a);
537
+ const { sessionId: g, pageVisitId: h, requestId: m } = this.extractIdsFromTraceHeader(s.headers);
538
+ e.doSend({ apiKey: u().apiKey, requestId: m, pageVisitId: h, recordingSessionId: g, serviceUuid: u().serviceUUID, timestampStart: Date.now().toString(), timestampEnd: Date.now().toString(), responseCode: c.statusCode || 0, success: !!c.statusCode && c.statusCode < 400, error: null, url: l, method: s.method || "GET", retryWithoutTraceId: a, parentSpanId: q() }), d?.(c);
549
539
  });
550
540
  }, u().sfDebug && console.log("✅ HTTP and HTTPS request methods patched globally.");
551
541
  }
@@ -559,7 +549,7 @@ class qe {
559
549
  return [...this.contextManager.getExcludedDomains()];
560
550
  }
561
551
  }
562
- class He extends V {
552
+ class Ke extends J {
563
553
  constructor() {
564
554
  super(), this.setOperationName("UpdateServiceDetails");
565
555
  }
@@ -604,10 +594,10 @@ class He extends V {
604
594
  )
605
595
  }
606
596
  `, e = u(), i = this.getVariables({ serviceIdentifier: e.serviceIdentifier, serviceVersion: e.serviceVersion, serviceAdditionalMetadata: e.serviceAdditionalMetadata, gitSha: e.gitSha || "", gitOrg: e.gitOrg || void 0, gitRepo: e.gitRepo || void 0, gitProvider: e.gitProvider || void 0, serviceDisplayName: e.serviceDisplayName || void 0, infrastructureType: e.infrastructureType || void 0, infrastructureDetails: e.infrastructureDetails || void 0, setupInterceptorsFile: e.setupInterceptorsFile || void 0, setupInterceptorsLine: e.setupInterceptorsLine || void 0 });
607
- E(this.endpoint, this.operationName, t, i);
597
+ P(this.endpoint, this.operationName, t, i);
608
598
  }
609
599
  }
610
- class Me {
600
+ class We {
611
601
  constructor(t = [process.cwd()], e = !1) {
612
602
  y(this, "rootPaths");
613
603
  y(this, "fileConfigs", /* @__PURE__ */ new Map());
@@ -621,17 +611,17 @@ class Me {
621
611
  async loadAllConfigs() {
622
612
  this.debug && console.log("[FuncSpan ConfigLoader] Scanning for .sailfish files in:", this.rootPaths);
623
613
  const t = [];
624
- for (const e of this.rootPaths) M.existsSync(e) ? await this._walkDirectory(e, t) : this.debug && console.log(`[FuncSpan ConfigLoader] Root path does not exist: ${e}`);
614
+ for (const e of this.rootPaths) Te.existsSync(e) ? await this._walkDirectory(e, t) : this.debug && console.log(`[FuncSpan ConfigLoader] Root path does not exist: ${e}`);
625
615
  t.length > 0 ? (this.hasSailfishFiles = !0, this.debug && (console.log(`[FuncSpan ConfigLoader] Found ${t.length} .sailfish files:`), t.forEach((e) => console.log(`[FuncSpan ConfigLoader] - ${e}`)))) : this.debug && console.log("[FuncSpan ConfigLoader] No .sailfish files found - function spans disabled by default");
626
616
  for (const e of t) await this._loadConfigFile(e);
627
617
  await this._resolveInheritance(), this.debug && console.log(`[FuncSpan ConfigLoader] Loaded ${this.fileConfigs.size} file configs, ${this.functionConfigs.size} function configs`);
628
618
  }
629
619
  getConfig(t, e) {
630
- const i = this.hasSailfishFiles ? Se() : de(), n = this._getDirectoryConfig(t), o = F.normalize(t), d = this.fileConfigs.get(o) || {};
620
+ const i = this.hasSailfishFiles ? $e() : ue(), n = this._getDirectoryConfig(t), o = N.normalize(t), d = this.fileConfigs.get(o) || {};
631
621
  let s = {};
632
622
  if (e) {
633
- const c = this.functionConfigs.get(o);
634
- c && (s = c.get(e) || {});
623
+ const a = this.functionConfigs.get(o);
624
+ a && (s = a.get(e) || {});
635
625
  }
636
626
  return U(i, n, d, s);
637
627
  }
@@ -640,9 +630,9 @@ class Me {
640
630
  }
641
631
  async _walkDirectory(t, e) {
642
632
  try {
643
- const i = M.readdirSync(t, { withFileTypes: !0 });
633
+ const i = await X.readdir(t, { withFileTypes: !0 });
644
634
  for (const n of i) {
645
- const o = F.join(t, n.name);
635
+ const o = N.join(t, n.name);
646
636
  n.isFile() && n.name === ".sailfish" ? e.push(o) : n.name === "node_modules" || n.isDirectory() && n.name.startsWith(".") && n.name !== ".sailfish" || n.isDirectory() && await this._walkDirectory(o, e);
647
637
  }
648
638
  } catch (i) {
@@ -651,7 +641,7 @@ class Me {
651
641
  }
652
642
  async _loadConfigFile(t) {
653
643
  try {
654
- const e = M.readFileSync(t, "utf-8"), i = F.dirname(t);
644
+ const e = await X.readFile(t, "utf-8"), i = N.dirname(t);
655
645
  let n = null;
656
646
  try {
657
647
  n = JSON.parse(e);
@@ -674,11 +664,11 @@ class Me {
674
664
  }
675
665
  async _expandFileGlobs(t, e, i) {
676
666
  for (const [n, o] of Object.entries(e)) try {
677
- const d = F.join(t, n), s = await we(d, { absolute: !0, nodir: !0, ignore: ["**/node_modules/**", "**/.git/**"] });
667
+ const d = N.join(t, n), s = await Le(d, { absolute: !0, nodir: !0, ignore: ["**/node_modules/**", "**/.git/**"] });
678
668
  this.debug && console.log(`[FuncSpan ConfigLoader] Pattern '${n}' matched ${s.length} files`);
679
- for (const c of s) {
680
- const a = F.normalize(c), l = U(i, o);
681
- this.fileConfigs.set(a, l), this.debug && s.length <= 5 && console.log(`[FuncSpan ConfigLoader] - ${c}`);
669
+ for (const a of s) {
670
+ const c = N.normalize(a), l = U(i, o);
671
+ this.fileConfigs.set(c, l), this.debug && s.length <= 5 && console.log(`[FuncSpan ConfigLoader] - ${a}`);
682
672
  }
683
673
  } catch (d) {
684
674
  this.debug && console.error(`[FuncSpan ConfigLoader] Error expanding glob '${n}':`, d);
@@ -691,52 +681,52 @@ class Me {
691
681
  this.debug && console.warn(`[FuncSpan ConfigLoader] Invalid function pattern '${n}' (expected format: 'file.ts::functionName')`);
692
682
  continue;
693
683
  }
694
- const [s, c] = d, a = F.normalize(F.join(t, s));
695
- this.functionConfigs.has(a) || this.functionConfigs.set(a, /* @__PURE__ */ new Map());
696
- const l = this.functionConfigs.get(a), g = U(i, o);
697
- l.set(c, g), this.debug && console.log(`[FuncSpan ConfigLoader] Function config: ${a}::${c}`);
684
+ const [s, a] = d, c = N.normalize(N.join(t, s));
685
+ this.functionConfigs.has(c) || this.functionConfigs.set(c, /* @__PURE__ */ new Map());
686
+ const l = this.functionConfigs.get(c), g = U(i, o);
687
+ l.set(a, g), this.debug && console.log(`[FuncSpan ConfigLoader] Function config: ${c}::${a}`);
698
688
  }
699
689
  }
700
690
  async _resolveInheritance() {
701
691
  }
702
692
  _getDirectoryConfig(t) {
703
- let e = F.dirname(F.normalize(t));
693
+ let e = N.dirname(N.normalize(t));
704
694
  const i = [];
705
- for (; e && e !== F.dirname(e); ) {
695
+ for (; e && e !== N.dirname(e); ) {
706
696
  const n = this.directoryConfigs.get(e);
707
- n && i.unshift(n), e = F.dirname(e);
697
+ n && i.unshift(n), e = N.dirname(e);
708
698
  }
709
699
  return i.reduce((n, o) => U(n, o), {});
710
700
  }
711
701
  }
712
- const le = "__sf_globalConfigLoader";
713
- function pe() {
714
- return globalThis[le] ?? null;
702
+ const ge = "__sf_globalConfigLoader";
703
+ function fe() {
704
+ return globalThis[ge] ?? null;
715
705
  }
716
- async function xe(r, t) {
717
- const e = new Me(r, t);
706
+ async function Be(r, t) {
707
+ const e = new We(r, t);
718
708
  (function(i) {
719
- globalThis[le] = i;
709
+ globalThis[ge] = i;
720
710
  })(e), await e.loadAllConfigs();
721
711
  }
722
- function Ge(r, t) {
723
- const e = pe();
724
- return e ? e.getConfig(r, t) : (process.env.SF_DEBUG === "true" && console.log("[FuncSpan ConfigLoader] Config loader not initialized, using default config (disabled)"), de());
712
+ function ze(r, t) {
713
+ const e = fe();
714
+ return e ? e.getConfig(r, t) : (process.env.SF_DEBUG === "true" && console.log("[FuncSpan ConfigLoader] Config loader not initialized, using default config (disabled)"), ue());
725
715
  }
726
- function Ke() {
727
- return pe() !== null;
716
+ function je() {
717
+ return fe() !== null;
728
718
  }
729
- const We = ["readFile", "writeFile", "appendFile", "readdir", "stat", "lstat", "fstat", "access", "open", "close", "read", "write", "chmod", "mkdir", "rmdir", "unlink", "rename"], Z = ["lookup", "resolve", "resolve4", "resolve6", "resolveAny", "resolveMx", "resolveNs", "resolveTxt", "reverse"], Be = ["pbkdf2", "randomBytes", "scrypt", "generateKeyPair"], ze = ["gzip", "gunzip", "deflate", "inflate", "deflateRaw", "inflateRaw", "brotliCompress", "brotliDecompress"];
730
- let ee = !1;
731
- function Je(r) {
719
+ const Je = ["readFile", "writeFile", "appendFile", "readdir", "stat", "lstat", "fstat", "access", "open", "close", "read", "write", "chmod", "mkdir", "rmdir", "unlink", "rename"], ee = ["lookup", "resolve", "resolve4", "resolve6", "resolveAny", "resolveMx", "resolveNs", "resolveTxt", "reverse"], Ve = ["pbkdf2", "randomBytes", "scrypt", "generateKeyPair"], Qe = ["gzip", "gunzip", "deflate", "inflate", "deflateRaw", "inflateRaw", "brotliCompress", "brotliDecompress"];
720
+ let te = !1;
721
+ function Xe(r) {
732
722
  if (typeof r != "string") return !1;
733
723
  const t = process.env.SF_FUNCSPAN_JSONL_FILE;
734
724
  if (t && r.includes(t)) return !0;
735
725
  const e = process.env.SF_WORKER_POOL_JSONL_FILE;
736
726
  return !(!e || !r.includes(e));
737
727
  }
738
- let te = !1;
739
- function ne(r) {
728
+ let ne = !1;
729
+ function re(r) {
740
730
  if (typeof r != "string") return !1;
741
731
  if (r === "localhost" || r === "127.0.0.1" || r === "::1") return !0;
742
732
  try {
@@ -747,8 +737,8 @@ function ne(r) {
747
737
  }
748
738
  return !1;
749
739
  }
750
- function je() {
751
- if (!te) try {
740
+ function Ye() {
741
+ if (!ne) try {
752
742
  let r;
753
743
  if (typeof require > "u") return void (process.env.SF_DEBUG === "true" && console.log("[WorkerPool] Skipping dns patching in pure ESM environment (require unavailable)"));
754
744
  try {
@@ -758,230 +748,231 @@ function je() {
758
748
  }
759
749
  if (r.__sf_worker_pool_patched__) return;
760
750
  Object.defineProperty(r, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
761
- for (const t of Z) if (typeof r[t] == "function") {
751
+ for (const t of ee) if (typeof r[t] == "function") {
762
752
  const e = r[t];
763
753
  r[t] = function(...i) {
764
- return ne(i[0]) ? e.apply(this, i) : typeof i[i.length - 1] == "function" ? A("dns", t, e, i, this) : e.apply(this, i);
754
+ return Q() ? e.apply(this, i) : re(i[0]) ? e.apply(this, i) : typeof i[i.length - 1] == "function" ? A("dns", t, e, i, this) : e.apply(this, i);
765
755
  }, Object.defineProperty(r[t], "name", { value: t, writable: !1 });
766
756
  }
767
757
  (function(t) {
768
758
  if (!t.promises) return void (process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns.promises not available, skipping"));
769
759
  if (!t.promises.__sf_worker_pool_patched__) {
770
760
  Object.defineProperty(t.promises, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
771
- for (const e of Z) if (typeof t.promises[e] == "function") {
761
+ for (const e of ee) if (typeof t.promises[e] == "function") {
772
762
  const i = t.promises[e];
773
763
  t.promises[e] = function(...n) {
774
- return ne(n[0]) ? i.apply(this, n) : Ie("dns", e, i, n, this);
764
+ return Q() ? i.apply(this, n) : re(n[0]) ? i.apply(this, n) : _e("dns", e, i, n, this);
775
765
  }, Object.defineProperty(t.promises[e], "name", { value: e, writable: !1 });
776
766
  }
777
767
  process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns.promises module patched successfully");
778
768
  }
779
- })(r), te = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns module patched successfully");
769
+ })(r), ne = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns module patched successfully");
780
770
  } catch (r) {
781
771
  console.error("[WorkerPool] Error patching dns module:", r);
782
772
  }
783
773
  }
784
- let re = !1, ie = !1, z = !1;
785
- function Ve() {
786
- if (z) return;
774
+ let ie = !1, se = !1, B = !1;
775
+ function Ze() {
776
+ if (B) return;
787
777
  const r = process.env.SF_DEBUG === "true";
788
778
  r && console.log("[WorkerPool] Initializing worker pool patching..."), R("fs") && (r && console.log("[WorkerPool] Patching fs module..."), (function() {
789
- if (!ee) try {
779
+ if (!te) try {
790
780
  const t = require("node:fs");
791
781
  if (t.__sf_worker_pool_patched__) return;
792
782
  Object.defineProperty(t, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
793
- for (const e of We) if (typeof t[e] == "function") {
783
+ for (const e of Je) if (typeof t[e] == "function") {
794
784
  const i = t[e];
795
785
  t[e] = function(...n) {
796
- return Je(n[0]) ? i.apply(this, n) : typeof n[n.length - 1] == "function" ? A("fs", e, i, n, this) : i.apply(this, n);
786
+ return Xe(n[0]) ? i.apply(this, n) : typeof n[n.length - 1] == "function" ? A("fs", e, i, n, this) : i.apply(this, n);
797
787
  }, Object.defineProperty(t[e], "name", { value: e, writable: !1 });
798
788
  }
799
- ee = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] fs module patched successfully");
789
+ te = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] fs module patched successfully");
800
790
  } catch (t) {
801
791
  console.error("[WorkerPool] Error patching fs module:", t);
802
792
  }
803
- })()), R("dns") && (r && console.log("[WorkerPool] Patching dns module..."), je()), R("crypto") && (r && console.log("[WorkerPool] Patching crypto module..."), (function() {
804
- if (!re) try {
793
+ })()), R("dns") && (r && console.log("[WorkerPool] Patching dns module..."), Ye()), R("crypto") && (r && console.log("[WorkerPool] Patching crypto module..."), (function() {
794
+ if (!ie) try {
805
795
  const t = require("node:crypto");
806
796
  if (t.__sf_worker_pool_patched__) return;
807
797
  Object.defineProperty(t, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
808
- for (const e of Be) if (typeof t[e] == "function") {
798
+ for (const e of Ve) if (typeof t[e] == "function") {
809
799
  const i = t[e];
810
800
  t[e] = function(...n) {
811
801
  return typeof n[n.length - 1] == "function" ? A("crypto", e, i, n, this) : i.apply(this, n);
812
802
  }, Object.defineProperty(t[e], "name", { value: e, writable: !1 });
813
803
  }
814
- re = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] crypto module patched successfully");
804
+ ie = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] crypto module patched successfully");
815
805
  } catch (t) {
816
806
  console.error("[WorkerPool] Error patching crypto module:", t);
817
807
  }
818
808
  })()), R("zlib") && (r && console.log("[WorkerPool] Patching zlib module..."), (function() {
819
- if (!ie) try {
809
+ if (!se) try {
820
810
  const t = require("node:zlib");
821
811
  if (t.__sf_worker_pool_patched__) return;
822
812
  Object.defineProperty(t, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
823
- for (const e of ze) if (typeof t[e] == "function") {
813
+ for (const e of Qe) if (typeof t[e] == "function") {
824
814
  const i = t[e];
825
815
  t[e] = function(...n) {
826
816
  return typeof n[n.length - 1] == "function" ? A("zlib", e, i, n, this) : i.apply(this, n);
827
817
  }, Object.defineProperty(t[e], "name", { value: e, writable: !1 });
828
818
  }
829
- ie = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] zlib module patched successfully");
819
+ se = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] zlib module patched successfully");
830
820
  } catch (t) {
831
821
  console.error("[WorkerPool] Error patching zlib module:", t);
832
822
  }
833
- })()), z = !0, r && console.log("[WorkerPool] Worker pool patching initialized");
823
+ })()), B = !0, r && console.log("[WorkerPool] Worker pool patching initialized");
834
824
  }
835
- function Qe() {
836
- return z;
825
+ function et() {
826
+ return B;
837
827
  }
838
- let J = !1, W = !1;
839
- function ot(r) {
840
- if (W) console.warn("[setupInterceptors] ⚠️ Recursive call detected and blocked!");
841
- else if (!J) {
842
- W = !0;
828
+ let z = !1, K = !1;
829
+ function ut(r) {
830
+ if (K) console.warn("[setupInterceptors] ⚠️ Recursive call detected and blocked!");
831
+ else if (!z) {
832
+ K = !0;
843
833
  try {
844
834
  let t, e;
845
- const i = new Error().stack;
835
+ const i = le(new Error().stack);
846
836
  if (i) {
847
837
  const s = i.split(`
848
- `)[2] || "", c = s.match(/\((.+):(\d+):\d+\)/) || s.match(/at (.+):(\d+):\d+/);
849
- c && (t = c[1], e = parseInt(c[2], 10));
838
+ `)[2] || "", a = s.match(/\((.+):(\d+):\d+\)/) || s.match(/at (.+):(\d+):\d+/);
839
+ a && (t = a[1], e = parseInt(a[2], 10));
850
840
  }
851
841
  if (!r || !r.apiKey) {
852
842
  const s = `The required API Key is not provided: ${JSON.stringify(r)}`;
853
843
  console.error(s);
854
844
  }
855
- const { config: n } = me(r);
856
- if (t && (n.setupInterceptorsFile = t), e && (n.setupInterceptorsLine = e), n.sfDebug && console.log("Updated configuration after applying options:", n), !n.apiKey || !n.apiGraphqlEndpoint) {
845
+ const { config: n } = Se(r);
846
+ if (Ie(n).catch(() => {
847
+ }), t && (n.setupInterceptorsFile = t), e && (n.setupInterceptorsLine = e), n.sfDebug && console.log("Updated configuration after applying options:", n), !n.apiKey || !n.apiGraphqlEndpoint) {
857
848
  const s = `The required config is not provided: ${JSON.stringify(n)}`;
858
849
  throw console.error(s), new Error(s);
859
850
  }
860
- Ke() || xe(void 0, n.sfDebug).catch((s) => {
851
+ je() || Be(void 0, n.sfDebug).catch((s) => {
861
852
  n.sfDebug && console.error("[FuncSpan] Failed to initialize config loader:", s);
862
- }), process.env.SF_WORKER_POOL_DISABLED === "true" ? n.sfDebug && console.log("[setupInterceptors] Worker pool patching DISABLED (SF_WORKER_POOL_DISABLED=true)") : Qe() || (Ve(), n.sfDebug && console.log("[setupInterceptors] Worker pool patching initialized (DNS tracking enabled)"));
863
- const o = new V();
864
- o.setServiceUUID(n.serviceUUID), be(o), (function(s = []) {
865
- const c = new qe(s);
866
- new Le().doSend(c.getExcludedDomains());
867
- const a = new Ae(), l = new ke();
868
- c.patchFetch(a, l), c.patchHttp(a, l);
853
+ }), process.env.SF_WORKER_POOL_DISABLED === "true" ? n.sfDebug && console.log("[setupInterceptors] Worker pool patching DISABLED (SF_WORKER_POOL_DISABLED=true)") : et() || (Ze(), n.sfDebug && console.log("[setupInterceptors] Worker pool patching initialized (DNS tracking enabled)"));
854
+ const o = new J();
855
+ o.setServiceUUID(n.serviceUUID), we(o), (function(s = []) {
856
+ const a = new Ge(s);
857
+ new He().doSend(a.getExcludedDomains());
858
+ const c = new Me(), l = new xe();
859
+ a.patchFetch(c, l), a.patchHttp(c, l);
869
860
  })(n.domainsToNotPropagateHeadersTo);
870
- const d = new Ue();
871
- d.setServiceUUID(n.serviceUUID), Ne(d), Oe(), new He().send(), J = !0, n.sfDebug && console.log("[setupInterceptors] ✅ Initialization complete");
861
+ const d = new Ae();
862
+ d.setServiceUUID(n.serviceUUID), Pe(d), qe(), new Ke().send(), z = !0, n.sfDebug && console.log("[setupInterceptors] ✅ Initialization complete");
872
863
  } finally {
873
- W = !1;
864
+ K = !1;
874
865
  }
875
866
  }
876
867
  }
877
- function at() {
878
- return J;
868
+ function lt() {
869
+ return z;
879
870
  }
880
- function ct(r, t, e, i = !1) {
871
+ function pt(r, t, e, i = !1) {
881
872
  const n = u();
882
- new ue(n.apiKey).identify(r, t, e, i);
873
+ new pe(n.apiKey).identify(r, t, e, i);
883
874
  }
884
- function dt(r, t = {}, e, i = !1) {
875
+ function gt(r, t = {}, e, i = !1) {
885
876
  const n = u();
886
- new ue(n.apiKey).addOrUpdateMetadata(r, t, e, i);
877
+ new pe(n.apiKey).addOrUpdateMetadata(r, t, e, i);
887
878
  }
888
- let B = null;
889
- function ut(r, t, e, i) {
879
+ let W = null;
880
+ function ft(r, t, e, i) {
890
881
  const n = function(...o) {
891
- const d = oe(), s = d?.sfDebug || !1;
882
+ const d = ae(), s = d?.sfDebug || !1;
892
883
  s && console.log(`[FuncSpan] captureFunctionSpan wrapper called for ${e}::${t}`);
893
- const c = (function(m, I) {
894
- const v = ae();
884
+ const a = (function(f, I) {
885
+ const v = ce();
895
886
  if (v) {
896
- const D = ce(v);
897
- if (D) return process.env.SF_DEBUG === "true" && console.log(`[FuncSpan] Using HTTP header override for ${m}::${I}`), D;
887
+ const D = de(v);
888
+ if (D) return process.env.SF_DEBUG === "true" && console.log(`[FuncSpan] Using HTTP header override for ${f}::${I}`), D;
898
889
  }
899
890
  try {
900
- return Ge(m, I);
891
+ return ze(f, I);
901
892
  } catch {
902
893
  return { sample_rate: process.env.SF_FUNCSPAN_SAMPLE_RATE ? parseFloat(process.env.SF_FUNCSPAN_SAMPLE_RATE) : 1, capture_arguments: !0, capture_return_value: !0, arg_limit_mb: 1, return_limit_mb: 1, enable_sampling: !1, autocapture_all_child_functions: !1, capture_sf_veritas: !1, parse_json_strings: !1 };
903
894
  }
904
895
  })(e, t);
905
- if (s && console.log(`[FuncSpan] Config for ${e}::${t}:`, c), c.enable_sampling && c.sample_rate < 1 && Math.random() > c.sample_rate) return s && console.log(`[FuncSpan] Skipping ${t} due to sampling`), r.apply(this, o);
906
- if (c.sample_rate === 0) return s && console.log(`[FuncSpan] Skipping ${t} - sample_rate is 0.0`), r.apply(this, o);
896
+ if (s && console.log(`[FuncSpan] Config for ${e}::${t}:`, a), a.enable_sampling && a.sample_rate < 1 && Math.random() > a.sample_rate) return s && console.log(`[FuncSpan] Skipping ${t} due to sampling`), r.apply(this, o);
897
+ if (a.sample_rate === 0) return s && console.log(`[FuncSpan] Skipping ${t} - sample_rate is 0.0`), r.apply(this, o);
907
898
  s && console.log(`[FuncSpan] Capturing function span for ${t}`);
908
- const a = j.getInstance(), l = a.getCurrentFunctionSpanId(), g = se();
909
- a.setCurrentFunctionSpanId(g);
910
- const f = process.hrtime.bigint(), h = Date.now();
899
+ const c = j.getInstance(), l = c.getCurrentFunctionSpanId(), g = oe();
900
+ c.setCurrentFunctionSpanId(g);
901
+ const h = process.hrtime.bigint(), m = Date.now();
911
902
  let p = null;
912
- c.capture_arguments && (p = {}, i.paramNames.forEach((m, I) => {
913
- I < o.length && (p[m] = o[I]);
914
- }), p && c.arg_limit_mb > 0 && (p = H(p, c.arg_limit_mb)));
903
+ a.capture_arguments && (p = {}, i.paramNames.forEach((f, I) => {
904
+ I < o.length && (p[f] = o[I]);
905
+ }), p && a.arg_limit_mb > 0 && (p = H(p, a.arg_limit_mb)));
915
906
  try {
916
- const m = r.apply(this, o);
917
- if (m && typeof m.then == "function") return l ? a.setCurrentFunctionSpanId(l) : a.clearCurrentFunctionSpanId(), m.then((b) => {
918
- const S = process.hrtime.bigint(), N = Date.now(), w = Number(S - f);
919
- let Q = null;
920
- return c.capture_return_value && c.return_limit_mb > 0 && (Q = H(b, c.return_limit_mb)), L({ functionName: t, filePath: e, metadata: i, args: p, result: Q, error: null, duration: N - h, durationNs: w, startTimeNs: f.toString(), async: !0, spanId: g, parentSpanId: l, pid: process.pid, threadId: O }), b;
907
+ const f = r.apply(this, o);
908
+ if (f && typeof f.then == "function") return l ? c.setCurrentFunctionSpanId(l) : c.clearCurrentFunctionSpanId(), f.then((b) => {
909
+ const S = process.hrtime.bigint(), F = Date.now(), E = Number(S - h);
910
+ let V = null;
911
+ return a.capture_return_value && a.return_limit_mb > 0 && (V = H(b, a.return_limit_mb)), O({ functionName: t, filePath: e, metadata: i, args: p, result: V, error: null, duration: F - m, durationNs: E, startTimeNs: h.toString(), async: !0, spanId: g, parentSpanId: l, pid: process.pid, threadId: L }), b;
921
912
  }, (b) => {
922
- const S = process.hrtime.bigint(), N = Date.now(), w = Number(S - f);
923
- throw L({ functionName: t, filePath: e, metadata: i, args: p, result: null, error: b?.message || String(b), duration: N - h, durationNs: w, startTimeNs: f.toString(), async: !0, spanId: g, parentSpanId: l, pid: process.pid, threadId: O }), b;
913
+ const S = process.hrtime.bigint(), F = Date.now(), E = Number(S - h);
914
+ throw O({ functionName: t, filePath: e, metadata: i, args: p, result: null, error: b?.message || String(b), duration: F - m, durationNs: E, startTimeNs: h.toString(), async: !0, spanId: g, parentSpanId: l, pid: process.pid, threadId: L }), b;
924
915
  });
925
- const I = process.hrtime.bigint(), v = Date.now(), D = Number(I - f);
916
+ const I = process.hrtime.bigint(), v = Date.now(), D = Number(I - h);
926
917
  let $ = null;
927
- return c.capture_return_value && c.return_limit_mb > 0 && ($ = H(m, c.return_limit_mb)), L({ functionName: t, filePath: e, metadata: i, args: p, result: $, error: null, duration: v - h, durationNs: D, startTimeNs: f.toString(), async: !1, spanId: g, parentSpanId: l, pid: process.pid, threadId: O }), l ? a.setCurrentFunctionSpanId(l) : a.clearCurrentFunctionSpanId(), m;
928
- } catch (m) {
929
- const I = process.hrtime.bigint(), v = Date.now(), D = Number(I - f);
930
- throw L({ functionName: t, filePath: e, metadata: i, args: p, result: null, error: m?.message || String(m), duration: v - h, durationNs: D, startTimeNs: f.toString(), async: !1, spanId: g, parentSpanId: l, pid: process.pid, threadId: O }), l ? a.setCurrentFunctionSpanId(l) : a.clearCurrentFunctionSpanId(), m;
918
+ return a.capture_return_value && a.return_limit_mb > 0 && ($ = H(f, a.return_limit_mb)), O({ functionName: t, filePath: e, metadata: i, args: p, result: $, error: null, duration: v - m, durationNs: D, startTimeNs: h.toString(), async: !1, spanId: g, parentSpanId: l, pid: process.pid, threadId: L }), l ? c.setCurrentFunctionSpanId(l) : c.clearCurrentFunctionSpanId(), f;
919
+ } catch (f) {
920
+ const I = process.hrtime.bigint(), v = Date.now(), D = Number(I - h);
921
+ throw O({ functionName: t, filePath: e, metadata: i, args: p, result: null, error: f?.message || String(f), duration: v - m, durationNs: D, startTimeNs: h.toString(), async: !1, spanId: g, parentSpanId: l, pid: process.pid, threadId: L }), l ? c.setCurrentFunctionSpanId(l) : c.clearCurrentFunctionSpanId(), f;
931
922
  }
932
923
  };
933
924
  Object.defineProperty(n, "name", { value: t, writable: !1 });
934
925
  for (const o in r) r.hasOwnProperty(o) && (n[o] = r[o]);
935
926
  return n;
936
927
  }
937
- function L(r) {
938
- const t = oe(), e = t?.sfDebug || !1;
928
+ function O(r) {
929
+ const t = ae(), e = t?.sfDebug || !1;
939
930
  e && console.log("[FuncSpan] captureSpanData called for:", { function: r.functionName, file: r.filePath, duration: `${r.duration}ms`, async: r.async, error: r.error, spanId: r.spanId });
940
931
  const i = { functionName: r.functionName, filePath: r.filePath, metadata: r.metadata, args: r.args, result: r.result, error: r.error, duration: r.duration, durationNs: r.durationNs, async: r.async, spanId: r.spanId, parentSpanId: r.parentSpanId };
941
932
  process.env.SF_FUNCSPAN_CONSOLE_OUTPUT === "true" && console.log(`
942
933
  📊 Function Span:`, { function: `${r.functionName} (${r.filePath}:${r.metadata.line}:${r.metadata.column})`, duration: `${r.duration.toFixed(2)}ms`, arguments: r.args, result: r.error ? `Error: ${r.error}` : r.result, spanId: r.spanId, parentSpanId: r.parentSpanId || "none" });
943
934
  const n = process.env.SF_FUNCSPAN_JSONL_FILE;
944
935
  if (n) try {
945
- const o = n === "true" || n === "1" ? "funcspans.jsonl" : n, d = Date.now(), s = process.hrtime.bigint(), c = BigInt(r.startTimeNs), a = Number(s - c) / 1e6, l = new Date(d - a).toISOString(), g = JSON.stringify({ timestamp: l, functionName: r.functionName, filePath: r.filePath, line: r.metadata.line, column: r.metadata.column, duration: r.duration, durationNs: r.durationNs, startTimeNs: r.startTimeNs, arguments: r.args, returnValue: r.error ? { error: String(r.error) } : r.result, spanId: r.spanId, parentSpanId: r.parentSpanId, async: r.async, pid: r.pid, threadId: r.threadId }) + `
936
+ const o = n === "true" || n === "1" ? "funcspans.jsonl" : n, d = Date.now(), s = process.hrtime.bigint(), a = BigInt(r.startTimeNs), c = Number(s - a) / 1e6, l = new Date(d - c).toISOString(), g = JSON.stringify({ timestamp: l, functionName: r.functionName, filePath: r.filePath, line: r.metadata.line, column: r.metadata.column, duration: r.duration, durationNs: r.durationNs, startTimeNs: r.startTimeNs, arguments: r.args, returnValue: r.error ? { error: String(r.error) } : r.result, spanId: r.spanId, parentSpanId: r.parentSpanId, async: r.async, pid: r.pid, threadId: r.threadId }) + `
946
937
  `;
947
- Pe(o, g, "utf-8");
938
+ Ue(o, g, "utf-8");
948
939
  } catch (o) {
949
940
  console.error("[FuncSpan] Error writing to JSONL file:", o);
950
941
  }
951
942
  if (e && console.log("[FuncSpan] Sending function span to transmitter:", i), process.env.SF_FUNCSPAN_SKIP_BACKEND !== "true") try {
952
- (B || (B = new ve()), B).send([i]), e && console.log("[FuncSpan] Function span sent successfully");
943
+ (W || (W = new be()), W).send([i]), e && console.log("[FuncSpan] Function span sent successfully");
953
944
  } catch (o) {
954
945
  e && console.error("[FuncSpan] Error sending function span:", o);
955
946
  }
956
947
  }
957
- function lt(r) {
948
+ function ht(r) {
958
949
  return !!r.includes("captureFunctionSpan(") || !!r.includes("@sailfish-ai/sf-veritas") || !(!r.includes("/* @sailfish-instrumented */") && !r.includes("// @sailfish-instrumented"));
959
950
  }
960
951
  export {
961
952
  j as ContextManager,
962
- dt as addOrUpdateMetadata,
963
- ut as captureFunctionSpan,
964
- mt as clearFuncspanOverride,
953
+ gt as addOrUpdateMetadata,
954
+ ft as captureFunctionSpan,
955
+ vt as clearFuncspanOverride,
965
956
  q as getCurrentFunctionSpanId,
966
- de as getDefaultConfig,
967
- Se as getEnvConfig,
968
- ae as getFuncspanOverride,
969
- Ge as getGlobalConfig,
970
- ct as identify,
971
- xe as initializeConfigLoader,
972
- Ve as initializeWorkerPoolPatching,
973
- lt as isAlreadyInstrumented,
974
- Ke as isConfigLoaderInitialized,
975
- It as isProductionEnvironment,
976
- vt as isRuntimeModeEnabled,
977
- at as isSetupInterceptorsInitialized,
978
- Qe as isWorkerPoolInitialized,
979
- ce as parseHeaderOverride,
980
- ft as runWithContext,
981
- yt as setFuncspanOverride,
982
- bt as setSkipTypeScriptPlugin,
983
- ot as setupInterceptors,
984
- $t as shouldEnableRuntimeHooks,
985
- Nt as transformFunctionSpans,
986
- Ft as transformFunctionSpansSync
957
+ ue as getDefaultConfig,
958
+ $e as getEnvConfig,
959
+ ce as getFuncspanOverride,
960
+ ze as getGlobalConfig,
961
+ pt as identify,
962
+ Be as initializeConfigLoader,
963
+ Ze as initializeWorkerPoolPatching,
964
+ ht as isAlreadyInstrumented,
965
+ je as isConfigLoaderInitialized,
966
+ bt as isProductionEnvironment,
967
+ Ft as isRuntimeModeEnabled,
968
+ lt as isSetupInterceptorsInitialized,
969
+ et as isWorkerPoolInitialized,
970
+ de as parseHeaderOverride,
971
+ St as runWithContext,
972
+ $t as setFuncspanOverride,
973
+ wt as setSkipTypeScriptPlugin,
974
+ ut as setupInterceptors,
975
+ Nt as shouldEnableRuntimeHooks,
976
+ Pt as transformFunctionSpans,
977
+ Et as transformFunctionSpansSync
987
978
  };