@sailfish-ai/sf-veritas 0.2.7 → 0.2.10

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 (40) 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 +417 -619
  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/funcSpanConfigLoader.d.ts +10 -0
  26. package/dist/types/index.d.ts +3 -1
  27. package/dist/types/logHandler.d.ts +5 -0
  28. package/dist/types/plugins/funcSpanTransformer.d.ts +13 -0
  29. package/dist/types/runtime/instrumentationDetector.d.ts +33 -0
  30. package/dist/types/runtime/runtimeConfig.d.ts +48 -0
  31. package/dist/types/sourceLocation.d.ts +30 -0
  32. package/dist/worker-pool-capture.cjs +1 -1
  33. package/dist/worker-pool-capture.mjs +1 -1
  34. package/dist/workerPoolSpanCapture-B5KN-q4b.js +528 -0
  35. package/dist/workerPoolSpanCapture-Dg_WGjmO.cjs +86 -0
  36. package/package.json +5 -2
  37. package/dist/funcSpanTransformer-BLhIRZqX.js +0 -765
  38. package/dist/funcSpanTransformer-BpWuHXKT.cjs +0 -1
  39. package/dist/workerPoolSpanCapture-D0-0Z0Jw.js +0 -718
  40. package/dist/workerPoolSpanCapture-DEwlTq0a.cjs +0 -86
