@sailfish-ai/sf-veritas 0.2.21 → 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.
Files changed (41) hide show
  1. package/README.md +53 -0
  2. package/dist/consoleLocationTransformer-BSSB5msZ.cjs +1 -0
  3. package/dist/consoleLocationTransformer-DZu_9MDA.js +51 -0
  4. package/dist/contextManager-BsolAr_q.cjs +1 -0
  5. package/dist/{contextManager-RxrMXs5c.js → contextManager-D2ijKL-E.js} +105 -102
  6. package/dist/plugins/funcspanEsbuildPlugin.cjs +1 -1
  7. package/dist/plugins/funcspanEsbuildPlugin.mjs +20 -16
  8. package/dist/plugins/funcspanRollupPlugin.cjs +1 -1
  9. package/dist/plugins/funcspanRollupPlugin.mjs +17 -13
  10. package/dist/plugins/funcspanTscPlugin.cjs +1 -1
  11. package/dist/plugins/funcspanTscPlugin.mjs +34 -30
  12. package/dist/plugins/funcspanVitePlugin.cjs +1 -1
  13. package/dist/plugins/funcspanVitePlugin.mjs +16 -12
  14. package/dist/plugins/funcspanWebpackLoader.cjs +1 -1
  15. package/dist/plugins/funcspanWebpackLoader.mjs +55 -50
  16. package/dist/plugins/funcspanWebpackPlugin.cjs +1 -1
  17. package/dist/plugins/funcspanWebpackPlugin.mjs +1 -1
  18. package/dist/runtimeConfig-C4mv7SVM.js +484 -0
  19. package/dist/runtimeConfig-XIm4yAFB.cjs +6 -0
  20. package/dist/sf-veritas.cjs +13 -13
  21. package/dist/sf-veritas.mjs +532 -388
  22. package/dist/telemetryWorker.cjs +1 -0
  23. package/dist/types/dataTransmitter.d.ts +6 -5
  24. package/dist/types/exceptionTransmitter.d.ts +2 -1
  25. package/dist/types/networkHopTransmitter.d.ts +2 -1
  26. package/dist/types/networkRequestTransmitter.d.ts +2 -1
  27. package/dist/types/plugins/consoleLocationTransformer.d.ts +37 -0
  28. package/dist/types/requestTransmitter.d.ts +45 -0
  29. package/dist/types/requestUtils.d.ts +17 -6
  30. package/dist/types/setupConfig.d.ts +21 -0
  31. package/dist/types/sourceLocation.d.ts +19 -19
  32. package/dist/types/telemetryWorker.d.ts +1 -0
  33. package/dist/worker-pool-capture.cjs +1 -1
  34. package/dist/worker-pool-capture.mjs +1 -1
  35. package/dist/workerPoolSpanCapture-DzCJnMDA.cjs +83 -0
  36. package/dist/{workerPoolSpanCapture-DVYmzgbN.js → workerPoolSpanCapture-hyxgVqUF.js} +222 -168
  37. package/package.json +17 -1
  38. package/dist/contextManager-0D8uHQ1_.cjs +0 -1
  39. package/dist/runtimeConfig-CB57auSb.js +0 -444
  40. package/dist/runtimeConfig-sm_7bnKx.cjs +0 -9
  41. package/dist/workerPoolSpanCapture-DFnbcpkU.cjs +0 -83
