@sailfish-ai/sf-veritas 0.2.20 → 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/contextManager-0D8uHQ1_.cjs +1 -0
- package/dist/{contextManager-Dw7Yot7r.js → contextManager-RxrMXs5c.js} +106 -83
- 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 +25 -13
- package/dist/sf-veritas.mjs +453 -393
- 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/frameworkDetection.d.ts +18 -0
- 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/setupConfig.d.ts +3 -0
- 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-Dm4Reseo.js → workerPoolSpanCapture-BjdZn3LE.js} +222 -168
- package/package.json +1 -1
- package/dist/contextManager-DQMeQfS_.cjs +0 -1
- package/dist/runtimeConfig-Bfqf33tO.js +0 -444
- package/dist/runtimeConfig-DmD4lUhG.cjs +0 -9
- package/dist/workerPoolSpanCapture-CAM2z9Jx.cjs +0 -83
package/dist/sf-veritas.mjs
CHANGED
|
@@ -1,30 +1,32 @@
|
|
|
1
1
|
var he = Object.defineProperty;
|
|
2
2
|
var me = (r, t, e) => t in r ? he(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
|
|
3
3
|
var y = (r, t, e) => me(r, typeof t != "symbol" ? t + "" : t, e);
|
|
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
|
|
4
|
+
import { g as f, C as V, D as ye, v as K, b as H, c as Se, d as ve, a as de } from "./contextManager-RxrMXs5c.js";
|
|
5
|
+
import { r as $t } from "./contextManager-RxrMXs5c.js";
|
|
6
|
+
import { B as R, n as w, f as Ie, g as W, p as j, a as le, b as $e, m as C, c as A, i as Y, d as _e, e as k, r as be, t as M, F as Fe } from "./workerPoolSpanCapture-BjdZn3LE.js";
|
|
7
|
+
import { h as bt, s as Ft } from "./workerPoolSpanCapture-BjdZn3LE.js";
|
|
8
|
+
import { a as Ne, C as De, i as b, b as we, c as ue, d as Pe, e as Ee } from "./runtimeConfig-BZ61efqE.js";
|
|
9
|
+
import { f as Dt, g as wt, s as Pt } from "./runtimeConfig-BZ61efqE.js";
|
|
10
|
+
import { createRequire as Re } from "node:module";
|
|
11
11
|
import * as Te from "fs";
|
|
12
|
-
import { readFileSync as Ce, appendFileSync as
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import {
|
|
19
|
-
|
|
12
|
+
import { readFileSync as Ce, appendFileSync as ke } from "fs";
|
|
13
|
+
import E from "http";
|
|
14
|
+
import U from "https";
|
|
15
|
+
import { s as Ue } from "./source-map-Cr6YkjTd.js";
|
|
16
|
+
import * as Z from "fs/promises";
|
|
17
|
+
import * as D from "path";
|
|
18
|
+
import { glob as Oe } from "glob";
|
|
19
|
+
import { threadId as O } from "worker_threads";
|
|
20
|
+
import { s as Rt, t as Tt, a as Ct } from "./funcSpanTransformer-S_WeAt_m.js";
|
|
21
|
+
class T extends R {
|
|
20
22
|
constructor() {
|
|
21
23
|
super(), this.setOperationName("IdentifyServiceDetails");
|
|
22
24
|
}
|
|
23
25
|
async doSend(t) {
|
|
24
|
-
if (!
|
|
26
|
+
if (!f().serviceIdentificationReceived) try {
|
|
25
27
|
this.send();
|
|
26
28
|
} catch (e) {
|
|
27
|
-
|
|
29
|
+
f().sfDebug && console.error(" Error during service identification:", e);
|
|
28
30
|
}
|
|
29
31
|
}
|
|
30
32
|
async send() {
|
|
@@ -43,6 +45,9 @@ class C extends T {
|
|
|
43
45
|
$gitRepo: String,
|
|
44
46
|
$gitProvider: String,
|
|
45
47
|
$serviceDisplayName: String,
|
|
48
|
+
$framework: String,
|
|
49
|
+
$additionalFrameworks: JSON,
|
|
50
|
+
$serviceRole: String,
|
|
46
51
|
) {
|
|
47
52
|
${this.queryName}(
|
|
48
53
|
apiKey: $apiKey,
|
|
@@ -58,33 +63,42 @@ class C extends T {
|
|
|
58
63
|
gitRepo: $gitRepo,
|
|
59
64
|
gitProvider: $gitProvider,
|
|
60
65
|
serviceDisplayName: $serviceDisplayName,
|
|
66
|
+
framework: $framework,
|
|
67
|
+
additionalFrameworks: $additionalFrameworks,
|
|
68
|
+
serviceRole: $serviceRole,
|
|
61
69
|
)
|
|
62
70
|
}
|
|
63
|
-
`, e = this.getVariables({ serviceIdentifier:
|
|
64
|
-
|
|
71
|
+
`, e = f(), 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
|
+
w(this.endpoint, this.operationName, t, i);
|
|
65
73
|
}
|
|
66
74
|
}
|
|
67
|
-
class
|
|
75
|
+
class Le extends R {
|
|
68
76
|
constructor() {
|
|
69
77
|
super();
|
|
70
|
-
y(this, "serviceIdentifier", new
|
|
78
|
+
y(this, "serviceIdentifier", new T());
|
|
79
|
+
y(this, "identifyStarted", !1);
|
|
71
80
|
this.setOperationName("CollectMetadata");
|
|
72
81
|
}
|
|
73
|
-
|
|
74
|
-
this.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
startBackgroundIdentify() {
|
|
83
|
+
if (this.identifyStarted) return;
|
|
84
|
+
this.identifyStarted = !0, this.serviceIdentifier.doSend({});
|
|
85
|
+
const e = setInterval(() => {
|
|
86
|
+
f().serviceIdentificationReceived ? clearInterval(e) : this.serviceIdentifier.doSend({});
|
|
87
|
+
}, 5e3);
|
|
88
|
+
e && typeof e == "object" && "unref" in e && e.unref();
|
|
89
|
+
}
|
|
90
|
+
async doSend(e, i, n, s) {
|
|
91
|
+
this.startBackgroundIdentify(), this.send(e, i, n, s);
|
|
92
|
+
}
|
|
93
|
+
async send(e, i, n, s) {
|
|
94
|
+
if (!i && !s) throw new Error('Must pass in either traits or traits_json to "add_or_update_traits"');
|
|
95
|
+
let l = [];
|
|
96
|
+
if (!s) {
|
|
97
|
+
const o = Ne(i);
|
|
98
|
+
s = o.traitsJson, l = o.excludedFields;
|
|
85
99
|
}
|
|
86
|
-
const
|
|
87
|
-
|
|
100
|
+
const a = this.getVariables({ userId: e, traitsJson: s, excludedFields: l, override: n, library: f().packageLibraryType, version: f().version });
|
|
101
|
+
w(this.endpoint, this.operationName, this.getQuery(), a);
|
|
88
102
|
}
|
|
89
103
|
getQuery() {
|
|
90
104
|
return `
|
|
@@ -97,33 +111,39 @@ class Oe extends T {
|
|
|
97
111
|
class pe {
|
|
98
112
|
constructor(t) {
|
|
99
113
|
y(this, "metadataTransmitter");
|
|
100
|
-
this.apiKey = t, this.metadataTransmitter = new
|
|
114
|
+
this.apiKey = t, this.metadataTransmitter = new Le();
|
|
101
115
|
}
|
|
102
116
|
identify(t, e, i, n = !1) {
|
|
103
117
|
e || i ? this.addOrUpdateMetadata(t, e, i, n) : this.addOrUpdateMetadata(t, {}, void 0, n);
|
|
104
118
|
}
|
|
105
119
|
addOrUpdateMetadata(t, e = {}, i, n = !1) {
|
|
106
120
|
if (!e && !i) throw new Error('Must pass in either traits or traitsJson to "addOrUpdateMetadata"');
|
|
107
|
-
|
|
121
|
+
f().sfDebug && console.log(" [[DEBUG - addOrUpdateMetadata]] Starting operation"), f().sfDebug && console.log(" addOrUpdateMetadata...SENDING DATA...", t, e, i), this.metadataTransmitter.doSend(t, e, n, i);
|
|
108
122
|
}
|
|
109
123
|
}
|
|
110
|
-
class
|
|
124
|
+
class Q extends R {
|
|
111
125
|
constructor() {
|
|
112
126
|
super();
|
|
113
|
-
y(this, "serviceIdentifier", new
|
|
127
|
+
y(this, "serviceIdentifier", new T());
|
|
128
|
+
y(this, "identifyStarted", !1);
|
|
114
129
|
}
|
|
115
|
-
|
|
116
|
-
this.
|
|
130
|
+
startBackgroundIdentify() {
|
|
131
|
+
if (this.identifyStarted) return;
|
|
132
|
+
this.identifyStarted = !0, this.serviceIdentifier.doSend({});
|
|
133
|
+
const e = setInterval(() => {
|
|
134
|
+
f().serviceIdentificationReceived ? clearInterval(e) : this.serviceIdentifier.doSend({});
|
|
135
|
+
}, 5e3);
|
|
136
|
+
e && typeof e == "object" && "unref" in e && e.unref();
|
|
117
137
|
}
|
|
118
138
|
async doSend(e) {
|
|
119
|
-
this.
|
|
139
|
+
this.startBackgroundIdentify(), this.send(e);
|
|
120
140
|
}
|
|
121
141
|
async send(e) {
|
|
122
142
|
try {
|
|
123
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 });
|
|
124
|
-
|
|
144
|
+
w(this.endpoint, this.operationName, this.getQuery(), n);
|
|
125
145
|
} catch (i) {
|
|
126
|
-
|
|
146
|
+
f().sfDebug && console.error("🚨 Error in send():", i);
|
|
127
147
|
}
|
|
128
148
|
}
|
|
129
149
|
getQuery() {
|
|
@@ -154,11 +174,12 @@ class J extends T {
|
|
|
154
174
|
`;
|
|
155
175
|
}
|
|
156
176
|
}
|
|
157
|
-
class Ae extends
|
|
177
|
+
class Ae extends R {
|
|
158
178
|
constructor() {
|
|
159
179
|
super();
|
|
160
|
-
y(this, "serviceIdentifier", new
|
|
180
|
+
y(this, "serviceIdentifier", new T());
|
|
161
181
|
y(this, "supplementalFields", {});
|
|
182
|
+
y(this, "identifyStarted", !1);
|
|
162
183
|
this.setOperationName("CollectExceptions");
|
|
163
184
|
}
|
|
164
185
|
setSupplementalFields(e) {
|
|
@@ -168,16 +189,21 @@ class Ae extends T {
|
|
|
168
189
|
const { isFromLocalService: e } = this.supplementalFields, i = {};
|
|
169
190
|
return e !== void 0 && (i.isFromLocalService = e), i;
|
|
170
191
|
}
|
|
171
|
-
|
|
172
|
-
this.
|
|
192
|
+
startBackgroundIdentify() {
|
|
193
|
+
if (this.identifyStarted) return;
|
|
194
|
+
this.identifyStarted = !0, this.serviceIdentifier.doSend({});
|
|
195
|
+
const e = setInterval(() => {
|
|
196
|
+
f().serviceIdentificationReceived ? clearInterval(e) : this.serviceIdentifier.doSend({});
|
|
197
|
+
}, 5e3);
|
|
198
|
+
e && typeof e == "object" && "unref" in e && e.unref();
|
|
173
199
|
}
|
|
174
200
|
async doSend(e, i) {
|
|
175
|
-
this.
|
|
201
|
+
this.startBackgroundIdentify(), this.send(e, i);
|
|
176
202
|
}
|
|
177
203
|
async send(e, i) {
|
|
178
|
-
|
|
179
|
-
const n = JSON.stringify(
|
|
180
|
-
|
|
204
|
+
f().sfDebug && console.log(" SENDING EXCEPTION...");
|
|
205
|
+
const n = JSON.stringify(De.encode(i)), s = this.normalizedSupplementalForGraphQL(), l = this.getVariables({ exceptionMessage: e, traceJson: n, reentrancyGuardPreactive: !1, library: f().packageLibraryType, version: f().version, ...s });
|
|
206
|
+
w(this.endpoint, this.operationName, this.getQuery(), l);
|
|
181
207
|
}
|
|
182
208
|
getQuery() {
|
|
183
209
|
return `
|
|
@@ -211,56 +237,56 @@ class Ae extends T {
|
|
|
211
237
|
`;
|
|
212
238
|
}
|
|
213
239
|
}
|
|
214
|
-
const
|
|
215
|
-
var
|
|
216
|
-
const
|
|
217
|
-
let
|
|
218
|
-
function
|
|
219
|
-
const r =
|
|
220
|
-
if (
|
|
240
|
+
const ee = "getting request source code";
|
|
241
|
+
var q = ((r) => (r.UNKNOWN = "unknown", r.ANONYMOUS = "anonymous", r.NOT_CAPTURED = "not captured", r))(q || {});
|
|
242
|
+
const te = "http:", qe = Re(import.meta.url);
|
|
243
|
+
let ne = !1;
|
|
244
|
+
function He() {
|
|
245
|
+
const r = f().sfDebug;
|
|
246
|
+
if (ne) return void (r && b("[patchNodeHttpInbound] Already installed, skipping."));
|
|
221
247
|
let t;
|
|
222
|
-
|
|
248
|
+
ne = !0;
|
|
223
249
|
try {
|
|
224
|
-
t =
|
|
250
|
+
t = qe("node:http"), r && b("[patchNodeHttpInbound] node:http required successfully.");
|
|
225
251
|
} catch (n) {
|
|
226
|
-
return void
|
|
252
|
+
return void we("Failed to require node:http:", n);
|
|
227
253
|
}
|
|
228
|
-
if (!t?.Server?.prototype) return void (r &&
|
|
254
|
+
if (!t?.Server?.prototype) return void (r && b("[patchNodeHttpInbound] http.Server.prototype not found."));
|
|
229
255
|
const e = t.Server.prototype, i = e.emit;
|
|
230
|
-
i && !e.__sf_inbound_patched__ ? (Object.defineProperty(e, "__sf_inbound_patched__", { value: !0, enumerable: !1, configurable: !1, writable: !1 }), r &&
|
|
231
|
-
if (n !== "request") return r &&
|
|
232
|
-
const
|
|
233
|
-
const
|
|
234
|
-
if (!
|
|
235
|
-
for (const [
|
|
236
|
-
return
|
|
237
|
-
})(
|
|
238
|
-
r && (
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
const
|
|
242
|
-
r &&
|
|
243
|
-
const m = () =>
|
|
244
|
-
|
|
245
|
-
const
|
|
246
|
-
r &&
|
|
256
|
+
i && !e.__sf_inbound_patched__ ? (Object.defineProperty(e, "__sf_inbound_patched__", { value: !0, enumerable: !1, configurable: !1, writable: !1 }), r && b("[patchNodeHttpInbound] Patching http.Server.prototype.emit."), e.emit = function(n, ...s) {
|
|
257
|
+
if (n !== "request") return r && b(`[patchNodeHttpInbound] Passing through event: ${n}`), i.call(this, n, ...s);
|
|
258
|
+
const l = s[0], a = s[1], o = (function(u) {
|
|
259
|
+
const h = {};
|
|
260
|
+
if (!u) return h;
|
|
261
|
+
for (const [v, I] of Object.entries(u)) I != null && (Array.isArray(I) ? h[v.toLowerCase()] = I.join(", ") : h[v.toLowerCase()] = String(I));
|
|
262
|
+
return h;
|
|
263
|
+
})(l?.headers), d = o["x-sf3-rid"], p = o["x-sf3-functionspancaptureoverride"];
|
|
264
|
+
r && (b("[patchNodeHttpInbound] Intercepted request event."), b("[patchNodeHttpInbound] Inbound headers:", o), b("[patchNodeHttpInbound] Trace header:", d), b("[patchNodeHttpInbound] FuncSpan override header:", p));
|
|
265
|
+
const c = V.getInstance();
|
|
266
|
+
c.setTraceId(d);
|
|
267
|
+
const g = c.getTraceId();
|
|
268
|
+
r && b("[patchNodeHttpInbound] Context traceId set:", g);
|
|
269
|
+
const m = () => c.runWith({ inboundHeaders: o, ...d ? { traceId: d } : {} }, () => {
|
|
270
|
+
d && c.setTraceId(d), r && b("[patchNodeHttpInbound] Running request handler in context.");
|
|
271
|
+
const u = () => {
|
|
272
|
+
r && b("[patchNodeHttpInbound] Response finished/closed for traceId:", c.getTraceId());
|
|
247
273
|
};
|
|
248
|
-
return
|
|
274
|
+
return a.on("finish", u), a.on("close", u), i.call(this, n, l, a);
|
|
249
275
|
});
|
|
250
|
-
if (!
|
|
276
|
+
if (!p) return m();
|
|
251
277
|
try {
|
|
252
|
-
return
|
|
278
|
+
return Ie.run(p, () => m());
|
|
253
279
|
} catch {
|
|
254
280
|
return m();
|
|
255
281
|
}
|
|
256
|
-
}) : r &&
|
|
282
|
+
}) : r && b("[patchNodeHttpInbound] Already patched, skipping.");
|
|
257
283
|
}
|
|
258
|
-
class
|
|
284
|
+
class Me extends Q {
|
|
259
285
|
constructor() {
|
|
260
286
|
super(), this.setOperationName("DomainsToNotPassHeaderTo");
|
|
261
287
|
}
|
|
262
288
|
async doSend(t) {
|
|
263
|
-
this.
|
|
289
|
+
this.send(t);
|
|
264
290
|
}
|
|
265
291
|
async send(t) {
|
|
266
292
|
const e = `
|
|
@@ -276,24 +302,30 @@ class He extends J {
|
|
|
276
302
|
)
|
|
277
303
|
}
|
|
278
304
|
`, i = { apiKey: this.apiKey, serviceUuid: this.serviceUUID, domains: t };
|
|
279
|
-
|
|
305
|
+
w(this.endpoint, this.operationName, e, i);
|
|
280
306
|
}
|
|
281
307
|
}
|
|
282
|
-
class
|
|
308
|
+
class xe extends R {
|
|
283
309
|
constructor() {
|
|
284
310
|
super();
|
|
285
|
-
y(this, "serviceIdentifier", new
|
|
311
|
+
y(this, "serviceIdentifier", new T());
|
|
312
|
+
y(this, "identifyStarted", !1);
|
|
286
313
|
this.setOperationName("CollectNetworkHops");
|
|
287
314
|
}
|
|
288
|
-
|
|
289
|
-
this.
|
|
315
|
+
startBackgroundIdentify() {
|
|
316
|
+
if (this.identifyStarted) return;
|
|
317
|
+
this.identifyStarted = !0, this.serviceIdentifier.doSend({});
|
|
318
|
+
const e = setInterval(() => {
|
|
319
|
+
f().serviceIdentificationReceived ? clearInterval(e) : this.serviceIdentifier.doSend({});
|
|
320
|
+
}, 5e3);
|
|
321
|
+
e && typeof e == "object" && "unref" in e && e.unref();
|
|
290
322
|
}
|
|
291
323
|
async doSend(e) {
|
|
292
|
-
this.
|
|
324
|
+
this.startBackgroundIdentify(), this.send(e);
|
|
293
325
|
}
|
|
294
326
|
async send(e) {
|
|
295
|
-
const { name: i, column: n, line:
|
|
296
|
-
|
|
327
|
+
const { name: i, column: n, line: s, entrypoint: l, retryWithoutTraceId: a } = e, o = this.getVariables({ name: i, column: n, line: s, entrypoint: l, retryWithoutTraceId: a });
|
|
328
|
+
w(this.endpoint, this.operationName, this.getQuery(), o);
|
|
297
329
|
}
|
|
298
330
|
getQuery() {
|
|
299
331
|
return `
|
|
@@ -323,17 +355,23 @@ class Me extends T {
|
|
|
323
355
|
`;
|
|
324
356
|
}
|
|
325
357
|
}
|
|
326
|
-
class
|
|
358
|
+
class Be extends R {
|
|
327
359
|
constructor() {
|
|
328
360
|
super();
|
|
329
|
-
y(this, "serviceIdentifier", new
|
|
361
|
+
y(this, "serviceIdentifier", new T());
|
|
362
|
+
y(this, "identifyStarted", !1);
|
|
330
363
|
this.setOperationName("CollectNetworkRequest");
|
|
331
364
|
}
|
|
332
|
-
|
|
333
|
-
this.
|
|
365
|
+
startBackgroundIdentify() {
|
|
366
|
+
if (this.identifyStarted) return;
|
|
367
|
+
this.identifyStarted = !0, this.serviceIdentifier.doSend({});
|
|
368
|
+
const e = setInterval(() => {
|
|
369
|
+
f().serviceIdentificationReceived ? clearInterval(e) : this.serviceIdentifier.doSend({});
|
|
370
|
+
}, 5e3);
|
|
371
|
+
e && typeof e == "object" && "unref" in e && e.unref();
|
|
334
372
|
}
|
|
335
373
|
async doSend(e) {
|
|
336
|
-
this.
|
|
374
|
+
this.startBackgroundIdentify(), this.send(e);
|
|
337
375
|
}
|
|
338
376
|
getQuery() {
|
|
339
377
|
return `
|
|
@@ -347,10 +385,10 @@ class xe extends T {
|
|
|
347
385
|
}
|
|
348
386
|
async send(e) {
|
|
349
387
|
const i = { data: { ...e } };
|
|
350
|
-
await
|
|
388
|
+
await w(this.endpoint, this.operationName, this.getQuery(), i);
|
|
351
389
|
}
|
|
352
390
|
}
|
|
353
|
-
const
|
|
391
|
+
const x = [400, 403];
|
|
354
392
|
class Ge {
|
|
355
393
|
constructor(t = []) {
|
|
356
394
|
y(this, "HEADER_TRACING", "X-Sf3-Rid");
|
|
@@ -358,17 +396,17 @@ class Ge {
|
|
|
358
396
|
y(this, "HEADER_PRINT_GUARD", "reentrancy_guard_print_preactive");
|
|
359
397
|
y(this, "HEADER_EXCEPTION_GUARD", "reentrancy_guard_exception_preactive");
|
|
360
398
|
y(this, "contextManager");
|
|
361
|
-
this.contextManager =
|
|
399
|
+
this.contextManager = V.getInstance(), t?.forEach((e) => {
|
|
362
400
|
typeof e == "string" && e.trim() && this.contextManager.getExcludedDomains().add(e);
|
|
363
|
-
}),
|
|
401
|
+
}), f().sfDebug && console.log("[RequestInterceptor] Initialized with static excluded domains.");
|
|
364
402
|
}
|
|
365
403
|
extractIdsFromTraceHeader(t, e = this.HEADER_TRACING) {
|
|
366
404
|
let i;
|
|
367
405
|
if (t instanceof Headers) i = t.get(e) ?? void 0;
|
|
368
406
|
else {
|
|
369
|
-
const
|
|
370
|
-
for (const [
|
|
371
|
-
i =
|
|
407
|
+
const s = e.toLowerCase();
|
|
408
|
+
for (const [l, a] of Object.entries(t)) if (l.toLowerCase() === s) {
|
|
409
|
+
i = a;
|
|
372
410
|
break;
|
|
373
411
|
}
|
|
374
412
|
}
|
|
@@ -379,43 +417,43 @@ class Ge {
|
|
|
379
417
|
parseStackFrame(t) {
|
|
380
418
|
const e = /\((.*):(\d+):(\d+)\)$/.exec(t.trim());
|
|
381
419
|
if (!e) return null;
|
|
382
|
-
const [, i, n,
|
|
383
|
-
return { filePath: i, line: parseInt(n, 10), column: parseInt(
|
|
420
|
+
const [, i, n, s] = e;
|
|
421
|
+
return { filePath: i, line: parseInt(n, 10), column: parseInt(s, 10) };
|
|
384
422
|
}
|
|
385
423
|
async getOriginalPosition(t, e, i) {
|
|
386
424
|
let n = { source: t, line: e, column: i, name: null };
|
|
387
425
|
if (t.includes("://")) return { originalPos: n };
|
|
388
|
-
const
|
|
426
|
+
const s = t + ".map";
|
|
389
427
|
try {
|
|
390
|
-
const
|
|
391
|
-
let
|
|
392
|
-
|
|
393
|
-
} catch (
|
|
394
|
-
|
|
428
|
+
const l = JSON.parse(Ce(s, "utf-8"));
|
|
429
|
+
let a = (await new Ue.SourceMapConsumer(l)).originalPositionFor({ line: e, column: i });
|
|
430
|
+
a.source && (n = a);
|
|
431
|
+
} catch (l) {
|
|
432
|
+
f().sfDebug && console.error(`Could not read/parse map file at ${s}:`, l);
|
|
395
433
|
}
|
|
396
434
|
return { originalPos: n };
|
|
397
435
|
}
|
|
398
436
|
captureFirstUserLines(t, e = 10, i = !1) {
|
|
399
|
-
const n =
|
|
400
|
-
Error.stackTraceLimit = Math.max(
|
|
401
|
-
const
|
|
402
|
-
|
|
403
|
-
const
|
|
404
|
-
Error.stackTraceLimit =
|
|
405
|
-
const
|
|
406
|
-
`).slice(1),
|
|
407
|
-
for (const
|
|
408
|
-
if (!(
|
|
409
|
-
for (const
|
|
410
|
-
const
|
|
411
|
-
|
|
412
|
-
const { originalPos:
|
|
413
|
-
if (
|
|
414
|
-
|
|
415
|
-
const m = { line:
|
|
437
|
+
const n = f().sfDebug ? 10 : e, s = Error.stackTraceLimit;
|
|
438
|
+
Error.stackTraceLimit = Math.max(s, n);
|
|
439
|
+
const l = new Error(ee);
|
|
440
|
+
ee in Error && Error.captureStackTrace(l, this.captureFirstUserLines);
|
|
441
|
+
const a = ue(l.stack);
|
|
442
|
+
Error.stackTraceLimit = s;
|
|
443
|
+
const o = a.split(`
|
|
444
|
+
`).slice(1), d = [];
|
|
445
|
+
for (const p of o)
|
|
446
|
+
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
|
+
for (const p of d) {
|
|
448
|
+
const c = this.parseStackFrame(p);
|
|
449
|
+
c ? (async () => {
|
|
450
|
+
const { originalPos: g } = await this.getOriginalPosition(c.filePath, c.line, c.column);
|
|
451
|
+
if (g) {
|
|
452
|
+
f().sfDebug && console.log("[RequestInterceptor] First user code line:", g);
|
|
453
|
+
const m = { line: g.line?.toString() || q.UNKNOWN, column: g.column?.toString() || q.NOT_CAPTURED, name: g.name || q.NOT_CAPTURED, entrypoint: g.source, retryWithoutTraceId: i };
|
|
416
454
|
t.doSend(m);
|
|
417
455
|
}
|
|
418
|
-
})() :
|
|
456
|
+
})() : f().sfDebug && console.error("Could not parse stack line:", p);
|
|
419
457
|
}
|
|
420
458
|
}
|
|
421
459
|
addReentrancyGuardHeaders(t) {
|
|
@@ -426,118 +464,134 @@ class Ge {
|
|
|
426
464
|
}
|
|
427
465
|
addTracingHeaders(t, e) {
|
|
428
466
|
const i = new URL(e).hostname, n = this.shouldPropagateHeaders(i);
|
|
429
|
-
return n ? this.addTracingHeader(t, e) :
|
|
467
|
+
return n ? this.addTracingHeader(t, e) : f().sfDebug && console.error(`[RequestInterceptor] Excluded domain: ${i}`), n;
|
|
430
468
|
}
|
|
431
469
|
addTracingHeader(t, e) {
|
|
432
|
-
const i =
|
|
470
|
+
const i = W();
|
|
433
471
|
if (i) {
|
|
434
|
-
const
|
|
435
|
-
if (
|
|
472
|
+
const a = j(i);
|
|
473
|
+
if (a && a.sample_rate === 0) return void (f().sfDebug && console.log(`[RequestInterceptor] Function span tracking disabled (sample_rate=0), skipping tracing header for ${e}`));
|
|
436
474
|
}
|
|
437
|
-
const n = this.contextManager.getOrSetSfTraceId(),
|
|
438
|
-
t.set(this.HEADER_TRACING, `${n}/${
|
|
475
|
+
const n = this.contextManager.getOrSetSfTraceId(), s = this.contextManager.getOrSetPageVisitUUID(), l = K();
|
|
476
|
+
t.set(this.HEADER_TRACING, `${n}/${s}/${l}`), f().sfDebug && console.log(`[RequestInterceptor] Added tracing header for ${e}`);
|
|
439
477
|
}
|
|
440
478
|
patchFetch(t, e) {
|
|
441
479
|
const i = globalThis.fetch;
|
|
442
|
-
typeof i == "function" ? globalThis.fetch = async (n,
|
|
443
|
-
const
|
|
444
|
-
if (
|
|
480
|
+
typeof i == "function" ? globalThis.fetch = async (n, s) => {
|
|
481
|
+
const l = new Headers(s?.headers);
|
|
482
|
+
if (l.get(this.HEADER_LOG_GUARD) === "true" || l.get(this.HEADER_PRINT_GUARD) === "true" || l.get(this.HEADER_EXCEPTION_GUARD) === "true") return i(n, s);
|
|
445
483
|
this.captureFirstUserLines(t);
|
|
446
|
-
const
|
|
447
|
-
let
|
|
448
|
-
typeof n == "string" || n instanceof URL ?
|
|
449
|
-
|
|
450
|
-
})) :
|
|
451
|
-
const
|
|
484
|
+
const a = Date.now();
|
|
485
|
+
let o;
|
|
486
|
+
typeof n == "string" || n instanceof URL ? o = n.toString() : n instanceof Request ? (o = n.url, n.headers.forEach((u, h) => {
|
|
487
|
+
l.set(h, u);
|
|
488
|
+
})) : f().sfDebug && console.error("[Sailfish RequestInterceptor] Invalid fetch input."), f().sfDebug && console.log("[RequestInterceptor] Fetching request to:", o);
|
|
489
|
+
const d = new URL(o).hostname, p = new Headers(l), c = this.addTracingHeaders(l, o), g = { ...s, headers: l };
|
|
452
490
|
let m;
|
|
453
491
|
try {
|
|
454
|
-
let
|
|
455
|
-
this.addTracingHeaders(
|
|
456
|
-
const
|
|
457
|
-
|
|
458
|
-
const { sessionId:
|
|
459
|
-
if (
|
|
460
|
-
const
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
}),
|
|
492
|
+
let u = !1;
|
|
493
|
+
this.addTracingHeaders(p, o), m = await i(o, g), c && x.includes(m.status) ? (m = await i(o, { ...s, headers: p }), u = !0, this.captureFirstUserLines(t, 10, u)) : this.contextManager.addSupportedDomains(d);
|
|
494
|
+
const h = Date.now();
|
|
495
|
+
f().sfDebug && console.log(`[RequestInterceptor] Fetch completed: ${o}, Status: ${m.status}, Duration: ${h - a}ms`);
|
|
496
|
+
const { sessionId: v, pageVisitId: I, requestId: _ } = this.extractIdsFromTraceHeader(l), S = f(), F = { apiKey: S.apiKey, requestId: _, pageVisitId: I, recordingSessionId: v, serviceUuid: S.serviceUUID, timestampStart: a.toString(), timestampEnd: h.toString(), responseCode: m.status, success: !0, error: null, url: o, method: g.method || "GET", retryWithoutTraceId: u, parentSpanId: H() };
|
|
497
|
+
if (S.captureRequestHeaders) {
|
|
498
|
+
const $ = {};
|
|
499
|
+
l.forEach((N, P) => {
|
|
500
|
+
$[P] = N;
|
|
501
|
+
}), F.requestHeaders = $;
|
|
464
502
|
}
|
|
465
|
-
if (
|
|
466
|
-
const
|
|
467
|
-
m.headers.forEach((
|
|
468
|
-
|
|
469
|
-
}),
|
|
503
|
+
if (S.captureResponseHeaders) {
|
|
504
|
+
const $ = {};
|
|
505
|
+
m.headers.forEach((N, P) => {
|
|
506
|
+
$[P] = N;
|
|
507
|
+
}), F.responseHeaders = $;
|
|
470
508
|
}
|
|
471
|
-
if (
|
|
472
|
-
const
|
|
473
|
-
|
|
509
|
+
if (S.captureRequestBody && s?.body) try {
|
|
510
|
+
const $ = typeof s.body == "string" ? s.body : JSON.stringify(s.body);
|
|
511
|
+
F.requestBody = $.length > S.requestBodyLimitBytes ? $.substring(0, S.requestBodyLimitBytes) + "...[truncated]" : $;
|
|
474
512
|
} catch {
|
|
475
513
|
}
|
|
476
|
-
if (
|
|
477
|
-
const
|
|
478
|
-
|
|
514
|
+
if (S.captureResponseBody) try {
|
|
515
|
+
const $ = m.clone(), N = await $.text();
|
|
516
|
+
F.responseBody = N.length > S.responseBodyLimitBytes ? N.substring(0, S.responseBodyLimitBytes) + "...[truncated]" : N;
|
|
479
517
|
} catch {
|
|
480
518
|
}
|
|
481
|
-
return e.doSend(
|
|
482
|
-
} catch (
|
|
483
|
-
const
|
|
484
|
-
|
|
519
|
+
return e.doSend(F), m;
|
|
520
|
+
} catch (u) {
|
|
521
|
+
const h = Date.now();
|
|
522
|
+
f().sfDebug && console.error(`[RequestInterceptor] Fetch failed: ${o}, Error: ${u}, Duration: ${h - a}ms`);
|
|
523
|
+
}
|
|
524
|
+
} : f().sfDebug && console.error("[RequestInterceptor] Fetch not available.");
|
|
525
|
+
}
|
|
526
|
+
setHeader(t, e, i) {
|
|
527
|
+
t instanceof Headers ? t.set(e, i) : t[e] = i;
|
|
528
|
+
}
|
|
529
|
+
addTracingHeadersToPlainObject(t, e) {
|
|
530
|
+
const i = new URL(e).hostname, n = this.shouldPropagateHeaders(i);
|
|
531
|
+
if (n) {
|
|
532
|
+
const s = W();
|
|
533
|
+
if (s) {
|
|
534
|
+
const d = j(s);
|
|
535
|
+
if (d && d.sample_rate === 0) return f().sfDebug && console.log(`[RequestInterceptor] Function span tracking disabled (sample_rate=0), skipping tracing header for ${e}`), !1;
|
|
485
536
|
}
|
|
486
|
-
|
|
537
|
+
const l = this.contextManager.getOrSetSfTraceId(), a = this.contextManager.getOrSetPageVisitUUID(), o = K();
|
|
538
|
+
t[this.HEADER_TRACING] = `${l}/${a}/${o}`, f().sfDebug && console.log(`[RequestInterceptor] Added tracing header for ${e}`);
|
|
539
|
+
} else f().sfDebug && console.error(`[RequestInterceptor] Excluded domain: ${i}`);
|
|
540
|
+
return n;
|
|
487
541
|
}
|
|
488
542
|
patchHttp(t, e) {
|
|
489
|
-
if (
|
|
490
|
-
const i =
|
|
491
|
-
|
|
492
|
-
|
|
543
|
+
if (f().sfDebug && console.log("[RequestInterceptor] Initializing HTTP/HTTPS request patch..."), !E || typeof E.request != "function") return void (f().sfDebug && console.log("[RequestInterceptor] HTTP/HTTPS not available."));
|
|
544
|
+
const i = E.request.bind(E), n = U.request.bind(U), s = (o, d, p, c = te) => {
|
|
545
|
+
let g, m;
|
|
546
|
+
if (typeof o == "string" || o instanceof URL) {
|
|
547
|
+
const u = typeof o == "string" ? new URL(o) : o;
|
|
548
|
+
g = { ...typeof d == "object" && d !== null ? d : {}, protocol: u.protocol || c, hostname: u.hostname, port: u.port || void 0, path: u.pathname + u.search }, m = typeof d == "function" ? d : p;
|
|
549
|
+
} else g = { ...o }, g.protocol || (g.protocol = c), m = typeof d == "function" ? d : void 0;
|
|
550
|
+
return g.headers || (g.headers = {}), [g, m];
|
|
551
|
+
}, l = (o, d, p) => {
|
|
552
|
+
const [c, g] = s(o, d, p, te);
|
|
493
553
|
try {
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
if (s.headers) {
|
|
499
|
-
const c = `${s.protocol}//${s.hostname}`;
|
|
500
|
-
this.addTracingHeaders(s.headers, c), this.captureFirstUserLines(t);
|
|
501
|
-
} else u().sfDebug && console.warn("[RequestInterceptor] No headers found in HTTP request options. Skipping header addition.");
|
|
502
|
-
} catch (c) {
|
|
503
|
-
throw u().sfDebug && console.error("[RequestInterceptor] Error while processing HTTP request options:", c), c;
|
|
554
|
+
const u = `${c.protocol}//${c.hostname}`;
|
|
555
|
+
this.addTracingHeadersToPlainObject(c.headers, u), this.captureFirstUserLines(t);
|
|
556
|
+
} catch (u) {
|
|
557
|
+
f().sfDebug && console.error("[RequestInterceptor] Error while processing HTTP request options:", u);
|
|
504
558
|
}
|
|
505
|
-
let
|
|
506
|
-
return i(
|
|
507
|
-
const
|
|
508
|
-
if (
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
delete p.headers[this.HEADER_TRACING], i(p, d), a = !0, this.captureFirstUserLines(t, 10, a);
|
|
559
|
+
let m = !1;
|
|
560
|
+
return i(c, (u) => {
|
|
561
|
+
const h = `${c.protocol}//${c.hostname}`;
|
|
562
|
+
if (this.shouldPropagateHeaders(new URL(h).hostname) && x.includes(u.statusCode || 0)) {
|
|
563
|
+
const S = { ...c, headers: { ...c.headers } };
|
|
564
|
+
delete S.headers[this.HEADER_TRACING], i(S, g), m = !0, this.captureFirstUserLines(t, 10, m);
|
|
512
565
|
}
|
|
513
|
-
const { sessionId:
|
|
514
|
-
e.doSend({ apiKey:
|
|
566
|
+
const { sessionId: v, pageVisitId: I, requestId: _ } = this.extractIdsFromTraceHeader(c.headers);
|
|
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);
|
|
515
568
|
});
|
|
516
|
-
},
|
|
517
|
-
|
|
569
|
+
}, a = (o, d, p) => {
|
|
570
|
+
const [c, g] = s(o, d, p, "https:");
|
|
518
571
|
try {
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
if (s.headers) {
|
|
524
|
-
const c = `${s.protocol}//${s.hostname}`;
|
|
525
|
-
this.addTracingHeaders(s.headers, c);
|
|
526
|
-
} else u().sfDebug && console.warn("[RequestInterceptor] No headers found in HTTPS request options. Skipping header addition.");
|
|
527
|
-
} catch (c) {
|
|
528
|
-
throw u().sfDebug && console.error("[RequestInterceptor] Error while processing HTTPS request options:", c), c;
|
|
572
|
+
const u = `${c.protocol}//${c.hostname}`;
|
|
573
|
+
this.addTracingHeadersToPlainObject(c.headers, u), this.captureFirstUserLines(t);
|
|
574
|
+
} catch (u) {
|
|
575
|
+
f().sfDebug && console.error("[RequestInterceptor] Error while processing HTTPS request options:", u);
|
|
529
576
|
}
|
|
530
|
-
let
|
|
531
|
-
return n(
|
|
532
|
-
const
|
|
533
|
-
if (
|
|
534
|
-
const
|
|
535
|
-
delete
|
|
577
|
+
let m = !1;
|
|
578
|
+
return n(c, (u) => {
|
|
579
|
+
const h = `${c.protocol}//${c.hostname}`;
|
|
580
|
+
if (this.shouldPropagateHeaders(new URL(h).hostname) && x.includes(u.statusCode || 0)) {
|
|
581
|
+
const S = { ...c, headers: { ...c.headers } };
|
|
582
|
+
delete S.headers[this.HEADER_TRACING], n(S, g), m = !0, this.captureFirstUserLines(t, 10, m);
|
|
536
583
|
}
|
|
537
|
-
const { sessionId:
|
|
538
|
-
e.doSend({ apiKey:
|
|
584
|
+
const { sessionId: v, pageVisitId: I, requestId: _ } = this.extractIdsFromTraceHeader(c.headers);
|
|
585
|
+
e.doSend({ apiKey: f().apiKey, requestId: _, pageVisitId: I, recordingSessionId: v, serviceUuid: f().serviceUUID, timestampStart: Date.now().toString(), timestampEnd: Date.now().toString(), responseCode: u.statusCode || 0, success: !!u.statusCode && u.statusCode < 400, error: null, url: h, method: c.method || "GET", retryWithoutTraceId: m, parentSpanId: H() }), g?.(u);
|
|
539
586
|
});
|
|
540
|
-
}
|
|
587
|
+
};
|
|
588
|
+
E.request = l, U.request = a, E.get = (o, d, p) => {
|
|
589
|
+
const c = l(o, d, p);
|
|
590
|
+
return c.end(), c;
|
|
591
|
+
}, U.get = (o, d, p) => {
|
|
592
|
+
const c = a(o, d, p);
|
|
593
|
+
return c.end(), c;
|
|
594
|
+
}, f().sfDebug && console.log("✅ HTTP and HTTPS request/get methods patched globally.");
|
|
541
595
|
}
|
|
542
596
|
tryPatch(t, e) {
|
|
543
597
|
try {
|
|
@@ -549,12 +603,12 @@ class Ge {
|
|
|
549
603
|
return [...this.contextManager.getExcludedDomains()];
|
|
550
604
|
}
|
|
551
605
|
}
|
|
552
|
-
class Ke extends
|
|
606
|
+
class Ke extends Q {
|
|
553
607
|
constructor() {
|
|
554
608
|
super(), this.setOperationName("UpdateServiceDetails");
|
|
555
609
|
}
|
|
556
610
|
async doSend() {
|
|
557
|
-
this.
|
|
611
|
+
this.send();
|
|
558
612
|
}
|
|
559
613
|
async send() {
|
|
560
614
|
const t = `
|
|
@@ -574,6 +628,9 @@ class Ke extends J {
|
|
|
574
628
|
$infrastructureDetails: JSON,
|
|
575
629
|
$setupInterceptorsFile: String,
|
|
576
630
|
$setupInterceptorsLine: Int,
|
|
631
|
+
$framework: String,
|
|
632
|
+
$additionalFrameworks: JSON,
|
|
633
|
+
$serviceRole: String,
|
|
577
634
|
) {
|
|
578
635
|
${this.queryName}(
|
|
579
636
|
apiKey: $apiKey,
|
|
@@ -591,10 +648,13 @@ class Ke extends J {
|
|
|
591
648
|
infrastructureDetails: $infrastructureDetails,
|
|
592
649
|
setupInterceptorsFile: $setupInterceptorsFile,
|
|
593
650
|
setupInterceptorsLine: $setupInterceptorsLine,
|
|
651
|
+
framework: $framework,
|
|
652
|
+
additionalFrameworks: $additionalFrameworks,
|
|
653
|
+
serviceRole: $serviceRole,
|
|
594
654
|
)
|
|
595
655
|
}
|
|
596
|
-
`, e =
|
|
597
|
-
|
|
656
|
+
`, e = f(), 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 });
|
|
657
|
+
w(this.endpoint, this.operationName, t, i);
|
|
598
658
|
}
|
|
599
659
|
}
|
|
600
660
|
class We {
|
|
@@ -617,23 +677,23 @@ class We {
|
|
|
617
677
|
await this._resolveInheritance(), this.debug && console.log(`[FuncSpan ConfigLoader] Loaded ${this.fileConfigs.size} file configs, ${this.functionConfigs.size} function configs`);
|
|
618
678
|
}
|
|
619
679
|
getConfig(t, e) {
|
|
620
|
-
const i = this.hasSailfishFiles ? $e() :
|
|
621
|
-
let
|
|
680
|
+
const i = this.hasSailfishFiles ? $e() : le(), n = this._getDirectoryConfig(t), s = D.normalize(t), l = this.fileConfigs.get(s) || {};
|
|
681
|
+
let a = {};
|
|
622
682
|
if (e) {
|
|
623
|
-
const
|
|
624
|
-
|
|
683
|
+
const o = this.functionConfigs.get(s);
|
|
684
|
+
o && (a = o.get(e) || {});
|
|
625
685
|
}
|
|
626
|
-
return
|
|
686
|
+
return C(i, n, l, a);
|
|
627
687
|
}
|
|
628
688
|
hasRuntimeMode() {
|
|
629
689
|
return this.runtimeModeEnabled;
|
|
630
690
|
}
|
|
631
691
|
async _walkDirectory(t, e) {
|
|
632
692
|
try {
|
|
633
|
-
const i = await
|
|
693
|
+
const i = await Z.readdir(t, { withFileTypes: !0 });
|
|
634
694
|
for (const n of i) {
|
|
635
|
-
const
|
|
636
|
-
n.isFile() && n.name === ".sailfish" ? e.push(
|
|
695
|
+
const s = D.join(t, n.name);
|
|
696
|
+
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);
|
|
637
697
|
}
|
|
638
698
|
} catch (i) {
|
|
639
699
|
this.debug && console.error(`[FuncSpan ConfigLoader] Error walking directory ${t}:`, i);
|
|
@@ -641,7 +701,7 @@ class We {
|
|
|
641
701
|
}
|
|
642
702
|
async _loadConfigFile(t) {
|
|
643
703
|
try {
|
|
644
|
-
const e = await
|
|
704
|
+
const e = await Z.readFile(t, "utf-8"), i = D.dirname(t);
|
|
645
705
|
let n = null;
|
|
646
706
|
try {
|
|
647
707
|
n = JSON.parse(e);
|
|
@@ -651,8 +711,8 @@ class We {
|
|
|
651
711
|
} catch {
|
|
652
712
|
try {
|
|
653
713
|
n = require("js-yaml").load(e);
|
|
654
|
-
} catch (
|
|
655
|
-
return void (this.debug && console.error(`[FuncSpan ConfigLoader] Failed to parse ${t} as JSON, TOML, or YAML:`,
|
|
714
|
+
} catch (s) {
|
|
715
|
+
return void (this.debug && console.error(`[FuncSpan ConfigLoader] Failed to parse ${t} as JSON, TOML, or YAML:`, s));
|
|
656
716
|
}
|
|
657
717
|
}
|
|
658
718
|
}
|
|
@@ -663,70 +723,70 @@ class We {
|
|
|
663
723
|
}
|
|
664
724
|
}
|
|
665
725
|
async _expandFileGlobs(t, e, i) {
|
|
666
|
-
for (const [n,
|
|
667
|
-
const
|
|
668
|
-
this.debug && console.log(`[FuncSpan ConfigLoader] Pattern '${n}' matched ${
|
|
669
|
-
for (const
|
|
670
|
-
const
|
|
671
|
-
this.fileConfigs.set(
|
|
726
|
+
for (const [n, s] of Object.entries(e)) try {
|
|
727
|
+
const l = D.join(t, n), a = await Oe(l, { absolute: !0, nodir: !0, ignore: ["**/node_modules/**", "**/.git/**"] });
|
|
728
|
+
this.debug && console.log(`[FuncSpan ConfigLoader] Pattern '${n}' matched ${a.length} files`);
|
|
729
|
+
for (const o of a) {
|
|
730
|
+
const d = D.normalize(o), p = C(i, s);
|
|
731
|
+
this.fileConfigs.set(d, p), this.debug && a.length <= 5 && console.log(`[FuncSpan ConfigLoader] - ${o}`);
|
|
672
732
|
}
|
|
673
|
-
} catch (
|
|
674
|
-
this.debug && console.error(`[FuncSpan ConfigLoader] Error expanding glob '${n}':`,
|
|
733
|
+
} catch (l) {
|
|
734
|
+
this.debug && console.error(`[FuncSpan ConfigLoader] Error expanding glob '${n}':`, l);
|
|
675
735
|
}
|
|
676
736
|
}
|
|
677
737
|
_storeFunctionConfigs(t, e, i) {
|
|
678
|
-
for (const [n,
|
|
679
|
-
const
|
|
680
|
-
if (
|
|
738
|
+
for (const [n, s] of Object.entries(e)) {
|
|
739
|
+
const l = n.split("::");
|
|
740
|
+
if (l.length !== 2) {
|
|
681
741
|
this.debug && console.warn(`[FuncSpan ConfigLoader] Invalid function pattern '${n}' (expected format: 'file.ts::functionName')`);
|
|
682
742
|
continue;
|
|
683
743
|
}
|
|
684
|
-
const [
|
|
685
|
-
this.functionConfigs.has(
|
|
686
|
-
const
|
|
687
|
-
|
|
744
|
+
const [a, o] = l, d = D.normalize(D.join(t, a));
|
|
745
|
+
this.functionConfigs.has(d) || this.functionConfigs.set(d, /* @__PURE__ */ new Map());
|
|
746
|
+
const p = this.functionConfigs.get(d), c = C(i, s);
|
|
747
|
+
p.set(o, c), this.debug && console.log(`[FuncSpan ConfigLoader] Function config: ${d}::${o}`);
|
|
688
748
|
}
|
|
689
749
|
}
|
|
690
750
|
async _resolveInheritance() {
|
|
691
751
|
}
|
|
692
752
|
_getDirectoryConfig(t) {
|
|
693
|
-
let e =
|
|
753
|
+
let e = D.dirname(D.normalize(t));
|
|
694
754
|
const i = [];
|
|
695
|
-
for (; e && e !==
|
|
755
|
+
for (; e && e !== D.dirname(e); ) {
|
|
696
756
|
const n = this.directoryConfigs.get(e);
|
|
697
|
-
n && i.unshift(n), e =
|
|
757
|
+
n && i.unshift(n), e = D.dirname(e);
|
|
698
758
|
}
|
|
699
|
-
return i.reduce((n,
|
|
759
|
+
return i.reduce((n, s) => C(n, s), {});
|
|
700
760
|
}
|
|
701
761
|
}
|
|
702
|
-
const
|
|
703
|
-
function
|
|
704
|
-
return globalThis[
|
|
762
|
+
const fe = "__sf_globalConfigLoader";
|
|
763
|
+
function ge() {
|
|
764
|
+
return globalThis[fe] ?? null;
|
|
705
765
|
}
|
|
706
|
-
async function
|
|
766
|
+
async function je(r, t) {
|
|
707
767
|
const e = new We(r, t);
|
|
708
768
|
(function(i) {
|
|
709
|
-
globalThis[
|
|
769
|
+
globalThis[fe] = i;
|
|
710
770
|
})(e), await e.loadAllConfigs();
|
|
711
771
|
}
|
|
712
772
|
function ze(r, t) {
|
|
713
|
-
const e =
|
|
714
|
-
return e ? e.getConfig(r, t) : (process.env.SF_DEBUG === "true" && console.log("[FuncSpan ConfigLoader] Config loader not initialized, using default config (disabled)"),
|
|
773
|
+
const e = ge();
|
|
774
|
+
return e ? e.getConfig(r, t) : (process.env.SF_DEBUG === "true" && console.log("[FuncSpan ConfigLoader] Config loader not initialized, using default config (disabled)"), le());
|
|
715
775
|
}
|
|
716
|
-
function
|
|
717
|
-
return
|
|
776
|
+
function Je() {
|
|
777
|
+
return ge() !== null;
|
|
718
778
|
}
|
|
719
|
-
const
|
|
720
|
-
let
|
|
721
|
-
function
|
|
779
|
+
const Ve = ["readFile", "writeFile", "appendFile", "readdir", "stat", "lstat", "fstat", "access", "open", "close", "read", "write", "chmod", "mkdir", "rmdir", "unlink", "rename"], re = ["lookup", "resolve", "resolve4", "resolve6", "resolveAny", "resolveMx", "resolveNs", "resolveTxt", "reverse"], Qe = ["pbkdf2", "randomBytes", "scrypt", "generateKeyPair"], Xe = ["gzip", "gunzip", "deflate", "inflate", "deflateRaw", "inflateRaw", "brotliCompress", "brotliDecompress"];
|
|
780
|
+
let ie = !1;
|
|
781
|
+
function Ye(r) {
|
|
722
782
|
if (typeof r != "string") return !1;
|
|
723
783
|
const t = process.env.SF_FUNCSPAN_JSONL_FILE;
|
|
724
784
|
if (t && r.includes(t)) return !0;
|
|
725
785
|
const e = process.env.SF_WORKER_POOL_JSONL_FILE;
|
|
726
786
|
return !(!e || !r.includes(e));
|
|
727
787
|
}
|
|
728
|
-
let
|
|
729
|
-
function
|
|
788
|
+
let se = !1;
|
|
789
|
+
function oe(r) {
|
|
730
790
|
if (typeof r != "string") return !1;
|
|
731
791
|
if (r === "localhost" || r === "127.0.0.1" || r === "::1") return !0;
|
|
732
792
|
try {
|
|
@@ -737,8 +797,8 @@ function re(r) {
|
|
|
737
797
|
}
|
|
738
798
|
return !1;
|
|
739
799
|
}
|
|
740
|
-
function
|
|
741
|
-
if (!
|
|
800
|
+
function Ze() {
|
|
801
|
+
if (!se) try {
|
|
742
802
|
let r;
|
|
743
803
|
if (typeof require > "u") return void (process.env.SF_DEBUG === "true" && console.log("[WorkerPool] Skipping dns patching in pure ESM environment (require unavailable)"));
|
|
744
804
|
try {
|
|
@@ -748,231 +808,231 @@ function Ye() {
|
|
|
748
808
|
}
|
|
749
809
|
if (r.__sf_worker_pool_patched__) return;
|
|
750
810
|
Object.defineProperty(r, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
751
|
-
for (const t of
|
|
811
|
+
for (const t of re) if (typeof r[t] == "function") {
|
|
752
812
|
const e = r[t];
|
|
753
813
|
r[t] = function(...i) {
|
|
754
|
-
return
|
|
814
|
+
return Y() ? e.apply(this, i) : oe(i[0]) ? e.apply(this, i) : typeof i[i.length - 1] == "function" ? A("dns", t, e, i, this) : e.apply(this, i);
|
|
755
815
|
}, Object.defineProperty(r[t], "name", { value: t, writable: !1 });
|
|
756
816
|
}
|
|
757
817
|
(function(t) {
|
|
758
818
|
if (!t.promises) return void (process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns.promises not available, skipping"));
|
|
759
819
|
if (!t.promises.__sf_worker_pool_patched__) {
|
|
760
820
|
Object.defineProperty(t.promises, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
761
|
-
for (const e of
|
|
821
|
+
for (const e of re) if (typeof t.promises[e] == "function") {
|
|
762
822
|
const i = t.promises[e];
|
|
763
823
|
t.promises[e] = function(...n) {
|
|
764
|
-
return
|
|
824
|
+
return Y() ? i.apply(this, n) : oe(n[0]) ? i.apply(this, n) : _e("dns", e, i, n, this);
|
|
765
825
|
}, Object.defineProperty(t.promises[e], "name", { value: e, writable: !1 });
|
|
766
826
|
}
|
|
767
827
|
process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns.promises module patched successfully");
|
|
768
828
|
}
|
|
769
|
-
})(r),
|
|
829
|
+
})(r), se = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns module patched successfully");
|
|
770
830
|
} catch (r) {
|
|
771
831
|
console.error("[WorkerPool] Error patching dns module:", r);
|
|
772
832
|
}
|
|
773
833
|
}
|
|
774
|
-
let
|
|
775
|
-
function
|
|
776
|
-
if (
|
|
834
|
+
let ae = !1, ce = !1, z = !1;
|
|
835
|
+
function et() {
|
|
836
|
+
if (z) return;
|
|
777
837
|
const r = process.env.SF_DEBUG === "true";
|
|
778
|
-
r && console.log("[WorkerPool] Initializing worker pool patching..."),
|
|
779
|
-
if (!
|
|
838
|
+
r && console.log("[WorkerPool] Initializing worker pool patching..."), k("fs") && (r && console.log("[WorkerPool] Patching fs module..."), (function() {
|
|
839
|
+
if (!ie) try {
|
|
780
840
|
const t = require("node:fs");
|
|
781
841
|
if (t.__sf_worker_pool_patched__) return;
|
|
782
842
|
Object.defineProperty(t, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
783
|
-
for (const e of
|
|
843
|
+
for (const e of Ve) if (typeof t[e] == "function") {
|
|
784
844
|
const i = t[e];
|
|
785
845
|
t[e] = function(...n) {
|
|
786
|
-
return
|
|
846
|
+
return Ye(n[0]) ? i.apply(this, n) : typeof n[n.length - 1] == "function" ? A("fs", e, i, n, this) : i.apply(this, n);
|
|
787
847
|
}, Object.defineProperty(t[e], "name", { value: e, writable: !1 });
|
|
788
848
|
}
|
|
789
|
-
|
|
849
|
+
ie = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] fs module patched successfully");
|
|
790
850
|
} catch (t) {
|
|
791
851
|
console.error("[WorkerPool] Error patching fs module:", t);
|
|
792
852
|
}
|
|
793
|
-
})()),
|
|
794
|
-
if (!
|
|
853
|
+
})()), k("dns") && (r && console.log("[WorkerPool] Patching dns module..."), Ze()), k("crypto") && (r && console.log("[WorkerPool] Patching crypto module..."), (function() {
|
|
854
|
+
if (!ae) try {
|
|
795
855
|
const t = require("node:crypto");
|
|
796
856
|
if (t.__sf_worker_pool_patched__) return;
|
|
797
857
|
Object.defineProperty(t, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
798
|
-
for (const e of
|
|
858
|
+
for (const e of Qe) if (typeof t[e] == "function") {
|
|
799
859
|
const i = t[e];
|
|
800
860
|
t[e] = function(...n) {
|
|
801
861
|
return typeof n[n.length - 1] == "function" ? A("crypto", e, i, n, this) : i.apply(this, n);
|
|
802
862
|
}, Object.defineProperty(t[e], "name", { value: e, writable: !1 });
|
|
803
863
|
}
|
|
804
|
-
|
|
864
|
+
ae = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] crypto module patched successfully");
|
|
805
865
|
} catch (t) {
|
|
806
866
|
console.error("[WorkerPool] Error patching crypto module:", t);
|
|
807
867
|
}
|
|
808
|
-
})()),
|
|
809
|
-
if (!
|
|
868
|
+
})()), k("zlib") && (r && console.log("[WorkerPool] Patching zlib module..."), (function() {
|
|
869
|
+
if (!ce) try {
|
|
810
870
|
const t = require("node:zlib");
|
|
811
871
|
if (t.__sf_worker_pool_patched__) return;
|
|
812
872
|
Object.defineProperty(t, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
813
|
-
for (const e of
|
|
873
|
+
for (const e of Xe) if (typeof t[e] == "function") {
|
|
814
874
|
const i = t[e];
|
|
815
875
|
t[e] = function(...n) {
|
|
816
876
|
return typeof n[n.length - 1] == "function" ? A("zlib", e, i, n, this) : i.apply(this, n);
|
|
817
877
|
}, Object.defineProperty(t[e], "name", { value: e, writable: !1 });
|
|
818
878
|
}
|
|
819
|
-
|
|
879
|
+
ce = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] zlib module patched successfully");
|
|
820
880
|
} catch (t) {
|
|
821
881
|
console.error("[WorkerPool] Error patching zlib module:", t);
|
|
822
882
|
}
|
|
823
|
-
})()),
|
|
883
|
+
})()), z = !0, r && console.log("[WorkerPool] Worker pool patching initialized");
|
|
824
884
|
}
|
|
825
|
-
function
|
|
826
|
-
return
|
|
885
|
+
function tt() {
|
|
886
|
+
return z;
|
|
827
887
|
}
|
|
828
|
-
let
|
|
829
|
-
function
|
|
830
|
-
if (
|
|
831
|
-
else if (!
|
|
832
|
-
|
|
888
|
+
let J = !1, B = !1;
|
|
889
|
+
function ft(r) {
|
|
890
|
+
if (B) console.warn("[setupInterceptors] ⚠️ Recursive call detected and blocked!");
|
|
891
|
+
else if (!J) {
|
|
892
|
+
B = !0, be();
|
|
833
893
|
try {
|
|
834
894
|
let t, e;
|
|
835
|
-
const i =
|
|
895
|
+
const i = ue(new Error().stack);
|
|
836
896
|
if (i) {
|
|
837
|
-
const
|
|
838
|
-
`)[2] || "",
|
|
839
|
-
|
|
897
|
+
const a = i.split(`
|
|
898
|
+
`)[2] || "", o = a.match(/\((.+):(\d+):\d+\)/) || a.match(/at (.+):(\d+):\d+/);
|
|
899
|
+
o && (t = o[1], e = parseInt(o[2], 10));
|
|
840
900
|
}
|
|
841
901
|
if (!r || !r.apiKey) {
|
|
842
|
-
const
|
|
843
|
-
console.error(
|
|
902
|
+
const a = `The required API Key is not provided: ${JSON.stringify(r)}`;
|
|
903
|
+
console.error(a);
|
|
844
904
|
}
|
|
845
905
|
const { config: n } = Se(r);
|
|
846
|
-
if (
|
|
906
|
+
if (ve(n).catch(() => {
|
|
847
907
|
}), t && (n.setupInterceptorsFile = t), e && (n.setupInterceptorsLine = e), n.sfDebug && console.log("Updated configuration after applying options:", n), !n.apiKey || !n.apiGraphqlEndpoint) {
|
|
848
|
-
const
|
|
849
|
-
throw console.error(
|
|
908
|
+
const a = `The required config is not provided: ${JSON.stringify(n)}`;
|
|
909
|
+
throw console.error(a), new Error(a);
|
|
850
910
|
}
|
|
851
|
-
|
|
852
|
-
n.sfDebug && console.error("[FuncSpan] Failed to initialize config loader:",
|
|
853
|
-
}), process.env.SF_WORKER_POOL_DISABLED === "true" ? n.sfDebug && console.log("[setupInterceptors] Worker pool patching DISABLED (SF_WORKER_POOL_DISABLED=true)") :
|
|
854
|
-
const
|
|
855
|
-
|
|
856
|
-
const
|
|
857
|
-
new
|
|
858
|
-
const
|
|
859
|
-
|
|
911
|
+
Je() || je(void 0, n.sfDebug).catch((a) => {
|
|
912
|
+
n.sfDebug && console.error("[FuncSpan] Failed to initialize config loader:", a);
|
|
913
|
+
}), process.env.SF_WORKER_POOL_DISABLED === "true" ? n.sfDebug && console.log("[setupInterceptors] Worker pool patching DISABLED (SF_WORKER_POOL_DISABLED=true)") : tt() || (et(), n.sfDebug && console.log("[setupInterceptors] Worker pool patching initialized (DNS tracking enabled)"));
|
|
914
|
+
const s = new Q();
|
|
915
|
+
s.setServiceUUID(n.serviceUUID), Pe(s), (function(a = []) {
|
|
916
|
+
const o = new Ge(a);
|
|
917
|
+
new Me().doSend(o.getExcludedDomains());
|
|
918
|
+
const d = new xe(), p = new Be();
|
|
919
|
+
o.patchFetch(d, p), o.patchHttp(d, p);
|
|
860
920
|
})(n.domainsToNotPropagateHeadersTo);
|
|
861
|
-
const
|
|
862
|
-
|
|
921
|
+
const l = new Ae();
|
|
922
|
+
l.setServiceUUID(n.serviceUUID), Ee(l), He(), new Ke().send(), J = !0, n.sfDebug && console.log("[setupInterceptors] ✅ Initialization complete");
|
|
863
923
|
} finally {
|
|
864
|
-
|
|
924
|
+
B = !1;
|
|
865
925
|
}
|
|
866
926
|
}
|
|
867
927
|
}
|
|
868
|
-
function
|
|
869
|
-
return
|
|
928
|
+
function gt() {
|
|
929
|
+
return J;
|
|
870
930
|
}
|
|
871
|
-
function
|
|
872
|
-
const n =
|
|
931
|
+
function ht(r, t, e, i = !1) {
|
|
932
|
+
const n = f();
|
|
873
933
|
new pe(n.apiKey).identify(r, t, e, i);
|
|
874
934
|
}
|
|
875
|
-
function
|
|
876
|
-
const n =
|
|
935
|
+
function mt(r, t = {}, e, i = !1) {
|
|
936
|
+
const n = f();
|
|
877
937
|
new pe(n.apiKey).addOrUpdateMetadata(r, t, e, i);
|
|
878
938
|
}
|
|
879
|
-
let
|
|
880
|
-
function
|
|
881
|
-
const n = function(...
|
|
882
|
-
const
|
|
883
|
-
|
|
884
|
-
const
|
|
885
|
-
const
|
|
886
|
-
if (
|
|
887
|
-
const
|
|
888
|
-
if (
|
|
939
|
+
let G = null;
|
|
940
|
+
function yt(r, t, e, i) {
|
|
941
|
+
const n = function(...s) {
|
|
942
|
+
const l = de(), a = l?.sfDebug || !1;
|
|
943
|
+
a && console.log(`[FuncSpan] captureFunctionSpan wrapper called for ${e}::${t}`);
|
|
944
|
+
const o = (function(h, v) {
|
|
945
|
+
const I = W();
|
|
946
|
+
if (I) {
|
|
947
|
+
const _ = j(I);
|
|
948
|
+
if (_) return process.env.SF_DEBUG === "true" && console.log(`[FuncSpan] Using HTTP header override for ${h}::${v}`), _;
|
|
889
949
|
}
|
|
890
950
|
try {
|
|
891
|
-
return ze(
|
|
951
|
+
return ze(h, v);
|
|
892
952
|
} catch {
|
|
893
953
|
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 };
|
|
894
954
|
}
|
|
895
955
|
})(e, t);
|
|
896
|
-
if (
|
|
897
|
-
if (
|
|
898
|
-
|
|
899
|
-
const
|
|
900
|
-
|
|
901
|
-
const
|
|
902
|
-
let
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
}),
|
|
956
|
+
if (a && console.log(`[FuncSpan] Config for ${e}::${t}:`, o), o.enable_sampling && o.sample_rate < 1 && Math.random() > o.sample_rate) return a && console.log(`[FuncSpan] Skipping ${t} due to sampling`), r.apply(this, s);
|
|
957
|
+
if (o.sample_rate === 0) return a && console.log(`[FuncSpan] Skipping ${t} - sample_rate is 0.0`), r.apply(this, s);
|
|
958
|
+
a && console.log(`[FuncSpan] Capturing function span for ${t}`);
|
|
959
|
+
const d = V.getInstance(), p = d.getCurrentFunctionSpanId(), c = K();
|
|
960
|
+
d.setCurrentFunctionSpanId(c);
|
|
961
|
+
const g = process.hrtime.bigint(), m = Date.now();
|
|
962
|
+
let u = null;
|
|
963
|
+
o.capture_arguments && (u = {}, i.paramNames.forEach((h, v) => {
|
|
964
|
+
v < s.length && (u[h] = s[v]);
|
|
965
|
+
}), u && o.arg_limit_mb > 0 && (u = M(u, o.arg_limit_mb)));
|
|
906
966
|
try {
|
|
907
|
-
const
|
|
908
|
-
if (
|
|
909
|
-
const
|
|
910
|
-
let
|
|
911
|
-
return
|
|
912
|
-
}, (
|
|
913
|
-
const
|
|
914
|
-
throw
|
|
967
|
+
const h = r.apply(this, s);
|
|
968
|
+
if (h && typeof h.then == "function") return p ? d.setCurrentFunctionSpanId(p) : d.clearCurrentFunctionSpanId(), h.then((F) => {
|
|
969
|
+
const $ = process.hrtime.bigint(), N = Date.now(), P = Number($ - g);
|
|
970
|
+
let X = null;
|
|
971
|
+
return o.capture_return_value && o.return_limit_mb > 0 && (X = M(F, o.return_limit_mb)), L({ functionName: t, filePath: e, metadata: i, args: u, result: X, error: null, duration: N - m, durationNs: P, startTimeNs: g.toString(), async: !0, spanId: c, parentSpanId: p, pid: process.pid, threadId: O }), F;
|
|
972
|
+
}, (F) => {
|
|
973
|
+
const $ = process.hrtime.bigint(), N = Date.now(), P = Number($ - g);
|
|
974
|
+
throw L({ functionName: t, filePath: e, metadata: i, args: u, result: null, error: F?.message || String(F), duration: N - m, durationNs: P, startTimeNs: g.toString(), async: !0, spanId: c, parentSpanId: p, pid: process.pid, threadId: O }), F;
|
|
915
975
|
});
|
|
916
|
-
const
|
|
917
|
-
let
|
|
918
|
-
return
|
|
919
|
-
} catch (
|
|
920
|
-
const
|
|
921
|
-
throw
|
|
976
|
+
const v = process.hrtime.bigint(), I = Date.now(), _ = Number(v - g);
|
|
977
|
+
let S = null;
|
|
978
|
+
return o.capture_return_value && o.return_limit_mb > 0 && (S = M(h, o.return_limit_mb)), L({ functionName: t, filePath: e, metadata: i, args: u, result: S, error: null, duration: I - m, durationNs: _, startTimeNs: g.toString(), async: !1, spanId: c, parentSpanId: p, pid: process.pid, threadId: O }), p ? d.setCurrentFunctionSpanId(p) : d.clearCurrentFunctionSpanId(), h;
|
|
979
|
+
} catch (h) {
|
|
980
|
+
const v = process.hrtime.bigint(), I = Date.now(), _ = Number(v - g);
|
|
981
|
+
throw L({ functionName: t, filePath: e, metadata: i, args: u, result: null, error: h?.message || String(h), duration: I - m, durationNs: _, startTimeNs: g.toString(), async: !1, spanId: c, parentSpanId: p, pid: process.pid, threadId: O }), p ? d.setCurrentFunctionSpanId(p) : d.clearCurrentFunctionSpanId(), h;
|
|
922
982
|
}
|
|
923
983
|
};
|
|
924
984
|
Object.defineProperty(n, "name", { value: t, writable: !1 });
|
|
925
|
-
for (const
|
|
985
|
+
for (const s in r) r.hasOwnProperty(s) && (n[s] = r[s]);
|
|
926
986
|
return n;
|
|
927
987
|
}
|
|
928
|
-
function
|
|
929
|
-
const t =
|
|
988
|
+
function L(r) {
|
|
989
|
+
const t = de(), e = t?.sfDebug || !1;
|
|
930
990
|
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 });
|
|
931
991
|
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 };
|
|
932
992
|
process.env.SF_FUNCSPAN_CONSOLE_OUTPUT === "true" && console.log(`
|
|
933
993
|
📊 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" });
|
|
934
994
|
const n = process.env.SF_FUNCSPAN_JSONL_FILE;
|
|
935
995
|
if (n) try {
|
|
936
|
-
const
|
|
996
|
+
const s = n === "true" || n === "1" ? "funcspans.jsonl" : n, l = Date.now(), a = process.hrtime.bigint(), o = BigInt(r.startTimeNs), d = Number(a - o) / 1e6, p = new Date(l - d).toISOString(), c = 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 }) + `
|
|
937
997
|
`;
|
|
938
|
-
|
|
939
|
-
} catch (
|
|
940
|
-
console.error("[FuncSpan] Error writing to JSONL file:",
|
|
998
|
+
ke(s, c, "utf-8");
|
|
999
|
+
} catch (s) {
|
|
1000
|
+
console.error("[FuncSpan] Error writing to JSONL file:", s);
|
|
941
1001
|
}
|
|
942
1002
|
if (e && console.log("[FuncSpan] Sending function span to transmitter:", i), process.env.SF_FUNCSPAN_SKIP_BACKEND !== "true") try {
|
|
943
|
-
(
|
|
944
|
-
} catch (
|
|
945
|
-
e && console.error("[FuncSpan] Error sending function span:",
|
|
1003
|
+
(G || (G = new Fe()), G).send([i]), e && console.log("[FuncSpan] Function span sent successfully");
|
|
1004
|
+
} catch (s) {
|
|
1005
|
+
e && console.error("[FuncSpan] Error sending function span:", s);
|
|
946
1006
|
}
|
|
947
1007
|
}
|
|
948
|
-
function
|
|
1008
|
+
function St(r) {
|
|
949
1009
|
return !!r.includes("captureFunctionSpan(") || !!r.includes("@sailfish-ai/sf-veritas") || !(!r.includes("/* @sailfish-instrumented */") && !r.includes("// @sailfish-instrumented"));
|
|
950
1010
|
}
|
|
951
1011
|
export {
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
1012
|
+
V as ContextManager,
|
|
1013
|
+
mt as addOrUpdateMetadata,
|
|
1014
|
+
yt as captureFunctionSpan,
|
|
1015
|
+
bt as clearFuncspanOverride,
|
|
1016
|
+
H as getCurrentFunctionSpanId,
|
|
1017
|
+
le as getDefaultConfig,
|
|
958
1018
|
$e as getEnvConfig,
|
|
959
|
-
|
|
1019
|
+
W as getFuncspanOverride,
|
|
960
1020
|
ze as getGlobalConfig,
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
1021
|
+
ht as identify,
|
|
1022
|
+
je as initializeConfigLoader,
|
|
1023
|
+
et as initializeWorkerPoolPatching,
|
|
1024
|
+
St as isAlreadyInstrumented,
|
|
1025
|
+
Je as isConfigLoaderInitialized,
|
|
1026
|
+
Dt as isProductionEnvironment,
|
|
1027
|
+
wt as isRuntimeModeEnabled,
|
|
1028
|
+
gt as isSetupInterceptorsInitialized,
|
|
1029
|
+
tt as isWorkerPoolInitialized,
|
|
1030
|
+
j as parseHeaderOverride,
|
|
1031
|
+
$t as runWithContext,
|
|
1032
|
+
Ft as setFuncspanOverride,
|
|
1033
|
+
Rt as setSkipTypeScriptPlugin,
|
|
1034
|
+
ft as setupInterceptors,
|
|
1035
|
+
Pt as shouldEnableRuntimeHooks,
|
|
1036
|
+
Tt as transformFunctionSpans,
|
|
1037
|
+
Ct as transformFunctionSpansSync
|
|
978
1038
|
};
|