@sailfish-ai/sf-veritas 0.2.14 → 0.2.16
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/sf-veritas.cjs +12 -12
- package/dist/sf-veritas.mjs +201 -193
- package/dist/types/funcSpanConfig.d.ts +0 -4
- package/dist/types/funcSpanConfigLoader.d.ts +1 -1
- package/dist/worker-pool-capture.cjs +1 -1
- package/dist/worker-pool-capture.mjs +1 -1
- package/dist/{workerPoolSpanCapture-Danyb3Qa.cjs → workerPoolSpanCapture-COwiNikM.cjs} +2 -2
- package/dist/{workerPoolSpanCapture-DWS_V0Mn.js → workerPoolSpanCapture-d-8ExI18.js} +84 -82
- package/package.json +1 -1
package/dist/sf-veritas.mjs
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var y = (r, t, e) =>
|
|
4
|
-
import { g as u, C as
|
|
5
|
-
import { r as
|
|
6
|
-
import { B as T, n as E, f as
|
|
7
|
-
import { e as
|
|
8
|
-
import { C as
|
|
9
|
-
import { d as
|
|
10
|
-
import { createRequire as
|
|
11
|
-
import * as
|
|
12
|
-
import { readFileSync as
|
|
13
|
-
import { s as
|
|
1
|
+
var ge = Object.defineProperty;
|
|
2
|
+
var fe = (r, t, e) => t in r ? ge(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
|
|
3
|
+
var y = (r, t, e) => fe(r, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
import { g as u, C as j, D as he, v as se, b as q, c as me, a as oe } from "./contextManager-Cx03mw7l.js";
|
|
5
|
+
import { r as ft } from "./contextManager-Cx03mw7l.js";
|
|
6
|
+
import { B as T, n as E, f as ye, g as ae, p as ce, a as de, b as Se, m as U, c as A, d as Ie, i as R, t as H, F as ve } from "./workerPoolSpanCapture-d-8ExI18.js";
|
|
7
|
+
import { e as mt, s as yt } from "./workerPoolSpanCapture-d-8ExI18.js";
|
|
8
|
+
import { C as $e, i as _, a as _e, h as P, b as be, c as Ne } from "./runtimeConfig-DndXTWki.js";
|
|
9
|
+
import { d as It, e as vt, s as $t } from "./runtimeConfig-DndXTWki.js";
|
|
10
|
+
import { createRequire as Fe } from "node:module";
|
|
11
|
+
import * as M from "fs";
|
|
12
|
+
import { readFileSync as De, appendFileSync as Pe } from "fs";
|
|
13
|
+
import { s as Ee } from "./source-map-Cr6YkjTd.js";
|
|
14
14
|
import * as F from "path";
|
|
15
|
-
import { glob as
|
|
16
|
-
import { threadId as
|
|
17
|
-
import { s as
|
|
18
|
-
class
|
|
15
|
+
import { glob as we } from "glob";
|
|
16
|
+
import { threadId as O } from "worker_threads";
|
|
17
|
+
import { s as bt, t as Nt, a as Ft } from "./funcSpanTransformer-Byqzu4B1.js";
|
|
18
|
+
class C extends T {
|
|
19
19
|
constructor() {
|
|
20
20
|
super(), this.setOperationName("IdentifyServiceDetails");
|
|
21
21
|
}
|
|
@@ -63,17 +63,17 @@ class U extends T {
|
|
|
63
63
|
E(this.endpoint, this.operationName, t, e);
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
function
|
|
66
|
+
function Te(r) {
|
|
67
67
|
try {
|
|
68
68
|
return JSON.stringify(r), !0;
|
|
69
69
|
} catch {
|
|
70
70
|
return !1;
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
|
-
class
|
|
73
|
+
class Ce extends T {
|
|
74
74
|
constructor() {
|
|
75
75
|
super();
|
|
76
|
-
y(this, "serviceIdentifier", new
|
|
76
|
+
y(this, "serviceIdentifier", new C());
|
|
77
77
|
this.setOperationName("CollectMetadata");
|
|
78
78
|
}
|
|
79
79
|
async sendAppIdentifier() {
|
|
@@ -88,7 +88,7 @@ class Te extends T {
|
|
|
88
88
|
if (!o) {
|
|
89
89
|
const c = (function(a) {
|
|
90
90
|
const l = {}, g = [];
|
|
91
|
-
if (a) for (const [f, h] of Object.entries(a))
|
|
91
|
+
if (a) for (const [f, h] of Object.entries(a)) Te(h) ? l[f] = h : g.push(f);
|
|
92
92
|
return { traitsJson: JSON.stringify(l), excludedFields: g };
|
|
93
93
|
})(i);
|
|
94
94
|
o = c.traitsJson, d = c.excludedFields;
|
|
@@ -104,10 +104,10 @@ class Te extends T {
|
|
|
104
104
|
`;
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
|
-
class
|
|
107
|
+
class ue {
|
|
108
108
|
constructor(t) {
|
|
109
109
|
y(this, "metadataTransmitter");
|
|
110
|
-
this.apiKey = t, this.metadataTransmitter = new
|
|
110
|
+
this.apiKey = t, this.metadataTransmitter = new Ce();
|
|
111
111
|
}
|
|
112
112
|
identify(t, e, i, n = !1) {
|
|
113
113
|
e || i ? this.addOrUpdateMetadata(t, e, i, n) : this.addOrUpdateMetadata(t, {}, void 0, n);
|
|
@@ -117,10 +117,10 @@ class le {
|
|
|
117
117
|
u().sfDebug && console.log(" [[DEBUG - addOrUpdateMetadata]] Starting operation"), u().sfDebug && console.log(" addOrUpdateMetadata...SENDING DATA...", t, e, i), this.metadataTransmitter.doSend(t, e, n, i);
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
-
class
|
|
120
|
+
class V extends T {
|
|
121
121
|
constructor() {
|
|
122
122
|
super();
|
|
123
|
-
y(this, "serviceIdentifier", new
|
|
123
|
+
y(this, "serviceIdentifier", new C());
|
|
124
124
|
}
|
|
125
125
|
async sendAppIdentifier() {
|
|
126
126
|
this.serviceIdentifier.doSend({});
|
|
@@ -164,10 +164,10 @@ class Q extends T {
|
|
|
164
164
|
`;
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
|
-
class
|
|
167
|
+
class Ue extends T {
|
|
168
168
|
constructor() {
|
|
169
169
|
super();
|
|
170
|
-
y(this, "serviceIdentifier", new
|
|
170
|
+
y(this, "serviceIdentifier", new C());
|
|
171
171
|
y(this, "supplementalFields", {});
|
|
172
172
|
this.setOperationName("CollectExceptions");
|
|
173
173
|
}
|
|
@@ -186,7 +186,7 @@ class Ce extends T {
|
|
|
186
186
|
}
|
|
187
187
|
async send(e, i) {
|
|
188
188
|
u().sfDebug && console.log(" SENDING EXCEPTION...");
|
|
189
|
-
const n = JSON.stringify(
|
|
189
|
+
const n = JSON.stringify($e.encode(i)), o = this.normalizedSupplementalForGraphQL(), d = this.getVariables({ exceptionMessage: e, traceJson: n, reentrancyGuardPreactive: !1, library: u().packageLibraryType, version: u().version, ...o });
|
|
190
190
|
E(this.endpoint, this.operationName, this.getQuery(), d);
|
|
191
191
|
}
|
|
192
192
|
getQuery() {
|
|
@@ -221,19 +221,19 @@ class Ce extends T {
|
|
|
221
221
|
`;
|
|
222
222
|
}
|
|
223
223
|
}
|
|
224
|
-
const
|
|
225
|
-
var
|
|
226
|
-
const
|
|
227
|
-
let
|
|
228
|
-
function
|
|
224
|
+
const X = "getting request source code";
|
|
225
|
+
var k = ((r) => (r.UNKNOWN = "unknown", r.ANONYMOUS = "anonymous", r.NOT_CAPTURED = "not captured", r))(k || {});
|
|
226
|
+
const x = "http:", G = "https:", Re = Fe(import.meta.url);
|
|
227
|
+
let Y = !1;
|
|
228
|
+
function Oe() {
|
|
229
229
|
const r = u().sfDebug;
|
|
230
|
-
if (
|
|
230
|
+
if (Y) return void (r && _("[patchNodeHttpInbound] Already installed, skipping."));
|
|
231
231
|
let t;
|
|
232
|
-
|
|
232
|
+
Y = !0;
|
|
233
233
|
try {
|
|
234
|
-
t =
|
|
234
|
+
t = Re("node:http"), r && _("[patchNodeHttpInbound] node:http required successfully.");
|
|
235
235
|
} catch (n) {
|
|
236
|
-
return void
|
|
236
|
+
return void _e("Failed to require node:http:", n);
|
|
237
237
|
}
|
|
238
238
|
if (!t?.Server?.prototype) return void (r && _("[patchNodeHttpInbound] http.Server.prototype not found."));
|
|
239
239
|
const e = t.Server.prototype, i = e.emit;
|
|
@@ -246,7 +246,7 @@ function Re() {
|
|
|
246
246
|
return m;
|
|
247
247
|
})(d?.headers), a = c["x-sf3-rid"], l = c["x-sf3-functionspancaptureoverride"];
|
|
248
248
|
r && (_("[patchNodeHttpInbound] Intercepted request event."), _("[patchNodeHttpInbound] Inbound headers:", c), _("[patchNodeHttpInbound] Trace header:", a), _("[patchNodeHttpInbound] FuncSpan override header:", l));
|
|
249
|
-
const g =
|
|
249
|
+
const g = j.getInstance();
|
|
250
250
|
g.setTraceId(a);
|
|
251
251
|
const f = g.getTraceId();
|
|
252
252
|
r && _("[patchNodeHttpInbound] Context traceId set:", f);
|
|
@@ -259,13 +259,13 @@ function Re() {
|
|
|
259
259
|
});
|
|
260
260
|
if (!l) return h();
|
|
261
261
|
try {
|
|
262
|
-
return
|
|
262
|
+
return ye.run(l, () => h());
|
|
263
263
|
} catch {
|
|
264
264
|
return h();
|
|
265
265
|
}
|
|
266
266
|
}) : r && _("[patchNodeHttpInbound] Already patched, skipping.");
|
|
267
267
|
}
|
|
268
|
-
class
|
|
268
|
+
class Le extends V {
|
|
269
269
|
constructor() {
|
|
270
270
|
super(), this.setOperationName("DomainsToNotPassHeaderTo");
|
|
271
271
|
}
|
|
@@ -289,10 +289,10 @@ class Oe extends Q {
|
|
|
289
289
|
E(this.endpoint, this.operationName, e, i);
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
|
-
class
|
|
292
|
+
class Ae extends T {
|
|
293
293
|
constructor() {
|
|
294
294
|
super();
|
|
295
|
-
y(this, "serviceIdentifier", new
|
|
295
|
+
y(this, "serviceIdentifier", new C());
|
|
296
296
|
this.setOperationName("CollectNetworkHops");
|
|
297
297
|
}
|
|
298
298
|
async sendAppIdentifier() {
|
|
@@ -333,10 +333,10 @@ class Le extends T {
|
|
|
333
333
|
`;
|
|
334
334
|
}
|
|
335
335
|
}
|
|
336
|
-
class
|
|
336
|
+
class ke extends T {
|
|
337
337
|
constructor() {
|
|
338
338
|
super();
|
|
339
|
-
y(this, "serviceIdentifier", new
|
|
339
|
+
y(this, "serviceIdentifier", new C());
|
|
340
340
|
this.setOperationName("CollectNetworkRequest");
|
|
341
341
|
}
|
|
342
342
|
async sendAppIdentifier() {
|
|
@@ -360,15 +360,15 @@ class Ae extends T {
|
|
|
360
360
|
await E(this.endpoint, this.operationName, this.getQuery(), i);
|
|
361
361
|
}
|
|
362
362
|
}
|
|
363
|
-
const
|
|
364
|
-
class
|
|
363
|
+
const K = [400, 403];
|
|
364
|
+
class qe {
|
|
365
365
|
constructor(t = []) {
|
|
366
366
|
y(this, "HEADER_TRACING", "X-Sf3-Rid");
|
|
367
367
|
y(this, "HEADER_LOG_GUARD", "reentrancy_guard_logging_preactive");
|
|
368
368
|
y(this, "HEADER_PRINT_GUARD", "reentrancy_guard_print_preactive");
|
|
369
369
|
y(this, "HEADER_EXCEPTION_GUARD", "reentrancy_guard_exception_preactive");
|
|
370
370
|
y(this, "contextManager");
|
|
371
|
-
this.contextManager =
|
|
371
|
+
this.contextManager = j.getInstance(), t?.forEach((e) => {
|
|
372
372
|
typeof e == "string" && e.trim() && this.contextManager.getExcludedDomains().add(e);
|
|
373
373
|
}), u().sfDebug && console.log("[RequestInterceptor] Initialized with static excluded domains.");
|
|
374
374
|
}
|
|
@@ -394,10 +394,11 @@ class ke {
|
|
|
394
394
|
}
|
|
395
395
|
async getOriginalPosition(t, e, i) {
|
|
396
396
|
let n = { source: t, line: e, column: i, name: null };
|
|
397
|
+
if (t.includes("://")) return { originalPos: n };
|
|
397
398
|
const o = t + ".map";
|
|
398
399
|
try {
|
|
399
|
-
const d = JSON.parse(
|
|
400
|
-
let s = (await new
|
|
400
|
+
const d = JSON.parse(De(o, "utf-8"));
|
|
401
|
+
let s = (await new Ee.SourceMapConsumer(d)).originalPositionFor({ line: e, column: i });
|
|
401
402
|
s.source && (n = s);
|
|
402
403
|
} catch (d) {
|
|
403
404
|
u().sfDebug && console.error(`Could not read/parse map file at ${o}:`, d);
|
|
@@ -407,8 +408,8 @@ class ke {
|
|
|
407
408
|
captureFirstUserLines(t, e = 10, i = !1) {
|
|
408
409
|
const n = u().sfDebug ? 10 : e, o = Error.stackTraceLimit;
|
|
409
410
|
Error.stackTraceLimit = Math.max(o, n);
|
|
410
|
-
const d = new Error(
|
|
411
|
-
|
|
411
|
+
const d = new Error(X);
|
|
412
|
+
X in Error && Error.captureStackTrace(d, this.captureFirstUserLines);
|
|
412
413
|
const s = d.stack || "";
|
|
413
414
|
Error.stackTraceLimit = o;
|
|
414
415
|
const c = s.split(`
|
|
@@ -421,7 +422,7 @@ class ke {
|
|
|
421
422
|
const { originalPos: f } = await this.getOriginalPosition(g.filePath, g.line, g.column);
|
|
422
423
|
if (f) {
|
|
423
424
|
u().sfDebug && console.log("[RequestInterceptor] First user code line:", f);
|
|
424
|
-
const h = { line: f.line?.toString() ||
|
|
425
|
+
const h = { line: f.line?.toString() || k.UNKNOWN, column: f.column?.toString() || k.NOT_CAPTURED, name: f.name || k.NOT_CAPTURED, entrypoint: f.source, retryWithoutTraceId: i };
|
|
425
426
|
t.doSend(h);
|
|
426
427
|
}
|
|
427
428
|
})() : u().sfDebug && console.error("Could not parse stack line:", l);
|
|
@@ -431,19 +432,19 @@ class ke {
|
|
|
431
432
|
t.set(this.HEADER_LOG_GUARD, "true"), t.set(this.HEADER_PRINT_GUARD, "true"), t.set(this.HEADER_EXCEPTION_GUARD, "true");
|
|
432
433
|
}
|
|
433
434
|
shouldPropagateHeaders(t) {
|
|
434
|
-
return !
|
|
435
|
+
return !he.some((e) => new RegExp(`^${e.replace(/\*/g, ".*")}$`).test(t));
|
|
435
436
|
}
|
|
436
437
|
addTracingHeaders(t, e) {
|
|
437
438
|
const i = new URL(e).hostname, n = this.shouldPropagateHeaders(i);
|
|
438
439
|
return n ? this.addTracingHeader(t, e) : u().sfDebug && console.error(`[RequestInterceptor] Excluded domain: ${i}`), n;
|
|
439
440
|
}
|
|
440
441
|
addTracingHeader(t, e) {
|
|
441
|
-
const i =
|
|
442
|
+
const i = ae();
|
|
442
443
|
if (i) {
|
|
443
|
-
const s =
|
|
444
|
+
const s = ce(i);
|
|
444
445
|
if (s && s.sample_rate === 0) return void (u().sfDebug && console.log(`[RequestInterceptor] Function span tracking disabled (sample_rate=0), skipping tracing header for ${e}`));
|
|
445
446
|
}
|
|
446
|
-
const n = this.contextManager.getOrSetSfTraceId(), o = this.contextManager.getOrSetPageVisitUUID(), d =
|
|
447
|
+
const n = this.contextManager.getOrSetSfTraceId(), o = this.contextManager.getOrSetPageVisitUUID(), d = se();
|
|
447
448
|
t.set(this.HEADER_TRACING, `${n}/${o}/${d}`), u().sfDebug && console.log(`[RequestInterceptor] Added tracing header for ${e}`);
|
|
448
449
|
}
|
|
449
450
|
patchFetch(t, e) {
|
|
@@ -461,20 +462,20 @@ class ke {
|
|
|
461
462
|
let h;
|
|
462
463
|
try {
|
|
463
464
|
let p = !1;
|
|
464
|
-
this.addTracingHeaders(l, c), h = await i(c, f), g &&
|
|
465
|
+
this.addTracingHeaders(l, c), h = await i(c, f), g && K.includes(h.status) ? (h = await i(c, { ...o, headers: l }), p = !0, this.captureFirstUserLines(t, 10, p)) : this.contextManager.addSupportedDomains(a);
|
|
465
466
|
const m = Date.now();
|
|
466
467
|
u().sfDebug && console.log(`[RequestInterceptor] Fetch completed: ${c}, Status: ${h.status}, Duration: ${m - s}ms`);
|
|
467
|
-
const { sessionId: I, pageVisitId: v, requestId: D } = this.extractIdsFromTraceHeader(d), $ = u(), b = { apiKey: $.apiKey, requestId: D, pageVisitId: v, recordingSessionId: I, serviceUuid: $.serviceUUID, timestampStart: s.toString(), timestampEnd: m.toString(), responseCode: h.status, success: !0, error: null, url: c, method: f.method || "GET", retryWithoutTraceId: p, parentSpanId:
|
|
468
|
+
const { sessionId: I, pageVisitId: v, requestId: D } = this.extractIdsFromTraceHeader(d), $ = u(), b = { apiKey: $.apiKey, requestId: D, pageVisitId: v, recordingSessionId: I, serviceUuid: $.serviceUUID, timestampStart: s.toString(), timestampEnd: m.toString(), responseCode: h.status, success: !0, error: null, url: c, method: f.method || "GET", retryWithoutTraceId: p, parentSpanId: q() };
|
|
468
469
|
if ($.captureRequestHeaders) {
|
|
469
470
|
const S = {};
|
|
470
|
-
d.forEach((N,
|
|
471
|
-
S[
|
|
471
|
+
d.forEach((N, w) => {
|
|
472
|
+
S[w] = N;
|
|
472
473
|
}), b.requestHeaders = S;
|
|
473
474
|
}
|
|
474
475
|
if ($.captureResponseHeaders) {
|
|
475
476
|
const S = {};
|
|
476
|
-
h.headers.forEach((N,
|
|
477
|
-
S[
|
|
477
|
+
h.headers.forEach((N, w) => {
|
|
478
|
+
S[w] = N;
|
|
478
479
|
}), b.responseHeaders = S;
|
|
479
480
|
}
|
|
480
481
|
if ($.captureRequestBody && o?.body) try {
|
|
@@ -495,15 +496,15 @@ class ke {
|
|
|
495
496
|
} : u().sfDebug && console.error("[RequestInterceptor] Fetch not available.");
|
|
496
497
|
}
|
|
497
498
|
patchHttp(t, e) {
|
|
498
|
-
if (u().sfDebug && console.log("[RequestInterceptor] Initializing HTTP/HTTPS request patch..."), !
|
|
499
|
-
const i =
|
|
500
|
-
|
|
499
|
+
if (u().sfDebug && console.log("[RequestInterceptor] Initializing HTTP/HTTPS request patch..."), !P || typeof P.request != "function") return void (u().sfDebug && console.log("[RequestInterceptor] HTTP/HTTPS not available."));
|
|
500
|
+
const i = P.request.bind(P), n = P.request.bind(P);
|
|
501
|
+
P.request = function(o, d) {
|
|
501
502
|
let s;
|
|
502
503
|
try {
|
|
503
504
|
if (typeof o == "string") {
|
|
504
505
|
const a = new URL(o);
|
|
505
|
-
s = { protocol: a.protocol ||
|
|
506
|
-
} else o instanceof URL ? s = { protocol: o.protocol ||
|
|
506
|
+
s = { protocol: a.protocol || x, hostname: a.hostname, path: a.pathname + a.search, headers: {} };
|
|
507
|
+
} else o instanceof URL ? s = { protocol: o.protocol || x, hostname: o.hostname, path: o.pathname + o.search, headers: {} } : (s = { ...o }, s.protocol || (s.protocol = x));
|
|
507
508
|
if (s.headers) {
|
|
508
509
|
const a = `${s.protocol}//${s.hostname}`;
|
|
509
510
|
this.addTracingHeaders(s.headers, a), this.captureFirstUserLines(t);
|
|
@@ -514,21 +515,21 @@ class ke {
|
|
|
514
515
|
let c = !1;
|
|
515
516
|
return i(s, (a) => {
|
|
516
517
|
const l = `${s.protocol}//${s.hostname}`;
|
|
517
|
-
if (s.headers && this.shouldPropagateHeaders(new URL(l).hostname) &&
|
|
518
|
+
if (s.headers && this.shouldPropagateHeaders(new URL(l).hostname) && K.includes(a.statusCode || 0)) {
|
|
518
519
|
s.hostname;
|
|
519
520
|
const p = { ...s, headers: { ...s.headers } };
|
|
520
521
|
delete p.headers[this.HEADER_TRACING], i(p, d), c = !0, this.captureFirstUserLines(t, 10, c);
|
|
521
522
|
}
|
|
522
523
|
const { sessionId: g, pageVisitId: f, requestId: h } = this.extractIdsFromTraceHeader(s.headers);
|
|
523
|
-
e.doSend({ apiKey: u().apiKey, requestId: h, pageVisitId: f, recordingSessionId: g, serviceUuid: u().serviceUUID, timestampStart: Date.now().toString(), timestampEnd: Date.now().toString(), responseCode: a.statusCode || 0, success: !!a.statusCode && a.statusCode < 400, error: null, url: l, method: s.method || "GET", retryWithoutTraceId: c, parentSpanId:
|
|
524
|
+
e.doSend({ apiKey: u().apiKey, requestId: h, pageVisitId: f, recordingSessionId: g, serviceUuid: u().serviceUUID, timestampStart: Date.now().toString(), timestampEnd: Date.now().toString(), responseCode: a.statusCode || 0, success: !!a.statusCode && a.statusCode < 400, error: null, url: l, method: s.method || "GET", retryWithoutTraceId: c, parentSpanId: q() }), d?.(a);
|
|
524
525
|
});
|
|
525
|
-
},
|
|
526
|
+
}, P.request = function(o, d) {
|
|
526
527
|
let s;
|
|
527
528
|
try {
|
|
528
529
|
if (typeof o == "string") {
|
|
529
530
|
const a = new URL(o);
|
|
530
|
-
s = { protocol: a.protocol ||
|
|
531
|
-
} else o instanceof URL ? s = { protocol: o.protocol ||
|
|
531
|
+
s = { protocol: a.protocol || G, hostname: a.hostname, path: a.pathname + a.search, headers: {} };
|
|
532
|
+
} else o instanceof URL ? s = { protocol: o.protocol || G, hostname: o.hostname, path: o.pathname + o.search, headers: {} } : (s = { ...o }, s.protocol || (s.protocol = G));
|
|
532
533
|
if (s.headers) {
|
|
533
534
|
const a = `${s.protocol}//${s.hostname}`;
|
|
534
535
|
this.addTracingHeaders(s.headers, a);
|
|
@@ -539,12 +540,12 @@ class ke {
|
|
|
539
540
|
let c = !1;
|
|
540
541
|
return n(s, (a) => {
|
|
541
542
|
const l = `${s.protocol}//${s.hostname}`;
|
|
542
|
-
if (s.headers && this.shouldPropagateHeaders(new URL(l).hostname) &&
|
|
543
|
+
if (s.headers && this.shouldPropagateHeaders(new URL(l).hostname) && K.includes(a.statusCode || 0)) {
|
|
543
544
|
const p = { ...s, headers: { ...s.headers } };
|
|
544
545
|
delete p.headers[this.HEADER_TRACING], n(p, d), c = !0, this.captureFirstUserLines(t, 10, c);
|
|
545
546
|
}
|
|
546
547
|
const { sessionId: g, pageVisitId: f, requestId: h } = this.extractIdsFromTraceHeader(s.headers);
|
|
547
|
-
e.doSend({ apiKey: u().apiKey, requestId: h, pageVisitId: f, recordingSessionId: g, serviceUuid: u().serviceUUID, timestampStart: Date.now().toString(), timestampEnd: Date.now().toString(), responseCode: a.statusCode || 0, success: !!a.statusCode && a.statusCode < 400, error: null, url: l, method: s.method || "GET", retryWithoutTraceId: c, parentSpanId:
|
|
548
|
+
e.doSend({ apiKey: u().apiKey, requestId: h, pageVisitId: f, recordingSessionId: g, serviceUuid: u().serviceUUID, timestampStart: Date.now().toString(), timestampEnd: Date.now().toString(), responseCode: a.statusCode || 0, success: !!a.statusCode && a.statusCode < 400, error: null, url: l, method: s.method || "GET", retryWithoutTraceId: c, parentSpanId: q() }), d?.(a);
|
|
548
549
|
});
|
|
549
550
|
}, u().sfDebug && console.log("✅ HTTP and HTTPS request methods patched globally.");
|
|
550
551
|
}
|
|
@@ -558,7 +559,7 @@ class ke {
|
|
|
558
559
|
return [...this.contextManager.getExcludedDomains()];
|
|
559
560
|
}
|
|
560
561
|
}
|
|
561
|
-
class
|
|
562
|
+
class He extends V {
|
|
562
563
|
constructor() {
|
|
563
564
|
super(), this.setOperationName("UpdateServiceDetails");
|
|
564
565
|
}
|
|
@@ -606,7 +607,7 @@ class qe extends Q {
|
|
|
606
607
|
E(this.endpoint, this.operationName, t, i);
|
|
607
608
|
}
|
|
608
609
|
}
|
|
609
|
-
class
|
|
610
|
+
class Me {
|
|
610
611
|
constructor(t = [process.cwd()], e = !1) {
|
|
611
612
|
y(this, "rootPaths");
|
|
612
613
|
y(this, "fileConfigs", /* @__PURE__ */ new Map());
|
|
@@ -620,26 +621,26 @@ class He {
|
|
|
620
621
|
async loadAllConfigs() {
|
|
621
622
|
this.debug && console.log("[FuncSpan ConfigLoader] Scanning for .sailfish files in:", this.rootPaths);
|
|
622
623
|
const t = [];
|
|
623
|
-
for (const e of this.rootPaths)
|
|
624
|
+
for (const e of this.rootPaths) M.existsSync(e) ? await this._walkDirectory(e, t) : this.debug && console.log(`[FuncSpan ConfigLoader] Root path does not exist: ${e}`);
|
|
624
625
|
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");
|
|
625
626
|
for (const e of t) await this._loadConfigFile(e);
|
|
626
627
|
await this._resolveInheritance(), this.debug && console.log(`[FuncSpan ConfigLoader] Loaded ${this.fileConfigs.size} file configs, ${this.functionConfigs.size} function configs`);
|
|
627
628
|
}
|
|
628
629
|
getConfig(t, e) {
|
|
629
|
-
const i = this.hasSailfishFiles ?
|
|
630
|
+
const i = this.hasSailfishFiles ? Se() : de(), n = this._getDirectoryConfig(t), o = F.normalize(t), d = this.fileConfigs.get(o) || {};
|
|
630
631
|
let s = {};
|
|
631
632
|
if (e) {
|
|
632
633
|
const c = this.functionConfigs.get(o);
|
|
633
634
|
c && (s = c.get(e) || {});
|
|
634
635
|
}
|
|
635
|
-
return
|
|
636
|
+
return U(i, n, d, s);
|
|
636
637
|
}
|
|
637
638
|
hasRuntimeMode() {
|
|
638
639
|
return this.runtimeModeEnabled;
|
|
639
640
|
}
|
|
640
641
|
async _walkDirectory(t, e) {
|
|
641
642
|
try {
|
|
642
|
-
const i =
|
|
643
|
+
const i = M.readdirSync(t, { withFileTypes: !0 });
|
|
643
644
|
for (const n of i) {
|
|
644
645
|
const o = F.join(t, n.name);
|
|
645
646
|
n.isFile() && n.name === ".sailfish" ? e.push(o) : n.name === "node_modules" || n.isDirectory() && n.name.startsWith(".") && n.name !== ".sailfish" || n.isDirectory() && await this._walkDirectory(o, e);
|
|
@@ -650,7 +651,7 @@ class He {
|
|
|
650
651
|
}
|
|
651
652
|
async _loadConfigFile(t) {
|
|
652
653
|
try {
|
|
653
|
-
const e =
|
|
654
|
+
const e = M.readFileSync(t, "utf-8"), i = F.dirname(t);
|
|
654
655
|
let n = null;
|
|
655
656
|
try {
|
|
656
657
|
n = JSON.parse(e);
|
|
@@ -673,10 +674,10 @@ class He {
|
|
|
673
674
|
}
|
|
674
675
|
async _expandFileGlobs(t, e, i) {
|
|
675
676
|
for (const [n, o] of Object.entries(e)) try {
|
|
676
|
-
const d = F.join(t, n), s = await
|
|
677
|
+
const d = F.join(t, n), s = await we(d, { absolute: !0, nodir: !0, ignore: ["**/node_modules/**", "**/.git/**"] });
|
|
677
678
|
this.debug && console.log(`[FuncSpan ConfigLoader] Pattern '${n}' matched ${s.length} files`);
|
|
678
679
|
for (const c of s) {
|
|
679
|
-
const a = F.normalize(c), l =
|
|
680
|
+
const a = F.normalize(c), l = U(i, o);
|
|
680
681
|
this.fileConfigs.set(a, l), this.debug && s.length <= 5 && console.log(`[FuncSpan ConfigLoader] - ${c}`);
|
|
681
682
|
}
|
|
682
683
|
} catch (d) {
|
|
@@ -692,7 +693,7 @@ class He {
|
|
|
692
693
|
}
|
|
693
694
|
const [s, c] = d, a = F.normalize(F.join(t, s));
|
|
694
695
|
this.functionConfigs.has(a) || this.functionConfigs.set(a, /* @__PURE__ */ new Map());
|
|
695
|
-
const l = this.functionConfigs.get(a), g =
|
|
696
|
+
const l = this.functionConfigs.get(a), g = U(i, o);
|
|
696
697
|
l.set(c, g), this.debug && console.log(`[FuncSpan ConfigLoader] Function config: ${a}::${c}`);
|
|
697
698
|
}
|
|
698
699
|
}
|
|
@@ -705,30 +706,37 @@ class He {
|
|
|
705
706
|
const n = this.directoryConfigs.get(e);
|
|
706
707
|
n && i.unshift(n), e = F.dirname(e);
|
|
707
708
|
}
|
|
708
|
-
return i.reduce((n, o) =>
|
|
709
|
+
return i.reduce((n, o) => U(n, o), {});
|
|
709
710
|
}
|
|
710
711
|
}
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
712
|
+
const le = "__sf_globalConfigLoader";
|
|
713
|
+
function pe() {
|
|
714
|
+
return globalThis[le] ?? null;
|
|
714
715
|
}
|
|
715
|
-
function xe(r, t) {
|
|
716
|
-
|
|
716
|
+
async function xe(r, t) {
|
|
717
|
+
const e = new Me(r, t);
|
|
718
|
+
(function(i) {
|
|
719
|
+
globalThis[le] = i;
|
|
720
|
+
})(e), await e.loadAllConfigs();
|
|
717
721
|
}
|
|
718
|
-
function Ge() {
|
|
719
|
-
|
|
722
|
+
function Ge(r, t) {
|
|
723
|
+
const e = pe();
|
|
724
|
+
return e ? e.getConfig(r, t) : (process.env.SF_DEBUG === "true" && console.log("[FuncSpan ConfigLoader] Config loader not initialized, using default config (disabled)"), de());
|
|
720
725
|
}
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
726
|
+
function Ke() {
|
|
727
|
+
return pe() !== null;
|
|
728
|
+
}
|
|
729
|
+
const We = ["readFile", "writeFile", "appendFile", "readdir", "stat", "lstat", "fstat", "access", "open", "close", "read", "write", "chmod", "mkdir", "rmdir", "unlink", "rename"], Z = ["lookup", "resolve", "resolve4", "resolve6", "resolveAny", "resolveMx", "resolveNs", "resolveTxt", "reverse"], Be = ["pbkdf2", "randomBytes", "scrypt", "generateKeyPair"], ze = ["gzip", "gunzip", "deflate", "inflate", "deflateRaw", "inflateRaw", "brotliCompress", "brotliDecompress"];
|
|
730
|
+
let ee = !1;
|
|
731
|
+
function Je(r) {
|
|
724
732
|
if (typeof r != "string") return !1;
|
|
725
733
|
const t = process.env.SF_FUNCSPAN_JSONL_FILE;
|
|
726
734
|
if (t && r.includes(t)) return !0;
|
|
727
735
|
const e = process.env.SF_WORKER_POOL_JSONL_FILE;
|
|
728
736
|
return !(!e || !r.includes(e));
|
|
729
737
|
}
|
|
730
|
-
let
|
|
731
|
-
function
|
|
738
|
+
let te = !1;
|
|
739
|
+
function ne(r) {
|
|
732
740
|
if (typeof r != "string") return !1;
|
|
733
741
|
if (r === "localhost" || r === "127.0.0.1" || r === "::1") return !0;
|
|
734
742
|
try {
|
|
@@ -739,8 +747,8 @@ function re(r) {
|
|
|
739
747
|
}
|
|
740
748
|
return !1;
|
|
741
749
|
}
|
|
742
|
-
function
|
|
743
|
-
if (!
|
|
750
|
+
function je() {
|
|
751
|
+
if (!te) try {
|
|
744
752
|
let r;
|
|
745
753
|
if (typeof require > "u") return void (process.env.SF_DEBUG === "true" && console.log("[WorkerPool] Skipping dns patching in pure ESM environment (require unavailable)"));
|
|
746
754
|
try {
|
|
@@ -750,88 +758,88 @@ function Je() {
|
|
|
750
758
|
}
|
|
751
759
|
if (r.__sf_worker_pool_patched__) return;
|
|
752
760
|
Object.defineProperty(r, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
753
|
-
for (const t of
|
|
761
|
+
for (const t of Z) if (typeof r[t] == "function") {
|
|
754
762
|
const e = r[t];
|
|
755
763
|
r[t] = function(...i) {
|
|
756
|
-
return
|
|
764
|
+
return ne(i[0]) ? e.apply(this, i) : typeof i[i.length - 1] == "function" ? A("dns", t, e, i, this) : e.apply(this, i);
|
|
757
765
|
}, Object.defineProperty(r[t], "name", { value: t, writable: !1 });
|
|
758
766
|
}
|
|
759
767
|
(function(t) {
|
|
760
768
|
if (!t.promises) return void (process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns.promises not available, skipping"));
|
|
761
769
|
if (!t.promises.__sf_worker_pool_patched__) {
|
|
762
770
|
Object.defineProperty(t.promises, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
763
|
-
for (const e of
|
|
771
|
+
for (const e of Z) if (typeof t.promises[e] == "function") {
|
|
764
772
|
const i = t.promises[e];
|
|
765
773
|
t.promises[e] = function(...n) {
|
|
766
|
-
return
|
|
774
|
+
return ne(n[0]) ? i.apply(this, n) : Ie("dns", e, i, n, this);
|
|
767
775
|
}, Object.defineProperty(t.promises[e], "name", { value: e, writable: !1 });
|
|
768
776
|
}
|
|
769
777
|
process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns.promises module patched successfully");
|
|
770
778
|
}
|
|
771
|
-
})(r),
|
|
779
|
+
})(r), te = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns module patched successfully");
|
|
772
780
|
} catch (r) {
|
|
773
781
|
console.error("[WorkerPool] Error patching dns module:", r);
|
|
774
782
|
}
|
|
775
783
|
}
|
|
776
|
-
let
|
|
777
|
-
function
|
|
778
|
-
if (
|
|
784
|
+
let re = !1, ie = !1, z = !1;
|
|
785
|
+
function Ve() {
|
|
786
|
+
if (z) return;
|
|
779
787
|
const r = process.env.SF_DEBUG === "true";
|
|
780
|
-
r && console.log("[WorkerPool] Initializing worker pool patching..."),
|
|
781
|
-
if (!
|
|
788
|
+
r && console.log("[WorkerPool] Initializing worker pool patching..."), R("fs") && (r && console.log("[WorkerPool] Patching fs module..."), (function() {
|
|
789
|
+
if (!ee) try {
|
|
782
790
|
const t = require("node:fs");
|
|
783
791
|
if (t.__sf_worker_pool_patched__) return;
|
|
784
792
|
Object.defineProperty(t, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
785
|
-
for (const e of
|
|
793
|
+
for (const e of We) if (typeof t[e] == "function") {
|
|
786
794
|
const i = t[e];
|
|
787
795
|
t[e] = function(...n) {
|
|
788
|
-
return
|
|
796
|
+
return Je(n[0]) ? i.apply(this, n) : typeof n[n.length - 1] == "function" ? A("fs", e, i, n, this) : i.apply(this, n);
|
|
789
797
|
}, Object.defineProperty(t[e], "name", { value: e, writable: !1 });
|
|
790
798
|
}
|
|
791
|
-
|
|
799
|
+
ee = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] fs module patched successfully");
|
|
792
800
|
} catch (t) {
|
|
793
801
|
console.error("[WorkerPool] Error patching fs module:", t);
|
|
794
802
|
}
|
|
795
|
-
})()),
|
|
796
|
-
if (!
|
|
803
|
+
})()), R("dns") && (r && console.log("[WorkerPool] Patching dns module..."), je()), R("crypto") && (r && console.log("[WorkerPool] Patching crypto module..."), (function() {
|
|
804
|
+
if (!re) try {
|
|
797
805
|
const t = require("node:crypto");
|
|
798
806
|
if (t.__sf_worker_pool_patched__) return;
|
|
799
807
|
Object.defineProperty(t, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
800
|
-
for (const e of
|
|
808
|
+
for (const e of Be) if (typeof t[e] == "function") {
|
|
801
809
|
const i = t[e];
|
|
802
810
|
t[e] = function(...n) {
|
|
803
|
-
return typeof n[n.length - 1] == "function" ?
|
|
811
|
+
return typeof n[n.length - 1] == "function" ? A("crypto", e, i, n, this) : i.apply(this, n);
|
|
804
812
|
}, Object.defineProperty(t[e], "name", { value: e, writable: !1 });
|
|
805
813
|
}
|
|
806
|
-
|
|
814
|
+
re = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] crypto module patched successfully");
|
|
807
815
|
} catch (t) {
|
|
808
816
|
console.error("[WorkerPool] Error patching crypto module:", t);
|
|
809
817
|
}
|
|
810
|
-
})()),
|
|
811
|
-
if (!
|
|
818
|
+
})()), R("zlib") && (r && console.log("[WorkerPool] Patching zlib module..."), (function() {
|
|
819
|
+
if (!ie) try {
|
|
812
820
|
const t = require("node:zlib");
|
|
813
821
|
if (t.__sf_worker_pool_patched__) return;
|
|
814
822
|
Object.defineProperty(t, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
815
|
-
for (const e of
|
|
823
|
+
for (const e of ze) if (typeof t[e] == "function") {
|
|
816
824
|
const i = t[e];
|
|
817
825
|
t[e] = function(...n) {
|
|
818
|
-
return typeof n[n.length - 1] == "function" ?
|
|
826
|
+
return typeof n[n.length - 1] == "function" ? A("zlib", e, i, n, this) : i.apply(this, n);
|
|
819
827
|
}, Object.defineProperty(t[e], "name", { value: e, writable: !1 });
|
|
820
828
|
}
|
|
821
|
-
|
|
829
|
+
ie = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] zlib module patched successfully");
|
|
822
830
|
} catch (t) {
|
|
823
831
|
console.error("[WorkerPool] Error patching zlib module:", t);
|
|
824
832
|
}
|
|
825
|
-
})()),
|
|
833
|
+
})()), z = !0, r && console.log("[WorkerPool] Worker pool patching initialized");
|
|
826
834
|
}
|
|
827
|
-
function
|
|
828
|
-
return
|
|
835
|
+
function Qe() {
|
|
836
|
+
return z;
|
|
829
837
|
}
|
|
830
|
-
let
|
|
831
|
-
function
|
|
832
|
-
if (
|
|
833
|
-
else if (!
|
|
834
|
-
|
|
838
|
+
let J = !1, W = !1;
|
|
839
|
+
function ot(r) {
|
|
840
|
+
if (W) console.warn("[setupInterceptors] ⚠️ Recursive call detected and blocked!");
|
|
841
|
+
else if (!J) {
|
|
842
|
+
W = !0;
|
|
835
843
|
try {
|
|
836
844
|
let t, e;
|
|
837
845
|
const i = new Error().stack;
|
|
@@ -844,52 +852,52 @@ function st(r) {
|
|
|
844
852
|
const s = `The required API Key is not provided: ${JSON.stringify(r)}`;
|
|
845
853
|
console.error(s);
|
|
846
854
|
}
|
|
847
|
-
const { config: n } =
|
|
855
|
+
const { config: n } = me(r);
|
|
848
856
|
if (t && (n.setupInterceptorsFile = t), e && (n.setupInterceptorsLine = e), n.sfDebug && console.log("Updated configuration after applying options:", n), !n.apiKey || !n.apiGraphqlEndpoint) {
|
|
849
857
|
const s = `The required config is not provided: ${JSON.stringify(n)}`;
|
|
850
858
|
throw console.error(s), new Error(s);
|
|
851
859
|
}
|
|
852
|
-
|
|
860
|
+
Ke() || xe(void 0, n.sfDebug).catch((s) => {
|
|
853
861
|
n.sfDebug && console.error("[FuncSpan] Failed to initialize config loader:", s);
|
|
854
|
-
}), process.env.SF_WORKER_POOL_DISABLED === "true" ? n.sfDebug && console.log("[setupInterceptors] Worker pool patching DISABLED (SF_WORKER_POOL_DISABLED=true)") :
|
|
855
|
-
const o = new
|
|
856
|
-
o.setServiceUUID(n.serviceUUID),
|
|
857
|
-
const c = new
|
|
858
|
-
new
|
|
859
|
-
const a = new
|
|
862
|
+
}), process.env.SF_WORKER_POOL_DISABLED === "true" ? n.sfDebug && console.log("[setupInterceptors] Worker pool patching DISABLED (SF_WORKER_POOL_DISABLED=true)") : Qe() || (Ve(), n.sfDebug && console.log("[setupInterceptors] Worker pool patching initialized (DNS tracking enabled)"));
|
|
863
|
+
const o = new V();
|
|
864
|
+
o.setServiceUUID(n.serviceUUID), be(o), (function(s = []) {
|
|
865
|
+
const c = new qe(s);
|
|
866
|
+
new Le().doSend(c.getExcludedDomains());
|
|
867
|
+
const a = new Ae(), l = new ke();
|
|
860
868
|
c.patchFetch(a, l), c.patchHttp(a, l);
|
|
861
869
|
})(n.domainsToNotPropagateHeadersTo);
|
|
862
|
-
const d = new
|
|
863
|
-
d.setServiceUUID(n.serviceUUID),
|
|
870
|
+
const d = new Ue();
|
|
871
|
+
d.setServiceUUID(n.serviceUUID), Ne(d), Oe(), new He().send(), J = !0, n.sfDebug && console.log("[setupInterceptors] ✅ Initialization complete");
|
|
864
872
|
} finally {
|
|
865
|
-
|
|
873
|
+
W = !1;
|
|
866
874
|
}
|
|
867
875
|
}
|
|
868
876
|
}
|
|
869
|
-
function
|
|
870
|
-
return
|
|
877
|
+
function at() {
|
|
878
|
+
return J;
|
|
871
879
|
}
|
|
872
|
-
function
|
|
880
|
+
function ct(r, t, e, i = !1) {
|
|
873
881
|
const n = u();
|
|
874
|
-
new
|
|
882
|
+
new ue(n.apiKey).identify(r, t, e, i);
|
|
875
883
|
}
|
|
876
|
-
function
|
|
884
|
+
function dt(r, t = {}, e, i = !1) {
|
|
877
885
|
const n = u();
|
|
878
|
-
new
|
|
886
|
+
new ue(n.apiKey).addOrUpdateMetadata(r, t, e, i);
|
|
879
887
|
}
|
|
880
|
-
let
|
|
881
|
-
function
|
|
888
|
+
let B = null;
|
|
889
|
+
function ut(r, t, e, i) {
|
|
882
890
|
const n = function(...o) {
|
|
883
|
-
const d =
|
|
891
|
+
const d = oe(), s = d?.sfDebug || !1;
|
|
884
892
|
s && console.log(`[FuncSpan] captureFunctionSpan wrapper called for ${e}::${t}`);
|
|
885
893
|
const c = (function(m, I) {
|
|
886
|
-
const v =
|
|
894
|
+
const v = ae();
|
|
887
895
|
if (v) {
|
|
888
|
-
const D =
|
|
896
|
+
const D = ce(v);
|
|
889
897
|
if (D) return process.env.SF_DEBUG === "true" && console.log(`[FuncSpan] Using HTTP header override for ${m}::${I}`), D;
|
|
890
898
|
}
|
|
891
899
|
try {
|
|
892
|
-
return
|
|
900
|
+
return Ge(m, I);
|
|
893
901
|
} catch {
|
|
894
902
|
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 };
|
|
895
903
|
}
|
|
@@ -897,37 +905,37 @@ function dt(r, t, e, i) {
|
|
|
897
905
|
if (s && console.log(`[FuncSpan] Config for ${e}::${t}:`, c), c.enable_sampling && c.sample_rate < 1 && Math.random() > c.sample_rate) return s && console.log(`[FuncSpan] Skipping ${t} due to sampling`), r.apply(this, o);
|
|
898
906
|
if (c.sample_rate === 0) return s && console.log(`[FuncSpan] Skipping ${t} - sample_rate is 0.0`), r.apply(this, o);
|
|
899
907
|
s && console.log(`[FuncSpan] Capturing function span for ${t}`);
|
|
900
|
-
const a =
|
|
908
|
+
const a = j.getInstance(), l = a.getCurrentFunctionSpanId(), g = se();
|
|
901
909
|
a.setCurrentFunctionSpanId(g);
|
|
902
910
|
const f = process.hrtime.bigint(), h = Date.now();
|
|
903
911
|
let p = null;
|
|
904
912
|
c.capture_arguments && (p = {}, i.paramNames.forEach((m, I) => {
|
|
905
913
|
I < o.length && (p[m] = o[I]);
|
|
906
|
-
}), p && c.arg_limit_mb > 0 && (p =
|
|
914
|
+
}), p && c.arg_limit_mb > 0 && (p = H(p, c.arg_limit_mb)));
|
|
907
915
|
try {
|
|
908
916
|
const m = r.apply(this, o);
|
|
909
917
|
if (m && typeof m.then == "function") return l ? a.setCurrentFunctionSpanId(l) : a.clearCurrentFunctionSpanId(), m.then((b) => {
|
|
910
|
-
const S = process.hrtime.bigint(), N = Date.now(),
|
|
911
|
-
let
|
|
912
|
-
return c.capture_return_value && c.return_limit_mb > 0 && (
|
|
918
|
+
const S = process.hrtime.bigint(), N = Date.now(), w = Number(S - f);
|
|
919
|
+
let Q = null;
|
|
920
|
+
return c.capture_return_value && c.return_limit_mb > 0 && (Q = H(b, c.return_limit_mb)), L({ functionName: t, filePath: e, metadata: i, args: p, result: Q, error: null, duration: N - h, durationNs: w, startTimeNs: f.toString(), async: !0, spanId: g, parentSpanId: l, pid: process.pid, threadId: O }), b;
|
|
913
921
|
}, (b) => {
|
|
914
|
-
const S = process.hrtime.bigint(), N = Date.now(),
|
|
915
|
-
throw
|
|
922
|
+
const S = process.hrtime.bigint(), N = Date.now(), w = Number(S - f);
|
|
923
|
+
throw L({ functionName: t, filePath: e, metadata: i, args: p, result: null, error: b?.message || String(b), duration: N - h, durationNs: w, startTimeNs: f.toString(), async: !0, spanId: g, parentSpanId: l, pid: process.pid, threadId: O }), b;
|
|
916
924
|
});
|
|
917
925
|
const I = process.hrtime.bigint(), v = Date.now(), D = Number(I - f);
|
|
918
926
|
let $ = null;
|
|
919
|
-
return c.capture_return_value && c.return_limit_mb > 0 && ($ =
|
|
927
|
+
return c.capture_return_value && c.return_limit_mb > 0 && ($ = H(m, c.return_limit_mb)), L({ functionName: t, filePath: e, metadata: i, args: p, result: $, error: null, duration: v - h, durationNs: D, startTimeNs: f.toString(), async: !1, spanId: g, parentSpanId: l, pid: process.pid, threadId: O }), l ? a.setCurrentFunctionSpanId(l) : a.clearCurrentFunctionSpanId(), m;
|
|
920
928
|
} catch (m) {
|
|
921
929
|
const I = process.hrtime.bigint(), v = Date.now(), D = Number(I - f);
|
|
922
|
-
throw
|
|
930
|
+
throw L({ functionName: t, filePath: e, metadata: i, args: p, result: null, error: m?.message || String(m), duration: v - h, durationNs: D, startTimeNs: f.toString(), async: !1, spanId: g, parentSpanId: l, pid: process.pid, threadId: O }), l ? a.setCurrentFunctionSpanId(l) : a.clearCurrentFunctionSpanId(), m;
|
|
923
931
|
}
|
|
924
932
|
};
|
|
925
933
|
Object.defineProperty(n, "name", { value: t, writable: !1 });
|
|
926
934
|
for (const o in r) r.hasOwnProperty(o) && (n[o] = r[o]);
|
|
927
935
|
return n;
|
|
928
936
|
}
|
|
929
|
-
function
|
|
930
|
-
const t =
|
|
937
|
+
function L(r) {
|
|
938
|
+
const t = oe(), e = t?.sfDebug || !1;
|
|
931
939
|
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 });
|
|
932
940
|
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 };
|
|
933
941
|
process.env.SF_FUNCSPAN_CONSOLE_OUTPUT === "true" && console.log(`
|
|
@@ -936,44 +944,44 @@ function A(r) {
|
|
|
936
944
|
if (n) try {
|
|
937
945
|
const o = n === "true" || n === "1" ? "funcspans.jsonl" : n, d = Date.now(), s = process.hrtime.bigint(), c = BigInt(r.startTimeNs), a = Number(s - c) / 1e6, l = new Date(d - a).toISOString(), g = JSON.stringify({ timestamp: l, functionName: r.functionName, filePath: r.filePath, line: r.metadata.line, column: r.metadata.column, duration: r.duration, durationNs: r.durationNs, startTimeNs: r.startTimeNs, arguments: r.args, returnValue: r.error ? { error: String(r.error) } : r.result, spanId: r.spanId, parentSpanId: r.parentSpanId, async: r.async, pid: r.pid, threadId: r.threadId }) + `
|
|
938
946
|
`;
|
|
939
|
-
|
|
947
|
+
Pe(o, g, "utf-8");
|
|
940
948
|
} catch (o) {
|
|
941
949
|
console.error("[FuncSpan] Error writing to JSONL file:", o);
|
|
942
950
|
}
|
|
943
951
|
if (e && console.log("[FuncSpan] Sending function span to transmitter:", i), process.env.SF_FUNCSPAN_SKIP_BACKEND !== "true") try {
|
|
944
|
-
(
|
|
952
|
+
(B || (B = new ve()), B).send([i]), e && console.log("[FuncSpan] Function span sent successfully");
|
|
945
953
|
} catch (o) {
|
|
946
954
|
e && console.error("[FuncSpan] Error sending function span:", o);
|
|
947
955
|
}
|
|
948
956
|
}
|
|
949
|
-
function
|
|
957
|
+
function lt(r) {
|
|
950
958
|
return !!r.includes("captureFunctionSpan(") || !!r.includes("@sailfish-ai/sf-veritas") || !(!r.includes("/* @sailfish-instrumented */") && !r.includes("// @sailfish-instrumented"));
|
|
951
959
|
}
|
|
952
960
|
export {
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
961
|
+
j as ContextManager,
|
|
962
|
+
dt as addOrUpdateMetadata,
|
|
963
|
+
ut as captureFunctionSpan,
|
|
964
|
+
mt as clearFuncspanOverride,
|
|
965
|
+
q as getCurrentFunctionSpanId,
|
|
966
|
+
de as getDefaultConfig,
|
|
967
|
+
Se as getEnvConfig,
|
|
968
|
+
ae as getFuncspanOverride,
|
|
969
|
+
Ge as getGlobalConfig,
|
|
970
|
+
ct as identify,
|
|
971
|
+
xe as initializeConfigLoader,
|
|
972
|
+
Ve as initializeWorkerPoolPatching,
|
|
973
|
+
lt as isAlreadyInstrumented,
|
|
974
|
+
Ke as isConfigLoaderInitialized,
|
|
975
|
+
It as isProductionEnvironment,
|
|
976
|
+
vt as isRuntimeModeEnabled,
|
|
977
|
+
at as isSetupInterceptorsInitialized,
|
|
978
|
+
Qe as isWorkerPoolInitialized,
|
|
979
|
+
ce as parseHeaderOverride,
|
|
980
|
+
ft as runWithContext,
|
|
981
|
+
yt as setFuncspanOverride,
|
|
982
|
+
bt as setSkipTypeScriptPlugin,
|
|
983
|
+
ot as setupInterceptors,
|
|
984
|
+
$t as shouldEnableRuntimeHooks,
|
|
985
|
+
Nt as transformFunctionSpans,
|
|
986
|
+
Ft as transformFunctionSpansSync
|
|
979
987
|
};
|