@@ -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, C as V, D as ye, v as W, b as H, c as Se, d as ve, a as de } from "./contextManager-RxrMXs5c.js";
5
- import { r as It } from "./contextManager-RxrMXs5c.js";
6
- import { B as T, n as w, f as Ie, g as B, p as j, a as le, b as $e, m as R, c as A, i as Y, d as _e, e as U, t as M, F as be } from "./workerPoolSpanCapture-DVYmzgbN.js";
7
- import { h as _t, s as bt } from "./workerPoolSpanCapture-DVYmzgbN.js";
8
- import { a as Fe, C as Ne, i as b, b as De, c as ue, d as we, e as Pe } from "./runtimeConfig-CB57auSb.js";
9
- import { f as Nt, g as Dt, s as wt } from "./runtimeConfig-CB57auSb.js";
10
- import { createRequire as Ee } from "node:module";
11
- import * as Te from "fs";
12
- import { readFileSync as Ce, appendFileSync as Re } from "fs";
13
- import E from "http";
14
- import O 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 k } from "worker_threads";
20
- import { s as Et, t as Tt, a as Ct } from "./funcSpanTransformer-S_WeAt_m.js";
21
- class C extends T {
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 (!g().serviceIdentificationReceived) try {
26
+ if (!a().serviceIdentificationReceived) try {
27
27
  this.send();
28
28
  } catch (e) {
29
- g().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,31 +68,37 @@ class C extends T {
68
68
  serviceRole: $serviceRole,
69
69
  )
70
70
  }
71
- `, e = g(), 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 ke extends T {
75
+ class xe extends k {
76
76
  constructor() {
77
77
  super();
78
- y(this, "serviceIdentifier", new C());
78
+ b(this, "serviceIdentifier", new O());
79
+ b(this, "identifyStarted", !1);
79
80
  this.setOperationName("CollectMetadata");
80
81
  }
81
- async sendAppIdentifier() {
82
- this.serviceIdentifier.doSend({});
82
+ startBackgroundIdentify() {
83
+ if (this.identifyStarted) return;
84
+ this.identifyStarted = !0, this.serviceIdentifier.doSend({});
85
+ const e = setInterval(() => {
86
+ a().serviceIdentificationReceived ? clearInterval(e) : this.serviceIdentifier.doSend({});
87
+ }, 5e3);
88
+ e && typeof e == "object" && "unref" in e && e.unref();
83
89
  }
84
90
  async doSend(e, i, n, s) {
85
- this.sendAppIdentifier(), this.send(e, i, n, s);
91
+ this.startBackgroundIdentify(), this.send(e, i, n, s);
86
92
  }
87
93
  async send(e, i, n, s) {
88
94
  if (!i && !s) throw new Error('Must pass in either traits or traits_json to "add_or_update_traits"');
89
95
  let l = [];
90
96
  if (!s) {
91
- const o = Fe(i);
97
+ const o = Re(i);
92
98
  s = o.traitsJson, l = o.excludedFields;
93
99
  }
94
- const a = this.getVariables({ userId: e, traitsJson: s, excludedFields: l, override: n, library: g().packageLibraryType, version: g().version });
95
- 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);
96
102
  }
97
103
  getQuery() {
98
104
  return `
@@ -102,36 +108,42 @@ class ke extends T {
102
108
  `;
103
109
  }
104
110
  }
105
- class pe {
111
+ class me {
106
112
  constructor(t) {
107
- y(this, "metadataTransmitter");
108
- this.apiKey = t, this.metadataTransmitter = new ke();
113
+ b(this, "metadataTransmitter");
114
+ this.apiKey = t, this.metadataTransmitter = new xe();
109
115
  }
110
116
  identify(t, e, i, n = !1) {
111
117
  e || i ? this.addOrUpdateMetadata(t, e, i, n) : this.addOrUpdateMetadata(t, {}, void 0, n);
112
118
  }
113
119
  addOrUpdateMetadata(t, e = {}, i, n = !1) {
114
120
  if (!e && !i) throw new Error('Must pass in either traits or traitsJson to "addOrUpdateMetadata"');
115
- g().sfDebug && console.log(" [[DEBUG - addOrUpdateMetadata]] Starting operation"), g().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);
116
122
  }
117
123
  }
118
- class Q extends T {
124
+ class te extends k {
119
125
  constructor() {
120
126
  super();
121
- y(this, "serviceIdentifier", new C());
127
+ b(this, "serviceIdentifier", new O());
128
+ b(this, "identifyStarted", !1);
122
129
  }
123
- async sendAppIdentifier() {
124
- this.serviceIdentifier.doSend({});
130
+ startBackgroundIdentify() {
131
+ if (this.identifyStarted) return;
132
+ this.identifyStarted = !0, this.serviceIdentifier.doSend({});
133
+ const e = setInterval(() => {
134
+ a().serviceIdentificationReceived ? clearInterval(e) : this.serviceIdentifier.doSend({});
135
+ }, 5e3);
136
+ e && typeof e == "object" && "unref" in e && e.unref();
125
137
  }
126
138
  async doSend(e) {
127
- this.sendAppIdentifier(), this.send(e);
139
+ this.startBackgroundIdentify(), this.send(e);
128
140
  }
129
141
  async send(e) {
130
142
  try {
131
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 });
132
- w(this.endpoint, this.operationName, this.getQuery(), n);
144
+ C(this.endpoint, this.operationName, this.getQuery(), n);
133
145
  } catch (i) {
134
- g().sfDebug && console.error("🚨 Error in send():", i);
146
+ a().sfDebug && console.error("🚨 Error in send():", i);
135
147
  }
136
148
  }
137
149
  getQuery() {
@@ -162,11 +174,12 @@ class Q extends T {
162
174
  `;
163
175
  }
164
176
  }
165
- class Le extends T {
177
+ class Be extends k {
166
178
  constructor() {
167
179
  super();
168
- y(this, "serviceIdentifier", new C());
169
- y(this, "supplementalFields", {});
180
+ b(this, "serviceIdentifier", new O());
181
+ b(this, "supplementalFields", {});
182
+ b(this, "identifyStarted", !1);
170
183
  this.setOperationName("CollectExceptions");
171
184
  }
172
185
  setSupplementalFields(e) {
@@ -176,16 +189,21 @@ class Le extends T {
176
189
  const { isFromLocalService: e } = this.supplementalFields, i = {};
177
190
  return e !== void 0 && (i.isFromLocalService = e), i;
178
191
  }
179
- async sendAppIdentifier() {
180
- this.serviceIdentifier.doSend({});
192
+ startBackgroundIdentify() {
193
+ if (this.identifyStarted) return;
194
+ this.identifyStarted = !0, this.serviceIdentifier.doSend({});
195
+ const e = setInterval(() => {
196
+ a().serviceIdentificationReceived ? clearInterval(e) : this.serviceIdentifier.doSend({});
197
+ }, 5e3);
198
+ e && typeof e == "object" && "unref" in e && e.unref();
181
199
  }
182
200
  async doSend(e, i) {
183
- this.sendAppIdentifier(), this.send(e, i);
201
+ this.startBackgroundIdentify(), this.send(e, i);
184
202
  }
185
203
  async send(e, i) {
186
- g().sfDebug && console.log(" SENDING EXCEPTION...");
187
- const n = JSON.stringify(Ne.encode(i)), s = this.normalizedSupplementalForGraphQL(), l = this.getVariables({ exceptionMessage: e, traceJson: n, reentrancyGuardPreactive: !1, library: g().packageLibraryType, version: g().version, ...s });
188
- 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);
189
207
  }
190
208
  getQuery() {
191
209
  return `
@@ -219,56 +237,56 @@ class Le extends T {
219
237
  `;
220
238
  }
221
239
  }
222
- const ee = "getting request source code";
223
- var q = ((r) => (r.UNKNOWN = "unknown", r.ANONYMOUS = "anonymous", r.NOT_CAPTURED = "not captured", r))(q || {});
224
- const te = "http:", Ae = Ee(import.meta.url);
225
- let ne = !1;
226
- function qe() {
227
- const r = g().sfDebug;
228
- 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."));
229
247
  let t;
230
- ne = !0;
248
+ oe = !0;
231
249
  try {
232
- t = Ae("node:http"), r && b("[patchNodeHttpInbound] node:http required successfully.");
250
+ t = Ge("node:http"), r && w("[patchNodeHttpInbound] node:http required successfully.");
233
251
  } catch (n) {
234
- return void De("Failed to require node:http:", n);
252
+ return void Te("Failed to require node:http:", n);
235
253
  }
236
- 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."));
237
255
  const e = t.Server.prototype, i = e.emit;
238
- 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) {
239
- if (n !== "request") return r && b(`[patchNodeHttpInbound] Passing through event: ${n}`), i.call(this, n, ...s);
240
- 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) {
241
259
  const h = {};
242
- if (!u) return h;
243
- 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));
244
262
  return h;
245
263
  })(l?.headers), d = o["x-sf3-rid"], p = o["x-sf3-functionspancaptureoverride"];