@@ -1,25 +1,29 @@
1
- var Ze = Object.defineProperty;
2
- var Se = (n, e, t) => e in n ? Ze(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
- var A = (n, e, t) => Se(n, typeof e != "symbol" ? e + "" : e, t);
4
- import { B as F, g as d, n as v, C as N, f as Ge, D as Be, a as ue, p as pe, v as Ce, b as T, d as me, e as ve, m as R, c as _, h as We, i as X, j as Ne, k as he, t as $, F as Fe } from "./workerPoolSpanCapture-D0-0Z0Jw.js";
5
- import { l as bt, r as At, s as ft } from "./workerPoolSpanCapture-D0-0Z0Jw.js";
6
- import * as L from "fs";
7
- import { readFileSync as be, appendFileSync as we } from "fs";
8
- import { s as Ae } from "./funcSpanTransformer-BLhIRZqX.js";
9
- import { t as Zt } from "./funcSpanTransformer-BLhIRZqX.js";
10
- import { Worker as Ve, threadId as J } from "worker_threads";
11
- import { createRequire as He } from "node:module";
12
- import * as S from "path";
13
- import { glob as Ye } 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
- v(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 Re(n) {
58
+ function Pe(n) {
55
59
  try {
56
60
  return JSON.stringify(n), !0;
57
61
  } catch {
58
62
  return !1;
59
63
  }
60
64
  }
61
- class Xe 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, o, i) {
71
- this.sendAppIdentifier(), this.send(t, s, o, i);
74
+ async doSend(t, s, r, o) {
75
+ this.sendAppIdentifier(), this.send(t, s, r, o);
72
76
  }
73
- async send(t, s, o, 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)) Re(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: o, library: d().packageLibraryType, version: d().version });
85
- v(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 Xe extends F {
92
96
  `;
93
97
  }
94
98
  }
95
- class fe {
99
+ class ue {
96
100
  constructor(e) {
97
- A(this, "metadataTransmitter");
98
- this.apiKey = e, this.metadataTransmitter = new Xe();
101
+ S(this, "metadataTransmitter");
102
+ this.apiKey = e, this.metadataTransmitter = new Ce();
99
103
  }
100
- identify(e, t, s, o = !1) {
101
- t || s ? this.addOrUpdateMetadata(e, t, s, o) : this.addOrUpdateMetadata(e, {}, void 0, o);
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, o = !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, o, 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 ee 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 ee extends F {
118
122
  }
119
123
  async send(t) {
120
124
  try {
121
- const s = Array.isArray(t) ? t : [t, "default"], o = this.getVariables({ contents: s[0], level: s[1] });
122
- v(this.endpoint, this.operationName, this.getQuery(), o);
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 ee 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 ee 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 G = {};
152
- class V {
153
- constructor({ file: e, line: t, function: s, code: o, 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 = o, 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 z {
172
- static encode(e) {
173
- return e instanceof V ? e.toDict() : Array.isArray(e) ? e.map((t) => z.encode(t)) : typeof e == "object" && e !== null ? JSON.stringify(e) : e;
174
- }
175
- static stringify(e) {
176
- return JSON.stringify(z.encode(e), (t, s) => s instanceof V ? s.toDict() : s);
177
- }
178
- }
179
- let B, w = 0;
180
- function Je(n) {
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 = se(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 = (G.hostname?.() || c.HOSTNAME || "").toLowerCase();
191
- return I === "localhost" || I.endsWith(".local") || I.includes("local") ? B = !0 : B = !1;
192
- })();
193
- n?.setSupplementalFields?.({ isFromLocalService: r }), (async function(c) {
194
- if (oe) return;
195
- oe = !0;
196
- const a = process.env || {};
197
- if (se(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
- })(n).catch(() => {
206
- });
207
- } catch {
208
- }
209
- const e = new Ve(new URL("data:application/javascript;base64,aW1wb3J0IHsgU2Vzc2lvbiB9IGZyb20gImluc3BlY3Rvci9wcm9taXNlcyI7CmltcG9ydCB7IHBhcmVudFBvcnQsIHdvcmtlckRhdGEgfSBmcm9tICJ3b3JrZXJfdGhyZWFkcyI7CgpnbG9iYWwuc2ZE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5zY3JpcHRJZDsKICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgIGNvbnN0IHsgc2NyaXB0U291cmNlIH0gPSBhd2FpdCBzZXNzaW9uLnBvc3QoCiAgICAgICAgICAgICAgIkRlYnVnZ2VyLmdldFNjcmlwdFNvdXJjZSIsCiAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgc2NyaXB0SWQsCiAgICAgICAgICAgICAgfSwKICAgICAgICAgICAgKTsKICAgICAgICAgICAgY29uc3Qgc291cmNlTGluZXMgPSBzY3JpcHRTb3VyY2Uuc3BsaXQoIlxuIik7CiAgICAgICAgICAgIGNvZGUgPSBzb3VyY2VMaW5lc1tsb2NhdGlvbi5saW5lTnVtYmVyXSB8fCAiPG5vdCBjYXB0dXJlZD4iOwogICAgICAgICAgfSBjYXRjaCAoZXJyKSB7CiAgICAgICAgICAgIGlmIChnbG9iYWwuc2ZEZWJ1ZykgewogICAgICAgICAgICAgIGNvbnNvbGUuZXJyb3IoIltXb3JrZXJdIEZhaWxlZCB0byBmZXRjaCBzY3JpcHQgc291cmNlOiIsIGVycik7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIC8vIEZldGNoIGxvY2FsIHZhcmlhYmxlcyBpZiB0aGVyZSdzIGFuIG9iamVjdElkCiAgICAgICAgY29uc3QgbG9jYWxzID0gbG9jYWxTY29wZT8ub2JqZWN0Py5vYmplY3RJZAogICAgICAgICAgPyBhd2FpdCBmZXRjaExvY2FsVmFyaWFibGVzKHNlc3Npb24sIGxvY2FsU2NvcGUub2JqZWN0Lm9iamVjdElkKQogICAgICAgICAgOiB7fTsKCiAgICAgICAgcmV0dXJuIHsKICAgICAgICAgIGZ1bmN0aW9uOiBmdW5jdGlvbk5hbWUgfHwgIjxhbm9ueW1vdXM+IiwKICAgICAgICAgIGxvY2FscywKICAgICAgICAgIGZpbGUsCiAgICAgICAgICBsaW5lOiBsb2NhdGlvbj8ubGluZU51bWJlciB8fCAwLAogICAg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ZXJlbmNlcyBvbmUgb2YgdGhlIG1vZHVsZXMgd2UgYWxsb3cgY2FwdHVyaW5nIGZyb20KICAgICAgICBjb25zdCBpc0Zyb21BbGxvd2VkTm9kZU1vZHVsZSA9IG5vZGVNb2R1bGVzTGlzdC5zb21lKChtb2R1bGVOYW1lKSA9PgogICAgICAgICAgZmlyc3RGcmFtZUxpbmUuaW5jbHVkZXMoYCR7bW9kdWxlTmFtZX1gKSwKICAgICAgICApOwoKICAgICAgICBpZiAoIWlzRnJvbUFsbG93ZWROb2RlTW9kdWxlKSB7CiAgICAgICAgICAvLyBOb3QgZnJvbSBhbiBhbGxvd2VkIG5vZGUgbW9kdWxlID0+IHJldHVybiBlYXJseQogICAgICAgICAgaWYgKGdsb2JhbC5zZkRlYnVnKSB7CiAgICAgICAgICAgIGNvbnNvbGUubG9nKAogICAgICAgICAgICAgICJbV29ya2VyXSBFcnJvciBhcHBlYXJzIHRvIGJlIHRyaWdnZXJlZCBmcm9tIG5vbi1hcHBsaWNhdGlvbiBzb3VyY2VzOyBpZ25vcmluZy4iLAogICAgICAgICAgICApOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuOwogICAgICAgIH0KICAgICAgICAvLyBPdGhlcndpc2UsIGl0J3MgZnJvbSBhbiBhbGxvd2VkIG5vZGUgbW9kdWxlLCBzbyBjb250aW51ZQogICAgICB9IGVsc2UgewogICAgICAgIC8vIElmIHRoZSBsaXN0IGlzIGVtcHR5LCBwcmVzZXJ2ZSBleGlzdGluZyBiZWhhdmlvciBhbmQgaWdub3JlIG5vbi1hcHBsaWNhdGlvbiBlcnJvcnMKICAgICAgICBpZiAoZ2xvYmFsLnNmRGVidWcpIHsKICAgICAgICAgIGNvbnNvbGUubG9nKAogICAgICAgICAgICAiW1dvcmtlcl0gRXJyb3IgYXBwZWFycyB0byBiZSB0cmlnZ2VyZWQgZnJvbSBub24tYXBwbGljYXRpb24gc291cmNlczsgaWdub3JpbmcuIiwKICAgICAgICAgICk7CiAgICAgICA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IoIltXb3JrZXJdIEZhaWxlZCB0byBmZXRjaCBsb2NhbCB2YXJpYWJsZXM6IiwgZXJyKTsKICAgIH0KICAgIHJldHVybiB7fTsKICB9Cn0KCnN0YXJ0RGVidWdnZXIoKS5jYXRjaCgoZXJyb3IpID0+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 = _e(C[b].file);
231
- if (Z = b, y !== "<unknown>") {
232
- for (let f = 0; f < u.length; f++) {
233
- const W = u[f];
234
- if (ye(W, y) || typeof W.file == "string" && W.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 = Ke(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
- n.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), n.doSend(h, u);
263
- })) : n.doSend(h, u), l ? N.getInstance().runWithSession(l, () => {
264
- n.doSend(h, u);
265
- }) : n.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 o = Error, i = /* @__PURE__ */ new Set();
274
- function g(...r) {
275
- const c = Reflect.construct(o, r);
276
- Reflect.setPrototypeOf(c, g.prototype);
277
- try {
278
- const l = N.getInstance().getTraceId();
279
- s.set(c, l);
280
- } catch {
281
- }
282
- o.captureStackTrace && o.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(o.prototype, { constructor: { value: g, enumerable: !1, writable: !0, configurable: !0 } }), Object.setPrototypeOf(g, o), globalThis.Error = g;
293
- }
294
- function ne(n) {
295
- return n = (n = (n = n.replace(/^webpack:\/\/[^\/]+\/\.?\//, "")).replace(/^.*\/pages\//, "pages/")).replace(/\.(js|ts)$/, "");
296
- }
297
- function Ke(n, 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
- })(n);
303
- if (!s || s === "<unknown>") return null;
304
- const o = s + ".map";
305
- try {
306
- const i = be(o, "utf-8");
307
- if (i) {
308
- const g = JSON.parse(i);
309
- let r = new Ae.SourceMapConsumer(g).originalPositionFor({ line: e, column: t });
310
- if (s && r.source) {
311
- const c = ne(s), a = g.sources.findIndex((l) => ne(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 "${o}: Error - ".`, i);
326
- }
327
- return null;
328
- }
329
- function _e(n) {
330
- return n?.split("/").pop() || "<unknown>";
331
- }
332
- function ye(n, e) {
333
- if (!n || typeof n != "object") return !1;
334
- for (const t of Object.values(n))
335
- if (typeof t == "string" && t.includes(e) || typeof t == "object" && ye(t, e)) return !0;
336
- return !1;
337
- }
338
- let oe = !1;
339
- function se(n) {
340
- if (!n) return;
341
- const e = n.toLowerCase().trim();
342
- return !!["1", "true", "yes", "on"].includes(e) || !["0", "false", "no", "off"].includes(e) && void 0;
343
- }
344
- function D(n, e, t) {
345
- return new Promise((s) => {
346
- try {
347
- const o = new URL(n), i = (o.protocol, G).request({ method: "GET", hostname: o.hostname, port: o.port || (o.protocol === "https:" ? 443 : 80), path: o.pathname + (o.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 o = JSON.stringify(z.encode(s)), i = this.normalizedSupplementalForGraphQL(), g = this.getVariables({ exceptionMessage: t, traceJson: o, reentrancyGuardPreactive: !1, library: d().packageLibraryType, version: d().version, ...i });
381
- v(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,51 +213,51 @@ class ke extends F {
412
213
  `;
413
214
  }
414
215
  }
415
- const ie = "getting request source code";
416
- var k = ((n) => (n.UNKNOWN = "unknown", n.ANONYMOUS = "anonymous", n.NOT_CAPTURED = "not captured", n))(k || {});
417
- const P = "http:", x = "https:", ze = He(import.meta.url);
418
- let re = !1;
419
- function Ue() {
420
- const n = d().sfDebug;
421
- if (re) return void (n && 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
- re = !0;
224
+ Z = !0;
424
225
  try {
425
- e = ze("node:http"), n && console.log("[patchNodeHttpInbound] node:http required successfully.");
426
- } catch (o) {
427
- return void console.error("Failed to require node:http:", o);
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 (n && 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 }), n && console.log("[patchNodeHttpInbound] Patching http.Server.prototype.emit."), t.emit = function(o, ...i) {
432
- if (o !== "request") return n && console.log(`[patchNodeHttpInbound] Passing through event: ${o}`), s.call(this, o, ...i);
433
- const g = i[0], r = i[1], c = (function(u) {
434
- const m = {};
435
- if (!u) return m;
436
- for (const [h, Z] of Object.entries(u)) Z != null && (Array.isArray(Z) ? m[h.toLowerCase()] = Z.join(", ") : m[h.toLowerCase()] = String(Z));
437
- return m;
438
- })(g?.headers), a = c["x-sf3-rid"], l = c["x-sf3-functionspancaptureoverride"];
439
- n && (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
- n && console.log("[patchNodeHttpInbound] Context traceId set:", p);
444
- const C = () => I.runWith({ inboundHeaders: c, ...a ? { traceId: a } : {} }, () => {
445
- a && I.setTraceId(a), n && console.log("[patchNodeHttpInbound] Running request handler in context.");
446
- const u = () => {
447
- n && console.log("[patchNodeHttpInbound] Response finished/closed for traceId:", I.getTraceId());
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());
448
249
  };
449
- return r.on("finish", u), r.on("close", u), s.call(this, o, g, r);
250
+ return i.on("finish", p), i.on("close", p), s.call(this, r, d, i);
450
251
  });
451
- if (!l) return C();
252
+ if (!u) return m();
452
253
  try {
453
- return Ge.run(l, () => C());
254
+ return me.run(u, () => m());
454
255
  } catch {
455
- return C();
256
+ return m();
456
257
  }
457
- }) : n && console.log("[patchNodeHttpInbound] Already patched, skipping.");
258
+ }) : n && _("[patchNodeHttpInbound] Already patched, skipping.");
458
259
  }
459
- class Ee extends ee {
260
+ class Ae extends V {
460
261
  constructor() {
461
262
  super(), this.setOperationName("DomainsToNotPassHeaderTo");
462
263
  }
@@ -477,13 +278,13 @@ class Ee extends ee {
477
278
  )
478
279
  }
479
280
  `, s = { apiKey: this.apiKey, serviceUuid: this.serviceUUID, domains: e };
480
- v(this.endpoint, this.operationName, t, s);
281
+ F(this.endpoint, this.operationName, t, s);
481
282
  }
482
283
  }
483
- class Te extends F {
284
+ class Oe extends D {
484
285
  constructor() {
485
286
  super();
486
- A(this, "serviceIdentifier", new Y());
287
+ S(this, "serviceIdentifier", new E());
487
288
  this.setOperationName("CollectNetworkHops");
488
289
  }
489
290
  async sendAppIdentifier() {
@@ -493,8 +294,8 @@ class Te extends F {
493
294
  this.sendAppIdentifier(), this.send(t);
494
295
  }
495
296
  async send(t) {
496
- const { name: s, column: o, line: i, entrypoint: g, retryWithoutTraceId: r } = t, c = this.getVariables({ name: s, column: o, line: i, entrypoint: g, retryWithoutTraceId: r });
497
- v(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);
498
299
  }
499
300
  getQuery() {
500
301
  return `
@@ -524,10 +325,10 @@ class Te extends F {
524
325
  `;
525
326
  }
526
327
  }
527
- class $e extends F {
328
+ class Le extends D {
528
329
  constructor() {
529
330
  super();
530
- A(this, "serviceIdentifier", new Y());
331
+ S(this, "serviceIdentifier", new E());
531
332
  this.setOperationName("CollectNetworkRequest");
532
333
  }
533
334
  async sendAppIdentifier() {
@@ -548,174 +349,174 @@ class $e extends F {
548
349
  }
549
350
  async send(t) {
550
351
  const s = { data: { ...t } };
551
- await v(this.endpoint, this.operationName, this.getQuery(), s);
352
+ await F(this.endpoint, this.operationName, this.getQuery(), s);
552
353
  }
553
354
  }
554
- const O = [400, 403];
555
- class Le {
355
+ const K = [400, 403];
356
+ class ke {
556
357
  constructor(e = []) {
557
- A(this, "HEADER_TRACING", "X-Sf3-Rid");
558
- A(this, "HEADER_LOG_GUARD", "reentrancy_guard_logging_preactive");
559
- A(this, "HEADER_PRINT_GUARD", "reentrancy_guard_print_preactive");
560
- A(this, "HEADER_EXCEPTION_GUARD", "reentrancy_guard_exception_preactive");
561
- A(this, "contextManager");
562
- 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) => {
563
364
  typeof t == "string" && t.trim() && this.contextManager.getExcludedDomains().add(t);
564
- }), d().sfDebug && console.log("[RequestInterceptor] Initialized with static excluded domains.");
365
+ }), l().sfDebug && console.log("[RequestInterceptor] Initialized with static excluded domains.");
565
366
  }
566
367
  extractIdsFromTraceHeader(e, t = this.HEADER_TRACING) {
567
368
  let s;
568
369
  if (e instanceof Headers) s = e.get(t) ?? void 0;
569
370
  else {
570
- const i = t.toLowerCase();
571
- for (const [g, r] of Object.entries(e)) if (g.toLowerCase() === i) {
572
- s = r;
371
+ const o = t.toLowerCase();
372
+ for (const [d, i] of Object.entries(e)) if (d.toLowerCase() === o) {
373
+ s = i;
573
374
  break;
574
375
  }
575
376
  }
576
377
  if (!s) return {};
577
- const o = s.split("/").filter(Boolean);
578
- return o.length < 3 ? {} : { sessionId: o[0], pageVisitId: o[1], requestId: o[o.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] };
579
380
  }
580
381
  parseStackFrame(e) {
581
382
  const t = /\((.*):(\d+):(\d+)\)$/.exec(e.trim());
582
383
  if (!t) return null;
583
- const [, s, o, i] = t;
584
- return { filePath: s, line: parseInt(o, 10), column: parseInt(i, 10) };
384
+ const [, s, r, o] = t;
385
+ return { filePath: s, line: parseInt(r, 10), column: parseInt(o, 10) };
585
386
  }
586
387
  async getOriginalPosition(e, t, s) {
587
- let o = { source: e, line: t, column: s, name: null };
588
- const i = e + ".map";
388
+ let r = { source: e, line: t, column: s, name: null };
389
+ const o = e + ".map";
589
390
  try {
590
- const g = JSON.parse(be(i, "utf-8"));
591
- let r = (await new Ae.SourceMapConsumer(g)).originalPositionFor({ line: t, column: s });
592
- r.source && (o = r);
593
- } catch (g) {
594
- 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);
595
396
  }
596
- return { originalPos: o };
397
+ return { originalPos: r };
597
398
  }
598
399
  captureFirstUserLines(e, t = 10, s = !1) {
599
- const o = d().sfDebug ? 10 : t, i = Error.stackTraceLimit;
600
- Error.stackTraceLimit = Math.max(i, o);
601
- const g = new Error(ie);
602
- ie in Error && Error.captureStackTrace(g, this.captureFirstUserLines);
603
- const r = g.stack || "";
604
- Error.stackTraceLimit = i;
605
- 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(`
606
407
  `).slice(1), a = [];
607
- for (const l of c)
608
- 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;
609
- for (const l of a) {
610
- const I = this.parseStackFrame(l);
611
- I ? (async () => {
612
- const { originalPos: p } = await this.getOriginalPosition(I.filePath, I.line, I.column);
613
- if (p) {
614
- d().sfDebug && console.log("[RequestInterceptor] First user code line:", p);
615
- const C = { line: p.line?.toString() || k.UNKNOWN, column: p.column?.toString() || k.NOT_CAPTURED, name: p.name || k.NOT_CAPTURED, entrypoint: p.source, retryWithoutTraceId: s };
616
- 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);
617
418
  }
618
- })() : d().sfDebug && console.error("Could not parse stack line:", l);
419
+ })() : l().sfDebug && console.error("Could not parse stack line:", u);
619
420
  }
620
421
  }
621
422
  addReentrancyGuardHeaders(e) {
622
423
  e.set(this.HEADER_LOG_GUARD, "true"), e.set(this.HEADER_PRINT_GUARD, "true"), e.set(this.HEADER_EXCEPTION_GUARD, "true");
623
424
  }
624
425
  shouldPropagateHeaders(e) {
625
- return !Be.some((t) => new RegExp(`^${t.replace(/\*/g, ".*")}$`).test(e));
426
+ return !he.some((t) => new RegExp(`^${t.replace(/\*/g, ".*")}$`).test(e));
626
427
  }
627
428
  addTracingHeaders(e, t) {
628
- const s = new URL(t).hostname, o = this.shouldPropagateHeaders(s);
629
- return o ? this.addTracingHeader(e, t) : d().sfDebug && console.error(`[RequestInterceptor] Excluded domain: ${s}`), o;
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;
630
431
  }
631
432
  addTracingHeader(e, t) {
632
- const s = ue();
433
+ const s = ce();
633
434
  if (s) {
634
- const r = pe(s);
635
- 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}`));
636
437
  }
637
- const o = this.contextManager.getOrSetSfTraceId(), i = this.contextManager.getOrSetPageVisitUUID(), g = Ce();
638
- e.set(this.HEADER_TRACING, `${o}/${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}`);
639
440
  }
640
441
  patchFetch(e, t) {
641
442
  const s = globalThis.fetch;
642
- typeof s == "function" ? globalThis.fetch = async (o, i) => {
643
- const g = new Headers(i?.headers);
644
- if (g.get(this.HEADER_LOG_GUARD) === "true" || g.get(this.HEADER_PRINT_GUARD) === "true" || g.get(this.HEADER_EXCEPTION_GUARD) === "true") return s(o, 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);
645
446
  this.captureFirstUserLines(e);
646
- const r = Date.now();
447
+ const i = Date.now();
647
448
  let c;
648
- typeof o == "string" || o instanceof URL ? c = o.toString() : o instanceof Request ? (c = o.url, o.headers.forEach((u, m) => {
649
- g.set(m, u);
650
- })) : d().sfDebug && console.error("[Sailfish RequestInterceptor] Invalid fetch input."), d().sfDebug && console.log("[RequestInterceptor] Fetching request to:", c);
651
- const a = new URL(c).hostname, l = new Headers(g), I = this.addTracingHeaders(g, c), p = { ...i, headers: g };
652
- 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;
653
454
  try {
654
- let u = !1;
655
- 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);
656
- const m = Date.now();
657
- d().sfDebug && console.log(`[RequestInterceptor] Fetch completed: ${c}, Status: ${C.status}, Duration: ${m - r}ms`);
658
- const { sessionId: h, pageVisitId: Z, requestId: b } = this.extractIdsFromTraceHeader(g);
659
- 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: T() }), C;
660
- } catch (u) {
661
- const m = Date.now();
662
- 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`);
663
464
  }
664
- } : d().sfDebug && console.error("[RequestInterceptor] Fetch not available.");
465
+ } : l().sfDebug && console.error("[RequestInterceptor] Fetch not available.");
665
466
  }
666
467
  patchHttp(e, t) {
667
- if (d().sfDebug && console.log("[RequestInterceptor] Initializing HTTP/HTTPS request patch..."), !G || typeof G.request != "function") return void (d().sfDebug && console.log("[RequestInterceptor] HTTP/HTTPS not available."));
668
- const s = G.request.bind(G), o = G.request.bind(G);
669
- G.request = function(i, g) {
670
- 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;
671
472
  try {
672
- if (typeof i == "string") {
673
- const a = new URL(i);
674
- r = { protocol: a.protocol || P, hostname: a.hostname, path: a.pathname + a.search, headers: {} };
675
- } 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));
676
- if (r.headers) {
677
- const a = `${r.protocol}//${r.hostname}`;
678
- this.addTracingHeaders(r.headers, a), this.captureFirstUserLines(e);
679
- } 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.");
680
481
  } catch (a) {
681
- 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;
682
483
  }
683
484
  let c = !1;
684
- return s(r, (a) => {
685
- const l = `${r.protocol}//${r.hostname}`;
686
- if (r.headers && this.shouldPropagateHeaders(new URL(l).hostname) && O.includes(a.statusCode || 0)) {
687
- r.hostname;
688
- const u = { ...r, headers: { ...r.headers } };
689
- 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);
690
491
  }
691
- const { sessionId: I, pageVisitId: p, requestId: C } = this.extractIdsFromTraceHeader(r.headers);
692
- 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: T() }), 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);
693
494
  });
