@sailfish-ai/sf-veritas 0.2.21 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/consoleLocationTransformer-BSSB5msZ.cjs +1 -0
- package/dist/consoleLocationTransformer-DZu_9MDA.js +51 -0
- package/dist/plugins/funcspanEsbuildPlugin.cjs +1 -1
- package/dist/plugins/funcspanEsbuildPlugin.mjs +20 -16
- package/dist/plugins/funcspanRollupPlugin.cjs +1 -1
- package/dist/plugins/funcspanRollupPlugin.mjs +17 -13
- package/dist/plugins/funcspanTscPlugin.cjs +1 -1
- package/dist/plugins/funcspanTscPlugin.mjs +34 -30
- package/dist/plugins/funcspanVitePlugin.cjs +1 -1
- package/dist/plugins/funcspanVitePlugin.mjs +16 -12
- package/dist/plugins/funcspanWebpackLoader.cjs +1 -1
- package/dist/plugins/funcspanWebpackLoader.mjs +55 -50
- package/dist/plugins/funcspanWebpackPlugin.cjs +1 -1
- package/dist/plugins/funcspanWebpackPlugin.mjs +1 -1
- package/dist/runtimeConfig-BZ61efqE.js +485 -0
- package/dist/runtimeConfig-CWpFWsmz.cjs +6 -0
- package/dist/sf-veritas.cjs +13 -13
- package/dist/sf-veritas.mjs +206 -176
- package/dist/telemetryWorker.cjs +1 -0
- package/dist/types/dataTransmitter.d.ts +6 -5
- package/dist/types/exceptionTransmitter.d.ts +2 -1
- package/dist/types/networkHopTransmitter.d.ts +2 -1
- package/dist/types/networkRequestTransmitter.d.ts +2 -1
- package/dist/types/plugins/consoleLocationTransformer.d.ts +37 -0
- package/dist/types/requestUtils.d.ts +17 -6
- package/dist/types/sourceLocation.d.ts +19 -19
- package/dist/types/telemetryWorker.d.ts +1 -0
- package/dist/worker-pool-capture.cjs +1 -1
- package/dist/worker-pool-capture.mjs +1 -1
- package/dist/workerPoolSpanCapture-Bg5av6gn.cjs +83 -0
- package/dist/{workerPoolSpanCapture-DVYmzgbN.js → workerPoolSpanCapture-BjdZn3LE.js} +222 -168
- package/package.json +1 -1
- package/dist/runtimeConfig-CB57auSb.js +0 -444
- package/dist/runtimeConfig-sm_7bnKx.cjs +0 -9
- package/dist/workerPoolSpanCapture-DFnbcpkU.cjs +0 -83
|
@@ -1,26 +1,28 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { AsyncLocalStorage as
|
|
5
|
-
import { appendFileSync as
|
|
6
|
-
import { threadId as
|
|
7
|
-
import { g as
|
|
8
|
-
|
|
1
|
+
var Q = Object.defineProperty;
|
|
2
|
+
var X = (n, t, s) => t in n ? Q(n, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : n[t] = s;
|
|
3
|
+
var y = (n, t, s) => X(n, typeof t != "symbol" ? t + "" : t, s);
|
|
4
|
+
import { AsyncLocalStorage as Z, AsyncResource as Y } from "async_hooks";
|
|
5
|
+
import { appendFileSync as ee } from "fs";
|
|
6
|
+
import { Worker as te, threadId as O } from "worker_threads";
|
|
7
|
+
import { g as S, C as L, v as j, a as M } from "./contextManager-RxrMXs5c.js";
|
|
8
|
+
import { dirname as ne, join as re } from "path";
|
|
9
|
+
import { fileURLToPath as se } from "url";
|
|
10
|
+
class oe {
|
|
9
11
|
constructor() {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
this.apiKey =
|
|
12
|
+
y(this, "apiKey");
|
|
13
|
+
y(this, "endpoint");
|
|
14
|
+
y(this, "queryType", "mutation");
|
|
15
|
+
y(this, "operationName", "");
|
|
16
|
+
y(this, "serviceUUID", S().serviceUUID);
|
|
17
|
+
y(this, "contextManager");
|
|
18
|
+
this.apiKey = S().apiKey, this.endpoint = S().apiGraphqlEndpoint, this.contextManager = L.getInstance();
|
|
17
19
|
}
|
|
18
20
|
get queryName() {
|
|
19
21
|
return this.operationName ? this.operationName.charAt(0).toLowerCase() + this.operationName.slice(1) : "";
|
|
20
22
|
}
|
|
21
23
|
getDefaultVariables() {
|
|
22
|
-
const t = Date.now().toString(),
|
|
23
|
-
return { apiKey: this.apiKey, serviceUuid: this.serviceUUID, sessionId:
|
|
24
|
+
const t = Date.now().toString(), s = this.contextManager.getOrSetSfTraceId(), a = this.contextManager.getCurrentFunctionSpanId();
|
|
25
|
+
return { apiKey: this.apiKey, serviceUuid: this.serviceUUID, sessionId: s, timestampMs: t, parentSpanId: a };
|
|
24
26
|
}
|
|
25
27
|
getVariables(t = {}) {
|
|
26
28
|
return { ...this.getDefaultVariables(), ...t };
|
|
@@ -35,44 +37,95 @@ class j {
|
|
|
35
37
|
this.serviceUUID = t;
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
|
-
const
|
|
39
|
-
let
|
|
40
|
-
function
|
|
41
|
-
return
|
|
40
|
+
const ae = typeof __dirname < "u" ? __dirname : ne(se(import.meta.url)), ie = fetch;
|
|
41
|
+
let b = !1;
|
|
42
|
+
function ye() {
|
|
43
|
+
return b;
|
|
42
44
|
}
|
|
43
|
-
|
|
45
|
+
const ue = process.env.SF_NBPOST_DISABLE_BATCHING === "1", A = parseInt(process.env.SF_MAIN_BATCH_SIZE || "0", 10);
|
|
46
|
+
let m = null, k = !1;
|
|
47
|
+
function B() {
|
|
48
|
+
if (k) return null;
|
|
49
|
+
if (m) return m;
|
|
44
50
|
try {
|
|
45
|
-
const
|
|
51
|
+
const n = re(ae, "telemetryWorker.cjs");
|
|
52
|
+
return m = new te(n, { env: { ...process.env, SF_NBPOST_BATCH_MAX: process.env.SF_NBPOST_BATCH_MAX || "50", SF_FLUSH_TELEMETRY_IN_BATCH: process.env.SF_FLUSH_TELEMETRY_IN_BATCH || "0", SF_BATCH_FLUSH_INTERVAL_MS: process.env.SF_BATCH_FLUSH_INTERVAL_MS || "50", SF_WORKER_MAX_CONCURRENT: process.env.SF_WORKER_MAX_CONCURRENT || "10" } }), m.unref(), m.on("error", () => {
|
|
53
|
+
k = !0, m = null;
|
|
54
|
+
}), m.on("exit", () => {
|
|
55
|
+
m = null;
|
|
56
|
+
}), m;
|
|
57
|
+
} catch {
|
|
58
|
+
return k = !0, null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
let g = [], v = !1;
|
|
62
|
+
function R() {
|
|
63
|
+
if (g.length === 0) return;
|
|
64
|
+
const n = B();
|
|
65
|
+
if (!n) {
|
|
66
|
+
for (const t of g) U(t.url, t.item.operationName, t.item.query, t.item.variables);
|
|
67
|
+
return g = [], void (v = !1);
|
|
68
|
+
}
|
|
69
|
+
g.length === 1 ? n.postMessage(g[0]) : n.postMessage({ batch: g }), g = [], v = !1;
|
|
70
|
+
}
|
|
71
|
+
async function V(n, t, s, a) {
|
|
72
|
+
if (ue) return U(n, t, s, a);
|
|
73
|
+
const o = { url: n, item: { query: s, variables: a, operationName: t } };
|
|
74
|
+
if (A === 1) {
|
|
75
|
+
const i = B();
|
|
76
|
+
return i ? void i.postMessage(o) : U(n, t, s, a);
|
|
77
|
+
}
|
|
78
|
+
g.push(o), A > 1 && g.length >= A ? R() : v || (v = !0, queueMicrotask(R));
|
|
79
|
+
}
|
|
80
|
+
async function U(n, t, s, a) {
|
|
81
|
+
try {
|
|
82
|
+
const o = S();
|
|
46
83
|
let i;
|
|
47
84
|
try {
|
|
48
|
-
i = JSON.stringify({ query:
|
|
85
|
+
i = JSON.stringify({ query: s, variables: a, operationName: t });
|
|
49
86
|
} catch {
|
|
50
|
-
i = JSON.stringify({ query:
|
|
87
|
+
i = JSON.stringify({ query: s, operationName: t });
|
|
51
88
|
}
|
|
52
|
-
|
|
53
|
-
if (
|
|
89
|
+
b = !0, ie(n, { method: "POST", headers: { "Content-Type": "application/json" }, body: i }).then(async (e) => {
|
|
90
|
+
if (b = !1, !e.ok) return void (o.sfDebug && console.error(`GraphQL request failed with status ${e.status} for ${t}`));
|
|
54
91
|
const r = await e.json();
|
|
55
92
|
r.errors?.length ? (function(u, d, l) {
|
|
56
93
|
const p = u && typeof u == "object" && !Array.isArray(u) ? Object.keys(u)[0] : void 0;
|
|
57
94
|
console.error(p === "identifyServiceDetails" ? `IdentifyServiceDetails NOT sent successfully for service: UUID=${l.serviceUUID}` : `GraphQL request failed with errors: ${JSON.stringify(d)} for operation key ${p}`);
|
|
58
|
-
})(r.data, r.errors,
|
|
95
|
+
})(r.data, r.errors, o) : o.sfDebug && (function(u, d, l) {
|
|
59
96
|
const p = u && typeof u == "object" && !Array.isArray(u) ? Object.keys(u)[0] : void 0, c = u[p] || !1;
|
|
60
|
-
p === "identifyServiceDetails" && (l.setServiceIdentificationReceived(c),
|
|
61
|
-
})(r.data, 0,
|
|
97
|
+
p === "identifyServiceDetails" && (l.setServiceIdentificationReceived(c), S().sfDebug && console.log(`IdentifyServiceDetails sent successfully for service: UUID=${l.serviceUUID}; serviceIdentificationReceived=${p === "identifyServiceDetails" ? c : "N/A"}`));
|
|
98
|
+
})(r.data, 0, o);
|
|
62
99
|
}).catch((e) => {
|
|
63
|
-
|
|
100
|
+
b = !1, o.sfDebug && (console.error(`[RequestUtils] Fetch error for ${t} to ${n}:`, e), e.cause && console.error("[RequestUtils] Error cause:", e.cause));
|
|
64
101
|
});
|
|
65
|
-
} catch (
|
|
66
|
-
|
|
102
|
+
} catch (o) {
|
|
103
|
+
b = !1, S().sfDebug && console.error("Error sending data to GraphQL server:", o);
|
|
67
104
|
}
|
|
68
105
|
}
|
|
69
|
-
|
|
70
|
-
|
|
106
|
+
let J = !1;
|
|
107
|
+
function Ne() {
|
|
108
|
+
if (J) return;
|
|
109
|
+
J = !0;
|
|
110
|
+
const n = () => {
|
|
111
|
+
try {
|
|
112
|
+
(function() {
|
|
113
|
+
R();
|
|
114
|
+
const t = B();
|
|
115
|
+
t && t.postMessage("flush");
|
|
116
|
+
})();
|
|
117
|
+
} catch {
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
process.on("beforeExit", n), process.on("SIGTERM", n), process.on("SIGINT", n);
|
|
121
|
+
}
|
|
122
|
+
function he() {
|
|
123
|
+
return { capture_arguments: $(process.env.SF_FUNCSPAN_CAPTURE_ARGUMENTS, !0), capture_return_value: $(process.env.SF_FUNCSPAN_CAPTURE_RETURN_VALUE, !0), arg_limit_mb: parseInt(process.env.SF_FUNCSPAN_ARG_LIMIT_MB || "1", 10), return_limit_mb: parseInt(process.env.SF_FUNCSPAN_RETURN_LIMIT_MB || "1", 10), autocapture_all_child_functions: $(process.env.SF_FUNCSPAN_AUTOCAPTURE_ALL_CHILD_FUNCTIONS, !1), sample_rate: parseFloat(process.env.SF_FUNCSPAN_SAMPLE_RATE || "1.0"), enable_sampling: $(process.env.SF_FUNCSPAN_ENABLE_SAMPLING, !1), capture_sf_veritas: $(process.env.SF_FUNCSPAN_CAPTURE_SF_VERITAS, !1), parse_json_strings: $(process.env.SF_FUNCSPAN_PARSE_JSON_STRINGS, !1) };
|
|
71
124
|
}
|
|
72
|
-
function
|
|
125
|
+
function $e() {
|
|
73
126
|
return { capture_arguments: !1, capture_return_value: !1, arg_limit_mb: 1, return_limit_mb: 1, autocapture_all_child_functions: !1, sample_rate: 0, enable_sampling: !1, capture_sf_veritas: !1, parse_json_strings: !1 };
|
|
74
127
|
}
|
|
75
|
-
function
|
|
128
|
+
function Ie(n) {
|
|
76
129
|
try {
|
|
77
130
|
const t = n.split("-");
|
|
78
131
|
return t.length !== 9 ? (console.error(`[FuncSpan] Invalid header format: expected 9 parts, got ${t.length}`), null) : { capture_arguments: t[0] === "1", capture_return_value: t[1] === "1", arg_limit_mb: parseInt(t[2], 10), return_limit_mb: parseInt(t[3], 10), autocapture_all_child_functions: t[4] === "1", sample_rate: parseFloat(t[5]), enable_sampling: t[6] === "1", capture_sf_veritas: t[7] === "1", parse_json_strings: t[8] === "1" };
|
|
@@ -80,50 +133,50 @@ function ae(n) {
|
|
|
80
133
|
return console.error(`[FuncSpan] Failed to parse header override "${n}":`, t), null;
|
|
81
134
|
}
|
|
82
135
|
}
|
|
83
|
-
function
|
|
136
|
+
function $(n, t) {
|
|
84
137
|
if (!n) return t;
|
|
85
|
-
const
|
|
86
|
-
return
|
|
138
|
+
const s = n.toLowerCase();
|
|
139
|
+
return s === "true" || s === "1" || s === "yes";
|
|
87
140
|
}
|
|
88
|
-
const
|
|
89
|
-
globalThis[
|
|
90
|
-
const
|
|
91
|
-
function
|
|
92
|
-
|
|
141
|
+
const C = "__sf_funcspanOverrideStorage";
|
|
142
|
+
globalThis[C] || (globalThis[C] = new Z());
|
|
143
|
+
const z = globalThis[C];
|
|
144
|
+
function be(n) {
|
|
145
|
+
z.enterWith(n);
|
|
93
146
|
}
|
|
94
|
-
function
|
|
95
|
-
return
|
|
147
|
+
function ve() {
|
|
148
|
+
return z.getStore();
|
|
96
149
|
}
|
|
97
|
-
function
|
|
150
|
+
function Te() {
|
|
98
151
|
}
|
|
99
|
-
function
|
|
152
|
+
function Fe(...n) {
|
|
100
153
|
const t = {};
|
|
101
|
-
for (const
|
|
154
|
+
for (const s of n) for (const a in s) s[a] !== void 0 && (t[a] = s[a]);
|
|
102
155
|
return t;
|
|
103
156
|
}
|
|
104
|
-
function
|
|
157
|
+
function q(n, t) {
|
|
105
158
|
try {
|
|
106
|
-
const
|
|
107
|
-
return
|
|
159
|
+
const s = JSON.stringify(n).length / 1048576;
|
|
160
|
+
return s <= t ? n : { _truncated: !0, _originalSizeMB: s.toFixed(2), _limitMB: t, _preview: JSON.stringify(n).substring(0, 500) + "..." };
|
|
108
161
|
} catch {
|
|
109
162
|
return { _error: "Failed to serialize data", _type: typeof n };
|
|
110
163
|
}
|
|
111
164
|
}
|
|
112
|
-
function
|
|
113
|
-
const
|
|
114
|
-
return
|
|
165
|
+
function N(n, t) {
|
|
166
|
+
const s = process.env[n];
|
|
167
|
+
return s === void 0 ? t : s === "true" || s === "1";
|
|
115
168
|
}
|
|
116
|
-
function
|
|
117
|
-
const
|
|
118
|
-
if (
|
|
119
|
-
const
|
|
120
|
-
return isNaN(
|
|
169
|
+
function x(n, t) {
|
|
170
|
+
const s = process.env[n];
|
|
171
|
+
if (s === void 0) return t;
|
|
172
|
+
const a = parseFloat(s);
|
|
173
|
+
return isNaN(a) ? t : a;
|
|
121
174
|
}
|
|
122
|
-
function
|
|
123
|
-
return { enabled:
|
|
175
|
+
function D() {
|
|
176
|
+
return { enabled: N("SF_WORKER_POOL_ENABLED", !0), trackFs: N("SF_WORKER_POOL_TRACK_FS", !1), trackDns: N("SF_WORKER_POOL_TRACK_DNS", !1), trackCrypto: N("SF_WORKER_POOL_TRACK_CRYPTO", !1), trackZlib: N("SF_WORKER_POOL_TRACK_ZLIB", !1), captureArguments: N("SF_WORKER_POOL_CAPTURE_ARGUMENTS", !0), captureReturnValue: N("SF_WORKER_POOL_CAPTURE_RETURN_VALUE", !0), argLimitMb: x("SF_WORKER_POOL_ARG_LIMIT_MB", 1), returnLimitMb: x("SF_WORKER_POOL_RETURN_LIMIT_MB", 1) };
|
|
124
177
|
}
|
|
125
|
-
function
|
|
126
|
-
const t =
|
|
178
|
+
function Ae(n) {
|
|
179
|
+
const t = D();
|
|
127
180
|
if (!t.enabled) return !1;
|
|
128
181
|
switch (n) {
|
|
129
182
|
case "fs":
|
|
@@ -138,12 +191,12 @@ function le(n) {
|
|
|
138
191
|
return !1;
|
|
139
192
|
}
|
|
140
193
|
}
|
|
141
|
-
function
|
|
142
|
-
let
|
|
194
|
+
function G(n, t, s, a) {
|
|
195
|
+
let o;
|
|
143
196
|
try {
|
|
144
197
|
switch (n) {
|
|
145
198
|
case "fs":
|
|
146
|
-
|
|
199
|
+
o = (function(i, e) {
|
|
147
200
|
const r = {};
|
|
148
201
|
switch (i) {
|
|
149
202
|
case "readFile":
|
|
@@ -179,10 +232,10 @@ function B(n, t, a, o) {
|
|
|
179
232
|
r.argsCount = e.length - 1;
|
|
180
233
|
}
|
|
181
234
|
return r;
|
|
182
|
-
})(t,
|
|
235
|
+
})(t, s);
|
|
183
236
|
break;
|
|
184
237
|
case "dns":
|
|
185
|
-
|
|
238
|
+
o = (function(i, e) {
|
|
186
239
|
const r = {};
|
|
187
240
|
switch (i) {
|
|
188
241
|
case "lookup":
|
|
@@ -204,10 +257,10 @@ function B(n, t, a, o) {
|
|
|
204
257
|
r.argsCount = e.length - 1;
|
|
205
258
|
}
|
|
206
259
|
return r;
|
|
207
|
-
})(t,
|
|
260
|
+
})(t, s);
|
|
208
261
|
break;
|
|
209
262
|
case "crypto":
|
|
210
|
-
|
|
263
|
+
o = (function(i, e) {
|
|
211
264
|
const r = {};
|
|
212
265
|
switch (i) {
|
|
213
266
|
case "pbkdf2":
|
|
@@ -226,28 +279,28 @@ function B(n, t, a, o) {
|
|
|
226
279
|
r.argsCount = e.length - 1;
|
|
227
280
|
}
|
|
228
281
|
return r;
|
|
229
|
-
})(t,
|
|
282
|
+
})(t, s);
|
|
230
283
|
break;
|
|
231
284
|
case "zlib":
|
|
232
|
-
|
|
285
|
+
o = (function(i, e) {
|
|
233
286
|
const r = {};
|
|
234
287
|
return Buffer.isBuffer(e[0]) ? (r.inputType = "Buffer", r.inputSize = e[0].length) : typeof e[0] == "string" ? (r.inputType = "string", r.inputSize = e[0].length) : r.inputType = typeof e[0], e[1] && typeof e[1] == "object" && typeof e[1] != "function" && (r.options = { ...e[1] }), r;
|
|
235
|
-
})(0,
|
|
288
|
+
})(0, s);
|
|
236
289
|
break;
|
|
237
290
|
default:
|
|
238
291
|
return null;
|
|
239
292
|
}
|
|
240
|
-
return
|
|
293
|
+
return a > 0 ? q(o, a) : o;
|
|
241
294
|
} catch {
|
|
242
|
-
return { error: "Failed to capture arguments", argsCount:
|
|
295
|
+
return { error: "Failed to capture arguments", argsCount: s.length - 1 };
|
|
243
296
|
}
|
|
244
297
|
}
|
|
245
|
-
function
|
|
246
|
-
let
|
|
298
|
+
function H(n, t, s, a) {
|
|
299
|
+
let o;
|
|
247
300
|
try {
|
|
248
301
|
switch (n) {
|
|
249
302
|
case "fs":
|
|
250
|
-
|
|
303
|
+
o = (function(i, e) {
|
|
251
304
|
if (!e) return null;
|
|
252
305
|
switch (i) {
|
|
253
306
|
case "readFile":
|
|
@@ -267,10 +320,10 @@ function M(n, t, a, o) {
|
|
|
267
320
|
default:
|
|
268
321
|
return e;
|
|
269
322
|
}
|
|
270
|
-
})(t,
|
|
323
|
+
})(t, s);
|
|
271
324
|
break;
|
|
272
325
|
case "dns":
|
|
273
|
-
|
|
326
|
+
o = (function(i, e) {
|
|
274
327
|
if (!e) return null;
|
|
275
328
|
switch (i) {
|
|
276
329
|
case "lookup":
|
|
@@ -288,10 +341,10 @@ function M(n, t, a, o) {
|
|
|
288
341
|
default:
|
|
289
342
|
return e;
|
|
290
343
|
}
|
|
291
|
-
})(t,
|
|
344
|
+
})(t, s);
|
|
292
345
|
break;
|
|
293
346
|
case "crypto":
|
|
294
|
-
|
|
347
|
+
o = (function(i, e) {
|
|
295
348
|
if (!e) return null;
|
|
296
349
|
switch (i) {
|
|
297
350
|
case "pbkdf2":
|
|
@@ -303,59 +356,59 @@ function M(n, t, a, o) {
|
|
|
303
356
|
default:
|
|
304
357
|
return e;
|
|
305
358
|
}
|
|
306
|
-
})(t,
|
|
359
|
+
})(t, s);
|
|
307
360
|
break;
|
|
308
361
|
case "zlib":
|
|
309
|
-
|
|
362
|
+
o = (function(i, e) {
|
|
310
363
|
return e ? Buffer.isBuffer(e) ? { type: "Buffer", size: e.length } : typeof e == "string" ? { type: "string", size: e.length } : { type: typeof e } : null;
|
|
311
|
-
})(0,
|
|
364
|
+
})(0, s);
|
|
312
365
|
break;
|
|
313
366
|
default:
|
|
314
367
|
return null;
|
|
315
368
|
}
|
|
316
|
-
return
|
|
369
|
+
return a > 0 ? q(o, a) : o;
|
|
317
370
|
} catch {
|
|
318
|
-
return { error: "Failed to capture result", type: typeof
|
|
371
|
+
return { error: "Failed to capture result", type: typeof s };
|
|
319
372
|
}
|
|
320
373
|
}
|
|
321
|
-
function
|
|
374
|
+
function le(n) {
|
|
322
375
|
return n.operationType === "worker_pool";
|
|
323
376
|
}
|
|
324
|
-
class
|
|
377
|
+
class ce extends oe {
|
|
325
378
|
constructor() {
|
|
326
379
|
super(), this.operationName = "CollectFunctionSpans";
|
|
327
380
|
}
|
|
328
381
|
send(t) {
|
|
329
|
-
const
|
|
330
|
-
|
|
331
|
-
for (const
|
|
332
|
-
if (
|
|
333
|
-
this.sendWorkerPoolSpan(
|
|
382
|
+
const s = S().sfDebug;
|
|
383
|
+
s && console.log(`[FunctionSpanTransmitter] Preparing to send ${t.length} function span(s)`);
|
|
384
|
+
for (const a of t) try {
|
|
385
|
+
if (le(a)) {
|
|
386
|
+
this.sendWorkerPoolSpan(a, s);
|
|
334
387
|
continue;
|
|
335
388
|
}
|
|
336
|
-
const
|
|
389
|
+
const o = a;
|
|
337
390
|
let i;
|
|
338
|
-
if (
|
|
339
|
-
const r = typeof
|
|
340
|
-
i = JSON.stringify({ type: r, has_value: !0, value:
|
|
341
|
-
} else i =
|
|
342
|
-
const e = this.getVariables({ library: "JS/TS BACKEND", version:
|
|
343
|
-
|
|
344
|
-
} catch (
|
|
345
|
-
console.error(`[FunctionSpanTransmitter] Error preparing function span for ${
|
|
391
|
+
if (o.result !== void 0 && o.result !== null) {
|
|
392
|
+
const r = typeof o.result;
|
|
393
|
+
i = JSON.stringify({ type: r, has_value: !0, value: o.result });
|
|
394
|
+
} else i = o.result === null ? JSON.stringify({ type: "null", has_value: !0, value: null }) : JSON.stringify({ type: "undefined", has_value: !1, value: null });
|
|
395
|
+
const e = this.getVariables({ library: "JS/TS BACKEND", version: S().version, spanId: o.spanId, parentSpanId: o.parentSpanId, filePath: o.filePath, lineNumber: o.metadata.line, columnNumber: o.metadata.column, functionName: o.functionName, arguments: JSON.stringify(o.args || {}), returnValue: i, startTimeNs: (1e6 * Date.now() - 1e6 * o.duration).toString(), durationNs: (1e6 * o.duration).toString() });
|
|
396
|
+
s && (console.log(`[FunctionSpanTransmitter] Sending GraphQL mutation to ${this.endpoint}`), console.log("[FunctionSpanTransmitter] Variables:", JSON.stringify(e, null, 2))), V(this.endpoint, this.operationName, this.getQuery(), e), s && console.log(`[FunctionSpanTransmitter] Queued function span for ${o.functionName}`);
|
|
397
|
+
} catch (o) {
|
|
398
|
+
console.error(`[FunctionSpanTransmitter] Error preparing function span for ${a.functionName}:`, o);
|
|
346
399
|
}
|
|
347
400
|
}
|
|
348
|
-
sendWorkerPoolSpan(t,
|
|
401
|
+
sendWorkerPoolSpan(t, s) {
|
|
349
402
|
try {
|
|
350
|
-
let
|
|
403
|
+
let a;
|
|
351
404
|
if (t.result !== void 0 && t.result !== null) {
|
|
352
405
|
const i = typeof t.result;
|
|
353
|
-
|
|
354
|
-
} else
|
|
355
|
-
const
|
|
356
|
-
|
|
357
|
-
} catch (
|
|
358
|
-
console.error(`[FunctionSpanTransmitter] Error preparing worker pool span for ${t.operationName}:`,
|
|
406
|
+
a = JSON.stringify({ type: i, has_value: !0, value: t.result });
|
|
407
|
+
} else a = t.result === null ? JSON.stringify({ type: "null", has_value: !0, value: null }) : JSON.stringify({ type: "undefined", has_value: !1, value: null });
|
|
408
|
+
const o = this.getVariables({ library: "JS/TS BACKEND", version: S().version, spanId: t.spanId, operationName: t.operationName, moduleName: t.moduleName, methodName: t.methodName, startTimeNs: t.startTimeNs, durationNs: t.durationNs, arguments: JSON.stringify(t.args || {}), returnValue: a, error: t.error, pid: t.pid, threadId: t.threadId });
|
|
409
|
+
s && (console.log(`[FunctionSpanTransmitter] Sending worker pool span: ${t.operationName}`), console.log("[FunctionSpanTransmitter] Variables:", JSON.stringify(o, null, 2))), V(this.endpoint, "CollectWorkerPoolSpans", this.getWorkerPoolQuery(), o), s && console.log(`[FunctionSpanTransmitter] Queued worker pool span for ${t.operationName}`);
|
|
410
|
+
} catch (a) {
|
|
411
|
+
console.error(`[FunctionSpanTransmitter] Error preparing worker pool span for ${t.operationName}:`, a);
|
|
359
412
|
}
|
|
360
413
|
}
|
|
361
414
|
getWorkerPoolQuery() {
|
|
@@ -445,77 +498,78 @@ class Q extends j {
|
|
|
445
498
|
`;
|
|
446
499
|
}
|
|
447
500
|
}
|
|
448
|
-
let
|
|
449
|
-
function
|
|
450
|
-
const i =
|
|
501
|
+
let P = null;
|
|
502
|
+
function ke(n, t, s, a, o) {
|
|
503
|
+
const i = M(), e = i?.sfDebug || !1;
|
|
451
504
|
e && console.log(`[WorkerPool] Capturing ${n}.${t}`);
|
|
452
|
-
const r =
|
|
505
|
+
const r = D(), u = L.getInstance().getCurrentFunctionSpanId(), d = j();
|
|
453
506
|
e && console.log(`[WorkerPool] Span ID: ${d}, Parent: ${u || "none"}`);
|
|
454
|
-
const l = new
|
|
507
|
+
const l = new Y("WorkerPoolOperation"), p = process.hrtime.bigint();
|
|
455
508
|
let c = null;
|
|
456
|
-
r.captureArguments && (c =
|
|
457
|
-
const
|
|
458
|
-
if (
|
|
459
|
-
const
|
|
460
|
-
return
|
|
461
|
-
const
|
|
462
|
-
|
|
463
|
-
e && console.log(`[WorkerPool] ${n}.${t} completed in ${
|
|
464
|
-
let
|
|
465
|
-
|
|
509
|
+
r.captureArguments && (c = G(n, t, a, r.argLimitMb));
|
|
510
|
+
const f = a.findIndex((h) => typeof h == "function");
|
|
511
|
+
if (f === -1) return e && console.log(`[WorkerPool] No callback found for ${n}.${t}`), s.apply(o, a);
|
|
512
|
+
const _ = a[f], I = [...a];
|
|
513
|
+
return I[f] = function(h, ...T) {
|
|
514
|
+
const F = process.hrtime.bigint() - p, w = Number(F) / 1e6;
|
|
515
|
+
_(h, ...T), l.runInAsyncScope(() => {
|
|
516
|
+
e && console.log(`[WorkerPool] ${n}.${t} completed in ${w.toFixed(3)}ms (${F}ns)`);
|
|
517
|
+
let W = null, K = null;
|
|
518
|
+
h ? K = h?.message || String(h) : r.captureReturnValue && T.length > 0 && (W = H(n, t, T[0], r.returnLimitMb)), E({ operationType: "worker_pool", operationName: `${n}.${t}`, moduleName: n, methodName: t, duration: w, durationNs: F.toString(), startTimeNs: p.toString(), args: c, result: W, error: K, spanId: d, parentSpanId: u, pid: process.pid, threadId: O });
|
|
466
519
|
}), l.emitDestroy();
|
|
467
|
-
},
|
|
520
|
+
}, s.apply(o, I);
|
|
468
521
|
}
|
|
469
|
-
function
|
|
470
|
-
const i =
|
|
522
|
+
function Pe(n, t, s, a, o) {
|
|
523
|
+
const i = M(), e = i?.sfDebug || !1;
|
|
471
524
|
e && console.log(`[WorkerPool] Capturing ${n}.${t} (Promise)`);
|
|
472
|
-
const r =
|
|
525
|
+
const r = D(), u = L.getInstance().getCurrentFunctionSpanId(), d = j();
|
|
473
526
|
e && console.log(`[WorkerPool] Span ID: ${d}, Parent: ${u || "none"}`);
|
|
474
527
|
const l = process.hrtime.bigint();
|
|
475
528
|
let p = null;
|
|
476
|
-
return r.captureArguments && (p =
|
|
477
|
-
const
|
|
478
|
-
e && console.log(`[WorkerPool] ${n}.${t} completed in ${
|
|
479
|
-
let
|
|
480
|
-
return r.captureReturnValue && (
|
|
529
|
+
return r.captureArguments && (p = G(n, t, a, r.argLimitMb)), s.apply(o, a).then((c) => {
|
|
530
|
+
const f = process.hrtime.bigint() - l, _ = Number(f) / 1e6;
|
|
531
|
+
e && console.log(`[WorkerPool] ${n}.${t} completed in ${_.toFixed(3)}ms (${f}ns)`);
|
|
532
|
+
let I = null;
|
|
533
|
+
return r.captureReturnValue && (I = H(n, t, c, r.returnLimitMb)), E({ operationType: "worker_pool", operationName: `${n}.${t}`, moduleName: n, methodName: t, duration: _, durationNs: f.toString(), startTimeNs: l.toString(), args: p, result: I, error: null, spanId: d, parentSpanId: u, pid: process.pid, threadId: O }), c;
|
|
481
534
|
}, (c) => {
|
|
482
|
-
const
|
|
483
|
-
throw e && console.log(`[WorkerPool] ${n}.${t} failed in ${
|
|
535
|
+
const f = process.hrtime.bigint() - l, _ = Number(f) / 1e6;
|
|
536
|
+
throw e && console.log(`[WorkerPool] ${n}.${t} failed in ${_.toFixed(3)}ms: ${c?.message || c}`), E({ operationType: "worker_pool", operationName: `${n}.${t}`, moduleName: n, methodName: t, duration: _, durationNs: f.toString(), startTimeNs: l.toString(), args: p, result: null, error: c?.message || String(c), spanId: d, parentSpanId: u, pid: process.pid, threadId: O }), c;
|
|
484
537
|
});
|
|
485
538
|
}
|
|
486
|
-
function
|
|
487
|
-
const t =
|
|
488
|
-
|
|
539
|
+
function E(n) {
|
|
540
|
+
const t = M(), s = t?.sfDebug || !1;
|
|
541
|
+
s && console.log("[WorkerPool] Capturing span:", { operation: n.operationName, duration: `${n.duration}ms`, error: n.error, spanId: n.spanId, parentSpanId: n.parentSpanId }), process.env.SF_FUNCSPAN_CONSOLE_OUTPUT === "true" && console.log(`
|
|
489
542
|
⚙️ Worker Pool Operation:`, { operation: n.operationName, duration: `${n.duration.toFixed(2)}ms`, arguments: n.args, result: n.error ? `Error: ${n.error}` : n.result, spanId: n.spanId, parentSpanId: n.parentSpanId || "none" });
|
|
490
|
-
const
|
|
491
|
-
if (
|
|
492
|
-
const
|
|
543
|
+
const a = process.env.SF_FUNCSPAN_JSONL_FILE;
|
|
544
|
+
if (a) try {
|
|
545
|
+
const o = a === "true" || a === "1" ? "funcspans.jsonl" : a, i = Date.now(), e = process.hrtime.bigint(), r = BigInt(n.startTimeNs), u = Number(e - r) / 1e6, d = new Date(i - u).toISOString(), l = JSON.stringify({ timestamp: d, operationType: n.operationType, operationName: n.operationName, moduleName: n.moduleName, methodName: n.methodName, duration: n.duration, durationNs: n.durationNs, startTimeNs: n.startTimeNs, arguments: n.args, returnValue: n.error ? { error: String(n.error) } : n.result, spanId: n.spanId, parentSpanId: n.parentSpanId, pid: n.pid, threadId: n.threadId }) + `
|
|
493
546
|
`;
|
|
494
|
-
|
|
495
|
-
} catch (
|
|
496
|
-
console.error("[WorkerPool] Error writing to JSONL file:",
|
|
547
|
+
ee(o, l, "utf-8");
|
|
548
|
+
} catch (o) {
|
|
549
|
+
console.error("[WorkerPool] Error writing to JSONL file:", o);
|
|
497
550
|
}
|
|
498
|
-
if (
|
|
499
|
-
(
|
|
500
|
-
} catch (
|
|
501
|
-
|
|
551
|
+
if (s && console.log("[WorkerPool] Sending span to transmitter"), process.env.SF_FUNCSPAN_SKIP_BACKEND !== "true") try {
|
|
552
|
+
(P || (P = new ce()), P).send([n]), s && console.log("[WorkerPool] Span sent successfully");
|
|
553
|
+
} catch (o) {
|
|
554
|
+
s && console.error("[WorkerPool] Error sending span:", o);
|
|
502
555
|
}
|
|
503
556
|
}
|
|
504
557
|
export {
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
558
|
+
oe as B,
|
|
559
|
+
ce as F,
|
|
560
|
+
$e as a,
|
|
561
|
+
he as b,
|
|
562
|
+
ke as c,
|
|
563
|
+
Pe as d,
|
|
564
|
+
Ae as e,
|
|
565
|
+
z as f,
|
|
566
|
+
ve as g,
|
|
567
|
+
Te as h,
|
|
568
|
+
ye as i,
|
|
569
|
+
Fe as m,
|
|
570
|
+
V as n,
|
|
571
|
+
Ie as p,
|
|
572
|
+
Ne as r,
|
|
573
|
+
be as s,
|
|
574
|
+
q as t
|
|
521
575
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sailfish-ai/sf-veritas",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"publishPublicly": true,
|
|
5
5
|
"description": "A versatile Edge Runtime-compatible package for JavaScript and TypeScript backend systems and scripts.",
|
|
6
6
|
"main": "./dist/sf-veritas.cjs",
|