246
- r && (b("[patchNodeHttpInbound] Intercepted request event."), b("[patchNodeHttpInbound] Inbound headers:", o), b("[patchNodeHttpInbound] Trace header:", d), b("[patchNodeHttpInbound] FuncSpan override header:", p));
247
- const c = V.getInstance();
248
- c.setTraceId(d);
249
- const f = c.getTraceId();
250
- r && b("[patchNodeHttpInbound] Context traceId set:", f);
251
- const m = () => c.runWith({ inboundHeaders: o, ...d ? { traceId: d } : {} }, () => {
252
- d && c.setTraceId(d), r && b("[patchNodeHttpInbound] Running request handler in context.");
253
- const u = () => {
254
- 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());
255
273
  };
256
- 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);
257
275
  });
258
- if (!p) return m();
276
+ if (!p) return $();
259
277
  try {
260
- return Ie.run(p, () => m());
278
+ return De.run(p, () => $());
261
279
  } catch {
262
- return m();
280
+ return $();
263
281
  }
264
- }) : r && b("[patchNodeHttpInbound] Already patched, skipping.");
282
+ }) : r && w("[patchNodeHttpInbound] Already patched, skipping.");
265
283
  }
266
- class He extends Q {
284
+ class We extends te {
267
285
  constructor() {
268
286
  super(), this.setOperationName("DomainsToNotPassHeaderTo");
269
287
  }
270
288
  async doSend(t) {
271
- this.sendAppIdentifier(), this.send(t);
289
+ this.send(t);
272
290
  }
273
291
  async send(t) {
274
292
  const e = `
@@ -284,24 +302,30 @@ class He extends Q {
284
302
  )
285
303
  }
286
304
  `, i = { apiKey: this.apiKey, serviceUuid: this.serviceUUID, domains: t };
287
- w(this.endpoint, this.operationName, e, i);
305
+ C(this.endpoint, this.operationName, e, i);
288
306
  }
289
307
  }
290
- class Me extends T {
308
+ class je extends k {
291
309
  constructor() {
292
310
  super();
293
- y(this, "serviceIdentifier", new C());
311
+ b(this, "serviceIdentifier", new O());
312
+ b(this, "identifyStarted", !1);
294
313
  this.setOperationName("CollectNetworkHops");
295
314
  }
296
- async sendAppIdentifier() {
297
- this.serviceIdentifier.doSend({});
315
+ startBackgroundIdentify() {
316
+ if (this.identifyStarted) return;
317
+ this.identifyStarted = !0, this.serviceIdentifier.doSend({});
318
+ const e = setInterval(() => {
319
+ a().serviceIdentificationReceived ? clearInterval(e) : this.serviceIdentifier.doSend({});
320
+ }, 5e3);
321
+ e && typeof e == "object" && "unref" in e && e.unref();
298
322
  }
299
323
  async doSend(e) {
300
- this.sendAppIdentifier(), this.send(e);
324
+ this.startBackgroundIdentify(), this.send(e);
301
325
  }
302
326
  async send(e) {
303
- 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 });
304
- 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);
305
329
  }
306
330
  getQuery() {
307
331
  return `
@@ -331,17 +355,23 @@ class Me extends T {
331
355
  `;
332
356
  }
333
357
  }
