@sailfish-ai/sf-veritas 0.3.0 → 0.3.1

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 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";
13
+ import U from "http";
14
+ import A from "https";
15
+ import { s as He } from "./source-map-Cr6YkjTd.js";
16
+ import * as re from "fs/promises";
17
+ import * as P from "path";
18
+ import { glob as Me } from "glob";
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";
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 (!a().serviceIdentificationReceived) try {
27
27
  this.send();
28
28
  } catch (e) {
29
- f().sfDebug && console.error(" Error during service identification:", e);
29
+ a().sfDebug && console.error(" Error during service identification:", e);
30
30
  }
31
31
  }
32
32
  async send() {
@@ -68,22 +68,22 @@ 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 = 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);
73
73
  }
74
74
  }
75
- class Le extends R {
75
+ class xe 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
+ a().serviceIdentificationReceived ? clearInterval(e) : this.serviceIdentifier.doSend({});
87
87
  }, 5e3);
88
88
  e && typeof e == "object" && "unref" in e && e.unref();
89
89
  }
@@ -94,11 +94,11 @@ class Le extends R {
94
94
  if (!i && !s) throw new Error('Must pass in either traits or traits_json to "add_or_update_traits"');
95
95
  let l = [];
96
96
  if (!s) {
97
- const o = Ne(i);
97
+ const o = Re(i);
98
98
  s = o.traitsJson, l = o.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 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);
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 me {
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 xe();
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
+ 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);
122
122
  }
123
123
  }
124
- class Q extends R {
124
+ class te 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
+ a().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
+ C(this.endpoint, this.operationName, this.getQuery(), n);
145
145
  } catch (i) {
146
- f().sfDebug && console.error("🚨 Error in send():", i);
146
+ a().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 Be 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
+ a().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
+ 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);
207
207
  }
208
208
  getQuery() {
209
209
  return `
@@ -237,51 +237,51 @@ 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 ie = "getting request source code";
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."));
247
247
  let t;
248
- ne = !0;
248
+ oe = !0;
249
249
  try {
250
- t = qe("node:http"), r && b("[patchNodeHttpInbound] node:http required successfully.");
250
+ t = Ge("node:http"), r && w("[patchNodeHttpInbound] node:http required successfully.");
251
251
  } catch (n) {
252
- return void we("Failed to require node:http:", n);
252
+ return void Te("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 && w("[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) {
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
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));
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
262
  return h;
263
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());
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.");
271
+ const S = () => {
272
+ r && w("[patchNodeHttpInbound] Response finished/closed for traceId:", u.getTraceId());
273
273
  };
274
- return a.on("finish", u), a.on("close", u), i.call(this, n, l, a);
274
+ return c.on("finish", S), c.on("close", S), i.call(this, n, l, c);
275
275
  });
276
- if (!p) return m();
276
+ if (!p) return $();
277
277
  try {
278
- return Ie.run(p, () => m());
278
+ return De.run(p, () => $());
279
279
  } catch {
280
- return m();
280
+ return $();
281
281
  }
282
- }) : r && b("[patchNodeHttpInbound] Already patched, skipping.");
282
+ }) : r && w("[patchNodeHttpInbound] Already patched, skipping.");
283
283
  }
284
- class Me extends Q {
284
+ class We extends te {
285
285
  constructor() {
286
286
  super(), this.setOperationName("DomainsToNotPassHeaderTo");
287
287
  }
@@ -302,21 +302,21 @@ class Me extends Q {
302
302
  )
303
303
  }
304
304
  `, i = { apiKey: this.apiKey, serviceUuid: this.serviceUUID, domains: t };
305
- w(this.endpoint, this.operationName, e, i);
305
+ C(this.endpoint, this.operationName, e, i);
306
306
  }
307
307
  }
