@sailfish-ai/sf-veritas 0.2.12 → 0.2.14

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 (32) 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-CpQ27dZD.cjs → runtimeConfig-TWzqPe1S.cjs} +7 -7
  19. package/dist/sf-veritas.cjs +37 -12
  20. package/dist/sf-veritas.mjs +546 -489
  21. package/dist/types/networkRequestTransmitter.d.ts +4 -0
  22. package/dist/types/setupConfig.d.ts +35 -0
  23. package/dist/worker-pool-capture.cjs +1 -1
  24. package/dist/worker-pool-capture.mjs +1 -1
  25. package/dist/{workerPoolSpanCapture-BYaf3NOr.js → workerPoolSpanCapture-DWS_V0Mn.js} +1 -1
  26. package/dist/workerPoolSpanCapture-Danyb3Qa.cjs +83 -0
  27. package/package.json +7 -2
  28. package/dist/contextManager-CEPhVu9T.js +0 -197
  29. package/dist/contextManager-CGINtRN5.cjs +0 -1
  30. package/dist/funcSpanTransformer-B9WWl-g1.cjs +0 -1
  31. package/dist/funcSpanTransformer-CWNEWRxq.js +0 -225
  32. package/dist/workerPoolSpanCapture-BQ3Pbkl2.cjs +0 -83