694
- }, G.request = function(i, g) {
695
- let r;
495
+ }, b.request = function(o, d) {
496
+ let i;
696
497
  try {
697
- if (typeof i == "string") {
698
- const a = new URL(i);
699
- r = { protocol: a.protocol || x, hostname: a.hostname, path: a.pathname + a.search, headers: {} };
700
- } 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));
701
- if (r.headers) {
702
- const a = `${r.protocol}//${r.hostname}`;
703
- this.addTracingHeaders(r.headers, a);
704
- } 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.");
705
506
  } catch (a) {
706
- 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;
707
508
  }
708
509
  let c = !1;
709
- return o(r, (a) => {
710
- const l = `${r.protocol}//${r.hostname}`;
711
- if (r.headers && this.shouldPropagateHeaders(new URL(l).hostname) && O.includes(a.statusCode || 0)) {
712
- const u = { ...r, headers: { ...r.headers } };
713
- delete u.headers[this.HEADER_TRACING], o(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);
714
515
  }
715
- const { sessionId: I, pageVisitId: p, requestId: C } = this.extractIdsFromTraceHeader(r.headers);
716
- 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: T() }), 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);
717
518
  });
718
- }, d().sfDebug && console.log("✅ HTTP and HTTPS request methods patched globally.");
519
+ }, l().sfDebug && console.log("✅ HTTP and HTTPS request methods patched globally.");
719
520
  }