308
- class xe extends R {
308
+ class je extends k {
309
309
  constructor() {
310
310
  super();
311
- y(this, "serviceIdentifier", new T());
312
- y(this, "identifyStarted", !1);
311
+ b(this, "serviceIdentifier", new O());
312
+ b(this, "identifyStarted", !1);
313
313
  this.setOperationName("CollectNetworkHops");
314
314
  }
315
315
  startBackgroundIdentify() {
316
316
  if (this.identifyStarted) return;
317
317
  this.identifyStarted = !0, this.serviceIdentifier.doSend({});
318
318
  const e = setInterval(() => {
319
- f().serviceIdentificationReceived ? clearInterval(e) : this.serviceIdentifier.doSend({});
319
+ a().serviceIdentificationReceived ? clearInterval(e) : this.serviceIdentifier.doSend({});
320
320
  }, 5e3);
321
321
  e && typeof e == "object" && "unref" in e && e.unref();
322
322
  }
@@ -324,8 +324,8 @@ class xe extends R {
324
324
  this.startBackgroundIdentify(), this.send(e);
325
325
  }
326
326
  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);
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);
329
329
  }
330
330
  getQuery() {
331
331
  return `
@@ -355,18 +355,18 @@ class xe extends R {
355
355
  `;
356
356
  }
357
357
  }
358
- class Be extends R {
358
+ class Ve extends k {
359
359
  constructor() {
360
360
  super();
361
- y(this, "serviceIdentifier", new T());
362
- y(this, "identifyStarted", !1);
361
+ b(this, "serviceIdentifier", new O());
362
+ b(this, "identifyStarted", !1);
363
363
  this.setOperationName("CollectNetworkRequest");
364
364
  }
365
365
  startBackgroundIdentify() {
366
366
  if (this.identifyStarted) return;
367
367
  this.identifyStarted = !0, this.serviceIdentifier.doSend({});
368
368
  const e = setInterval(() => {
369
- f().serviceIdentificationReceived ? clearInterval(e) : this.serviceIdentifier.doSend({});
369
+ a().serviceIdentificationReceived ? clearInterval(e) : this.serviceIdentifier.doSend({});
370
370
  }, 5e3);
371
371
  e && typeof e == "object" && "unref" in e && e.unref();
372
372
  }
@@ -385,28 +385,31 @@ class Be extends R {
385
385
  }
386
386
  async send(e) {
387
387
  const i = { data: { ...e } };
388
- await w(this.endpoint, this.operationName, this.getQuery(), i);
388
+ await C(this.endpoint, this.operationName, this.getQuery(), i);
389
389
  }
390
390
  }
391
- const x = [400, 403];
392
- class Ge {
391
+ const W = [400, 403];
392
+ function j(r, t) {
393
+ return t !== "none" && (t === "all" || r === "GET" || r === "HEAD" || r === "OPTIONS");
394
+ }
395
+ class ze {
393
396
  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) => {
397
+ b(this, "HEADER_TRACING", "X-Sf3-Rid");
398
+ b(this, "HEADER_LOG_GUARD", "reentrancy_guard_logging_preactive");
399
+ b(this, "HEADER_PRINT_GUARD", "reentrancy_guard_print_preactive");
400
+ b(this, "HEADER_EXCEPTION_GUARD", "reentrancy_guard_exception_preactive");
401
+ b(this, "contextManager");
402
+ this.contextManager = ee.getInstance(), t?.forEach((e) => {
400
403
  typeof e == "string" && e.trim() && this.contextManager.getExcludedDomains().add(e);
401
- }), f().sfDebug && console.log("[RequestInterceptor] Initialized with static excluded domains.");
404
+ }), a().sfDebug && console.log("[RequestInterceptor] Initialized with static excluded domains.");
402
405
  }
403
406
  extractIdsFromTraceHeader(t, e = this.HEADER_TRACING) {
404
407
  let i;
405
408
  if (t instanceof Headers) i = t.get(e) ?? void 0;
406
409
  else {
407
410
  const s = e.toLowerCase();
408
- for (const [l, a] of Object.entries(t)) if (l.toLowerCase() === s) {
409
- i = a;
411
+ for (const [l, c] of Object.entries(t)) if (l.toLowerCase() === s) {
412
+ i = c;
410
413
  break;
411
414
  }
412
415
  }
@@ -425,55 +428,55 @@ class Ge {
425
428
  if (t.includes("://")) return { originalPos: n };
426
429
  const s = t + ".map";
427
430
  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);
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);
431
434
  } catch (l) {
432
- f().sfDebug && console.error(`Could not read/parse map file at ${s}:`, l);
435
+ a().sfDebug && console.error(`Could not read/parse map file at ${s}:`, l);
433
436
  }
