@sailfish-ai/sf-veritas 0.2.3 → 0.2.5

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 (37) hide show
  1. package/README.md +120 -0
  2. package/dist/funcSpanTransformer-TjdooSrw.cjs +1 -0
  3. package/dist/funcSpanTransformer-sqmZLAcs.js +750 -0
  4. package/dist/plugins/funcspanEsbuildPlugin.cjs +1 -1
  5. package/dist/plugins/funcspanEsbuildPlugin.mjs +1 -1
  6. package/dist/plugins/funcspanRollupPlugin.cjs +1 -1
  7. package/dist/plugins/funcspanRollupPlugin.mjs +1 -1
  8. package/dist/plugins/funcspanTscPlugin.cjs +1 -1
  9. package/dist/plugins/funcspanTscPlugin.mjs +1 -1
  10. package/dist/plugins/funcspanVitePlugin.cjs +1 -1
  11. package/dist/plugins/funcspanVitePlugin.mjs +1 -1
  12. package/dist/plugins/funcspanWebpackLoader.cjs +1 -1
  13. package/dist/plugins/funcspanWebpackLoader.mjs +1 -1
  14. package/dist/plugins/funcspanWebpackPlugin.cjs +1 -1
  15. package/dist/plugins/funcspanWebpackPlugin.mjs +19 -17
  16. package/dist/runtime/register.cjs +1 -0
  17. package/dist/runtime/register.mjs +27 -0
  18. package/dist/sf-veritas.cjs +61 -15
  19. package/dist/sf-veritas.mjs +1064 -622
  20. package/dist/types/functionSpanTransmitter.d.ts +15 -1
  21. package/dist/types/index.d.ts +2 -0
  22. package/dist/types/patches/workerPool/argumentCapture.d.ts +47 -0
  23. package/dist/types/patches/workerPool/index.d.ts +19 -0
  24. package/dist/types/patches/workerPool/patchCrypto.d.ts +9 -0
  25. package/dist/types/patches/workerPool/patchDns.d.ts +10 -0
  26. package/dist/types/patches/workerPool/patchFs.d.ts +9 -0
  27. package/dist/types/patches/workerPool/patchZlib.d.ts +9 -0
  28. package/dist/types/patches/workerPool/workerPoolTypes.d.ts +70 -0
  29. package/dist/types/requestUtils.d.ts +1 -0
  30. package/dist/types/runtime/register.d.ts +56 -0
  31. package/dist/types/workerPoolConfig.d.ts +22 -0
  32. package/dist/types/workerPoolSpanCapture.d.ts +36 -0
  33. package/package.json +12 -1
  34. package/dist/funcSpanTransformer-CTddGtUV.cjs +0 -1
  35. package/dist/funcSpanTransformer-coYDqcrs.js +0 -136
  36. package/dist/source-map-Cr6YkjTd.js +0 -631
  37. package/dist/source-map-rHHEdpre.cjs +0 -1