720
521
  tryPatch(e, t) {
721
522
  try {
@@ -728,7 +529,7 @@ class Le {
728
529
  return [...this.contextManager.getExcludedDomains()];
729
530
  }
730
531
  }
731
- class De extends ee {
532
+ class qe extends V {
732
533
  constructor() {
733
534
  super(), this.setOperationName("UpdateServiceDetails");
734
535
  }
@@ -756,43 +557,47 @@ class De extends ee {
756
557
  gitSha: $gitSha,
757
558
  )
758
559
  }
759
- `, t = this.getVariables({ serviceIdentifier: d().serviceIdentifier, serviceVersion: d().serviceVersion, serviceAdditionalMetadata: d().serviceAdditionalMetadata, gitSha: d().gitSha || "" });
760
- v(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);
761
562
  }
762
563
  }
763
- class Pe {
564
+ class Me {
764
565
  constructor(e = [process.cwd()], t = !1) {
765
- A(this, "rootPaths");
766
- A(this, "fileConfigs", /* @__PURE__ */ new Map());
767
- A(this, "functionConfigs", /* @__PURE__ */ new Map());
768
- A(this, "directoryConfigs", /* @__PURE__ */ new Map());
769
- A(this, "hasSailfishFiles", !1);
770
- 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");
771
573
  this.rootPaths = e, this.debug = t || process.env.SF_DEBUG === "true";
772
574
  }
773
575
  async loadAllConfigs() {
774
576
  this.debug && console.log("[FuncSpan ConfigLoader] Scanning for .sailfish files in:", this.rootPaths);
775
577
  const e = [];
776
- 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}`);
777
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");
778
580
  for (const t of e) await this._loadConfigFile(t);
779
581
  await this._resolveInheritance(), this.debug && console.log(`[FuncSpan ConfigLoader] Loaded ${this.fileConfigs.size} file configs, ${this.functionConfigs.size} function configs`);
780
582
  }
