@sailfish-ai/sf-veritas 0.3.1 → 0.3.2

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.
@@ -1,32 +1,32 @@
1
- var ve = Object.defineProperty;
2
- var $e = (r, t, e) => t in r ? ve(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
- var b = (r, t, e) => $e(r, typeof t != "symbol" ? t + "" : t, e);
4
- import { g as a, C as ee, D as be, v as J, b as T, c as _e, d as Fe, a as fe } from "./contextManager-D2ijKL-E.js";
5
- import { r as Nt } from "./contextManager-D2ijKL-E.js";
6
- import { B as k, n as C, f as De, g as Q, p as X, a as ge, b as Ne, m as L, c as x, i as ne, d as we, e as q, r as Ee, t as K, F as Pe } from "./workerPoolSpanCapture-hyxgVqUF.js";
7
- import { h as Et, s as Pt } from "./workerPoolSpanCapture-hyxgVqUF.js";
8
- import { a as Re, C as Ce, i as w, b as Te, c as he, d as Ue, e as ke } from "./runtimeConfig-C4mv7SVM.js";
9
- import { f as Ct, g as Tt, s as Ut } from "./runtimeConfig-C4mv7SVM.js";
10
- import { createRequire as Oe } from "node:module";
11
- import * as Le from "fs";
12
- import { readFileSync as qe, appendFileSync as Ae } from "fs";
1
+ var Fe = Object.defineProperty;
2
+ var we = (r, t, e) => t in r ? Fe(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
+ var b = (r, t, e) => we(r, typeof t != "symbol" ? t + "" : t, e);
4
+ import { g as c, C as ne, D as De, v as X, b as C, c as Ne, d as Ee, a as ye } from "./contextManager-CZy0w11U.js";
5
+ import { r as Rt } from "./contextManager-CZy0w11U.js";
6
+ import { B as k, n as T, f as Pe, g as Y, p as Z, a as Se, b as Re, m as L, c as x, i as ie, d as Te, e as q, r as Ce, t as K, F as Ue } from "./workerPoolSpanCapture-BomWTMM2.js";
7
+ import { h as Ct, s as Ut } from "./workerPoolSpanCapture-BomWTMM2.js";
8
+ import { a as ke, C as Oe, i as N, b as Le, c as Ie, d as qe, e as Ae } from "./runtimeConfig-ButdW4zP.js";
9
+ import { f as Ot, g as Lt, s as qt } from "./runtimeConfig-ButdW4zP.js";
10
+ import { createRequire as He } from "node:module";
11
+ import * as Me from "fs";
12
+ import { readFileSync as xe, appendFileSync as Be } from "fs";
13
13
  import U from "http";
14
14
  import A from "https";
15
- import { s as He } from "./source-map-Cr6YkjTd.js";
16
- import * as re from "fs/promises";
15
+ import { s as Ge } from "./source-map-Cr6YkjTd.js";
16
+ import * as se from "fs/promises";
17
17
  import * as P from "path";
18
- import { glob as Me } from "glob";
18
+ import { glob as Ke } from "glob";
19
19
  import { threadId as H } from "worker_threads";
20
- import { s as Ot, t as Lt, a as qt } from "./funcSpanTransformer-S_WeAt_m.js";
20
+ import { s as Ht, t as Mt, a as xt } from "./funcSpanTransformer-S_WeAt_m.js";
21
21
  class O extends k {
22
22
  constructor() {
23
23
  super(), this.setOperationName("IdentifyServiceDetails");
24
24
  }
25
25
  async doSend(t) {
26
- if (!a().serviceIdentificationReceived) try {
26
+ if (!c().serviceIdentificationReceived) try {
27
27
  this.send();
28
28
  } catch (e) {
29
- a().sfDebug && console.error(" Error during service identification:", e);
29
+ c().sfDebug && console.error(" Error during service identification:", e);
30
30
  }
31
31
  }
32
32
  async send() {
@@ -68,11 +68,11 @@ class O extends k {
68
68
  serviceRole: $serviceRole,
69
69
  )
70
70
  }
71
- `, e = a(), i = this.getVariables({ serviceIdentifier: e.serviceIdentifier, serviceVersion: e.serviceVersion, library: e.packageLibraryType, version: e.version, 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, framework: e.framework || void 0, additionalFrameworks: e.additionalFrameworks.length > 0 ? e.additionalFrameworks : void 0, serviceRole: e.serviceRole || void 0 });
72
- C(this.endpoint, this.operationName, t, i);
71
+ `, e = c(), i = this.getVariables({ serviceIdentifier: e.serviceIdentifier, serviceVersion: e.serviceVersion, library: e.packageLibraryType, version: e.version, 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, framework: e.framework || void 0, additionalFrameworks: e.additionalFrameworks.length > 0 ? e.additionalFrameworks : void 0, serviceRole: e.serviceRole || void 0 });
72
+ T(this.endpoint, this.operationName, t, i);
73
73
  }
74
74
  }
75
- class xe extends k {
75
+ class We extends k {
76
76
  constructor() {
77
77
  super();
78
78
  b(this, "serviceIdentifier", new O());
@@ -83,22 +83,22 @@ class xe extends k {
83
83
  if (this.identifyStarted) return;
84
84
  this.identifyStarted = !0, this.serviceIdentifier.doSend({});
85
85
  const e = setInterval(() => {
86
- a().serviceIdentificationReceived ? clearInterval(e) : this.serviceIdentifier.doSend({});
86
+ c().serviceIdentificationReceived ? clearInterval(e) : this.serviceIdentifier.doSend({});
87
87
  }, 5e3);
88
88
  e && typeof e == "object" && "unref" in e && e.unref();
89
89
  }
90
- async doSend(e, i, n, s) {
91
- this.startBackgroundIdentify(), this.send(e, i, n, s);
90
+ async doSend(e, i, n, o) {
91
+ this.startBackgroundIdentify(), this.send(e, i, n, o);
92
92
  }
93
- async send(e, i, n, s) {
94
- if (!i && !s) throw new Error('Must pass in either traits or traits_json to "add_or_update_traits"');
93
+ async send(e, i, n, o) {
94
+ if (!i && !o) throw new Error('Must pass in either traits or traits_json to "add_or_update_traits"');
95
95
  let l = [];
96
- if (!s) {
97
- const o = Re(i);
98
- s = o.traitsJson, l = o.excludedFields;
96
+ if (!o) {
97
+ const s = ke(i);
98
+ o = s.traitsJson, l = s.excludedFields;
99
99
  }
100
- const c = this.getVariables({ userId: e, traitsJson: s, excludedFields: l, override: n, library: a().packageLibraryType, version: a().version });
101
- C(this.endpoint, this.operationName, this.getQuery(), c);
100
+ const u = this.getVariables({ userId: e, traitsJson: o, excludedFields: l, override: n, library: c().packageLibraryType, version: c().version });
101
+ T(this.endpoint, this.operationName, this.getQuery(), u);
102
102
  }
103
103
  getQuery() {
104
104
  return `
@@ -108,20 +108,20 @@ class xe extends k {
108
108
  `;
109
109
  }
110
110
  }
111
- class me {
111
+ class ve {
112
112
  constructor(t) {
113
113
  b(this, "metadataTransmitter");
114
- this.apiKey = t, this.metadataTransmitter = new xe();
114
+ this.apiKey = t, this.metadataTransmitter = new We();
115
115
  }
116
116
  identify(t, e, i, n = !1) {
117
117
  e || i ? this.addOrUpdateMetadata(t, e, i, n) : this.addOrUpdateMetadata(t, {}, void 0, n);
118
118
  }
119
119
  addOrUpdateMetadata(t, e = {}, i, n = !1) {
120
120
  if (!e && !i) throw new Error('Must pass in either traits or traitsJson to "addOrUpdateMetadata"');
121
- a().sfDebug && console.log(" [[DEBUG - addOrUpdateMetadata]] Starting operation"), a().sfDebug && console.log(" addOrUpdateMetadata...SENDING DATA...", t, e, i), this.metadataTransmitter.doSend(t, e, n, i);
121
+ c().sfDebug && console.log(" [[DEBUG - addOrUpdateMetadata]] Starting operation"), c().sfDebug && console.log(" addOrUpdateMetadata...SENDING DATA...", t, e, i), this.metadataTransmitter.doSend(t, e, n, i);
122
122
  }
123
123
  }
124
- class te extends k {
124
+ class re extends k {
125
125
  constructor() {
126
126
  super();
127
127
  b(this, "serviceIdentifier", new O());
@@ -131,7 +131,7 @@ class te extends k {
131
131
  if (this.identifyStarted) return;
132
132
  this.identifyStarted = !0, this.serviceIdentifier.doSend({});
133
133
  const e = setInterval(() => {
134
- a().serviceIdentificationReceived ? clearInterval(e) : this.serviceIdentifier.doSend({});
134
+ c().serviceIdentificationReceived ? clearInterval(e) : this.serviceIdentifier.doSend({});
135
135
  }, 5e3);
136
136
  e && typeof e == "object" && "unref" in e && e.unref();
137
137
  }
@@ -141,9 +141,9 @@ class te extends k {
141
141
  async send(e) {
142
142
  try {
143
143
  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 });
144
- C(this.endpoint, this.operationName, this.getQuery(), n);
144
+ T(this.endpoint, this.operationName, this.getQuery(), n);
145
145
  } catch (i) {
146
- a().sfDebug && console.error("🚨 Error in send():", i);
146
+ c().sfDebug && console.error("🚨 Error in send():", i);
147
147
  }
148
148
  }
149
149
  getQuery() {
@@ -174,7 +174,7 @@ class te extends k {
174
174
  `;
175
175
  }
176
176
  }
177
- class Be extends k {
177
+ class je extends k {
178
178
  constructor() {
179
179
  super();
180
180
  b(this, "serviceIdentifier", new O());
@@ -193,7 +193,7 @@ class Be extends k {
193
193
  if (this.identifyStarted) return;
194
194
  this.identifyStarted = !0, this.serviceIdentifier.doSend({});
195
195
  const e = setInterval(() => {
196
- a().serviceIdentificationReceived ? clearInterval(e) : this.serviceIdentifier.doSend({});
196
+ c().serviceIdentificationReceived ? clearInterval(e) : this.serviceIdentifier.doSend({});
197
197
  }, 5e3);
198
198
  e && typeof e == "object" && "unref" in e && e.unref();
199
199
  }
@@ -201,9 +201,9 @@ class Be extends k {
201
201
  this.startBackgroundIdentify(), this.send(e, i);
202
202
  }
203
203
  async send(e, i) {
204
- a().sfDebug && console.log(" SENDING EXCEPTION...");
205
- const n = JSON.stringify(Ce.encode(i)), s = this.normalizedSupplementalForGraphQL(), l = this.getVariables({ exceptionMessage: e, traceJson: n, reentrancyGuardPreactive: !1, library: a().packageLibraryType, version: a().version, ...s });
206
- C(this.endpoint, this.operationName, this.getQuery(), l);
204
+ c().sfDebug && console.log(" SENDING EXCEPTION...");
205
+ const n = JSON.stringify(Oe.encode(i)), o = this.normalizedSupplementalForGraphQL(), l = this.getVariables({ exceptionMessage: e, traceJson: n, reentrancyGuardPreactive: !1, library: c().packageLibraryType, version: c().version, ...o });
206
+ T(this.endpoint, this.operationName, this.getQuery(), l);
207
207
  }
208
208
  getQuery() {
209
209
  return `
@@ -237,51 +237,82 @@ class Be extends k {
237
237
  `;
238
238
  }
239
239
  }
240
- const ie = "getting request source code";
240
+ const oe = "X-Sf4-Prid", ae = "getting request source code";
241
241
  var B = ((r) => (r.UNKNOWN = "unknown", r.ANONYMOUS = "anonymous", r.NOT_CAPTURED = "not captured", r))(B || {});
242
- const se = "http:", Ge = Oe(import.meta.url);
243
- let oe = !1;
244
- function Ke() {
245
- const r = a().sfDebug;
246
- if (oe) return void (r && w("[patchNodeHttpInbound] Already installed, skipping."));
242
+ const ce = "http:", Ve = He(import.meta.url);
243
+ let de = !1;
244
+ function ze() {
245
+ const r = c().sfDebug;
246
+ if (de) return void (r && N("[patchNodeHttpInbound] Already installed, skipping."));
247
247
  let t;
248
- oe = !0;
248
+ de = !0;
249
249
  try {
250
- t = Ge("node:http"), r && w("[patchNodeHttpInbound] node:http required successfully.");
250
+ t = Ve("node:http"), r && N("[patchNodeHttpInbound] node:http required successfully.");
251
251
  } catch (n) {
252
- return void Te("Failed to require node:http:", n);
252
+ return void Le("Failed to require node:http:", n);
253
253
  }
254
- if (!t?.Server?.prototype) return void (r && w("[patchNodeHttpInbound] http.Server.prototype not found."));
254
+ if (!t?.Server?.prototype) return void (r && N("[patchNodeHttpInbound] http.Server.prototype not found."));
255
255
  const e = t.Server.prototype, i = e.emit;
256
- i && !e.__sf_inbound_patched__ ? (Object.defineProperty(e, "__sf_inbound_patched__", { value: !0, enumerable: !1, configurable: !1, writable: !1 }), r && w("[patchNodeHttpInbound] Patching http.Server.prototype.emit."), e.emit = function(n, ...s) {
257
- if (n !== "request") return r && w(`[patchNodeHttpInbound] Passing through event: ${n}`), i.call(this, n, ...s);
258
- const l = s[0], c = s[1], o = (function(S) {
259
- const h = {};
260
- if (!S) return h;
261
- for (const [f, I] of Object.entries(S)) I != null && (Array.isArray(I) ? h[f.toLowerCase()] = I.join(", ") : h[f.toLowerCase()] = String(I));
262
- return h;
263
- })(l?.headers), d = o["x-sf3-rid"], p = o["x-sf3-functionspancaptureoverride"];
264
- r && (w("[patchNodeHttpInbound] Intercepted request event."), w("[patchNodeHttpInbound] Inbound headers:", o), w("[patchNodeHttpInbound] Trace header:", d), w("[patchNodeHttpInbound] FuncSpan override header:", p));
265
- const u = ee.getInstance();
266
- u.setTraceId(d);
267
- const y = u.getTraceId();
268
- r && w("[patchNodeHttpInbound] Context traceId set:", y);
269
- const $ = () => u.runWith({ inboundHeaders: o, ...d ? { traceId: d } : {} }, () => {
270
- d && u.setTraceId(d), r && w("[patchNodeHttpInbound] Running request handler in context.");
256
+ i && !e.__sf_inbound_patched__ ? (Object.defineProperty(e, "__sf_inbound_patched__", { value: !0, enumerable: !1, configurable: !1, writable: !1 }), r && N("[patchNodeHttpInbound] Patching http.Server.prototype.emit."), e.emit = function(n, ...o) {
257
+ if (n !== "request") return r && N(`[patchNodeHttpInbound] Passing through event: ${n}`), i.call(this, n, ...o);
258
+ const l = o[0], u = o[1], s = (function(S) {
259
+ const g = {};
260
+ if (!S) return g;
261
+ for (const [f, v] of Object.entries(S)) v != null && (Array.isArray(v) ? g[f.toLowerCase()] = v.join(", ") : g[f.toLowerCase()] = String(v));
262
+ return g;
263
+ })(l?.headers), d = s["x-sf3-rid"], p = s["x-sf3-functionspancaptureoverride"];
264
+ r && (N("[patchNodeHttpInbound] Intercepted request event."), N("[patchNodeHttpInbound] Inbound headers:", s), N("[patchNodeHttpInbound] Trace header:", d), N("[patchNodeHttpInbound] FuncSpan override header:", p));
265
+ const a = ne.getInstance();
266
+ a.setTraceId(d);
267
+ const m = a.getTraceId();
268
+ r && N("[patchNodeHttpInbound] Context traceId set:", m);
269
+ const I = () => a.runWith({ inboundHeaders: s, ...d ? { traceId: d } : {} }, () => {
270
+ d && a.setTraceId(d), r && N("[patchNodeHttpInbound] Running request handler in context.");
271
271
  const S = () => {
272
- r && w("[patchNodeHttpInbound] Response finished/closed for traceId:", u.getTraceId());
272
+ r && N("[patchNodeHttpInbound] Response finished/closed for traceId:", a.getTraceId());
273
273
  };
274
- return c.on("finish", S), c.on("close", S), i.call(this, n, l, c);
274
+ return u.on("finish", S), u.on("close", S), i.call(this, n, l, u);
275
275
  });
276
- if (!p) return $();
276
+ if (!p) return I();
277
277
  try {
278
- return De.run(p, () => $());
278
+ return Pe.run(p, () => I());
279
279
  } catch {
280
- return $();
280
+ return I();
281
+ }
282
+ }) : r && N("[patchNodeHttpInbound] Already patched, skipping.");
283
+ }
284
+ const ue = /* @__PURE__ */ new Map();
285
+ function W(r, t) {
286
+ const e = `${r}|${t}`;
287
+ let i = ue.get(e);
288
+ return i || (i = new RegExp(r, t), ue.set(e, i)), i;
289
+ }
290
+ function j(r, t) {
291
+ let e, i;
292
+ if (typeof r == "string" ? e = r : typeof URL < "u" && r instanceof URL ? e = r.href : typeof Request < "u" && r instanceof Request ? e = r.url : r != null && typeof r.toString == "function" && (e = r.toString()), !e) return !1;
293
+ try {
294
+ i = new URL(e, "http://localhost/");
295
+ } catch {
296
+ return !1;
297
+ }
298
+ const { hostname: n, pathname: o, port: l, protocol: u } = i;
299
+ if (!/^https?:$/.test(u)) return !1;
300
+ const s = n.startsWith("www.") ? n.slice(4).toLowerCase() : n.toLowerCase();
301
+ return t.some((d) => {
302
+ const p = String(d || "").replace(/^[a-zA-Z]+:\/\//, "");
303
+ if (!p) return !1;
304
+ let [a, m] = p.split("/", 2), I = "";
305
+ a.includes(":") && ([a, I] = a.split(":"));
306
+ const S = W(`^${a.replace(/\./g, "\\.").replace(/\*/g, ".*")}$`, "i"), g = s.startsWith("www.") ? s.slice(4) : s;
307
+ if (I && l !== I) return !1;
308
+ if (a.startsWith("*.")) {
309
+ const f = a.slice(2).toLowerCase();
310
+ return s === f || g === f || s.endsWith("." + f) ? m ? W(`^/${m.replace(/\*/g, ".*").replace(/\/$/, "")}`, "i").test(o) : !0 : !1;
281
311
  }
282
- }) : r && w("[patchNodeHttpInbound] Already patched, skipping.");
312
+ return !S.test(g) && !S.test(s) ? !1 : m ? W(`^/${m.replace(/\*/g, ".*").replace(/\/$/, "")}`, "i").test(o) : !0;
313
+ });
283
314
  }
284
- class We extends te {
315
+ class Je extends re {
285
316
  constructor() {
286
317
  super(), this.setOperationName("DomainsToNotPassHeaderTo");
287
318
  }
@@ -302,10 +333,10 @@ class We extends te {
302
333
  )
303
334
  }
304
335
  `, i = { apiKey: this.apiKey, serviceUuid: this.serviceUUID, domains: t };
305
- C(this.endpoint, this.operationName, e, i);
336
+ T(this.endpoint, this.operationName, e, i);
306
337
  }
307
338
  }
308
- class je extends k {
339
+ class Qe extends k {
309
340
  constructor() {
310
341
  super();
311
342
  b(this, "serviceIdentifier", new O());
@@ -316,7 +347,7 @@ class je extends k {
316
347
  if (this.identifyStarted) return;
317
348
  this.identifyStarted = !0, this.serviceIdentifier.doSend({});
318
349
  const e = setInterval(() => {
319
- a().serviceIdentificationReceived ? clearInterval(e) : this.serviceIdentifier.doSend({});
350
+ c().serviceIdentificationReceived ? clearInterval(e) : this.serviceIdentifier.doSend({});
320
351
  }, 5e3);
321
352
  e && typeof e == "object" && "unref" in e && e.unref();
322
353
  }
@@ -324,8 +355,8 @@ class je extends k {
324
355
  this.startBackgroundIdentify(), this.send(e);
325
356
  }
326
357
  async send(e) {
327
- const { name: i, column: n, line: s, entrypoint: l, retryWithoutTraceId: c } = e, o = this.getVariables({ name: i, column: n, line: s, entrypoint: l, retryWithoutTraceId: c });
328
- C(this.endpoint, this.operationName, this.getQuery(), o);
358
+ const { name: i, column: n, line: o, entrypoint: l, retryWithoutTraceId: u } = e, s = this.getVariables({ name: i, column: n, line: o, entrypoint: l, retryWithoutTraceId: u });
359
+ T(this.endpoint, this.operationName, this.getQuery(), s);
329
360
  }
330
361
  getQuery() {
331
362
  return `
@@ -355,7 +386,7 @@ class je extends k {
355
386
  `;
356
387
  }
357
388
  }
358
- class Ve extends k {
389
+ class Xe extends k {
359
390
  constructor() {
360
391
  super();
361
392
  b(this, "serviceIdentifier", new O());
@@ -366,7 +397,7 @@ class Ve extends k {
366
397
  if (this.identifyStarted) return;
367
398
  this.identifyStarted = !0, this.serviceIdentifier.doSend({});
368
399
  const e = setInterval(() => {
369
- a().serviceIdentificationReceived ? clearInterval(e) : this.serviceIdentifier.doSend({});
400
+ c().serviceIdentificationReceived ? clearInterval(e) : this.serviceIdentifier.doSend({});
370
401
  }, 5e3);
371
402
  e && typeof e == "object" && "unref" in e && e.unref();
372
403
  }
@@ -385,31 +416,31 @@ class Ve extends k {
385
416
  }
386
417
  async send(e) {
387
418
  const i = { data: { ...e } };
388
- await C(this.endpoint, this.operationName, this.getQuery(), i);
419
+ await T(this.endpoint, this.operationName, this.getQuery(), i);
389
420
  }
390
421
  }
391
- const W = [400, 403];
392
- function j(r, t) {
422
+ const V = [400, 403];
423
+ function z(r, t) {
393
424
  return t !== "none" && (t === "all" || r === "GET" || r === "HEAD" || r === "OPTIONS");
394
425
  }
395
- class ze {
426
+ class Ye {
396
427
  constructor(t = []) {
397
428
  b(this, "HEADER_TRACING", "X-Sf3-Rid");
398
429
  b(this, "HEADER_LOG_GUARD", "reentrancy_guard_logging_preactive");
399
430
  b(this, "HEADER_PRINT_GUARD", "reentrancy_guard_print_preactive");
400
431
  b(this, "HEADER_EXCEPTION_GUARD", "reentrancy_guard_exception_preactive");
401
432
  b(this, "contextManager");
402
- this.contextManager = ee.getInstance(), t?.forEach((e) => {
433
+ this.contextManager = ne.getInstance(), t?.forEach((e) => {
403
434
  typeof e == "string" && e.trim() && this.contextManager.getExcludedDomains().add(e);
404
- }), a().sfDebug && console.log("[RequestInterceptor] Initialized with static excluded domains.");
435
+ }), c().sfDebug && console.log("[RequestInterceptor] Initialized with static excluded domains.");
405
436
  }
406
437
  extractIdsFromTraceHeader(t, e = this.HEADER_TRACING) {
407
438
  let i;
408
439
  if (t instanceof Headers) i = t.get(e) ?? void 0;
409
440
  else {
410
- const s = e.toLowerCase();
411
- for (const [l, c] of Object.entries(t)) if (l.toLowerCase() === s) {
412
- i = c;
441
+ const o = e.toLowerCase();
442
+ for (const [l, u] of Object.entries(t)) if (l.toLowerCase() === o) {
443
+ i = u;
413
444
  break;
414
445
  }
415
446
  }
@@ -420,292 +451,313 @@ class ze {
420
451
  parseStackFrame(t) {
421
452
  const e = /\((.*):(\d+):(\d+)\)$/.exec(t.trim());
422
453
  if (!e) return null;
423
- const [, i, n, s] = e;
424
- return { filePath: i, line: parseInt(n, 10), column: parseInt(s, 10) };
454
+ const [, i, n, o] = e;
455
+ return { filePath: i, line: parseInt(n, 10), column: parseInt(o, 10) };
425
456
  }
426
457
  async getOriginalPosition(t, e, i) {
427
458
  let n = { source: t, line: e, column: i, name: null };
428
459
  if (t.includes("://")) return { originalPos: n };
429
- const s = t + ".map";
460
+ const o = t + ".map";
430
461
  try {
431
- const l = JSON.parse(qe(s, "utf-8"));
432
- let c = (await new He.SourceMapConsumer(l)).originalPositionFor({ line: e, column: i });
433
- c.source && (n = c);
462
+ const l = JSON.parse(xe(o, "utf-8"));
463
+ let u = (await new Ge.SourceMapConsumer(l)).originalPositionFor({ line: e, column: i });
464
+ u.source && (n = u);
434
465
  } catch (l) {
435
- a().sfDebug && console.error(`Could not read/parse map file at ${s}:`, l);
466
+ c().sfDebug && console.error(`Could not read/parse map file at ${o}:`, l);
436
467
  }
437
468
  return { originalPos: n };
438
469
  }
439
470
  captureFirstUserLines(t, e = 10, i = !1) {
440
- const n = a().sfDebug ? 10 : e, s = Error.stackTraceLimit;
441
- Error.stackTraceLimit = Math.max(s, n);
442
- const l = new Error(ie);
443
- ie in Error && Error.captureStackTrace(l, this.captureFirstUserLines);
444
- const c = he(l.stack);
445
- Error.stackTraceLimit = s;
446
- const o = c.split(`
471
+ const n = c().sfDebug ? 10 : e, o = Error.stackTraceLimit;
472
+ Error.stackTraceLimit = Math.max(o, n);
473
+ const l = new Error(ae);
474
+ ae in Error && Error.captureStackTrace(l, this.captureFirstUserLines);
475
+ const u = Ie(l.stack);
476
+ Error.stackTraceLimit = o;
477
+ const s = u.split(`
447
478
  `).slice(1), d = [];
448
- for (const p of o)
479
+ for (const p of s)
449
480
  if (!(p.includes("node:internal") || p.includes("internal/modules") || p.includes("internal/process") || p.includes("node_modules") || p.includes(".next/server/chunks") || p.includes("RequestInterceptor") || p.includes("contextManager") || p.includes("setupConfig")) && (d.push(p.trim()), d.length >= e)) break;
450
481
  for (const p of d) {
451
- const u = this.parseStackFrame(p);
452
- u ? (async () => {
453
- const { originalPos: y } = await this.getOriginalPosition(u.filePath, u.line, u.column);
454
- if (y) {
455
- a().sfDebug && console.log("[RequestInterceptor] First user code line:", y);
456
- const $ = { line: y.line?.toString() || B.UNKNOWN, column: y.column?.toString() || B.NOT_CAPTURED, name: y.name || B.NOT_CAPTURED, entrypoint: y.source, retryWithoutTraceId: i };
457
- t.doSend($);
482
+ const a = this.parseStackFrame(p);
483
+ a ? (async () => {
484
+ const { originalPos: m } = await this.getOriginalPosition(a.filePath, a.line, a.column);
485
+ if (m) {
486
+ c().sfDebug && console.log("[RequestInterceptor] First user code line:", m);
487
+ const I = { line: m.line?.toString() || B.UNKNOWN, column: m.column?.toString() || B.NOT_CAPTURED, name: m.name || B.NOT_CAPTURED, entrypoint: m.source, retryWithoutTraceId: i };
488
+ t.doSend(I);
458
489
  }
459
- })() : a().sfDebug && console.error("Could not parse stack line:", p);
490
+ })() : c().sfDebug && console.error("Could not parse stack line:", p);
460
491
  }
461
492
  }
462
493
  addReentrancyGuardHeaders(t) {
463
494
  t.set(this.HEADER_LOG_GUARD, "true"), t.set(this.HEADER_PRINT_GUARD, "true"), t.set(this.HEADER_EXCEPTION_GUARD, "true");
464
495
  }
465
496
  shouldPropagateHeaders(t) {
466
- return !be.some((e) => new RegExp(`^${e.replace(/\*/g, ".*")}$`).test(t));
497
+ const e = c(), i = e.domainsToPropagateHeadersTo, n = e.domainsToNotPropagateHeadersTo || [], o = Array.from(De);
498
+ return !!j(t, i) && !(n.length > 0 && j(t, n)) && !j(t, o);
467
499
  }
468
500
  addTracingHeaders(t, e) {
469
- const i = new URL(e).hostname, n = this.shouldPropagateHeaders(i);
470
- return n ? this.addTracingHeader(t, e) : a().sfDebug && console.error(`[RequestInterceptor] Excluded domain: ${i}`), n;
501
+ const i = this.shouldPropagateHeaders(e);
502
+ if (i) this.addTracingHeader(t, e);
503
+ else if (c().sfDebug) {
504
+ let n = e;
505
+ try {
506
+ n = new URL(e).hostname;
507
+ } catch {
508
+ }
509
+ console.error(`[RequestInterceptor] Excluded domain: ${n}`);
510
+ }
511
+ return i;
512
+ }
513
+ deriveTraceBaseAndParent(t) {
514
+ const e = t.split("/").filter(Boolean);
515
+ return e.length < 2 ? { base: t, parent: t } : { base: `${e[0]}/${e[1]}`, parent: t };
471
516
  }
472
517
  addTracingHeader(t, e) {
473
- const i = Q();
518
+ const i = Y();
474
519
  if (i) {
475
- const c = X(i);
476
- if (c && c.sample_rate === 0) return void (a().sfDebug && console.log(`[RequestInterceptor] Function span tracking disabled (sample_rate=0), skipping tracing header for ${e}`));
520
+ const s = Z(i);
521
+ if (s && s.sample_rate === 0) return void (c().sfDebug && console.log(`[RequestInterceptor] Function span tracking disabled (sample_rate=0), skipping tracing header for ${e}`));
477
522
  }
478
- const n = this.contextManager.getOrSetSfTraceId(), s = this.contextManager.getOrSetPageVisitUUID(), l = J();
479
- t.set(this.HEADER_TRACING, `${n}/${s}/${l}`), a().sfDebug && console.log(`[RequestInterceptor] Added tracing header for ${e}`);
523
+ const n = this.contextManager.getOrSetSfTraceId(), { base: o, parent: l } = this.deriveTraceBaseAndParent(n), u = X();
524
+ t.set(this.HEADER_TRACING, `${o}/${u}`), t.set(oe, l), c().sfDebug && console.log(`[RequestInterceptor] Added tracing header for ${e}`);
480
525
  }
481
526
  patchFetch(t, e) {
482
527
  const i = globalThis.fetch;
483
- typeof i == "function" ? globalThis.fetch = async (n, s) => {
484
- const l = new Headers(s?.headers);
485
- if (l.get(this.HEADER_LOG_GUARD) === "true" || l.get(this.HEADER_PRINT_GUARD) === "true" || l.get(this.HEADER_EXCEPTION_GUARD) === "true") return i(n, s);
528
+ typeof i == "function" ? globalThis.fetch = async (n, o) => {
529
+ const l = new Headers(o?.headers);
530
+ if (l.get(this.HEADER_LOG_GUARD) === "true" || l.get(this.HEADER_PRINT_GUARD) === "true" || l.get(this.HEADER_EXCEPTION_GUARD) === "true") return i(n, o);
486
531
  this.captureFirstUserLines(t);
487
- const c = Date.now();
488
- let o, d = "GET";
489
- if (typeof n == "string" || n instanceof URL) o = n.toString(), d = (s?.method || "GET").toUpperCase();
532
+ const u = Date.now();
533
+ let s, d = "GET";
534
+ if (typeof n == "string" || n instanceof URL) s = n.toString(), d = (o?.method || "GET").toUpperCase();
490
535
  else {
491
- if (!(n instanceof Request)) return a().sfDebug && console.error("[Sailfish RequestInterceptor] Invalid fetch input."), i(n, s);
492
- o = n.url, d = n.method.toUpperCase(), n.headers.forEach((g, D) => {
493
- l.set(D, g);
536
+ if (!(n instanceof Request)) return c().sfDebug && console.error("[Sailfish RequestInterceptor] Invalid fetch input."), i(n, o);
537
+ s = n.url, d = n.method.toUpperCase(), n.headers.forEach((h, w) => {
538
+ l.set(w, h);
494
539
  });
495
540
  }
496
- a().sfDebug && console.log("[RequestInterceptor] Fetching request to:", o);
541
+ c().sfDebug && console.log("[RequestInterceptor] Fetching request to:", s);
497
542
  let p = "unknown";
498
543
  try {
499
- p = new URL(o).hostname;
544
+ p = new URL(s).hostname;
500
545
  } catch {
501
- return a().sfDebug && console.warn(`[RequestInterceptor] Could not parse URL '${o}' — passing through without tracing headers.`), i(n, s);
546
+ return c().sfDebug && console.warn(`[RequestInterceptor] Could not parse URL '${s}' — passing through without tracing headers.`), i(n, o);
502
547
  }
503
- const u = new Headers(l), y = this.addTracingHeaders(l, o), $ = (g) => n instanceof Request ? [new Request(n, { ...s || {}, headers: g }), void 0] : [o, { ...s, headers: g }], S = a().retryOnClientError;
504
- let h, f = !1;
548
+ const a = new Headers(l), m = this.addTracingHeaders(l, s), I = (h) => n instanceof Request ? [new Request(n, { ...o || {}, headers: h }), void 0] : [s, { ...o, headers: h }], S = c().retryOnClientError;
549
+ let g, f = !1;
505
550
  try {
506
- const [g, D] = $(l);
507
- if (h = await i(g, D), y && j(d, S) && W.includes(h.status)) {
508
- const [v, _] = $(u);
509
- h = await i(v, _), f = !0;
551
+ const [h, w] = I(l);
552
+ if (g = await i(h, w), m && z(d, S) && V.includes(g.status)) {
553
+ const [$, _] = I(a);
554
+ g = await i($, _), f = !0;
510
555
  try {
511
556
  this.captureFirstUserLines(t, 10, f);
512
557
  } catch (F) {
513
- a().sfDebug && console.error("[RequestInterceptor] captureFirstUserLines (retry) failed:", F);
558
+ c().sfDebug && console.error("[RequestInterceptor] captureFirstUserLines (retry) failed:", F);
514
559
  }
515
560
  } else try {
516
561
  this.contextManager.addSupportedDomains(p);
517
- } catch (v) {
518
- a().sfDebug && console.error("[RequestInterceptor] addSupportedDomains failed:", v);
562
+ } catch ($) {
563
+ c().sfDebug && console.error("[RequestInterceptor] addSupportedDomains failed:", $);
519
564
  }
520
- } catch (g) {
521
- const D = Date.now();
522
- a().sfDebug && console.error(`[RequestInterceptor] Fetch failed: ${o}, Error: ${g}, Duration: ${D - c}ms`);
565
+ } catch (h) {
566
+ const w = Date.now();
567
+ c().sfDebug && console.error(`[RequestInterceptor] Fetch failed: ${s}, Error: ${h}, Duration: ${w - u}ms`);
523
568
  try {
524
- const { sessionId: v, pageVisitId: _, requestId: F } = this.extractIdsFromTraceHeader(l), R = a();
525
- e.doSend({ apiKey: R.apiKey, requestId: F, pageVisitId: _, recordingSessionId: v, serviceUuid: R.serviceUUID, timestampStart: c.toString(), timestampEnd: D.toString(), responseCode: 0, success: !1, error: g instanceof Error ? g.message : typeof g == "string" ? g : JSON.stringify(g), url: o, method: d, retryWithoutTraceId: f, parentSpanId: T() });
526
- } catch (v) {
527
- a().sfDebug && console.error("[RequestInterceptor] Error telemetry send failed:", v);
569
+ const { sessionId: $, pageVisitId: _, requestId: F } = this.extractIdsFromTraceHeader(l), R = c();
570
+ e.doSend({ apiKey: R.apiKey, requestId: F, pageVisitId: _, recordingSessionId: $, serviceUuid: R.serviceUUID, timestampStart: u.toString(), timestampEnd: w.toString(), responseCode: 0, success: !1, error: h instanceof Error ? h.message : typeof h == "string" ? h : JSON.stringify(h), url: s, method: d, retryWithoutTraceId: f, parentSpanId: C() });
571
+ } catch ($) {
572
+ c().sfDebug && console.error("[RequestInterceptor] Error telemetry send failed:", $);
528
573
  }
529
- throw g;
574
+ throw h;
530
575
  }
531
- const I = Date.now();
576
+ const v = Date.now();
532
577
  try {
533
- a().sfDebug && console.log(`[RequestInterceptor] Fetch completed: ${o}, Status: ${h.status}, Duration: ${I - c}ms`);
534
- const { sessionId: g, pageVisitId: D, requestId: v } = this.extractIdsFromTraceHeader(l), _ = a(), F = { apiKey: _.apiKey, requestId: v, pageVisitId: D, recordingSessionId: g, serviceUuid: _.serviceUUID, timestampStart: c.toString(), timestampEnd: I.toString(), responseCode: h.status, success: !0, error: null, url: o, method: d, retryWithoutTraceId: f, parentSpanId: T() };
578
+ c().sfDebug && console.log(`[RequestInterceptor] Fetch completed: ${s}, Status: ${g.status}, Duration: ${v - u}ms`);
579
+ const { sessionId: h, pageVisitId: w, requestId: $ } = this.extractIdsFromTraceHeader(l), _ = c(), F = { apiKey: _.apiKey, requestId: $, pageVisitId: w, recordingSessionId: h, serviceUuid: _.serviceUUID, timestampStart: u.toString(), timestampEnd: v.toString(), responseCode: g.status, success: !0, error: null, url: s, method: d, retryWithoutTraceId: f, parentSpanId: C() };
535
580
  if (_.captureRequestHeaders) {
536
- const m = {};
537
- l.forEach((E, N) => {
538
- m[N] = E;
539
- }), F.requestHeaders = m;
581
+ const y = {};
582
+ l.forEach((E, D) => {
583
+ y[D] = E;
584
+ }), F.requestHeaders = y;
540
585
  }
541
586
  if (_.captureResponseHeaders) {
542
- const m = {};
543
- h.headers.forEach((E, N) => {
544
- m[N] = E;
545
- }), F.responseHeaders = m;
587
+ const y = {};
588
+ g.headers.forEach((E, D) => {
589
+ y[D] = E;
590
+ }), F.responseHeaders = y;
546
591
  }
547
- if (_.captureRequestBody && s?.body) {
548
- const m = s.body, E = _.requestBodyLimitBytes;
592
+ if (_.captureRequestBody && o?.body) {
593
+ const y = o.body, E = _.requestBodyLimitBytes;
549
594
  try {
550
- if (typeof m == "string") F.requestBody = m.length > E ? m.substring(0, E) + "...[truncated]" : m;
551
- else if (m instanceof URLSearchParams) {
552
- const N = m.toString();
553
- F.requestBody = N.length > E ? N.substring(0, E) + "...[truncated]" : N;
554
- } else if (typeof ArrayBuffer < "u" && (m instanceof ArrayBuffer || ArrayBuffer.isView(m))) {
555
- const N = m.byteLength ?? m.byteLength;
556
- F.requestBody = `[binary body, ${N} bytes — not captured]`;
557
- } else if (typeof Blob < "u" && m instanceof Blob) F.requestBody = `[Blob, ${m.size} bytes, type=${m.type || "unknown"} — not captured]`;
558
- else if (typeof FormData < "u" && m instanceof FormData) F.requestBody = "[FormData — not captured]";
559
- else if (typeof ReadableStream < "u" && m instanceof ReadableStream) F.requestBody = "[ReadableStream — not captured]";
595
+ if (typeof y == "string") F.requestBody = y.length > E ? y.substring(0, E) + "...[truncated]" : y;
596
+ else if (y instanceof URLSearchParams) {
597
+ const D = y.toString();
598
+ F.requestBody = D.length > E ? D.substring(0, E) + "...[truncated]" : D;
599
+ } else if (typeof ArrayBuffer < "u" && (y instanceof ArrayBuffer || ArrayBuffer.isView(y))) {
600
+ const D = y.byteLength ?? y.byteLength;
601
+ F.requestBody = `[binary body, ${D} bytes — not captured]`;
602
+ } else if (typeof Blob < "u" && y instanceof Blob) F.requestBody = `[Blob, ${y.size} bytes, type=${y.type || "unknown"} — not captured]`;
603
+ else if (typeof FormData < "u" && y instanceof FormData) F.requestBody = "[FormData — not captured]";
604
+ else if (typeof ReadableStream < "u" && y instanceof ReadableStream) F.requestBody = "[ReadableStream — not captured]";
560
605
  else {
561
- const N = JSON.stringify(m);
562
- N && N !== "{}" && (F.requestBody = N.length > E ? N.substring(0, E) + "...[truncated]" : N);
606
+ const D = JSON.stringify(y);
607
+ D && D !== "{}" && (F.requestBody = D.length > E ? D.substring(0, E) + "...[truncated]" : D);
563
608
  }
564
609
  } catch {
565
610
  }
566
611
  }
567
612
  let R;
568
613
  if (_.captureResponseBody) {
569
- const m = (h.headers.get("content-type") || "").toLowerCase();
570
- if (!m || m.includes("json") || m.includes("xml") || m.includes("text/") || m.includes("javascript") || m.includes("ecmascript") || m.includes("x-www-form-urlencoded") || m.includes("application/graphql")) {
571
- const E = h.clone(), N = _.responseBodyLimitBytes;
614
+ const y = (g.headers.get("content-type") || "").toLowerCase();
615
+ if (!y || y.includes("json") || y.includes("xml") || y.includes("text/") || y.includes("javascript") || y.includes("ecmascript") || y.includes("x-www-form-urlencoded") || y.includes("application/graphql")) {
616
+ const E = g.clone(), D = _.responseBodyLimitBytes;
572
617
  R = (async () => {
573
618
  try {
574
- const G = await E.text(), Ie = G.length > N ? G.substring(0, N) + "...[truncated]" : G;
619
+ const G = await E.text(), _e = G.length > D ? G.substring(0, D) + "...[truncated]" : G;
575
620
  try {
576
- e.doSend({ ...F, responseBody: Ie });
621
+ e.doSend({ ...F, responseBody: _e });
577
622
  } catch {
578
623
  }
579
624
  } catch {
580
625
  }
581
626
  })(), R.catch(() => {
582
627
  });
583
- } else F.responseBody = `[non-text body, content-type=${m} — not captured]`;
628
+ } else F.responseBody = `[non-text body, content-type=${y} — not captured]`;
584
629
  }
585
630
  R || e.doSend(F);
586
- } catch (g) {
587
- a().sfDebug && console.error("[RequestInterceptor] Post-fetch telemetry failed (response still returned):", g);
631
+ } catch (h) {
632
+ c().sfDebug && console.error("[RequestInterceptor] Post-fetch telemetry failed (response still returned):", h);
588
633
  }
589
- return h;
590
- } : a().sfDebug && console.error("[RequestInterceptor] Fetch not available.");
634
+ return g;
635
+ } : c().sfDebug && console.error("[RequestInterceptor] Fetch not available.");
591
636
  }
592
637
  setHeader(t, e, i) {
593
638
  t instanceof Headers ? t.set(e, i) : t[e] = i;
594
639
  }
595
640
  addTracingHeadersToPlainObject(t, e) {
596
- const i = new URL(e).hostname, n = this.shouldPropagateHeaders(i);
597
- if (n) {
598
- const s = Q();
599
- if (s) {
600
- const d = X(s);
601
- if (d && d.sample_rate === 0) return a().sfDebug && console.log(`[RequestInterceptor] Function span tracking disabled (sample_rate=0), skipping tracing header for ${e}`), !1;
641
+ const i = this.shouldPropagateHeaders(e);
642
+ if (i) {
643
+ const n = Y();
644
+ if (n) {
645
+ const d = Z(n);
646
+ if (d && d.sample_rate === 0) return c().sfDebug && console.log(`[RequestInterceptor] Function span tracking disabled (sample_rate=0), skipping tracing header for ${e}`), !1;
602
647
  }
603
- const l = this.contextManager.getOrSetSfTraceId(), c = this.contextManager.getOrSetPageVisitUUID(), o = J();
604
- t[this.HEADER_TRACING] = `${l}/${c}/${o}`, a().sfDebug && console.log(`[RequestInterceptor] Added tracing header for ${e}`);
605
- } else a().sfDebug && console.error(`[RequestInterceptor] Excluded domain: ${i}`);
606
- return n;
648
+ const o = this.contextManager.getOrSetSfTraceId(), { base: l, parent: u } = this.deriveTraceBaseAndParent(o), s = X();
649
+ t[this.HEADER_TRACING] = `${l}/${s}`, t[oe] = u, c().sfDebug && console.log(`[RequestInterceptor] Added tracing header for ${e}`);
650
+ } else if (c().sfDebug) {
651
+ let n = e;
652
+ try {
653
+ n = new URL(e).hostname;
654
+ } catch {
655
+ }
656
+ console.error(`[RequestInterceptor] Excluded domain: ${n}`);
657
+ }
658
+ return i;
607
659
  }
608
660
  patchHttp(t, e) {
609
- if (a().sfDebug && console.log("[RequestInterceptor] Initializing HTTP/HTTPS request patch..."), !U || typeof U.request != "function") return void (a().sfDebug && console.log("[RequestInterceptor] HTTP/HTTPS not available."));
610
- const i = U.request.bind(U), n = A.request.bind(A), s = (o, d, p, u = se) => {
611
- let y, $;
612
- if (typeof o == "string" || o instanceof URL) {
613
- const S = typeof o == "string" ? new URL(o) : o;
614
- y = { ...typeof d == "object" && d !== null ? d : {}, protocol: S.protocol || u, hostname: S.hostname, port: S.port || void 0, path: S.pathname + S.search }, $ = typeof d == "function" ? d : p;
615
- } else y = { ...o }, y.protocol || (y.protocol = u), $ = typeof d == "function" ? d : void 0;
616
- return y.headers || (y.headers = {}), [y, $];
617
- }, l = (o, d, p) => {
618
- const [u, y] = s(o, d, p, se);
661
+ if (c().sfDebug && console.log("[RequestInterceptor] Initializing HTTP/HTTPS request patch..."), !U || typeof U.request != "function") return void (c().sfDebug && console.log("[RequestInterceptor] HTTP/HTTPS not available."));
662
+ const i = U.request.bind(U), n = A.request.bind(A), o = (s, d, p, a = ce) => {
663
+ let m, I;
664
+ if (typeof s == "string" || s instanceof URL) {
665
+ const S = typeof s == "string" ? new URL(s) : s;
666
+ m = { ...typeof d == "object" && d !== null ? d : {}, protocol: S.protocol || a, hostname: S.hostname, port: S.port || void 0, path: S.pathname + S.search }, I = typeof d == "function" ? d : p;
667
+ } else m = { ...s }, m.protocol || (m.protocol = a), I = typeof d == "function" ? d : void 0;
668
+ return m.headers || (m.headers = {}), [m, I];
669
+ }, l = (s, d, p) => {
670
+ const [a, m] = o(s, d, p, ce);
619
671
  try {
620
- const f = `${u.protocol}//${u.hostname}`;
621
- this.addTracingHeadersToPlainObject(u.headers, f), this.captureFirstUserLines(t);
672
+ const f = `${a.protocol}//${a.hostname}`;
673
+ this.addTracingHeadersToPlainObject(a.headers, f), this.captureFirstUserLines(t);
622
674
  } catch (f) {
623
- a().sfDebug && console.error("[RequestInterceptor] Error while processing HTTP request options:", f);
675
+ c().sfDebug && console.error("[RequestInterceptor] Error while processing HTTP request options:", f);
624
676
  }
625
- const $ = (u.method || "GET").toUpperCase(), S = a().retryOnClientError, h = (f, I, g) => {
677
+ const I = (a.method || "GET").toUpperCase(), S = c().retryOnClientError, g = (f, v, h) => {
626
678
  try {
627
- const { sessionId: D, pageVisitId: v, requestId: _ } = this.extractIdsFromTraceHeader(u.headers);
628
- e.doSend({ apiKey: a().apiKey, requestId: _, pageVisitId: v, recordingSessionId: D, serviceUuid: a().serviceUUID, timestampStart: Date.now().toString(), timestampEnd: Date.now().toString(), responseCode: f.statusCode || 0, success: !!f.statusCode && f.statusCode < 400, error: null, url: I, method: $, retryWithoutTraceId: g, parentSpanId: T() });
679
+ const { sessionId: w, pageVisitId: $, requestId: _ } = this.extractIdsFromTraceHeader(a.headers);
680
+ e.doSend({ apiKey: c().apiKey, requestId: _, pageVisitId: $, recordingSessionId: w, serviceUuid: c().serviceUUID, timestampStart: Date.now().toString(), timestampEnd: Date.now().toString(), responseCode: f.statusCode || 0, success: !!f.statusCode && f.statusCode < 400, error: null, url: v, method: I, retryWithoutTraceId: h, parentSpanId: C() });
629
681
  } catch {
630
682
  }
631
- y?.(f);
683
+ m?.(f);
632
684
  };
633
- return i(u, (f) => {
634
- const I = `${u.protocol}//${u.hostname}`;
635
- let g = !1;
685
+ return i(a, (f) => {
686
+ const v = `${a.protocol}//${a.hostname}`;
687
+ let h = !1;
636
688
  try {
637
- g = this.shouldPropagateHeaders(new URL(I).hostname);
689
+ h = this.shouldPropagateHeaders(v);
638
690
  } catch {
639
- g = !1;
691
+ h = !1;
640
692
  }
641
- if (g && j($, S) && W.includes(f.statusCode || 0)) {
693
+ if (h && z(I, S) && V.includes(f.statusCode || 0)) {
642
694
  f.resume();
643
695
  try {
644
- const { sessionId: v, pageVisitId: _, requestId: F } = this.extractIdsFromTraceHeader(u.headers);
645
- e.doSend({ apiKey: a().apiKey, requestId: F, pageVisitId: _, recordingSessionId: v, serviceUuid: a().serviceUUID, timestampStart: Date.now().toString(), timestampEnd: Date.now().toString(), responseCode: f.statusCode || 0, success: !1, error: null, url: I, method: $, retryWithoutTraceId: !1, parentSpanId: T() });
696
+ const { sessionId: $, pageVisitId: _, requestId: F } = this.extractIdsFromTraceHeader(a.headers);
697
+ e.doSend({ apiKey: c().apiKey, requestId: F, pageVisitId: _, recordingSessionId: $, serviceUuid: c().serviceUUID, timestampStart: Date.now().toString(), timestampEnd: Date.now().toString(), responseCode: f.statusCode || 0, success: !1, error: null, url: v, method: I, retryWithoutTraceId: !1, parentSpanId: C() });
646
698
  } catch {
647
699
  }
648
700
  try {
649
701
  this.captureFirstUserLines(t, 10, !0);
650
702
  } catch {
651
703
  }
652
- const D = { ...u, headers: { ...u.headers } };
653
- return delete D.headers[this.HEADER_TRACING], void i(D, (v) => {
654
- h(v, I, !0);
704
+ const w = { ...a, headers: { ...a.headers } };
705
+ return delete w.headers[this.HEADER_TRACING], void i(w, ($) => {
706
+ g($, v, !0);
655
707
  }).end();
656
708
  }
657
- h(f, I, !1);
709
+ g(f, v, !1);
658
710
  });
659
- }, c = (o, d, p) => {
660
- const [u, y] = s(o, d, p, "https:");
711
+ }, u = (s, d, p) => {
712
+ const [a, m] = o(s, d, p, "https:");
661
713
  try {
662
- const f = `${u.protocol}//${u.hostname}`;
663
- this.addTracingHeadersToPlainObject(u.headers, f), this.captureFirstUserLines(t);
714
+ const f = `${a.protocol}//${a.hostname}`;
715
+ this.addTracingHeadersToPlainObject(a.headers, f), this.captureFirstUserLines(t);
664
716
  } catch (f) {
665
- a().sfDebug && console.error("[RequestInterceptor] Error while processing HTTPS request options:", f);
717
+ c().sfDebug && console.error("[RequestInterceptor] Error while processing HTTPS request options:", f);
666
718
  }
667
- const $ = (u.method || "GET").toUpperCase(), S = a().retryOnClientError, h = (f, I, g) => {
719
+ const I = (a.method || "GET").toUpperCase(), S = c().retryOnClientError, g = (f, v, h) => {
668
720
  try {
669
- const { sessionId: D, pageVisitId: v, requestId: _ } = this.extractIdsFromTraceHeader(u.headers);
670
- e.doSend({ apiKey: a().apiKey, requestId: _, pageVisitId: v, recordingSessionId: D, serviceUuid: a().serviceUUID, timestampStart: Date.now().toString(), timestampEnd: Date.now().toString(), responseCode: f.statusCode || 0, success: !!f.statusCode && f.statusCode < 400, error: null, url: I, method: $, retryWithoutTraceId: g, parentSpanId: T() });
721
+ const { sessionId: w, pageVisitId: $, requestId: _ } = this.extractIdsFromTraceHeader(a.headers);
722
+ e.doSend({ apiKey: c().apiKey, requestId: _, pageVisitId: $, recordingSessionId: w, serviceUuid: c().serviceUUID, timestampStart: Date.now().toString(), timestampEnd: Date.now().toString(), responseCode: f.statusCode || 0, success: !!f.statusCode && f.statusCode < 400, error: null, url: v, method: I, retryWithoutTraceId: h, parentSpanId: C() });
671
723
  } catch {
672
724
  }
673
- y?.(f);
725
+ m?.(f);
674
726
  };
675
- return n(u, (f) => {
676
- const I = `${u.protocol}//${u.hostname}`;
677
- let g = !1;
727
+ return n(a, (f) => {
728
+ const v = `${a.protocol}//${a.hostname}`;
729
+ let h = !1;
678
730
  try {
679
- g = this.shouldPropagateHeaders(new URL(I).hostname);
731
+ h = this.shouldPropagateHeaders(v);
680
732
  } catch {
681
- g = !1;
733
+ h = !1;
682
734
  }
683
- if (g && j($, S) && W.includes(f.statusCode || 0)) {
735
+ if (h && z(I, S) && V.includes(f.statusCode || 0)) {
684
736
  f.resume();
685
737
  try {
686
- const { sessionId: v, pageVisitId: _, requestId: F } = this.extractIdsFromTraceHeader(u.headers);
687
- e.doSend({ apiKey: a().apiKey, requestId: F, pageVisitId: _, recordingSessionId: v, serviceUuid: a().serviceUUID, timestampStart: Date.now().toString(), timestampEnd: Date.now().toString(), responseCode: f.statusCode || 0, success: !1, error: null, url: I, method: $, retryWithoutTraceId: !1, parentSpanId: T() });
738
+ const { sessionId: $, pageVisitId: _, requestId: F } = this.extractIdsFromTraceHeader(a.headers);
739
+ e.doSend({ apiKey: c().apiKey, requestId: F, pageVisitId: _, recordingSessionId: $, serviceUuid: c().serviceUUID, timestampStart: Date.now().toString(), timestampEnd: Date.now().toString(), responseCode: f.statusCode || 0, success: !1, error: null, url: v, method: I, retryWithoutTraceId: !1, parentSpanId: C() });
688
740
  } catch {
689
741
  }
690
742
  try {
691
743
  this.captureFirstUserLines(t, 10, !0);
692
744
  } catch {
693
745
  }
694
- const D = { ...u, headers: { ...u.headers } };
695
- return delete D.headers[this.HEADER_TRACING], void n(D, (v) => {
696
- h(v, I, !0);
746
+ const w = { ...a, headers: { ...a.headers } };
747
+ return delete w.headers[this.HEADER_TRACING], void n(w, ($) => {
748
+ g($, v, !0);
697
749
  }).end();
698
750
  }
699
- h(f, I, !1);
751
+ g(f, v, !1);
700
752
  });
701
753
  };
702
- U.request = l, A.request = c, U.get = (o, d, p) => {
703
- const u = l(o, d, p);
704
- return u.end(), u;
705
- }, A.get = (o, d, p) => {
706
- const u = c(o, d, p);
707
- return u.end(), u;
708
- }, a().sfDebug && console.log("✅ HTTP and HTTPS request/get methods patched globally.");
754
+ U.request = l, A.request = u, U.get = (s, d, p) => {
755
+ const a = l(s, d, p);
756
+ return a.end(), a;
757
+ }, A.get = (s, d, p) => {
758
+ const a = u(s, d, p);
759
+ return a.end(), a;
760
+ }, c().sfDebug && console.log("✅ HTTP and HTTPS request/get methods patched globally.");
709
761
  }
710
762
  tryPatch(t, e) {
711
763
  try {
@@ -717,7 +769,7 @@ class ze {
717
769
  return [...this.contextManager.getExcludedDomains()];
718
770
  }
719
771
  }
720
- class Je extends te {
772
+ class Ze extends re {
721
773
  constructor() {
722
774
  super(), this.setOperationName("UpdateServiceDetails");
723
775
  }
@@ -767,11 +819,11 @@ class Je extends te {
767
819
  serviceRole: $serviceRole,
768
820
  )
769
821
  }
770
- `, e = a(), 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, framework: e.framework || void 0, additionalFrameworks: e.additionalFrameworks?.length > 0 ? e.additionalFrameworks : void 0, serviceRole: e.serviceRole || void 0 });
771
- C(this.endpoint, this.operationName, t, i);
822
+ `, e = c(), 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, framework: e.framework || void 0, additionalFrameworks: e.additionalFrameworks?.length > 0 ? e.additionalFrameworks : void 0, serviceRole: e.serviceRole || void 0 });
823
+ T(this.endpoint, this.operationName, t, i);
772
824
  }
773
825
  }
774
- class Qe {
826
+ class et {
775
827
  constructor(t = [process.cwd()], e = !1) {
776
828
  b(this, "rootPaths");
777
829
  b(this, "fileConfigs", /* @__PURE__ */ new Map());
@@ -785,29 +837,29 @@ class Qe {
785
837
  async loadAllConfigs() {
786
838
  this.debug && console.log("[FuncSpan ConfigLoader] Scanning for .sailfish files in:", this.rootPaths);
787
839
  const t = [];
788
- for (const e of this.rootPaths) Le.existsSync(e) ? await this._walkDirectory(e, t) : this.debug && console.log(`[FuncSpan ConfigLoader] Root path does not exist: ${e}`);
840
+ for (const e of this.rootPaths) Me.existsSync(e) ? await this._walkDirectory(e, t) : this.debug && console.log(`[FuncSpan ConfigLoader] Root path does not exist: ${e}`);
789
841
  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");
790
842
  for (const e of t) await this._loadConfigFile(e);
791
843
  await this._resolveInheritance(), this.debug && console.log(`[FuncSpan ConfigLoader] Loaded ${this.fileConfigs.size} file configs, ${this.functionConfigs.size} function configs`);
792
844
  }
793
845
  getConfig(t, e) {
794
- const i = this.hasSailfishFiles ? Ne() : ge(), n = this._getDirectoryConfig(t), s = P.normalize(t), l = this.fileConfigs.get(s) || {};
795
- let c = {};
846
+ const i = this.hasSailfishFiles ? Re() : Se(), n = this._getDirectoryConfig(t), o = P.normalize(t), l = this.fileConfigs.get(o) || {};
847
+ let u = {};
796
848
  if (e) {
797
- const o = this.functionConfigs.get(s);
798
- o && (c = o.get(e) || {});
849
+ const s = this.functionConfigs.get(o);
850
+ s && (u = s.get(e) || {});
799
851
  }
800
- return L(i, n, l, c);
852
+ return L(i, n, l, u);
801
853
  }
802
854
  hasRuntimeMode() {
803
855
  return this.runtimeModeEnabled;
804
856
  }
805
857
  async _walkDirectory(t, e) {
806
858
  try {
807
- const i = await re.readdir(t, { withFileTypes: !0 });
859
+ const i = await se.readdir(t, { withFileTypes: !0 });
808
860
  for (const n of i) {
809
- const s = P.join(t, n.name);
810
- n.isFile() && n.name === ".sailfish" ? e.push(s) : n.name === "node_modules" || n.isDirectory() && n.name.startsWith(".") && n.name !== ".sailfish" || n.isDirectory() && await this._walkDirectory(s, e);
861
+ const o = P.join(t, n.name);
862
+ 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);
811
863
  }
812
864
  } catch (i) {
813
865
  this.debug && console.error(`[FuncSpan ConfigLoader] Error walking directory ${t}:`, i);
@@ -815,7 +867,7 @@ class Qe {
815
867
  }
816
868
  async _loadConfigFile(t) {
817
869
  try {
818
- const e = await re.readFile(t, "utf-8"), i = P.dirname(t);
870
+ const e = await se.readFile(t, "utf-8"), i = P.dirname(t);
819
871
  let n = null;
820
872
  try {
821
873
  n = JSON.parse(e);
@@ -825,8 +877,8 @@ class Qe {
825
877
  } catch {
826
878
  try {
827
879
  n = require("js-yaml").load(e);
828
- } catch (s) {
829
- return void (this.debug && console.error(`[FuncSpan ConfigLoader] Failed to parse ${t} as JSON, TOML, or YAML:`, s));
880
+ } catch (o) {
881
+ return void (this.debug && console.error(`[FuncSpan ConfigLoader] Failed to parse ${t} as JSON, TOML, or YAML:`, o));
830
882
  }
831
883
  }
832
884
  }
@@ -837,28 +889,28 @@ class Qe {
837
889
  }
838
890
  }
839
891
  async _expandFileGlobs(t, e, i) {
840
- for (const [n, s] of Object.entries(e)) try {
841
- const l = P.join(t, n), c = await Me(l, { absolute: !0, nodir: !0, ignore: ["**/node_modules/**", "**/.git/**"] });
842
- this.debug && console.log(`[FuncSpan ConfigLoader] Pattern '${n}' matched ${c.length} files`);
843
- for (const o of c) {
844
- const d = P.normalize(o), p = L(i, s);
845
- this.fileConfigs.set(d, p), this.debug && c.length <= 5 && console.log(`[FuncSpan ConfigLoader] - ${o}`);
892
+ for (const [n, o] of Object.entries(e)) try {
893
+ const l = P.join(t, n), u = await Ke(l, { absolute: !0, nodir: !0, ignore: ["**/node_modules/**", "**/.git/**"] });
894
+ this.debug && console.log(`[FuncSpan ConfigLoader] Pattern '${n}' matched ${u.length} files`);
895
+ for (const s of u) {
896
+ const d = P.normalize(s), p = L(i, o);
897
+ this.fileConfigs.set(d, p), this.debug && u.length <= 5 && console.log(`[FuncSpan ConfigLoader] - ${s}`);
846
898
  }
847
899
  } catch (l) {
848
900
  this.debug && console.error(`[FuncSpan ConfigLoader] Error expanding glob '${n}':`, l);
849
901
  }
850
902
  }
851
903
  _storeFunctionConfigs(t, e, i) {
852
- for (const [n, s] of Object.entries(e)) {
904
+ for (const [n, o] of Object.entries(e)) {
853
905
  const l = n.split("::");
854
906
  if (l.length !== 2) {
855
907
  this.debug && console.warn(`[FuncSpan ConfigLoader] Invalid function pattern '${n}' (expected format: 'file.ts::functionName')`);
856
908
  continue;
857
909
  }
858
- const [c, o] = l, d = P.normalize(P.join(t, c));
910
+ const [u, s] = l, d = P.normalize(P.join(t, u));
859
911
  this.functionConfigs.has(d) || this.functionConfigs.set(d, /* @__PURE__ */ new Map());
860
- const p = this.functionConfigs.get(d), u = L(i, s);
861
- p.set(o, u), this.debug && console.log(`[FuncSpan ConfigLoader] Function config: ${d}::${o}`);
912
+ const p = this.functionConfigs.get(d), a = L(i, o);
913
+ p.set(s, a), this.debug && console.log(`[FuncSpan ConfigLoader] Function config: ${d}::${s}`);
862
914
  }
863
915
  }
864
916
  async _resolveInheritance() {
@@ -870,37 +922,37 @@ class Qe {
870
922
  const n = this.directoryConfigs.get(e);
871
923
  n && i.unshift(n), e = P.dirname(e);
872
924
  }
873
- return i.reduce((n, s) => L(n, s), {});
925
+ return i.reduce((n, o) => L(n, o), {});
874
926
  }
875
927
  }
876
- const ye = "__sf_globalConfigLoader";
877
- function Se() {
878
- return globalThis[ye] ?? null;
928
+ const $e = "__sf_globalConfigLoader";
929
+ function be() {
930
+ return globalThis[$e] ?? null;
879
931
  }
880
- async function Xe(r, t) {
881
- const e = new Qe(r, t);
932
+ async function tt(r, t) {
933
+ const e = new et(r, t);
882
934
  (function(i) {
883
- globalThis[ye] = i;
935
+ globalThis[$e] = i;
884
936
  })(e), await e.loadAllConfigs();
885
937
  }
886
- function Ye(r, t) {
887
- const e = Se();
888
- return e ? e.getConfig(r, t) : (process.env.SF_DEBUG === "true" && console.log("[FuncSpan ConfigLoader] Config loader not initialized, using default config (disabled)"), ge());
938
+ function nt(r, t) {
939
+ const e = be();
940
+ return e ? e.getConfig(r, t) : (process.env.SF_DEBUG === "true" && console.log("[FuncSpan ConfigLoader] Config loader not initialized, using default config (disabled)"), Se());
889
941
  }
890
- function Ze() {
891
- return Se() !== null;
942
+ function rt() {
943
+ return be() !== null;
892
944
  }
893
- const et = ["readFile", "writeFile", "appendFile", "readdir", "stat", "lstat", "fstat", "access", "open", "close", "read", "write", "chmod", "mkdir", "rmdir", "unlink", "rename"], ae = ["lookup", "resolve", "resolve4", "resolve6", "resolveAny", "resolveMx", "resolveNs", "resolveTxt", "reverse"], tt = ["pbkdf2", "randomBytes", "scrypt", "generateKeyPair"], nt = ["gzip", "gunzip", "deflate", "inflate", "deflateRaw", "inflateRaw", "brotliCompress", "brotliDecompress"];
894
- let ce = !1;
895
- function rt(r) {
945
+ const it = ["readFile", "writeFile", "appendFile", "readdir", "stat", "lstat", "fstat", "access", "open", "close", "read", "write", "chmod", "mkdir", "rmdir", "unlink", "rename"], le = ["lookup", "resolve", "resolve4", "resolve6", "resolveAny", "resolveMx", "resolveNs", "resolveTxt", "reverse"], st = ["pbkdf2", "randomBytes", "scrypt", "generateKeyPair"], ot = ["gzip", "gunzip", "deflate", "inflate", "deflateRaw", "inflateRaw", "brotliCompress", "brotliDecompress"];
946
+ let pe = !1;
947
+ function at(r) {
896
948
  if (typeof r != "string") return !1;
897
949
  const t = process.env.SF_FUNCSPAN_JSONL_FILE;
898
950
  if (t && r.includes(t)) return !0;
899
951
  const e = process.env.SF_WORKER_POOL_JSONL_FILE;
900
952
  return !(!e || !r.includes(e));
901
953
  }
902
- let de = !1;
903
- function ue(r) {
954
+ let fe = !1;
955
+ function ge(r) {
904
956
  if (typeof r != "string") return !1;
905
957
  if (r === "localhost" || r === "127.0.0.1" || r === "::1") return !0;
906
958
  try {
@@ -911,8 +963,8 @@ function ue(r) {
911
963
  }
912
964
  return !1;
913
965
  }
914
- function it() {
915
- if (!de) try {
966
+ function ct() {
967
+ if (!fe) try {
916
968
  let r;
917
969
  if (typeof require > "u") return void (process.env.SF_DEBUG === "true" && console.log("[WorkerPool] Skipping dns patching in pure ESM environment (require unavailable)"));
918
970
  try {
@@ -922,231 +974,231 @@ function it() {
922
974
  }
923
975
  if (r.__sf_worker_pool_patched__) return;
924
976
  Object.defineProperty(r, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
925
- for (const t of ae) if (typeof r[t] == "function") {
977
+ for (const t of le) if (typeof r[t] == "function") {
926
978
  const e = r[t];
927
979
  r[t] = function(...i) {
928
- return ne() ? e.apply(this, i) : ue(i[0]) ? e.apply(this, i) : typeof i[i.length - 1] == "function" ? x("dns", t, e, i, this) : e.apply(this, i);
980
+ return ie() ? e.apply(this, i) : ge(i[0]) ? e.apply(this, i) : typeof i[i.length - 1] == "function" ? x("dns", t, e, i, this) : e.apply(this, i);
929
981
  }, Object.defineProperty(r[t], "name", { value: t, writable: !1 });
930
982
  }
931
983
  (function(t) {
932
984
  if (!t.promises) return void (process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns.promises not available, skipping"));
933
985
  if (!t.promises.__sf_worker_pool_patched__) {
934
986
  Object.defineProperty(t.promises, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
935
- for (const e of ae) if (typeof t.promises[e] == "function") {
987
+ for (const e of le) if (typeof t.promises[e] == "function") {
936
988
  const i = t.promises[e];
937
989
  t.promises[e] = function(...n) {
938
- return ne() ? i.apply(this, n) : ue(n[0]) ? i.apply(this, n) : we("dns", e, i, n, this);
990
+ return ie() ? i.apply(this, n) : ge(n[0]) ? i.apply(this, n) : Te("dns", e, i, n, this);
939
991
  }, Object.defineProperty(t.promises[e], "name", { value: e, writable: !1 });
940
992
  }
941
993
  process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns.promises module patched successfully");
942
994
  }
943
- })(r), de = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns module patched successfully");
995
+ })(r), fe = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns module patched successfully");
944
996
  } catch (r) {
945
997
  console.error("[WorkerPool] Error patching dns module:", r);
946
998
  }
947
999
  }
948
- let le = !1, pe = !1, Y = !1;
949
- function st() {
950
- if (Y) return;
1000
+ let he = !1, me = !1, ee = !1;
1001
+ function dt() {
1002
+ if (ee) return;
951
1003
  const r = process.env.SF_DEBUG === "true";
952
1004
  r && console.log("[WorkerPool] Initializing worker pool patching..."), q("fs") && (r && console.log("[WorkerPool] Patching fs module..."), (function() {
953
- if (!ce) try {
1005
+ if (!pe) try {
954
1006
  const t = require("node:fs");
955
1007
  if (t.__sf_worker_pool_patched__) return;
956
1008
  Object.defineProperty(t, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
957
- for (const e of et) if (typeof t[e] == "function") {
1009
+ for (const e of it) if (typeof t[e] == "function") {
958
1010
  const i = t[e];
959
1011
  t[e] = function(...n) {
960
- return rt(n[0]) ? i.apply(this, n) : typeof n[n.length - 1] == "function" ? x("fs", e, i, n, this) : i.apply(this, n);
1012
+ return at(n[0]) ? i.apply(this, n) : typeof n[n.length - 1] == "function" ? x("fs", e, i, n, this) : i.apply(this, n);
961
1013
  }, Object.defineProperty(t[e], "name", { value: e, writable: !1 });
962
1014
  }
963
- ce = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] fs module patched successfully");
1015
+ pe = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] fs module patched successfully");
964
1016
  } catch (t) {
965
1017
  console.error("[WorkerPool] Error patching fs module:", t);
966
1018
  }
967
- })()), q("dns") && (r && console.log("[WorkerPool] Patching dns module..."), it()), q("crypto") && (r && console.log("[WorkerPool] Patching crypto module..."), (function() {
968
- if (!le) try {
1019
+ })()), q("dns") && (r && console.log("[WorkerPool] Patching dns module..."), ct()), q("crypto") && (r && console.log("[WorkerPool] Patching crypto module..."), (function() {
1020
+ if (!he) try {
969
1021
  const t = require("node:crypto");
970
1022
  if (t.__sf_worker_pool_patched__) return;
971
1023
  Object.defineProperty(t, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
972
- for (const e of tt) if (typeof t[e] == "function") {
1024
+ for (const e of st) if (typeof t[e] == "function") {
973
1025
  const i = t[e];
974
1026
  t[e] = function(...n) {
975
1027
  return typeof n[n.length - 1] == "function" ? x("crypto", e, i, n, this) : i.apply(this, n);
976
1028
  }, Object.defineProperty(t[e], "name", { value: e, writable: !1 });
977
1029
  }
978
- le = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] crypto module patched successfully");
1030
+ he = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] crypto module patched successfully");
979
1031
  } catch (t) {
980
1032
  console.error("[WorkerPool] Error patching crypto module:", t);
981
1033
  }
982
1034
  })()), q("zlib") && (r && console.log("[WorkerPool] Patching zlib module..."), (function() {
983
- if (!pe) try {
1035
+ if (!me) try {
984
1036
  const t = require("node:zlib");
985
1037
  if (t.__sf_worker_pool_patched__) return;
986
1038
  Object.defineProperty(t, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
987
- for (const e of nt) if (typeof t[e] == "function") {
1039
+ for (const e of ot) if (typeof t[e] == "function") {
988
1040
  const i = t[e];
989
1041
  t[e] = function(...n) {
990
1042
  return typeof n[n.length - 1] == "function" ? x("zlib", e, i, n, this) : i.apply(this, n);
991
1043
  }, Object.defineProperty(t[e], "name", { value: e, writable: !1 });
992
1044
  }
993
- pe = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] zlib module patched successfully");
1045
+ me = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] zlib module patched successfully");
994
1046
  } catch (t) {
995
1047
  console.error("[WorkerPool] Error patching zlib module:", t);
996
1048
  }
997
- })()), Y = !0, r && console.log("[WorkerPool] Worker pool patching initialized");
1049
+ })()), ee = !0, r && console.log("[WorkerPool] Worker pool patching initialized");
998
1050
  }
999
- function ot() {
1000
- return Y;
1051
+ function ut() {
1052
+ return ee;
1001
1053
  }
1002
- let Z = !1, V = !1;
1003
- function St(r) {
1004
- if (V) console.warn("[setupInterceptors] ⚠️ Recursive call detected and blocked!");
1005
- else if (!Z) {
1006
- V = !0, Ee();
1054
+ let te = !1, J = !1;
1055
+ function bt(r) {
1056
+ if (J) console.warn("[setupInterceptors] ⚠️ Recursive call detected and blocked!");
1057
+ else if (!te) {
1058
+ J = !0, Ce();
1007
1059
  try {
1008
1060
  let t, e;
1009
- const i = he(new Error().stack);
1061
+ const i = Ie(new Error().stack);
1010
1062
  if (i) {
1011
- const c = i.split(`
1012
- `)[2] || "", o = c.match(/\((.+):(\d+):\d+\)/) || c.match(/at (.+):(\d+):\d+/);
1013
- o && (t = o[1], e = parseInt(o[2], 10));
1063
+ const u = i.split(`
1064
+ `)[2] || "", s = u.match(/\((.+):(\d+):\d+\)/) || u.match(/at (.+):(\d+):\d+/);
1065
+ s && (t = s[1], e = parseInt(s[2], 10));
1014
1066
  }
1015
1067
  if (!r || !r.apiKey) {
1016
- const c = `The required API Key is not provided: ${JSON.stringify(r)}`;
1017
- console.error(c);
1068
+ const u = `The required API Key is not provided: ${JSON.stringify(r)}`;
1069
+ console.error(u);
1018
1070
  }
1019
- const { config: n } = _e(r);
1020
- if (Fe(n).catch(() => {
1071
+ const { config: n } = Ne(r);
1072
+ if (Ee(n).catch(() => {
1021
1073
  }), t && (n.setupInterceptorsFile = t), e && (n.setupInterceptorsLine = e), n.sfDebug && console.log("Updated configuration after applying options:", n), !n.apiKey || !n.apiGraphqlEndpoint) {
1022
- const c = `The required config is not provided: ${JSON.stringify(n)}`;
1023
- throw console.error(c), new Error(c);
1074
+ const u = `The required config is not provided: ${JSON.stringify(n)}`;
1075
+ throw console.error(u), new Error(u);
1024
1076
  }
1025
- Ze() || Xe(void 0, n.sfDebug).catch((c) => {
1026
- n.sfDebug && console.error("[FuncSpan] Failed to initialize config loader:", c);
1027
- }), process.env.SF_WORKER_POOL_DISABLED === "true" ? n.sfDebug && console.log("[setupInterceptors] Worker pool patching DISABLED (SF_WORKER_POOL_DISABLED=true)") : ot() || (st(), n.sfDebug && console.log("[setupInterceptors] Worker pool patching initialized (DNS tracking enabled)"));
1028
- const s = new te();
1029
- s.setServiceUUID(n.serviceUUID), Ue(s), (function(c = []) {
1030
- const o = new ze(c);
1031
- new We().doSend(o.getExcludedDomains());
1032
- const d = new je(), p = new Ve();
1033
- o.patchFetch(d, p), o.patchHttp(d, p);
1077
+ rt() || tt(void 0, n.sfDebug).catch((u) => {
1078
+ n.sfDebug && console.error("[FuncSpan] Failed to initialize config loader:", u);
1079
+ }), process.env.SF_WORKER_POOL_DISABLED === "true" ? n.sfDebug && console.log("[setupInterceptors] Worker pool patching DISABLED (SF_WORKER_POOL_DISABLED=true)") : ut() || (dt(), n.sfDebug && console.log("[setupInterceptors] Worker pool patching initialized (DNS tracking enabled)"));
1080
+ const o = new re();
1081
+ o.setServiceUUID(n.serviceUUID), qe(o), (function(u = []) {
1082
+ const s = new Ye(u);
1083
+ new Je().doSend(s.getExcludedDomains());
1084
+ const d = new Qe(), p = new Xe();
1085
+ s.patchFetch(d, p), s.patchHttp(d, p);
1034
1086
  })(n.domainsToNotPropagateHeadersTo);
1035
- const l = new Be();
1036
- l.setServiceUUID(n.serviceUUID), ke(l), Ke(), new Je().send(), Z = !0, n.sfDebug && console.log("[setupInterceptors] ✅ Initialization complete");
1087
+ const l = new je();
1088
+ l.setServiceUUID(n.serviceUUID), Ae(l), ze(), new Ze().send(), te = !0, n.sfDebug && console.log("[setupInterceptors] ✅ Initialization complete");
1037
1089
  } finally {
1038
- V = !1;
1090
+ J = !1;
1039
1091
  }
1040
1092
  }
1041
1093
  }
1042
- function It() {
1043
- return Z;
1094
+ function _t() {
1095
+ return te;
1044
1096
  }
1045
- function vt(r, t, e, i = !1) {
1046
- const n = a();
1047
- new me(n.apiKey).identify(r, t, e, i);
1097
+ function Ft(r, t, e, i = !1) {
1098
+ const n = c();
1099
+ new ve(n.apiKey).identify(r, t, e, i);
1048
1100
  }
1049
- function $t(r, t = {}, e, i = !1) {
1050
- const n = a();
1051
- new me(n.apiKey).addOrUpdateMetadata(r, t, e, i);
1101
+ function wt(r, t = {}, e, i = !1) {
1102
+ const n = c();
1103
+ new ve(n.apiKey).addOrUpdateMetadata(r, t, e, i);
1052
1104
  }
1053
- let z = null;
1054
- function bt(r, t, e, i) {
1055
- const n = function(...s) {
1056
- const l = fe(), c = l?.sfDebug || !1;
1057
- c && console.log(`[FuncSpan] captureFunctionSpan wrapper called for ${e}::${t}`);
1058
- const o = (function(h, f) {
1059
- const I = Q();
1060
- if (I) {
1061
- const g = X(I);
1062
- if (g) return process.env.SF_DEBUG === "true" && console.log(`[FuncSpan] Using HTTP header override for ${h}::${f}`), g;
1105
+ let Q = null;
1106
+ function Dt(r, t, e, i) {
1107
+ const n = function(...o) {
1108
+ const l = ye(), u = l?.sfDebug || !1;
1109
+ u && console.log(`[FuncSpan] captureFunctionSpan wrapper called for ${e}::${t}`);
1110
+ const s = (function(g, f) {
1111
+ const v = Y();
1112
+ if (v) {
1113
+ const h = Z(v);
1114
+ if (h) return process.env.SF_DEBUG === "true" && console.log(`[FuncSpan] Using HTTP header override for ${g}::${f}`), h;
1063
1115
  }
1064
1116
  try {
1065
- return Ye(h, f);
1117
+ return nt(g, f);
1066
1118
  } catch {
1067
1119
  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 };
1068
1120
  }
1069
1121
  })(e, t);
1070
- if (c && console.log(`[FuncSpan] Config for ${e}::${t}:`, o), o.enable_sampling && o.sample_rate < 1 && Math.random() > o.sample_rate) return c && console.log(`[FuncSpan] Skipping ${t} due to sampling`), r.apply(this, s);
1071
- if (o.sample_rate === 0) return c && console.log(`[FuncSpan] Skipping ${t} - sample_rate is 0.0`), r.apply(this, s);
1072
- c && console.log(`[FuncSpan] Capturing function span for ${t}`);
1073
- const d = ee.getInstance(), p = d.getCurrentFunctionSpanId(), u = J();
1074
- d.setCurrentFunctionSpanId(u);
1075
- const y = process.hrtime.bigint(), $ = Date.now();
1122
+ if (u && console.log(`[FuncSpan] Config for ${e}::${t}:`, s), s.enable_sampling && s.sample_rate < 1 && Math.random() > s.sample_rate) return u && console.log(`[FuncSpan] Skipping ${t} due to sampling`), r.apply(this, o);
1123
+ if (s.sample_rate === 0) return u && console.log(`[FuncSpan] Skipping ${t} - sample_rate is 0.0`), r.apply(this, o);
1124
+ u && console.log(`[FuncSpan] Capturing function span for ${t}`);
1125
+ const d = ne.getInstance(), p = d.getCurrentFunctionSpanId(), a = X();
1126
+ d.setCurrentFunctionSpanId(a);
1127
+ const m = process.hrtime.bigint(), I = Date.now();
1076
1128
  let S = null;
1077
- o.capture_arguments && (S = {}, i.paramNames.forEach((h, f) => {
1078
- f < s.length && (S[h] = s[f]);
1079
- }), S && o.arg_limit_mb > 0 && (S = K(S, o.arg_limit_mb)));
1129
+ s.capture_arguments && (S = {}, i.paramNames.forEach((g, f) => {
1130
+ f < o.length && (S[g] = o[f]);
1131
+ }), S && s.arg_limit_mb > 0 && (S = K(S, s.arg_limit_mb)));
1080
1132
  try {
1081
- const h = r.apply(this, s);
1082
- if (h && typeof h.then == "function") return p ? d.setCurrentFunctionSpanId(p) : d.clearCurrentFunctionSpanId(), h.then((v) => {
1083
- const _ = process.hrtime.bigint(), F = Date.now(), R = Number(_ - y);
1084
- let m = null;
1085
- return o.capture_return_value && o.return_limit_mb > 0 && (m = K(v, o.return_limit_mb)), M({ functionName: t, filePath: e, metadata: i, args: S, result: m, error: null, duration: F - $, durationNs: R, startTimeNs: y.toString(), async: !0, spanId: u, parentSpanId: p, pid: process.pid, threadId: H }), v;
1086
- }, (v) => {
1087
- const _ = process.hrtime.bigint(), F = Date.now(), R = Number(_ - y);
1088
- throw M({ functionName: t, filePath: e, metadata: i, args: S, result: null, error: v?.message || String(v), duration: F - $, durationNs: R, startTimeNs: y.toString(), async: !0, spanId: u, parentSpanId: p, pid: process.pid, threadId: H }), v;
1133
+ const g = r.apply(this, o);
1134
+ if (g && typeof g.then == "function") return p ? d.setCurrentFunctionSpanId(p) : d.clearCurrentFunctionSpanId(), g.then(($) => {
1135
+ const _ = process.hrtime.bigint(), F = Date.now(), R = Number(_ - m);
1136
+ let y = null;
1137
+ return s.capture_return_value && s.return_limit_mb > 0 && (y = K($, s.return_limit_mb)), M({ functionName: t, filePath: e, metadata: i, args: S, result: y, error: null, duration: F - I, durationNs: R, startTimeNs: m.toString(), async: !0, spanId: a, parentSpanId: p, pid: process.pid, threadId: H }), $;
1138
+ }, ($) => {
1139
+ const _ = process.hrtime.bigint(), F = Date.now(), R = Number(_ - m);
1140
+ throw M({ functionName: t, filePath: e, metadata: i, args: S, result: null, error: $?.message || String($), duration: F - I, durationNs: R, startTimeNs: m.toString(), async: !0, spanId: a, parentSpanId: p, pid: process.pid, threadId: H }), $;
1089
1141
  });
1090
- const f = process.hrtime.bigint(), I = Date.now(), g = Number(f - y);
1091
- let D = null;
1092
- return o.capture_return_value && o.return_limit_mb > 0 && (D = K(h, o.return_limit_mb)), M({ functionName: t, filePath: e, metadata: i, args: S, result: D, error: null, duration: I - $, durationNs: g, startTimeNs: y.toString(), async: !1, spanId: u, parentSpanId: p, pid: process.pid, threadId: H }), p ? d.setCurrentFunctionSpanId(p) : d.clearCurrentFunctionSpanId(), h;
1093
- } catch (h) {
1094
- const f = process.hrtime.bigint(), I = Date.now(), g = Number(f - y);
1095
- throw M({ functionName: t, filePath: e, metadata: i, args: S, result: null, error: h?.message || String(h), duration: I - $, durationNs: g, startTimeNs: y.toString(), async: !1, spanId: u, parentSpanId: p, pid: process.pid, threadId: H }), p ? d.setCurrentFunctionSpanId(p) : d.clearCurrentFunctionSpanId(), h;
1142
+ const f = process.hrtime.bigint(), v = Date.now(), h = Number(f - m);
1143
+ let w = null;
1144
+ return s.capture_return_value && s.return_limit_mb > 0 && (w = K(g, s.return_limit_mb)), M({ functionName: t, filePath: e, metadata: i, args: S, result: w, error: null, duration: v - I, durationNs: h, startTimeNs: m.toString(), async: !1, spanId: a, parentSpanId: p, pid: process.pid, threadId: H }), p ? d.setCurrentFunctionSpanId(p) : d.clearCurrentFunctionSpanId(), g;
1145
+ } catch (g) {
1146
+ const f = process.hrtime.bigint(), v = Date.now(), h = Number(f - m);
1147
+ throw M({ functionName: t, filePath: e, metadata: i, args: S, result: null, error: g?.message || String(g), duration: v - I, durationNs: h, startTimeNs: m.toString(), async: !1, spanId: a, parentSpanId: p, pid: process.pid, threadId: H }), p ? d.setCurrentFunctionSpanId(p) : d.clearCurrentFunctionSpanId(), g;
1096
1148
  }
1097
1149
  };
1098
1150
  Object.defineProperty(n, "name", { value: t, writable: !1 });
1099
- for (const s in r) r.hasOwnProperty(s) && (n[s] = r[s]);
1151
+ for (const o in r) r.hasOwnProperty(o) && (n[o] = r[o]);
1100
1152
  return n;
1101
1153
  }
1102
1154
  function M(r) {
1103
- const t = fe(), e = t?.sfDebug || !1;
1155
+ const t = ye(), e = t?.sfDebug || !1;
1104
1156
  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 });
1105
1157
  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 };
1106
1158
  process.env.SF_FUNCSPAN_CONSOLE_OUTPUT === "true" && console.log(`
1107
1159
  📊 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" });
1108
1160
  const n = process.env.SF_FUNCSPAN_JSONL_FILE;
1109
1161
  if (n) try {
1110
- const s = n === "true" || n === "1" ? "funcspans.jsonl" : n, l = Date.now(), c = process.hrtime.bigint(), o = BigInt(r.startTimeNs), d = Number(c - o) / 1e6, p = new Date(l - d).toISOString(), u = JSON.stringify({ timestamp: p, 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 }) + `
1162
+ const o = n === "true" || n === "1" ? "funcspans.jsonl" : n, l = Date.now(), u = process.hrtime.bigint(), s = BigInt(r.startTimeNs), d = Number(u - s) / 1e6, p = new Date(l - d).toISOString(), a = JSON.stringify({ timestamp: p, 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 }) + `
1111
1163
  `;
1112
- Ae(s, u, "utf-8");
1113
- } catch (s) {
1114
- console.error("[FuncSpan] Error writing to JSONL file:", s);
1164
+ Be(o, a, "utf-8");
1165
+ } catch (o) {
1166
+ console.error("[FuncSpan] Error writing to JSONL file:", o);
1115
1167
  }
1116
1168
  if (e && console.log("[FuncSpan] Sending function span to transmitter:", i), process.env.SF_FUNCSPAN_SKIP_BACKEND !== "true") try {
1117
- (z || (z = new Pe()), z).send([i]), e && console.log("[FuncSpan] Function span sent successfully");
1118
- } catch (s) {
1119
- e && console.error("[FuncSpan] Error sending function span:", s);
1169
+ (Q || (Q = new Ue()), Q).send([i]), e && console.log("[FuncSpan] Function span sent successfully");
1170
+ } catch (o) {
1171
+ e && console.error("[FuncSpan] Error sending function span:", o);
1120
1172
  }
1121
1173
  }
1122
- function _t(r) {
1174
+ function Nt(r) {
1123
1175
  return !!r.includes("captureFunctionSpan(") || !!r.includes("@sailfish-ai/sf-veritas") || !(!r.includes("/* @sailfish-instrumented */") && !r.includes("// @sailfish-instrumented"));
1124
1176
  }
1125
1177
  export {
1126
- ee as ContextManager,
1127
- $t as addOrUpdateMetadata,
1128
- bt as captureFunctionSpan,
1129
- Et as clearFuncspanOverride,
1130
- T as getCurrentFunctionSpanId,
1131
- ge as getDefaultConfig,
1132
- Ne as getEnvConfig,
1133
- Q as getFuncspanOverride,
1134
- Ye as getGlobalConfig,
1135
- vt as identify,
1136
- Xe as initializeConfigLoader,
1137
- st as initializeWorkerPoolPatching,
1138
- _t as isAlreadyInstrumented,
1139
- Ze as isConfigLoaderInitialized,
1140
- Ct as isProductionEnvironment,
1141
- Tt as isRuntimeModeEnabled,
1142
- It as isSetupInterceptorsInitialized,
1143
- ot as isWorkerPoolInitialized,
1144
- X as parseHeaderOverride,
1145
- Nt as runWithContext,
1146
- Pt as setFuncspanOverride,
1147
- Ot as setSkipTypeScriptPlugin,
1148
- St as setupInterceptors,
1149
- Ut as shouldEnableRuntimeHooks,
1150
- Lt as transformFunctionSpans,
1151
- qt as transformFunctionSpansSync
1178
+ ne as ContextManager,
1179
+ wt as addOrUpdateMetadata,
1180
+ Dt as captureFunctionSpan,
1181
+ Ct as clearFuncspanOverride,
1182
+ C as getCurrentFunctionSpanId,
1183
+ Se as getDefaultConfig,
1184
+ Re as getEnvConfig,
1185
+ Y as getFuncspanOverride,
1186
+ nt as getGlobalConfig,
1187
+ Ft as identify,
1188
+ tt as initializeConfigLoader,
1189
+ dt as initializeWorkerPoolPatching,
1190
+ Nt as isAlreadyInstrumented,
1191
+ rt as isConfigLoaderInitialized,
1192
+ Ot as isProductionEnvironment,
1193
+ Lt as isRuntimeModeEnabled,
1194
+ _t as isSetupInterceptorsInitialized,
1195
+ ut as isWorkerPoolInitialized,
1196
+ Z as parseHeaderOverride,
1197
+ Rt as runWithContext,
1198
+ Ut as setFuncspanOverride,
1199
+ Ht as setSkipTypeScriptPlugin,
1200
+ bt as setupInterceptors,
1201
+ qt as shouldEnableRuntimeHooks,
1202
+ Mt as transformFunctionSpans,
1203
+ xt as transformFunctionSpansSync
1152
1204
  };