@@ -1,33 +1,33 @@
1
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";
10
- import { createRequire as Fe } from "node:module";
11
- import * as H from "fs";
12
- import { readFileSync as Ne, appendFileSync as De } from "fs";
2
+ var ge = (r, t, e) => t in r ? pe(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
+ var y = (r, t, e) => ge(r, typeof t != "symbol" ? t + "" : t, e);
4
+ import { g as u, C as V, D as fe, v as oe, b as H, c as he, a as ae } from "./contextManager-Cx03mw7l.js";
5
+ import { r as gt } from "./contextManager-Cx03mw7l.js";
6
+ import { B as T, n as E, f as me, g as ce, p as de, a as ue, b as ye, m as R, c as k, d as Se, i as O, t as M, F as Ie } from "./workerPoolSpanCapture-DWS_V0Mn.js";
7
+ import { e as ht, s as mt } from "./workerPoolSpanCapture-DWS_V0Mn.js";
8
+ import { C as ve, i as _, a as $e, h as w, b as _e, c as be } from "./runtimeConfig-DndXTWki.js";
9
+ import { d as St, e as It, s as vt } from "./runtimeConfig-DndXTWki.js";
10
+ import { createRequire as Ne } from "node:module";
11
+ import * as x from "fs";
12
+ import { readFileSync as Fe, appendFileSync as De } from "fs";
13
13
  import { s as we } from "./source-map-Cr6YkjTd.js";
14
- import * as v from "path";
14
+ import * as F from "path";
15
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 {
16
+ import { threadId as L } from "worker_threads";
17
+ import { s as _t, t as bt, a as Nt } from "./funcSpanTransformer-Byqzu4B1.js";
18
+ class U 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 Pe(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 Te extends T {
66
74
  constructor() {
67
75
  super();
68
- S(this, "serviceIdentifier", new E());
76
+ y(this, "serviceIdentifier", new U());
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)) Pe(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 `
@@ -96,36 +104,36 @@ class Ce extends D {
96
104
  `;
97
105
  }
98
106
  }
99
- class ue {
100
- constructor(e) {
101
- S(this, "metadataTransmitter");
102
- this.apiKey = e, this.metadataTransmitter = new Ce();
107
+ class le {
108
+ constructor(t) {
109
+ y(this, "metadataTransmitter");
110
+ this.apiKey = t, this.metadataTransmitter = new Te();
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 Q extends T {
113
121
  constructor() {
114
122
  super();
115
- S(this, "serviceIdentifier", new E());
123
+ y(this, "serviceIdentifier", new U());
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 Ce extends T {
160
168
  constructor() {
161
169
  super();
162
- S(this, "serviceIdentifier", new E());
163
- S(this, "supplementalFields", {});
170
+ y(this, "serviceIdentifier", new U());
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(ve.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 `
@@ -214,58 +222,58 @@ class Te extends D {
214
222
  }
215
223
  }
216
224
  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);
225
+ var q = ((r) => (r.UNKNOWN = "unknown", r.ANONYMOUS = "anonymous", r.NOT_CAPTURED = "not captured", r))(q || {});
226
+ const G = "http:", K = "https:", Ue = Ne(import.meta.url);
219
227
  let Z = !1;
220
228
  function Re() {
221
- const n = l().sfDebug;
222
- if (Z) return void (n && _("[patchNodeHttpInbound] Already installed, skipping."));
223
- let e;
229
+ const r = u().sfDebug;
230
+ if (Z) return void (r && _("[patchNodeHttpInbound] Already installed, skipping."));
231
+ let t;
224
232
  Z = !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 = Ue("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 = V.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 me.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 Oe extends Q {
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 Le extends T {
285
293
  constructor() {
286
294
  super();
287
- S(this, "serviceIdentifier", new E());
295
+ y(this, "serviceIdentifier", new U());
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 Ae extends T {
329
337
  constructor() {
330
338
  super();
331
- S(this, "serviceIdentifier", new E());
339
+ y(this, "serviceIdentifier", new U());
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,202 @@ 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
- const K = [400, 403];
363
+ const W = [400, 403];
356
364
  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;
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 = V.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
+ const o = t + ".map";
390
398
  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);
399
+ const d = JSON.parse(Fe(o, "utf-8"));
400
+ let s = (await new we.SourceMapConsumer(d)).originalPositionFor({ line: e, column: i });
401
+ s.source && (n = s);
394
402
  } catch (d) {
395
- l().sfDebug && console.error(`Could not read/parse map file at ${o}:`, d);
403
+ u().sfDebug && console.error(`Could not read/parse map file at ${o}:`, d);
396
404
  }
397
- return { originalPos: r };
405
+ return { originalPos: n };
398
406
  }
399
- captureFirstUserLines(e, t = 10, s = !1) {
400
- const r = l().sfDebug ? 10 : t, o = Error.stackTraceLimit;
401
- Error.stackTraceLimit = Math.max(o, r);
407
+ captureFirstUserLines(t, e = 10, i = !1) {
408
+ const n = u().sfDebug ? 10 : e, o = Error.stackTraceLimit;
409
+ Error.stackTraceLimit = Math.max(o, n);
402
410
  const d = new Error(Y);
403
411
  Y in Error && Error.captureStackTrace(d, this.captureFirstUserLines);
404
- const i = d.stack || "";
412
+ const s = d.stack || "";
405
413
  Error.stackTraceLimit = o;
406
- const c = i.split(`
414
+ const c = s.split(`
407
415
  `).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);
416
+ for (const l of c)
417
+ 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;
418
+ for (const l of a) {
419
+ const g = this.parseStackFrame(l);
420
+ g ? (async () => {
421
+ const { originalPos: f } = await this.getOriginalPosition(g.filePath, g.line, g.column);
422
+ if (f) {
423
+ u().sfDebug && console.log("[RequestInterceptor] First user code line:", f);
424
+ const h = { line: f.line?.toString() || q.UNKNOWN, column: f.column?.toString() || q.NOT_CAPTURED, name: f.name || q.NOT_CAPTURED, entrypoint: f.source, retryWithoutTraceId: i };
425
+ t.doSend(h);
418
426
  }
419
- })() : l().sfDebug && console.error("Could not parse stack line:", u);
427
+ })() : u().sfDebug && console.error("Could not parse stack line:", l);
420
428
  }
421
429
  }
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");
430
+ addReentrancyGuardHeaders(t) {
431
+ t.set(this.HEADER_LOG_GUARD, "true"), t.set(this.HEADER_PRINT_GUARD, "true"), t.set(this.HEADER_EXCEPTION_GUARD, "true");
424
432
  }
425
- shouldPropagateHeaders(e) {
426
- return !he.some((t) => new RegExp(`^${t.replace(/\*/g, ".*")}$`).test(e));
433
+ shouldPropagateHeaders(t) {
434
+ return !fe.some((e) => new RegExp(`^${e.replace(/\*/g, ".*")}$`).test(t));
427
435
  }
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;
436
+ addTracingHeaders(t, e) {
437
+ const i = new URL(e).hostname, n = this.shouldPropagateHeaders(i);
438
+ return n ? this.addTracingHeader(t, e) : u().sfDebug && console.error(`[RequestInterceptor] Excluded domain: ${i}`), n;
431
439
  }
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}`));
440
+ addTracingHeader(t, e) {
441
+ const i = ce();
442
+ if (i) {
443
+ const s = de(i);
444
+ 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
445
  }
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}`);
446
+ const n = this.contextManager.getOrSetSfTraceId(), o = this.contextManager.getOrSetPageVisitUUID(), d = oe();
447
+ t.set(this.HEADER_TRACING, `${n}/${o}/${d}`), u().sfDebug && console.log(`[RequestInterceptor] Added tracing header for ${e}`);
440
448
  }
441
- patchFetch(e, t) {
442
- const s = globalThis.fetch;
443
- typeof s == "function" ? globalThis.fetch = async (r, o) => {
449
+ patchFetch(t, e) {
450
+ const i = globalThis.fetch;
451
+ typeof i == "function" ? globalThis.fetch = async (n, o) => {
444
452
  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();
453
+ 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);
454
+ this.captureFirstUserLines(t);
455
+ const s = Date.now();
448
456
  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;
457
+ typeof n == "string" || n instanceof URL ? c = n.toString() : n instanceof Request ? (c = n.url, n.headers.forEach((p, m) => {
458
+ d.set(m, p);
459
+ })) : u().sfDebug && console.error("[Sailfish RequestInterceptor] Invalid fetch input."), u().sfDebug && console.log("[RequestInterceptor] Fetching request to:", c);
460
+ const a = new URL(c).hostname, l = new Headers(d), g = this.addTracingHeaders(d, c), f = { ...o, headers: d };
461
+ let h;
454
462
  try {
455
463
  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;
464
+ this.addTracingHeaders(l, c), h = await i(c, f), g && W.includes(h.status) ? (h = await i(c, { ...o, headers: l }), p = !0, this.captureFirstUserLines(t, 10, p)) : this.contextManager.addSupportedDomains(a);
465
+ const m = Date.now();
466
+ u().sfDebug && console.log(`[RequestInterceptor] Fetch completed: ${c}, Status: ${h.status}, Duration: ${m - s}ms`);
467
+ 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: H() };
468
+ if ($.captureRequestHeaders) {
469
+ const S = {};
470
+ d.forEach((N, P) => {
471
+ S[P] = N;
472
+ }), b.requestHeaders = S;
473
+ }
474
+ if ($.captureResponseHeaders) {
475
+ const S = {};
476
+ h.headers.forEach((N, P) => {
477
+ S[P] = N;
478
+ }), b.responseHeaders = S;
479
+ }
480
+ if ($.captureRequestBody && o?.body) try {
481
+ const S = typeof o.body == "string" ? o.body : JSON.stringify(o.body);
482
+ b.requestBody = S.length > $.requestBodyLimitBytes ? S.substring(0, $.requestBodyLimitBytes) + "...[truncated]" : S;
483
+ } catch {
484
+ }
485
+ if ($.captureResponseBody) try {
486
+ const S = h.clone(), N = await S.text();
487
+ b.responseBody = N.length > $.responseBodyLimitBytes ? N.substring(0, $.responseBodyLimitBytes) + "...[truncated]" : N;
488
+ } catch {
489
+ }
490
+ return e.doSend(b), h;
461
491
  } catch (p) {
462
- const g = Date.now();
463
- l().sfDebug && console.error(`[RequestInterceptor] Fetch failed: ${c}, Error: ${p}, Duration: ${g - i}ms`);
492
+ const m = Date.now();
493
+ u().sfDebug && console.error(`[RequestInterceptor] Fetch failed: ${c}, Error: ${p}, Duration: ${m - s}ms`);
464
494
  }
465
- } : l().sfDebug && console.error("[RequestInterceptor] Fetch not available.");
495
+ } : u().sfDebug && console.error("[RequestInterceptor] Fetch not available.");
466
496
  }
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;
497
+ patchHttp(t, e) {
498
+ if (u().sfDebug && console.log("[RequestInterceptor] Initializing HTTP/HTTPS request patch..."), !w || typeof w.request != "function") return void (u().sfDebug && console.log("[RequestInterceptor] HTTP/HTTPS not available."));
499
+ const i = w.request.bind(w), n = w.request.bind(w);
500
+ w.request = function(o, d) {
501
+ let s;
472
502
  try {
473
503
  if (typeof o == "string") {
474
504
  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.");
505
+ s = { protocol: a.protocol || G, hostname: a.hostname, path: a.pathname + a.search, headers: {} };
506
+ } 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));
507
+ if (s.headers) {
508
+ const a = `${s.protocol}//${s.hostname}`;
509
+ this.addTracingHeaders(s.headers, a), this.captureFirstUserLines(t);
510
+ } else u().sfDebug && console.warn("[RequestInterceptor] No headers found in HTTP request options. Skipping header addition.");
481
511
  } catch (a) {
482
- throw l().sfDebug && console.error("[RequestInterceptor] Error while processing HTTP request options:", a), a;
512
+ throw u().sfDebug && console.error("[RequestInterceptor] Error while processing HTTP request options:", a), a;
483
513
  }
484
514
  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);
515
+ return i(s, (a) => {
516
+ const l = `${s.protocol}//${s.hostname}`;
517
+ if (s.headers && this.shouldPropagateHeaders(new URL(l).hostname) && W.includes(a.statusCode || 0)) {
518
+ s.hostname;
519
+ const p = { ...s, headers: { ...s.headers } };
520
+ delete p.headers[this.HEADER_TRACING], i(p, d), c = !0, this.captureFirstUserLines(t, 10, c);
491
521
  }
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);
522
+ const { sessionId: g, pageVisitId: f, requestId: h } = this.extractIdsFromTraceHeader(s.headers);
523
+ 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: H() }), d?.(a);
494
524
  });