434
437
  return { originalPos: n };
435
438
  }
436
439
  captureFirstUserLines(t, e = 10, i = !1) {
437
- const n = f().sfDebug ? 10 : e, s = Error.stackTraceLimit;
440
+ const n = a().sfDebug ? 10 : e, s = Error.stackTraceLimit;
438
441
  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
+ const l = new Error(ie);
443
+ ie in Error && Error.captureStackTrace(l, this.captureFirstUserLines);
444
+ const c = he(l.stack);
442
445
  Error.stackTraceLimit = s;
443
- const o = a.split(`
446
+ const o = c.split(`
444
447
  `).slice(1), d = [];
445
448
  for (const p of o)
446
449
  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
450
  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);
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($);
455
458
  }
456
- })() : f().sfDebug && console.error("Could not parse stack line:", p);
459
+ })() : a().sfDebug && console.error("Could not parse stack line:", p);
457
460
  }
458
461
  }
459
462
  addReentrancyGuardHeaders(t) {
460
463
  t.set(this.HEADER_LOG_GUARD, "true"), t.set(this.HEADER_PRINT_GUARD, "true"), t.set(this.HEADER_EXCEPTION_GUARD, "true");
461
464
  }
462
465
  shouldPropagateHeaders(t) {
463
- return !ye.some((e) => new RegExp(`^${e.replace(/\*/g, ".*")}$`).test(t));
466
+ return !be.some((e) => new RegExp(`^${e.replace(/\*/g, ".*")}$`).test(t));
464
467
  }
465
468
  addTracingHeaders(t, e) {
466
469
  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;
470
+ return n ? this.addTracingHeader(t, e) : a().sfDebug && console.error(`[RequestInterceptor] Excluded domain: ${i}`), n;
468
471
  }
469
472
  addTracingHeader(t, e) {
470
- const i = W();
473
+ const i = Q();
471
474
  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}`));
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}`));
474
477
  }
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}`);
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}`);
477
480
  }
478
481
  patchFetch(t, e) {
479
482
  const i = globalThis.fetch;
@@ -481,47 +484,110 @@ class Ge {
481
484
  const l = new Headers(s?.headers);
482
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);
483
486
  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;
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();
490
+ 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);
494
+ });
495
+ }
496
+ a().sfDebug && console.log("[RequestInterceptor] Fetching request to:", o);
497
+ let p = "unknown";
498
+ try {
499
+ p = new URL(o).hostname;
500
+ } catch {
501
+ return a().sfDebug && console.warn(`[RequestInterceptor] Could not parse URL '${o}' — passing through without tracing headers.`), i(n, s);
502
+ }
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;
491
505
  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 = $;
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;
510
+ try {
511
+ this.captureFirstUserLines(t, 10, f);
512
+ } catch (F) {
513
+ a().sfDebug && console.error("[RequestInterceptor] captureFirstUserLines (retry) failed:", F);
514
+ }
515
+ } else try {
516
+ this.contextManager.addSupportedDomains(p);
517
+ } catch (v) {
518
+ a().sfDebug && console.error("[RequestInterceptor] addSupportedDomains failed:", v);
502
519
  }
503
- if (S.captureResponseHeaders) {
504
- const $ = {};
505
- m.headers.forEach((N, P) => {
506
- $[P] = N;
507
- }), F.responseHeaders = $;
520
+ } catch (g) {
521
+ const D = Date.now();
522
+ a().sfDebug && console.error(`[RequestInterceptor] Fetch failed: ${o}, Error: ${g}, Duration: ${D - c}ms`);
523
+ 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);
508
528
  }
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 {
529
+ throw g;
530
+ }
531
+ const I = Date.now();
532
+ 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() };
535
+ if (_.captureRequestHeaders) {
536
+ const m = {};
537
+ l.forEach((E, N) => {
538
+ m[N] = E;
539
+ }), F.requestHeaders = m;
513
540
  }
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 {
541
+ if (_.captureResponseHeaders) {
542
+ const m = {};
543
+ h.headers.forEach((E, N) => {
544
+ m[N] = E;
545
+ }), F.responseHeaders = m;
518
546
  }
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`);
547
+ if (_.captureRequestBody && s?.body) {
548
+ const m = s.body, E = _.requestBodyLimitBytes;
549
+ 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]";
560
+ else {
561
+ const N = JSON.stringify(m);
562
+ N && N !== "{}" && (F.requestBody = N.length > E ? N.substring(0, E) + "...[truncated]" : N);
563
+ }
564
+ } catch {
565
+ }
566
+ }
567
+ let R;
568
+ 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;
572
+ R = (async () => {
573
+ try {
574
+ const G = await E.text(), Ie = G.length > N ? G.substring(0, N) + "...[truncated]" : G;
575
+ try {
576
+ e.doSend({ ...F, responseBody: Ie });
577
+ } catch {
578
+ }
579
+ } catch {
580
+ }
581
+ })(), R.catch(() => {
582
+ });
583
+ } else F.responseBody = `[non-text body, content-type=${m} — not captured]`;
584
+ }
585
+ R || e.doSend(F);
586
+ } catch (g) {
587
+ a().sfDebug && console.error("[RequestInterceptor] Post-fetch telemetry failed (response still returned):", g);
523
588
  }
