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