495
- }, b.request = function(o, d) {
496
- let i;
525
+ }, w.request = function(o, d) {
526
+ let s;
497
527
  try {
498
528
  if (typeof o == "string") {
499
529
  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.");
530
+ s = { protocol: a.protocol || K, hostname: a.hostname, path: a.pathname + a.search, headers: {} };
531
+ } else o instanceof URL ? s = { protocol: o.protocol || K, hostname: o.hostname, path: o.pathname + o.search, headers: {} } : (s = { ...o }, s.protocol || (s.protocol = K));
532
+ if (s.headers) {
533
+ const a = `${s.protocol}//${s.hostname}`;
534
+ this.addTracingHeaders(s.headers, a);
535
+ } else u().sfDebug && console.warn("[RequestInterceptor] No headers found in HTTPS request options. Skipping header addition.");
506
536
  } catch (a) {
507
- throw l().sfDebug && console.error("[RequestInterceptor] Error while processing HTTPS request options:", a), a;
537
+ throw u().sfDebug && console.error("[RequestInterceptor] Error while processing HTTPS request options:", a), a;
508
538
  }
509
539
  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);
540
+ return n(s, (a) => {
541
+ const l = `${s.protocol}//${s.hostname}`;
542
+ if (s.headers && this.shouldPropagateHeaders(new URL(l).hostname) && W.includes(a.statusCode || 0)) {
543
+ const p = { ...s, headers: { ...s.headers } };
544
+ delete p.headers[this.HEADER_TRACING], n(p, d), c = !0, this.captureFirstUserLines(t, 10, c);
515
545
  }
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);
546
+ const { sessionId: g, pageVisitId: f, requestId: h } = this.extractIdsFromTraceHeader(s.headers);
547
+ 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: H() }), d?.(a);
518
548
  });