524
- } : f().sfDebug && console.error("[RequestInterceptor] Fetch not available.");
589
+ return h;
590
+ } : a().sfDebug && console.error("[RequestInterceptor] Fetch not available.");
525
591
  }
526
592
  setHeader(t, e, i) {
527
593
  t instanceof Headers ? t.set(e, i) : t[e] = i;
@@ -529,69 +595,117 @@ class Ge {
529
595
  addTracingHeadersToPlainObject(t, e) {
530
596
  const i = new URL(e).hostname, n = this.shouldPropagateHeaders(i);
531
597
  if (n) {
532
- const s = W();
598
+ const s = Q();
533
599
  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;
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;
536
602
  }
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}`);
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}`);
540
606
  return n;
541
607
  }
542
608
  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;
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, $;
546
612
  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];
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, $];
551
617
  }, l = (o, d, p) => {
552
- const [c, g] = s(o, d, p, te);
618
+ const [u, y] = s(o, d, p, se);
553
619
  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);
620
+ const f = `${u.protocol}//${u.hostname}`;
621
+ this.addTracingHeadersToPlainObject(u.headers, f), this.captureFirstUserLines(t);
622
+ } catch (f) {
623
+ a().sfDebug && console.error("[RequestInterceptor] Error while processing HTTP request options:", f);
558
624
  }
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);
625
+ const $ = (u.method || "GET").toUpperCase(), S = a().retryOnClientError, h = (f, I, g) => {
626
+ 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() });
629
+ } catch {
630
+ }
631
+ y?.(f);
632
+ };
633
+ return i(u, (f) => {
634
+ const I = `${u.protocol}//${u.hostname}`;
635
+ let g = !1;
636
+ try {
637
+ g = this.shouldPropagateHeaders(new URL(I).hostname);
638
+ } catch {
639
+ g = !1;
640
+ }
641
+ if (g && j($, S) && W.includes(f.statusCode || 0)) {
642
+ f.resume();
643
+ 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() });
646
+ } catch {
647
+ }
648
+ try {
649
+ this.captureFirstUserLines(t, 10, !0);
650
+ } catch {
651
+ }
652
+ const D = { ...u, headers: { ...u.headers } };
653
+ return delete D.headers[this.HEADER_TRACING], void i(D, (v) => {
654
+ h(v, I, !0);
655
+ }).end();
565
656
  }
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);
657
+ h(f, I, !1);
568
658
  });
569
- }, a = (o, d, p) => {
570
- const [c, g] = s(o, d, p, "https:");
659
+ }, c = (o, d, p) => {
660
+ const [u, y] = s(o, d, p, "https:");
571
661
  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);
