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