519
- }, l().sfDebug && console.log("✅ HTTP and HTTPS request methods patched globally.");
549
+ }, u().sfDebug && console.log("✅ HTTP and HTTPS request methods patched globally.");
520
550
  }
521
- tryPatch(e, t) {
551
+ tryPatch(t, e) {
522
552
  try {
523
- require.resolve(t), e();
553
+ require.resolve(e), t();
524
554
  } catch {
525
555
  }
526
556
  }
@@ -528,7 +558,7 @@ class ke {
528
558
  return [...this.contextManager.getExcludedDomains()];
529
559
  }
530
560
  }
531
- class qe extends V {
561
+ class qe extends Q {
532
562
  constructor() {
533
563
  super(), this.setOperationName("UpdateServiceDetails");
534
564
  }
@@ -536,7 +566,7 @@ class qe extends V {
536
566
  this.sendAppIdentifier(), this.send();
537
567
  }
538
568
  async send() {
539
- const e = `
569
+ const t = `
540
570
  ${this.queryType} ${this.operationName}(
541
571
  $apiKey: String!,
542
572
  $serviceUuid: String!,
@@ -545,6 +575,14 @@ class qe extends V {
545
575
  $serviceVersion: String,
546
576
  $serviceAdditionalMetadata: JSON,
547
577
  $gitSha: String!,
578
+ $gitOrg: String,
579
+ $gitRepo: String,
580
+ $gitProvider: String,
581
+ $serviceDisplayName: String,
582
+ $infrastructureType: String,
583
+ $infrastructureDetails: JSON,
584
+ $setupInterceptorsFile: String,
585
+ $setupInterceptorsLine: Int,
548
586
  ) {
549
587
  ${this.queryName}(
550
588
  apiKey: $apiKey,
@@ -554,369 +592,388 @@ class qe extends V {
554
592
  serviceVersion: $serviceVersion,
555
593
  serviceAdditionalMetadata: $serviceAdditionalMetadata,
556
594
  gitSha: $gitSha,
595
+ gitOrg: $gitOrg,
596
+ gitRepo: $gitRepo,
597
+ gitProvider: $gitProvider,
598
+ serviceDisplayName: $serviceDisplayName,
599
+ infrastructureType: $infrastructureType,
600
+ infrastructureDetails: $infrastructureDetails,
601
+ setupInterceptorsFile: $setupInterceptorsFile,
602
+ setupInterceptorsLine: $setupInterceptorsLine,
557
603
  )
558
604
  }
559
- `, t = this.getVariables({ serviceIdentifier: l().serviceIdentifier, serviceVersion: l().serviceVersion, serviceAdditionalMetadata: l().serviceAdditionalMetadata, gitSha: l().gitSha || "" });
560
- F(this.endpoint, this.operationName, e, t);
605
+ `, 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 });
606
+ E(this.endpoint, this.operationName, t, i);
561
607
  }
562
608
  }
563
- 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";
609
+ class He {
610
+ constructor(t = [process.cwd()], e = !1) {
611
+ y(this, "rootPaths");
612
+ y(this, "fileConfigs", /* @__PURE__ */ new Map());
613
+ y(this, "functionConfigs", /* @__PURE__ */ new Map());
614
+ y(this, "directoryConfigs", /* @__PURE__ */ new Map());
615
+ y(this, "hasSailfishFiles", !1);
616
+ y(this, "runtimeModeEnabled", !1);
617
+ y(this, "debug");
618
+ this.rootPaths = t, this.debug = e || process.env.SF_DEBUG === "true";
573
619
  }
574
620
  async loadAllConfigs() {
575
621
  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);
622
+ const t = [];
623
+ for (const e of this.rootPaths) x.existsSync(e) ? await this._walkDirectory(e, t) : this.debug && console.log(`[FuncSpan ConfigLoader] Root path does not exist: ${e}`);
624
+ 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");
625
+ for (const e of t) await this._loadConfigFile(e);
580
626
  await this._resolveInheritance(), this.debug && console.log(`[FuncSpan ConfigLoader] Loaded ${this.fileConfigs.size} file configs, ${this.functionConfigs.size} function configs`);
581
627
  }
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) {
628
+ getConfig(t, e) {
629
+ const i = this.hasSailfishFiles ? ue() : ye(), n = this._getDirectoryConfig(t), o = F.normalize(t), d = this.fileConfigs.get(o) || {};
630
+ let s = {};
631
+ if (e) {
586
632
  const c = this.functionConfigs.get(o);
587
- c && (i = c.get(t) || {});
633
+ c && (s = c.get(e) || {});
588
634
  }
589
- return P(s, r, d, i);
635
+ return R(i, n, d, s);
590
636
  }
591
637
  hasRuntimeMode() {
592
638
  return this.runtimeModeEnabled;
593
639
  }
594
- async _walkDirectory(e, t) {
640
+ async _walkDirectory(t, e) {
595
641
  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);
642
+ const i = x.readdirSync(t, { withFileTypes: !0 });
643
+ for (const n of i) {
644
+ const o = F.join(t, n.name);
645
+ 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
646
  }
601
- } catch (s) {
602
- this.debug && console.error(`[FuncSpan ConfigLoader] Error walking directory ${e}:`, s);
647
+ } catch (i) {
648
+ this.debug && console.error(`[FuncSpan ConfigLoader] Error walking directory ${t}:`, i);
603
649
  }
604
650
  }