334
- class xe extends T {
358
+ class Ve extends k {
335
359
  constructor() {
336
360
  super();
337
- y(this, "serviceIdentifier", new C());
361
+ b(this, "serviceIdentifier", new O());
362
+ b(this, "identifyStarted", !1);
338
363
  this.setOperationName("CollectNetworkRequest");
339
364
  }
340
- async sendAppIdentifier() {
341
- this.serviceIdentifier.doSend({});
365
+ startBackgroundIdentify() {
366
+ if (this.identifyStarted) return;
367
+ this.identifyStarted = !0, this.serviceIdentifier.doSend({});
368
+ const e = setInterval(() => {
369
+ a().serviceIdentificationReceived ? clearInterval(e) : this.serviceIdentifier.doSend({});
370
+ }, 5e3);
371
+ e && typeof e == "object" && "unref" in e && e.unref();
342
372
  }
343
373
  async doSend(e) {
344
- this.sendAppIdentifier(), this.send(e);
374
+ this.startBackgroundIdentify(), this.send(e);
345
375
  }
346
376
  getQuery() {
347
377
  return `
@@ -355,28 +385,31 @@ class xe extends T {
355
385
  }
356
386
  async send(e) {
357
387
  const i = { data: { ...e } };
358
- await w(this.endpoint, this.operationName, this.getQuery(), i);
388
+ await C(this.endpoint, this.operationName, this.getQuery(), i);
359
389
  }
360
390
  }
361
- const x = [400, 403];
362
- 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 {
363
396
  constructor(t = []) {
364
- y(this, "HEADER_TRACING", "X-Sf3-Rid");
365
- y(this, "HEADER_LOG_GUARD", "reentrancy_guard_logging_preactive");
366
- y(this, "HEADER_PRINT_GUARD", "reentrancy_guard_print_preactive");
367
- y(this, "HEADER_EXCEPTION_GUARD", "reentrancy_guard_exception_preactive");
368
- y(this, "contextManager");
369
- 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) => {
370
403
  typeof e == "string" && e.trim() && this.contextManager.getExcludedDomains().add(e);
371
- }), g().sfDebug && console.log("[RequestInterceptor] Initialized with static excluded domains.");
404
+ }), a().sfDebug && console.log("[RequestInterceptor] Initialized with static excluded domains.");
372
405
  }
373
406
  extractIdsFromTraceHeader(t, e = this.HEADER_TRACING) {
374
407
  let i;
375
408
  if (t instanceof Headers) i = t.get(e) ?? void 0;
376
409
  else {
377
410
  const s = e.toLowerCase();
378
- for (const [l, a] of Object.entries(t)) if (l.toLowerCase() === s) {
379
- i = a;
411
+ for (const [l, c] of Object.entries(t)) if (l.toLowerCase() === s) {
412
+ i = c;
380
413
  break;
381
414
  }
382
415
  }
@@ -395,55 +428,55 @@ class Ge {
395
428
  if (t.includes("://")) return { originalPos: n };
396
429
  const s = t + ".map";
397
430
  try {
398
- const l = JSON.parse(Ce(s, "utf-8"));
399
- let a = (await new Ue.SourceMapConsumer(l)).originalPositionFor({ line: e, column: i });
400
- 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);
401
434
  } catch (l) {
402
- g().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);
403
436
  }
404
437
  return { originalPos: n };
405
438
  }
406
439
  captureFirstUserLines(t, e = 10, i = !1) {
407
- const n = g().sfDebug ? 10 : e, s = Error.stackTraceLimit;
440
+ const n = a().sfDebug ? 10 : e, s = Error.stackTraceLimit;
408
441
  Error.stackTraceLimit = Math.max(s, n);
409
- const l = new Error(ee);
410
- ee in Error && Error.captureStackTrace(l, this.captureFirstUserLines);
411
- 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);
412
445
  Error.stackTraceLimit = s;
413
- const o = a.split(`
446
+ const o = c.split(`
414
447
  `).slice(1), d = [];
415
448
  for (const p of o)
416
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;
417
450
  for (const p of d) {
418
- const c = this.parseStackFrame(p);
419
- c ? (async () => {
420
- const { originalPos: f } = await this.getOriginalPosition(c.filePath, c.line, c.column);
421
- if (f) {
422
- g().sfDebug && console.log("[RequestInterceptor] First user code line:", f);
423
- const m = { line: f.line?.toString() || q.UNKNOWN, column: f.column?.toString() || q.NOT_CAPTURED, name: f.name || q.NOT_CAPTURED, entrypoint: f.source, retryWithoutTraceId: i };
424
- 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($);
425
458
  }
426
- })() : g().sfDebug && console.error("Could not parse stack line:", p);
459
+ })() : a().sfDebug && console.error("Could not parse stack line:", p);
427
460
  }
428
461
  }
429
462
  addReentrancyGuardHeaders(t) {
430
463
  t.set(this.HEADER_LOG_GUARD, "true"), t.set(this.HEADER_PRINT_GUARD, "true"), t.set(this.HEADER_EXCEPTION_GUARD, "true");
431
464
  }
432
465
  shouldPropagateHeaders(t) {
433
- return !ye.some((e) => new RegExp(`^${e.replace(/\*/g, ".*")}$`).test(t));
466
+ return !be.some((e) => new RegExp(`^${e.replace(/\*/g, ".*")}$`).test(t));
434
467
  }
435
468
  addTracingHeaders(t, e) {
436
469
  const i = new URL(e).hostname, n = this.shouldPropagateHeaders(i);
437
- return n ? this.addTracingHeader(t, e) : g().sfDebug && console.error(`[RequestInterceptor] Excluded domain: ${i}`), n;
470
+ return n ? this.addTracingHeader(t, e) : a().sfDebug && console.error(`[RequestInterceptor] Excluded domain: ${i}`), n;
438
471
  }
439
472
  addTracingHeader(t, e) {
440
- const i = B();
473
+ const i = Q();
441
474
  if (i) {
442
- const a = j(i);
443
- if (a && a.sample_rate === 0) return void (g().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}`));
444
477
  }
445
- const n = this.contextManager.getOrSetSfTraceId(), s = this.contextManager.getOrSetPageVisitUUID(), l = W();
446
- t.set(this.HEADER_TRACING, `${n}/${s}/${l}`), g().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}`);
447
480
  }
448
481
  patchFetch(t, e) {
449
482
  const i = globalThis.fetch;
@@ -451,47 +484,110 @@ class Ge {
451
484
  const l = new Headers(s?.headers);
452
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);
453
486
  this.captureFirstUserLines(t);
454
- const a = Date.now();
455
- let o;
456
- typeof n == "string" || n instanceof URL ? o = n.toString() : n instanceof Request ? (o = n.url, n.headers.forEach((u, h) => {
457
- l.set(h, u);
458
- })) : g().sfDebug && console.error("[Sailfish RequestInterceptor] Invalid fetch input."), g().sfDebug && console.log("[RequestInterceptor] Fetching request to:", o);
459
- const d = new URL(o).hostname, p = new Headers(l), c = this.addTracingHeaders(l, o), f = { ...s, headers: l };
460
- 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;
461
505
  try {
462
- let u = !1;
463
- this.addTracingHeaders(p, o), m = await i(o, f), c && x.includes(m.status) ? (m = await i(o, { ...s, headers: p }), u = !0, this.captureFirstUserLines(t, 10, u)) : this.contextManager.addSupportedDomains(d);
464
- const h = Date.now();
465
- g().sfDebug && console.log(`[RequestInterceptor] Fetch completed: ${o}, Status: ${m.status}, Duration: ${h - a}ms`);
466
- const { sessionId: v, pageVisitId: I, requestId: _ } = this.extractIdsFromTraceHeader(l), S = g(), 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: f.method || "GET", retryWithoutTraceId: u, parentSpanId: H() };
467
- if (S.captureRequestHeaders) {
468
- const $ = {};
469
- l.forEach((N, P) => {
470
- $[P] = N;
471
- }), 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);
472
519
  }
473
- if (S.captureResponseHeaders) {
474
- const $ = {};
475
- m.headers.forEach((N, P) => {
476
- $[P] = N;
477
- }), 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);
478
528
  }
479
- if (S.captureRequestBody && s?.body) try {
480
- const $ = typeof s.body == "string" ? s.body : JSON.stringify(s.body);
481
- F.requestBody = $.length > S.requestBodyLimitBytes ? $.substring(0, S.requestBodyLimitBytes) + "...[truncated]" : $;
482
- } 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;
483
540
  }