662
+ const f = `${u.protocol}//${u.hostname}`;
663
+ this.addTracingHeadersToPlainObject(u.headers, f), this.captureFirstUserLines(t);
664
+ } catch (f) {
665
+ a().sfDebug && console.error("[RequestInterceptor] Error while processing HTTPS request options:", f);
576
666
  }
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);
667
+ const $ = (u.method || "GET").toUpperCase(), S = a().retryOnClientError, h = (f, I, g) => {
668
+ 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() });
671
+ } catch {
672
+ }
673
+ y?.(f);
674
+ };
675
+ return n(u, (f) => {
676
+ const I = `${u.protocol}//${u.hostname}`;
677
+ let g = !1;
678
+ try {
679
+ g = this.shouldPropagateHeaders(new URL(I).hostname);
680
+ } catch {
681
+ g = !1;
583
682
  }
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);
683
+ if (g && j($, S) && W.includes(f.statusCode || 0)) {
684
+ f.resume();
685
+ 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() });
688
+ } catch {
689
+ }
690
+ try {
691
+ this.captureFirstUserLines(t, 10, !0);
692
+ } catch {
693
+ }
694
+ const D = { ...u, headers: { ...u.headers } };
695
+ return delete D.headers[this.HEADER_TRACING], void n(D, (v) => {
696
+ h(v, I, !0);
697
+ }).end();
698
+ }
699
+ h(f, I, !1);
586
700
  });
587
701
  };
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.");
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.");
595
709
  }
596
710
  tryPatch(t, e) {
597
711
  try {
@@ -603,7 +717,7 @@ class Ge {
603
717
  return [...this.contextManager.getExcludedDomains()];
604
718
  }
605
719
  }
606
- class Ke extends Q {
720
+ class Je extends te {
607
721
  constructor() {
608
722
  super(), this.setOperationName("UpdateServiceDetails");
609
723
  }
@@ -653,46 +767,46 @@ class Ke extends Q {
653
767
  serviceRole: $serviceRole,
654
768
  )
655
769
  }
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);
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);
658
772
  }
659
773
  }
660
- class We {
774
+ class Qe {
661
775
  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");
776
+ b(this, "rootPaths");
777
+ b(this, "fileConfigs", /* @__PURE__ */ new Map());
778
+ b(this, "functionConfigs", /* @__PURE__ */ new Map());
779
+ b(this, "directoryConfigs", /* @__PURE__ */ new Map());
780
+ b(this, "hasSailfishFiles", !1);
781
+ b(this, "runtimeModeEnabled", !1);
782
+ b(this, "debug");
669
783
  this.rootPaths = t, this.debug = e || process.env.SF_DEBUG === "true";
670
784
  }
671
785
  async loadAllConfigs() {
672
786
  this.debug && console.log("[FuncSpan ConfigLoader] Scanning for .sailfish files in:", this.rootPaths);
673
787
  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}`);
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}`);
675
789
  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
790
  for (const e of t) await this._loadConfigFile(e);
677
791
  await this._resolveInheritance(), this.debug && console.log(`[FuncSpan ConfigLoader] Loaded ${this.fileConfigs.size} file configs, ${this.functionConfigs.size} function configs`);
678
792
  }
679
793
  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 = {};
794
+ const i = this.hasSailfishFiles ? Ne() : ge(), n = this._getDirectoryConfig(t), s = P.normalize(t), l = this.fileConfigs.get(s) || {};
795
+ let c = {};
682
796
  if (e) {
683
797
  const o = this.functionConfigs.get(s);
684
- o && (a = o.get(e) || {});
798
+ o && (c = o.get(e) || {});
685
799
  }
686
- return C(i, n, l, a);
800
+ return L(i, n, l, c);
687
801
  }
688
802
  hasRuntimeMode() {
689
803
  return this.runtimeModeEnabled;
690
804
  }
691
805
  async _walkDirectory(t, e) {
692
806
  try {
693
- const i = await Z.readdir(t, { withFileTypes: !0 });
807
+ const i = await re.readdir(t, { withFileTypes: !0 });
694
808
  for (const n of i) {
695
- const s = D.join(t, n.name);
809
+ const s = P.join(t, n.name);
696
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);
697
811
  }
698
812
  } catch (i) {
@@ -701,7 +815,7 @@ class We {
701
815
  }
702
816
  async _loadConfigFile(t) {
703
817
  try {
704
- const e = await Z.readFile(t, "utf-8"), i = D.dirname(t);
818
+ const e = await re.readFile(t, "utf-8"), i = P.dirname(t);
705
819
  let n = null;
706
820
  try {
707
821
  n = JSON.parse(e);
@@ -724,11 +838,11 @@ class We {
724
838
  }
725
839
  async _expandFileGlobs(t, e, i) {
726
840
  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}`);
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}`);
732
846
  }
733
847
  } catch (l) {
734
848
  this.debug && console.error(`[FuncSpan ConfigLoader] Error expanding glob '${n}':`, l);
@@ -741,52 +855,52 @@ class We {
741
855
  this.debug && console.warn(`[FuncSpan ConfigLoader] Invalid function pattern '${n}' (expected format: 'file.ts::functionName')`);
742
856
  continue;
743
857
  }
744
- const [a, o] = l, d = D.normalize(D.join(t, a));
858
+ const [c, o] = l, d = P.normalize(P.join(t, c));
745
859
  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}`);
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}`);
748
862
  }