781
583
  getConfig(e, t) {
782
- const s = this.hasSailfishFiles ? me() : ve(), o = this._getDirectoryConfig(e), i = S.normalize(e), g = this.fileConfigs.get(i) || {};
783
- let r = {};
584
+ const s = this.hasSailfishFiles ? le() : Se(), r = this._getDirectoryConfig(e), o = $.normalize(e), d = this.fileConfigs.get(o) || {};
585
+ let i = {};
784
586
  if (t) {
785
- const c = this.functionConfigs.get(i);
786
- c && (r = c.get(t) || {});
587
+ const c = this.functionConfigs.get(o);
588
+ c && (i = c.get(t) || {});
787
589
  }
788
- return R(s, o, g, r);
590
+ return P(s, r, d, i);
591
+ }
592
+ hasRuntimeMode() {
593
+ return this.runtimeModeEnabled;
789
594
  }
790
595
  async _walkDirectory(e, t) {
791
596
  try {
792
- const s = L.readdirSync(e, { withFileTypes: !0 });
793
- for (const o of s) {
794
- const i = S.join(e, o.name);
795
- o.isFile() && o.name === ".sailfish" ? t.push(i) : o.name === "node_modules" || o.isDirectory() && o.name.startsWith(".") && o.name !== ".sailfish" || o.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);
796
601
  }
797
602
  } catch (s) {
798
603
  this.debug && console.error(`[FuncSpan ConfigLoader] Error walking directory ${e}:`, s);
@@ -800,81 +605,81 @@ class Pe {
800
605
  }
801
606
  async _loadConfigFile(e) {
802
607
  try {
803
- const t = L.readFileSync(e, "utf-8"), s = S.dirname(e);
804
- let o = null;
608
+ const t = H.readFileSync(e, "utf-8"), s = $.dirname(e);
609
+ let r = null;
805
610
  try {
806
- o = JSON.parse(t);
611
+ r = JSON.parse(t);
807
612
  } catch {
808
613
  try {
809
- o = require("js-yaml").load(t);
810
- } catch (i) {
811
- 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));
812
617
  }
813
618
  }
814
- if (!o) return;
815
- o.default && this.directoryConfigs.set(s, o.default), o.files && await this._expandFileGlobs(s, o.files, o.default || {}), o.functions && this._storeFunctionConfigs(s, o.functions, o.default || {}), this.debug && (console.log(`[FuncSpan ConfigLoader] Loaded config from ${e}`), console.log(`[FuncSpan ConfigLoader] Directory: ${s}`), console.log(`[FuncSpan ConfigLoader] Has default: ${!!o.default}`), console.log(`[FuncSpan ConfigLoader] File patterns: ${Object.keys(o.files || {}).length}`), console.log(`[FuncSpan ConfigLoader] Functions: ${Object.keys(o.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}`));
816
621
  } catch (t) {
817
622
  this.debug && console.error(`[FuncSpan ConfigLoader] Error loading ${e}:`, t);
818
623
  }
819
624
  }