484
- if (S.captureResponseBody) try {
485
- const $ = m.clone(), N = await $.text();
486
- F.responseBody = N.length > S.responseBodyLimitBytes ? N.substring(0, S.responseBodyLimitBytes) + "...[truncated]" : N;
487
- } catch {
541
+ if (_.captureResponseHeaders) {
542
+ const m = {};
543
+ h.headers.forEach((E, N) => {
544
+ m[N] = E;
545
+ }), F.responseHeaders = m;
546
+ }
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]`;
488
584
  }
489
- return e.doSend(F), m;
490
- } catch (u) {
491
- const h = Date.now();
492
- g().sfDebug && console.error(`[RequestInterceptor] Fetch failed: ${o}, Error: ${u}, Duration: ${h - a}ms`);
585
+ R || e.doSend(F);
586
+ } catch (g) {
587
+ a().sfDebug && console.error("[RequestInterceptor] Post-fetch telemetry failed (response still returned):", g);
493
588
  }
494
- } : g().sfDebug && console.error("[RequestInterceptor] Fetch not available.");
589
+ return h;
590
+ } : a().sfDebug && console.error("[RequestInterceptor] Fetch not available.");
495
591
  }
496
592
  setHeader(t, e, i) {
497
593
  t instanceof Headers ? t.set(e, i) : t[e] = i;
@@ -499,69 +595,117 @@ class Ge {
499
595
  addTracingHeadersToPlainObject(t, e) {
500
596
  const i = new URL(e).hostname, n = this.shouldPropagateHeaders(i);
501
597
  if (n) {
502
- const s = B();
598
+ const s = Q();
503
599
  if (s) {
504
- const d = j(s);
505
- if (d && d.sample_rate === 0) return g().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;
506
602
  }
507
- const l = this.contextManager.getOrSetSfTraceId(), a = this.contextManager.getOrSetPageVisitUUID(), o = W();
508
- t[this.HEADER_TRACING] = `${l}/${a}/${o}`, g().sfDebug && console.log(`[RequestInterceptor] Added tracing header for ${e}`);
509
- } else g().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}`);
510
606
  return n;
511
607
  }
512
608
  patchHttp(t, e) {
513
- if (g().sfDebug && console.log("[RequestInterceptor] Initializing HTTP/HTTPS request patch..."), !E || typeof E.request != "function") return void (g().sfDebug && console.log("[RequestInterceptor] HTTP/HTTPS not available."));
514
- const i = E.request.bind(E), n = O.request.bind(O), s = (o, d, p, c = te) => {
515
- let f, 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, $;
516
612
  if (typeof o == "string" || o instanceof URL) {
517
- const u = typeof o == "string" ? new URL(o) : o;
518
- f = { ...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;
519
- } else f = { ...o }, f.protocol || (f.protocol = c), m = typeof d == "function" ? d : void 0;
520
- return f.headers || (f.headers = {}), [f, 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, $];
521
617
  }, l = (o, d, p) => {
522
- const [c, f] = s(o, d, p, te);
618
+ const [u, y] = s(o, d, p, se);
523
619
  try {
524
- const u = `${c.protocol}//${c.hostname}`;
525
- this.addTracingHeadersToPlainObject(c.headers, u), this.captureFirstUserLines(t);
526
- } catch (u) {
527
- g().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);
528
624
  }
529
- let m = !1;
530
- return i(c, (u) => {
531
- const h = `${c.protocol}//${c.hostname}`;
532
- if (this.shouldPropagateHeaders(new URL(h).hostname) && x.includes(u.statusCode || 0)) {
533
- const S = { ...c, headers: { ...c.headers } };
534
- delete S.headers[this.HEADER_TRACING], i(S, f), 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;
535
640
  }
536
- const { sessionId: v, pageVisitId: I, requestId: _ } = this.extractIdsFromTraceHeader(c.headers);
537
- e.doSend({ apiKey: g().apiKey, requestId: _, pageVisitId: I, recordingSessionId: v, serviceUuid: g().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() }), f?.(u);
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();
656
+ }
657
+ h(f, I, !1);
538
658
  });
539
- }, a = (o, d, p) => {
540
- const [c, f] = s(o, d, p, "https:");
659
+ }, c = (o, d, p) => {
660
+ const [u, y] = s(o, d, p, "https:");
541
661
  try {
542
- const u = `${c.protocol}//${c.hostname}`;
543
- this.addTracingHeadersToPlainObject(c.headers, u), this.captureFirstUserLines(t);
544
- } catch (u) {
545
- g().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);
546
666
  }
547
- let m = !1;
548
- return n(c, (u) => {
549
- const h = `${c.protocol}//${c.hostname}`;
550
- if (this.shouldPropagateHeaders(new URL(h).hostname) && x.includes(u.statusCode || 0)) {
551
- const S = { ...c, headers: { ...c.headers } };
552
- delete S.headers[this.HEADER_TRACING], n(S, f), 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;
553
682
  }
554
- const { sessionId: v, pageVisitId: I, requestId: _ } = this.extractIdsFromTraceHeader(c.headers);
555
- e.doSend({ apiKey: g().apiKey, requestId: _, pageVisitId: I, recordingSessionId: v, serviceUuid: g().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() }), f?.(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);
556
700
  });
557
701
  };
558
- E.request = l, O.request = a, E.get = (o, d, p) => {
559
- const c = l(o, d, p);
560
- return c.end(), c;
561
- }, O.get = (o, d, p) => {
562
- const c = a(o, d, p);
563
- return c.end(), c;
564
- }, g().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.");
565
709
  }
566
710
  tryPatch(t, e) {
567
711
  try {
@@ -573,12 +717,12 @@ class Ge {
573
717
  return [...this.contextManager.getExcludedDomains()];
574
718
  }
575
719
  }
576
- class Ke extends Q {
720
+ class Je extends te {
577
721
  constructor() {
578
722
  super(), this.setOperationName("UpdateServiceDetails");
579
723
  }
580
724
  async doSend() {
581
- this.sendAppIdentifier(), this.send();
725
+ this.send();
582
726
  }
583
727
  async send() {
584
728
  const t = `
@@ -623,46 +767,46 @@ class Ke extends Q {
623
767
  serviceRole: $serviceRole,
624
768
  )
625
769
  }
626
- `, e = g(), 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 });
627
- 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);
628
772
  }
629
773
  }