749
863
  }
750
864
  async _resolveInheritance() {
751
865
  }
752
866
  _getDirectoryConfig(t) {
753
- let e = D.dirname(D.normalize(t));
867
+ let e = P.dirname(P.normalize(t));
754
868
  const i = [];
755
- for (; e && e !== D.dirname(e); ) {
869
+ for (; e && e !== P.dirname(e); ) {
756
870
  const n = this.directoryConfigs.get(e);
757
- n && i.unshift(n), e = D.dirname(e);
871
+ n && i.unshift(n), e = P.dirname(e);
758
872
  }
759
- return i.reduce((n, s) => C(n, s), {});
873
+ return i.reduce((n, s) => L(n, s), {});
760
874
  }
761
875
  }
762
- const fe = "__sf_globalConfigLoader";
763
- function ge() {
764
- return globalThis[fe] ?? null;
876
+ const ye = "__sf_globalConfigLoader";
877
+ function Se() {
878
+ return globalThis[ye] ?? null;
765
879
  }
766
- async function je(r, t) {
767
- const e = new We(r, t);
880
+ async function Xe(r, t) {
881
+ const e = new Qe(r, t);
768
882
  (function(i) {
769
- globalThis[fe] = i;
883
+ globalThis[ye] = i;
770
884
  })(e), await e.loadAllConfigs();
771
885
  }
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());
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());
775
889
  }
776
- function Je() {
777
- return ge() !== null;
890
+ function Ze() {
891
+ return Se() !== null;
778
892
  }
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) {
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) {
782
896
  if (typeof r != "string") return !1;
783
897
  const t = process.env.SF_FUNCSPAN_JSONL_FILE;
784
898
  if (t && r.includes(t)) return !0;
785
899
  const e = process.env.SF_WORKER_POOL_JSONL_FILE;
786
900
  return !(!e || !r.includes(e));
787
901
  }
788
- let se = !1;
789
- function oe(r) {
902
+ let de = !1;
903
+ function ue(r) {
790
904
  if (typeof r != "string") return !1;
791
905
  if (r === "localhost" || r === "127.0.0.1" || r === "::1") return !0;
792
906
  try {
@@ -797,8 +911,8 @@ function oe(r) {
797
911
  }
798
912
  return !1;
799
913
  }
800
- function Ze() {
801
- if (!se) try {
914
+ function it() {
915
+ if (!de) try {
802
916
  let r;
803
917
  if (typeof require > "u") return void (process.env.SF_DEBUG === "true" && console.log("[WorkerPool] Skipping dns patching in pure ESM environment (require unavailable)"));
804
918
  try {
@@ -808,231 +922,231 @@ function Ze() {
808
922
  }
809
923
  if (r.__sf_worker_pool_patched__) return;
810
924
  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") {
925
+ for (const t of ae) if (typeof r[t] == "function") {
812
926
  const e = r[t];
813
927
  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);
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);
815
929
  }, Object.defineProperty(r[t], "name", { value: t, writable: !1 });
816
930
  }
817
931
  (function(t) {
818
932
  if (!t.promises) return void (process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns.promises not available, skipping"));
819
933
  if (!t.promises.__sf_worker_pool_patched__) {
820
934
  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") {
935
+ for (const e of ae) if (typeof t.promises[e] == "function") {
822
936
  const i = t.promises[e];
823
937
  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);
938
+ return ne() ? i.apply(this, n) : ue(n[0]) ? i.apply(this, n) : we("dns", e, i, n, this);
825
939
  }, Object.defineProperty(t.promises[e], "name", { value: e, writable: !1 });
826
940
  }
827
941
  process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns.promises module patched successfully");
828
942
  }
829
- })(r), se = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns module patched successfully");
943
+ })(r), de = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns module patched successfully");
830
944
  } catch (r) {
831
945
  console.error("[WorkerPool] Error patching dns module:", r);
832
946
  }