605
- async _loadConfigFile(e) {
651
+ async _loadConfigFile(t) {
606
652
  try {
607
- const t = H.readFileSync(e, "utf-8"), s = v.dirname(e);
608
- let r = null;
653
+ const e = x.readFileSync(t, "utf-8"), i = F.dirname(t);
654
+ let n = null;
609
655
  try {
610
- r = JSON.parse(t);
656
+ n = JSON.parse(e);
611
657
  } catch {
612
658
  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));
659
+ n = require("toml").parse(e);
660
+ } catch {
661
+ try {
662
+ n = require("js-yaml").load(e);
663
+ } catch (o) {
664
+ return void (this.debug && console.error(`[FuncSpan ConfigLoader] Failed to parse ${t} as JSON, TOML, or YAML:`, o));
665
+ }
616
666
  }
617
667
  }
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);
668
+ if (!n) return;
669
+ 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}`));
670
+ } catch (e) {
671
+ this.debug && console.error(`[FuncSpan ConfigLoader] Error loading ${t}:`, e);
622
672
  }
623
673
  }
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}`);
674
+ async _expandFileGlobs(t, e, i) {
675
+ for (const [n, o] of Object.entries(e)) try {
676
+ const d = F.join(t, n), s = await Ee(d, { absolute: !0, nodir: !0, ignore: ["**/node_modules/**", "**/.git/**"] });
677
+ this.debug && console.log(`[FuncSpan ConfigLoader] Pattern '${n}' matched ${s.length} files`);
678
+ for (const c of s) {
679
+ const a = F.normalize(c), l = R(i, o);
680
+ this.fileConfigs.set(a, l), this.debug && s.length <= 5 && console.log(`[FuncSpan ConfigLoader] - ${c}`);
631
681
  }
632
682
  } catch (d) {
633
- this.debug && console.error(`[FuncSpan ConfigLoader] Error expanding glob '${r}':`, d);
683
+ this.debug && console.error(`[FuncSpan ConfigLoader] Error expanding glob '${n}':`, d);
634
684
  }
635
685
  }