630
- class We {
774
+ class Qe {
631
775
  constructor(t = [process.cwd()], e = !1) {
632
- y(this, "rootPaths");
633
- y(this, "fileConfigs", /* @__PURE__ */ new Map());
634
- y(this, "functionConfigs", /* @__PURE__ */ new Map());
635
- y(this, "directoryConfigs", /* @__PURE__ */ new Map());
636
- y(this, "hasSailfishFiles", !1);
637
- y(this, "runtimeModeEnabled", !1);
638
- 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");
639
783
  this.rootPaths = t, this.debug = e || process.env.SF_DEBUG === "true";
640
784
  }
641
785
  async loadAllConfigs() {
642
786
  this.debug && console.log("[FuncSpan ConfigLoader] Scanning for .sailfish files in:", this.rootPaths);
643
787
  const t = [];
644
- 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}`);
645
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");
646
790
  for (const e of t) await this._loadConfigFile(e);
647
791
  await this._resolveInheritance(), this.debug && console.log(`[FuncSpan ConfigLoader] Loaded ${this.fileConfigs.size} file configs, ${this.functionConfigs.size} function configs`);
648
792
  }
649
793
  getConfig(t, e) {
650
- const i = this.hasSailfishFiles ? $e() : le(), n = this._getDirectoryConfig(t), s = D.normalize(t), l = this.fileConfigs.get(s) || {};
651
- 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 = {};
652
796
  if (e) {
653
797
  const o = this.functionConfigs.get(s);
654
- o && (a = o.get(e) || {});
798
+ o && (c = o.get(e) || {});
655
799
  }
656
- return R(i, n, l, a);
800
+ return L(i, n, l, c);
657
801
  }
658
802
  hasRuntimeMode() {
659
803
  return this.runtimeModeEnabled;
660
804
  }
661
805
  async _walkDirectory(t, e) {
662
806
  try {
663
- const i = await Z.readdir(t, { withFileTypes: !0 });
807
+ const i = await re.readdir(t, { withFileTypes: !0 });
664
808
  for (const n of i) {
665
- const s = D.join(t, n.name);
809
+ const s = P.join(t, n.name);
666
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);
667
811
  }
668
812
  } catch (i) {
@@ -671,7 +815,7 @@ class We {
671
815
  }
672
816
  async _loadConfigFile(t) {
673
817
  try {
674
- 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);
675
819
  let n = null;
676
820
  try {
677
821
  n = JSON.parse(e);
@@ -694,11 +838,11 @@ class We {
694
838
  }
695
839
  async _expandFileGlobs(t, e, i) {
696
840
  for (const [n, s] of Object.entries(e)) try {
697
- const l = D.join(t, n), a = await Oe(l, { absolute: !0, nodir: !0, ignore: ["**/node_modules/**", "**/.git/**"] });
698
- this.debug && console.log(`[FuncSpan ConfigLoader] Pattern '${n}' matched ${a.length} files`);
699
- for (const o of a) {
700
- const d = D.normalize(o), p = R(i, s);
701
- 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}`);
702
846
  }
