@sailfish-ai/sf-veritas 0.2.6 → 0.2.9

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