@sailfish-ai/sf-veritas 0.3.0 → 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 +88 -0
- package/dist/{contextManager-RxrMXs5c.js → contextManager-CZy0w11U.js} +118 -114
- 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-BZ61efqE.js → runtimeConfig-ButdW4zP.js} +329 -340
- package/dist/runtimeConfig-C4_zc4Zg.cjs +5 -0
- package/dist/sf-veritas.cjs +13 -13
- package/dist/sf-veritas.mjs +590 -424
- package/dist/types/constants.d.ts +7 -0
- package/dist/types/requestTransmitter.d.ts +75 -0
- package/dist/types/setupConfig.d.ts +39 -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-Bg5av6gn.cjs → workerPoolSpanCapture-BUFN_RMW.cjs} +1 -1
- package/dist/{workerPoolSpanCapture-BjdZn3LE.js → workerPoolSpanCapture-BomWTMM2.js} +1 -1
- package/package.json +17 -1
- package/dist/contextManager-0D8uHQ1_.cjs +0 -1
- package/dist/runtimeConfig-CWpFWsmz.cjs +0 -6
package/dist/sf-veritas.mjs
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { g as
|
|
5
|
-
import { r as
|
|
6
|
-
import { B as
|
|
7
|
-
import { h as
|
|
8
|
-
import { a as
|
|
9
|
-
import { f as
|
|
10
|
-
import { createRequire as
|
|
11
|
-
import * as
|
|
12
|
-
import { readFileSync as
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import { s as
|
|
16
|
-
import * as
|
|
17
|
-
import * as
|
|
18
|
-
import { glob as
|
|
19
|
-
import { threadId as
|
|
20
|
-
import { s as
|
|
21
|
-
class
|
|
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
|
+
import U from "http";
|
|
14
|
+
import A from "https";
|
|
15
|
+
import { s as Ge } from "./source-map-Cr6YkjTd.js";
|
|
16
|
+
import * as se from "fs/promises";
|
|
17
|
+
import * as P from "path";
|
|
18
|
+
import { glob as Ke } from "glob";
|
|
19
|
+
import { threadId as H } from "worker_threads";
|
|
20
|
+
import { s as Ht, t as Mt, a as xt } from "./funcSpanTransformer-S_WeAt_m.js";
|
|
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,37 +68,37 @@ class T extends R {
|
|
|
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
|
-
|
|
79
|
-
|
|
78
|
+
b(this, "serviceIdentifier", new O());
|
|
79
|
+
b(this, "identifyStarted", !1);
|
|
80
80
|
this.setOperationName("CollectMetadata");
|
|
81
81
|
}
|
|
82
82
|
startBackgroundIdentify() {
|
|
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,30 +108,30 @@ class Le extends R {
|
|
|
108
108
|
`;
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
|
-
class
|
|
111
|
+
class ve {
|
|
112
112
|
constructor(t) {
|
|
113
|
-
|
|
114
|
-
this.apiKey = t, this.metadataTransmitter = new
|
|
113
|
+
b(this, "metadataTransmitter");
|
|
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
|
-
|
|
128
|
-
|
|
127
|
+
b(this, "serviceIdentifier", new O());
|
|
128
|
+
b(this, "identifyStarted", !1);
|
|
129
129
|
}
|
|
130
130
|
startBackgroundIdentify() {
|
|
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 Q extends R {
|
|
|
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,12 +174,12 @@ class Q extends R {
|
|
|
174
174
|
`;
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
|
-
class
|
|
177
|
+
class je extends k {
|
|
178
178
|
constructor() {
|
|
179
179
|
super();
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
180
|
+
b(this, "serviceIdentifier", new O());
|
|
181
|
+
b(this, "supplementalFields", {});
|
|
182
|
+
b(this, "identifyStarted", !1);
|
|
183
183
|
this.setOperationName("CollectExceptions");
|
|
184
184
|
}
|
|
185
185
|
setSupplementalFields(e) {
|
|
@@ -193,7 +193,7 @@ class Ae extends R {
|
|
|
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 Ae extends R {
|
|
|
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 Ae extends R {
|
|
|
237
237
|
`;
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
|
-
const
|
|
241
|
-
var
|
|
242
|
-
const
|
|
243
|
-
let
|
|
244
|
-
function
|
|
245
|
-
const r =
|
|
246
|
-
if (
|
|
240
|
+
const oe = "X-Sf4-Prid", ae = "getting request source code";
|
|
241
|
+
var B = ((r) => (r.UNKNOWN = "unknown", r.ANONYMOUS = "anonymous", r.NOT_CAPTURED = "not captured", r))(B || {});
|
|
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 (!
|
|
261
|
-
for (const [
|
|
262
|
-
return
|
|
263
|
-
})(l?.headers), d =
|
|
264
|
-
r && (
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
const
|
|
268
|
-
r &&
|
|
269
|
-
const
|
|
270
|
-
d &&
|
|
271
|
-
const
|
|
272
|
-
r &&
|
|
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
|
+
const S = () => {
|
|
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
281
|
}
|
|
282
|
-
}) : r &&
|
|
282
|
+
}) : r && N("[patchNodeHttpInbound] Already patched, skipping.");
|
|
283
283
|
}
|
|
284
|
-
|
|
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;
|
|
311
|
+
}
|
|
312
|
+
return !S.test(g) && !S.test(s) ? !1 : m ? W(`^/${m.replace(/\*/g, ".*").replace(/\/$/, "")}`, "i").test(o) : !0;
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
class Je extends re {
|
|
285
316
|
constructor() {
|
|
286
317
|
super(), this.setOperationName("DomainsToNotPassHeaderTo");
|
|
287
318
|
}
|
|
@@ -302,21 +333,21 @@ class Me extends Q {
|
|
|
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
|
-
|
|
312
|
-
|
|
342
|
+
b(this, "serviceIdentifier", new O());
|
|
343
|
+
b(this, "identifyStarted", !1);
|
|
313
344
|
this.setOperationName("CollectNetworkHops");
|
|
314
345
|
}
|
|
315
346
|
startBackgroundIdentify() {
|
|
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 xe extends R {
|
|
|
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,18 +386,18 @@ class xe extends R {
|
|
|
355
386
|
`;
|
|
356
387
|
}
|
|
357
388
|
}
|
|
358
|
-
class
|
|
389
|
+
class Xe extends k {
|
|
359
390
|
constructor() {
|
|
360
391
|
super();
|
|
361
|
-
|
|
362
|
-
|
|
392
|
+
b(this, "serviceIdentifier", new O());
|
|
393
|
+
b(this, "identifyStarted", !1);
|
|
363
394
|
this.setOperationName("CollectNetworkRequest");
|
|
364
395
|
}
|
|
365
396
|
startBackgroundIdentify() {
|
|
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,28 +416,31 @@ class Be extends R {
|
|
|
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
|
-
|
|
422
|
+
const V = [400, 403];
|
|
423
|
+
function z(r, t) {
|
|
424
|
+
return t !== "none" && (t === "all" || r === "GET" || r === "HEAD" || r === "OPTIONS");
|
|
425
|
+
}
|
|
426
|
+
class Ye {
|
|
393
427
|
constructor(t = []) {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
this.contextManager =
|
|
428
|
+
b(this, "HEADER_TRACING", "X-Sf3-Rid");
|
|
429
|
+
b(this, "HEADER_LOG_GUARD", "reentrancy_guard_logging_preactive");
|
|
430
|
+
b(this, "HEADER_PRINT_GUARD", "reentrancy_guard_print_preactive");
|
|
431
|
+
b(this, "HEADER_EXCEPTION_GUARD", "reentrancy_guard_exception_preactive");
|
|
432
|
+
b(this, "contextManager");
|
|
433
|
+
this.contextManager = ne.getInstance(), t?.forEach((e) => {
|
|
400
434
|
typeof e == "string" && e.trim() && this.contextManager.getExcludedDomains().add(e);
|
|
401
|
-
}),
|
|
435
|
+
}), c().sfDebug && console.log("[RequestInterceptor] Initialized with static excluded domains.");
|
|
402
436
|
}
|
|
403
437
|
extractIdsFromTraceHeader(t, e = this.HEADER_TRACING) {
|
|
404
438
|
let i;
|
|
405
439
|
if (t instanceof Headers) i = t.get(e) ?? void 0;
|
|
406
440
|
else {
|
|
407
|
-
const
|
|
408
|
-
for (const [l,
|
|
409
|
-
i =
|
|
441
|
+
const o = e.toLowerCase();
|
|
442
|
+
for (const [l, u] of Object.entries(t)) if (l.toLowerCase() === o) {
|
|
443
|
+
i = u;
|
|
410
444
|
break;
|
|
411
445
|
}
|
|
412
446
|
}
|
|
@@ -417,181 +451,313 @@ class Ge {
|
|
|
417
451
|
parseStackFrame(t) {
|
|
418
452
|
const e = /\((.*):(\d+):(\d+)\)$/.exec(t.trim());
|
|
419
453
|
if (!e) return null;
|
|
420
|
-
const [, i, n,
|
|
421
|
-
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) };
|
|
422
456
|
}
|
|
423
457
|
async getOriginalPosition(t, e, i) {
|
|
424
458
|
let n = { source: t, line: e, column: i, name: null };
|
|
425
459
|
if (t.includes("://")) return { originalPos: n };
|
|
426
|
-
const
|
|
460
|
+
const o = t + ".map";
|
|
427
461
|
try {
|
|
428
|
-
const l = JSON.parse(
|
|
429
|
-
let
|
|
430
|
-
|
|
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);
|
|
431
465
|
} catch (l) {
|
|
432
|
-
|
|
466
|
+
c().sfDebug && console.error(`Could not read/parse map file at ${o}:`, l);
|
|
433
467
|
}
|
|
434
468
|
return { originalPos: n };
|
|
435
469
|
}
|
|
436
470
|
captureFirstUserLines(t, e = 10, i = !1) {
|
|
437
|
-
const n =
|
|
438
|
-
Error.stackTraceLimit = Math.max(
|
|
439
|
-
const l = new Error(
|
|
440
|
-
|
|
441
|
-
const
|
|
442
|
-
Error.stackTraceLimit =
|
|
443
|
-
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(`
|
|
444
478
|
`).slice(1), d = [];
|
|
445
|
-
for (const p of
|
|
479
|
+
for (const p of s)
|
|
446
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;
|
|
447
481
|
for (const p of d) {
|
|
448
|
-
const
|
|
449
|
-
|
|
450
|
-
const { originalPos:
|
|
451
|
-
if (
|
|
452
|
-
|
|
453
|
-
const
|
|
454
|
-
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);
|
|
455
489
|
}
|
|
456
|
-
})() :
|
|
490
|
+
})() : c().sfDebug && console.error("Could not parse stack line:", p);
|
|
457
491
|
}
|
|
458
492
|
}
|
|
459
493
|
addReentrancyGuardHeaders(t) {
|
|
460
494
|
t.set(this.HEADER_LOG_GUARD, "true"), t.set(this.HEADER_PRINT_GUARD, "true"), t.set(this.HEADER_EXCEPTION_GUARD, "true");
|
|
461
495
|
}
|
|
462
496
|
shouldPropagateHeaders(t) {
|
|
463
|
-
|
|
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);
|
|
464
499
|
}
|
|
465
500
|
addTracingHeaders(t, e) {
|
|
466
|
-
const i =
|
|
467
|
-
|
|
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 };
|
|
468
516
|
}
|
|
469
517
|
addTracingHeader(t, e) {
|
|
470
|
-
const i =
|
|
518
|
+
const i = Y();
|
|
471
519
|
if (i) {
|
|
472
|
-
const
|
|
473
|
-
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}`));
|
|
474
522
|
}
|
|
475
|
-
const n = this.contextManager.getOrSetSfTraceId(),
|
|
476
|
-
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}`);
|
|
477
525
|
}
|
|
478
526
|
patchFetch(t, e) {
|
|
479
527
|
const i = globalThis.fetch;
|
|
480
|
-
typeof i == "function" ? globalThis.fetch = async (n,
|
|
481
|
-
const l = new 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,
|
|
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);
|
|
483
531
|
this.captureFirstUserLines(t);
|
|
484
|
-
const
|
|
485
|
-
let
|
|
486
|
-
typeof n == "string" || n instanceof URL
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
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();
|
|
535
|
+
else {
|
|
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);
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
c().sfDebug && console.log("[RequestInterceptor] Fetching request to:", s);
|
|
542
|
+
let p = "unknown";
|
|
491
543
|
try {
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
544
|
+
p = new URL(s).hostname;
|
|
545
|
+
} catch {
|
|
546
|
+
return c().sfDebug && console.warn(`[RequestInterceptor] Could not parse URL '${s}' — passing through without tracing headers.`), i(n, o);
|
|
547
|
+
}
|
|
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;
|
|
550
|
+
try {
|
|
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;
|
|
555
|
+
try {
|
|
556
|
+
this.captureFirstUserLines(t, 10, f);
|
|
557
|
+
} catch (F) {
|
|
558
|
+
c().sfDebug && console.error("[RequestInterceptor] captureFirstUserLines (retry) failed:", F);
|
|
559
|
+
}
|
|
560
|
+
} else try {
|
|
561
|
+
this.contextManager.addSupportedDomains(p);
|
|
562
|
+
} catch ($) {
|
|
563
|
+
c().sfDebug && console.error("[RequestInterceptor] addSupportedDomains failed:", $);
|
|
502
564
|
}
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
565
|
+
} catch (h) {
|
|
566
|
+
const w = Date.now();
|
|
567
|
+
c().sfDebug && console.error(`[RequestInterceptor] Fetch failed: ${s}, Error: ${h}, Duration: ${w - u}ms`);
|
|
568
|
+
try {
|
|
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:", $);
|
|
508
573
|
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
574
|
+
throw h;
|
|
575
|
+
}
|
|
576
|
+
const v = Date.now();
|
|
577
|
+
try {
|
|
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() };
|
|
580
|
+
if (_.captureRequestHeaders) {
|
|
581
|
+
const y = {};
|
|
582
|
+
l.forEach((E, D) => {
|
|
583
|
+
y[D] = E;
|
|
584
|
+
}), F.requestHeaders = y;
|
|
513
585
|
}
|
|
514
|
-
if (
|
|
515
|
-
const
|
|
516
|
-
|
|
517
|
-
|
|
586
|
+
if (_.captureResponseHeaders) {
|
|
587
|
+
const y = {};
|
|
588
|
+
g.headers.forEach((E, D) => {
|
|
589
|
+
y[D] = E;
|
|
590
|
+
}), F.responseHeaders = y;
|
|
591
|
+
}
|
|
592
|
+
if (_.captureRequestBody && o?.body) {
|
|
593
|
+
const y = o.body, E = _.requestBodyLimitBytes;
|
|
594
|
+
try {
|
|
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]";
|
|
605
|
+
else {
|
|
606
|
+
const D = JSON.stringify(y);
|
|
607
|
+
D && D !== "{}" && (F.requestBody = D.length > E ? D.substring(0, E) + "...[truncated]" : D);
|
|
608
|
+
}
|
|
609
|
+
} catch {
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
let R;
|
|
613
|
+
if (_.captureResponseBody) {
|
|
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;
|
|
617
|
+
R = (async () => {
|
|
618
|
+
try {
|
|
619
|
+
const G = await E.text(), _e = G.length > D ? G.substring(0, D) + "...[truncated]" : G;
|
|
620
|
+
try {
|
|
621
|
+
e.doSend({ ...F, responseBody: _e });
|
|
622
|
+
} catch {
|
|
623
|
+
}
|
|
624
|
+
} catch {
|
|
625
|
+
}
|
|
626
|
+
})(), R.catch(() => {
|
|
627
|
+
});
|
|
628
|
+
} else F.responseBody = `[non-text body, content-type=${y} — not captured]`;
|
|
518
629
|
}
|
|
519
|
-
|
|
520
|
-
} catch (
|
|
521
|
-
|
|
522
|
-
f().sfDebug && console.error(`[RequestInterceptor] Fetch failed: ${o}, Error: ${u}, Duration: ${h - a}ms`);
|
|
630
|
+
R || e.doSend(F);
|
|
631
|
+
} catch (h) {
|
|
632
|
+
c().sfDebug && console.error("[RequestInterceptor] Post-fetch telemetry failed (response still returned):", h);
|
|
523
633
|
}
|
|
524
|
-
|
|
634
|
+
return g;
|
|
635
|
+
} : c().sfDebug && console.error("[RequestInterceptor] Fetch not available.");
|
|
525
636
|
}
|
|
526
637
|
setHeader(t, e, i) {
|
|
527
638
|
t instanceof Headers ? t.set(e, i) : t[e] = i;
|
|
528
639
|
}
|
|
529
640
|
addTracingHeadersToPlainObject(t, e) {
|
|
530
|
-
const i =
|
|
531
|
-
if (
|
|
532
|
-
const
|
|
533
|
-
if (
|
|
534
|
-
const d =
|
|
535
|
-
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;
|
|
647
|
+
}
|
|
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 {
|
|
536
655
|
}
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
return n;
|
|
656
|
+
console.error(`[RequestInterceptor] Excluded domain: ${n}`);
|
|
657
|
+
}
|
|
658
|
+
return i;
|
|
541
659
|
}
|
|
542
660
|
patchHttp(t, e) {
|
|
543
|
-
if (
|
|
544
|
-
const i =
|
|
545
|
-
let
|
|
546
|
-
if (typeof
|
|
547
|
-
const
|
|
548
|
-
|
|
549
|
-
} else
|
|
550
|
-
return
|
|
551
|
-
}, l = (
|
|
552
|
-
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);
|
|
553
671
|
try {
|
|
554
|
-
const
|
|
555
|
-
this.addTracingHeadersToPlainObject(
|
|
556
|
-
} catch (
|
|
557
|
-
|
|
672
|
+
const f = `${a.protocol}//${a.hostname}`;
|
|
673
|
+
this.addTracingHeadersToPlainObject(a.headers, f), this.captureFirstUserLines(t);
|
|
674
|
+
} catch (f) {
|
|
675
|
+
c().sfDebug && console.error("[RequestInterceptor] Error while processing HTTP request options:", f);
|
|
558
676
|
}
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
delete S.headers[this.HEADER_TRACING], i(S, g), m = !0, this.captureFirstUserLines(t, 10, m);
|
|
677
|
+
const I = (a.method || "GET").toUpperCase(), S = c().retryOnClientError, g = (f, v, h) => {
|
|
678
|
+
try {
|
|
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() });
|
|
681
|
+
} catch {
|
|
565
682
|
}
|
|
566
|
-
|
|
567
|
-
|
|
683
|
+
m?.(f);
|
|
684
|
+
};
|
|
685
|
+
return i(a, (f) => {
|
|
686
|
+
const v = `${a.protocol}//${a.hostname}`;
|
|
687
|
+
let h = !1;
|
|
688
|
+
try {
|
|
689
|
+
h = this.shouldPropagateHeaders(v);
|
|
690
|
+
} catch {
|
|
691
|
+
h = !1;
|
|
692
|
+
}
|
|
693
|
+
if (h && z(I, S) && V.includes(f.statusCode || 0)) {
|
|
694
|
+
f.resume();
|
|
695
|
+
try {
|
|
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() });
|
|
698
|
+
} catch {
|
|
699
|
+
}
|
|
700
|
+
try {
|
|
701
|
+
this.captureFirstUserLines(t, 10, !0);
|
|
702
|
+
} catch {
|
|
703
|
+
}
|
|
704
|
+
const w = { ...a, headers: { ...a.headers } };
|
|
705
|
+
return delete w.headers[this.HEADER_TRACING], void i(w, ($) => {
|
|
706
|
+
g($, v, !0);
|
|
707
|
+
}).end();
|
|
708
|
+
}
|
|
709
|
+
g(f, v, !1);
|
|
568
710
|
});
|
|
569
|
-
},
|
|
570
|
-
const [
|
|
711
|
+
}, u = (s, d, p) => {
|
|
712
|
+
const [a, m] = o(s, d, p, "https:");
|
|
571
713
|
try {
|
|
572
|
-
const
|
|
573
|
-
this.addTracingHeadersToPlainObject(
|
|
574
|
-
} catch (
|
|
575
|
-
|
|
714
|
+
const f = `${a.protocol}//${a.hostname}`;
|
|
715
|
+
this.addTracingHeadersToPlainObject(a.headers, f), this.captureFirstUserLines(t);
|
|
716
|
+
} catch (f) {
|
|
717
|
+
c().sfDebug && console.error("[RequestInterceptor] Error while processing HTTPS request options:", f);
|
|
576
718
|
}
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
719
|
+
const I = (a.method || "GET").toUpperCase(), S = c().retryOnClientError, g = (f, v, h) => {
|
|
720
|
+
try {
|
|
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() });
|
|
723
|
+
} catch {
|
|
724
|
+
}
|
|
725
|
+
m?.(f);
|
|
726
|
+
};
|
|
727
|
+
return n(a, (f) => {
|
|
728
|
+
const v = `${a.protocol}//${a.hostname}`;
|
|
729
|
+
let h = !1;
|
|
730
|
+
try {
|
|
731
|
+
h = this.shouldPropagateHeaders(v);
|
|
732
|
+
} catch {
|
|
733
|
+
h = !1;
|
|
734
|
+
}
|
|
735
|
+
if (h && z(I, S) && V.includes(f.statusCode || 0)) {
|
|
736
|
+
f.resume();
|
|
737
|
+
try {
|
|
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() });
|
|
740
|
+
} catch {
|
|
741
|
+
}
|
|
742
|
+
try {
|
|
743
|
+
this.captureFirstUserLines(t, 10, !0);
|
|
744
|
+
} catch {
|
|
745
|
+
}
|
|
746
|
+
const w = { ...a, headers: { ...a.headers } };
|
|
747
|
+
return delete w.headers[this.HEADER_TRACING], void n(w, ($) => {
|
|
748
|
+
g($, v, !0);
|
|
749
|
+
}).end();
|
|
583
750
|
}
|
|
584
|
-
|
|
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);
|
|
751
|
+
g(f, v, !1);
|
|
586
752
|
});
|
|
587
753
|
};
|
|
588
|
-
|
|
589
|
-
const
|
|
590
|
-
return
|
|
591
|
-
},
|
|
592
|
-
const
|
|
593
|
-
return
|
|
594
|
-
},
|
|
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.");
|
|
595
761
|
}
|
|
596
762
|
tryPatch(t, e) {
|
|
597
763
|
try {
|
|
@@ -603,7 +769,7 @@ class Ge {
|
|
|
603
769
|
return [...this.contextManager.getExcludedDomains()];
|
|
604
770
|
}
|
|
605
771
|
}
|
|
606
|
-
class
|
|
772
|
+
class Ze extends re {
|
|
607
773
|
constructor() {
|
|
608
774
|
super(), this.setOperationName("UpdateServiceDetails");
|
|
609
775
|
}
|
|
@@ -653,47 +819,47 @@ class Ke extends Q {
|
|
|
653
819
|
serviceRole: $serviceRole,
|
|
654
820
|
)
|
|
655
821
|
}
|
|
656
|
-
`, e =
|
|
657
|
-
|
|
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);
|
|
658
824
|
}
|
|
659
825
|
}
|
|
660
|
-
class
|
|
826
|
+
class et {
|
|
661
827
|
constructor(t = [process.cwd()], e = !1) {
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
828
|
+
b(this, "rootPaths");
|
|
829
|
+
b(this, "fileConfigs", /* @__PURE__ */ new Map());
|
|
830
|
+
b(this, "functionConfigs", /* @__PURE__ */ new Map());
|
|
831
|
+
b(this, "directoryConfigs", /* @__PURE__ */ new Map());
|
|
832
|
+
b(this, "hasSailfishFiles", !1);
|
|
833
|
+
b(this, "runtimeModeEnabled", !1);
|
|
834
|
+
b(this, "debug");
|
|
669
835
|
this.rootPaths = t, this.debug = e || process.env.SF_DEBUG === "true";
|
|
670
836
|
}
|
|
671
837
|
async loadAllConfigs() {
|
|
672
838
|
this.debug && console.log("[FuncSpan ConfigLoader] Scanning for .sailfish files in:", this.rootPaths);
|
|
673
839
|
const t = [];
|
|
674
|
-
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}`);
|
|
675
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");
|
|
676
842
|
for (const e of t) await this._loadConfigFile(e);
|
|
677
843
|
await this._resolveInheritance(), this.debug && console.log(`[FuncSpan ConfigLoader] Loaded ${this.fileConfigs.size} file configs, ${this.functionConfigs.size} function configs`);
|
|
678
844
|
}
|
|
679
845
|
getConfig(t, e) {
|
|
680
|
-
const i = this.hasSailfishFiles ?
|
|
681
|
-
let
|
|
846
|
+
const i = this.hasSailfishFiles ? Re() : Se(), n = this._getDirectoryConfig(t), o = P.normalize(t), l = this.fileConfigs.get(o) || {};
|
|
847
|
+
let u = {};
|
|
682
848
|
if (e) {
|
|
683
|
-
const
|
|
684
|
-
|
|
849
|
+
const s = this.functionConfigs.get(o);
|
|
850
|
+
s && (u = s.get(e) || {});
|
|
685
851
|
}
|
|
686
|
-
return
|
|
852
|
+
return L(i, n, l, u);
|
|
687
853
|
}
|
|
688
854
|
hasRuntimeMode() {
|
|
689
855
|
return this.runtimeModeEnabled;
|
|
690
856
|
}
|
|
691
857
|
async _walkDirectory(t, e) {
|
|
692
858
|
try {
|
|
693
|
-
const i = await
|
|
859
|
+
const i = await se.readdir(t, { withFileTypes: !0 });
|
|
694
860
|
for (const n of i) {
|
|
695
|
-
const
|
|
696
|
-
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);
|
|
697
863
|
}
|
|
698
864
|
} catch (i) {
|
|
699
865
|
this.debug && console.error(`[FuncSpan ConfigLoader] Error walking directory ${t}:`, i);
|
|
@@ -701,7 +867,7 @@ class We {
|
|
|
701
867
|
}
|
|
702
868
|
async _loadConfigFile(t) {
|
|
703
869
|
try {
|
|
704
|
-
const e = await
|
|
870
|
+
const e = await se.readFile(t, "utf-8"), i = P.dirname(t);
|
|
705
871
|
let n = null;
|
|
706
872
|
try {
|
|
707
873
|
n = JSON.parse(e);
|
|
@@ -711,8 +877,8 @@ class We {
|
|
|
711
877
|
} catch {
|
|
712
878
|
try {
|
|
713
879
|
n = require("js-yaml").load(e);
|
|
714
|
-
} catch (
|
|
715
|
-
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));
|
|
716
882
|
}
|
|
717
883
|
}
|
|
718
884
|
}
|
|
@@ -723,70 +889,70 @@ class We {
|
|
|
723
889
|
}
|
|
724
890
|
}
|
|
725
891
|
async _expandFileGlobs(t, e, i) {
|
|
726
|
-
for (const [n,
|
|
727
|
-
const l =
|
|
728
|
-
this.debug && console.log(`[FuncSpan ConfigLoader] Pattern '${n}' matched ${
|
|
729
|
-
for (const
|
|
730
|
-
const d =
|
|
731
|
-
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}`);
|
|
732
898
|
}
|
|
733
899
|
} catch (l) {
|
|
734
900
|
this.debug && console.error(`[FuncSpan ConfigLoader] Error expanding glob '${n}':`, l);
|
|
735
901
|
}
|
|
736
902
|
}
|
|
737
903
|
_storeFunctionConfigs(t, e, i) {
|
|
738
|
-
for (const [n,
|
|
904
|
+
for (const [n, o] of Object.entries(e)) {
|
|
739
905
|
const l = n.split("::");
|
|
740
906
|
if (l.length !== 2) {
|
|
741
907
|
this.debug && console.warn(`[FuncSpan ConfigLoader] Invalid function pattern '${n}' (expected format: 'file.ts::functionName')`);
|
|
742
908
|
continue;
|
|
743
909
|
}
|
|
744
|
-
const [
|
|
910
|
+
const [u, s] = l, d = P.normalize(P.join(t, u));
|
|
745
911
|
this.functionConfigs.has(d) || this.functionConfigs.set(d, /* @__PURE__ */ new Map());
|
|
746
|
-
const p = this.functionConfigs.get(d),
|
|
747
|
-
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}`);
|
|
748
914
|
}
|
|
749
915
|
}
|
|
750
916
|
async _resolveInheritance() {
|
|
751
917
|
}
|
|
752
918
|
_getDirectoryConfig(t) {
|
|
753
|
-
let e =
|
|
919
|
+
let e = P.dirname(P.normalize(t));
|
|
754
920
|
const i = [];
|
|
755
|
-
for (; e && e !==
|
|
921
|
+
for (; e && e !== P.dirname(e); ) {
|
|
756
922
|
const n = this.directoryConfigs.get(e);
|
|
757
|
-
n && i.unshift(n), e =
|
|
923
|
+
n && i.unshift(n), e = P.dirname(e);
|
|
758
924
|
}
|
|
759
|
-
return i.reduce((n,
|
|
925
|
+
return i.reduce((n, o) => L(n, o), {});
|
|
760
926
|
}
|
|
761
927
|
}
|
|
762
|
-
const
|
|
763
|
-
function
|
|
764
|
-
return globalThis[
|
|
928
|
+
const $e = "__sf_globalConfigLoader";
|
|
929
|
+
function be() {
|
|
930
|
+
return globalThis[$e] ?? null;
|
|
765
931
|
}
|
|
766
|
-
async function
|
|
767
|
-
const e = new
|
|
932
|
+
async function tt(r, t) {
|
|
933
|
+
const e = new et(r, t);
|
|
768
934
|
(function(i) {
|
|
769
|
-
globalThis[
|
|
935
|
+
globalThis[$e] = i;
|
|
770
936
|
})(e), await e.loadAllConfigs();
|
|
771
937
|
}
|
|
772
|
-
function
|
|
773
|
-
const e =
|
|
774
|
-
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());
|
|
775
941
|
}
|
|
776
|
-
function
|
|
777
|
-
return
|
|
942
|
+
function rt() {
|
|
943
|
+
return be() !== null;
|
|
778
944
|
}
|
|
779
|
-
const
|
|
780
|
-
let
|
|
781
|
-
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) {
|
|
782
948
|
if (typeof r != "string") return !1;
|
|
783
949
|
const t = process.env.SF_FUNCSPAN_JSONL_FILE;
|
|
784
950
|
if (t && r.includes(t)) return !0;
|
|
785
951
|
const e = process.env.SF_WORKER_POOL_JSONL_FILE;
|
|
786
952
|
return !(!e || !r.includes(e));
|
|
787
953
|
}
|
|
788
|
-
let
|
|
789
|
-
function
|
|
954
|
+
let fe = !1;
|
|
955
|
+
function ge(r) {
|
|
790
956
|
if (typeof r != "string") return !1;
|
|
791
957
|
if (r === "localhost" || r === "127.0.0.1" || r === "::1") return !0;
|
|
792
958
|
try {
|
|
@@ -797,8 +963,8 @@ function oe(r) {
|
|
|
797
963
|
}
|
|
798
964
|
return !1;
|
|
799
965
|
}
|
|
800
|
-
function
|
|
801
|
-
if (!
|
|
966
|
+
function ct() {
|
|
967
|
+
if (!fe) try {
|
|
802
968
|
let r;
|
|
803
969
|
if (typeof require > "u") return void (process.env.SF_DEBUG === "true" && console.log("[WorkerPool] Skipping dns patching in pure ESM environment (require unavailable)"));
|
|
804
970
|
try {
|
|
@@ -808,231 +974,231 @@ function Ze() {
|
|
|
808
974
|
}
|
|
809
975
|
if (r.__sf_worker_pool_patched__) return;
|
|
810
976
|
Object.defineProperty(r, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
811
|
-
for (const t of
|
|
977
|
+
for (const t of le) if (typeof r[t] == "function") {
|
|
812
978
|
const e = r[t];
|
|
813
979
|
r[t] = function(...i) {
|
|
814
|
-
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);
|
|
815
981
|
}, Object.defineProperty(r[t], "name", { value: t, writable: !1 });
|
|
816
982
|
}
|
|
817
983
|
(function(t) {
|
|
818
984
|
if (!t.promises) return void (process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns.promises not available, skipping"));
|
|
819
985
|
if (!t.promises.__sf_worker_pool_patched__) {
|
|
820
986
|
Object.defineProperty(t.promises, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
821
|
-
for (const e of
|
|
987
|
+
for (const e of le) if (typeof t.promises[e] == "function") {
|
|
822
988
|
const i = t.promises[e];
|
|
823
989
|
t.promises[e] = function(...n) {
|
|
824
|
-
return
|
|
990
|
+
return ie() ? i.apply(this, n) : ge(n[0]) ? i.apply(this, n) : Te("dns", e, i, n, this);
|
|
825
991
|
}, Object.defineProperty(t.promises[e], "name", { value: e, writable: !1 });
|
|
826
992
|
}
|
|
827
993
|
process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns.promises module patched successfully");
|
|
828
994
|
}
|
|
829
|
-
})(r),
|
|
995
|
+
})(r), fe = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns module patched successfully");
|
|
830
996
|
} catch (r) {
|
|
831
997
|
console.error("[WorkerPool] Error patching dns module:", r);
|
|
832
998
|
}
|
|
833
999
|
}
|
|
834
|
-
let
|
|
835
|
-
function
|
|
836
|
-
if (
|
|
1000
|
+
let he = !1, me = !1, ee = !1;
|
|
1001
|
+
function dt() {
|
|
1002
|
+
if (ee) return;
|
|
837
1003
|
const r = process.env.SF_DEBUG === "true";
|
|
838
|
-
r && console.log("[WorkerPool] Initializing worker pool patching..."),
|
|
839
|
-
if (!
|
|
1004
|
+
r && console.log("[WorkerPool] Initializing worker pool patching..."), q("fs") && (r && console.log("[WorkerPool] Patching fs module..."), (function() {
|
|
1005
|
+
if (!pe) try {
|
|
840
1006
|
const t = require("node:fs");
|
|
841
1007
|
if (t.__sf_worker_pool_patched__) return;
|
|
842
1008
|
Object.defineProperty(t, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
843
|
-
for (const e of
|
|
1009
|
+
for (const e of it) if (typeof t[e] == "function") {
|
|
844
1010
|
const i = t[e];
|
|
845
1011
|
t[e] = function(...n) {
|
|
846
|
-
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);
|
|
847
1013
|
}, Object.defineProperty(t[e], "name", { value: e, writable: !1 });
|
|
848
1014
|
}
|
|
849
|
-
|
|
1015
|
+
pe = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] fs module patched successfully");
|
|
850
1016
|
} catch (t) {
|
|
851
1017
|
console.error("[WorkerPool] Error patching fs module:", t);
|
|
852
1018
|
}
|
|
853
|
-
})()),
|
|
854
|
-
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 {
|
|
855
1021
|
const t = require("node:crypto");
|
|
856
1022
|
if (t.__sf_worker_pool_patched__) return;
|
|
857
1023
|
Object.defineProperty(t, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
858
|
-
for (const e of
|
|
1024
|
+
for (const e of st) if (typeof t[e] == "function") {
|
|
859
1025
|
const i = t[e];
|
|
860
1026
|
t[e] = function(...n) {
|
|
861
|
-
return typeof n[n.length - 1] == "function" ?
|
|
1027
|
+
return typeof n[n.length - 1] == "function" ? x("crypto", e, i, n, this) : i.apply(this, n);
|
|
862
1028
|
}, Object.defineProperty(t[e], "name", { value: e, writable: !1 });
|
|
863
1029
|
}
|
|
864
|
-
|
|
1030
|
+
he = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] crypto module patched successfully");
|
|
865
1031
|
} catch (t) {
|
|
866
1032
|
console.error("[WorkerPool] Error patching crypto module:", t);
|
|
867
1033
|
}
|
|
868
|
-
})()),
|
|
869
|
-
if (!
|
|
1034
|
+
})()), q("zlib") && (r && console.log("[WorkerPool] Patching zlib module..."), (function() {
|
|
1035
|
+
if (!me) try {
|
|
870
1036
|
const t = require("node:zlib");
|
|
871
1037
|
if (t.__sf_worker_pool_patched__) return;
|
|
872
1038
|
Object.defineProperty(t, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
873
|
-
for (const e of
|
|
1039
|
+
for (const e of ot) if (typeof t[e] == "function") {
|
|
874
1040
|
const i = t[e];
|
|
875
1041
|
t[e] = function(...n) {
|
|
876
|
-
return typeof n[n.length - 1] == "function" ?
|
|
1042
|
+
return typeof n[n.length - 1] == "function" ? x("zlib", e, i, n, this) : i.apply(this, n);
|
|
877
1043
|
}, Object.defineProperty(t[e], "name", { value: e, writable: !1 });
|
|
878
1044
|
}
|
|
879
|
-
|
|
1045
|
+
me = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] zlib module patched successfully");
|
|
880
1046
|
} catch (t) {
|
|
881
1047
|
console.error("[WorkerPool] Error patching zlib module:", t);
|
|
882
1048
|
}
|
|
883
|
-
})()),
|
|
1049
|
+
})()), ee = !0, r && console.log("[WorkerPool] Worker pool patching initialized");
|
|
884
1050
|
}
|
|
885
|
-
function
|
|
886
|
-
return
|
|
1051
|
+
function ut() {
|
|
1052
|
+
return ee;
|
|
887
1053
|
}
|
|
888
|
-
let
|
|
889
|
-
function
|
|
890
|
-
if (
|
|
891
|
-
else if (!
|
|
892
|
-
|
|
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();
|
|
893
1059
|
try {
|
|
894
1060
|
let t, e;
|
|
895
|
-
const i =
|
|
1061
|
+
const i = Ie(new Error().stack);
|
|
896
1062
|
if (i) {
|
|
897
|
-
const
|
|
898
|
-
`)[2] || "",
|
|
899
|
-
|
|
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));
|
|
900
1066
|
}
|
|
901
1067
|
if (!r || !r.apiKey) {
|
|
902
|
-
const
|
|
903
|
-
console.error(
|
|
1068
|
+
const u = `The required API Key is not provided: ${JSON.stringify(r)}`;
|
|
1069
|
+
console.error(u);
|
|
904
1070
|
}
|
|
905
|
-
const { config: n } =
|
|
906
|
-
if (
|
|
1071
|
+
const { config: n } = Ne(r);
|
|
1072
|
+
if (Ee(n).catch(() => {
|
|
907
1073
|
}), t && (n.setupInterceptorsFile = t), e && (n.setupInterceptorsLine = e), n.sfDebug && console.log("Updated configuration after applying options:", n), !n.apiKey || !n.apiGraphqlEndpoint) {
|
|
908
|
-
const
|
|
909
|
-
throw console.error(
|
|
1074
|
+
const u = `The required config is not provided: ${JSON.stringify(n)}`;
|
|
1075
|
+
throw console.error(u), new Error(u);
|
|
910
1076
|
}
|
|
911
|
-
|
|
912
|
-
n.sfDebug && console.error("[FuncSpan] Failed to initialize config loader:",
|
|
913
|
-
}), process.env.SF_WORKER_POOL_DISABLED === "true" ? n.sfDebug && console.log("[setupInterceptors] Worker pool patching DISABLED (SF_WORKER_POOL_DISABLED=true)") :
|
|
914
|
-
const
|
|
915
|
-
|
|
916
|
-
const
|
|
917
|
-
new
|
|
918
|
-
const d = new
|
|
919
|
-
|
|
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);
|
|
920
1086
|
})(n.domainsToNotPropagateHeadersTo);
|
|
921
|
-
const l = new
|
|
922
|
-
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");
|
|
923
1089
|
} finally {
|
|
924
|
-
|
|
1090
|
+
J = !1;
|
|
925
1091
|
}
|
|
926
1092
|
}
|
|
927
1093
|
}
|
|
928
|
-
function
|
|
929
|
-
return
|
|
1094
|
+
function _t() {
|
|
1095
|
+
return te;
|
|
930
1096
|
}
|
|
931
|
-
function
|
|
932
|
-
const n =
|
|
933
|
-
new
|
|
1097
|
+
function Ft(r, t, e, i = !1) {
|
|
1098
|
+
const n = c();
|
|
1099
|
+
new ve(n.apiKey).identify(r, t, e, i);
|
|
934
1100
|
}
|
|
935
|
-
function
|
|
936
|
-
const n =
|
|
937
|
-
new
|
|
1101
|
+
function wt(r, t = {}, e, i = !1) {
|
|
1102
|
+
const n = c();
|
|
1103
|
+
new ve(n.apiKey).addOrUpdateMetadata(r, t, e, i);
|
|
938
1104
|
}
|
|
939
|
-
let
|
|
940
|
-
function
|
|
941
|
-
const n = function(...
|
|
942
|
-
const l =
|
|
943
|
-
|
|
944
|
-
const
|
|
945
|
-
const
|
|
946
|
-
if (
|
|
947
|
-
const
|
|
948
|
-
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;
|
|
949
1115
|
}
|
|
950
1116
|
try {
|
|
951
|
-
return
|
|
1117
|
+
return nt(g, f);
|
|
952
1118
|
} catch {
|
|
953
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 };
|
|
954
1120
|
}
|
|
955
1121
|
})(e, t);
|
|
956
|
-
if (
|
|
957
|
-
if (
|
|
958
|
-
|
|
959
|
-
const d =
|
|
960
|
-
d.setCurrentFunctionSpanId(
|
|
961
|
-
const
|
|
962
|
-
let
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
}),
|
|
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();
|
|
1128
|
+
let S = null;
|
|
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)));
|
|
966
1132
|
try {
|
|
967
|
-
const
|
|
968
|
-
if (
|
|
969
|
-
const
|
|
970
|
-
let
|
|
971
|
-
return
|
|
972
|
-
}, (
|
|
973
|
-
const
|
|
974
|
-
throw
|
|
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 }), $;
|
|
975
1141
|
});
|
|
976
|
-
const
|
|
977
|
-
let
|
|
978
|
-
return
|
|
979
|
-
} catch (
|
|
980
|
-
const
|
|
981
|
-
throw
|
|
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;
|
|
982
1148
|
}
|
|
983
1149
|
};
|
|
984
1150
|
Object.defineProperty(n, "name", { value: t, writable: !1 });
|
|
985
|
-
for (const
|
|
1151
|
+
for (const o in r) r.hasOwnProperty(o) && (n[o] = r[o]);
|
|
986
1152
|
return n;
|
|
987
1153
|
}
|
|
988
|
-
function
|
|
989
|
-
const t =
|
|
1154
|
+
function M(r) {
|
|
1155
|
+
const t = ye(), e = t?.sfDebug || !1;
|
|
990
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 });
|
|
991
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 };
|
|
992
1158
|
process.env.SF_FUNCSPAN_CONSOLE_OUTPUT === "true" && console.log(`
|
|
993
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" });
|
|
994
1160
|
const n = process.env.SF_FUNCSPAN_JSONL_FILE;
|
|
995
1161
|
if (n) try {
|
|
996
|
-
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 }) + `
|
|
997
1163
|
`;
|
|
998
|
-
|
|
999
|
-
} catch (
|
|
1000
|
-
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);
|
|
1001
1167
|
}
|
|
1002
1168
|
if (e && console.log("[FuncSpan] Sending function span to transmitter:", i), process.env.SF_FUNCSPAN_SKIP_BACKEND !== "true") try {
|
|
1003
|
-
(
|
|
1004
|
-
} catch (
|
|
1005
|
-
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);
|
|
1006
1172
|
}
|
|
1007
1173
|
}
|
|
1008
|
-
function
|
|
1174
|
+
function Nt(r) {
|
|
1009
1175
|
return !!r.includes("captureFunctionSpan(") || !!r.includes("@sailfish-ai/sf-veritas") || !(!r.includes("/* @sailfish-instrumented */") && !r.includes("// @sailfish-instrumented"));
|
|
1010
1176
|
}
|
|
1011
1177
|
export {
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
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
|
|
1038
1204
|
};
|