833
947
  }
834
- let ae = !1, ce = !1, z = !1;
835
- function et() {
836
- if (z) return;
948
+ let le = !1, pe = !1, Y = !1;
949
+ function st() {
950
+ if (Y) return;
837
951
  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 {
952
+ r && console.log("[WorkerPool] Initializing worker pool patching..."), q("fs") && (r && console.log("[WorkerPool] Patching fs module..."), (function() {
953
+ if (!ce) try {
840
954
  const t = require("node:fs");
841
955
  if (t.__sf_worker_pool_patched__) return;
842
956
  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") {
957
+ for (const e of et) if (typeof t[e] == "function") {
844
958
  const i = t[e];
845
959
  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);
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);
847
961
  }, Object.defineProperty(t[e], "name", { value: e, writable: !1 });
848
962
  }
849
- ie = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] fs module patched successfully");
963
+ ce = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] fs module patched successfully");
850
964
  } catch (t) {
851
965
  console.error("[WorkerPool] Error patching fs module:", t);
852
966
  }
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 {
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 {
855
969
  const t = require("node:crypto");
856
970
  if (t.__sf_worker_pool_patched__) return;
857
971
  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") {
972
+ for (const e of tt) if (typeof t[e] == "function") {
859
973
  const i = t[e];
860
974
  t[e] = function(...n) {
861
- return typeof n[n.length - 1] == "function" ? A("crypto", e, i, n, this) : i.apply(this, n);
975
+ return typeof n[n.length - 1] == "function" ? x("crypto", e, i, n, this) : i.apply(this, n);
862
976
  }, Object.defineProperty(t[e], "name", { value: e, writable: !1 });
863
977
  }
864
- ae = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] crypto module patched successfully");
978
+ le = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] crypto module patched successfully");
865
979
  } catch (t) {
866
980
  console.error("[WorkerPool] Error patching crypto module:", t);
867
981
  }
868
- })()), k("zlib") && (r && console.log("[WorkerPool] Patching zlib module..."), (function() {
869
- if (!ce) try {
982
+ })()), q("zlib") && (r && console.log("[WorkerPool] Patching zlib module..."), (function() {
983
+ if (!pe) try {
870
984
  const t = require("node:zlib");
871
985
  if (t.__sf_worker_pool_patched__) return;
872
986
  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") {
987
+ for (const e of nt) if (typeof t[e] == "function") {
874
988
  const i = t[e];
875
989
  t[e] = function(...n) {
876
- return typeof n[n.length - 1] == "function" ? A("zlib", e, i, n, this) : i.apply(this, n);
990
+ return typeof n[n.length - 1] == "function" ? x("zlib", e, i, n, this) : i.apply(this, n);
877
991
  }, Object.defineProperty(t[e], "name", { value: e, writable: !1 });
878
992
  }
879
- ce = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] zlib module patched successfully");
993
+ pe = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] zlib module patched successfully");
880
994
  } catch (t) {
881
995
  console.error("[WorkerPool] Error patching zlib module:", t);
882
996
  }
883
- })()), z = !0, r && console.log("[WorkerPool] Worker pool patching initialized");
997
+ })()), Y = !0, r && console.log("[WorkerPool] Worker pool patching initialized");
884
998
  }