820
625
  async _expandFileGlobs(e, t, s) {
821
- for (const [o, i] of Object.entries(t)) try {
822
- const g = S.join(e, o), r = await Ye(g, { absolute: !0, nodir: !0, ignore: ["**/node_modules/**", "**/.git/**"] });
823
- this.debug && console.log(`[FuncSpan ConfigLoader] Pattern '${o}' matched ${r.length} files`);
824
- for (const c of r) {
825
- const a = S.normalize(c), l = R(s, i);
826
- 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}`);
827
632
  }
828
- } catch (g) {
829
- this.debug && console.error(`[FuncSpan ConfigLoader] Error expanding glob '${o}':`, g);
633
+ } catch (d) {
634
+ this.debug && console.error(`[FuncSpan ConfigLoader] Error expanding glob '${r}':`, d);
830
635
  }
831
636
  }
832
637
  _storeFunctionConfigs(e, t, s) {
833
- for (const [o, i] of Object.entries(t)) {
834
- const g = o.split("::");
835
- if (g.length !== 2) {
836
- this.debug && console.warn(`[FuncSpan ConfigLoader] Invalid function pattern '${o}' (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')`);
837
642
  continue;
838
643
  }
839
- const [r, c] = g, a = S.normalize(S.join(e, r));
644
+ const [i, c] = d, a = $.normalize($.join(e, i));
840
645
  this.functionConfigs.has(a) || this.functionConfigs.set(a, /* @__PURE__ */ new Map());
841
- const l = this.functionConfigs.get(a), I = R(s, i);
842
- 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}`);
843
648
  }
844
649
  }
845
650
  async _resolveInheritance() {
846
651
  }
847
652
  _getDirectoryConfig(e) {
848
- let t = S.dirname(S.normalize(e));
653
+ let t = $.dirname($.normalize(e));
849
654
  const s = [];
850
- for (; t && t !== S.dirname(t); ) {
851
- const o = this.directoryConfigs.get(t);
852
- o && s.unshift(o), t = S.dirname(t);
655
+ for (; t && t !== $.dirname(t); ) {
656
+ const r = this.directoryConfigs.get(t);
657
+ r && s.unshift(r), t = $.dirname(t);
853
658
  }
854
- return s.reduce((o, i) => R(o, i), {});
659
+ return s.reduce((r, o) => P(r, o), {});
855
660
  }
856
661
  }
857
- let H = null;
858
- async function xe(n, e) {
859
- H = new Pe(n, e), await H.loadAllConfigs();
662
+ let w = null;
663
+ async function He(n, e) {
664
+ w = new Me(n, e), await w.loadAllConfigs();
860
665
  }
861
- function Oe(n, e) {
862
- return H ? H.getConfig(n, e) : (process.env.SF_DEBUG === "true" && console.log("[FuncSpan ConfigLoader] Config loader not initialized, using env config for worker process"), me());
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());
863
668
  }
864
- function je() {
865
- return H !== null;
669
+ function Ge() {
670
+ return w !== null;
866
671
  }
867
- const Me = ["readFile", "writeFile", "appendFile", "readdir", "stat", "lstat", "fstat", "access", "open", "close", "read", "write", "chmod", "mkdir", "rmdir", "unlink", "rename"], ae = ["lookup", "resolve", "resolve4", "resolve6", "resolveAny", "resolveMx", "resolveNs", "resolveTxt", "reverse"], Qe = ["pbkdf2", "randomBytes", "scrypt", "generateKeyPair"], qe = ["gzip", "gunzip", "deflate", "inflate", "deflateRaw", "inflateRaw", "brotliCompress", "brotliDecompress"];
868
- let ce = !1;
869
- function et(n) {
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) {
870
675
  if (typeof n != "string") return !1;
871
676
  const e = process.env.SF_FUNCSPAN_JSONL_FILE;
872
677
  if (e && n.includes(e)) return !0;
873
678
  const t = process.env.SF_WORKER_POOL_JSONL_FILE;
874
679
  return !(!t || !n.includes(t));
875
680
  }
876
- let ge = !1;
877
- function le(n) {
681
+ let ne = !1;
682
+ function re(n) {
878
683
  if (typeof n != "string") return !1;
879
684
  if (n === "localhost" || n === "127.0.0.1" || n === "::1") return !0;
880
685
  try {
@@ -885,8 +690,8 @@ function le(n) {
885
690
  }
886
691
  return !1;
887
692
  }
888
- function tt() {
889
- if (!ge) try {
693
+ function Be() {
694
+ if (!ne) try {
890
695
  let n;
891
696
  if (typeof require > "u") return void (process.env.SF_DEBUG === "true" && console.log("[WorkerPool] Skipping dns patching in pure ESM environment (require unavailable)"));
892
697
  try {
@@ -896,230 +701,223 @@ function tt() {
896
701
  }
897
702
  if (n.__sf_worker_pool_patched__) return;
898
703
  Object.defineProperty(n, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
899
- for (const e of ae) if (typeof n[e] == "function") {
704
+ for (const e of ee) if (typeof n[e] == "function") {
900
705
  const t = n[e];
901
706
  n[e] = function(...s) {
902
- return le(s[0]) ? t.apply(this, s) : typeof s[s.length - 1] == "function" ? _("dns", e, t, s, this) : t.apply(this, 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);
903
708
  }, Object.defineProperty(n[e], "name", { value: e, writable: !1 });
904
709
  }
905
710
  (function(e) {
906
711
  if (!e.promises) return void (process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns.promises not available, skipping"));
907
712
  if (!e.promises.__sf_worker_pool_patched__) {
908
713
  Object.defineProperty(e.promises, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
909
- for (const t of ae) if (typeof e.promises[t] == "function") {
714
+ for (const t of ee) if (typeof e.promises[t] == "function") {
910
715
  const s = e.promises[t];
911
- e.promises[t] = function(...o) {
912
- return le(o[0]) ? s.apply(this, o) : We("dns", t, s, o, this);
716
+ e.promises[t] = function(...r) {
717
+ return re(r[0]) ? s.apply(this, r) : ye("dns", t, s, r, this);
913
718
  }, Object.defineProperty(e.promises[t], "name", { value: t, writable: !1 });
914
719
  }
915
720
  process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns.promises module patched successfully");
916
721
  }
917
- })(n), ge = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns module patched successfully");
722
+ })(n), ne = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns module patched successfully");
918
723
  } catch (n) {
919
724
  console.error("[WorkerPool] Error patching dns module:", n);
920
725
  }
921
726
  }
922
- let de = !1, Ie = !1, Q = !1;
923
- function nt() {
924
- if (Q) return;
727
+ let se = !1, oe = !1, j = !1;
728
+ function Je() {
729
+ if (j) return;
925
730
  const n = process.env.SF_DEBUG === "true";
926
- n && console.log("[WorkerPool] Initializing worker pool patching..."), X("fs") && (n && console.log("[WorkerPool] Patching fs module..."), (function() {
927
- if (!ce) try {
731
+ n && console.log("[WorkerPool] Initializing worker pool patching..."), C("fs") && (n && console.log("[WorkerPool] Patching fs module..."), (function() {
732
+ if (!te) try {
928
733
  const e = require("node:fs");
929
734
  if (e.__sf_worker_pool_patched__) return;
930
735
  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") {
736
+ for (const t of Ke) if (typeof e[t] == "function") {
932
737
  const s = e[t];
933
- e[t] = function(...o) {
934
- return et(o[0]) ? s.apply(this, o) : typeof o[o.length - 1] == "function" ? _("fs", t, s, o, this) : s.apply(this, o);
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);
935
740
  }, Object.defineProperty(e[t], "name", { value: t, writable: !1 });
936
741
  }
937
- ce = !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");
938
743
  } catch (e) {
939
744
  console.error("[WorkerPool] Error patching fs module:", e);
940
745
  }
941
- })()), X("dns") && (n && console.log("[WorkerPool] Patching dns module..."), tt()), X("crypto") && (n && console.log("[WorkerPool] Patching crypto module..."), (function() {
942
- if (!de) 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 {
943
748
  const e = require("node:crypto");
944
749
  if (e.__sf_worker_pool_patched__) return;
945
750
  Object.defineProperty(e, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
946
- for (const t of Qe) if (typeof e[t] == "function") {
751
+ for (const t of We) if (typeof e[t] == "function") {
947
752
  const s = e[t];
948
- e[t] = function(...o) {
949
- return typeof o[o.length - 1] == "function" ? _("crypto", t, s, o, this) : s.apply(this, o);
753
+ e[t] = function(...r) {
754
+ return typeof r[r.length - 1] == "function" ? R("crypto", t, s, r, this) : s.apply(this, r);
950
755
  }, Object.defineProperty(e[t], "name", { value: t, writable: !1 });
951
756
  }
952
- de = !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");
953
758
  } catch (e) {
954
759
  console.error("[WorkerPool] Error patching crypto module:", e);
955
760
  }
956
- })()), X("zlib") && (n && console.log("[WorkerPool] Patching zlib module..."), (function() {
957
- if (!Ie) try {
761
+ })()), C("zlib") && (n && console.log("[WorkerPool] Patching zlib module..."), (function() {
762
+ if (!oe) try {
958
763
  const e = require("node:zlib");
959
764
  if (e.__sf_worker_pool_patched__) return;
960
765
  Object.defineProperty(e, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
961
- for (const t of qe) if (typeof e[t] == "function") {
766
+ for (const t of ze) if (typeof e[t] == "function") {
962
767
  const s = e[t];
963
- e[t] = function(...o) {
964
- return typeof o[o.length - 1] == "function" ? _("zlib", t, s, o, this) : s.apply(this, o);
768
+ e[t] = function(...r) {
769
+ return typeof r[r.length - 1] == "function" ? R("zlib", t, s, r, this) : s.apply(this, r);
965
770
  }, Object.defineProperty(e[t], "name", { value: t, writable: !1 });
966
771
  }
967
- Ie = !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");
968
773
  } catch (e) {
969
774
  console.error("[WorkerPool] Error patching zlib module:", e);
970
775
  }
971
- })()), Q = !0, n && console.log("[WorkerPool] Worker pool patching initialized");
776
+ })()), j = !0, n && console.log("[WorkerPool] Worker pool patching initialized");
972
777
  }
973
- function ot() {
974
- return Q;
778
+ function Ve() {
779
+ return j;
975
780
  }
976
- let q = !1, j = !1;
977
- function dt(n) {
978
- if (j) console.warn("[setupInterceptors] ⚠️ Recursive call detected and blocked!");
979
- else if (!q) {
980
- j = !0;
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;
981
786
  try {
982
787
  if (!n || !n.apiKey) {
983
- const o = `The required API Key is not provided: ${JSON.stringify(n)}`;
984
- console.error(o);
788
+ const r = `The required API Key is not provided: ${JSON.stringify(n)}`;
789
+ console.error(r);
985
790
  }
986
- const { config: e } = Ne(n);
791
+ const { config: e } = ge(n);
987
792
  if (e.sfDebug && console.log("Updated configuration after applying options:", e), !e.apiKey || !e.apiGraphqlEndpoint) {
988
- const o = `The required config is not provided: ${JSON.stringify(e)}`;
989
- throw console.error(o), new Error(o);
793
+ const r = `The required config is not provided: ${JSON.stringify(e)}`;
794
+ throw console.error(r), new Error(r);
990
795
  }
991
- je() || xe(void 0, e.sfDebug).catch((o) => {
992
- e.sfDebug && console.error("[FuncSpan] Failed to initialize config loader:", o);
993
- }), process.env.SF_WORKER_POOL_DISABLED === "true" ? e.sfDebug && console.log("[setupInterceptors] Worker pool patching DISABLED (SF_WORKER_POOL_DISABLED=true)") : ot() || (nt(), e.sfDebug && console.log("[setupInterceptors] Worker pool patching initialized (DNS tracking enabled)"));
994
- const t = new ee();
995
- t.setServiceUUID(e.serviceUUID), (function(o) {
996
- function i(I, p) {
997
- o.setOperationName("CollectLogs"), o.doSend([p, I]);
998
- }
999
- 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);
1000
- console.log = (...I) => {
1001
- i("INFO", I.join(" ")), g(...I);
1002
- }, console.error = (...I) => {
1003
- i("ERROR", I.join(" ")), r(...I);
1004
- }, console.warn = (...I) => {
1005
- i("WARN", I.join(" ")), c(...I);
1006
- }, console.info = (...I) => {
1007
- i("INFO", I.join(" ")), a(...I);
1008
- }, d().logLevel === "DEBUG" && (console.debug = (...I) => {
1009
- i("DEBUG", I.join(" ")), l(...I);
1010
- });
1011
- })(t), (function(o = []) {
1012
- const i = new Le(o);
1013
- new Ee().doSend(i.getExcludedDomains());
1014
- const g = new Te(), r = new $e();
1015
- i.patchFetch(g, r), i.patchHttp(g, r);
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);
1016
805
  })(e.domainsToNotPropagateHeadersTo);
1017
- const s = new ke();
1018
- s.setServiceUUID(e.serviceUUID), Je(s), Ue(), new De().send(), q = !0, e.sfDebug && console.log("[setupInterceptors] ✅ Initialization complete");
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");
1019
808
  } finally {
1020
- j = !1;
809
+ W = !1;
1021
810
  }
1022
811
  }
1023
812
  }
1024
- function It() {
1025
- return q;
813
+ function it() {
814
+ return B;
1026
815
  }
1027
- function ut(n, e, t, s = !1) {
1028
- const o = d();
1029
- new fe(o.apiKey).identify(n, 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);
1030
819
  }
1031
- function pt(n, e = {}, t, s = !1) {
1032
- const o = d();
1033
- new fe(o.apiKey).addOrUpdateMetadata(n, e, t, s);
820
+ function ct(n, e = {}, t, s = !1) {
821
+ const r = l();
822
+ new ue(r.apiKey).addOrUpdateMetadata(n, e, t, s);
1034
823
  }
1035
- let M = null;
1036
- function Ct(n, e, t, s) {
1037
- const o = function(...i) {
1038
- const g = he(), r = g?.sfDebug || !1;
1039
- r && console.log(`[FuncSpan] captureFunctionSpan wrapper called for ${t}::${e}`);
1040
- const c = (function(m, h) {
1041
- const Z = ue();
1042
- if (Z) {
1043
- const b = pe(Z);
1044
- if (b) return process.env.SF_DEBUG === "true" && console.log(`[FuncSpan] Using HTTP header override for ${m}::${h}`), b;
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;
1045
834
  }
1046
835
  try {
1047
- return Oe(m, h);
836
+ return xe(g, y);
1048
837
  } catch {
1049
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 };
1050
839
  }
1051
840
  })(t, e);
1052
- 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`), n.apply(this, i);
1053
- if (c.sample_rate === 0) return r && console.log(`[FuncSpan] Skipping ${e} - sample_rate is 0.0`), n.apply(this, i);
1054
- r && console.log(`[FuncSpan] Capturing function span for ${e}`);
1055
- const a = N.getInstance(), l = a.getCurrentFunctionSpanId(), I = Ce();
1056
- a.setCurrentFunctionSpanId(I);
1057
- const p = process.hrtime.bigint(), C = Date.now();
1058
- let u = null;
1059
- c.capture_arguments && (u = {}, s.paramNames.forEach((m, h) => {
1060
- h < i.length && (u[m] = i[h]);
1061
- }), u && c.arg_limit_mb > 0 && (u = $(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)));
1062
851
  try {
1063
- const m = n.apply(this, i);
1064
- if (m && typeof m.then == "function") return l ? a.setCurrentFunctionSpanId(l) : a.clearCurrentFunctionSpanId(), m.then((f) => {
1065
- const W = process.hrtime.bigint(), U = Date.now(), E = Number(W - p);
1066
- let te = null;
1067
- return c.capture_return_value && c.return_limit_mb > 0 && (te = $(f, c.return_limit_mb)), K({ functionName: e, filePath: t, metadata: s, args: u, result: te, error: null, duration: U - C, durationNs: E, startTimeNs: p.toString(), async: !0, spanId: I, parentSpanId: l, pid: process.pid, threadId: J }), f;
1068
- }, (f) => {
1069
- const W = process.hrtime.bigint(), U = Date.now(), E = Number(W - p);
1070
- throw K({ functionName: e, filePath: t, metadata: s, args: u, result: null, error: f?.message || String(f), duration: U - C, durationNs: E, 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;
1071
860
  });
1072
- const h = process.hrtime.bigint(), Z = Date.now(), b = Number(h - p);
1073
- let y = null;
1074
- return c.capture_return_value && c.return_limit_mb > 0 && (y = $(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;
1075
- } catch (m) {
1076
- const h = process.hrtime.bigint(), Z = Date.now(), b = Number(h - p);
1077
- 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;
1078
867
  }
1079
868
  };
1080
- Object.defineProperty(o, "name", { value: e, writable: !1 });
1081
- for (const i in n) n.hasOwnProperty(i) && (o[i] = n[i]);
1082
- return o;
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;
1083
872
  }
1084
- function K(n) {
1085
- const e = he(), t = e?.sfDebug || !1;
873
+ function U(n) {
874
+ const e = ae(), t = e?.sfDebug || !1;
1086
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 });
1087
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 };
1088
877
  process.env.SF_FUNCSPAN_CONSOLE_OUTPUT === "true" && console.log(`
1089
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" });
1090
- const o = process.env.SF_FUNCSPAN_JSONL_FILE;
1091
- if (o) try {
1092
- const i = o === "true" || o === "1" ? "funcspans.jsonl" : o, g = Date.now(), r = process.hrtime.bigint(), c = BigInt(n.startTimeNs), a = Number(r - c) / 1e6, l = new Date(g - a).toISOString(), I = JSON.stringify({ timestamp: l, 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 }) + `
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 }) + `
1093
882
  `;