703
847
  } catch (l) {
704
848
  this.debug && console.error(`[FuncSpan ConfigLoader] Error expanding glob '${n}':`, l);
@@ -711,52 +855,52 @@ class We {
711
855
  this.debug && console.warn(`[FuncSpan ConfigLoader] Invalid function pattern '${n}' (expected format: 'file.ts::functionName')`);
712
856
  continue;
713
857
  }
714
- const [a, o] = l, d = D.normalize(D.join(t, a));
858
+ const [c, o] = l, d = P.normalize(P.join(t, c));
715
859
  this.functionConfigs.has(d) || this.functionConfigs.set(d, /* @__PURE__ */ new Map());
716
- const p = this.functionConfigs.get(d), c = R(i, s);
717
- 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}`);
718
862
  }
719
863
  }
720
864
  async _resolveInheritance() {
721
865
  }
722
866
  _getDirectoryConfig(t) {
723
- let e = D.dirname(D.normalize(t));
867
+ let e = P.dirname(P.normalize(t));
724
868
  const i = [];
725
- for (; e && e !== D.dirname(e); ) {
869
+ for (; e && e !== P.dirname(e); ) {
726
870
  const n = this.directoryConfigs.get(e);
727
- n && i.unshift(n), e = D.dirname(e);
871
+ n && i.unshift(n), e = P.dirname(e);
728
872
  }
729
- return i.reduce((n, s) => R(n, s), {});
873
+ return i.reduce((n, s) => L(n, s), {});
730
874
  }
731
875
  }
732
- const ge = "__sf_globalConfigLoader";
733
- function fe() {
734
- return globalThis[ge] ?? null;
876
+ const ye = "__sf_globalConfigLoader";
877
+ function Se() {
878
+ return globalThis[ye] ?? null;
735
879
  }
736
- async function Be(r, t) {
737
- const e = new We(r, t);
880
+ async function Xe(r, t) {
881
+ const e = new Qe(r, t);
738
882
  (function(i) {
739
- globalThis[ge] = i;
883
+ globalThis[ye] = i;
740
884
  })(e), await e.loadAllConfigs();
741
885
  }
742
- function je(r, t) {
743
- const e = fe();
744
- 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());
745
889
  }
746
- function ze() {
747
- return fe() !== null;
890
+ function Ze() {
891
+ return Se() !== null;
748
892
  }
749
- const Je = ["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"], Ve = ["pbkdf2", "randomBytes", "scrypt", "generateKeyPair"], Qe = ["gzip", "gunzip", "deflate", "inflate", "deflateRaw", "inflateRaw", "brotliCompress", "brotliDecompress"];
750
- let ie = !1;
751
- function Xe(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) {
752
896
  if (typeof r != "string") return !1;
753
897
  const t = process.env.SF_FUNCSPAN_JSONL_FILE;
754
898
  if (t && r.includes(t)) return !0;
755
899
  const e = process.env.SF_WORKER_POOL_JSONL_FILE;
756
900
  return !(!e || !r.includes(e));
757
901
  }
758
- let se = !1;
759
- function oe(r) {
902
+ let de = !1;
903
+ function ue(r) {
760
904
  if (typeof r != "string") return !1;
761
905
  if (r === "localhost" || r === "127.0.0.1" || r === "::1") return !0;
762
906
  try {
@@ -767,8 +911,8 @@ function oe(r) {
767
911
  }
768
912
  return !1;
769
913
  }
770
- function Ye() {
771
- if (!se) try {
914
+ function it() {
915
+ if (!de) try {
772
916
  let r;
773
917
  if (typeof require > "u") return void (process.env.SF_DEBUG === "true" && console.log("[WorkerPool] Skipping dns patching in pure ESM environment (require unavailable)"));
774
918
  try {
@@ -778,231 +922,231 @@ function Ye() {
778
922
  }
779
923
  if (r.__sf_worker_pool_patched__) return;
780
924
  Object.defineProperty(r, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
781
- for (const t of re) if (typeof r[t] == "function") {
925
+ for (const t of ae) if (typeof r[t] == "function") {
782
926
  const e = r[t];
783
927
  r[t] = function(...i) {
784
- 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);
785
929
  }, Object.defineProperty(r[t], "name", { value: t, writable: !1 });
786
930
  }
787
931
  (function(t) {
788
932
  if (!t.promises) return void (process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns.promises not available, skipping"));
789
933
  if (!t.promises.__sf_worker_pool_patched__) {
790
934
  Object.defineProperty(t.promises, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
791
- for (const e of re) if (typeof t.promises[e] == "function") {
935
+ for (const e of ae) if (typeof t.promises[e] == "function") {
792
936
  const i = t.promises[e];
793
937
  t.promises[e] = function(...n) {
794
- 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);
795
939
  }, Object.defineProperty(t.promises[e], "name", { value: e, writable: !1 });
796
940
  }
797
941
  process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns.promises module patched successfully");
798
942
  }
799
- })(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");
800
944
  } catch (r) {
801
945
  console.error("[WorkerPool] Error patching dns module:", r);
802
946
  }
803
947
  }
804
- let ae = !1, ce = !1, z = !1;
805
- function Ze() {
806
- if (z) return;
948
+ let le = !1, pe = !1, Y = !1;
949
+ function st() {
950
+ if (Y) return;
807
951
  const r = process.env.SF_DEBUG === "true";
808
- r && console.log("[WorkerPool] Initializing worker pool patching..."), U("fs") && (r && console.log("[WorkerPool] Patching fs module..."), (function() {
809
- 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 {
810
954
  const t = require("node:fs");
811
955
  if (t.__sf_worker_pool_patched__) return;
812
956
  Object.defineProperty(t, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
813
- for (const e of Je) if (typeof t[e] == "function") {
957
+ for (const e of et) if (typeof t[e] == "function") {
814
958
  const i = t[e];
815
959
  t[e] = function(...n) {
816
- return Xe(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);
817
961
  }, Object.defineProperty(t[e], "name", { value: e, writable: !1 });
818
962
  }
819
- 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");
820
964
  } catch (t) {
821
965
  console.error("[WorkerPool] Error patching fs module:", t);
822
966
  }
823
- })()), U("dns") && (r && console.log("[WorkerPool] Patching dns module..."), Ye()), U("crypto") && (r && console.log("[WorkerPool] Patching crypto module..."), (function() {
824
- 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 {
825
969
  const t = require("node:crypto");
826
970
  if (t.__sf_worker_pool_patched__) return;
827
971
  Object.defineProperty(t, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
828
- for (const e of Ve) if (typeof t[e] == "function") {
972
+ for (const e of tt) if (typeof t[e] == "function") {
829
973
  const i = t[e];
830
974
  t[e] = function(...n) {
831
- 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);
832
976
  }, Object.defineProperty(t[e], "name", { value: e, writable: !1 });
833
977
  }
834
- 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");
835
979
  } catch (t) {
836
980
  console.error("[WorkerPool] Error patching crypto module:", t);
837
981
  }
838
- })()), U("zlib") && (r && console.log("[WorkerPool] Patching zlib module..."), (function() {
839
- if (!ce) try {
982
+ })()), q("zlib") && (r && console.log("[WorkerPool] Patching zlib module..."), (function() {
983
+ if (!pe) try {
840
984
  const t = require("node:zlib");
841
985
  if (t.__sf_worker_pool_patched__) return;
842
986
  Object.defineProperty(t, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
843
- for (const e of Qe) if (typeof t[e] == "function") {
987
+ for (const e of nt) if (typeof t[e] == "function") {
844
988
  const i = t[e];
845
989
  t[e] = function(...n) {
846
- 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);
847
991
  }, Object.defineProperty(t[e], "name", { value: e, writable: !1 });
848
992
  }
849
- 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");
850
994
  } catch (t) {
851
995
  console.error("[WorkerPool] Error patching zlib module:", t);
852
996
  }
853
- })()), z = !0, r && console.log("[WorkerPool] Worker pool patching initialized");
997
+ })()), Y = !0, r && console.log("[WorkerPool] Worker pool patching initialized");
854
998
  }
855
- function et() {
856
- return z;
999
+ function ot() {
1000
+ return Y;
857
1001
  }
858
- let J = !1, G = !1;
859
- function pt(r) {
860
- if (G) console.warn("[setupInterceptors] ⚠️ Recursive call detected and blocked!");
861
- else if (!J) {
862
- G = !0;
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();
863
1007
  try {
864
1008
  let t, e;
865
- const i = ue(new Error().stack);
1009
+ const i = he(new Error().stack);
866
1010
  if (i) {
867
- const a = i.split(`
868
- `)[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+/);
869
1013
  o && (t = o[1], e = parseInt(o[2], 10));
870
1014
  }
871
1015
  if (!r || !r.apiKey) {
872
- const a = `The required API Key is not provided: ${JSON.stringify(r)}`;
873
- console.error(a);
1016
+ const c = `The required API Key is not provided: ${JSON.stringify(r)}`;
1017
+ console.error(c);
874
1018
  }
875
- const { config: n } = Se(r);
876
- if (ve(n).catch(() => {
1019
+ const { config: n } = _e(r);
1020
+ if (Fe(n).catch(() => {
877
1021
  }), t && (n.setupInterceptorsFile = t), e && (n.setupInterceptorsLine = e), n.sfDebug && console.log("Updated configuration after applying options:", n), !n.apiKey || !n.apiGraphqlEndpoint) {
878
- const a = `The required config is not provided: ${JSON.stringify(n)}`;
879
- 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);
880
1024
  }
881
- ze() || Be(void 0, n.sfDebug).catch((a) => {
882
- n.sfDebug && console.error("[FuncSpan] Failed to initialize config loader:", a);
883
- }), process.env.SF_WORKER_POOL_DISABLED === "true" ? n.sfDebug && console.log("[setupInterceptors] Worker pool patching DISABLED (SF_WORKER_POOL_DISABLED=true)") : et() || (Ze(), n.sfDebug && console.log("[setupInterceptors] Worker pool patching initialized (DNS tracking enabled)"));
884
- const s = new Q();
885
- s.setServiceUUID(n.serviceUUID), we(s), (function(a = []) {
886
- const o = new Ge(a);
887
- new He().doSend(o.getExcludedDomains());
888
- const d = new Me(), p = new xe();
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();
889
1033
  o.patchFetch(d, p), o.patchHttp(d, p);
890
1034
  })(n.domainsToNotPropagateHeadersTo);
891
- const l = new Le();
892
- l.setServiceUUID(n.serviceUUID), Pe(l), qe(), 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");
893
1037
  } finally {
894
- G = !1;
1038
+ V = !1;
895
1039
  }
896
1040
  }
897
1041
  }
898
- function gt() {
899
- return J;
1042
+ function It() {
1043
+ return Z;
900
1044
  }
901
- function ft(r, t, e, i = !1) {
902
- const n = g();
903
- 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);
904
1048
  }
905
- function ht(r, t = {}, e, i = !1) {
906
- const n = g();
907
- 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);
908
1052
  }
909
- let K = null;
910
- function mt(r, t, e, i) {
1053
+ let z = null;
1054
+ function bt(r, t, e, i) {
911
1055
  const n = function(...s) {
912
- const l = de(), a = l?.sfDebug || !1;
913
- a && console.log(`[FuncSpan] captureFunctionSpan wrapper called for ${e}::${t}`);
914
- const o = (function(h, v) {
915
- const I = B();
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();
916
1060
  if (I) {
917
- const _ = j(I);
918
- 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;
919
1063
  }
920
1064
  try {
921
- return je(h, v);
1065
+ return Ye(h, f);
922
1066
  } catch {
923
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 };
924
1068
  }
925
1069
  })(e, t);
926
- 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);
927
- if (o.sample_rate === 0) return a && console.log(`[FuncSpan] Skipping ${t} - sample_rate is 0.0`), r.apply(this, s);
928
- a && console.log(`[FuncSpan] Capturing function span for ${t}`);
929
- const d = V.getInstance(), p = d.getCurrentFunctionSpanId(), c = W();
930
- d.setCurrentFunctionSpanId(c);
931
- const f = process.hrtime.bigint(), m = Date.now();
932
- let u = null;
933
- o.capture_arguments && (u = {}, i.paramNames.forEach((h, v) => {
934
- v < s.length && (u[h] = s[v]);
935
- }), 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)));
936
1080
  try {
937
1081
  const h = r.apply(this, s);
938
- if (h && typeof h.then == "function") return p ? d.setCurrentFunctionSpanId(p) : d.clearCurrentFunctionSpanId(), h.then((F) => {
939
- const $ = process.hrtime.bigint(), N = Date.now(), P = Number($ - f);
940
- let X = null;
941
- 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: f.toString(), async: !0, spanId: c, parentSpanId: p, pid: process.pid, threadId: k }), F;
942
- }, (F) => {
943
- const $ = process.hrtime.bigint(), N = Date.now(), P = Number($ - f);
944
- throw L({ functionName: t, filePath: e, metadata: i, args: u, result: null, error: F?.message || String(F), duration: N - m, durationNs: P, startTimeNs: f.toString(), async: !0, spanId: c, parentSpanId: p, pid: process.pid, threadId: k }), 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;
945
1089
  });
946
- const v = process.hrtime.bigint(), I = Date.now(), _ = Number(v - f);
947
- let S = null;
948
- 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: f.toString(), async: !1, spanId: c, parentSpanId: p, pid: process.pid, threadId: k }), 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;
949
1093
  } catch (h) {
950
- const v = process.hrtime.bigint(), I = Date.now(), _ = Number(v - f);
951
- throw L({ functionName: t, filePath: e, metadata: i, args: u, result: null, error: h?.message || String(h), duration: I - m, durationNs: _, startTimeNs: f.toString(), async: !1, spanId: c, parentSpanId: p, pid: process.pid, threadId: k }), 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;
952
1096
  }
953
1097
  };
954
1098
  Object.defineProperty(n, "name", { value: t, writable: !1 });
955
1099
  for (const s in r) r.hasOwnProperty(s) && (n[s] = r[s]);
956
1100
  return n;
957
1101
  }
958
- function L(r) {
959
- const t = de(), e = t?.sfDebug || !1;
1102
+ function M(r) {
1103
+ const t = fe(), e = t?.sfDebug || !1;
960
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 });
961
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 };
962
1106
  process.env.SF_FUNCSPAN_CONSOLE_OUTPUT === "true" && console.log(`