885
- function tt() {
886
- return z;
999
+ function ot() {
1000
+ return Y;
887
1001
  }
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();
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();
893
1007
  try {
894
1008
  let t, e;
895
- const i = ue(new Error().stack);
1009
+ const i = he(new Error().stack);
896
1010
  if (i) {
897
- const a = i.split(`
898
- `)[2] || "", o = a.match(/\((.+):(\d+):\d+\)/) || a.match(/at (.+):(\d+):\d+/);
1011
+ const c = i.split(`
1012
+ `)[2] || "", o = c.match(/\((.+):(\d+):\d+\)/) || c.match(/at (.+):(\d+):\d+/);
899
1013
  o && (t = o[1], e = parseInt(o[2], 10));
900
1014
  }
901
1015
  if (!r || !r.apiKey) {
902
- const a = `The required API Key is not provided: ${JSON.stringify(r)}`;
903
- console.error(a);
1016
+ const c = `The required API Key is not provided: ${JSON.stringify(r)}`;
1017
+ console.error(c);
904
1018
  }
905
- const { config: n } = Se(r);
906
- if (ve(n).catch(() => {
1019
+ const { config: n } = _e(r);
1020
+ if (Fe(n).catch(() => {
907
1021
  }), 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);
1022
+ const c = `The required config is not provided: ${JSON.stringify(n)}`;
1023
+ throw console.error(c), new Error(c);
910
1024
  }
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();
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();
919
1033
  o.patchFetch(d, p), o.patchHttp(d, p);
920
1034
  })(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");
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");
923
1037
  } finally {
924
- B = !1;
1038
+ V = !1;
925
1039
  }
926
1040
  }
927
1041
  }
928
- function gt() {
929
- return J;
1042
+ function It() {
1043
+ return Z;
930
1044
  }
931
- function ht(r, t, e, i = !1) {
932
- const n = f();
933
- new pe(n.apiKey).identify(r, t, e, i);
1045
+ function vt(r, t, e, i = !1) {
1046
+ const n = a();
1047
+ new me(n.apiKey).identify(r, t, e, i);
934
1048
  }
935
- function mt(r, t = {}, e, i = !1) {
936
- const n = f();
937
- new pe(n.apiKey).addOrUpdateMetadata(r, t, e, i);
1049
+ function $t(r, t = {}, e, i = !1) {
1050
+ const n = a();
1051
+ new me(n.apiKey).addOrUpdateMetadata(r, t, e, i);
938
1052
  }
939
- let G = null;
940
- function yt(r, t, e, i) {
1053
+ let z = null;
1054
+ function bt(r, t, e, i) {
941
1055
  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();
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();
946
1060
  if (I) {
947
- const _ = j(I);
948
- if (_) return process.env.SF_DEBUG === "true" && console.log(`[FuncSpan] Using HTTP header override for ${h}::${v}`), _;
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;
949
1063
  }
950
1064
  try {
951
- return ze(h, v);
1065
+ return Ye(h, f);
952
1066
  } catch {
953
1067
  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
1068
  }
955
1069
  })(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)));
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();
1076
+ 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)));
966
1080
  try {
967
1081
  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;
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;
975
1089
  });
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;
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;
979
1093
  } 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;
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;
982
1096
  }
983
1097
  };
984
1098
  Object.defineProperty(n, "name", { value: t, writable: !1 });
985
1099
  for (const s in r) r.hasOwnProperty(s) && (n[s] = r[s]);
986
1100
  return n;
987
1101
  }
988
- function L(r) {
989
- const t = de(), e = t?.sfDebug || !1;
1102
+ function M(r) {
1103
+ const t = fe(), e = t?.sfDebug || !1;
990
1104
  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
1105
  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
1106
  process.env.SF_FUNCSPAN_CONSOLE_OUTPUT === "true" && console.log(`
993
1107
  📊 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
1108
  const n = process.env.SF_FUNCSPAN_JSONL_FILE;
995
1109
  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 }) + `
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 }) + `
997
1111
  `;
998
- ke(s, c, "utf-8");
1112
+ Ae(s, u, "utf-8");
999
1113
  } catch (s) {
1000
1114
  console.error("[FuncSpan] Error writing to JSONL file:", s);
1001
1115
  }
1002
1116
  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");
1117
+ (z || (z = new Pe()), z).send([i]), e && console.log("[FuncSpan] Function span sent successfully");
1004
1118
  } catch (s) {
1005
1119
  e && console.error("[FuncSpan] Error sending function span:", s);
1006
1120
  }
1007
1121
  }
1008
- function St(r) {
1122
+ function _t(r) {
1009
1123
  return !!r.includes("captureFunctionSpan(") || !!r.includes("@sailfish-ai/sf-veritas") || !(!r.includes("/* @sailfish-instrumented */") && !r.includes("// @sailfish-instrumented"));
1010
1124
  }
1011
1125
  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
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
1038
1152
  };