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