636
- _storeFunctionConfigs(e, t, s) {
637
- for (const [r, o] of Object.entries(t)) {
638
- const d = r.split("::");
686
+ _storeFunctionConfigs(t, e, i) {
687
+ for (const [n, o] of Object.entries(e)) {
688
+ const d = n.split("::");
639
689
  if (d.length !== 2) {
640
- this.debug && console.warn(`[FuncSpan ConfigLoader] Invalid function pattern '${r}' (expected format: 'file.ts::functionName')`);
690
+ this.debug && console.warn(`[FuncSpan ConfigLoader] Invalid function pattern '${n}' (expected format: 'file.ts::functionName')`);
641
691
  continue;
642
692
  }
643
- const [i, c] = d, a = v.normalize(v.join(e, i));
693
+ const [s, c] = d, a = F.normalize(F.join(t, s));
644
694
  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}`);
695
+ const l = this.functionConfigs.get(a), g = R(i, o);
696
+ l.set(c, g), this.debug && console.log(`[FuncSpan ConfigLoader] Function config: ${a}::${c}`);
647
697
  }
648
698
  }
649
699
  async _resolveInheritance() {
650
700
  }
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);
701
+ _getDirectoryConfig(t) {
702
+ let e = F.dirname(F.normalize(t));
703
+ const i = [];
704
+ for (; e && e !== F.dirname(e); ) {
705
+ const n = this.directoryConfigs.get(e);
706
+ n && i.unshift(n), e = F.dirname(e);
657
707
  }
658
- return s.reduce((r, o) => P(r, o), {});
708
+ return i.reduce((n, o) => R(n, o), {});
659
709
  }
660
710
  }
661
- let w = null;
662
- async function He(n, e) {
663
- w = new Me(n, e), await w.loadAllConfigs();
711
+ let C = null;
712
+ async function Me(r, t) {
713
+ C = new He(r, t), await C.loadAllConfigs();
664
714
  }
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());
715
+ function xe(r, t) {
716
+ return C ? C.getConfig(r, t) : (process.env.SF_DEBUG === "true" && console.log("[FuncSpan ConfigLoader] Config loader not initialized, using env config for worker process"), ue());
667
717
  }
668
718
  function Ge() {
669
- return w !== null;
719
+ return C !== null;
670
720
  }
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"];
721
+ 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"], Be = ["gzip", "gunzip", "deflate", "inflate", "deflateRaw", "inflateRaw", "brotliCompress", "brotliDecompress"];
672
722
  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));
723
+ function ze(r) {
724
+ if (typeof r != "string") return !1;
725
+ const t = process.env.SF_FUNCSPAN_JSONL_FILE;
726
+ if (t && r.includes(t)) return !0;
727
+ const e = process.env.SF_WORKER_POOL_JSONL_FILE;
728
+ return !(!e || !r.includes(e));
679
729
  }
680
730
  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;
731
+ function re(r) {
732
+ if (typeof r != "string") return !1;
733
+ if (r === "localhost" || r === "127.0.0.1" || r === "::1") return !0;
684
734
  try {
685
- const e = process.env.API_GRAPHQL_ENDPOINT;
686
- if (e && n === new URL(e).hostname)
735
+ const t = process.env.API_GRAPHQL_ENDPOINT;
736
+ if (t && r === new URL(t).hostname)
687
737
  return !0;
688
738
  } catch {
689
739
  }
690
740
  return !1;
691
741
  }
692
- function Be() {
742
+ function Je() {
693
743
  if (!ne) try {
694
- let n;
744
+ let r;
695
745
  if (typeof require > "u") return void (process.env.SF_DEBUG === "true" && console.log("[WorkerPool] Skipping dns patching in pure ESM environment (require unavailable)"));
696
746
  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));
747
+ r = require("node:dns");
748
+ } catch (t) {
749
+ return void (process.env.SF_DEBUG === "true" && console.log("[WorkerPool] Failed to require dns module:", t));
700
750
  }
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 });
751
+ if (r.__sf_worker_pool_patched__) return;
752
+ Object.defineProperty(r, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
753
+ for (const t of ee) if (typeof r[t] == "function") {
754
+ const e = r[t];
755
+ r[t] = function(...i) {
756
+ return re(i[0]) ? e.apply(this, i) : typeof i[i.length - 1] == "function" ? k("dns", t, e, i, this) : e.apply(this, i);
757
+ }, Object.defineProperty(r[t], "name", { value: t, writable: !1 });
708
758
  }
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 });
759
+ (function(t) {
760
+ if (!t.promises) return void (process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns.promises not available, skipping"));
761
+ if (!t.promises.__sf_worker_pool_patched__) {
762
+ Object.defineProperty(t.promises, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
763
+ for (const e of ee) if (typeof t.promises[e] == "function") {
764
+ const i = t.promises[e];
765
+ t.promises[e] = function(...n) {
766
+ return re(n[0]) ? i.apply(this, n) : Se("dns", e, i, n, this);
767
+ }, Object.defineProperty(t.promises[e], "name", { value: e, writable: !1 });
718
768
  }
719
769
  process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns.promises module patched successfully");
720
770
  }
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);
771
+ })(r), ne = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns module patched successfully");
772
+ } catch (r) {
773
+ console.error("[WorkerPool] Error patching dns module:", r);
724
774
  }
725
775
  }
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() {
776
+ let ie = !1, se = !1, J = !1;
777
+ function je() {
778
+ if (J) return;
779
+ const r = process.env.SF_DEBUG === "true";
780
+ r && console.log("[WorkerPool] Initializing worker pool patching..."), O("fs") && (r && console.log("[WorkerPool] Patching fs module..."), (function() {
731
781
  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 });
782
+ const t = require("node:fs");
783
+ if (t.__sf_worker_pool_patched__) return;
784
+ Object.defineProperty(t, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
785
+ for (const e of Ke) if (typeof t[e] == "function") {
786
+ const i = t[e];
787
+ t[e] = function(...n) {
788
+ return ze(n[0]) ? i.apply(this, n) : typeof n[n.length - 1] == "function" ? k("fs", e, i, n, this) : i.apply(this, n);
789
+ }, Object.defineProperty(t[e], "name", { value: e, writable: !1 });
740
790
  }
741
791
  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);
792
+ } catch (t) {
793
+ console.error("[WorkerPool] Error patching fs module:", t);
744
794
  }
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 });
795
+ })()), O("dns") && (r && console.log("[WorkerPool] Patching dns module..."), Je()), O("crypto") && (r && console.log("[WorkerPool] Patching crypto module..."), (function() {
796
+ if (!ie) try {
797
+ const t = require("node:crypto");
798
+ if (t.__sf_worker_pool_patched__) return;
799
+ Object.defineProperty(t, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
800
+ for (const e of We) if (typeof t[e] == "function") {
801
+ const i = t[e];
802
+ t[e] = function(...n) {
803
+ return typeof n[n.length - 1] == "function" ? k("crypto", e, i, n, this) : i.apply(this, n);
804
+ }, Object.defineProperty(t[e], "name", { value: e, writable: !1 });
755
805
  }
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);
806
+ ie = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] crypto module patched successfully");
807
+ } catch (t) {
808
+ console.error("[WorkerPool] Error patching crypto module:", t);
759
809
  }
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 });
810
+ })()), O("zlib") && (r && console.log("[WorkerPool] Patching zlib module..."), (function() {
811
+ if (!se) try {
812
+ const t = require("node:zlib");
813
+ if (t.__sf_worker_pool_patched__) return;
814
+ Object.defineProperty(t, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
815
+ for (const e of Be) if (typeof t[e] == "function") {
816
+ const i = t[e];
817
+ t[e] = function(...n) {
818
+ return typeof n[n.length - 1] == "function" ? k("zlib", e, i, n, this) : i.apply(this, n);
819
+ }, Object.defineProperty(t[e], "name", { value: e, writable: !1 });
770
820
  }
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);
821
+ se = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] zlib module patched successfully");
822
+ } catch (t) {
823
+ console.error("[WorkerPool] Error patching zlib module:", t);
774
824
  }
775
- })()), j = !0, n && console.log("[WorkerPool] Worker pool patching initialized");
825
+ })()), J = !0, r && console.log("[WorkerPool] Worker pool patching initialized");
776
826
  }
777
827
  function Ve() {
778
- return j;
828
+ return J;
779
829
  }
780
- let B = !1, W = !1;
781
- function ot(n) {
782
- if (W) console.warn("[setupInterceptors] ⚠️ Recursive call detected and blocked!");
783
- else if (!B) {
784
- W = !0;
830
+ let j = !1, B = !1;
831
+ function st(r) {
832
+ if (B) console.warn("[setupInterceptors] ⚠️ Recursive call detected and blocked!");
833
+ else if (!j) {
834
+ B = !0;
785
835
  try {
786
- if (!n || !n.apiKey) {
787
- const r = `The required API Key is not provided: ${JSON.stringify(n)}`;
788
- console.error(r);
836
+ let t, e;
837
+ const i = new Error().stack;
838
+ if (i) {
839
+ const s = i.split(`
840
+ `)[2] || "", c = s.match(/\((.+):(\d+):\d+\)/) || s.match(/at (.+):(\d+):\d+/);
841
+ c && (t = c[1], e = parseInt(c[2], 10));
842
+ }
843
+ if (!r || !r.apiKey) {
844
+ const s = `The required API Key is not provided: ${JSON.stringify(r)}`;
845
+ console.error(s);
789
846
  }
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);
847
+ const { config: n } = he(r);
848
+ if (t && (n.setupInterceptorsFile = t), e && (n.setupInterceptorsLine = e), n.sfDebug && console.log("Updated configuration after applying options:", n), !n.apiKey || !n.apiGraphqlEndpoint) {
849
+ const s = `The required config is not provided: ${JSON.stringify(n)}`;
850
+ throw console.error(s), new Error(s);
794
851
  }
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");
852
+ Ge() || Me(void 0, n.sfDebug).catch((s) => {
853
+ n.sfDebug && console.error("[FuncSpan] Failed to initialize config loader:", s);
854
+ }), process.env.SF_WORKER_POOL_DISABLED === "true" ? n.sfDebug && console.log("[setupInterceptors] Worker pool patching DISABLED (SF_WORKER_POOL_DISABLED=true)") : Ve() || (je(), n.sfDebug && console.log("[setupInterceptors] Worker pool patching initialized (DNS tracking enabled)"));
855
+ const o = new Q();
856
+ o.setServiceUUID(n.serviceUUID), _e(o), (function(s = []) {
857
+ const c = new ke(s);
858
+ new Oe().doSend(c.getExcludedDomains());
859
+ const a = new Le(), l = new Ae();
860
+ c.patchFetch(a, l), c.patchHttp(a, l);
861
+ })(n.domainsToNotPropagateHeadersTo);
862
+ const d = new Ce();
863
+ d.setServiceUUID(n.serviceUUID), be(d), Re(), new qe().send(), j = !0, n.sfDebug && console.log("[setupInterceptors] ✅ Initialization complete");
807
864
  } finally {
808
- W = !1;
865
+ B = !1;
809
866
  }
810
867
  }
811
868
  }
812
- function it() {
813
- return B;
869
+ function ot() {
870
+ return j;
814
871
  }
815
- function at(n, e, t, s = !1) {
816
- const r = l();
817
- new ue(r.apiKey).identify(n, e, t, s);
872
+ function at(r, t, e, i = !1) {
873
+ const n = u();
874
+ new le(n.apiKey).identify(r, t, e, i);
818
875
  }
819
- function ct(n, e = {}, t, s = !1) {
820
- const r = l();
821
- new ue(r.apiKey).addOrUpdateMetadata(n, e, t, s);
876
+ function ct(r, t = {}, e, i = !1) {
877
+ const n = u();
878
+ new le(n.apiKey).addOrUpdateMetadata(r, t, e, i);
822
879
  }
823
880
  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}`), $;
881
+ function dt(r, t, e, i) {
882
+ const n = function(...o) {
883
+ const d = ae(), s = d?.sfDebug || !1;
884
+ s && console.log(`[FuncSpan] captureFunctionSpan wrapper called for ${e}::${t}`);
885
+ const c = (function(m, I) {
886
+ const v = ce();
887
+ if (v) {
888
+ const D = de(v);
889
+ if (D) return process.env.SF_DEBUG === "true" && console.log(`[FuncSpan] Using HTTP header override for ${m}::${I}`), D;
833
890
  }
834
891
  try {
835
- return xe(g, y);
892
+ return xe(m, I);
836
893
  } catch {
837
894
  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
895
  }
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();
896
+ })(e, t);
897
+ 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);
898
+ if (c.sample_rate === 0) return s && console.log(`[FuncSpan] Skipping ${t} - sample_rate is 0.0`), r.apply(this, o);
899
+ s && console.log(`[FuncSpan] Capturing function span for ${t}`);
900
+ const a = V.getInstance(), l = a.getCurrentFunctionSpanId(), g = oe();
901
+ a.setCurrentFunctionSpanId(g);
902
+ const f = process.hrtime.bigint(), h = Date.now();
846
903
  let p = null;
847
- c.capture_arguments && (p = {}, s.paramNames.forEach((g, y) => {
848
- y < o.length && (p[g] = o[y]);
904
+ c.capture_arguments && (p = {}, i.paramNames.forEach((m, I) => {
905
+ I < o.length && (p[m] = o[I]);
849
906
  }), p && c.arg_limit_mb > 0 && (p = M(p, c.arg_limit_mb)));
850
907
  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);
908
+ const m = r.apply(this, o);
909
+ if (m && typeof m.then == "function") return l ? a.setCurrentFunctionSpanId(l) : a.clearCurrentFunctionSpanId(), m.then((b) => {
910
+ const S = process.hrtime.bigint(), N = Date.now(), P = Number(S - f);
854
911
  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;
912
+ return c.capture_return_value && c.return_limit_mb > 0 && (X = M(b, c.return_limit_mb)), A({ functionName: t, filePath: e, metadata: i, args: p, result: X, error: null, duration: N - h, durationNs: P, startTimeNs: f.toString(), async: !0, spanId: g, parentSpanId: l, pid: process.pid, threadId: L }), b;
913
+ }, (b) => {
914
+ const S = process.hrtime.bigint(), N = Date.now(), P = Number(S - f);
915
+ throw A({ functionName: t, filePath: e, metadata: i, args: p, result: null, error: b?.message || String(b), duration: N - h, durationNs: P, startTimeNs: f.toString(), async: !0, spanId: g, parentSpanId: l, pid: process.pid, threadId: L }), b;
859
916
  });
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;
917
+ const I = process.hrtime.bigint(), v = Date.now(), D = Number(I - f);
918
+ let $ = null;
919
+ return c.capture_return_value && c.return_limit_mb > 0 && ($ = M(m, c.return_limit_mb)), A({ 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: L }), l ? a.setCurrentFunctionSpanId(l) : a.clearCurrentFunctionSpanId(), m;
920
+ } catch (m) {
921
+ const I = process.hrtime.bigint(), v = Date.now(), D = Number(I - f);
922
+ throw A({ 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: L }), l ? a.setCurrentFunctionSpanId(l) : a.clearCurrentFunctionSpanId(), m;
866
923
  }
867
924
  };
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;
925
+ Object.defineProperty(n, "name", { value: t, writable: !1 });
926
+ for (const o in r) r.hasOwnProperty(o) && (n[o] = r[o]);
927
+ return n;
871
928
  }
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 };
929
+ function A(r) {
930
+ const t = ae(), e = t?.sfDebug || !1;
931
+ 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 });
932
+ 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
933
  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 }) + `
934
+ 📊 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" });
935
+ const n = process.env.SF_FUNCSPAN_JSONL_FILE;
936
+ if (n) try {
937
+ 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
938
  `;
