@sailfish-ai/sf-veritas 0.2.13 → 0.2.16

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