@sailfish-ai/sf-veritas 0.2.20 → 0.3.0

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