882
- De(o, f, "utf-8");
939
+ De(o, g, "utf-8");
883
940
  } catch (o) {
884
941
  console.error("[FuncSpan] Error writing to JSONL file:", o);
885
942
  }
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");
943
+ if (e && console.log("[FuncSpan] Sending function span to transmitter:", i), process.env.SF_FUNCSPAN_SKIP_BACKEND !== "true") try {
944
+ (z || (z = new Ie()), z).send([i]), e && console.log("[FuncSpan] Function span sent successfully");
888
945
  } catch (o) {
889
- t && console.error("[FuncSpan] Error sending function span:", o);
946
+ e && console.error("[FuncSpan] Error sending function span:", o);
890
947
  }
891
948
  }
892
- function lt(n) {
893
- return !!n.includes("captureFunctionSpan(") || !!n.includes("@sailfish-ai/sf-veritas") || !(!n.includes("/* @sailfish-instrumented */") && !n.includes("// @sailfish-instrumented"));
949
+ function ut(r) {
950
+ return !!r.includes("captureFunctionSpan(") || !!r.includes("@sailfish-ai/sf-veritas") || !(!r.includes("/* @sailfish-instrumented */") && !r.includes("// @sailfish-instrumented"));
894
951
  }
895
952
  export {
896
- J as ContextManager,
953
+ V as ContextManager,
897
954
  ct as addOrUpdateMetadata,
898
955
  dt as captureFunctionSpan,
899
- gt as clearFuncspanOverride,
900
- q as getCurrentFunctionSpanId,
901
- Se as getDefaultConfig,
902
- le as getEnvConfig,
956
+ ht as clearFuncspanOverride,
957
+ H as getCurrentFunctionSpanId,
958
+ ye as getDefaultConfig,
959
+ ue as getEnvConfig,
903
960
  ce as getFuncspanOverride,
904
961
  xe as getGlobalConfig,
905
962
  at as identify,
906
- He as initializeConfigLoader,
907
- Je as initializeWorkerPoolPatching,
908
- lt as isAlreadyInstrumented,
963
+ Me as initializeConfigLoader,
964
+ je as initializeWorkerPoolPatching,
965
+ ut as isAlreadyInstrumented,
909
966
  Ge as isConfigLoaderInitialized,
910
- yt as isProductionEnvironment,
967
+ St as isProductionEnvironment,
911
968
  It as isRuntimeModeEnabled,
912
- it as isSetupInterceptorsInitialized,
969
+ ot as isSetupInterceptorsInitialized,
913
970
  Ve as isWorkerPoolInitialized,
914
971
  de as parseHeaderOverride,
915
- ft as runWithContext,
972
+ gt as runWithContext,
916
973
  mt as setFuncspanOverride,
917
- $t as setSkipTypeScriptPlugin,
918
- ot as setupInterceptors,
919
- _t as shouldEnableRuntimeHooks,
974
+ _t as setSkipTypeScriptPlugin,
975
+ st as setupInterceptors,
976
+ vt as shouldEnableRuntimeHooks,
920
977
  bt as transformFunctionSpans,
921
- Ft as transformFunctionSpansSync
978
+ Nt as transformFunctionSpansSync
922
979
  };