@@ -1,32 +1,34 @@
1
- var Se = Object.defineProperty;
2
- var Ze = (o, e, t) => e in o ? Se(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
3
- var C = (o, e, t) => Ze(o, typeof e != "symbol" ? e + "" : e, t);
4
- import { AsyncLocalStorage as ie } from "async_hooks";
5
- import * as k from "fs";
6
- import { readFileSync as pe } from "fs";
7
- import { s as he } from "./source-map-Cr6YkjTd.js";
8
- import { Worker as Ge } from "worker_threads";
9
- import * as v from "path";
10
- import { glob as ve } from "glob";
11
- const Z = [];
12
- for (let o = 0; o < 256; ++o) Z.push((o + 256).toString(16).slice(1));
13
- let O;
14
- const Ne = new Uint8Array(16), re = { randomUUID: typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto) };
15
- function R(o, e, t) {
16
- if (re.randomUUID && !o) return re.randomUUID();
17
- const n = (o = o || {}).random ?? o.rng?.() ?? (function() {
18
- if (!O) {
1
+ var Pe = Object.defineProperty;
2
+ var ze = (n, e, t) => e in n ? Pe(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
+ var C = (n, e, t) => ze(n, typeof e != "symbol" ? e + "" : e, t);
4
+ import { AsyncLocalStorage as pe, AsyncResource as Oe } from "async_hooks";
5
+ import * as te from "fs";
6
+ import { readFileSync as Re, appendFileSync as Te } from "fs";
7
+ import { s as He } from "./funcSpanTransformer-sqmZLAcs.js";
8
+ import { t as Xt } from "./funcSpanTransformer-sqmZLAcs.js";
9
+ import { Worker as xe, threadId as T } from "worker_threads";
10
+ import { createRequire as Me } from "node:module";
11
+ import * as G from "path";
12
+ import { glob as je } from "glob";
13
+ const N = [];
14
+ for (let n = 0; n < 256; ++n) N.push((n + 256).toString(16).slice(1));
15
+ let ne;
16
+ const Qe = new Uint8Array(16), fe = { randomUUID: typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto) };
17
+ function w(n, e, t) {
18
+ if (fe.randomUUID && !n) return fe.randomUUID();
19
+ const s = (n = n || {}).random ?? n.rng?.() ?? (function() {
20
+ if (!ne) {
19
21
  if (typeof crypto > "u" || !crypto.getRandomValues) throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
20
- O = crypto.getRandomValues.bind(crypto);
22
+ ne = crypto.getRandomValues.bind(crypto);
21
23
  }
22
- return O(Ne);
24
+ return ne(Qe);
23
25
  })();
24
- if (n.length < 16) throw new Error("Random bytes length must be >= 16");
25
- return n[6] = 15 & n[6] | 64, n[8] = 63 & n[8] | 128, (function(i, s = 0) {
26
- return (Z[i[s + 0]] + Z[i[s + 1]] + Z[i[s + 2]] + Z[i[s + 3]] + "-" + Z[i[s + 4]] + Z[i[s + 5]] + "-" + Z[i[s + 6]] + Z[i[s + 7]] + "-" + Z[i[s + 8]] + Z[i[s + 9]] + "-" + Z[i[s + 10]] + Z[i[s + 11]] + Z[i[s + 12]] + Z[i[s + 13]] + Z[i[s + 14]] + Z[i[s + 15]]).toLowerCase();
27
- })(n);
26
+ if (s.length < 16) throw new Error("Random bytes length must be >= 16");
27
+ return s[6] = 15 & s[6] | 64, s[8] = 63 & s[8] | 128, (function(r, a = 0) {
28
+ return (N[r[a + 0]] + N[r[a + 1]] + N[r[a + 2]] + N[r[a + 3]] + "-" + N[r[a + 4]] + N[r[a + 5]] + "-" + N[r[a + 6]] + N[r[a + 7]] + "-" + N[r[a + 8]] + N[r[a + 9]] + "-" + N[r[a + 10]] + N[r[a + 11]] + N[r[a + 12]] + N[r[a + 13]] + N[r[a + 14]] + N[r[a + 15]]).toLowerCase();
29
+ })(s);
28
30
  }
29
- class Be {
31
+ class qe {
30
32
  constructor(e) {
31
33
  C(this, "apiKey");
32
34
  C(this, "apiGraphqlEndpoint");
@@ -48,7 +50,7 @@ class Be {
48
50
  C(this, "version");
49
51
  C(this, "gitSha");
50
52
  C(this, "_serviceIdentificationReceived", !1);
51
- this.apiKey = e.apiKey, this.apiGraphqlEndpoint = e?.apiGraphqlEndpoint || process.env.SAILFISH_GRAPHQL_ENDPOINT || "https://api-service.sailfishqa.com/graphql/", this.sfDebug = e?.debug === !0 || process.env.SF_DEBUG === "true", this.serviceIdentifier = e?.serviceIdentifier || process.env.SERVICE_IDENTIFIER, this.serviceUUID = R(), this.serviceVersion = e?.serviceVersion || process.env.SERVICE_VERSION, this.gitSha = e?.gitSha || process.env.GIT_SHA || process.env.VERCEL_GIT_COMMIT_SHA, this.serviceAdditionalMetadata = e?.serviceAdditionalMetadata || {}, this.profilingModeEnabled = e?.profilingModeEnabled ?? !1, this.profilingMaxDepth = e?.profilingMaxDepth ?? 5, this.profilingMaxVariableSizeKb = e?.profilingMaxVariableSizeKb ?? 25, this.domainsToNotPropagateHeadersTo = e?.domainsToNotPropagateHeadersTo || [], this.nodeModulesToCollectLocalVariablesOn = e?.nodeModulesToCollectLocalVariablesOn || ["_all_"], this.printConfigurationStatuses = process.env.PRINT_CONFIGURATION_STATUSES || "true", this.logLevel = process.env.LOG_LEVEL || "INFO", this.stackDepthLocals = process.env.SAILFISH_EXCEPTION_STACK_DEPTH_LOCALS !== void 0 ? parseInt(process.env.SAILFISH_EXCEPTION_STACK_DEPTH_LOCALS, 10) : 5, isNaN(this.stackDepthLocals) && (this.stackDepthLocals = -1), this.stackDepthCodeTraceDepth = process.env.SAILFISH_EXCEPTION_STACK_DEPTH_CODE_TRACE_DEPTH !== void 0 ? parseInt(process.env.SAILFISH_EXCEPTION_STACK_DEPTH_CODE_TRACE_DEPTH, 10) : -1, isNaN(this.stackDepthCodeTraceDepth) && (this.stackDepthCodeTraceDepth = -1), this.packageLibraryType = "JS/TS BACKEND", this.version = this.getPackageVersion();
53
+ this.apiKey = e.apiKey, this.apiGraphqlEndpoint = e?.apiGraphqlEndpoint || process.env.SAILFISH_GRAPHQL_ENDPOINT || "https://api-service.sailfishqa.com/graphql/", this.sfDebug = e?.debug === !0 || process.env.SF_DEBUG === "true", this.serviceIdentifier = e?.serviceIdentifier || process.env.SERVICE_IDENTIFIER, this.serviceUUID = w(), this.serviceVersion = e?.serviceVersion || process.env.SERVICE_VERSION, this.gitSha = e?.gitSha || process.env.GIT_SHA || process.env.VERCEL_GIT_COMMIT_SHA, this.serviceAdditionalMetadata = e?.serviceAdditionalMetadata || {}, this.profilingModeEnabled = e?.profilingModeEnabled ?? !1, this.profilingMaxDepth = e?.profilingMaxDepth ?? 5, this.profilingMaxVariableSizeKb = e?.profilingMaxVariableSizeKb ?? 25, this.domainsToNotPropagateHeadersTo = e?.domainsToNotPropagateHeadersTo || [], this.nodeModulesToCollectLocalVariablesOn = e?.nodeModulesToCollectLocalVariablesOn || ["_all_"], this.printConfigurationStatuses = process.env.PRINT_CONFIGURATION_STATUSES || "true", this.logLevel = process.env.LOG_LEVEL || "INFO", this.stackDepthLocals = process.env.SAILFISH_EXCEPTION_STACK_DEPTH_LOCALS !== void 0 ? parseInt(process.env.SAILFISH_EXCEPTION_STACK_DEPTH_LOCALS, 10) : 5, isNaN(this.stackDepthLocals) && (this.stackDepthLocals = -1), this.stackDepthCodeTraceDepth = process.env.SAILFISH_EXCEPTION_STACK_DEPTH_CODE_TRACE_DEPTH !== void 0 ? parseInt(process.env.SAILFISH_EXCEPTION_STACK_DEPTH_CODE_TRACE_DEPTH, 10) : -1, isNaN(this.stackDepthCodeTraceDepth) && (this.stackDepthCodeTraceDepth = -1), this.packageLibraryType = "JS/TS BACKEND", this.version = this.getPackageVersion();
52
54
  }
53
55
  getPackageVersion() {
54
56
  return "0.1.15";
@@ -60,67 +62,67 @@ class Be {
60
62
  this._serviceIdentificationReceived = e;
61
63
  }
62
64
  }
63
- const me = Symbol.for("sailfish.sf_config");
64
- function z() {
65
- return globalThis[me];
65
+ const $e = Symbol.for("sailfish.sf_config");
66
+ function H() {
67
+ return globalThis[$e];
66
68
  }
67
- function We(o) {
68
- const e = z();
69
+ function et(n) {
70
+ const e = H();
69
71
  if (e) return { config: e };
70
- const t = new Be(o);
71
- return (function(n) {
72
- globalThis[me] = n;
72
+ const t = new qe(n);
73
+ return (function(s) {
74
+ globalThis[$e] = s;
73
75
  })(t), t.sfDebug && console.log("[[getOrCreateConfig]] Created global config:", t), { config: t };
74
76
  }
75
- function l() {
76
- const o = z();
77
- if (!o) throw new Error("Configuration has not been initialized. Call getOrCreateConfig(options) first.");
78
- return o;
77
+ function d() {
78
+ const n = H();
79
+ if (!n) throw new Error("Configuration has not been initialized. Call getOrCreateConfig(options) first.");
80
+ return n;
79
81
  }
80
- const ae = Symbol.for("sf.ctx.storeAls"), W = globalThis, P = W[ae] ?? (W[ae] = new ie()), Ae = ["identitytoolkit.googleapis.com", "t.co", "*.twitter.com", "*.gravatar.com", "*.googleapis.com", "*.amazonaws.com", "*.smooch.io", "*.zendesk.com"], ce = Symbol.for("sf.ctx.als"), K = W[ce] ?? (W[ce] = new ie()), ge = Symbol.for("sf.ctx.sessionRegistry"), Y = W[ge] ?? (W[ge] = /* @__PURE__ */ new Map()), E = { handledExceptions: /* @__PURE__ */ new Set(), reentrancyGuardLoggingActive: !1, reentrancyGuardLoggingPreActive: !1, reentrancyGuardPrintActive: !1, reentrancyGuardPrintPreActive: !1, reentrancyGuardExceptionActive: !1, reentrancyGuardExceptionPreActive: !1, excludedDomains: new Set(Ae), supportedDomains: /* @__PURE__ */ new Set() }, V = class V {
82
+ const be = Symbol.for("sf.ctx.storeAls"), _ = globalThis, re = _[be] ?? (_[be] = new pe()), Ue = ["identitytoolkit.googleapis.com", "t.co", "*.twitter.com", "*.gravatar.com", "*.googleapis.com", "*.amazonaws.com", "*.smooch.io", "*.zendesk.com"], Ae = Symbol.for("sf.ctx.als"), k = _[Ae] ?? (_[Ae] = new pe()), ye = Symbol.for("sf.ctx.sessionRegistry"), K = _[ye] ?? (_[ye] = /* @__PURE__ */ new Map()), L = { handledExceptions: /* @__PURE__ */ new Set(), reentrancyGuardLoggingActive: !1, reentrancyGuardLoggingPreActive: !1, reentrancyGuardPrintActive: !1, reentrancyGuardPrintPreActive: !1, reentrancyGuardExceptionActive: !1, reentrancyGuardExceptionPreActive: !1, excludedDomains: new Set(Ue), supportedDomains: /* @__PURE__ */ new Set() }, R = class R {
81
83
  constructor() {
82
84
  }
83
85
  current() {
84
- return P.getStore();
86
+ return re.getStore();
85
87
  }
86
88
  ensureStore() {
87
89
  const e = this.current();
88
90
  if (e) return e;
89
91
  const t = /* @__PURE__ */ new Map();
90
- return P.enterWith(t), t;
92
+ return re.enterWith(t), t;
91
93
  }
92
94
  runWith(e, t) {
93
- const n = this.current() ?? /* @__PURE__ */ new Map(), i = new Map(n);
94
- for (const [s, g] of Object.entries(e)) i.set(s, g);
95
- return P.run(i, t);
95
+ const s = this.current() ?? /* @__PURE__ */ new Map(), r = new Map(s);
96
+ for (const [a, o] of Object.entries(e)) r.set(a, o);
97
+ return re.run(r, t);
96
98
  }
97
99
  static getInstance() {
98
- return W[V.GLOBAL_MANAGER_SYMBOL] || (W[V.GLOBAL_MANAGER_SYMBOL] = new V()), W[V.GLOBAL_MANAGER_SYMBOL];
100
+ return _[R.GLOBAL_MANAGER_SYMBOL] || (_[R.GLOBAL_MANAGER_SYMBOL] = new R()), _[R.GLOBAL_MANAGER_SYMBOL];
99
101
  }
100
102
  getCurrentContext() {
101
- return K.getStore() || E;
103
+ return k.getStore() || L;
102
104
  }
103
105
  setCurrentContext(e) {
104
- const t = K.getStore() || E;
105
- K.enterWith({ ...t, ...e });
106
+ const t = k.getStore() || L;
107
+ k.enterWith({ ...t, ...e });
106
108
  }
107
109
  ensureSession(e) {
108
- let t = Y.get(e);
109
- return t || (t = { ...E }, Y.set(e, t)), t;
110
+ let t = K.get(e);
111
+ return t || (t = { ...L }, K.set(e, t)), t;
110
112
  }
111
113
  getContextFor(e) {
112
- return Y.get(e) ?? E;
114
+ return K.get(e) ?? L;
113
115
  }
114
116
  updateContextFor(e, t) {
115
- const n = this.ensureSession(e);
116
- Y.set(e, { ...n, ...t });
117
+ const s = this.ensureSession(e);
118
+ K.set(e, { ...s, ...t });
117
119
  }
118
120
  runWithSession(e, t) {
119
- const n = { ...this.ensureSession(e) };
120
- return K.run(n, t);
121
+ const s = { ...this.ensureSession(e) };
122
+ return k.run(s, t);
121
123
  }
122
124
  deleteSession(e) {
123
- Y.delete(e);
125
+ K.delete(e);
124
126
  }
125
127
  getTraceId() {
126
128
  return this.getCurrentContext().traceId;
@@ -144,12 +146,12 @@ const ae = Symbol.for("sf.ctx.storeAls"), W = globalThis, P = W[ae] ?? (W[ae] =
144
146
  this.setCurrentContext({ currentFunctionSpanId: void 0 });
145
147
  }
146
148
  getOrSetSfTraceId(e, t = !1) {
147
- let n = this.getTraceId();
148
- return n || (n = e || (t ? R() : `nonsession-applogs-v3/${l().apiKey}/${R()}`), this.setTraceId(n), l().sfDebug && console.log(" Created new trace ID:", n), n);
149
+ let s = this.getTraceId();
150
+ return s || (s = e || (t ? w() : `nonsession-applogs-v3/${d().apiKey}/${w()}`), this.setTraceId(s), d().sfDebug && console.log(" Created new trace ID:", s), s);
149
151
  }
150
152
  getOrSetPageVisitUUID() {
151
153
  let e = this.getPageVisitUUID();
152
- return e || (e = R(), this.setPageVisitUUID(e), l().sfDebug && console.log(" Created new page visit UUID:", e), e);
154
+ return e || (e = w(), this.setPageVisitUUID(e), d().sfDebug && console.log(" Created new page visit UUID:", e), e);
153
155
  }
154
156
  getHandledExceptions() {
155
157
  return this.getCurrentContext().handledExceptions;
@@ -180,33 +182,33 @@ const ae = Symbol.for("sf.ctx.storeAls"), W = globalThis, P = W[ae] ?? (W[ae] =
180
182
  this.updateContextFor(e, { pageVisitUUID: t });
181
183
  }
182
184
  };
183
- C(V, "GLOBAL_MANAGER_SYMBOL", Symbol.for("sf.ctx.manager"));
184
- let G = V;
185
- function it(o) {
186
- const e = { ...G.getInstance().getCurrentContext() };
187
- K.run(e, () => {
188
- o();
185
+ C(R, "GLOBAL_MANAGER_SYMBOL", Symbol.for("sf.ctx.manager"));
186
+ let v = R;
187
+ function $t(n) {
188
+ const e = { ...v.getInstance().getCurrentContext() };
189
+ k.run(e, () => {
190
+ n();
189
191
  });
190
192
  }
191
- function M() {
192
- return G.getInstance().getCurrentFunctionSpanId();
193
+ function oe() {
194
+ return v.getInstance().getCurrentFunctionSpanId();
193
195
  }
194
- class w {
196
+ class $ {
195
197
  constructor() {
196
198
  C(this, "apiKey");
197
199
  C(this, "endpoint");
198
200
  C(this, "queryType", "mutation");
199
201
  C(this, "operationName", "");
200
- C(this, "serviceUUID", l().serviceUUID);
202
+ C(this, "serviceUUID", d().serviceUUID);
201
203
  C(this, "contextManager");
202
- this.apiKey = l().apiKey, this.endpoint = l().apiGraphqlEndpoint, this.contextManager = G.getInstance();
204
+ this.apiKey = d().apiKey, this.endpoint = d().apiGraphqlEndpoint, this.contextManager = v.getInstance();
203
205
  }
204
206
  get queryName() {
205
207
  return this.operationName ? this.operationName.charAt(0).toLowerCase() + this.operationName.slice(1) : "";
206
208
  }
207
209
  getDefaultVariables() {
208
- const e = Date.now().toString(), t = this.contextManager.getOrSetSfTraceId(), n = this.contextManager.getCurrentFunctionSpanId();
209
- return { apiKey: this.apiKey, serviceUuid: this.serviceUUID, sessionId: t, timestampMs: e, parentSpanId: n };
210
+ const e = Date.now().toString(), t = this.contextManager.getOrSetSfTraceId(), s = this.contextManager.getCurrentFunctionSpanId();
211
+ return { apiKey: this.apiKey, serviceUuid: this.serviceUUID, sessionId: t, timestampMs: e, parentSpanId: s };
210
212
  }
211
213
  getVariables(e = {}) {
212
214
  return { ...this.getDefaultVariables(), ...e };
@@ -221,42 +223,43 @@ class w {
221
223
  this.serviceUUID = e;
222
224
  }
223
225
  }
224
- const Fe = fetch;
225
- async function F(o, e, t, n) {
226
+ const tt = fetch;
227
+ let P = !1;
228
+ async function W(n, e, t, s) {
226
229
  try {
227
- const i = l();
228
- let s;
230
+ const r = d();
231
+ let a;
229
232
  try {
230
- s = JSON.stringify({ query: t, variables: n, operationName: e });
233
+ a = JSON.stringify({ query: t, variables: s, operationName: e });
231
234
  } catch {
232
- s = JSON.stringify({ query: t, operationName: e });
235
+ a = JSON.stringify({ query: t, operationName: e });
233
236
  }
234
- Fe(o, { method: "POST", headers: { "Content-Type": "application/json" }, body: s }).then(async (g) => {
235
- if (!g.ok) return void (i.sfDebug && console.error(`GraphQL request failed with status ${g.status} for ${e}`));
236
- const r = await g.json();
237
- r.errors?.length ? (function(a, c, d) {
238
- const I = a && typeof a == "object" && !Array.isArray(a) ? Object.keys(a)[0] : void 0;
239
- console.error(I === "identifyServiceDetails" ? `IdentifyServiceDetails NOT sent successfully for service: UUID=${d.serviceUUID}` : `GraphQL request failed with errors: ${JSON.stringify(c)} for operation key ${I}`);
240
- })(r.data, r.errors, i) : i.sfDebug && (function(a, c, d) {
241
- const I = a && typeof a == "object" && !Array.isArray(a) ? Object.keys(a)[0] : void 0, h = a[I] || !1;
242
- I === "identifyServiceDetails" && (d.setServiceIdentificationReceived(h), l().sfDebug && console.log(`IdentifyServiceDetails sent successfully for service: UUID=${d.serviceUUID}; serviceIdentificationReceived=${I === "identifyServiceDetails" ? h : "N/A"}`));
243
- })(r.data, 0, i);
244
- }).catch((g) => {
245
- i.sfDebug && (console.error(`[RequestUtils] Fetch error for ${e} to ${o}:`, g), g.cause && console.error("[RequestUtils] Error cause:", g.cause));
237
+ P = !0, tt(n, { method: "POST", headers: { "Content-Type": "application/json" }, body: a }).then(async (o) => {
238
+ if (P = !1, !o.ok) return void (r.sfDebug && console.error(`GraphQL request failed with status ${o.status} for ${e}`));
239
+ const i = await o.json();
240
+ i.errors?.length ? (function(c, l, g) {
241
+ const u = c && typeof c == "object" && !Array.isArray(c) ? Object.keys(c)[0] : void 0;
242
+ console.error(u === "identifyServiceDetails" ? `IdentifyServiceDetails NOT sent successfully for service: UUID=${g.serviceUUID}` : `GraphQL request failed with errors: ${JSON.stringify(l)} for operation key ${u}`);
243
+ })(i.data, i.errors, r) : r.sfDebug && (function(c, l, g) {
244
+ const u = c && typeof c == "object" && !Array.isArray(c) ? Object.keys(c)[0] : void 0, I = c[u] || !1;
245
+ u === "identifyServiceDetails" && (g.setServiceIdentificationReceived(I), d().sfDebug && console.log(`IdentifyServiceDetails sent successfully for service: UUID=${g.serviceUUID}; serviceIdentificationReceived=${u === "identifyServiceDetails" ? I : "N/A"}`));
246
+ })(i.data, 0, r);
247
+ }).catch((o) => {
248
+ P = !1, r.sfDebug && (console.error(`[RequestUtils] Fetch error for ${e} to ${n}:`, o), o.cause && console.error("[RequestUtils] Error cause:", o.cause));
246
249
  });
247
- } catch (i) {
248
- l().sfDebug && console.error("Error sending data to GraphQL server:", i);
250
+ } catch (r) {
251
+ P = !1, d().sfDebug && console.error("Error sending data to GraphQL server:", r);
249
252
  }
250
253
  }
251
- class X extends w {
254
+ class X extends $ {
252
255
  constructor() {
253
256
  super(), this.setOperationName("IdentifyServiceDetails");
254
257
  }
255
258
  async doSend(e) {
256
- if (!l().serviceIdentificationReceived) try {
259
+ if (!d().serviceIdentificationReceived) try {
257
260
  this.send();
258
261
  } catch (t) {
259
- l().sfDebug && console.error(" Error during service identification:", t);
262
+ d().sfDebug && console.error(" Error during service identification:", t);
260
263
  }
261
264
  }
262
265
  async send() {
@@ -284,18 +287,18 @@ class X extends w {
284
287
  gitSha: $gitSha,
285
288
  )
286
289
  }
287
- `, t = this.getVariables({ serviceIdentifier: l().serviceIdentifier, serviceVersion: l().serviceVersion, library: l().packageLibraryType, version: l().version, serviceAdditionalMetadata: l().serviceAdditionalMetadata, gitSha: l().gitSha || "" });
288
- F(this.endpoint, this.operationName, e, t);
290
+ `, t = this.getVariables({ serviceIdentifier: d().serviceIdentifier, serviceVersion: d().serviceVersion, library: d().packageLibraryType, version: d().version, serviceAdditionalMetadata: d().serviceAdditionalMetadata, gitSha: d().gitSha || "" });
291
+ W(this.endpoint, this.operationName, e, t);
289
292
  }
290
293
  }
291
- function Ve(o) {
294
+ function nt(n) {
292
295
  try {
293
- return JSON.stringify(o), !0;
296
+ return JSON.stringify(n), !0;
294
297
  } catch {
295
298
  return !1;
296
299
  }
297
300
  }
298
- class we extends w {
301
+ class rt extends $ {
299
302
  constructor() {
300
303
  super();
301
304
  C(this, "serviceIdentifier", new X());
@@ -304,22 +307,22 @@ class we extends w {
304
307
  async sendAppIdentifier() {
305
308
  this.serviceIdentifier.doSend({});
306
309
  }
307
- async doSend(t, n, i, s) {
308
- this.sendAppIdentifier(), this.send(t, n, i, s);
309
- }
310
- async send(t, n, i, s) {
311
- if (!n && !s) throw new Error('Must pass in either traits or traits_json to "add_or_update_traits"');
312
- let g = [];
313
- if (!s) {
314
- const a = (function(c) {
315
- const d = {}, I = [];
316
- if (c) for (const [h, p] of Object.entries(c)) Ve(p) ? d[h] = p : I.push(h);
317
- return { traitsJson: JSON.stringify(d), excludedFields: I };
318
- })(n);
319
- s = a.traitsJson, g = a.excludedFields;
310
+ async doSend(t, s, r, a) {
311
+ this.sendAppIdentifier(), this.send(t, s, r, a);
312
+ }
313
+ async send(t, s, r, a) {
314
+ if (!s && !a) throw new Error('Must pass in either traits or traits_json to "add_or_update_traits"');
315
+ let o = [];
316
+ if (!a) {
317
+ const c = (function(l) {
318
+ const g = {}, u = [];
319
+ if (l) for (const [I, m] of Object.entries(l)) nt(m) ? g[I] = m : u.push(I);
320
+ return { traitsJson: JSON.stringify(g), excludedFields: u };
321
+ })(s);
322
+ a = c.traitsJson, o = c.excludedFields;
320
323
  }
321
- const r = this.getVariables({ userId: t, traitsJson: s, excludedFields: g, override: i, library: l().packageLibraryType, version: l().version });
322
- F(this.endpoint, this.operationName, this.getQuery(), r);
324
+ const i = this.getVariables({ userId: t, traitsJson: a, excludedFields: o, override: r, library: d().packageLibraryType, version: d().version });
325
+ W(this.endpoint, this.operationName, this.getQuery(), i);
323
326
  }
324
327
  getQuery() {
325
328
  return `
@@ -329,20 +332,20 @@ class we extends w {
329
332
  `;
330
333
  }
331
334
  }
332
- class be {
335
+ class Ke {
333
336
  constructor(e) {
334
337
  C(this, "metadataTransmitter");
335
- this.apiKey = e, this.metadataTransmitter = new we();
338
+ this.apiKey = e, this.metadataTransmitter = new rt();
336
339
  }
337
- identify(e, t, n, i = !1) {
338
- t || n ? this.addOrUpdateMetadata(e, t, n, i) : this.addOrUpdateMetadata(e, {}, void 0, i);
340
+ identify(e, t, s, r = !1) {
341
+ t || s ? this.addOrUpdateMetadata(e, t, s, r) : this.addOrUpdateMetadata(e, {}, void 0, r);
339
342
  }
340
- addOrUpdateMetadata(e, t = {}, n, i = !1) {
341
- if (!t && !n) throw new Error('Must pass in either traits or traitsJson to "addOrUpdateMetadata"');
342
- l().sfDebug && console.log(" [[DEBUG - addOrUpdateMetadata]] Starting operation"), l().sfDebug && console.log(" addOrUpdateMetadata...SENDING DATA...", e, t, n), this.metadataTransmitter.doSend(e, t, i, n);
343
+ addOrUpdateMetadata(e, t = {}, s, r = !1) {
344
+ if (!t && !s) throw new Error('Must pass in either traits or traitsJson to "addOrUpdateMetadata"');
345
+ d().sfDebug && console.log(" [[DEBUG - addOrUpdateMetadata]] Starting operation"), d().sfDebug && console.log(" addOrUpdateMetadata...SENDING DATA...", e, t, s), this.metadataTransmitter.doSend(e, t, r, s);
343
346
  }
344
347
  }
345
- class oe extends w {
348
+ class Ie extends $ {
346
349
  constructor() {
347
350
  super();
348
351
  C(this, "serviceIdentifier", new X());
@@ -355,10 +358,10 @@ class oe extends w {
355
358
  }
356
359
  async send(t) {
357
360
  try {
358
- const n = Array.isArray(t) ? t : [t, "default"], i = this.getVariables({ contents: n[0], level: n[1] });
359
- F(this.endpoint, this.operationName, this.getQuery(), i);
360
- } catch (n) {
361
- l().sfDebug && console.error("🚨 Error in send():", n);
361
+ const s = Array.isArray(t) ? t : [t, "default"], r = this.getVariables({ contents: s[0], level: s[1] });
362
+ W(this.endpoint, this.operationName, this.getQuery(), r);
363
+ } catch (s) {
364
+ d().sfDebug && console.error("🚨 Error in send():", s);
362
365
  }
363
366
  }
364
367
  getQuery() {
@@ -385,9 +388,9 @@ class oe extends w {
385
388
  `;
386
389
  }
387
390
  }
388
- const N = {};
389
- class T {
390
- constructor({ file: e, line: t, function: n, code: i, locals: s = {}, offender: g = !1, column: r }) {
391
+ const B = {};
392
+ class Y {
393
+ constructor({ file: e, line: t, function: s, code: r, locals: a = {}, offender: o = !1, column: i }) {
391
394
  C(this, "file");
392
395
  C(this, "line");
393
396
  C(this, "function");
@@ -395,204 +398,204 @@ class T {
395
398
  C(this, "locals");
396
399
  C(this, "offender");
397
400
  C(this, "column");
398
- this.file = e, this.line = t, this.function = n, this.code = i, this.locals = s, this.offender = g, this.column = r;
401
+ this.file = e, this.line = t, this.function = s, this.code = r, this.locals = a, this.offender = o, this.column = i;
399
402
  }
400
403
  toDict() {
401
- const e = { file: this.file, line: this.line, function: this.function, code: this.code, locals: Object.fromEntries(Object.entries(this.locals).map(([t, n]) => [t, String(n)])) };
404
+ const e = { file: this.file, line: this.line, function: this.function, code: this.code, locals: Object.fromEntries(Object.entries(this.locals).map(([t, s]) => [t, String(s)])) };
402
405
  return this.offender && (e.offender = this.offender), this.column !== void 0 && (e.column = this.column), e;
403
406
  }
404
407
  toJson() {
405
408
  return JSON.stringify(this.toDict());
406
409
  }
407
410
  }
408
- class L {
411
+ class Q {
409
412
  static encode(e) {
410
- return e instanceof T ? e.toDict() : Array.isArray(e) ? e.map((t) => L.encode(t)) : typeof e == "object" && e !== null ? JSON.stringify(e) : e;
413
+ return e instanceof Y ? e.toDict() : Array.isArray(e) ? e.map((t) => Q.encode(t)) : typeof e == "object" && e !== null ? JSON.stringify(e) : e;
411
414
  }
412
415
  static stringify(e) {
413
- return JSON.stringify(L.encode(e), (t, n) => n instanceof T ? n.toDict() : n);
416
+ return JSON.stringify(Q.encode(e), (t, s) => s instanceof Y ? s.toDict() : s);
414
417
  }
415
418
  }
416
- let B, U = 0;
417
- function He(o) {
418
- l().sfDebug && console.log("Initializing Exception Interceptor...");
419
+ let F, E = 0;
420
+ function ot(n) {
421
+ d().sfDebug && console.log("Initializing Exception Interceptor...");
419
422
  try {
420
- const r = (function() {
421
- if (B !== void 0) return B;
422
- const a = process.env || {}, c = Ie(a.SF_IS_LOCAL);
423
- if (c !== void 0) return B = c;
424
- const d = (a.SF_ENV || a.NODE_ENV || "").toLowerCase();
425
- if (["local", "dev", "development"].includes(d)) return B = !0;
426
- if (["KUBERNETES_SERVICE_HOST", "AWS_EXECUTION_ENV", "ECS_CONTAINER_METADATA_URI", "ECS_CONTAINER_METADATA_URI_V4", "GAE_ENV", "K_SERVICE", "GOOGLE_CLOUD_PROJECT", "WEBSITE_INSTANCE_ID", "VERCEL", "NETLIFY", "DYNO", "RENDER", "FLY_APP_NAME", "RAILWAY_STATIC_URL", "CF_PAGES", "CLOUDFLARE"].some((h) => !!a[h])) return B = !1;
427
- const I = (N.hostname?.() || a.HOSTNAME || "").toLowerCase();
428
- return I === "localhost" || I.endsWith(".local") || I.includes("local") ? B = !0 : B = !1;
423
+ const i = (function() {
424
+ if (F !== void 0) return F;
425
+ const c = process.env || {}, l = ve(c.SF_IS_LOCAL);
426
+ if (l !== void 0) return F = l;
427
+ const g = (c.SF_ENV || c.NODE_ENV || "").toLowerCase();
428
+ if (["local", "dev", "development"].includes(g)) return F = !0;
429
+ if (["KUBERNETES_SERVICE_HOST", "AWS_EXECUTION_ENV", "ECS_CONTAINER_METADATA_URI", "ECS_CONTAINER_METADATA_URI_V4", "GAE_ENV", "K_SERVICE", "GOOGLE_CLOUD_PROJECT", "WEBSITE_INSTANCE_ID", "VERCEL", "NETLIFY", "DYNO", "RENDER", "FLY_APP_NAME", "RAILWAY_STATIC_URL", "CF_PAGES", "CLOUDFLARE"].some((I) => !!c[I])) return F = !1;
430
+ const u = (B.hostname?.() || c.HOSTNAME || "").toLowerCase();
431
+ return u === "localhost" || u.endsWith(".local") || u.includes("local") ? F = !0 : F = !1;
429
432
  })();
430
- o?.setSupplementalFields?.({ isFromLocalService: r }), (async function(a) {
431
- if (de) return;
432
- de = !0;
433
- const c = process.env || {};
434
- if (Ie(c.SF_IS_LOCAL) === void 0)
433
+ n?.setSupplementalFields?.({ isFromLocalService: i }), (async function(c) {
434
+ if (Ne) return;
435
+ Ne = !0;
436
+ const l = process.env || {};
437
+ if (ve(l.SF_IS_LOCAL) === void 0)
435
438
  try {
436
- await (async function(d) {
437
- const I = j("http://169.254.169.254/latest/meta-data/", {}, d), h = j("http://metadata.google.internal/computeMetadata/v1/instance/", { "Metadata-Flavor": "Google" }, d), p = j("http://169.254.169.254/metadata/instance?api-version=2021-02-01", { Metadata: "true" }, d);
438
- return (await Promise.allSettled([I, h, p])).some((u) => u.status === "fulfilled" && (u.value === "ok" || u.value === "http_error"));
439
- })(150) && B && (B = !1, a?.setSupplementalFields?.({ isFromLocalService: !1 }));
439
+ await (async function(g) {
440
+ const u = se("http://169.254.169.254/latest/meta-data/", {}, g), I = se("http://metadata.google.internal/computeMetadata/v1/instance/", { "Metadata-Flavor": "Google" }, g), m = se("http://169.254.169.254/metadata/instance?api-version=2021-02-01", { Metadata: "true" }, g);
441
+ return (await Promise.allSettled([u, I, m])).some((p) => p.status === "fulfilled" && (p.value === "ok" || p.value === "http_error"));
442
+ })(150) && F && (F = !1, c?.setSupplementalFields?.({ isFromLocalService: !1 }));
440
443
  } catch {
441
444
  }
442
- })(o).catch(() => {
445
+ })(n).catch(() => {
443
446
  });
444
447
  } catch {
445
448
  }
446
- const e = new Ge(new URL("data:application/javascript;base64,aW1wb3J0IHsgU2Vzc2lvbiB9IGZyb20gImluc3BlY3Rvci9wcm9taXNlcyI7CmltcG9ydCB7IHBhcmVudFBvcnQsIHdvcmtlckRhdGEgfSBmcm9tICJ3b3JrZXJfdGhyZWFkcyI7CgpnbG9iYWwuc2ZEZWJ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JpcHRJZDsKICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgIGNvbnN0IHsgc2NyaXB0U291cmNlIH0gPSBhd2FpdCBzZXNzaW9uLnBvc3QoCiAgICAgICAgICAgICAgIkRlYnVnZ2VyLmdldFNjcmlwdFNvdXJjZSIsCiAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgc2NyaXB0SWQsCiAgICAgICAgICAgICAgfSwKICAgICAgICAgICAgKTsKICAgICAgICAgICAgY29uc3Qgc291cmNlTGluZXMgPSBzY3JpcHRTb3VyY2Uuc3BsaXQoIlxuIik7CiAgICAgICAgICAgIGNvZGUgPSBzb3VyY2VMaW5lc1tsb2NhdGlvbi5saW5lTnVtYmVyXSB8fCAiPG5vdCBjYXB0dXJlZD4iOwogICAgICAgICAgfSBjYXRjaCAoZXJyKSB7CiAgICAgICAgICAgIGlmIChnbG9iYWwuc2ZEZWJ1ZykgewogICAgICAgICAgICAgIGNvbnNvbGUuZXJyb3IoIltXb3JrZXJdIEZhaWxlZCB0byBmZXRjaCBzY3JpcHQgc291cmNlOiIsIGVycik7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIC8vIEZldGNoIGxvY2FsIHZhcmlhYmxlcyBpZiB0aGVyZSdzIGFuIG9iamVjdElkCiAgICAgICAgY29uc3QgbG9jYWxzID0gbG9jYWxTY29wZT8ub2JqZWN0Py5vYmplY3RJZAogICAgICAgICAgPyBhd2FpdCBmZXRjaExvY2FsVmFyaWFibGVzKHNlc3Npb24sIGxvY2FsU2NvcGUub2JqZWN0Lm9iamVjdElkKQogICAgICAgICAgOiB7fTsKCiAgICAgICAgcmV0dXJuIHsKICAgICAgICAgIGZ1bmN0aW9uOiBmdW5jdGlvbk5hbWUgfHwgIjxhbm9ueW1vdXM+IiwKICAgICAgICAgIGxvY2FscywKICAgICAgICAgIGZpbGUsCiAgICAgICAgICBsaW5lOiBsb2NhdGlvbj8ubGluZU51bWJlciB8fCAwLAogICAgICAgIC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bmNlcyBvbmUgb2YgdGhlIG1vZHVsZXMgd2UgYWxsb3cgY2FwdHVyaW5nIGZyb20KICAgICAgICBjb25zdCBpc0Zyb21BbGxvd2VkTm9kZU1vZHVsZSA9IG5vZGVNb2R1bGVzTGlzdC5zb21lKChtb2R1bGVOYW1lKSA9PgogICAgICAgICAgZmlyc3RGcmFtZUxpbmUuaW5jbHVkZXMoYCR7bW9kdWxlTmFtZX1gKSwKICAgICAgICApOwoKICAgICAgICBpZiAoIWlzRnJvbUFsbG93ZWROb2RlTW9kdWxlKSB7CiAgICAgICAgICAvLyBOb3QgZnJvbSBhbiBhbGxvd2VkIG5vZGUgbW9kdWxlID0+IHJldHVybiBlYXJseQogICAgICAgICAgaWYgKGdsb2JhbC5zZkRlYnVnKSB7CiAgICAgICAgICAgIGNvbnNvbGUubG9nKAogICAgICAgICAgICAgICJbV29ya2VyXSBFcnJvciBhcHBlYXJzIHRvIGJlIHRyaWdnZXJlZCBmcm9tIG5vbi1hcHBsaWNhdGlvbiBzb3VyY2VzOyBpZ25vcmluZy4iLAogICAgICAgICAgICApOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuOwogICAgICAgIH0KICAgICAgICAvLyBPdGhlcndpc2UsIGl0J3MgZnJvbSBhbiBhbGxvd2VkIG5vZGUgbW9kdWxlLCBzbyBjb250aW51ZQogICAgICB9IGVsc2UgewogICAgICAgIC8vIElmIHRoZSBsaXN0IGlzIGVtcHR5LCBwcmVzZXJ2ZSBleGlzdGluZyBiZWhhdmlvciBhbmQgaWdub3JlIG5vbi1hcHBsaWNhdGlvbiBlcnJvcnMKICAgICAgICBpZiAoZ2xvYmFsLnNmRGVidWcpIHsKICAgICAgICAgIGNvbnNvbGUubG9nKAogICAgICAgICAgICAiW1dvcmtlcl0gRXJyb3IgYXBwZWFycyB0byBiZSB0cmlnZ2VyZWQgZnJvbSBub24tYXBwbGljYXRpb24gc291cmNlczsgaWdub3JpbmcuIiwKICAgICAgICAgICk7CiAgICAgICAgfQog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vbnNvbGUuZXJyb3IoIltXb3JrZXJdIEZhaWxlZCB0byBmZXRjaCBzY3JpcHQgc291cmNlOiIsIGVycik7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIC8vIEZldGNoIGxvY2FsIHZhcmlhYmxlcyBpZiB0aGVyZSdzIGFuIG9iamVjdElkCiAgICAgICAgY29uc3QgbG9jYWxzID0gbG9jYWxTY29wZT8ub2JqZWN0Py5vYmplY3RJZAogICAgICAgICAgPyBhd2FpdCBmZXRjaExvY2FsVmFyaWFibGVzKHNlc3Npb24sIGxvY2FsU2NvcGUub2JqZWN0Lm9iamVjdElkKQogICAgICAgICAgOiB7fTsKCiAgICAgICAgcmV0dXJuIHsKICAgICAgICAgIGZ1bmN0aW9uOiBmdW5jdGlvbk5hbWUgfHwgIjxhbm9ueW1vdXM+IiwKICAgICAgICAgIGxvY2FscywKICAgICAgICAgIGZpbGUsCiAgICAgICAgICBsaW5lOiBsb2NhdGlvbj8ubGluZU51bWJlciB8fCAwLAogICAgICAgICAgY29kZSwKICAgICAgICB9OwogICAgICB9IGNhdGNoIChlcnJvcikgewogICAgICAgIGlmIChnbG9iYWwuc2ZEZWJ1ZykgewogICAgICAgICAgY29uc29sZS5lcnJvcigiW1dvcmtlcl0gRXJyb3IgcHJvY2Vzc2luZyBjYWxsIGZyYW1lOiIsIGVycm9yKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHsKICAgICAgICAgIGZ1bmN0aW9uOiAiPGVycm9yPiIsCiAgICAgICAgICBsb2NhbHM6IHt9LAogICAgICAgICAgZmlsZTogIjx1bmtub3duPiIsCiAgICAgICAgICBsaW5lOiAwLAogICAgICAgICAgY29kZTogIjxub3QgY2FwdHVyZWQ+IiwKICAgICAgICB9OwogICAgICB9CiAgICB9KSwKICApOwogIC8vIFBvc3QgZXhjZXB0aW9uIGRhdGEKICBwYXJlbnRQb3J0Py5wb3N0TWVzc2FnZSh7IHR5cGU6ICJleGNlcHRpb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ibGVzT24gPQogICAgICAgICAgbWVzc2FnZS5ub2RlTW9kdWxlc1RvQ29sbGVjdExvY2FsVmFyaWFibGVzT247CgogICAgICAgIHJlc29sdmVNZXNzYWdlUHJvbWlzZSgpOwogICAgICB9CiAgICB9IGNhdGNoIChlcnJvcikgewogICAgICBpZiAoZ2xvYmFsLnNmRGVidWcpIHsKICAgICAgICBjb25zb2xlLmVycm9yKCLinYwgRXJyb3IgaW4gbWVzc2FnZSBoYW5kbGluZzoiLCBlcnJvcik7CiAgICAgIH0KICAgIH0KICB9KTsKCiAgYXdhaXQgbWVzc2FnZVByb21pc2U7CgogIHRyeSB7CiAgICBjb25zdCBzZXNzaW9uID0gbmV3IFNlc3Npb24oKTsKICAgIHNlc3Npb24uY29ubmVjdFRvTWFpblRocmVhZCgpOwoKICAgIHNlc3Npb24ub24oIkRlYnVnZ2VyLnJlc3VtZWQiLCAoKSA9PiB7CiAgICAgIGlzUGF1c2VkID0gZmFsc2U7CiAgICB9KTsKCiAgICBzZXNzaW9uLm9uKCJEZWJ1Z2dlci5wYXVzZWQiLCBhc3luYyAoZXZlbnQpID0+IHsKICAgICAgaXNQYXVzZWQgPSB0cnVlOwogICAgICBoYW5kbGVQYXVzZWQoc2Vzc2lvbiwgZXZlbnQucGFyYW1zKS50aGVuKAogICAgICAgIGFzeW5jICgpID0+IHsKICAgICAgICAgIC8vIEFmdGVyIHRoZSBwYXVzZSB3b3JrIGlzIGNvbXBsZXRlLCByZXN1bWUgZXhlY3V0aW9uIQogICAgICAgICAgaWYgKGlzUGF1c2VkKSB7CiAgICAgICAgICAgIGF3YWl0IHNlc3Npb24ucG9zdCgiRGVidWdnZXIucmVzdW1lIik7CiAgICAgICAgICB9CiAgICAgICAgfSwKICAgICAgICBhc3luYyAoXykgPT4gewogICAgICAgICAgaWYgKGlzUGF1c2VkKSB7CiAgICAgICAgICAgIGF3YWl0IHNlc3Npb24ucG9zdCgiRGVidWdnZXIucmVzdW1lIik7CiAgICAgICAgICB9CiAg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heShzZXNzaW9uLCBpZCwgcHJvcC5uYW1lLCB2YXJpYWJsZXMpOwogICAgICAgIH0gZWxzZSBpZiAoCiAgICAgICAgICBwcm9wPy52YWx1ZT8ub2JqZWN0SWQgJiYKICAgICAgICAgIHByb3A/LnZhbHVlPy5jbGFzc05hbWUgPT09ICJPYmplY3QiCiAgICAgICAgKSB7CiAgICAgICAgICBjb25zdCBpZCA9IHByb3AudmFsdWUub2JqZWN0SWQ7CiAgICAgICAgICBhd2FpdCB1bnJvbGxPYmplY3Qoc2Vzc2lvbiwgaWQsIHByb3AubmFtZSwgdmFyaWFibGVzKTsKICAgICAgICB9IGVsc2UgaWYgKHByb3A/LnZhbHVlKSB7CiAgICAgICAgICB1bnJvbGxPdGhlcihwcm9wLCB2YXJpYWJsZXMpOwogICAgICAgIH0KICAgICAgfQogICAgICByZXR1cm4gdmFyaWFibGVzOwogICAgfQogIH0gY2F0Y2ggKGVycikgewogICAgaWYgKGdsb2JhbC5zZkRlYnVnKSB7CiAgICAgIGNvbnNvbGUuZXJyb3IoIltXb3JrZXJdIEZhaWxlZCB0byBmZXRjaCBsb2NhbCB2YXJpYWJsZXM6IiwgZXJyKTsKICAgIH0KICAgIHJldHVybiB7fTsKICB9Cn0KCnN0YXJ0RGVidWdnZXIoKS5jYXRjaCgoZXJyb3IpID0+IHsKICBpZiAoZ2xvYmFsLnNmRGVidWcpIHsKICAgIGNvbnNvbGUuZXJyb3IoIltXb3JrZXJdIEZhaWxlZCB0byBzdGFydCBkZWJ1Z2dlcjoiLCBlcnJvcik7CiAgfQp9KTsKCi8vIEtlZXAgdGhlIHdvcmtlciBhbGl2ZQpzZXRJbnRlcnZhbCgoKSA9PiB7fSwgMTAwMDApOwo="), { workerData: { captureAllExceptions: !0 } });
447
450
  let t = null;
448
- const n = /* @__PURE__ */ new WeakMap();
449
- e.on("message", (r) => {
450
- if (typeof r == "string" && l().sfDebug && console.log(`[Worker] ${r}`), r.readyToGetParameters && e.postMessage({ sfDebug: l().sfDebug, stackDepthLocals: l().stackDepthLocals, nodeModulesToCollectLocalVariablesOn: l().nodeModulesToCollectLocalVariablesOn }), r.type === "exception") {
451
- const { frames: a } = r, c = t;
452
- if (!c) return;
453
- const d = n.get(c), I = (function(p) {
454
- return p ? p.split(`
455
- `).slice(1).map((u) => {
456
- const m = /at (.+?) \((.+):(\d+):(\d+)\)/.exec(u) || /at (.+):(\d+):(\d+)/.exec(u);
457
- if (m) {
458
- const [, A, y, b, f] = m;
459
- return new T({ function: A || "<anonymous>", locals: {}, file: y || "<unknown>", line: parseInt(b, 10) || 0, code: "<not captured>", column: parseInt(f) || 0 });
451
+ const s = /* @__PURE__ */ new WeakMap();
452
+ e.on("message", (i) => {
453
+ if (typeof i == "string" && d().sfDebug && console.log(`[Worker] ${i}`), i.readyToGetParameters && e.postMessage({ sfDebug: d().sfDebug, stackDepthLocals: d().stackDepthLocals, nodeModulesToCollectLocalVariablesOn: d().nodeModulesToCollectLocalVariablesOn }), i.type === "exception") {
454
+ const { frames: c } = i, l = t;
455
+ if (!l) return;
456
+ const g = s.get(l), u = (function(m) {
457
+ return m ? m.split(`
458
+ `).slice(1).map((p) => {
459
+ const h = /at (.+?) \((.+):(\d+):(\d+)\)/.exec(p) || /at (.+):(\d+):(\d+)/.exec(p);
460
+ if (h) {
461
+ const [, f, S, b, y] = h;
462
+ return new Y({ function: f || "<anonymous>", locals: {}, file: S || "<unknown>", line: parseInt(b, 10) || 0, code: "<not captured>", column: parseInt(y) || 0 });
460
463
  }
461
- return new T({ function: "<unknown>", locals: {}, file: "<unknown>", line: 0, code: "<not captured>", column: 0 });
464
+ return new Y({ function: "<unknown>", locals: {}, file: "<unknown>", line: 0, code: "<not captured>", column: 0 });
462
465
  }) : [];
463
- })(c.stack), h = (function(p, u) {
464
- const m = [];
465
- let A = -1, y = -1;
466
- for (let b = 0; b < p.length; b++) {
467
- const f = Ye(p[b].file);
468
- if (y = b, f !== "<unknown>") {
469
- for (let S = 0; S < u.length; S++) {
470
- const x = u[S];
471
- if (fe(x, f) || typeof x.file == "string" && x.file.includes(f)) {
472
- A = S, U = 0, l().sfDebug && console.log(`✅ Matched Frame Found: ${f} @ Debugger Frame ${S}`);
466
+ })(l.stack), I = (function(m, p) {
467
+ const h = [];
468
+ let f = -1, S = -1;
469
+ for (let b = 0; b < m.length; b++) {
470
+ const y = it(m[b].file);
471
+ if (S = b, y !== "<unknown>") {
472
+ for (let A = 0; A < p.length; A++) {
473
+ const Z = p[A];
474
+ if (Ee(Z, y) || typeof Z.file == "string" && Z.file.includes(y)) {
475
+ f = A, E = 0, d().sfDebug && console.log(`✅ Matched Frame Found: ${y} @ Debugger Frame ${A}`);
473
476
  break;
474
477
  }
475
478
  }
476
- if (A !== -1) break;
479
+ if (f !== -1) break;
477
480
  }
478
481
  }
479
- if (A === -1) return U === 10 ? (U = 0, p) : (++U, l().sfDebug && console.log(`"❌ No matching frame found. Checking once again, Attempt N ${U}"`), []);
480
- l().sfDebug && console.log(`🔄 Merging from matched index ${A} onward...`);
481
- for (let b = 0; b < u.length; b++) {
482
- const f = p[y + b], S = u[A + b];
483
- m.push(new T({ function: S?.function || f?.function || "<anonymous>", locals: S?.locals || f?.locals || {}, file: f?.file || S?.file || "<unknown>", line: S?.line || f?.line || 0, code: S?.code || f?.code || "<not captured>" }));
482
+ if (f === -1) return E === 10 ? (E = 0, m) : (++E, d().sfDebug && console.log(`"❌ No matching frame found. Checking once again, Attempt N ${E}"`), []);
483
+ d().sfDebug && console.log(`🔄 Merging from matched index ${f} onward...`);
484
+ for (let b = 0; b < p.length; b++) {
485
+ const y = m[S + b], A = p[f + b];
486
+ h.push(new Y({ function: A?.function || y?.function || "<anonymous>", locals: A?.locals || y?.locals || {}, file: y?.file || A?.file || "<unknown>", line: A?.line || y?.line || 0, code: A?.code || y?.code || "<not captured>" }));
484
487
  }
485
- return m;
486
- })(I, a || []);
487
- if (h.length !== 0) {
488
+ return h;
489
+ })(u, c || []);
490
+ if (I.length !== 0) {
488
491
  t = null;
489
- const p = l().stackDepthCodeTraceDepth, u = p === -1 ? h : h.slice(0, p + 1), m = Math.min(u.length, I.length);
490
- for (let f = 0; f < m; f++) (async () => {
491
- const S = Re(u[f].file, I[f].line, I[f].column);
492
- S && (S.content != null && (u[f].code = S.content), S.file != null && (u[f].file = S.file));
492
+ const m = d().stackDepthCodeTraceDepth, p = m === -1 ? I : I.slice(0, m + 1), h = Math.min(p.length, u.length);
493
+ for (let y = 0; y < h; y++) (async () => {
494
+ const A = st(p[y].file, u[y].line, u[y].column);
495
+ A && (A.content != null && (p[y].code = A.content), A.file != null && (p[y].file = A.file));
493
496
  })();
494
- o.setOperationName("CollectExceptions");
495
- const A = c.message ? `${c.name}: ${c.message}` : c.name;
496
- l().sfDebug && console.log("error message is : ", A);
497
- const y = G.getInstance(), b = n.get(c);
498
- b ? (y.setTraceIdFor(b, b), y.runWithSession(b, () => {
499
- y.setTraceId(b), o.doSend(A, u);
500
- })) : o.doSend(A, u), d ? G.getInstance().runWithSession(d, () => {
501
- o.doSend(A, u);
502
- }) : o.doSend(A, u);
497
+ n.setOperationName("CollectExceptions");
498
+ const f = l.message ? `${l.name}: ${l.message}` : l.name;
499
+ d().sfDebug && console.log("error message is : ", f);
500
+ const S = v.getInstance(), b = s.get(l);
501
+ b ? (S.setTraceIdFor(b, b), S.runWithSession(b, () => {
502
+ S.setTraceId(b), n.doSend(f, p);
503
+ })) : n.doSend(f, p), g ? v.getInstance().runWithSession(g, () => {
504
+ n.doSend(f, p);
505
+ }) : n.doSend(f, p);
503
506
  }
504
507
  }
505
- }), e.on("error", (r) => {
506
- console.error("[Worker Error]", r);
507
- }), e.on("exit", (r) => {
508
- console.error(`[Worker] Exited with code ${r}`);
508
+ }), e.on("error", (i) => {
509
+ console.error("[Worker Error]", i);
510
+ }), e.on("exit", (i) => {
511
+ console.error(`[Worker] Exited with code ${i}`);
509
512
  }), e.unref();
510
- const i = Error, s = /* @__PURE__ */ new Set();
511
- function g(...r) {
512
- const a = Reflect.construct(i, r);
513
- Reflect.setPrototypeOf(a, g.prototype);
513
+ const r = Error, a = /* @__PURE__ */ new Set();
514
+ function o(...i) {
515
+ const c = Reflect.construct(r, i);
516
+ Reflect.setPrototypeOf(c, o.prototype);
514
517
  try {
515
- const d = G.getInstance().getTraceId();
516
- n.set(a, d);
518
+ const g = v.getInstance().getTraceId();
519
+ s.set(c, g);
517
520
  } catch {
518
521
  }
519
- i.captureStackTrace && i.captureStackTrace(a, g);
520
- const c = `${a.message}:${a.stack?.split(`
522
+ r.captureStackTrace && r.captureStackTrace(c, o);
523
+ const l = `${c.message}:${c.stack?.split(`
521
524
  `)[1]?.trim()}`;
522
- if (!s.has(c)) {
523
- s.add(c), t = a;
524
- const d = G.getInstance().getTraceId();
525
- n.set(a, d), e.postMessage({ type: "processException", error: a.message });
525
+ if (!a.has(l)) {
526
+ a.add(l), t = c;
527
+ const g = v.getInstance().getTraceId();
528
+ s.set(c, g), e.postMessage({ type: "processException", error: c.message });
526
529
  }
527
- return a;
530
+ return c;
528
531
  }
529
- g.prototype = Object.create(i.prototype, { constructor: { value: g, enumerable: !1, writable: !0, configurable: !0 } }), Object.setPrototypeOf(g, i), globalThis.Error = g;
532
+ o.prototype = Object.create(r.prototype, { constructor: { value: o, enumerable: !1, writable: !0, configurable: !0 } }), Object.setPrototypeOf(o, r), globalThis.Error = o;
530
533
  }
531
- function le(o) {
532
- return o = (o = (o = o.replace(/^webpack:\/\/[^\/]+\/\.?\//, "")).replace(/^.*\/pages\//, "pages/")).replace(/\.(js|ts)$/, "");
534
+ function Se(n) {
535
+ return n = (n = (n = n.replace(/^webpack:\/\/[^\/]+\/\.?\//, "")).replace(/^.*\/pages\//, "pages/")).replace(/\.(js|ts)$/, "");
533
536
  }
534
- function Re(o, e, t) {
535
- const n = (function(s) {
536
- s.startsWith("at ") && (s = s.slice(3).trim());
537
- const g = s.match(/^(.*?)(:\d+)+(\.map)?$/);
538
- return g ? g[1] : s;
539
- })(o);
540
- if (!n || n === "<unknown>") return null;
541
- const i = n + ".map";
537
+ function st(n, e, t) {
538
+ const s = (function(a) {
539
+ a.startsWith("at ") && (a = a.slice(3).trim());
540
+ const o = a.match(/^(.*?)(:\d+)+(\.map)?$/);
541
+ return o ? o[1] : a;
542
+ })(n);
543
+ if (!s || s === "<unknown>") return null;
544
+ const r = s + ".map";
542
545
  try {
543
- const s = pe(i, "utf-8");
544
- if (s) {
545
- const g = JSON.parse(s);
546
- let r = new he.SourceMapConsumer(g).originalPositionFor({ line: e, column: t });
547
- if (n && r.source) {
548
- const a = le(n), c = g.sources.findIndex((d) => le(d) === a);
549
- if (c === -1) l().sfDebug && console.log(`Source file "${n}" not found in the source map.`);
546
+ const a = Re(r, "utf-8");
547
+ if (a) {
548
+ const o = JSON.parse(a);
549
+ let i = new He.SourceMapConsumer(o).originalPositionFor({ line: e, column: t });
550
+ if (s && i.source) {
551
+ const c = Se(s), l = o.sources.findIndex((g) => Se(g) === c);
552
+ if (l === -1) d().sfDebug && console.log(`Source file "${s}" not found in the source map.`);
550
553
  else {
551
- const d = g.sourcesContent[c], I = g.names.join(",");
552
- if (d)
553
- return { content: d.split(`
554
- `).slice(r.line - 1, r.line + 20).join(`
555
- `), name: I, file: r.source };
556
- l().sfDebug && console.log(`No source content available for file "${n}".`);
554
+ const g = o.sourcesContent[l], u = o.names.join(",");
555
+ if (g)
556
+ return { content: g.split(`
557
+ `).slice(i.line - 1, i.line + 20).join(`
558
+ `), name: u, file: i.source };
559
+ d().sfDebug && console.log(`No source content available for file "${s}".`);
557
560
  }
558
561
  }
559
- return { content: g.sourcesContent[0], name: g.names[0], file: g.file };
562
+ return { content: o.sourcesContent[0], name: o.names[0], file: o.file };
560
563
  }
561
- } catch (s) {
562
- l().sfDebug && console.log(`Cant read/parse "${i}: Error - ".`, s);
564
+ } catch (a) {
565
+ d().sfDebug && console.log(`Cant read/parse "${r}: Error - ".`, a);
563
566
  }
564
567
  return null;
565
568
  }
566
- function Ye(o) {
567
- return o?.split("/").pop() || "<unknown>";
569
+ function it(n) {
570
+ return n?.split("/").pop() || "<unknown>";
568
571
  }
569
- function fe(o, e) {
570
- if (!o || typeof o != "object") return !1;
571
- for (const t of Object.values(o))
572
- if (typeof t == "string" && t.includes(e) || typeof t == "object" && fe(t, e)) return !0;
572
+ function Ee(n, e) {
573
+ if (!n || typeof n != "object") return !1;
574
+ for (const t of Object.values(n))
575
+ if (typeof t == "string" && t.includes(e) || typeof t == "object" && Ee(t, e)) return !0;
573
576
  return !1;
574
577
  }
575
- let de = !1;
576
- function Ie(o) {
577
- if (!o) return;
578
- const e = o.toLowerCase().trim();
578
+ let Ne = !1;
579
+ function ve(n) {
580
+ if (!n) return;
581
+ const e = n.toLowerCase().trim();
579
582
  return !!["1", "true", "yes", "on"].includes(e) || !["0", "false", "no", "off"].includes(e) && void 0;
580
583
  }
581
- function j(o, e, t) {
582
- return new Promise((n) => {
584
+ function se(n, e, t) {
585
+ return new Promise((s) => {
583
586
  try {
584
- const i = new URL(o), s = (i.protocol, N).request({ method: "GET", hostname: i.hostname, port: i.port || (i.protocol === "https:" ? 443 : 80), path: i.pathname + (i.search || ""), headers: e }, (g) => {
585
- g.resume(), g.statusCode && g.statusCode >= 200 && g.statusCode < 400 ? n("ok") : n("http_error");
587
+ const r = new URL(n), a = (r.protocol, B).request({ method: "GET", hostname: r.hostname, port: r.port || (r.protocol === "https:" ? 443 : 80), path: r.pathname + (r.search || ""), headers: e }, (o) => {
588
+ o.resume(), o.statusCode && o.statusCode >= 200 && o.statusCode < 400 ? s("ok") : s("http_error");
586
589
  });
587
- s.on("error", () => n("error")), s.setTimeout(t, () => {
588
- s.destroy(), n("timeout");
589
- }), s.end();
590
+ a.on("error", () => s("error")), a.setTimeout(t, () => {
591
+ a.destroy(), s("timeout");
592
+ }), a.end();
590
593
  } catch {
591
- n("error");
594
+ s("error");
592
595
  }
593
596
  });
594
597
  }
595
- class Ue extends w {
598
+ class at extends $ {
596
599
  constructor() {
597
600
  super();
598
601
  C(this, "serviceIdentifier", new X());
@@ -603,19 +606,19 @@ class Ue extends w {
603
606
  this.supplementalFields = { ...this.supplementalFields, ...t };
604
607
  }
605
608
  normalizedSupplementalForGraphQL() {
606
- const { isFromLocalService: t } = this.supplementalFields, n = {};
607
- return t !== void 0 && (n.isFromLocalService = t), n;
609
+ const { isFromLocalService: t } = this.supplementalFields, s = {};
610
+ return t !== void 0 && (s.isFromLocalService = t), s;
608
611
  }
609
612
  async sendAppIdentifier() {
610
613
  this.serviceIdentifier.doSend({});
611
614
  }
612
- async doSend(t, n) {
613
- this.sendAppIdentifier(), this.send(t, n);
615
+ async doSend(t, s) {
616
+ this.sendAppIdentifier(), this.send(t, s);
614
617
  }
615
- async send(t, n) {
616
- l().sfDebug && console.log(" SENDING EXCEPTION...");
617
- const i = JSON.stringify(L.encode(n)), s = this.normalizedSupplementalForGraphQL(), g = this.getVariables({ exceptionMessage: t, traceJson: i, reentrancyGuardPreactive: !1, library: l().packageLibraryType, version: l().version, ...s });
618
- F(this.endpoint, this.operationName, this.getQuery(), g);
618
+ async send(t, s) {
619
+ d().sfDebug && console.log(" SENDING EXCEPTION...");
620
+ const r = JSON.stringify(Q.encode(s)), a = this.normalizedSupplementalForGraphQL(), o = this.getVariables({ exceptionMessage: t, traceJson: r, reentrancyGuardPreactive: !1, library: d().packageLibraryType, version: d().version, ...a });
621
+ W(this.endpoint, this.operationName, this.getQuery(), o);
619
622
  }
620
623
  getQuery() {
621
624
  return `
@@ -649,86 +652,87 @@ class Ue extends w {
649
652
  `;
650
653
  }
651
654
  }
652
- const ue = "getting request source code";
653
- var $ = ((o) => (o.UNKNOWN = "unknown", o.ANONYMOUS = "anonymous", o.NOT_CAPTURED = "not captured", o))($ || {});
654
- const Q = "http:", q = "https:";
655
- function ye() {
656
- return { capture_arguments: H(process.env.SF_FUNCSPAN_CAPTURE_ARGUMENTS, !0), capture_return_value: H(process.env.SF_FUNCSPAN_CAPTURE_RETURN_VALUE, !0), arg_limit_mb: parseInt(process.env.SF_FUNCSPAN_ARG_LIMIT_MB || "1", 10), return_limit_mb: parseInt(process.env.SF_FUNCSPAN_RETURN_LIMIT_MB || "1", 10), autocapture_all_child_functions: H(process.env.SF_FUNCSPAN_AUTOCAPTURE_ALL_CHILD_FUNCTIONS, !1), sample_rate: parseFloat(process.env.SF_FUNCSPAN_SAMPLE_RATE || "1.0"), enable_sampling: H(process.env.SF_FUNCSPAN_ENABLE_SAMPLING, !1), capture_sf_veritas: H(process.env.SF_FUNCSPAN_CAPTURE_SF_VERITAS, !1), parse_json_strings: H(process.env.SF_FUNCSPAN_PARSE_JSON_STRINGS, !1) };
655
+ const Ge = "getting request source code";
656
+ var M = ((n) => (n.UNKNOWN = "unknown", n.ANONYMOUS = "anonymous", n.NOT_CAPTURED = "not captured", n))(M || {});
657
+ const ie = "http:", ae = "https:";
658
+ function ke() {
659
+ return { capture_arguments: U(process.env.SF_FUNCSPAN_CAPTURE_ARGUMENTS, !0), capture_return_value: U(process.env.SF_FUNCSPAN_CAPTURE_RETURN_VALUE, !0), arg_limit_mb: parseInt(process.env.SF_FUNCSPAN_ARG_LIMIT_MB || "1", 10), return_limit_mb: parseInt(process.env.SF_FUNCSPAN_RETURN_LIMIT_MB || "1", 10), autocapture_all_child_functions: U(process.env.SF_FUNCSPAN_AUTOCAPTURE_ALL_CHILD_FUNCTIONS, !1), sample_rate: parseFloat(process.env.SF_FUNCSPAN_SAMPLE_RATE || "1.0"), enable_sampling: U(process.env.SF_FUNCSPAN_ENABLE_SAMPLING, !1), capture_sf_veritas: U(process.env.SF_FUNCSPAN_CAPTURE_SF_VERITAS, !1), parse_json_strings: U(process.env.SF_FUNCSPAN_PARSE_JSON_STRINGS, !1) };
657
660
  }
658
- function ot() {
661
+ function Ut() {
659
662
  return { capture_arguments: !1, capture_return_value: !1, arg_limit_mb: 1, return_limit_mb: 1, autocapture_all_child_functions: !1, sample_rate: 0, enable_sampling: !1, capture_sf_veritas: !1, parse_json_strings: !1 };
660
663
  }
661
- function Ke(o) {
664
+ function Ye(n) {
662
665
  try {
663
- const e = o.split("-");
666
+ const e = n.split("-");
664
667
  return e.length !== 9 ? (console.error(`[FuncSpan] Invalid header format: expected 9 parts, got ${e.length}`), null) : { capture_arguments: e[0] === "1", capture_return_value: e[1] === "1", arg_limit_mb: parseInt(e[2], 10), return_limit_mb: parseInt(e[3], 10), autocapture_all_child_functions: e[4] === "1", sample_rate: parseFloat(e[5]), enable_sampling: e[6] === "1", capture_sf_veritas: e[7] === "1", parse_json_strings: e[8] === "1" };
665
668
  } catch (e) {
666
- return console.error(`[FuncSpan] Failed to parse header override "${o}":`, e), null;
669
+ return console.error(`[FuncSpan] Failed to parse header override "${n}":`, e), null;
667
670
  }
668
671
  }
669
- function H(o, e) {
670
- if (!o) return e;
671
- const t = o.toLowerCase();
672
+ function U(n, e) {
673
+ if (!n) return e;
674
+ const t = n.toLowerCase();
672
675
  return t === "true" || t === "1" || t === "yes";
673
676
  }
674
- const se = new ie();
675
- function Te(o) {
676
- se.enterWith(o);
677
+ const Ce = new pe();
678
+ function ct(n) {
679
+ Ce.enterWith(n);
677
680
  }
678
681
  function Je() {
679
- return se.getStore();
682
+ return Ce.getStore();
680
683
  }
681
- function Xe() {
682
- se.enterWith(void 0);
684
+ function lt() {
685
+ Ce.enterWith(void 0);
683
686
  }
684
- function _(...o) {
687
+ function z(...n) {
685
688
  const e = {};
686
- for (const t of o) for (const n in t) t[n] !== void 0 && (e[n] = t[n]);
689
+ for (const t of n) for (const s in t) t[s] !== void 0 && (e[s] = t[s]);
687
690
  return e;
688
691
  }
689
- function ee(o, e) {
692
+ function J(n, e) {
690
693
  try {
691
- const t = JSON.stringify(o).length / 1048576;
692
- return t <= e ? o : { _truncated: !0, _originalSizeMB: t.toFixed(2), _limitMB: e, _preview: JSON.stringify(o).substring(0, 500) + "..." };
694
+ const t = JSON.stringify(n).length / 1048576;
695
+ return t <= e ? n : { _truncated: !0, _originalSizeMB: t.toFixed(2), _limitMB: e, _preview: JSON.stringify(n).substring(0, 500) + "..." };
693
696
  } catch {
694
- return { _error: "Failed to serialize data", _type: typeof o };
697
+ return { _error: "Failed to serialize data", _type: typeof n };
695
698
  }
696
699
  }
697
- let Ce = !1;
698
- function Ee() {
699
- const o = l().sfDebug;
700
- if (Ce) return void (o && console.log("[patchNodeHttpInbound] Already installed, skipping."));
700
+ const gt = Me(import.meta.url);
701
+ let Ze = !1;
702
+ function dt() {
703
+ const n = d().sfDebug;
704
+ if (Ze) return void (n && console.log("[patchNodeHttpInbound] Already installed, skipping."));
701
705
  let e;
702
- Ce = !0;
706
+ Ze = !0;
703
707
  try {
704
- e = require("node:http"), o && console.log("[patchNodeHttpInbound] node:http required successfully.");
705
- } catch (i) {
706
- return void console.error("Failed to require node:http:", i);
707
- }
708
- if (!e?.Server?.prototype) return void (o && console.log("[patchNodeHttpInbound] http.Server.prototype not found."));
709
- const t = e.Server.prototype, n = t.emit;
710
- n && !t.__sf_inbound_patched__ ? (Object.defineProperty(t, "__sf_inbound_patched__", { value: !0, enumerable: !1, configurable: !1, writable: !1 }), o && console.log("[patchNodeHttpInbound] Patching http.Server.prototype.emit."), t.emit = function(i, ...s) {
711
- if (i !== "request") return o && console.log(`[patchNodeHttpInbound] Passing through event: ${i}`), n.call(this, i, ...s);
712
- const g = s[0], r = s[1], a = (function(p) {
713
- const u = {};
714
- if (!p) return u;
715
- for (const [m, A] of Object.entries(p)) A != null && (Array.isArray(A) ? u[m.toLowerCase()] = A.join(", ") : u[m.toLowerCase()] = String(A));
716
- return u;
717
- })(g?.headers), c = a["x-sf3-rid"], d = a["x-sf3-functionspancaptureoverride"];
718
- o && (console.log("[patchNodeHttpInbound] Intercepted request event."), console.log("[patchNodeHttpInbound] Inbound headers:", a), console.log("[patchNodeHttpInbound] Trace header:", c), console.log("[patchNodeHttpInbound] FuncSpan override header:", d));
719
- const I = G.getInstance();
720
- I.setTraceId(c);
721
- const h = I.getTraceId();
722
- return o && console.log("[patchNodeHttpInbound] Context traceId set:", h), I.runWith({ inboundHeaders: a, ...c ? { traceId: c } : {} }, () => {
723
- c && I.setTraceId(c), d && (Te(d), o && console.log("[patchNodeHttpInbound] FuncSpan override set:", d)), o && console.log("[patchNodeHttpInbound] Running request handler in context.");
724
- const p = () => {
725
- o && console.log("[patchNodeHttpInbound] Response finished/closed for traceId:", I.getTraceId()), d && (Xe(), o && console.log("[patchNodeHttpInbound] FuncSpan override cleared"));
708
+ e = gt("node:http"), n && console.log("[patchNodeHttpInbound] node:http required successfully.");
709
+ } catch (r) {
710
+ return void console.error("Failed to require node:http:", r);
711
+ }
712
+ if (!e?.Server?.prototype) return void (n && console.log("[patchNodeHttpInbound] http.Server.prototype not found."));
713
+ const t = e.Server.prototype, s = t.emit;
714
+ s && !t.__sf_inbound_patched__ ? (Object.defineProperty(t, "__sf_inbound_patched__", { value: !0, enumerable: !1, configurable: !1, writable: !1 }), n && console.log("[patchNodeHttpInbound] Patching http.Server.prototype.emit."), t.emit = function(r, ...a) {
715
+ if (r !== "request") return n && console.log(`[patchNodeHttpInbound] Passing through event: ${r}`), s.call(this, r, ...a);
716
+ const o = a[0], i = a[1], c = (function(m) {
717
+ const p = {};
718
+ if (!m) return p;
719
+ for (const [h, f] of Object.entries(m)) f != null && (Array.isArray(f) ? p[h.toLowerCase()] = f.join(", ") : p[h.toLowerCase()] = String(f));
720
+ return p;
721
+ })(o?.headers), l = c["x-sf3-rid"], g = c["x-sf3-functionspancaptureoverride"];
722
+ n && (console.log("[patchNodeHttpInbound] Intercepted request event."), console.log("[patchNodeHttpInbound] Inbound headers:", c), console.log("[patchNodeHttpInbound] Trace header:", l), console.log("[patchNodeHttpInbound] FuncSpan override header:", g));
723
+ const u = v.getInstance();
724
+ u.setTraceId(l);
725
+ const I = u.getTraceId();
726
+ return n && console.log("[patchNodeHttpInbound] Context traceId set:", I), u.runWith({ inboundHeaders: c, ...l ? { traceId: l } : {} }, () => {
727
+ l && u.setTraceId(l), g && (ct(g), n && console.log("[patchNodeHttpInbound] FuncSpan override set:", g)), n && console.log("[patchNodeHttpInbound] Running request handler in context.");
728
+ const m = () => {
729
+ n && console.log("[patchNodeHttpInbound] Response finished/closed for traceId:", u.getTraceId()), g && (lt(), n && console.log("[patchNodeHttpInbound] FuncSpan override cleared"));
726
730
  };
727
- return r.on("finish", p), r.on("close", p), n.call(this, i, g, r);
731
+ return i.on("finish", m), i.on("close", m), s.call(this, r, o, i);
728
732
  });
729
- }) : o && console.log("[patchNodeHttpInbound] Already patched, skipping.");
733
+ }) : n && console.log("[patchNodeHttpInbound] Already patched, skipping.");
730
734
  }
731
- class _e extends oe {
735
+ class ut extends Ie {
732
736
  constructor() {
733
737
  super(), this.setOperationName("DomainsToNotPassHeaderTo");
734
738
  }
@@ -748,11 +752,11 @@ class _e extends oe {
748
752
  domains: $domains
749
753
  )
750
754
  }
751
- `, n = { apiKey: this.apiKey, serviceUuid: this.serviceUUID, domains: e };
752
- F(this.endpoint, this.operationName, t, n);
755
+ `, s = { apiKey: this.apiKey, serviceUuid: this.serviceUUID, domains: e };
756
+ W(this.endpoint, this.operationName, t, s);
753
757
  }
754
758
  }
755
- class De extends w {
759
+ class pt extends $ {
756
760
  constructor() {
757
761
  super();
758
762
  C(this, "serviceIdentifier", new X());
@@ -765,8 +769,8 @@ class De extends w {
765
769
  this.sendAppIdentifier(), this.send(t);
766
770
  }
767
771
  async send(t) {
768
- const { name: n, column: i, line: s, entrypoint: g, retryWithoutTraceId: r } = t, a = this.getVariables({ name: n, column: i, line: s, entrypoint: g, retryWithoutTraceId: r });
769
- F(this.endpoint, this.operationName, this.getQuery(), a);
772
+ const { name: s, column: r, line: a, entrypoint: o, retryWithoutTraceId: i } = t, c = this.getVariables({ name: s, column: r, line: a, entrypoint: o, retryWithoutTraceId: i });
773
+ W(this.endpoint, this.operationName, this.getQuery(), c);
770
774
  }
771
775
  getQuery() {
772
776
  return `
@@ -796,7 +800,7 @@ class De extends w {
796
800
  `;
797
801
  }
798
802
  }
799
- class $e extends w {
803
+ class It extends $ {
800
804
  constructor() {
801
805
  super();
802
806
  C(this, "serviceIdentifier", new X());
@@ -819,183 +823,188 @@ class $e extends w {
819
823
  `;
820
824
  }
821
825
  async send(t) {
822
- const n = { data: { ...t } };
823
- await F(this.endpoint, this.operationName, this.getQuery(), n);
826
+ const s = { data: { ...t } };
827
+ await W(this.endpoint, this.operationName, this.getQuery(), s);
824
828
  }
825
829
  }
826
- const te = [400, 403];
827
- class Le {
830
+ const ce = [400, 403];
831
+ class Ct {
828
832
  constructor(e = []) {
829
833
  C(this, "HEADER_TRACING", "X-Sf3-Rid");
830
834
  C(this, "HEADER_LOG_GUARD", "reentrancy_guard_logging_preactive");
831
835
  C(this, "HEADER_PRINT_GUARD", "reentrancy_guard_print_preactive");
832
836
  C(this, "HEADER_EXCEPTION_GUARD", "reentrancy_guard_exception_preactive");
833
837
  C(this, "contextManager");
834
- this.contextManager = G.getInstance(), e?.forEach((t) => {
838
+ this.contextManager = v.getInstance(), e?.forEach((t) => {
835
839
  typeof t == "string" && t.trim() && this.contextManager.getExcludedDomains().add(t);
836
- }), l().sfDebug && console.log("[RequestInterceptor] Initialized with static excluded domains.");
840
+ }), d().sfDebug && console.log("[RequestInterceptor] Initialized with static excluded domains.");
837
841
  }
838
842
  extractIdsFromTraceHeader(e, t = this.HEADER_TRACING) {
839
- let n;
840
- if (e instanceof Headers) n = e.get(t) ?? void 0;
843
+ let s;
844
+ if (e instanceof Headers) s = e.get(t) ?? void 0;
841
845
  else {
842
- const s = t.toLowerCase();
843
- for (const [g, r] of Object.entries(e)) if (g.toLowerCase() === s) {
844
- n = r;
846
+ const a = t.toLowerCase();
847
+ for (const [o, i] of Object.entries(e)) if (o.toLowerCase() === a) {
848
+ s = i;
845
849
  break;
846
850
  }
847
851
  }
848
- if (!n) return {};
849
- const i = n.split("/").filter(Boolean);
850
- return i.length < 3 ? {} : { sessionId: i[0], pageVisitId: i[1], requestId: i[i.length - 1] };
852
+ if (!s) return {};
853
+ const r = s.split("/").filter(Boolean);
854
+ return r.length < 3 ? {} : { sessionId: r[0], pageVisitId: r[1], requestId: r[r.length - 1] };
851
855
  }
852
856
  parseStackFrame(e) {
853
857
  const t = /\((.*):(\d+):(\d+)\)$/.exec(e.trim());
854
858
  if (!t) return null;
855
- const [, n, i, s] = t;
856
- return { filePath: n, line: parseInt(i, 10), column: parseInt(s, 10) };
859
+ const [, s, r, a] = t;
860
+ return { filePath: s, line: parseInt(r, 10), column: parseInt(a, 10) };
857
861
  }
858
- async getOriginalPosition(e, t, n) {
859
- let i = { source: e, line: t, column: n, name: null };
860
- const s = e + ".map";
862
+ async getOriginalPosition(e, t, s) {
863
+ let r = { source: e, line: t, column: s, name: null };
864
+ const a = e + ".map";
861
865
  try {
862
- const g = JSON.parse(pe(s, "utf-8"));
863
- let r = (await new he.SourceMapConsumer(g)).originalPositionFor({ line: t, column: n });
864
- r.source && (i = r);
865
- } catch (g) {
866
- l().sfDebug && console.error(`Could not read/parse map file at ${s}:`, g);
866
+ const o = JSON.parse(Re(a, "utf-8"));
867
+ let i = (await new He.SourceMapConsumer(o)).originalPositionFor({ line: t, column: s });
868
+ i.source && (r = i);
869
+ } catch (o) {
870
+ d().sfDebug && console.error(`Could not read/parse map file at ${a}:`, o);
867
871
  }
868
- return { originalPos: i };
869
- }
870
- captureFirstUserLines(e, t = 10, n = !1) {
871
- const i = l().sfDebug ? 10 : t, s = Error.stackTraceLimit;
872
- Error.stackTraceLimit = Math.max(s, i);
873
- const g = new Error(ue);
874
- ue in Error && Error.captureStackTrace(g, this.captureFirstUserLines);
875
- const r = g.stack || "";
876
- Error.stackTraceLimit = s;
877
- const a = r.split(`
878
- `).slice(1), c = [];
879
- for (const d of a)
880
- if (!(d.includes("node:internal") || d.includes("internal/modules") || d.includes("internal/process") || d.includes("node_modules") || d.includes(".next/server/chunks") || d.includes("RequestInterceptor") || d.includes("contextManager") || d.includes("setupConfig")) && (c.push(d.trim()), c.length >= t)) break;
881
- for (const d of c) {
882
- const I = this.parseStackFrame(d);
883
- I ? (async () => {
884
- const { originalPos: h } = await this.getOriginalPosition(I.filePath, I.line, I.column);
885
- if (h) {
886
- l().sfDebug && console.log("[RequestInterceptor] First user code line:", h);
887
- const p = { line: h.line?.toString() || $.UNKNOWN, column: h.column?.toString() || $.NOT_CAPTURED, name: h.name || $.NOT_CAPTURED, entrypoint: h.source, retryWithoutTraceId: n };
888
- e.doSend(p);
872
+ return { originalPos: r };
873
+ }
874
+ captureFirstUserLines(e, t = 10, s = !1) {
875
+ const r = d().sfDebug ? 10 : t, a = Error.stackTraceLimit;
876
+ Error.stackTraceLimit = Math.max(a, r);
877
+ const o = new Error(Ge);
878
+ Ge in Error && Error.captureStackTrace(o, this.captureFirstUserLines);
879
+ const i = o.stack || "";
880
+ Error.stackTraceLimit = a;
881
+ const c = i.split(`
882
+ `).slice(1), l = [];
883
+ for (const g of c)
884
+ if (!(g.includes("node:internal") || g.includes("internal/modules") || g.includes("internal/process") || g.includes("node_modules") || g.includes(".next/server/chunks") || g.includes("RequestInterceptor") || g.includes("contextManager") || g.includes("setupConfig")) && (l.push(g.trim()), l.length >= t)) break;
885
+ for (const g of l) {
886
+ const u = this.parseStackFrame(g);
887
+ u ? (async () => {
888
+ const { originalPos: I } = await this.getOriginalPosition(u.filePath, u.line, u.column);
889
+ if (I) {
890
+ d().sfDebug && console.log("[RequestInterceptor] First user code line:", I);
891
+ const m = { line: I.line?.toString() || M.UNKNOWN, column: I.column?.toString() || M.NOT_CAPTURED, name: I.name || M.NOT_CAPTURED, entrypoint: I.source, retryWithoutTraceId: s };
892
+ e.doSend(m);
889
893
  }
890
- })() : l().sfDebug && console.error("Could not parse stack line:", d);
894
+ })() : d().sfDebug && console.error("Could not parse stack line:", g);
891
895
  }
892
896
  }
893
897
  addReentrancyGuardHeaders(e) {
894
898
  e.set(this.HEADER_LOG_GUARD, "true"), e.set(this.HEADER_PRINT_GUARD, "true"), e.set(this.HEADER_EXCEPTION_GUARD, "true");
895
899
  }
896
900
  shouldPropagateHeaders(e) {
897
- return !Ae.some((t) => new RegExp(`^${t.replace(/\*/g, ".*")}$`).test(e));
901
+ return !Ue.some((t) => new RegExp(`^${t.replace(/\*/g, ".*")}$`).test(e));
898
902
  }
899
903
  addTracingHeaders(e, t) {
900
- const n = new URL(t).hostname, i = this.shouldPropagateHeaders(n);
901
- return i ? this.addTracingHeader(e, t) : l().sfDebug && console.error(`[RequestInterceptor] Excluded domain: ${n}`), i;
904
+ const s = new URL(t).hostname, r = this.shouldPropagateHeaders(s);
905
+ return r ? this.addTracingHeader(e, t) : d().sfDebug && console.error(`[RequestInterceptor] Excluded domain: ${s}`), r;
902
906
  }
903
907
  addTracingHeader(e, t) {
904
- const n = this.contextManager.getOrSetSfTraceId(), i = this.contextManager.getOrSetPageVisitUUID(), s = R();
905
- e.set(this.HEADER_TRACING, `${n}/${i}/${s}`), l().sfDebug && console.log(`[RequestInterceptor] Added tracing header for ${t}`);
908
+ const s = Je();
909
+ if (s) {
910
+ const i = Ye(s);
911
+ if (i && i.sample_rate === 0) return void (d().sfDebug && console.log(`[RequestInterceptor] Function span tracking disabled (sample_rate=0), skipping tracing header for ${t}`));
912
+ }
913
+ const r = this.contextManager.getOrSetSfTraceId(), a = this.contextManager.getOrSetPageVisitUUID(), o = w();
914
+ e.set(this.HEADER_TRACING, `${r}/${a}/${o}`), d().sfDebug && console.log(`[RequestInterceptor] Added tracing header for ${t}`);
906
915
  }
907
916
  patchFetch(e, t) {
908
- const n = globalThis.fetch;
909
- typeof n == "function" ? globalThis.fetch = async (i, s) => {
910
- const g = new Headers(s?.headers);
911
- if (g.get(this.HEADER_LOG_GUARD) === "true" || g.get(this.HEADER_PRINT_GUARD) === "true" || g.get(this.HEADER_EXCEPTION_GUARD) === "true") return n(i, s);
917
+ const s = globalThis.fetch;
918
+ typeof s == "function" ? globalThis.fetch = async (r, a) => {
919
+ const o = new Headers(a?.headers);
920
+ if (o.get(this.HEADER_LOG_GUARD) === "true" || o.get(this.HEADER_PRINT_GUARD) === "true" || o.get(this.HEADER_EXCEPTION_GUARD) === "true") return s(r, a);
912
921
  this.captureFirstUserLines(e);
913
- const r = Date.now();
914
- let a;
915
- typeof i == "string" || i instanceof URL ? a = i.toString() : i instanceof Request ? (a = i.url, i.headers.forEach((u, m) => {
916
- g.set(m, u);
917
- })) : l().sfDebug && console.error("[Sailfish RequestInterceptor] Invalid fetch input."), l().sfDebug && console.log("[RequestInterceptor] Fetching request to:", a);
918
- const c = new URL(a).hostname, d = new Headers(g), I = this.addTracingHeaders(g, a), h = { ...s, headers: g };
919
- let p;
922
+ const i = Date.now();
923
+ let c;
924
+ typeof r == "string" || r instanceof URL ? c = r.toString() : r instanceof Request ? (c = r.url, r.headers.forEach((p, h) => {
925
+ o.set(h, p);
926
+ })) : d().sfDebug && console.error("[Sailfish RequestInterceptor] Invalid fetch input."), d().sfDebug && console.log("[RequestInterceptor] Fetching request to:", c);
927
+ const l = new URL(c).hostname, g = new Headers(o), u = this.addTracingHeaders(o, c), I = { ...a, headers: o };
928
+ let m;
920
929
  try {
921
- let u = !1;
922
- this.addTracingHeaders(d, a), p = await n(a, h), I && te.includes(p.status) ? (p = await n(a, { ...s, headers: d }), u = !0, this.captureFirstUserLines(e, 10, u)) : this.contextManager.addSupportedDomains(c);
923
- const m = Date.now();
924
- l().sfDebug && console.log(`[RequestInterceptor] Fetch completed: ${a}, Status: ${p.status}, Duration: ${m - r}ms`);
925
- const { sessionId: A, pageVisitId: y, requestId: b } = this.extractIdsFromTraceHeader(g);
926
- return t.doSend({ apiKey: l().apiKey, requestId: b, pageVisitId: y, recordingSessionId: A, serviceUuid: l().serviceUUID, timestampStart: r.toString(), timestampEnd: m.toString(), responseCode: p.status, success: !0, error: null, url: a, method: h.method || "GET", retryWithoutTraceId: u, parentSpanId: M() }), p;
927
- } catch (u) {
928
- const m = Date.now();
929
- l().sfDebug && console.error(`[RequestInterceptor] Fetch failed: ${a}, Error: ${u}, Duration: ${m - r}ms`);
930
+ let p = !1;
931
+ this.addTracingHeaders(g, c), m = await s(c, I), u && ce.includes(m.status) ? (m = await s(c, { ...a, headers: g }), p = !0, this.captureFirstUserLines(e, 10, p)) : this.contextManager.addSupportedDomains(l);
932
+ const h = Date.now();
933
+ d().sfDebug && console.log(`[RequestInterceptor] Fetch completed: ${c}, Status: ${m.status}, Duration: ${h - i}ms`);
934
+ const { sessionId: f, pageVisitId: S, requestId: b } = this.extractIdsFromTraceHeader(o);
935
+ return t.doSend({ apiKey: d().apiKey, requestId: b, pageVisitId: S, recordingSessionId: f, serviceUuid: d().serviceUUID, timestampStart: i.toString(), timestampEnd: h.toString(), responseCode: m.status, success: !0, error: null, url: c, method: I.method || "GET", retryWithoutTraceId: p, parentSpanId: oe() }), m;
936
+ } catch (p) {
937
+ const h = Date.now();
938
+ d().sfDebug && console.error(`[RequestInterceptor] Fetch failed: ${c}, Error: ${p}, Duration: ${h - i}ms`);
930
939
  }
931
- } : l().sfDebug && console.error("[RequestInterceptor] Fetch not available.");
940
+ } : d().sfDebug && console.error("[RequestInterceptor] Fetch not available.");
932
941
  }
933
942
  patchHttp(e, t) {
934
- if (l().sfDebug && console.log("[RequestInterceptor] Initializing HTTP/HTTPS request patch..."), !N || typeof N.request != "function") return void (l().sfDebug && console.log("[RequestInterceptor] HTTP/HTTPS not available."));
935
- const n = N.request.bind(N), i = N.request.bind(N);
936
- N.request = function(s, g) {
937
- let r;
943
+ if (d().sfDebug && console.log("[RequestInterceptor] Initializing HTTP/HTTPS request patch..."), !B || typeof B.request != "function") return void (d().sfDebug && console.log("[RequestInterceptor] HTTP/HTTPS not available."));
944
+ const s = B.request.bind(B), r = B.request.bind(B);
945
+ B.request = function(a, o) {
946
+ let i;
938
947
  try {
939
- if (typeof s == "string") {
940
- const c = new URL(s);
941
- r = { protocol: c.protocol || Q, hostname: c.hostname, path: c.pathname + c.search, headers: {} };
942
- } else s instanceof URL ? r = { protocol: s.protocol || Q, hostname: s.hostname, path: s.pathname + s.search, headers: {} } : (r = { ...s }, r.protocol || (r.protocol = Q));
943
- if (r.headers) {
944
- const c = `${r.protocol}//${r.hostname}`;
945
- this.addTracingHeaders(r.headers, c), this.captureFirstUserLines(e);
946
- } else l().sfDebug && console.warn("[RequestInterceptor] No headers found in HTTP request options. Skipping header addition.");
947
- } catch (c) {
948
- throw l().sfDebug && console.error("[RequestInterceptor] Error while processing HTTP request options:", c), c;
948
+ if (typeof a == "string") {
949
+ const l = new URL(a);
950
+ i = { protocol: l.protocol || ie, hostname: l.hostname, path: l.pathname + l.search, headers: {} };
951
+ } else a instanceof URL ? i = { protocol: a.protocol || ie, hostname: a.hostname, path: a.pathname + a.search, headers: {} } : (i = { ...a }, i.protocol || (i.protocol = ie));
952
+ if (i.headers) {
953
+ const l = `${i.protocol}//${i.hostname}`;
954
+ this.addTracingHeaders(i.headers, l), this.captureFirstUserLines(e);
955
+ } else d().sfDebug && console.warn("[RequestInterceptor] No headers found in HTTP request options. Skipping header addition.");
956
+ } catch (l) {
957
+ throw d().sfDebug && console.error("[RequestInterceptor] Error while processing HTTP request options:", l), l;
949
958
  }
950
- let a = !1;
951
- return n(r, (c) => {
952
- const d = `${r.protocol}//${r.hostname}`;
953
- if (r.headers && this.shouldPropagateHeaders(new URL(d).hostname) && te.includes(c.statusCode || 0)) {
954
- r.hostname;
955
- const u = { ...r, headers: { ...r.headers } };
956
- delete u.headers[this.HEADER_TRACING], n(u, g), a = !0, this.captureFirstUserLines(e, 10, a);
959
+ let c = !1;
960
+ return s(i, (l) => {
961
+ const g = `${i.protocol}//${i.hostname}`;
962
+ if (i.headers && this.shouldPropagateHeaders(new URL(g).hostname) && ce.includes(l.statusCode || 0)) {
963
+ i.hostname;
964
+ const p = { ...i, headers: { ...i.headers } };
965
+ delete p.headers[this.HEADER_TRACING], s(p, o), c = !0, this.captureFirstUserLines(e, 10, c);
957
966
  }
958
- const { sessionId: I, pageVisitId: h, requestId: p } = this.extractIdsFromTraceHeader(r.headers);
959
- t.doSend({ apiKey: l().apiKey, requestId: p, pageVisitId: h, recordingSessionId: I, serviceUuid: l().serviceUUID, timestampStart: Date.now().toString(), timestampEnd: Date.now().toString(), responseCode: c.statusCode || 0, success: !!c.statusCode && c.statusCode < 400, error: null, url: d, method: r.method || "GET", retryWithoutTraceId: a, parentSpanId: M() }), g?.(c);
967
+ const { sessionId: u, pageVisitId: I, requestId: m } = this.extractIdsFromTraceHeader(i.headers);
968
+ t.doSend({ apiKey: d().apiKey, requestId: m, pageVisitId: I, recordingSessionId: u, serviceUuid: d().serviceUUID, timestampStart: Date.now().toString(), timestampEnd: Date.now().toString(), responseCode: l.statusCode || 0, success: !!l.statusCode && l.statusCode < 400, error: null, url: g, method: i.method || "GET", retryWithoutTraceId: c, parentSpanId: oe() }), o?.(l);
960
969
  });
961
- }, N.request = function(s, g) {
962
- let r;
970
+ }, B.request = function(a, o) {
971
+ let i;
963
972
  try {
964
- if (typeof s == "string") {
965
- const c = new URL(s);
966
- r = { protocol: c.protocol || q, hostname: c.hostname, path: c.pathname + c.search, headers: {} };
967
- } else s instanceof URL ? r = { protocol: s.protocol || q, hostname: s.hostname, path: s.pathname + s.search, headers: {} } : (r = { ...s }, r.protocol || (r.protocol = q));
968
- if (r.headers) {
969
- const c = `${r.protocol}//${r.hostname}`;
970
- this.addTracingHeaders(r.headers, c);
971
- } else l().sfDebug && console.warn("[RequestInterceptor] No headers found in HTTPS request options. Skipping header addition.");
972
- } catch (c) {
973
- throw l().sfDebug && console.error("[RequestInterceptor] Error while processing HTTPS request options:", c), c;
973
+ if (typeof a == "string") {
974
+ const l = new URL(a);
975
+ i = { protocol: l.protocol || ae, hostname: l.hostname, path: l.pathname + l.search, headers: {} };
976
+ } else a instanceof URL ? i = { protocol: a.protocol || ae, hostname: a.hostname, path: a.pathname + a.search, headers: {} } : (i = { ...a }, i.protocol || (i.protocol = ae));
977
+ if (i.headers) {
978
+ const l = `${i.protocol}//${i.hostname}`;
979
+ this.addTracingHeaders(i.headers, l);
980
+ } else d().sfDebug && console.warn("[RequestInterceptor] No headers found in HTTPS request options. Skipping header addition.");
981
+ } catch (l) {
982
+ throw d().sfDebug && console.error("[RequestInterceptor] Error while processing HTTPS request options:", l), l;
974
983
  }
975
- let a = !1;
976
- return i(r, (c) => {
977
- const d = `${r.protocol}//${r.hostname}`;
978
- if (r.headers && this.shouldPropagateHeaders(new URL(d).hostname) && te.includes(c.statusCode || 0)) {
979
- const u = { ...r, headers: { ...r.headers } };
980
- delete u.headers[this.HEADER_TRACING], i(u, g), a = !0, this.captureFirstUserLines(e, 10, a);
984
+ let c = !1;
985
+ return r(i, (l) => {
986
+ const g = `${i.protocol}//${i.hostname}`;
987
+ if (i.headers && this.shouldPropagateHeaders(new URL(g).hostname) && ce.includes(l.statusCode || 0)) {
988
+ const p = { ...i, headers: { ...i.headers } };
989
+ delete p.headers[this.HEADER_TRACING], r(p, o), c = !0, this.captureFirstUserLines(e, 10, c);
981
990
  }
982
- const { sessionId: I, pageVisitId: h, requestId: p } = this.extractIdsFromTraceHeader(r.headers);
983
- t.doSend({ apiKey: l().apiKey, requestId: p, pageVisitId: h, recordingSessionId: I, serviceUuid: l().serviceUUID, timestampStart: Date.now().toString(), timestampEnd: Date.now().toString(), responseCode: c.statusCode || 0, success: !!c.statusCode && c.statusCode < 400, error: null, url: d, method: r.method || "GET", retryWithoutTraceId: a, parentSpanId: M() }), g?.(c);
991
+ const { sessionId: u, pageVisitId: I, requestId: m } = this.extractIdsFromTraceHeader(i.headers);
992
+ t.doSend({ apiKey: d().apiKey, requestId: m, pageVisitId: I, recordingSessionId: u, serviceUuid: d().serviceUUID, timestampStart: Date.now().toString(), timestampEnd: Date.now().toString(), responseCode: l.statusCode || 0, success: !!l.statusCode && l.statusCode < 400, error: null, url: g, method: i.method || "GET", retryWithoutTraceId: c, parentSpanId: oe() }), o?.(l);
984
993
  });
985
- }, l().sfDebug && console.log("✅ HTTP and HTTPS request methods patched globally.");
994
+ }, d().sfDebug && console.log("✅ HTTP and HTTPS request methods patched globally.");
986
995
  }
987
996
  tryPatch(e, t) {
988
997
  try {
989
998
  require.resolve(t), e(), console.log(`[RequestInterceptor] Patched ${t}`);
990
- } catch (n) {
991
- console.warn(`[RequestInterceptor] Could not patch ${t}: ${n.message}`);
999
+ } catch (s) {
1000
+ console.warn(`[RequestInterceptor] Could not patch ${t}: ${s.message}`);
992
1001
  }
993
1002
  }
994
1003
  getExcludedDomains() {
995
1004
  return [...this.contextManager.getExcludedDomains()];
996
1005
  }
997
1006
  }
998
- class ze extends oe {
1007
+ class mt extends Ie {
999
1008
  constructor() {
1000
1009
  super(), this.setOperationName("UpdateServiceDetails");
1001
1010
  }
@@ -1023,11 +1032,11 @@ class ze extends oe {
1023
1032
  gitSha: $gitSha,
1024
1033
  )
1025
1034
  }
1026
- `, t = this.getVariables({ serviceIdentifier: l().serviceIdentifier, serviceVersion: l().serviceVersion, serviceAdditionalMetadata: l().serviceAdditionalMetadata, gitSha: l().gitSha || "" });
1027
- F(this.endpoint, this.operationName, e, t);
1035
+ `, t = this.getVariables({ serviceIdentifier: d().serviceIdentifier, serviceVersion: d().serviceVersion, serviceAdditionalMetadata: d().serviceAdditionalMetadata, gitSha: d().gitSha || "" });
1036
+ W(this.endpoint, this.operationName, e, t);
1028
1037
  }
1029
1038
  }
1030
- class xe {
1039
+ class ht {
1031
1040
  constructor(e = [process.cwd()], t = !1) {
1032
1041
  C(this, "rootPaths");
1033
1042
  C(this, "fileConfigs", /* @__PURE__ */ new Map());
@@ -1040,163 +1049,391 @@ class xe {
1040
1049
  async loadAllConfigs() {
1041
1050
  this.debug && console.log("[FuncSpan ConfigLoader] Scanning for .sailfish files in:", this.rootPaths);
1042
1051
  const e = [];
1043
- for (const t of this.rootPaths) k.existsSync(t) ? await this._walkDirectory(t, e) : this.debug && console.log(`[FuncSpan ConfigLoader] Root path does not exist: ${t}`);
1052
+ for (const t of this.rootPaths) te.existsSync(t) ? await this._walkDirectory(t, e) : this.debug && console.log(`[FuncSpan ConfigLoader] Root path does not exist: ${t}`);
1044
1053
  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");
1045
1054
  for (const t of e) await this._loadConfigFile(t);
1046
1055
  await this._resolveInheritance(), this.debug && console.log(`[FuncSpan ConfigLoader] Loaded ${this.fileConfigs.size} file configs, ${this.functionConfigs.size} function configs`);
1047
1056
  }
1048
1057
  getConfig(e, t) {
1049
- const n = this.hasSailfishFiles ? ye() : { capture_arguments: !1, capture_return_value: !1, arg_limit_mb: 1, return_limit_mb: 1, autocapture_all_child_functions: !1, sample_rate: 0, enable_sampling: !1, capture_sf_veritas: !1, parse_json_strings: !1 }, i = this._getDirectoryConfig(e), s = v.normalize(e), g = this.fileConfigs.get(s) || {};
1050
- let r = {};
1058
+ const s = this.hasSailfishFiles ? ke() : { capture_arguments: !1, capture_return_value: !1, arg_limit_mb: 1, return_limit_mb: 1, autocapture_all_child_functions: !1, sample_rate: 0, enable_sampling: !1, capture_sf_veritas: !1, parse_json_strings: !1 }, r = this._getDirectoryConfig(e), a = G.normalize(e), o = this.fileConfigs.get(a) || {};
1059
+ let i = {};
1051
1060
  if (t) {
1052
- const a = this.functionConfigs.get(s);
1053
- a && (r = a.get(t) || {});
1061
+ const c = this.functionConfigs.get(a);
1062
+ c && (i = c.get(t) || {});
1054
1063
  }
1055
- return _(n, i, g, r);
1064
+ return z(s, r, o, i);
1056
1065
  }
1057
1066
  async _walkDirectory(e, t) {
1058
1067
  try {
1059
- const n = k.readdirSync(e, { withFileTypes: !0 });
1060
- for (const i of n) {
1061
- const s = v.join(e, i.name);
1062
- i.isFile() && i.name === ".sailfish" ? t.push(s) : i.name === "node_modules" || i.isDirectory() && i.name.startsWith(".") && i.name !== ".sailfish" || i.isDirectory() && await this._walkDirectory(s, t);
1068
+ const s = te.readdirSync(e, { withFileTypes: !0 });
1069
+ for (const r of s) {
1070
+ const a = G.join(e, r.name);
1071
+ r.isFile() && r.name === ".sailfish" ? t.push(a) : r.name === "node_modules" || r.isDirectory() && r.name.startsWith(".") && r.name !== ".sailfish" || r.isDirectory() && await this._walkDirectory(a, t);
1063
1072
  }
1064
- } catch (n) {
1065
- this.debug && console.error(`[FuncSpan ConfigLoader] Error walking directory ${e}:`, n);
1073
+ } catch (s) {
1074
+ this.debug && console.error(`[FuncSpan ConfigLoader] Error walking directory ${e}:`, s);
1066
1075
  }
1067
1076
  }
1068
1077
  async _loadConfigFile(e) {
1069
1078
  try {
1070
- const t = k.readFileSync(e, "utf-8"), n = v.dirname(e);
1071
- let i = null;
1079
+ const t = te.readFileSync(e, "utf-8"), s = G.dirname(e);
1080
+ let r = null;
1072
1081
  try {
1073
- i = JSON.parse(t);
1082
+ r = JSON.parse(t);
1074
1083
  } catch {
1075
1084
  try {
1076
- i = require("js-yaml").load(t);
1077
- } catch (s) {
1078
- return void (this.debug && console.error(`[FuncSpan ConfigLoader] Failed to parse ${e} as JSON or YAML:`, s));
1085
+ r = require("js-yaml").load(t);
1086
+ } catch (a) {
1087
+ return void (this.debug && console.error(`[FuncSpan ConfigLoader] Failed to parse ${e} as JSON or YAML:`, a));
1079
1088
  }
1080
1089
  }
1081
- if (!i) return;
1082
- i.default && this.directoryConfigs.set(n, i.default), i.files && await this._expandFileGlobs(n, i.files, i.default || {}), i.functions && this._storeFunctionConfigs(n, i.functions, i.default || {}), this.debug && (console.log(`[FuncSpan ConfigLoader] Loaded config from ${e}`), console.log(`[FuncSpan ConfigLoader] Directory: ${n}`), console.log(`[FuncSpan ConfigLoader] Has default: ${!!i.default}`), console.log(`[FuncSpan ConfigLoader] File patterns: ${Object.keys(i.files || {}).length}`), console.log(`[FuncSpan ConfigLoader] Functions: ${Object.keys(i.functions || {}).length}`));
1090
+ if (!r) return;
1091
+ 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}`));
1083
1092
  } catch (t) {
1084
1093
  this.debug && console.error(`[FuncSpan ConfigLoader] Error loading ${e}:`, t);
1085
1094
  }
1086
1095
  }
1087
- async _expandFileGlobs(e, t, n) {
1088
- for (const [i, s] of Object.entries(t)) try {
1089
- const g = v.join(e, i), r = await ve(g, { absolute: !0, nodir: !0, ignore: ["**/node_modules/**", "**/.git/**"] });
1090
- this.debug && console.log(`[FuncSpan ConfigLoader] Pattern '${i}' matched ${r.length} files`);
1091
- for (const a of r) {
1092
- const c = v.normalize(a), d = _(n, s);
1093
- this.fileConfigs.set(c, d), this.debug && r.length <= 5 && console.log(`[FuncSpan ConfigLoader] - ${a}`);
1096
+ async _expandFileGlobs(e, t, s) {
1097
+ for (const [r, a] of Object.entries(t)) try {
1098
+ const o = G.join(e, r), i = await je(o, { absolute: !0, nodir: !0, ignore: ["**/node_modules/**", "**/.git/**"] });
1099
+ this.debug && console.log(`[FuncSpan ConfigLoader] Pattern '${r}' matched ${i.length} files`);
1100
+ for (const c of i) {
1101
+ const l = G.normalize(c), g = z(s, a);
1102
+ this.fileConfigs.set(l, g), this.debug && i.length <= 5 && console.log(`[FuncSpan ConfigLoader] - ${c}`);
1094
1103
  }
1095
- } catch (g) {
1096
- this.debug && console.error(`[FuncSpan ConfigLoader] Error expanding glob '${i}':`, g);
1104
+ } catch (o) {
1105
+ this.debug && console.error(`[FuncSpan ConfigLoader] Error expanding glob '${r}':`, o);
1097
1106
  }
1098
1107
  }
1099
- _storeFunctionConfigs(e, t, n) {
1100
- for (const [i, s] of Object.entries(t)) {
1101
- const g = i.split("::");
1102
- if (g.length !== 2) {
1103
- this.debug && console.warn(`[FuncSpan ConfigLoader] Invalid function pattern '${i}' (expected format: 'file.ts::functionName')`);
1108
+ _storeFunctionConfigs(e, t, s) {
1109
+ for (const [r, a] of Object.entries(t)) {
1110
+ const o = r.split("::");
1111
+ if (o.length !== 2) {
1112
+ this.debug && console.warn(`[FuncSpan ConfigLoader] Invalid function pattern '${r}' (expected format: 'file.ts::functionName')`);
1104
1113
  continue;
1105
1114
  }
1106
- const [r, a] = g, c = v.normalize(v.join(e, r));
1107
- this.functionConfigs.has(c) || this.functionConfigs.set(c, /* @__PURE__ */ new Map());
1108
- const d = this.functionConfigs.get(c), I = _(n, s);
1109
- d.set(a, I), this.debug && console.log(`[FuncSpan ConfigLoader] Function config: ${c}::${a}`);
1115
+ const [i, c] = o, l = G.normalize(G.join(e, i));
1116
+ this.functionConfigs.has(l) || this.functionConfigs.set(l, /* @__PURE__ */ new Map());
1117
+ const g = this.functionConfigs.get(l), u = z(s, a);
1118
+ g.set(c, u), this.debug && console.log(`[FuncSpan ConfigLoader] Function config: ${l}::${c}`);
1110
1119
  }
1111
1120
  }
1112
1121
  async _resolveInheritance() {
1113
1122
  }
1114
1123
  _getDirectoryConfig(e) {
1115
- let t = v.dirname(v.normalize(e));
1116
- const n = [];
1117
- for (; t && t !== v.dirname(t); ) {
1118
- const i = this.directoryConfigs.get(t);
1119
- i && n.unshift(i), t = v.dirname(t);
1124
+ let t = G.dirname(G.normalize(e));
1125
+ const s = [];
1126
+ for (; t && t !== G.dirname(t); ) {
1127
+ const r = this.directoryConfigs.get(t);
1128
+ r && s.unshift(r), t = G.dirname(t);
1120
1129
  }
1121
- return n.reduce((i, s) => _(i, s), {});
1130
+ return s.reduce((r, a) => z(r, a), {});
1122
1131
  }
1123
1132
  }
1124
- let J = null;
1125
- async function ke(o, e) {
1126
- J = new xe(o, e), await J.loadAllConfigs();
1133
+ let D = null;
1134
+ async function ft(n, e) {
1135
+ D = new ht(n, e), await D.loadAllConfigs();
1127
1136
  }
1128
- function Oe(o, e) {
1129
- return J ? J.getConfig(o, e) : (process.env.SF_DEBUG === "true" && console.log("[FuncSpan ConfigLoader] Config loader not initialized, using env config for worker process"), ye());
1137
+ function bt(n, e) {
1138
+ return D ? D.getConfig(n, e) : (process.env.SF_DEBUG === "true" && console.log("[FuncSpan ConfigLoader] Config loader not initialized, using env config for worker process"), ke());
1130
1139
  }
1131
- function Pe() {
1132
- return J !== null;
1140
+ function At() {
1141
+ return D !== null;
1133
1142
  }
1134
- function st(o) {
1135
- if (!o || !o.apiKey) {
1136
- const i = `The required API Key is not provided: ${JSON.stringify(o)}`;
1137
- console.error(i);
1138
- }
1139
- const { config: e } = We(o);
1140
- if (e.sfDebug && console.log("Updated configuration after applying options:", e), !e.apiKey || !e.apiGraphqlEndpoint) {
1141
- const i = `The required config is not provided: ${JSON.stringify(e)}`;
1142
- throw console.error(i), new Error(i);
1143
+ function V(n, e) {
1144
+ const t = process.env[n];
1145
+ return t === void 0 ? e : t === "true" || t === "1";
1146
+ }
1147
+ function Be(n, e) {
1148
+ const t = process.env[n];
1149
+ if (t === void 0) return e;
1150
+ const s = parseFloat(t);
1151
+ return isNaN(s) ? e : s;
1152
+ }
1153
+ function me() {
1154
+ return { enabled: V("SF_WORKER_POOL_ENABLED", !0), trackFs: V("SF_WORKER_POOL_TRACK_FS", !1), trackDns: V("SF_WORKER_POOL_TRACK_DNS", !0), trackCrypto: V("SF_WORKER_POOL_TRACK_CRYPTO", !1), trackZlib: V("SF_WORKER_POOL_TRACK_ZLIB", !1), captureArguments: V("SF_WORKER_POOL_CAPTURE_ARGUMENTS", !0), captureReturnValue: V("SF_WORKER_POOL_CAPTURE_RETURN_VALUE", !0), argLimitMb: Be("SF_WORKER_POOL_ARG_LIMIT_MB", 1), returnLimitMb: Be("SF_WORKER_POOL_RETURN_LIMIT_MB", 1) };
1155
+ }
1156
+ function O(n) {
1157
+ const e = me();
1158
+ if (!e.enabled) return !1;
1159
+ switch (n) {
1160
+ case "fs":
1161
+ return e.trackFs;
1162
+ case "dns":
1163
+ return e.trackDns;
1164
+ case "crypto":
1165
+ return e.trackCrypto;
1166
+ case "zlib":
1167
+ return e.trackZlib;
1168
+ default:
1169
+ return !1;
1143
1170
  }
1144
- Pe() || ke(void 0, e.sfDebug).catch((i) => {
1145
- e.sfDebug && console.error("[FuncSpan] Failed to initialize config loader:", i);
1146
- });
1147
- const t = new oe();
1148
- t.setServiceUUID(e.serviceUUID), (function(i) {
1149
- function s(I, h) {
1150
- i.setOperationName("CollectLogs"), i.doSend([h, I]);
1171
+ }
1172
+ function De(n, e, t, s) {
1173
+ let r;
1174
+ try {
1175
+ switch (n) {
1176
+ case "fs":
1177
+ r = (function(a, o) {
1178
+ const i = {};
1179
+ switch (a) {
1180
+ case "readFile":
1181
+ case "writeFile":
1182
+ case "appendFile":
1183
+ i.path = String(o[0] || ""), o[1] && typeof o[1] == "object" ? (i.encoding = o[1].encoding || null, i.flag = o[1].flag || null) : typeof o[1] == "string" && (i.encoding = o[1]), a !== "writeFile" && a !== "appendFile" || (Buffer.isBuffer(o[1]) ? (i.dataType = "Buffer", i.dataSize = o[1].length) : typeof o[1] == "string" && (i.dataType = "string", i.dataSize = o[1].length));
1184
+ break;
1185
+ case "readdir":
1186
+ case "stat":
1187
+ case "lstat":
1188
+ case "access":
1189
+ case "chmod":
1190
+ case "mkdir":
1191
+ case "rmdir":
1192
+ case "unlink":
1193
+ i.path = String(o[0] || ""), o[1] && typeof o[1] == "object" && (i.options = { ...o[1] }, delete i.options.callback);
1194
+ break;
1195
+ case "rename":
1196
+ i.oldPath = String(o[0] || ""), i.newPath = String(o[1] || "");
1197
+ break;
1198
+ case "open":
1199
+ i.path = String(o[0] || ""), i.flags = o[1], i.mode = o[2];
1200
+ break;
1201
+ case "close":
1202
+ case "fstat":
1203
+ i.fd = o[0];
1204
+ break;
1205
+ case "read":
1206
+ case "write":
1207
+ i.fd = o[0], Buffer.isBuffer(o[1]) && (i.bufferSize = o[1].length), i.offset = o[2], i.length = o[3], i.position = o[4];
1208
+ break;
1209
+ default:
1210
+ i.argsCount = o.length - 1;
1211
+ }
1212
+ return i;
1213
+ })(e, t);
1214
+ break;
1215
+ case "dns":
1216
+ r = (function(a, o) {
1217
+ const i = {};
1218
+ switch (a) {
1219
+ case "lookup":
1220
+ i.hostname = String(o[0] || ""), typeof o[1] == "object" ? (i.family = o[1].family, i.all = o[1].all) : typeof o[1] == "number" && (i.family = o[1]);
1221
+ break;
1222
+ case "resolve":
1223
+ case "resolve4":
1224
+ case "resolve6":
1225
+ case "resolveAny":
1226
+ case "resolveMx":
1227
+ case "resolveNs":
1228
+ case "resolveTxt":
1229
+ i.hostname = String(o[0] || "");
1230
+ break;
1231
+ case "reverse":
1232
+ i.ip = String(o[0] || "");
1233
+ break;
1234
+ default:
1235
+ i.argsCount = o.length - 1;
1236
+ }
1237
+ return i;
1238
+ })(e, t);
1239
+ break;
1240
+ case "crypto":
1241
+ r = (function(a, o) {
1242
+ const i = {};
1243
+ switch (a) {
1244
+ case "pbkdf2":
1245
+ i.passwordType = typeof o[0], i.saltType = typeof o[1], i.iterations = o[2], i.keylen = o[3], i.digest = o[4];
1246
+ break;
1247
+ case "scrypt":
1248
+ i.passwordType = typeof o[0], i.saltType = typeof o[1], i.keylen = o[2], typeof o[3] == "object" && (i.N = o[3].N, i.r = o[3].r, i.p = o[3].p);
1249
+ break;
1250
+ case "randomBytes":
1251
+ i.size = o[0];
1252
+ break;
1253
+ case "generateKeyPair":
1254
+ i.type = o[0], typeof o[1] == "object" && (i.modulusLength = o[1].modulusLength, i.namedCurve = o[1].namedCurve);
1255
+ break;
1256
+ default:
1257
+ i.argsCount = o.length - 1;
1258
+ }
1259
+ return i;
1260
+ })(e, t);
1261
+ break;
1262
+ case "zlib":
1263
+ r = (function(a, o) {
1264
+ const i = {};
1265
+ return Buffer.isBuffer(o[0]) ? (i.inputType = "Buffer", i.inputSize = o[0].length) : typeof o[0] == "string" ? (i.inputType = "string", i.inputSize = o[0].length) : i.inputType = typeof o[0], o[1] && typeof o[1] == "object" && typeof o[1] != "function" && (i.options = { ...o[1] }), i;
1266
+ })(0, t);
1267
+ break;
1268
+ default:
1269
+ return null;
1151
1270
  }
1152
- const g = console.log.bind(console), r = console.error.bind(console), a = console.warn.bind(console), c = console.info.bind(console), d = console.debug.bind(console);
1153
- console.log = (...I) => {
1154
- s("INFO", I.join(" ")), g(...I);
1155
- }, console.error = (...I) => {
1156
- s("ERROR", I.join(" ")), r(...I);
1157
- }, console.warn = (...I) => {
1158
- s("WARN", I.join(" ")), a(...I);
1159
- }, console.info = (...I) => {
1160
- s("INFO", I.join(" ")), c(...I);
1161
- }, l().logLevel === "DEBUG" && (console.debug = (...I) => {
1162
- s("DEBUG", I.join(" ")), d(...I);
1163
- });
1164
- })(t), (function(i = []) {
1165
- const s = new Le(i);
1166
- new _e().doSend(s.getExcludedDomains());
1167
- const g = new De(), r = new $e();
1168
- s.patchFetch(g, r), s.patchHttp(g, r);
1169
- })(e.domainsToNotPropagateHeadersTo);
1170
- const n = new Ue();
1171
- n.setServiceUUID(e.serviceUUID), He(n), Ee(), new ze().send();
1271
+ return s > 0 ? J(r, s) : r;
1272
+ } catch {
1273
+ return { error: "Failed to capture arguments", argsCount: t.length - 1 };
1274
+ }
1172
1275
  }
1173
- function rt(o, e, t, n = !1) {
1174
- const i = l();
1175
- new be(i.apiKey).identify(o, e, t, n);
1276
+ function Xe(n, e, t, s) {
1277
+ let r;
1278
+ try {
1279
+ switch (n) {
1280
+ case "fs":
1281
+ r = (function(a, o) {
1282
+ if (!o) return null;
1283
+ switch (a) {
1284
+ case "readFile":
1285
+ return Buffer.isBuffer(o) ? { type: "Buffer", size: o.length } : typeof o == "string" ? { type: "string", size: o.length } : { type: typeof o };
1286
+ case "readdir":
1287
+ return { count: Array.isArray(o) ? o.length : 0, items: o };
1288
+ case "stat":
1289
+ case "lstat":
1290
+ case "fstat":
1291
+ return { size: o.size, mode: o.mode, isFile: o.isFile(), isDirectory: o.isDirectory() };
1292
+ case "open":
1293
+ return { fd: o };
1294
+ case "read":
1295
+ return { bytesRead: o };
1296
+ case "write":
1297
+ return { bytesWritten: o };
1298
+ default:
1299
+ return o;
1300
+ }
1301
+ })(e, t);
1302
+ break;
1303
+ case "dns":
1304
+ r = (function(a, o) {
1305
+ if (!o) return null;
1306
+ switch (a) {
1307
+ case "lookup":
1308
+ return Array.isArray(o) ? { count: o.length, addresses: o } : o;
1309
+ case "resolve":
1310
+ case "resolve4":
1311
+ case "resolve6":
1312
+ case "resolveAny":
1313
+ case "resolveMx":
1314
+ case "resolveNs":
1315
+ case "resolveTxt":
1316
+ return { count: Array.isArray(o) ? o.length : 0, records: o };
1317
+ case "reverse":
1318
+ return { hostnames: o };
1319
+ default:
1320
+ return o;
1321
+ }
1322
+ })(e, t);
1323
+ break;
1324
+ case "crypto":
1325
+ r = (function(a, o) {
1326
+ if (!o) return null;
1327
+ switch (a) {
1328
+ case "pbkdf2":
1329
+ case "scrypt":
1330
+ case "randomBytes":
1331
+ return Buffer.isBuffer(o) ? { type: "Buffer", size: o.length } : { type: typeof o };
1332
+ case "generateKeyPair":
1333
+ return { hasPublicKey: !!o?.publicKey, hasPrivateKey: !!o?.privateKey };
1334
+ default:
1335
+ return o;
1336
+ }
1337
+ })(e, t);
1338
+ break;
1339
+ case "zlib":
1340
+ r = (function(a, o) {
1341
+ return o ? Buffer.isBuffer(o) ? { type: "Buffer", size: o.length } : typeof o == "string" ? { type: "string", size: o.length } : { type: typeof o } : null;
1342
+ })(0, t);
1343
+ break;
1344
+ default:
1345
+ return null;
1346
+ }
1347
+ return s > 0 ? J(r, s) : r;
1348
+ } catch {
1349
+ return { error: "Failed to capture result", type: typeof t };
1350
+ }
1176
1351
  }
1177
- function at(o, e = {}, t, n = !1) {
1178
- const i = l();
1179
- new be(i.apiKey).addOrUpdateMetadata(o, e, t, n);
1352
+ function yt(n) {
1353
+ return n.operationType === "worker_pool";
1180
1354
  }
1181
- class Me extends w {
1355
+ class Le extends $ {
1182
1356
  constructor() {
1183
1357
  super(), this.operationName = "CollectFunctionSpans";
1184
1358
  }
1185
1359
  send(e) {
1186
- const t = l().sfDebug;
1360
+ const t = d().sfDebug;
1187
1361
  t && console.log(`[FunctionSpanTransmitter] Preparing to send ${e.length} function span(s)`);
1188
- for (const n of e) try {
1189
- let i;
1190
- if (n.result !== void 0 && n.result !== null) {
1191
- const g = typeof n.result;
1192
- i = JSON.stringify({ type: g, has_value: !0, value: n.result });
1193
- } else i = n.result === null ? JSON.stringify({ type: "null", has_value: !0, value: null }) : JSON.stringify({ type: "undefined", has_value: !1, value: null });
1194
- const s = this.getVariables({ library: "JS/TS BACKEND", version: l().version, spanId: n.spanId, parentSpanId: n.parentSpanId, filePath: n.filePath, lineNumber: n.metadata.line, columnNumber: n.metadata.column, functionName: n.functionName, arguments: JSON.stringify(n.args || {}), returnValue: i, startTimeNs: (1e6 * Date.now() - 1e6 * n.duration).toString(), durationNs: (1e6 * n.duration).toString() });
1195
- t && (console.log(`[FunctionSpanTransmitter] Sending GraphQL mutation to ${this.endpoint}`), console.log("[FunctionSpanTransmitter] Variables:", JSON.stringify(s, null, 2))), F(this.endpoint, this.operationName, this.getQuery(), s), t && console.log(`[FunctionSpanTransmitter] Queued function span for ${n.functionName}`);
1196
- } catch (i) {
1197
- console.error(`[FunctionSpanTransmitter] Error preparing function span for ${n.functionName}:`, i);
1362
+ for (const s of e) try {
1363
+ if (yt(s)) {
1364
+ this.sendWorkerPoolSpan(s, t);
1365
+ continue;
1366
+ }
1367
+ const r = s;
1368
+ let a;
1369
+ if (r.result !== void 0 && r.result !== null) {
1370
+ const i = typeof r.result;
1371
+ a = JSON.stringify({ type: i, has_value: !0, value: r.result });
1372
+ } else a = r.result === null ? JSON.stringify({ type: "null", has_value: !0, value: null }) : JSON.stringify({ type: "undefined", has_value: !1, value: null });
1373
+ const o = this.getVariables({ library: "JS/TS BACKEND", version: d().version, spanId: r.spanId, parentSpanId: r.parentSpanId, filePath: r.filePath, lineNumber: r.metadata.line, columnNumber: r.metadata.column, functionName: r.functionName, arguments: JSON.stringify(r.args || {}), returnValue: a, startTimeNs: (1e6 * Date.now() - 1e6 * r.duration).toString(), durationNs: (1e6 * r.duration).toString() });
1374
+ t && (console.log(`[FunctionSpanTransmitter] Sending GraphQL mutation to ${this.endpoint}`), console.log("[FunctionSpanTransmitter] Variables:", JSON.stringify(o, null, 2))), W(this.endpoint, this.operationName, this.getQuery(), o), t && console.log(`[FunctionSpanTransmitter] Queued function span for ${r.functionName}`);
1375
+ } catch (r) {
1376
+ console.error(`[FunctionSpanTransmitter] Error preparing function span for ${s.functionName}:`, r);
1198
1377
  }
1199
1378
  }
1379
+ sendWorkerPoolSpan(e, t) {
1380
+ try {
1381
+ let s;
1382
+ if (e.result !== void 0 && e.result !== null) {
1383
+ const a = typeof e.result;
1384
+ s = JSON.stringify({ type: a, has_value: !0, value: e.result });
1385
+ } else s = e.result === null ? JSON.stringify({ type: "null", has_value: !0, value: null }) : JSON.stringify({ type: "undefined", has_value: !1, value: null });
1386
+ const r = this.getVariables({ library: "JS/TS BACKEND", version: d().version, spanId: e.spanId, operationName: e.operationName, moduleName: e.moduleName, methodName: e.methodName, startTimeNs: e.startTimeNs, durationNs: e.durationNs, arguments: JSON.stringify(e.args || {}), returnValue: s, error: e.error, pid: e.pid, threadId: e.threadId });
1387
+ t && (console.log(`[FunctionSpanTransmitter] Sending worker pool span: ${e.operationName}`), console.log("[FunctionSpanTransmitter] Variables:", JSON.stringify(r, null, 2))), W(this.endpoint, "CollectWorkerPoolSpans", this.getWorkerPoolQuery(), r), t && console.log(`[FunctionSpanTransmitter] Queued worker pool span for ${e.operationName}`);
1388
+ } catch (s) {
1389
+ console.error(`[FunctionSpanTransmitter] Error preparing worker pool span for ${e.operationName}:`, s);
1390
+ }
1391
+ }
1392
+ getWorkerPoolQuery() {
1393
+ return `
1394
+ mutation CollectWorkerPoolSpans(
1395
+ $apiKey: String!,
1396
+ $serviceUuid: String!,
1397
+ $sessionId: String!,
1398
+ $timestampMs: String!,
1399
+ $library: String!,
1400
+ $version: String!,
1401
+ $spanId: String!,
1402
+ $operationName: String!,
1403
+ $moduleName: String!,
1404
+ $methodName: String!,
1405
+ $startTimeNs: String!,
1406
+ $durationNs: String!,
1407
+ $parentSpanId: String,
1408
+ $arguments: String,
1409
+ $returnValue: String,
1410
+ $error: String,
1411
+ $pid: Int,
1412
+ $threadId: Int
1413
+ ) {
1414
+ collectWorkerPoolSpans(
1415
+ apiKey: $apiKey,
1416
+ serviceUuid: $serviceUuid,
1417
+ sessionId: $sessionId,
1418
+ timestampMs: $timestampMs,
1419
+ library: $library,
1420
+ version: $version,
1421
+ spanId: $spanId,
1422
+ operationName: $operationName,
1423
+ moduleName: $moduleName,
1424
+ methodName: $methodName,
1425
+ startTimeNs: $startTimeNs,
1426
+ durationNs: $durationNs,
1427
+ parentSpanId: $parentSpanId,
1428
+ arguments: $arguments,
1429
+ returnValue: $returnValue,
1430
+ error: $error,
1431
+ pid: $pid,
1432
+ threadId: $threadId
1433
+ )
1434
+ }
1435
+ `;
1436
+ }
1200
1437
  getQuery() {
1201
1438
  return `
1202
1439
  ${this.queryType} ${this.operationName}(
@@ -1239,77 +1476,282 @@ class Me extends w {
1239
1476
  `;
1240
1477
  }
1241
1478
  }
1242
- let ne = null;
1243
- function ct(o, e, t, n) {
1244
- const i = function(...s) {
1245
- const g = z(), r = g?.sfDebug || !1;
1246
- r && console.log(`[FuncSpan] captureFunctionSpan wrapper called for ${t}::${e}`);
1247
- const a = (function(u, m) {
1248
- const A = Je();
1249
- if (A) {
1250
- const y = Ke(A);
1251
- if (y) return process.env.SF_DEBUG === "true" && console.log(`[FuncSpan] Using HTTP header override for ${u}::${m}`), y;
1479
+ let le = null;
1480
+ function j(n, e, t, s, r) {
1481
+ const a = H(), o = a?.sfDebug || !1;
1482
+ o && console.log(`[WorkerPool] Capturing ${n}.${e}`);
1483
+ const i = me(), c = v.getInstance().getCurrentFunctionSpanId(), l = w();
1484
+ o && console.log(`[WorkerPool] Span ID: ${l}, Parent: ${c || "none"}`);
1485
+ const g = new Oe("WorkerPoolOperation"), u = process.hrtime.bigint();
1486
+ let I = null;
1487
+ i.captureArguments && (I = De(n, e, s, i.argLimitMb));
1488
+ const m = s.findIndex((f) => typeof f == "function");
1489
+ if (m === -1) return o && console.log(`[WorkerPool] No callback found for ${n}.${e}`), t.apply(r, s);
1490
+ const p = s[m], h = [...s];
1491
+ return h[m] = function(f, ...S) {
1492
+ const b = process.hrtime.bigint() - u, y = Number(b) / 1e6;
1493
+ p(f, ...S), g.runInAsyncScope(() => {
1494
+ o && console.log(`[WorkerPool] ${n}.${e} completed in ${y.toFixed(3)}ms (${b}ns)`);
1495
+ let A = null, Z = null;
1496
+ f ? Z = f?.message || String(f) : i.captureReturnValue && S.length > 0 && (A = Xe(n, e, S[0], i.returnLimitMb)), de({ operationType: "worker_pool", operationName: `${n}.${e}`, moduleName: n, methodName: e, duration: y, durationNs: b.toString(), startTimeNs: u.toString(), args: I, result: A, error: Z, spanId: l, parentSpanId: c, pid: process.pid, threadId: T });
1497
+ }), g.emitDestroy();
1498
+ }, t.apply(r, h);
1499
+ }
1500
+ function St(n, e, t, s, r) {
1501
+ const a = H(), o = a?.sfDebug || !1;
1502
+ o && console.log(`[WorkerPool] Capturing ${n}.${e} (Promise)`);
1503
+ const i = me(), c = v.getInstance().getCurrentFunctionSpanId(), l = w();
1504
+ o && console.log(`[WorkerPool] Span ID: ${l}, Parent: ${c || "none"}`);
1505
+ const g = process.hrtime.bigint();
1506
+ let u = null;
1507
+ return i.captureArguments && (u = De(n, e, s, i.argLimitMb)), t.apply(r, s).then((I) => {
1508
+ const m = process.hrtime.bigint() - g, p = Number(m) / 1e6;
1509
+ o && console.log(`[WorkerPool] ${n}.${e} completed in ${p.toFixed(3)}ms (${m}ns)`);
1510
+ let h = null;
1511
+ return i.captureReturnValue && (h = Xe(n, e, I, i.returnLimitMb)), de({ operationType: "worker_pool", operationName: `${n}.${e}`, moduleName: n, methodName: e, duration: p, durationNs: m.toString(), startTimeNs: g.toString(), args: u, result: h, error: null, spanId: l, parentSpanId: c, pid: process.pid, threadId: T }), I;
1512
+ }, (I) => {
1513
+ const m = process.hrtime.bigint() - g, p = Number(m) / 1e6;
1514
+ throw o && console.log(`[WorkerPool] ${n}.${e} failed in ${p.toFixed(3)}ms: ${I?.message || I}`), de({ operationType: "worker_pool", operationName: `${n}.${e}`, moduleName: n, methodName: e, duration: p, durationNs: m.toString(), startTimeNs: g.toString(), args: u, result: null, error: I?.message || String(I), spanId: l, parentSpanId: c, pid: process.pid, threadId: T }), I;
1515
+ });
1516
+ }
1517
+ function de(n) {
1518
+ const e = H(), t = e?.sfDebug || !1;
1519
+ t && console.log("[WorkerPool] Capturing span:", { operation: n.operationName, duration: `${n.duration}ms`, error: n.error, spanId: n.spanId, parentSpanId: n.parentSpanId }), process.env.SF_FUNCSPAN_CONSOLE_OUTPUT === "true" && console.log(`
1520
+ ⚙️ Worker Pool Operation:`, { operation: n.operationName, duration: `${n.duration.toFixed(2)}ms`, arguments: n.args, result: n.error ? `Error: ${n.error}` : n.result, spanId: n.spanId, parentSpanId: n.parentSpanId || "none" });
1521
+ const s = process.env.SF_FUNCSPAN_JSONL_FILE;
1522
+ if (s) try {
1523
+ const r = s === "true" || s === "1" ? "funcspans.jsonl" : s, a = Date.now(), o = process.hrtime.bigint(), i = BigInt(n.startTimeNs), c = Number(o - i) / 1e6, l = new Date(a - c).toISOString(), g = JSON.stringify({ timestamp: l, operationType: n.operationType, operationName: n.operationName, moduleName: n.moduleName, methodName: n.methodName, 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, pid: n.pid, threadId: n.threadId }) + `
1524
+ `;
1525
+ Te(r, g, "utf-8");
1526
+ } catch (r) {
1527
+ console.error("[WorkerPool] Error writing to JSONL file:", r);
1528
+ }
1529
+ if (t && console.log("[WorkerPool] Sending span to transmitter"), process.env.SF_FUNCSPAN_SKIP_BACKEND !== "true") try {
1530
+ (le || (le = new Le()), le).send([n]), t && console.log("[WorkerPool] Span sent successfully");
1531
+ } catch (r) {
1532
+ t && console.error("[WorkerPool] Error sending span:", r);
1533
+ }
1534
+ }
1535
+ const Nt = ["readFile", "writeFile", "appendFile", "readdir", "stat", "lstat", "fstat", "access", "open", "close", "read", "write", "chmod", "mkdir", "rmdir", "unlink", "rename"], We = ["lookup", "resolve", "resolve4", "resolve6", "resolveAny", "resolveMx", "resolveNs", "resolveTxt", "reverse"], vt = ["pbkdf2", "randomBytes", "scrypt", "generateKeyPair"], Gt = ["gzip", "gunzip", "deflate", "inflate", "deflateRaw", "inflateRaw", "brotliCompress", "brotliDecompress"];
1536
+ let Fe = !1, _e = !1;
1537
+ function Zt() {
1538
+ if (!_e) try {
1539
+ const n = require("node:dns");
1540
+ if (n.__sf_worker_pool_patched__) return;
1541
+ Object.defineProperty(n, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
1542
+ for (const e of We) if (typeof n[e] == "function") {
1543
+ const t = n[e];
1544
+ n[e] = function(...s) {
1545
+ const r = s[0];
1546
+ return typeof r == "string" && (r === "localhost" || r === "127.0.0.1") ? t.apply(this, s) : typeof s[s.length - 1] == "function" ? j("dns", e, t, s, this) : t.apply(this, s);
1547
+ }, Object.defineProperty(n[e], "name", { value: e, writable: !1 });
1548
+ }
1549
+ (function(e) {
1550
+ if (!e.promises) return void (process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns.promises not available, skipping"));
1551
+ if (!e.promises.__sf_worker_pool_patched__) {
1552
+ Object.defineProperty(e.promises, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
1553
+ for (const t of We) if (typeof e.promises[t] == "function") {
1554
+ const s = e.promises[t];
1555
+ e.promises[t] = function(...r) {
1556
+ const a = r[0];
1557
+ return typeof a != "string" || a !== "localhost" && a !== "127.0.0.1" ? St("dns", t, s, r, this) : s.apply(this, r);
1558
+ }, Object.defineProperty(e.promises[t], "name", { value: t, writable: !1 });
1559
+ }
1560
+ process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns.promises module patched successfully");
1561
+ }
1562
+ })(n), _e = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns module patched successfully");
1563
+ } catch (n) {
1564
+ console.error("[WorkerPool] Error patching dns module:", n);
1565
+ }
1566
+ }
1567
+ let we = !1, Ve = !1, ue = !1;
1568
+ function Bt() {
1569
+ if (ue) return;
1570
+ const n = process.env.SF_DEBUG === "true";
1571
+ n && console.log("[WorkerPool] Initializing worker pool patching..."), O("fs") && (n && console.log("[WorkerPool] Patching fs module..."), (function() {
1572
+ if (!Fe) try {
1573
+ const e = require("node:fs");
1574
+ if (e.__sf_worker_pool_patched__) return;
1575
+ Object.defineProperty(e, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
1576
+ for (const t of Nt) if (typeof e[t] == "function") {
1577
+ const s = e[t];
1578
+ e[t] = function(...r) {
1579
+ return typeof r[r.length - 1] == "function" ? j("fs", t, s, r, this) : s.apply(this, r);
1580
+ }, Object.defineProperty(e[t], "name", { value: t, writable: !1 });
1581
+ }
1582
+ Fe = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] fs module patched successfully");
1583
+ } catch (e) {
1584
+ console.error("[WorkerPool] Error patching fs module:", e);
1585
+ }
1586
+ })()), O("dns") && (n && console.log("[WorkerPool] Patching dns module..."), Zt()), O("crypto") && (n && console.log("[WorkerPool] Patching crypto module..."), (function() {
1587
+ if (!we) try {
1588
+ const e = require("node:crypto");
1589
+ if (e.__sf_worker_pool_patched__) return;
1590
+ Object.defineProperty(e, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
1591
+ for (const t of vt) if (typeof e[t] == "function") {
1592
+ const s = e[t];
1593
+ e[t] = function(...r) {
1594
+ return typeof r[r.length - 1] == "function" ? j("crypto", t, s, r, this) : s.apply(this, r);
1595
+ }, Object.defineProperty(e[t], "name", { value: t, writable: !1 });
1596
+ }
1597
+ we = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] crypto module patched successfully");
1598
+ } catch (e) {
1599
+ console.error("[WorkerPool] Error patching crypto module:", e);
1600
+ }
1601
+ })()), O("zlib") && (n && console.log("[WorkerPool] Patching zlib module..."), (function() {
1602
+ if (!Ve) try {
1603
+ const e = require("node:zlib");
1604
+ if (e.__sf_worker_pool_patched__) return;
1605
+ Object.defineProperty(e, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
1606
+ for (const t of Gt) if (typeof e[t] == "function") {
1607
+ const s = e[t];
1608
+ e[t] = function(...r) {
1609
+ return typeof r[r.length - 1] == "function" ? j("zlib", t, s, r, this) : s.apply(this, r);
1610
+ }, Object.defineProperty(e[t], "name", { value: t, writable: !1 });
1611
+ }
1612
+ Ve = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] zlib module patched successfully");
1613
+ } catch (e) {
1614
+ console.error("[WorkerPool] Error patching zlib module:", e);
1615
+ }
1616
+ })()), ue = !0, n && console.log("[WorkerPool] Worker pool patching initialized");
1617
+ }
1618
+ function Wt() {
1619
+ return ue;
1620
+ }
1621
+ function Kt(n) {
1622
+ if (!n || !n.apiKey) {
1623
+ const r = `The required API Key is not provided: ${JSON.stringify(n)}`;
1624
+ console.error(r);
1625
+ }
1626
+ const { config: e } = et(n);
1627
+ if (e.sfDebug && console.log("Updated configuration after applying options:", e), !e.apiKey || !e.apiGraphqlEndpoint) {
1628
+ const r = `The required config is not provided: ${JSON.stringify(e)}`;
1629
+ throw console.error(r), new Error(r);
1630
+ }
1631
+ At() || ft(void 0, e.sfDebug).catch((r) => {
1632
+ e.sfDebug && console.error("[FuncSpan] Failed to initialize config loader:", r);
1633
+ }), Wt() || (Bt(), e.sfDebug && console.log("[setupInterceptors] Worker pool patching initialized (DNS tracking enabled)"));
1634
+ const t = new Ie();
1635
+ t.setServiceUUID(e.serviceUUID), (function(r) {
1636
+ function a(u, I) {
1637
+ r.setOperationName("CollectLogs"), r.doSend([I, u]);
1638
+ }
1639
+ const o = console.log.bind(console), i = console.error.bind(console), c = console.warn.bind(console), l = console.info.bind(console), g = console.debug.bind(console);
1640
+ console.log = (...u) => {
1641
+ a("INFO", u.join(" ")), o(...u);
1642
+ }, console.error = (...u) => {
1643
+ a("ERROR", u.join(" ")), i(...u);
1644
+ }, console.warn = (...u) => {
1645
+ a("WARN", u.join(" ")), c(...u);
1646
+ }, console.info = (...u) => {
1647
+ a("INFO", u.join(" ")), l(...u);
1648
+ }, d().logLevel === "DEBUG" && (console.debug = (...u) => {
1649
+ a("DEBUG", u.join(" ")), g(...u);
1650
+ });
1651
+ })(t), (function(r = []) {
1652
+ const a = new Ct(r);
1653
+ new ut().doSend(a.getExcludedDomains());
1654
+ const o = new pt(), i = new It();
1655
+ a.patchFetch(o, i), a.patchHttp(o, i);
1656
+ })(e.domainsToNotPropagateHeadersTo);
1657
+ const s = new at();
1658
+ s.setServiceUUID(e.serviceUUID), ot(s), dt(), new mt().send();
1659
+ }
1660
+ function Et(n, e, t, s = !1) {
1661
+ const r = d();
1662
+ new Ke(r.apiKey).identify(n, e, t, s);
1663
+ }
1664
+ function kt(n, e = {}, t, s = !1) {
1665
+ const r = d();
1666
+ new Ke(r.apiKey).addOrUpdateMetadata(n, e, t, s);
1667
+ }
1668
+ let ge = null;
1669
+ function Yt(n, e, t, s) {
1670
+ const r = function(...a) {
1671
+ const o = H(), i = o?.sfDebug || !1;
1672
+ i && console.log(`[FuncSpan] captureFunctionSpan wrapper called for ${t}::${e}`);
1673
+ const c = (function(h, f) {
1674
+ const S = Je();
1675
+ if (S) {
1676
+ const b = Ye(S);
1677
+ if (b) return process.env.SF_DEBUG === "true" && console.log(`[FuncSpan] Using HTTP header override for ${h}::${f}`), b;
1678
+ }
1679
+ try {
1680
+ return bt(h, f);
1681
+ } catch {
1682
+ 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 };
1252
1683
  }
1253
- return Oe(u, m);
1254
1684
  })(t, e);
1255
- if (r && console.log(`[FuncSpan] Config for ${t}::${e}:`, a), a.enable_sampling && a.sample_rate < 1 && Math.random() > a.sample_rate) return r && console.log(`[FuncSpan] Skipping ${e} due to sampling`), o.apply(this, s);
1256
- if (a.sample_rate === 0) return r && console.log(`[FuncSpan] Skipping ${e} - sample_rate is 0.0`), o.apply(this, s);
1257
- r && console.log(`[FuncSpan] Capturing function span for ${e}`);
1258
- const c = G.getInstance(), d = c.getCurrentFunctionSpanId(), I = R();
1259
- c.setCurrentFunctionSpanId(I);
1260
- const h = Date.now();
1685
+ 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, a);
1686
+ if (c.sample_rate === 0) return i && console.log(`[FuncSpan] Skipping ${e} - sample_rate is 0.0`), n.apply(this, a);
1687
+ i && console.log(`[FuncSpan] Capturing function span for ${e}`);
1688
+ const l = v.getInstance(), g = l.getCurrentFunctionSpanId(), u = w();
1689
+ l.setCurrentFunctionSpanId(u);
1690
+ const I = process.hrtime.bigint(), m = Date.now();
1261
1691
  let p = null;
1262
- a.capture_arguments && (p = {}, n.paramNames.forEach((u, m) => {
1263
- m < s.length && (p[u] = s[m]);
1264
- }), p && a.arg_limit_mb > 0 && (p = ee(p, a.arg_limit_mb)));
1692
+ c.capture_arguments && (p = {}, s.paramNames.forEach((h, f) => {
1693
+ f < a.length && (p[h] = a[f]);
1694
+ }), p && c.arg_limit_mb > 0 && (p = J(p, c.arg_limit_mb)));
1265
1695
  try {
1266
- const u = o.apply(this, s);
1267
- if (u && typeof u.then == "function") return u.then((y) => {
1268
- const b = Date.now();
1269
- let f = null;
1270
- return a.capture_return_value && a.return_limit_mb > 0 && (f = ee(y, a.return_limit_mb)), D({ functionName: e, filePath: t, metadata: n, args: p, result: f, error: null, duration: b - h, async: !0, spanId: I, parentSpanId: d }), d ? c.setCurrentFunctionSpanId(d) : c.clearCurrentFunctionSpanId(), y;
1271
- }, (y) => {
1272
- const b = Date.now();
1273
- throw D({ functionName: e, filePath: t, metadata: n, args: p, result: null, error: y?.message || String(y), duration: b - h, async: !0, spanId: I, parentSpanId: d }), d ? c.setCurrentFunctionSpanId(d) : c.clearCurrentFunctionSpanId(), y;
1696
+ const h = n.apply(this, a);
1697
+ if (h && typeof h.then == "function") return g ? l.setCurrentFunctionSpanId(g) : l.clearCurrentFunctionSpanId(), h.then((A) => {
1698
+ const Z = process.hrtime.bigint(), q = Date.now(), ee = Number(Z - I);
1699
+ let he = null;
1700
+ return c.capture_return_value && c.return_limit_mb > 0 && (he = J(A, c.return_limit_mb)), x({ functionName: e, filePath: t, metadata: s, args: p, result: he, error: null, duration: q - m, durationNs: ee, startTimeNs: I.toString(), async: !0, spanId: u, parentSpanId: g, pid: process.pid, threadId: T }), A;
1701
+ }, (A) => {
1702
+ const Z = process.hrtime.bigint(), q = Date.now(), ee = Number(Z - I);
1703
+ throw x({ functionName: e, filePath: t, metadata: s, args: p, result: null, error: A?.message || String(A), duration: q - m, durationNs: ee, startTimeNs: I.toString(), async: !0, spanId: u, parentSpanId: g, pid: process.pid, threadId: T }), A;
1274
1704
  });
1275
- const m = Date.now();
1276
- let A = null;
1277
- return a.capture_return_value && a.return_limit_mb > 0 && (A = ee(u, a.return_limit_mb)), D({ functionName: e, filePath: t, metadata: n, args: p, result: A, error: null, duration: m - h, async: !1, spanId: I, parentSpanId: d }), d ? c.setCurrentFunctionSpanId(d) : c.clearCurrentFunctionSpanId(), u;
1278
- } catch (u) {
1279
- const m = Date.now();
1280
- throw D({ functionName: e, filePath: t, metadata: n, args: p, result: null, error: u?.message || String(u), duration: m - h, async: !1, spanId: I, parentSpanId: d }), d ? c.setCurrentFunctionSpanId(d) : c.clearCurrentFunctionSpanId(), u;
1705
+ const f = process.hrtime.bigint(), S = Date.now(), b = Number(f - I);
1706
+ let y = null;
1707
+ return c.capture_return_value && c.return_limit_mb > 0 && (y = J(h, c.return_limit_mb)), x({ functionName: e, filePath: t, metadata: s, args: p, result: y, error: null, duration: S - m, durationNs: b, startTimeNs: I.toString(), async: !1, spanId: u, parentSpanId: g, pid: process.pid, threadId: T }), g ? l.setCurrentFunctionSpanId(g) : l.clearCurrentFunctionSpanId(), h;
1708
+ } catch (h) {
1709
+ const f = process.hrtime.bigint(), S = Date.now(), b = Number(f - I);
1710
+ throw x({ functionName: e, filePath: t, metadata: s, args: p, result: null, error: h?.message || String(h), duration: S - m, durationNs: b, startTimeNs: I.toString(), async: !1, spanId: u, parentSpanId: g, pid: process.pid, threadId: T }), g ? l.setCurrentFunctionSpanId(g) : l.clearCurrentFunctionSpanId(), h;
1281
1711
  }
1282
1712
  };
1283
- Object.defineProperty(i, "name", { value: e, writable: !1 });
1284
- for (const s in o) o.hasOwnProperty(s) && (i[s] = o[s]);
1285
- return i;
1713
+ Object.defineProperty(r, "name", { value: e, writable: !1 });
1714
+ for (const a in n) n.hasOwnProperty(a) && (r[a] = n[a]);
1715
+ return r;
1286
1716
  }
1287
- function D(o) {
1288
- const e = z(), t = e?.sfDebug || !1;
1289
- t && console.log("[FuncSpan] captureSpanData called for:", { function: o.functionName, file: o.filePath, duration: `${o.duration}ms`, async: o.async, error: o.error, spanId: o.spanId });
1290
- const n = { functionName: o.functionName, filePath: o.filePath, metadata: o.metadata, args: o.args, result: o.result, error: o.error, duration: o.duration, async: o.async, spanId: o.spanId, parentSpanId: o.parentSpanId };
1291
- t && console.log("[FuncSpan] Sending function span to transmitter:", n);
1292
- try {
1293
- (ne || (ne = new Me()), ne).send([n]), t && console.log("[FuncSpan] Function span sent successfully");
1294
- } catch (i) {
1295
- console.error("[FuncSpan] Error sending function span:", i);
1717
+ function x(n) {
1718
+ const e = H(), t = e?.sfDebug || !1;
1719
+ 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 });
1720
+ 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 };
1721
+ process.env.SF_FUNCSPAN_CONSOLE_OUTPUT === "true" && console.log(`
1722
+ 📊 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" });
1723
+ const r = process.env.SF_FUNCSPAN_JSONL_FILE;
1724
+ if (r) try {
1725
+ const a = r === "true" || r === "1" ? "funcspans.jsonl" : r, o = Date.now(), i = process.hrtime.bigint(), c = BigInt(n.startTimeNs), l = Number(i - c) / 1e6, g = new Date(o - l).toISOString(), u = JSON.stringify({ timestamp: g, 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 }) + `
1726
+ `;
1727
+ Te(a, u, "utf-8");
1728
+ } catch (a) {
1729
+ console.error("[FuncSpan] Error writing to JSONL file:", a);
1730
+ }
1731
+ if (t && console.log("[FuncSpan] Sending function span to transmitter:", s), process.env.SF_FUNCSPAN_SKIP_BACKEND !== "true") try {
1732
+ (ge || (ge = new Le()), ge).send([s]), t && console.log("[FuncSpan] Function span sent successfully");
1733
+ } catch (a) {
1734
+ t && console.error("[FuncSpan] Error sending function span:", a);
1296
1735
  }
1297
1736
  }
1298
1737
  export {
1299
- G as ContextManager,
1300
- at as addOrUpdateMetadata,
1301
- ct as captureFunctionSpan,
1302
- Xe as clearFuncspanOverride,
1303
- M as getCurrentFunctionSpanId,
1304
- ot as getDefaultConfig,
1305
- ye as getEnvConfig,
1738
+ v as ContextManager,
1739
+ kt as addOrUpdateMetadata,
1740
+ Yt as captureFunctionSpan,
1741
+ lt as clearFuncspanOverride,
1742
+ oe as getCurrentFunctionSpanId,
1743
+ Ut as getDefaultConfig,
1744
+ ke as getEnvConfig,
1306
1745
  Je as getFuncspanOverride,
1307
- Oe as getGlobalConfig,
1308
- rt as identify,
1309
- ke as initializeConfigLoader,
1310
- Pe as isConfigLoaderInitialized,
1311
- Ke as parseHeaderOverride,
1312
- it as runWithContext,
1313
- Te as setFuncspanOverride,
1314
- st as setupInterceptors
1746
+ bt as getGlobalConfig,
1747
+ Et as identify,
1748
+ ft as initializeConfigLoader,
1749
+ Bt as initializeWorkerPoolPatching,
1750
+ At as isConfigLoaderInitialized,
1751
+ Wt as isWorkerPoolInitialized,
1752
+ Ye as parseHeaderOverride,
1753
+ $t as runWithContext,
1754
+ ct as setFuncspanOverride,
1755
+ Kt as setupInterceptors,
1756
+ Xt as transformFunctionSpans
1315
1757
  };