963
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" });
964
1108
  const n = process.env.SF_FUNCSPAN_JSONL_FILE;
965
1109
  if (n) try {
966
- 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 }) + `
967
1111
  `;
968
- Re(s, c, "utf-8");
1112
+ Ae(s, u, "utf-8");
969
1113
  } catch (s) {
970
1114
  console.error("[FuncSpan] Error writing to JSONL file:", s);
971
1115
  }
972
1116
  if (e && console.log("[FuncSpan] Sending function span to transmitter:", i), process.env.SF_FUNCSPAN_SKIP_BACKEND !== "true") try {
973
- (K || (K = new be()), K).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");
974
1118
  } catch (s) {
975
1119
  e && console.error("[FuncSpan] Error sending function span:", s);
976
1120
  }
977
1121
  }
978
- function yt(r) {
1122
+ function _t(r) {
979
1123
  return !!r.includes("captureFunctionSpan(") || !!r.includes("@sailfish-ai/sf-veritas") || !(!r.includes("/* @sailfish-instrumented */") && !r.includes("// @sailfish-instrumented"));
980
1124
  }
981
1125
  export {
982
- V as ContextManager,
983
- ht as addOrUpdateMetadata,
984
- mt as captureFunctionSpan,
985
- _t as clearFuncspanOverride,
986
- H as getCurrentFunctionSpanId,
987
- le as getDefaultConfig,
988
- $e as getEnvConfig,
989
- B as getFuncspanOverride,
990
- je as getGlobalConfig,
991
- ft as identify,
992
- Be as initializeConfigLoader,
993
- Ze as initializeWorkerPoolPatching,
994
- yt as isAlreadyInstrumented,
995
- ze as isConfigLoaderInitialized,
996
- Nt as isProductionEnvironment,
997
- Dt as isRuntimeModeEnabled,
998
- gt as isSetupInterceptorsInitialized,
999
- et as isWorkerPoolInitialized,
1000
- j as parseHeaderOverride,
1001
- It as runWithContext,
1002
- bt as setFuncspanOverride,
1003
- Et as setSkipTypeScriptPlugin,
1004
- pt as setupInterceptors,
1005
- wt as shouldEnableRuntimeHooks,
1006
- Tt as transformFunctionSpans,
1007
- 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
1008
1152
  };