@sailfish-ai/sf-veritas 0.3.1 → 0.3.2
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.
- package/README.md +35 -0
- package/dist/{contextManager-D2ijKL-E.js → contextManager-CZy0w11U.js} +36 -35
- package/dist/contextManager-qXvO_a5y.cjs +1 -0
- package/dist/plugins/funcspanEsbuildPlugin.cjs +1 -1
- package/dist/plugins/funcspanEsbuildPlugin.mjs +1 -1
- package/dist/plugins/funcspanRollupPlugin.cjs +1 -1
- package/dist/plugins/funcspanRollupPlugin.mjs +1 -1
- package/dist/plugins/funcspanTscPlugin.cjs +1 -1
- package/dist/plugins/funcspanTscPlugin.mjs +1 -1
- package/dist/plugins/funcspanVitePlugin.cjs +1 -1
- package/dist/plugins/funcspanVitePlugin.mjs +1 -1
- package/dist/plugins/funcspanWebpackPlugin.cjs +1 -1
- package/dist/plugins/funcspanWebpackPlugin.mjs +1 -1
- package/dist/runtimeConfig-ButdW4zP.js +474 -0
- package/dist/runtimeConfig-C4_zc4Zg.cjs +5 -0
- package/dist/sf-veritas.cjs +13 -13
- package/dist/sf-veritas.mjs +477 -425
- package/dist/types/constants.d.ts +7 -0
- package/dist/types/requestTransmitter.d.ts +30 -0
- package/dist/types/setupConfig.d.ts +18 -0
- package/dist/types/urlMatch.d.ts +19 -0
- package/dist/worker-pool-capture.cjs +1 -1
- package/dist/worker-pool-capture.mjs +1 -1
- package/dist/{workerPoolSpanCapture-DzCJnMDA.cjs → workerPoolSpanCapture-BUFN_RMW.cjs} +1 -1
- package/dist/{workerPoolSpanCapture-hyxgVqUF.js → workerPoolSpanCapture-BomWTMM2.js} +1 -1
- package/package.json +1 -1
- package/dist/contextManager-BsolAr_q.cjs +0 -1
- package/dist/runtimeConfig-C4mv7SVM.js +0 -484
- package/dist/runtimeConfig-XIm4yAFB.cjs +0 -6
package/dist/sf-veritas.mjs
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var b = (r, t, e) =>
|
|
4
|
-
import { g as
|
|
5
|
-
import { r as
|
|
6
|
-
import { B as k, n as
|
|
7
|
-
import { h as
|
|
8
|
-
import { a as
|
|
9
|
-
import { f as
|
|
10
|
-
import { createRequire as
|
|
11
|
-
import * as
|
|
12
|
-
import { readFileSync as
|
|
1
|
+
var Fe = Object.defineProperty;
|
|
2
|
+
var we = (r, t, e) => t in r ? Fe(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
|
|
3
|
+
var b = (r, t, e) => we(r, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
import { g as c, C as ne, D as De, v as X, b as C, c as Ne, d as Ee, a as ye } from "./contextManager-CZy0w11U.js";
|
|
5
|
+
import { r as Rt } from "./contextManager-CZy0w11U.js";
|
|
6
|
+
import { B as k, n as T, f as Pe, g as Y, p as Z, a as Se, b as Re, m as L, c as x, i as ie, d as Te, e as q, r as Ce, t as K, F as Ue } from "./workerPoolSpanCapture-BomWTMM2.js";
|
|
7
|
+
import { h as Ct, s as Ut } from "./workerPoolSpanCapture-BomWTMM2.js";
|
|
8
|
+
import { a as ke, C as Oe, i as N, b as Le, c as Ie, d as qe, e as Ae } from "./runtimeConfig-ButdW4zP.js";
|
|
9
|
+
import { f as Ot, g as Lt, s as qt } from "./runtimeConfig-ButdW4zP.js";
|
|
10
|
+
import { createRequire as He } from "node:module";
|
|
11
|
+
import * as Me from "fs";
|
|
12
|
+
import { readFileSync as xe, appendFileSync as Be } from "fs";
|
|
13
13
|
import U from "http";
|
|
14
14
|
import A from "https";
|
|
15
|
-
import { s as
|
|
16
|
-
import * as
|
|
15
|
+
import { s as Ge } from "./source-map-Cr6YkjTd.js";
|
|
16
|
+
import * as se from "fs/promises";
|
|
17
17
|
import * as P from "path";
|
|
18
|
-
import { glob as
|
|
18
|
+
import { glob as Ke } from "glob";
|
|
19
19
|
import { threadId as H } from "worker_threads";
|
|
20
|
-
import { s as
|
|
20
|
+
import { s as Ht, t as Mt, a as xt } from "./funcSpanTransformer-S_WeAt_m.js";
|
|
21
21
|
class O extends k {
|
|
22
22
|
constructor() {
|
|
23
23
|
super(), this.setOperationName("IdentifyServiceDetails");
|
|
24
24
|
}
|
|
25
25
|
async doSend(t) {
|
|
26
|
-
if (!
|
|
26
|
+
if (!c().serviceIdentificationReceived) try {
|
|
27
27
|
this.send();
|
|
28
28
|
} catch (e) {
|
|
29
|
-
|
|
29
|
+
c().sfDebug && console.error(" Error during service identification:", e);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
async send() {
|
|
@@ -68,11 +68,11 @@ class O extends k {
|
|
|
68
68
|
serviceRole: $serviceRole,
|
|
69
69
|
)
|
|
70
70
|
}
|
|
71
|
-
`, e =
|
|
72
|
-
|
|
71
|
+
`, e = c(), 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
|
+
T(this.endpoint, this.operationName, t, i);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
class
|
|
75
|
+
class We extends k {
|
|
76
76
|
constructor() {
|
|
77
77
|
super();
|
|
78
78
|
b(this, "serviceIdentifier", new O());
|
|
@@ -83,22 +83,22 @@ class xe extends k {
|
|
|
83
83
|
if (this.identifyStarted) return;
|
|
84
84
|
this.identifyStarted = !0, this.serviceIdentifier.doSend({});
|
|
85
85
|
const e = setInterval(() => {
|
|
86
|
-
|
|
86
|
+
c().serviceIdentificationReceived ? clearInterval(e) : this.serviceIdentifier.doSend({});
|
|
87
87
|
}, 5e3);
|
|
88
88
|
e && typeof e == "object" && "unref" in e && e.unref();
|
|
89
89
|
}
|
|
90
|
-
async doSend(e, i, n,
|
|
91
|
-
this.startBackgroundIdentify(), this.send(e, i, n,
|
|
90
|
+
async doSend(e, i, n, o) {
|
|
91
|
+
this.startBackgroundIdentify(), this.send(e, i, n, o);
|
|
92
92
|
}
|
|
93
|
-
async send(e, i, n,
|
|
94
|
-
if (!i && !
|
|
93
|
+
async send(e, i, n, o) {
|
|
94
|
+
if (!i && !o) throw new Error('Must pass in either traits or traits_json to "add_or_update_traits"');
|
|
95
95
|
let l = [];
|
|
96
|
-
if (!
|
|
97
|
-
const
|
|
98
|
-
|
|
96
|
+
if (!o) {
|
|
97
|
+
const s = ke(i);
|
|
98
|
+
o = s.traitsJson, l = s.excludedFields;
|
|
99
99
|
}
|
|
100
|
-
const
|
|
101
|
-
|
|
100
|
+
const u = this.getVariables({ userId: e, traitsJson: o, excludedFields: l, override: n, library: c().packageLibraryType, version: c().version });
|
|
101
|
+
T(this.endpoint, this.operationName, this.getQuery(), u);
|
|
102
102
|
}
|
|
103
103
|
getQuery() {
|
|
104
104
|
return `
|
|
@@ -108,20 +108,20 @@ class xe extends k {
|
|
|
108
108
|
`;
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
|
-
class
|
|
111
|
+
class ve {
|
|
112
112
|
constructor(t) {
|
|
113
113
|
b(this, "metadataTransmitter");
|
|
114
|
-
this.apiKey = t, this.metadataTransmitter = new
|
|
114
|
+
this.apiKey = t, this.metadataTransmitter = new We();
|
|
115
115
|
}
|
|
116
116
|
identify(t, e, i, n = !1) {
|
|
117
117
|
e || i ? this.addOrUpdateMetadata(t, e, i, n) : this.addOrUpdateMetadata(t, {}, void 0, n);
|
|
118
118
|
}
|
|
119
119
|
addOrUpdateMetadata(t, e = {}, i, n = !1) {
|
|
120
120
|
if (!e && !i) throw new Error('Must pass in either traits or traitsJson to "addOrUpdateMetadata"');
|
|
121
|
-
|
|
121
|
+
c().sfDebug && console.log(" [[DEBUG - addOrUpdateMetadata]] Starting operation"), c().sfDebug && console.log(" addOrUpdateMetadata...SENDING DATA...", t, e, i), this.metadataTransmitter.doSend(t, e, n, i);
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
|
-
class
|
|
124
|
+
class re extends k {
|
|
125
125
|
constructor() {
|
|
126
126
|
super();
|
|
127
127
|
b(this, "serviceIdentifier", new O());
|
|
@@ -131,7 +131,7 @@ class te extends k {
|
|
|
131
131
|
if (this.identifyStarted) return;
|
|
132
132
|
this.identifyStarted = !0, this.serviceIdentifier.doSend({});
|
|
133
133
|
const e = setInterval(() => {
|
|
134
|
-
|
|
134
|
+
c().serviceIdentificationReceived ? clearInterval(e) : this.serviceIdentifier.doSend({});
|
|
135
135
|
}, 5e3);
|
|
136
136
|
e && typeof e == "object" && "unref" in e && e.unref();
|
|
137
137
|
}
|
|
@@ -141,9 +141,9 @@ class te extends k {
|
|
|
141
141
|
async send(e) {
|
|
142
142
|
try {
|
|
143
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 });
|
|
144
|
-
|
|
144
|
+
T(this.endpoint, this.operationName, this.getQuery(), n);
|
|
145
145
|
} catch (i) {
|
|
146
|
-
|
|
146
|
+
c().sfDebug && console.error("🚨 Error in send():", i);
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
getQuery() {
|
|
@@ -174,7 +174,7 @@ class te extends k {
|
|
|
174
174
|
`;
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
|
-
class
|
|
177
|
+
class je extends k {
|
|
178
178
|
constructor() {
|
|
179
179
|
super();
|
|
180
180
|
b(this, "serviceIdentifier", new O());
|
|
@@ -193,7 +193,7 @@ class Be extends k {
|
|
|
193
193
|
if (this.identifyStarted) return;
|
|
194
194
|
this.identifyStarted = !0, this.serviceIdentifier.doSend({});
|
|
195
195
|
const e = setInterval(() => {
|
|
196
|
-
|
|
196
|
+
c().serviceIdentificationReceived ? clearInterval(e) : this.serviceIdentifier.doSend({});
|
|
197
197
|
}, 5e3);
|
|
198
198
|
e && typeof e == "object" && "unref" in e && e.unref();
|
|
199
199
|
}
|
|
@@ -201,9 +201,9 @@ class Be extends k {
|
|
|
201
201
|
this.startBackgroundIdentify(), this.send(e, i);
|
|
202
202
|
}
|
|
203
203
|
async send(e, i) {
|
|
204
|
-
|
|
205
|
-
const n = JSON.stringify(
|
|
206
|
-
|
|
204
|
+
c().sfDebug && console.log(" SENDING EXCEPTION...");
|
|
205
|
+
const n = JSON.stringify(Oe.encode(i)), o = this.normalizedSupplementalForGraphQL(), l = this.getVariables({ exceptionMessage: e, traceJson: n, reentrancyGuardPreactive: !1, library: c().packageLibraryType, version: c().version, ...o });
|
|
206
|
+
T(this.endpoint, this.operationName, this.getQuery(), l);
|
|
207
207
|
}
|
|
208
208
|
getQuery() {
|
|
209
209
|
return `
|
|
@@ -237,51 +237,82 @@ class Be extends k {
|
|
|
237
237
|
`;
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
|
-
const
|
|
240
|
+
const oe = "X-Sf4-Prid", ae = "getting request source code";
|
|
241
241
|
var B = ((r) => (r.UNKNOWN = "unknown", r.ANONYMOUS = "anonymous", r.NOT_CAPTURED = "not captured", r))(B || {});
|
|
242
|
-
const
|
|
243
|
-
let
|
|
244
|
-
function
|
|
245
|
-
const r =
|
|
246
|
-
if (
|
|
242
|
+
const ce = "http:", Ve = He(import.meta.url);
|
|
243
|
+
let de = !1;
|
|
244
|
+
function ze() {
|
|
245
|
+
const r = c().sfDebug;
|
|
246
|
+
if (de) return void (r && N("[patchNodeHttpInbound] Already installed, skipping."));
|
|
247
247
|
let t;
|
|
248
|
-
|
|
248
|
+
de = !0;
|
|
249
249
|
try {
|
|
250
|
-
t =
|
|
250
|
+
t = Ve("node:http"), r && N("[patchNodeHttpInbound] node:http required successfully.");
|
|
251
251
|
} catch (n) {
|
|
252
|
-
return void
|
|
252
|
+
return void Le("Failed to require node:http:", n);
|
|
253
253
|
}
|
|
254
|
-
if (!t?.Server?.prototype) return void (r &&
|
|
254
|
+
if (!t?.Server?.prototype) return void (r && N("[patchNodeHttpInbound] http.Server.prototype not found."));
|
|
255
255
|
const e = t.Server.prototype, i = e.emit;
|
|
256
|
-
i && !e.__sf_inbound_patched__ ? (Object.defineProperty(e, "__sf_inbound_patched__", { value: !0, enumerable: !1, configurable: !1, writable: !1 }), r &&
|
|
257
|
-
if (n !== "request") return r &&
|
|
258
|
-
const l =
|
|
259
|
-
const
|
|
260
|
-
if (!S) return
|
|
261
|
-
for (const [f,
|
|
262
|
-
return
|
|
263
|
-
})(l?.headers), d =
|
|
264
|
-
r && (
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
const
|
|
268
|
-
r &&
|
|
269
|
-
const
|
|
270
|
-
d &&
|
|
256
|
+
i && !e.__sf_inbound_patched__ ? (Object.defineProperty(e, "__sf_inbound_patched__", { value: !0, enumerable: !1, configurable: !1, writable: !1 }), r && N("[patchNodeHttpInbound] Patching http.Server.prototype.emit."), e.emit = function(n, ...o) {
|
|
257
|
+
if (n !== "request") return r && N(`[patchNodeHttpInbound] Passing through event: ${n}`), i.call(this, n, ...o);
|
|
258
|
+
const l = o[0], u = o[1], s = (function(S) {
|
|
259
|
+
const g = {};
|
|
260
|
+
if (!S) return g;
|
|
261
|
+
for (const [f, v] of Object.entries(S)) v != null && (Array.isArray(v) ? g[f.toLowerCase()] = v.join(", ") : g[f.toLowerCase()] = String(v));
|
|
262
|
+
return g;
|
|
263
|
+
})(l?.headers), d = s["x-sf3-rid"], p = s["x-sf3-functionspancaptureoverride"];
|
|
264
|
+
r && (N("[patchNodeHttpInbound] Intercepted request event."), N("[patchNodeHttpInbound] Inbound headers:", s), N("[patchNodeHttpInbound] Trace header:", d), N("[patchNodeHttpInbound] FuncSpan override header:", p));
|
|
265
|
+
const a = ne.getInstance();
|
|
266
|
+
a.setTraceId(d);
|
|
267
|
+
const m = a.getTraceId();
|
|
268
|
+
r && N("[patchNodeHttpInbound] Context traceId set:", m);
|
|
269
|
+
const I = () => a.runWith({ inboundHeaders: s, ...d ? { traceId: d } : {} }, () => {
|
|
270
|
+
d && a.setTraceId(d), r && N("[patchNodeHttpInbound] Running request handler in context.");
|
|
271
271
|
const S = () => {
|
|
272
|
-
r &&
|
|
272
|
+
r && N("[patchNodeHttpInbound] Response finished/closed for traceId:", a.getTraceId());
|
|
273
273
|
};
|
|
274
|
-
return
|
|
274
|
+
return u.on("finish", S), u.on("close", S), i.call(this, n, l, u);
|
|
275
275
|
});
|
|
276
|
-
if (!p) return
|
|
276
|
+
if (!p) return I();
|
|
277
277
|
try {
|
|
278
|
-
return
|
|
278
|
+
return Pe.run(p, () => I());
|
|
279
279
|
} catch {
|
|
280
|
-
return
|
|
280
|
+
return I();
|
|
281
|
+
}
|
|
282
|
+
}) : r && N("[patchNodeHttpInbound] Already patched, skipping.");
|
|
283
|
+
}
|
|
284
|
+
const ue = /* @__PURE__ */ new Map();
|
|
285
|
+
function W(r, t) {
|
|
286
|
+
const e = `${r}|${t}`;
|
|
287
|
+
let i = ue.get(e);
|
|
288
|
+
return i || (i = new RegExp(r, t), ue.set(e, i)), i;
|
|
289
|
+
}
|
|
290
|
+
function j(r, t) {
|
|
291
|
+
let e, i;
|
|
292
|
+
if (typeof r == "string" ? e = r : typeof URL < "u" && r instanceof URL ? e = r.href : typeof Request < "u" && r instanceof Request ? e = r.url : r != null && typeof r.toString == "function" && (e = r.toString()), !e) return !1;
|
|
293
|
+
try {
|
|
294
|
+
i = new URL(e, "http://localhost/");
|
|
295
|
+
} catch {
|
|
296
|
+
return !1;
|
|
297
|
+
}
|
|
298
|
+
const { hostname: n, pathname: o, port: l, protocol: u } = i;
|
|
299
|
+
if (!/^https?:$/.test(u)) return !1;
|
|
300
|
+
const s = n.startsWith("www.") ? n.slice(4).toLowerCase() : n.toLowerCase();
|
|
301
|
+
return t.some((d) => {
|
|
302
|
+
const p = String(d || "").replace(/^[a-zA-Z]+:\/\//, "");
|
|
303
|
+
if (!p) return !1;
|
|
304
|
+
let [a, m] = p.split("/", 2), I = "";
|
|
305
|
+
a.includes(":") && ([a, I] = a.split(":"));
|
|
306
|
+
const S = W(`^${a.replace(/\./g, "\\.").replace(/\*/g, ".*")}$`, "i"), g = s.startsWith("www.") ? s.slice(4) : s;
|
|
307
|
+
if (I && l !== I) return !1;
|
|
308
|
+
if (a.startsWith("*.")) {
|
|
309
|
+
const f = a.slice(2).toLowerCase();
|
|
310
|
+
return s === f || g === f || s.endsWith("." + f) ? m ? W(`^/${m.replace(/\*/g, ".*").replace(/\/$/, "")}`, "i").test(o) : !0 : !1;
|
|
281
311
|
}
|
|
282
|
-
|
|
312
|
+
return !S.test(g) && !S.test(s) ? !1 : m ? W(`^/${m.replace(/\*/g, ".*").replace(/\/$/, "")}`, "i").test(o) : !0;
|
|
313
|
+
});
|
|
283
314
|
}
|
|
284
|
-
class
|
|
315
|
+
class Je extends re {
|
|
285
316
|
constructor() {
|
|
286
317
|
super(), this.setOperationName("DomainsToNotPassHeaderTo");
|
|
287
318
|
}
|
|
@@ -302,10 +333,10 @@ class We extends te {
|
|
|
302
333
|
)
|
|
303
334
|
}
|
|
304
335
|
`, i = { apiKey: this.apiKey, serviceUuid: this.serviceUUID, domains: t };
|
|
305
|
-
|
|
336
|
+
T(this.endpoint, this.operationName, e, i);
|
|
306
337
|
}
|
|
307
338
|
}
|
|
308
|
-
class
|
|
339
|
+
class Qe extends k {
|
|
309
340
|
constructor() {
|
|
310
341
|
super();
|
|
311
342
|
b(this, "serviceIdentifier", new O());
|
|
@@ -316,7 +347,7 @@ class je extends k {
|
|
|
316
347
|
if (this.identifyStarted) return;
|
|
317
348
|
this.identifyStarted = !0, this.serviceIdentifier.doSend({});
|
|
318
349
|
const e = setInterval(() => {
|
|
319
|
-
|
|
350
|
+
c().serviceIdentificationReceived ? clearInterval(e) : this.serviceIdentifier.doSend({});
|
|
320
351
|
}, 5e3);
|
|
321
352
|
e && typeof e == "object" && "unref" in e && e.unref();
|
|
322
353
|
}
|
|
@@ -324,8 +355,8 @@ class je extends k {
|
|
|
324
355
|
this.startBackgroundIdentify(), this.send(e);
|
|
325
356
|
}
|
|
326
357
|
async send(e) {
|
|
327
|
-
const { name: i, column: n, line:
|
|
328
|
-
|
|
358
|
+
const { name: i, column: n, line: o, entrypoint: l, retryWithoutTraceId: u } = e, s = this.getVariables({ name: i, column: n, line: o, entrypoint: l, retryWithoutTraceId: u });
|
|
359
|
+
T(this.endpoint, this.operationName, this.getQuery(), s);
|
|
329
360
|
}
|
|
330
361
|
getQuery() {
|
|
331
362
|
return `
|
|
@@ -355,7 +386,7 @@ class je extends k {
|
|
|
355
386
|
`;
|
|
356
387
|
}
|
|
357
388
|
}
|
|
358
|
-
class
|
|
389
|
+
class Xe extends k {
|
|
359
390
|
constructor() {
|
|
360
391
|
super();
|
|
361
392
|
b(this, "serviceIdentifier", new O());
|
|
@@ -366,7 +397,7 @@ class Ve extends k {
|
|
|
366
397
|
if (this.identifyStarted) return;
|
|
367
398
|
this.identifyStarted = !0, this.serviceIdentifier.doSend({});
|
|
368
399
|
const e = setInterval(() => {
|
|
369
|
-
|
|
400
|
+
c().serviceIdentificationReceived ? clearInterval(e) : this.serviceIdentifier.doSend({});
|
|
370
401
|
}, 5e3);
|
|
371
402
|
e && typeof e == "object" && "unref" in e && e.unref();
|
|
372
403
|
}
|
|
@@ -385,31 +416,31 @@ class Ve extends k {
|
|
|
385
416
|
}
|
|
386
417
|
async send(e) {
|
|
387
418
|
const i = { data: { ...e } };
|
|
388
|
-
await
|
|
419
|
+
await T(this.endpoint, this.operationName, this.getQuery(), i);
|
|
389
420
|
}
|
|
390
421
|
}
|
|
391
|
-
const
|
|
392
|
-
function
|
|
422
|
+
const V = [400, 403];
|
|
423
|
+
function z(r, t) {
|
|
393
424
|
return t !== "none" && (t === "all" || r === "GET" || r === "HEAD" || r === "OPTIONS");
|
|
394
425
|
}
|
|
395
|
-
class
|
|
426
|
+
class Ye {
|
|
396
427
|
constructor(t = []) {
|
|
397
428
|
b(this, "HEADER_TRACING", "X-Sf3-Rid");
|
|
398
429
|
b(this, "HEADER_LOG_GUARD", "reentrancy_guard_logging_preactive");
|
|
399
430
|
b(this, "HEADER_PRINT_GUARD", "reentrancy_guard_print_preactive");
|
|
400
431
|
b(this, "HEADER_EXCEPTION_GUARD", "reentrancy_guard_exception_preactive");
|
|
401
432
|
b(this, "contextManager");
|
|
402
|
-
this.contextManager =
|
|
433
|
+
this.contextManager = ne.getInstance(), t?.forEach((e) => {
|
|
403
434
|
typeof e == "string" && e.trim() && this.contextManager.getExcludedDomains().add(e);
|
|
404
|
-
}),
|
|
435
|
+
}), c().sfDebug && console.log("[RequestInterceptor] Initialized with static excluded domains.");
|
|
405
436
|
}
|
|
406
437
|
extractIdsFromTraceHeader(t, e = this.HEADER_TRACING) {
|
|
407
438
|
let i;
|
|
408
439
|
if (t instanceof Headers) i = t.get(e) ?? void 0;
|
|
409
440
|
else {
|
|
410
|
-
const
|
|
411
|
-
for (const [l,
|
|
412
|
-
i =
|
|
441
|
+
const o = e.toLowerCase();
|
|
442
|
+
for (const [l, u] of Object.entries(t)) if (l.toLowerCase() === o) {
|
|
443
|
+
i = u;
|
|
413
444
|
break;
|
|
414
445
|
}
|
|
415
446
|
}
|
|
@@ -420,292 +451,313 @@ class ze {
|
|
|
420
451
|
parseStackFrame(t) {
|
|
421
452
|
const e = /\((.*):(\d+):(\d+)\)$/.exec(t.trim());
|
|
422
453
|
if (!e) return null;
|
|
423
|
-
const [, i, n,
|
|
424
|
-
return { filePath: i, line: parseInt(n, 10), column: parseInt(
|
|
454
|
+
const [, i, n, o] = e;
|
|
455
|
+
return { filePath: i, line: parseInt(n, 10), column: parseInt(o, 10) };
|
|
425
456
|
}
|
|
426
457
|
async getOriginalPosition(t, e, i) {
|
|
427
458
|
let n = { source: t, line: e, column: i, name: null };
|
|
428
459
|
if (t.includes("://")) return { originalPos: n };
|
|
429
|
-
const
|
|
460
|
+
const o = t + ".map";
|
|
430
461
|
try {
|
|
431
|
-
const l = JSON.parse(
|
|
432
|
-
let
|
|
433
|
-
|
|
462
|
+
const l = JSON.parse(xe(o, "utf-8"));
|
|
463
|
+
let u = (await new Ge.SourceMapConsumer(l)).originalPositionFor({ line: e, column: i });
|
|
464
|
+
u.source && (n = u);
|
|
434
465
|
} catch (l) {
|
|
435
|
-
|
|
466
|
+
c().sfDebug && console.error(`Could not read/parse map file at ${o}:`, l);
|
|
436
467
|
}
|
|
437
468
|
return { originalPos: n };
|
|
438
469
|
}
|
|
439
470
|
captureFirstUserLines(t, e = 10, i = !1) {
|
|
440
|
-
const n =
|
|
441
|
-
Error.stackTraceLimit = Math.max(
|
|
442
|
-
const l = new Error(
|
|
443
|
-
|
|
444
|
-
const
|
|
445
|
-
Error.stackTraceLimit =
|
|
446
|
-
const
|
|
471
|
+
const n = c().sfDebug ? 10 : e, o = Error.stackTraceLimit;
|
|
472
|
+
Error.stackTraceLimit = Math.max(o, n);
|
|
473
|
+
const l = new Error(ae);
|
|
474
|
+
ae in Error && Error.captureStackTrace(l, this.captureFirstUserLines);
|
|
475
|
+
const u = Ie(l.stack);
|
|
476
|
+
Error.stackTraceLimit = o;
|
|
477
|
+
const s = u.split(`
|
|
447
478
|
`).slice(1), d = [];
|
|
448
|
-
for (const p of
|
|
479
|
+
for (const p of s)
|
|
449
480
|
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;
|
|
450
481
|
for (const p of d) {
|
|
451
|
-
const
|
|
452
|
-
|
|
453
|
-
const { originalPos:
|
|
454
|
-
if (
|
|
455
|
-
|
|
456
|
-
const
|
|
457
|
-
t.doSend(
|
|
482
|
+
const a = this.parseStackFrame(p);
|
|
483
|
+
a ? (async () => {
|
|
484
|
+
const { originalPos: m } = await this.getOriginalPosition(a.filePath, a.line, a.column);
|
|
485
|
+
if (m) {
|
|
486
|
+
c().sfDebug && console.log("[RequestInterceptor] First user code line:", m);
|
|
487
|
+
const I = { line: m.line?.toString() || B.UNKNOWN, column: m.column?.toString() || B.NOT_CAPTURED, name: m.name || B.NOT_CAPTURED, entrypoint: m.source, retryWithoutTraceId: i };
|
|
488
|
+
t.doSend(I);
|
|
458
489
|
}
|
|
459
|
-
})() :
|
|
490
|
+
})() : c().sfDebug && console.error("Could not parse stack line:", p);
|
|
460
491
|
}
|
|
461
492
|
}
|
|
462
493
|
addReentrancyGuardHeaders(t) {
|
|
463
494
|
t.set(this.HEADER_LOG_GUARD, "true"), t.set(this.HEADER_PRINT_GUARD, "true"), t.set(this.HEADER_EXCEPTION_GUARD, "true");
|
|
464
495
|
}
|
|
465
496
|
shouldPropagateHeaders(t) {
|
|
466
|
-
|
|
497
|
+
const e = c(), i = e.domainsToPropagateHeadersTo, n = e.domainsToNotPropagateHeadersTo || [], o = Array.from(De);
|
|
498
|
+
return !!j(t, i) && !(n.length > 0 && j(t, n)) && !j(t, o);
|
|
467
499
|
}
|
|
468
500
|
addTracingHeaders(t, e) {
|
|
469
|
-
const i =
|
|
470
|
-
|
|
501
|
+
const i = this.shouldPropagateHeaders(e);
|
|
502
|
+
if (i) this.addTracingHeader(t, e);
|
|
503
|
+
else if (c().sfDebug) {
|
|
504
|
+
let n = e;
|
|
505
|
+
try {
|
|
506
|
+
n = new URL(e).hostname;
|
|
507
|
+
} catch {
|
|
508
|
+
}
|
|
509
|
+
console.error(`[RequestInterceptor] Excluded domain: ${n}`);
|
|
510
|
+
}
|
|
511
|
+
return i;
|
|
512
|
+
}
|
|
513
|
+
deriveTraceBaseAndParent(t) {
|
|
514
|
+
const e = t.split("/").filter(Boolean);
|
|
515
|
+
return e.length < 2 ? { base: t, parent: t } : { base: `${e[0]}/${e[1]}`, parent: t };
|
|
471
516
|
}
|
|
472
517
|
addTracingHeader(t, e) {
|
|
473
|
-
const i =
|
|
518
|
+
const i = Y();
|
|
474
519
|
if (i) {
|
|
475
|
-
const
|
|
476
|
-
if (
|
|
520
|
+
const s = Z(i);
|
|
521
|
+
if (s && s.sample_rate === 0) return void (c().sfDebug && console.log(`[RequestInterceptor] Function span tracking disabled (sample_rate=0), skipping tracing header for ${e}`));
|
|
477
522
|
}
|
|
478
|
-
const n = this.contextManager.getOrSetSfTraceId(),
|
|
479
|
-
t.set(this.HEADER_TRACING, `${
|
|
523
|
+
const n = this.contextManager.getOrSetSfTraceId(), { base: o, parent: l } = this.deriveTraceBaseAndParent(n), u = X();
|
|
524
|
+
t.set(this.HEADER_TRACING, `${o}/${u}`), t.set(oe, l), c().sfDebug && console.log(`[RequestInterceptor] Added tracing header for ${e}`);
|
|
480
525
|
}
|
|
481
526
|
patchFetch(t, e) {
|
|
482
527
|
const i = globalThis.fetch;
|
|
483
|
-
typeof i == "function" ? globalThis.fetch = async (n,
|
|
484
|
-
const l = new Headers(
|
|
485
|
-
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,
|
|
528
|
+
typeof i == "function" ? globalThis.fetch = async (n, o) => {
|
|
529
|
+
const l = new Headers(o?.headers);
|
|
530
|
+
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, o);
|
|
486
531
|
this.captureFirstUserLines(t);
|
|
487
|
-
const
|
|
488
|
-
let
|
|
489
|
-
if (typeof n == "string" || n instanceof URL)
|
|
532
|
+
const u = Date.now();
|
|
533
|
+
let s, d = "GET";
|
|
534
|
+
if (typeof n == "string" || n instanceof URL) s = n.toString(), d = (o?.method || "GET").toUpperCase();
|
|
490
535
|
else {
|
|
491
|
-
if (!(n instanceof Request)) return
|
|
492
|
-
|
|
493
|
-
l.set(
|
|
536
|
+
if (!(n instanceof Request)) return c().sfDebug && console.error("[Sailfish RequestInterceptor] Invalid fetch input."), i(n, o);
|
|
537
|
+
s = n.url, d = n.method.toUpperCase(), n.headers.forEach((h, w) => {
|
|
538
|
+
l.set(w, h);
|
|
494
539
|
});
|
|
495
540
|
}
|
|
496
|
-
|
|
541
|
+
c().sfDebug && console.log("[RequestInterceptor] Fetching request to:", s);
|
|
497
542
|
let p = "unknown";
|
|
498
543
|
try {
|
|
499
|
-
p = new URL(
|
|
544
|
+
p = new URL(s).hostname;
|
|
500
545
|
} catch {
|
|
501
|
-
return
|
|
546
|
+
return c().sfDebug && console.warn(`[RequestInterceptor] Could not parse URL '${s}' — passing through without tracing headers.`), i(n, o);
|
|
502
547
|
}
|
|
503
|
-
const
|
|
504
|
-
let
|
|
548
|
+
const a = new Headers(l), m = this.addTracingHeaders(l, s), I = (h) => n instanceof Request ? [new Request(n, { ...o || {}, headers: h }), void 0] : [s, { ...o, headers: h }], S = c().retryOnClientError;
|
|
549
|
+
let g, f = !1;
|
|
505
550
|
try {
|
|
506
|
-
const [
|
|
507
|
-
if (
|
|
508
|
-
const [
|
|
509
|
-
|
|
551
|
+
const [h, w] = I(l);
|
|
552
|
+
if (g = await i(h, w), m && z(d, S) && V.includes(g.status)) {
|
|
553
|
+
const [$, _] = I(a);
|
|
554
|
+
g = await i($, _), f = !0;
|
|
510
555
|
try {
|
|
511
556
|
this.captureFirstUserLines(t, 10, f);
|
|
512
557
|
} catch (F) {
|
|
513
|
-
|
|
558
|
+
c().sfDebug && console.error("[RequestInterceptor] captureFirstUserLines (retry) failed:", F);
|
|
514
559
|
}
|
|
515
560
|
} else try {
|
|
516
561
|
this.contextManager.addSupportedDomains(p);
|
|
517
|
-
} catch (
|
|
518
|
-
|
|
562
|
+
} catch ($) {
|
|
563
|
+
c().sfDebug && console.error("[RequestInterceptor] addSupportedDomains failed:", $);
|
|
519
564
|
}
|
|
520
|
-
} catch (
|
|
521
|
-
const
|
|
522
|
-
|
|
565
|
+
} catch (h) {
|
|
566
|
+
const w = Date.now();
|
|
567
|
+
c().sfDebug && console.error(`[RequestInterceptor] Fetch failed: ${s}, Error: ${h}, Duration: ${w - u}ms`);
|
|
523
568
|
try {
|
|
524
|
-
const { sessionId:
|
|
525
|
-
e.doSend({ apiKey: R.apiKey, requestId: F, pageVisitId: _, recordingSessionId:
|
|
526
|
-
} catch (
|
|
527
|
-
|
|
569
|
+
const { sessionId: $, pageVisitId: _, requestId: F } = this.extractIdsFromTraceHeader(l), R = c();
|
|
570
|
+
e.doSend({ apiKey: R.apiKey, requestId: F, pageVisitId: _, recordingSessionId: $, serviceUuid: R.serviceUUID, timestampStart: u.toString(), timestampEnd: w.toString(), responseCode: 0, success: !1, error: h instanceof Error ? h.message : typeof h == "string" ? h : JSON.stringify(h), url: s, method: d, retryWithoutTraceId: f, parentSpanId: C() });
|
|
571
|
+
} catch ($) {
|
|
572
|
+
c().sfDebug && console.error("[RequestInterceptor] Error telemetry send failed:", $);
|
|
528
573
|
}
|
|
529
|
-
throw
|
|
574
|
+
throw h;
|
|
530
575
|
}
|
|
531
|
-
const
|
|
576
|
+
const v = Date.now();
|
|
532
577
|
try {
|
|
533
|
-
|
|
534
|
-
const { sessionId:
|
|
578
|
+
c().sfDebug && console.log(`[RequestInterceptor] Fetch completed: ${s}, Status: ${g.status}, Duration: ${v - u}ms`);
|
|
579
|
+
const { sessionId: h, pageVisitId: w, requestId: $ } = this.extractIdsFromTraceHeader(l), _ = c(), F = { apiKey: _.apiKey, requestId: $, pageVisitId: w, recordingSessionId: h, serviceUuid: _.serviceUUID, timestampStart: u.toString(), timestampEnd: v.toString(), responseCode: g.status, success: !0, error: null, url: s, method: d, retryWithoutTraceId: f, parentSpanId: C() };
|
|
535
580
|
if (_.captureRequestHeaders) {
|
|
536
|
-
const
|
|
537
|
-
l.forEach((E,
|
|
538
|
-
|
|
539
|
-
}), F.requestHeaders =
|
|
581
|
+
const y = {};
|
|
582
|
+
l.forEach((E, D) => {
|
|
583
|
+
y[D] = E;
|
|
584
|
+
}), F.requestHeaders = y;
|
|
540
585
|
}
|
|
541
586
|
if (_.captureResponseHeaders) {
|
|
542
|
-
const
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
}), F.responseHeaders =
|
|
587
|
+
const y = {};
|
|
588
|
+
g.headers.forEach((E, D) => {
|
|
589
|
+
y[D] = E;
|
|
590
|
+
}), F.responseHeaders = y;
|
|
546
591
|
}
|
|
547
|
-
if (_.captureRequestBody &&
|
|
548
|
-
const
|
|
592
|
+
if (_.captureRequestBody && o?.body) {
|
|
593
|
+
const y = o.body, E = _.requestBodyLimitBytes;
|
|
549
594
|
try {
|
|
550
|
-
if (typeof
|
|
551
|
-
else if (
|
|
552
|
-
const
|
|
553
|
-
F.requestBody =
|
|
554
|
-
} else if (typeof ArrayBuffer < "u" && (
|
|
555
|
-
const
|
|
556
|
-
F.requestBody = `[binary body, ${
|
|
557
|
-
} else if (typeof Blob < "u" &&
|
|
558
|
-
else if (typeof FormData < "u" &&
|
|
559
|
-
else if (typeof ReadableStream < "u" &&
|
|
595
|
+
if (typeof y == "string") F.requestBody = y.length > E ? y.substring(0, E) + "...[truncated]" : y;
|
|
596
|
+
else if (y instanceof URLSearchParams) {
|
|
597
|
+
const D = y.toString();
|
|
598
|
+
F.requestBody = D.length > E ? D.substring(0, E) + "...[truncated]" : D;
|
|
599
|
+
} else if (typeof ArrayBuffer < "u" && (y instanceof ArrayBuffer || ArrayBuffer.isView(y))) {
|
|
600
|
+
const D = y.byteLength ?? y.byteLength;
|
|
601
|
+
F.requestBody = `[binary body, ${D} bytes — not captured]`;
|
|
602
|
+
} else if (typeof Blob < "u" && y instanceof Blob) F.requestBody = `[Blob, ${y.size} bytes, type=${y.type || "unknown"} — not captured]`;
|
|
603
|
+
else if (typeof FormData < "u" && y instanceof FormData) F.requestBody = "[FormData — not captured]";
|
|
604
|
+
else if (typeof ReadableStream < "u" && y instanceof ReadableStream) F.requestBody = "[ReadableStream — not captured]";
|
|
560
605
|
else {
|
|
561
|
-
const
|
|
562
|
-
|
|
606
|
+
const D = JSON.stringify(y);
|
|
607
|
+
D && D !== "{}" && (F.requestBody = D.length > E ? D.substring(0, E) + "...[truncated]" : D);
|
|
563
608
|
}
|
|
564
609
|
} catch {
|
|
565
610
|
}
|
|
566
611
|
}
|
|
567
612
|
let R;
|
|
568
613
|
if (_.captureResponseBody) {
|
|
569
|
-
const
|
|
570
|
-
if (!
|
|
571
|
-
const E =
|
|
614
|
+
const y = (g.headers.get("content-type") || "").toLowerCase();
|
|
615
|
+
if (!y || y.includes("json") || y.includes("xml") || y.includes("text/") || y.includes("javascript") || y.includes("ecmascript") || y.includes("x-www-form-urlencoded") || y.includes("application/graphql")) {
|
|
616
|
+
const E = g.clone(), D = _.responseBodyLimitBytes;
|
|
572
617
|
R = (async () => {
|
|
573
618
|
try {
|
|
574
|
-
const G = await E.text(),
|
|
619
|
+
const G = await E.text(), _e = G.length > D ? G.substring(0, D) + "...[truncated]" : G;
|
|
575
620
|
try {
|
|
576
|
-
e.doSend({ ...F, responseBody:
|
|
621
|
+
e.doSend({ ...F, responseBody: _e });
|
|
577
622
|
} catch {
|
|
578
623
|
}
|
|
579
624
|
} catch {
|
|
580
625
|
}
|
|
581
626
|
})(), R.catch(() => {
|
|
582
627
|
});
|
|
583
|
-
} else F.responseBody = `[non-text body, content-type=${
|
|
628
|
+
} else F.responseBody = `[non-text body, content-type=${y} — not captured]`;
|
|
584
629
|
}
|
|
585
630
|
R || e.doSend(F);
|
|
586
|
-
} catch (
|
|
587
|
-
|
|
631
|
+
} catch (h) {
|
|
632
|
+
c().sfDebug && console.error("[RequestInterceptor] Post-fetch telemetry failed (response still returned):", h);
|
|
588
633
|
}
|
|
589
|
-
return
|
|
590
|
-
} :
|
|
634
|
+
return g;
|
|
635
|
+
} : c().sfDebug && console.error("[RequestInterceptor] Fetch not available.");
|
|
591
636
|
}
|
|
592
637
|
setHeader(t, e, i) {
|
|
593
638
|
t instanceof Headers ? t.set(e, i) : t[e] = i;
|
|
594
639
|
}
|
|
595
640
|
addTracingHeadersToPlainObject(t, e) {
|
|
596
|
-
const i =
|
|
597
|
-
if (
|
|
598
|
-
const
|
|
599
|
-
if (
|
|
600
|
-
const d =
|
|
601
|
-
if (d && d.sample_rate === 0) return
|
|
641
|
+
const i = this.shouldPropagateHeaders(e);
|
|
642
|
+
if (i) {
|
|
643
|
+
const n = Y();
|
|
644
|
+
if (n) {
|
|
645
|
+
const d = Z(n);
|
|
646
|
+
if (d && d.sample_rate === 0) return c().sfDebug && console.log(`[RequestInterceptor] Function span tracking disabled (sample_rate=0), skipping tracing header for ${e}`), !1;
|
|
602
647
|
}
|
|
603
|
-
const
|
|
604
|
-
t[this.HEADER_TRACING] = `${l}/${
|
|
605
|
-
} else
|
|
606
|
-
|
|
648
|
+
const o = this.contextManager.getOrSetSfTraceId(), { base: l, parent: u } = this.deriveTraceBaseAndParent(o), s = X();
|
|
649
|
+
t[this.HEADER_TRACING] = `${l}/${s}`, t[oe] = u, c().sfDebug && console.log(`[RequestInterceptor] Added tracing header for ${e}`);
|
|
650
|
+
} else if (c().sfDebug) {
|
|
651
|
+
let n = e;
|
|
652
|
+
try {
|
|
653
|
+
n = new URL(e).hostname;
|
|
654
|
+
} catch {
|
|
655
|
+
}
|
|
656
|
+
console.error(`[RequestInterceptor] Excluded domain: ${n}`);
|
|
657
|
+
}
|
|
658
|
+
return i;
|
|
607
659
|
}
|
|
608
660
|
patchHttp(t, e) {
|
|
609
|
-
if (
|
|
610
|
-
const i = U.request.bind(U), n = A.request.bind(A),
|
|
611
|
-
let
|
|
612
|
-
if (typeof
|
|
613
|
-
const S = typeof
|
|
614
|
-
|
|
615
|
-
} else
|
|
616
|
-
return
|
|
617
|
-
}, l = (
|
|
618
|
-
const [
|
|
661
|
+
if (c().sfDebug && console.log("[RequestInterceptor] Initializing HTTP/HTTPS request patch..."), !U || typeof U.request != "function") return void (c().sfDebug && console.log("[RequestInterceptor] HTTP/HTTPS not available."));
|
|
662
|
+
const i = U.request.bind(U), n = A.request.bind(A), o = (s, d, p, a = ce) => {
|
|
663
|
+
let m, I;
|
|
664
|
+
if (typeof s == "string" || s instanceof URL) {
|
|
665
|
+
const S = typeof s == "string" ? new URL(s) : s;
|
|
666
|
+
m = { ...typeof d == "object" && d !== null ? d : {}, protocol: S.protocol || a, hostname: S.hostname, port: S.port || void 0, path: S.pathname + S.search }, I = typeof d == "function" ? d : p;
|
|
667
|
+
} else m = { ...s }, m.protocol || (m.protocol = a), I = typeof d == "function" ? d : void 0;
|
|
668
|
+
return m.headers || (m.headers = {}), [m, I];
|
|
669
|
+
}, l = (s, d, p) => {
|
|
670
|
+
const [a, m] = o(s, d, p, ce);
|
|
619
671
|
try {
|
|
620
|
-
const f = `${
|
|
621
|
-
this.addTracingHeadersToPlainObject(
|
|
672
|
+
const f = `${a.protocol}//${a.hostname}`;
|
|
673
|
+
this.addTracingHeadersToPlainObject(a.headers, f), this.captureFirstUserLines(t);
|
|
622
674
|
} catch (f) {
|
|
623
|
-
|
|
675
|
+
c().sfDebug && console.error("[RequestInterceptor] Error while processing HTTP request options:", f);
|
|
624
676
|
}
|
|
625
|
-
const
|
|
677
|
+
const I = (a.method || "GET").toUpperCase(), S = c().retryOnClientError, g = (f, v, h) => {
|
|
626
678
|
try {
|
|
627
|
-
const { sessionId:
|
|
628
|
-
e.doSend({ apiKey:
|
|
679
|
+
const { sessionId: w, pageVisitId: $, requestId: _ } = this.extractIdsFromTraceHeader(a.headers);
|
|
680
|
+
e.doSend({ apiKey: c().apiKey, requestId: _, pageVisitId: $, recordingSessionId: w, serviceUuid: c().serviceUUID, timestampStart: Date.now().toString(), timestampEnd: Date.now().toString(), responseCode: f.statusCode || 0, success: !!f.statusCode && f.statusCode < 400, error: null, url: v, method: I, retryWithoutTraceId: h, parentSpanId: C() });
|
|
629
681
|
} catch {
|
|
630
682
|
}
|
|
631
|
-
|
|
683
|
+
m?.(f);
|
|
632
684
|
};
|
|
633
|
-
return i(
|
|
634
|
-
const
|
|
635
|
-
let
|
|
685
|
+
return i(a, (f) => {
|
|
686
|
+
const v = `${a.protocol}//${a.hostname}`;
|
|
687
|
+
let h = !1;
|
|
636
688
|
try {
|
|
637
|
-
|
|
689
|
+
h = this.shouldPropagateHeaders(v);
|
|
638
690
|
} catch {
|
|
639
|
-
|
|
691
|
+
h = !1;
|
|
640
692
|
}
|
|
641
|
-
if (
|
|
693
|
+
if (h && z(I, S) && V.includes(f.statusCode || 0)) {
|
|
642
694
|
f.resume();
|
|
643
695
|
try {
|
|
644
|
-
const { sessionId:
|
|
645
|
-
e.doSend({ apiKey:
|
|
696
|
+
const { sessionId: $, pageVisitId: _, requestId: F } = this.extractIdsFromTraceHeader(a.headers);
|
|
697
|
+
e.doSend({ apiKey: c().apiKey, requestId: F, pageVisitId: _, recordingSessionId: $, serviceUuid: c().serviceUUID, timestampStart: Date.now().toString(), timestampEnd: Date.now().toString(), responseCode: f.statusCode || 0, success: !1, error: null, url: v, method: I, retryWithoutTraceId: !1, parentSpanId: C() });
|
|
646
698
|
} catch {
|
|
647
699
|
}
|
|
648
700
|
try {
|
|
649
701
|
this.captureFirstUserLines(t, 10, !0);
|
|
650
702
|
} catch {
|
|
651
703
|
}
|
|
652
|
-
const
|
|
653
|
-
return delete
|
|
654
|
-
|
|
704
|
+
const w = { ...a, headers: { ...a.headers } };
|
|
705
|
+
return delete w.headers[this.HEADER_TRACING], void i(w, ($) => {
|
|
706
|
+
g($, v, !0);
|
|
655
707
|
}).end();
|
|
656
708
|
}
|
|
657
|
-
|
|
709
|
+
g(f, v, !1);
|
|
658
710
|
});
|
|
659
|
-
},
|
|
660
|
-
const [
|
|
711
|
+
}, u = (s, d, p) => {
|
|
712
|
+
const [a, m] = o(s, d, p, "https:");
|
|
661
713
|
try {
|
|
662
|
-
const f = `${
|
|
663
|
-
this.addTracingHeadersToPlainObject(
|
|
714
|
+
const f = `${a.protocol}//${a.hostname}`;
|
|
715
|
+
this.addTracingHeadersToPlainObject(a.headers, f), this.captureFirstUserLines(t);
|
|
664
716
|
} catch (f) {
|
|
665
|
-
|
|
717
|
+
c().sfDebug && console.error("[RequestInterceptor] Error while processing HTTPS request options:", f);
|
|
666
718
|
}
|
|
667
|
-
const
|
|
719
|
+
const I = (a.method || "GET").toUpperCase(), S = c().retryOnClientError, g = (f, v, h) => {
|
|
668
720
|
try {
|
|
669
|
-
const { sessionId:
|
|
670
|
-
e.doSend({ apiKey:
|
|
721
|
+
const { sessionId: w, pageVisitId: $, requestId: _ } = this.extractIdsFromTraceHeader(a.headers);
|
|
722
|
+
e.doSend({ apiKey: c().apiKey, requestId: _, pageVisitId: $, recordingSessionId: w, serviceUuid: c().serviceUUID, timestampStart: Date.now().toString(), timestampEnd: Date.now().toString(), responseCode: f.statusCode || 0, success: !!f.statusCode && f.statusCode < 400, error: null, url: v, method: I, retryWithoutTraceId: h, parentSpanId: C() });
|
|
671
723
|
} catch {
|
|
672
724
|
}
|
|
673
|
-
|
|
725
|
+
m?.(f);
|
|
674
726
|
};
|
|
675
|
-
return n(
|
|
676
|
-
const
|
|
677
|
-
let
|
|
727
|
+
return n(a, (f) => {
|
|
728
|
+
const v = `${a.protocol}//${a.hostname}`;
|
|
729
|
+
let h = !1;
|
|
678
730
|
try {
|
|
679
|
-
|
|
731
|
+
h = this.shouldPropagateHeaders(v);
|
|
680
732
|
} catch {
|
|
681
|
-
|
|
733
|
+
h = !1;
|
|
682
734
|
}
|
|
683
|
-
if (
|
|
735
|
+
if (h && z(I, S) && V.includes(f.statusCode || 0)) {
|
|
684
736
|
f.resume();
|
|
685
737
|
try {
|
|
686
|
-
const { sessionId:
|
|
687
|
-
e.doSend({ apiKey:
|
|
738
|
+
const { sessionId: $, pageVisitId: _, requestId: F } = this.extractIdsFromTraceHeader(a.headers);
|
|
739
|
+
e.doSend({ apiKey: c().apiKey, requestId: F, pageVisitId: _, recordingSessionId: $, serviceUuid: c().serviceUUID, timestampStart: Date.now().toString(), timestampEnd: Date.now().toString(), responseCode: f.statusCode || 0, success: !1, error: null, url: v, method: I, retryWithoutTraceId: !1, parentSpanId: C() });
|
|
688
740
|
} catch {
|
|
689
741
|
}
|
|
690
742
|
try {
|
|
691
743
|
this.captureFirstUserLines(t, 10, !0);
|
|
692
744
|
} catch {
|
|
693
745
|
}
|
|
694
|
-
const
|
|
695
|
-
return delete
|
|
696
|
-
|
|
746
|
+
const w = { ...a, headers: { ...a.headers } };
|
|
747
|
+
return delete w.headers[this.HEADER_TRACING], void n(w, ($) => {
|
|
748
|
+
g($, v, !0);
|
|
697
749
|
}).end();
|
|
698
750
|
}
|
|
699
|
-
|
|
751
|
+
g(f, v, !1);
|
|
700
752
|
});
|
|
701
753
|
};
|
|
702
|
-
U.request = l, A.request =
|
|
703
|
-
const
|
|
704
|
-
return
|
|
705
|
-
}, A.get = (
|
|
706
|
-
const
|
|
707
|
-
return
|
|
708
|
-
},
|
|
754
|
+
U.request = l, A.request = u, U.get = (s, d, p) => {
|
|
755
|
+
const a = l(s, d, p);
|
|
756
|
+
return a.end(), a;
|
|
757
|
+
}, A.get = (s, d, p) => {
|
|
758
|
+
const a = u(s, d, p);
|
|
759
|
+
return a.end(), a;
|
|
760
|
+
}, c().sfDebug && console.log("✅ HTTP and HTTPS request/get methods patched globally.");
|
|
709
761
|
}
|
|
710
762
|
tryPatch(t, e) {
|
|
711
763
|
try {
|
|
@@ -717,7 +769,7 @@ class ze {
|
|
|
717
769
|
return [...this.contextManager.getExcludedDomains()];
|
|
718
770
|
}
|
|
719
771
|
}
|
|
720
|
-
class
|
|
772
|
+
class Ze extends re {
|
|
721
773
|
constructor() {
|
|
722
774
|
super(), this.setOperationName("UpdateServiceDetails");
|
|
723
775
|
}
|
|
@@ -767,11 +819,11 @@ class Je extends te {
|
|
|
767
819
|
serviceRole: $serviceRole,
|
|
768
820
|
)
|
|
769
821
|
}
|
|
770
|
-
`, e =
|
|
771
|
-
|
|
822
|
+
`, e = c(), 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 });
|
|
823
|
+
T(this.endpoint, this.operationName, t, i);
|
|
772
824
|
}
|
|
773
825
|
}
|
|
774
|
-
class
|
|
826
|
+
class et {
|
|
775
827
|
constructor(t = [process.cwd()], e = !1) {
|
|
776
828
|
b(this, "rootPaths");
|
|
777
829
|
b(this, "fileConfigs", /* @__PURE__ */ new Map());
|
|
@@ -785,29 +837,29 @@ class Qe {
|
|
|
785
837
|
async loadAllConfigs() {
|
|
786
838
|
this.debug && console.log("[FuncSpan ConfigLoader] Scanning for .sailfish files in:", this.rootPaths);
|
|
787
839
|
const t = [];
|
|
788
|
-
for (const e of this.rootPaths)
|
|
840
|
+
for (const e of this.rootPaths) Me.existsSync(e) ? await this._walkDirectory(e, t) : this.debug && console.log(`[FuncSpan ConfigLoader] Root path does not exist: ${e}`);
|
|
789
841
|
t.length > 0 ? (this.hasSailfishFiles = !0, this.debug && (console.log(`[FuncSpan ConfigLoader] Found ${t.length} .sailfish files:`), t.forEach((e) => console.log(`[FuncSpan ConfigLoader] - ${e}`)))) : this.debug && console.log("[FuncSpan ConfigLoader] No .sailfish files found - function spans disabled by default");
|
|
790
842
|
for (const e of t) await this._loadConfigFile(e);
|
|
791
843
|
await this._resolveInheritance(), this.debug && console.log(`[FuncSpan ConfigLoader] Loaded ${this.fileConfigs.size} file configs, ${this.functionConfigs.size} function configs`);
|
|
792
844
|
}
|
|
793
845
|
getConfig(t, e) {
|
|
794
|
-
const i = this.hasSailfishFiles ?
|
|
795
|
-
let
|
|
846
|
+
const i = this.hasSailfishFiles ? Re() : Se(), n = this._getDirectoryConfig(t), o = P.normalize(t), l = this.fileConfigs.get(o) || {};
|
|
847
|
+
let u = {};
|
|
796
848
|
if (e) {
|
|
797
|
-
const
|
|
798
|
-
|
|
849
|
+
const s = this.functionConfigs.get(o);
|
|
850
|
+
s && (u = s.get(e) || {});
|
|
799
851
|
}
|
|
800
|
-
return L(i, n, l,
|
|
852
|
+
return L(i, n, l, u);
|
|
801
853
|
}
|
|
802
854
|
hasRuntimeMode() {
|
|
803
855
|
return this.runtimeModeEnabled;
|
|
804
856
|
}
|
|
805
857
|
async _walkDirectory(t, e) {
|
|
806
858
|
try {
|
|
807
|
-
const i = await
|
|
859
|
+
const i = await se.readdir(t, { withFileTypes: !0 });
|
|
808
860
|
for (const n of i) {
|
|
809
|
-
const
|
|
810
|
-
n.isFile() && n.name === ".sailfish" ? e.push(
|
|
861
|
+
const o = P.join(t, n.name);
|
|
862
|
+
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);
|
|
811
863
|
}
|
|
812
864
|
} catch (i) {
|
|
813
865
|
this.debug && console.error(`[FuncSpan ConfigLoader] Error walking directory ${t}:`, i);
|
|
@@ -815,7 +867,7 @@ class Qe {
|
|
|
815
867
|
}
|
|
816
868
|
async _loadConfigFile(t) {
|
|
817
869
|
try {
|
|
818
|
-
const e = await
|
|
870
|
+
const e = await se.readFile(t, "utf-8"), i = P.dirname(t);
|
|
819
871
|
let n = null;
|
|
820
872
|
try {
|
|
821
873
|
n = JSON.parse(e);
|
|
@@ -825,8 +877,8 @@ class Qe {
|
|
|
825
877
|
} catch {
|
|
826
878
|
try {
|
|
827
879
|
n = require("js-yaml").load(e);
|
|
828
|
-
} catch (
|
|
829
|
-
return void (this.debug && console.error(`[FuncSpan ConfigLoader] Failed to parse ${t} as JSON, TOML, or YAML:`,
|
|
880
|
+
} catch (o) {
|
|
881
|
+
return void (this.debug && console.error(`[FuncSpan ConfigLoader] Failed to parse ${t} as JSON, TOML, or YAML:`, o));
|
|
830
882
|
}
|
|
831
883
|
}
|
|
832
884
|
}
|
|
@@ -837,28 +889,28 @@ class Qe {
|
|
|
837
889
|
}
|
|
838
890
|
}
|
|
839
891
|
async _expandFileGlobs(t, e, i) {
|
|
840
|
-
for (const [n,
|
|
841
|
-
const l = P.join(t, n),
|
|
842
|
-
this.debug && console.log(`[FuncSpan ConfigLoader] Pattern '${n}' matched ${
|
|
843
|
-
for (const
|
|
844
|
-
const d = P.normalize(
|
|
845
|
-
this.fileConfigs.set(d, p), this.debug &&
|
|
892
|
+
for (const [n, o] of Object.entries(e)) try {
|
|
893
|
+
const l = P.join(t, n), u = await Ke(l, { absolute: !0, nodir: !0, ignore: ["**/node_modules/**", "**/.git/**"] });
|
|
894
|
+
this.debug && console.log(`[FuncSpan ConfigLoader] Pattern '${n}' matched ${u.length} files`);
|
|
895
|
+
for (const s of u) {
|
|
896
|
+
const d = P.normalize(s), p = L(i, o);
|
|
897
|
+
this.fileConfigs.set(d, p), this.debug && u.length <= 5 && console.log(`[FuncSpan ConfigLoader] - ${s}`);
|
|
846
898
|
}
|
|
847
899
|
} catch (l) {
|
|
848
900
|
this.debug && console.error(`[FuncSpan ConfigLoader] Error expanding glob '${n}':`, l);
|
|
849
901
|
}
|
|
850
902
|
}
|
|
851
903
|
_storeFunctionConfigs(t, e, i) {
|
|
852
|
-
for (const [n,
|
|
904
|
+
for (const [n, o] of Object.entries(e)) {
|
|
853
905
|
const l = n.split("::");
|
|
854
906
|
if (l.length !== 2) {
|
|
855
907
|
this.debug && console.warn(`[FuncSpan ConfigLoader] Invalid function pattern '${n}' (expected format: 'file.ts::functionName')`);
|
|
856
908
|
continue;
|
|
857
909
|
}
|
|
858
|
-
const [
|
|
910
|
+
const [u, s] = l, d = P.normalize(P.join(t, u));
|
|
859
911
|
this.functionConfigs.has(d) || this.functionConfigs.set(d, /* @__PURE__ */ new Map());
|
|
860
|
-
const p = this.functionConfigs.get(d),
|
|
861
|
-
p.set(
|
|
912
|
+
const p = this.functionConfigs.get(d), a = L(i, o);
|
|
913
|
+
p.set(s, a), this.debug && console.log(`[FuncSpan ConfigLoader] Function config: ${d}::${s}`);
|
|
862
914
|
}
|
|
863
915
|
}
|
|
864
916
|
async _resolveInheritance() {
|
|
@@ -870,37 +922,37 @@ class Qe {
|
|
|
870
922
|
const n = this.directoryConfigs.get(e);
|
|
871
923
|
n && i.unshift(n), e = P.dirname(e);
|
|
872
924
|
}
|
|
873
|
-
return i.reduce((n,
|
|
925
|
+
return i.reduce((n, o) => L(n, o), {});
|
|
874
926
|
}
|
|
875
927
|
}
|
|
876
|
-
const
|
|
877
|
-
function
|
|
878
|
-
return globalThis[
|
|
928
|
+
const $e = "__sf_globalConfigLoader";
|
|
929
|
+
function be() {
|
|
930
|
+
return globalThis[$e] ?? null;
|
|
879
931
|
}
|
|
880
|
-
async function
|
|
881
|
-
const e = new
|
|
932
|
+
async function tt(r, t) {
|
|
933
|
+
const e = new et(r, t);
|
|
882
934
|
(function(i) {
|
|
883
|
-
globalThis[
|
|
935
|
+
globalThis[$e] = i;
|
|
884
936
|
})(e), await e.loadAllConfigs();
|
|
885
937
|
}
|
|
886
|
-
function
|
|
887
|
-
const e =
|
|
888
|
-
return e ? e.getConfig(r, t) : (process.env.SF_DEBUG === "true" && console.log("[FuncSpan ConfigLoader] Config loader not initialized, using default config (disabled)"),
|
|
938
|
+
function nt(r, t) {
|
|
939
|
+
const e = be();
|
|
940
|
+
return e ? e.getConfig(r, t) : (process.env.SF_DEBUG === "true" && console.log("[FuncSpan ConfigLoader] Config loader not initialized, using default config (disabled)"), Se());
|
|
889
941
|
}
|
|
890
|
-
function
|
|
891
|
-
return
|
|
942
|
+
function rt() {
|
|
943
|
+
return be() !== null;
|
|
892
944
|
}
|
|
893
|
-
const
|
|
894
|
-
let
|
|
895
|
-
function
|
|
945
|
+
const it = ["readFile", "writeFile", "appendFile", "readdir", "stat", "lstat", "fstat", "access", "open", "close", "read", "write", "chmod", "mkdir", "rmdir", "unlink", "rename"], le = ["lookup", "resolve", "resolve4", "resolve6", "resolveAny", "resolveMx", "resolveNs", "resolveTxt", "reverse"], st = ["pbkdf2", "randomBytes", "scrypt", "generateKeyPair"], ot = ["gzip", "gunzip", "deflate", "inflate", "deflateRaw", "inflateRaw", "brotliCompress", "brotliDecompress"];
|
|
946
|
+
let pe = !1;
|
|
947
|
+
function at(r) {
|
|
896
948
|
if (typeof r != "string") return !1;
|
|
897
949
|
const t = process.env.SF_FUNCSPAN_JSONL_FILE;
|
|
898
950
|
if (t && r.includes(t)) return !0;
|
|
899
951
|
const e = process.env.SF_WORKER_POOL_JSONL_FILE;
|
|
900
952
|
return !(!e || !r.includes(e));
|
|
901
953
|
}
|
|
902
|
-
let
|
|
903
|
-
function
|
|
954
|
+
let fe = !1;
|
|
955
|
+
function ge(r) {
|
|
904
956
|
if (typeof r != "string") return !1;
|
|
905
957
|
if (r === "localhost" || r === "127.0.0.1" || r === "::1") return !0;
|
|
906
958
|
try {
|
|
@@ -911,8 +963,8 @@ function ue(r) {
|
|
|
911
963
|
}
|
|
912
964
|
return !1;
|
|
913
965
|
}
|
|
914
|
-
function
|
|
915
|
-
if (!
|
|
966
|
+
function ct() {
|
|
967
|
+
if (!fe) try {
|
|
916
968
|
let r;
|
|
917
969
|
if (typeof require > "u") return void (process.env.SF_DEBUG === "true" && console.log("[WorkerPool] Skipping dns patching in pure ESM environment (require unavailable)"));
|
|
918
970
|
try {
|
|
@@ -922,231 +974,231 @@ function it() {
|
|
|
922
974
|
}
|
|
923
975
|
if (r.__sf_worker_pool_patched__) return;
|
|
924
976
|
Object.defineProperty(r, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
925
|
-
for (const t of
|
|
977
|
+
for (const t of le) if (typeof r[t] == "function") {
|
|
926
978
|
const e = r[t];
|
|
927
979
|
r[t] = function(...i) {
|
|
928
|
-
return
|
|
980
|
+
return ie() ? e.apply(this, i) : ge(i[0]) ? e.apply(this, i) : typeof i[i.length - 1] == "function" ? x("dns", t, e, i, this) : e.apply(this, i);
|
|
929
981
|
}, Object.defineProperty(r[t], "name", { value: t, writable: !1 });
|
|
930
982
|
}
|
|
931
983
|
(function(t) {
|
|
932
984
|
if (!t.promises) return void (process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns.promises not available, skipping"));
|
|
933
985
|
if (!t.promises.__sf_worker_pool_patched__) {
|
|
934
986
|
Object.defineProperty(t.promises, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
935
|
-
for (const e of
|
|
987
|
+
for (const e of le) if (typeof t.promises[e] == "function") {
|
|
936
988
|
const i = t.promises[e];
|
|
937
989
|
t.promises[e] = function(...n) {
|
|
938
|
-
return
|
|
990
|
+
return ie() ? i.apply(this, n) : ge(n[0]) ? i.apply(this, n) : Te("dns", e, i, n, this);
|
|
939
991
|
}, Object.defineProperty(t.promises[e], "name", { value: e, writable: !1 });
|
|
940
992
|
}
|
|
941
993
|
process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns.promises module patched successfully");
|
|
942
994
|
}
|
|
943
|
-
})(r),
|
|
995
|
+
})(r), fe = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns module patched successfully");
|
|
944
996
|
} catch (r) {
|
|
945
997
|
console.error("[WorkerPool] Error patching dns module:", r);
|
|
946
998
|
}
|
|
947
999
|
}
|
|
948
|
-
let
|
|
949
|
-
function
|
|
950
|
-
if (
|
|
1000
|
+
let he = !1, me = !1, ee = !1;
|
|
1001
|
+
function dt() {
|
|
1002
|
+
if (ee) return;
|
|
951
1003
|
const r = process.env.SF_DEBUG === "true";
|
|
952
1004
|
r && console.log("[WorkerPool] Initializing worker pool patching..."), q("fs") && (r && console.log("[WorkerPool] Patching fs module..."), (function() {
|
|
953
|
-
if (!
|
|
1005
|
+
if (!pe) try {
|
|
954
1006
|
const t = require("node:fs");
|
|
955
1007
|
if (t.__sf_worker_pool_patched__) return;
|
|
956
1008
|
Object.defineProperty(t, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
957
|
-
for (const e of
|
|
1009
|
+
for (const e of it) if (typeof t[e] == "function") {
|
|
958
1010
|
const i = t[e];
|
|
959
1011
|
t[e] = function(...n) {
|
|
960
|
-
return
|
|
1012
|
+
return at(n[0]) ? i.apply(this, n) : typeof n[n.length - 1] == "function" ? x("fs", e, i, n, this) : i.apply(this, n);
|
|
961
1013
|
}, Object.defineProperty(t[e], "name", { value: e, writable: !1 });
|
|
962
1014
|
}
|
|
963
|
-
|
|
1015
|
+
pe = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] fs module patched successfully");
|
|
964
1016
|
} catch (t) {
|
|
965
1017
|
console.error("[WorkerPool] Error patching fs module:", t);
|
|
966
1018
|
}
|
|
967
|
-
})()), q("dns") && (r && console.log("[WorkerPool] Patching dns module..."),
|
|
968
|
-
if (!
|
|
1019
|
+
})()), q("dns") && (r && console.log("[WorkerPool] Patching dns module..."), ct()), q("crypto") && (r && console.log("[WorkerPool] Patching crypto module..."), (function() {
|
|
1020
|
+
if (!he) try {
|
|
969
1021
|
const t = require("node:crypto");
|
|
970
1022
|
if (t.__sf_worker_pool_patched__) return;
|
|
971
1023
|
Object.defineProperty(t, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
972
|
-
for (const e of
|
|
1024
|
+
for (const e of st) if (typeof t[e] == "function") {
|
|
973
1025
|
const i = t[e];
|
|
974
1026
|
t[e] = function(...n) {
|
|
975
1027
|
return typeof n[n.length - 1] == "function" ? x("crypto", e, i, n, this) : i.apply(this, n);
|
|
976
1028
|
}, Object.defineProperty(t[e], "name", { value: e, writable: !1 });
|
|
977
1029
|
}
|
|
978
|
-
|
|
1030
|
+
he = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] crypto module patched successfully");
|
|
979
1031
|
} catch (t) {
|
|
980
1032
|
console.error("[WorkerPool] Error patching crypto module:", t);
|
|
981
1033
|
}
|
|
982
1034
|
})()), q("zlib") && (r && console.log("[WorkerPool] Patching zlib module..."), (function() {
|
|
983
|
-
if (!
|
|
1035
|
+
if (!me) try {
|
|
984
1036
|
const t = require("node:zlib");
|
|
985
1037
|
if (t.__sf_worker_pool_patched__) return;
|
|
986
1038
|
Object.defineProperty(t, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
987
|
-
for (const e of
|
|
1039
|
+
for (const e of ot) if (typeof t[e] == "function") {
|
|
988
1040
|
const i = t[e];
|
|
989
1041
|
t[e] = function(...n) {
|
|
990
1042
|
return typeof n[n.length - 1] == "function" ? x("zlib", e, i, n, this) : i.apply(this, n);
|
|
991
1043
|
}, Object.defineProperty(t[e], "name", { value: e, writable: !1 });
|
|
992
1044
|
}
|
|
993
|
-
|
|
1045
|
+
me = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] zlib module patched successfully");
|
|
994
1046
|
} catch (t) {
|
|
995
1047
|
console.error("[WorkerPool] Error patching zlib module:", t);
|
|
996
1048
|
}
|
|
997
|
-
})()),
|
|
1049
|
+
})()), ee = !0, r && console.log("[WorkerPool] Worker pool patching initialized");
|
|
998
1050
|
}
|
|
999
|
-
function
|
|
1000
|
-
return
|
|
1051
|
+
function ut() {
|
|
1052
|
+
return ee;
|
|
1001
1053
|
}
|
|
1002
|
-
let
|
|
1003
|
-
function
|
|
1004
|
-
if (
|
|
1005
|
-
else if (!
|
|
1006
|
-
|
|
1054
|
+
let te = !1, J = !1;
|
|
1055
|
+
function bt(r) {
|
|
1056
|
+
if (J) console.warn("[setupInterceptors] ⚠️ Recursive call detected and blocked!");
|
|
1057
|
+
else if (!te) {
|
|
1058
|
+
J = !0, Ce();
|
|
1007
1059
|
try {
|
|
1008
1060
|
let t, e;
|
|
1009
|
-
const i =
|
|
1061
|
+
const i = Ie(new Error().stack);
|
|
1010
1062
|
if (i) {
|
|
1011
|
-
const
|
|
1012
|
-
`)[2] || "",
|
|
1013
|
-
|
|
1063
|
+
const u = i.split(`
|
|
1064
|
+
`)[2] || "", s = u.match(/\((.+):(\d+):\d+\)/) || u.match(/at (.+):(\d+):\d+/);
|
|
1065
|
+
s && (t = s[1], e = parseInt(s[2], 10));
|
|
1014
1066
|
}
|
|
1015
1067
|
if (!r || !r.apiKey) {
|
|
1016
|
-
const
|
|
1017
|
-
console.error(
|
|
1068
|
+
const u = `The required API Key is not provided: ${JSON.stringify(r)}`;
|
|
1069
|
+
console.error(u);
|
|
1018
1070
|
}
|
|
1019
|
-
const { config: n } =
|
|
1020
|
-
if (
|
|
1071
|
+
const { config: n } = Ne(r);
|
|
1072
|
+
if (Ee(n).catch(() => {
|
|
1021
1073
|
}), t && (n.setupInterceptorsFile = t), e && (n.setupInterceptorsLine = e), n.sfDebug && console.log("Updated configuration after applying options:", n), !n.apiKey || !n.apiGraphqlEndpoint) {
|
|
1022
|
-
const
|
|
1023
|
-
throw console.error(
|
|
1074
|
+
const u = `The required config is not provided: ${JSON.stringify(n)}`;
|
|
1075
|
+
throw console.error(u), new Error(u);
|
|
1024
1076
|
}
|
|
1025
|
-
|
|
1026
|
-
n.sfDebug && console.error("[FuncSpan] Failed to initialize config loader:",
|
|
1027
|
-
}), process.env.SF_WORKER_POOL_DISABLED === "true" ? n.sfDebug && console.log("[setupInterceptors] Worker pool patching DISABLED (SF_WORKER_POOL_DISABLED=true)") :
|
|
1028
|
-
const
|
|
1029
|
-
|
|
1030
|
-
const
|
|
1031
|
-
new
|
|
1032
|
-
const d = new
|
|
1033
|
-
|
|
1077
|
+
rt() || tt(void 0, n.sfDebug).catch((u) => {
|
|
1078
|
+
n.sfDebug && console.error("[FuncSpan] Failed to initialize config loader:", u);
|
|
1079
|
+
}), process.env.SF_WORKER_POOL_DISABLED === "true" ? n.sfDebug && console.log("[setupInterceptors] Worker pool patching DISABLED (SF_WORKER_POOL_DISABLED=true)") : ut() || (dt(), n.sfDebug && console.log("[setupInterceptors] Worker pool patching initialized (DNS tracking enabled)"));
|
|
1080
|
+
const o = new re();
|
|
1081
|
+
o.setServiceUUID(n.serviceUUID), qe(o), (function(u = []) {
|
|
1082
|
+
const s = new Ye(u);
|
|
1083
|
+
new Je().doSend(s.getExcludedDomains());
|
|
1084
|
+
const d = new Qe(), p = new Xe();
|
|
1085
|
+
s.patchFetch(d, p), s.patchHttp(d, p);
|
|
1034
1086
|
})(n.domainsToNotPropagateHeadersTo);
|
|
1035
|
-
const l = new
|
|
1036
|
-
l.setServiceUUID(n.serviceUUID),
|
|
1087
|
+
const l = new je();
|
|
1088
|
+
l.setServiceUUID(n.serviceUUID), Ae(l), ze(), new Ze().send(), te = !0, n.sfDebug && console.log("[setupInterceptors] ✅ Initialization complete");
|
|
1037
1089
|
} finally {
|
|
1038
|
-
|
|
1090
|
+
J = !1;
|
|
1039
1091
|
}
|
|
1040
1092
|
}
|
|
1041
1093
|
}
|
|
1042
|
-
function
|
|
1043
|
-
return
|
|
1094
|
+
function _t() {
|
|
1095
|
+
return te;
|
|
1044
1096
|
}
|
|
1045
|
-
function
|
|
1046
|
-
const n =
|
|
1047
|
-
new
|
|
1097
|
+
function Ft(r, t, e, i = !1) {
|
|
1098
|
+
const n = c();
|
|
1099
|
+
new ve(n.apiKey).identify(r, t, e, i);
|
|
1048
1100
|
}
|
|
1049
|
-
function
|
|
1050
|
-
const n =
|
|
1051
|
-
new
|
|
1101
|
+
function wt(r, t = {}, e, i = !1) {
|
|
1102
|
+
const n = c();
|
|
1103
|
+
new ve(n.apiKey).addOrUpdateMetadata(r, t, e, i);
|
|
1052
1104
|
}
|
|
1053
|
-
let
|
|
1054
|
-
function
|
|
1055
|
-
const n = function(...
|
|
1056
|
-
const l =
|
|
1057
|
-
|
|
1058
|
-
const
|
|
1059
|
-
const
|
|
1060
|
-
if (
|
|
1061
|
-
const
|
|
1062
|
-
if (
|
|
1105
|
+
let Q = null;
|
|
1106
|
+
function Dt(r, t, e, i) {
|
|
1107
|
+
const n = function(...o) {
|
|
1108
|
+
const l = ye(), u = l?.sfDebug || !1;
|
|
1109
|
+
u && console.log(`[FuncSpan] captureFunctionSpan wrapper called for ${e}::${t}`);
|
|
1110
|
+
const s = (function(g, f) {
|
|
1111
|
+
const v = Y();
|
|
1112
|
+
if (v) {
|
|
1113
|
+
const h = Z(v);
|
|
1114
|
+
if (h) return process.env.SF_DEBUG === "true" && console.log(`[FuncSpan] Using HTTP header override for ${g}::${f}`), h;
|
|
1063
1115
|
}
|
|
1064
1116
|
try {
|
|
1065
|
-
return
|
|
1117
|
+
return nt(g, f);
|
|
1066
1118
|
} catch {
|
|
1067
1119
|
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 };
|
|
1068
1120
|
}
|
|
1069
1121
|
})(e, t);
|
|
1070
|
-
if (
|
|
1071
|
-
if (
|
|
1072
|
-
|
|
1073
|
-
const d =
|
|
1074
|
-
d.setCurrentFunctionSpanId(
|
|
1075
|
-
const
|
|
1122
|
+
if (u && console.log(`[FuncSpan] Config for ${e}::${t}:`, s), s.enable_sampling && s.sample_rate < 1 && Math.random() > s.sample_rate) return u && console.log(`[FuncSpan] Skipping ${t} due to sampling`), r.apply(this, o);
|
|
1123
|
+
if (s.sample_rate === 0) return u && console.log(`[FuncSpan] Skipping ${t} - sample_rate is 0.0`), r.apply(this, o);
|
|
1124
|
+
u && console.log(`[FuncSpan] Capturing function span for ${t}`);
|
|
1125
|
+
const d = ne.getInstance(), p = d.getCurrentFunctionSpanId(), a = X();
|
|
1126
|
+
d.setCurrentFunctionSpanId(a);
|
|
1127
|
+
const m = process.hrtime.bigint(), I = Date.now();
|
|
1076
1128
|
let S = null;
|
|
1077
|
-
|
|
1078
|
-
f <
|
|
1079
|
-
}), S &&
|
|
1129
|
+
s.capture_arguments && (S = {}, i.paramNames.forEach((g, f) => {
|
|
1130
|
+
f < o.length && (S[g] = o[f]);
|
|
1131
|
+
}), S && s.arg_limit_mb > 0 && (S = K(S, s.arg_limit_mb)));
|
|
1080
1132
|
try {
|
|
1081
|
-
const
|
|
1082
|
-
if (
|
|
1083
|
-
const _ = process.hrtime.bigint(), F = Date.now(), R = Number(_ -
|
|
1084
|
-
let
|
|
1085
|
-
return
|
|
1086
|
-
}, (
|
|
1087
|
-
const _ = process.hrtime.bigint(), F = Date.now(), R = Number(_ -
|
|
1088
|
-
throw M({ functionName: t, filePath: e, metadata: i, args: S, result: null, error:
|
|
1133
|
+
const g = r.apply(this, o);
|
|
1134
|
+
if (g && typeof g.then == "function") return p ? d.setCurrentFunctionSpanId(p) : d.clearCurrentFunctionSpanId(), g.then(($) => {
|
|
1135
|
+
const _ = process.hrtime.bigint(), F = Date.now(), R = Number(_ - m);
|
|
1136
|
+
let y = null;
|
|
1137
|
+
return s.capture_return_value && s.return_limit_mb > 0 && (y = K($, s.return_limit_mb)), M({ functionName: t, filePath: e, metadata: i, args: S, result: y, error: null, duration: F - I, durationNs: R, startTimeNs: m.toString(), async: !0, spanId: a, parentSpanId: p, pid: process.pid, threadId: H }), $;
|
|
1138
|
+
}, ($) => {
|
|
1139
|
+
const _ = process.hrtime.bigint(), F = Date.now(), R = Number(_ - m);
|
|
1140
|
+
throw M({ functionName: t, filePath: e, metadata: i, args: S, result: null, error: $?.message || String($), duration: F - I, durationNs: R, startTimeNs: m.toString(), async: !0, spanId: a, parentSpanId: p, pid: process.pid, threadId: H }), $;
|
|
1089
1141
|
});
|
|
1090
|
-
const f = process.hrtime.bigint(),
|
|
1091
|
-
let
|
|
1092
|
-
return
|
|
1093
|
-
} catch (
|
|
1094
|
-
const f = process.hrtime.bigint(),
|
|
1095
|
-
throw M({ functionName: t, filePath: e, metadata: i, args: S, result: null, error:
|
|
1142
|
+
const f = process.hrtime.bigint(), v = Date.now(), h = Number(f - m);
|
|
1143
|
+
let w = null;
|
|
1144
|
+
return s.capture_return_value && s.return_limit_mb > 0 && (w = K(g, s.return_limit_mb)), M({ functionName: t, filePath: e, metadata: i, args: S, result: w, error: null, duration: v - I, durationNs: h, startTimeNs: m.toString(), async: !1, spanId: a, parentSpanId: p, pid: process.pid, threadId: H }), p ? d.setCurrentFunctionSpanId(p) : d.clearCurrentFunctionSpanId(), g;
|
|
1145
|
+
} catch (g) {
|
|
1146
|
+
const f = process.hrtime.bigint(), v = Date.now(), h = Number(f - m);
|
|
1147
|
+
throw M({ functionName: t, filePath: e, metadata: i, args: S, result: null, error: g?.message || String(g), duration: v - I, durationNs: h, startTimeNs: m.toString(), async: !1, spanId: a, parentSpanId: p, pid: process.pid, threadId: H }), p ? d.setCurrentFunctionSpanId(p) : d.clearCurrentFunctionSpanId(), g;
|
|
1096
1148
|
}
|
|
1097
1149
|
};
|
|
1098
1150
|
Object.defineProperty(n, "name", { value: t, writable: !1 });
|
|
1099
|
-
for (const
|
|
1151
|
+
for (const o in r) r.hasOwnProperty(o) && (n[o] = r[o]);
|
|
1100
1152
|
return n;
|
|
1101
1153
|
}
|
|
1102
1154
|
function M(r) {
|
|
1103
|
-
const t =
|
|
1155
|
+
const t = ye(), e = t?.sfDebug || !1;
|
|
1104
1156
|
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 });
|
|
1105
1157
|
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 };
|
|
1106
1158
|
process.env.SF_FUNCSPAN_CONSOLE_OUTPUT === "true" && console.log(`
|
|
1107
1159
|
📊 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" });
|
|
1108
1160
|
const n = process.env.SF_FUNCSPAN_JSONL_FILE;
|
|
1109
1161
|
if (n) try {
|
|
1110
|
-
const
|
|
1162
|
+
const o = n === "true" || n === "1" ? "funcspans.jsonl" : n, l = Date.now(), u = process.hrtime.bigint(), s = BigInt(r.startTimeNs), d = Number(u - s) / 1e6, p = new Date(l - d).toISOString(), a = 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 }) + `
|
|
1111
1163
|
`;
|
|
1112
|
-
|
|
1113
|
-
} catch (
|
|
1114
|
-
console.error("[FuncSpan] Error writing to JSONL file:",
|
|
1164
|
+
Be(o, a, "utf-8");
|
|
1165
|
+
} catch (o) {
|
|
1166
|
+
console.error("[FuncSpan] Error writing to JSONL file:", o);
|
|
1115
1167
|
}
|
|
1116
1168
|
if (e && console.log("[FuncSpan] Sending function span to transmitter:", i), process.env.SF_FUNCSPAN_SKIP_BACKEND !== "true") try {
|
|
1117
|
-
(
|
|
1118
|
-
} catch (
|
|
1119
|
-
e && console.error("[FuncSpan] Error sending function span:",
|
|
1169
|
+
(Q || (Q = new Ue()), Q).send([i]), e && console.log("[FuncSpan] Function span sent successfully");
|
|
1170
|
+
} catch (o) {
|
|
1171
|
+
e && console.error("[FuncSpan] Error sending function span:", o);
|
|
1120
1172
|
}
|
|
1121
1173
|
}
|
|
1122
|
-
function
|
|
1174
|
+
function Nt(r) {
|
|
1123
1175
|
return !!r.includes("captureFunctionSpan(") || !!r.includes("@sailfish-ai/sf-veritas") || !(!r.includes("/* @sailfish-instrumented */") && !r.includes("// @sailfish-instrumented"));
|
|
1124
1176
|
}
|
|
1125
1177
|
export {
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1178
|
+
ne as ContextManager,
|
|
1179
|
+
wt as addOrUpdateMetadata,
|
|
1180
|
+
Dt as captureFunctionSpan,
|
|
1181
|
+
Ct as clearFuncspanOverride,
|
|
1182
|
+
C as getCurrentFunctionSpanId,
|
|
1183
|
+
Se as getDefaultConfig,
|
|
1184
|
+
Re as getEnvConfig,
|
|
1185
|
+
Y as getFuncspanOverride,
|
|
1186
|
+
nt as getGlobalConfig,
|
|
1187
|
+
Ft as identify,
|
|
1188
|
+
tt as initializeConfigLoader,
|
|
1189
|
+
dt as initializeWorkerPoolPatching,
|
|
1190
|
+
Nt as isAlreadyInstrumented,
|
|
1191
|
+
rt as isConfigLoaderInitialized,
|
|
1192
|
+
Ot as isProductionEnvironment,
|
|
1193
|
+
Lt as isRuntimeModeEnabled,
|
|
1194
|
+
_t as isSetupInterceptorsInitialized,
|
|
1195
|
+
ut as isWorkerPoolInitialized,
|
|
1196
|
+
Z as parseHeaderOverride,
|
|
1197
|
+
Rt as runWithContext,
|
|
1198
|
+
Ut as setFuncspanOverride,
|
|
1199
|
+
Ht as setSkipTypeScriptPlugin,
|
|
1200
|
+
bt as setupInterceptors,
|
|
1201
|
+
qt as shouldEnableRuntimeHooks,
|
|
1202
|
+
Mt as transformFunctionSpans,
|
|
1203
|
+
xt as transformFunctionSpansSync
|
|
1152
1204
|
};
|