1094
- we(i, I, "utf-8");
1095
- } catch (i) {
1096
- 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);
1097
886
  }
1098
887
  if (t && console.log("[FuncSpan] Sending function span to transmitter:", s), process.env.SF_FUNCSPAN_SKIP_BACKEND !== "true") try {
1099
- (M || (M = new Fe()), M).send([s]), t && console.log("[FuncSpan] Function span sent successfully");
1100
- } catch (i) {
1101
- 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);
1102
891
  }
1103
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
+ }
1104
896
  export {
1105
- N as ContextManager,
1106
- pt as addOrUpdateMetadata,
1107
- Ct as captureFunctionSpan,
1108
- bt as clearFuncspanOverride,
1109
- T as getCurrentFunctionSpanId,
1110
- ve as getDefaultConfig,
1111
- me as getEnvConfig,
1112
- ue as getFuncspanOverride,
1113
- Oe as getGlobalConfig,
1114
- ut as identify,
1115
- xe as initializeConfigLoader,
1116
- nt as initializeWorkerPoolPatching,
1117
- je as isConfigLoaderInitialized,
1118
- It as isSetupInterceptorsInitialized,
1119
- ot as isWorkerPoolInitialized,
1120
- pe as parseHeaderOverride,
1121
- At as runWithContext,
1122
- ft as setFuncspanOverride,
1123
- dt as setupInterceptors,
1124
- Zt as transformFunctionSpans
897
+ J as ContextManager,
898
+ ct as addOrUpdateMetadata,
899
+ dt as captureFunctionSpan,
900
+ gt as clearFuncspanOverride,
901
+ q as getCurrentFunctionSpanId,
902
+ Se as getDefaultConfig,
903
+ le as getEnvConfig,
904
+ ce as getFuncspanOverride,
905
+ xe as getGlobalConfig,
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,
915
+ de as parseHeaderOverride,
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
1125
923
  };