@sailfish-ai/sf-veritas 0.2.13 → 0.2.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/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-DIsq-KCn.cjs → runtimeConfig-TWzqPe1S.cjs} +7 -7
- package/dist/sf-veritas.cjs +37 -12
- package/dist/sf-veritas.mjs +574 -509
- package/dist/types/funcSpanConfig.d.ts +0 -4
- package/dist/types/funcSpanConfigLoader.d.ts +1 -1
- 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-D85i6nhQ.cjs → workerPoolSpanCapture-COwiNikM.cjs} +2 -2
- package/dist/{workerPoolSpanCapture-BYaf3NOr.js → workerPoolSpanCapture-d-8ExI18.js} +84 -82
- package/package.json +2 -1
- package/dist/contextManager-BkETRITg.cjs +0 -1
- package/dist/contextManager-CEPhVu9T.js +0 -197
- package/dist/funcSpanTransformer-B9WWl-g1.cjs +0 -1
- package/dist/funcSpanTransformer-CWNEWRxq.js +0 -225
package/dist/sf-veritas.mjs
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
var
|
|
2
|
-
var fe = (
|
|
3
|
-
var
|
|
4
|
-
import { g as
|
|
5
|
-
import { r as ft } from "./contextManager-
|
|
6
|
-
import { B as
|
|
7
|
-
import { e as
|
|
8
|
-
import { C as
|
|
9
|
-
import { d as
|
|
1
|
+
var ge = Object.defineProperty;
|
|
2
|
+
var fe = (r, t, e) => t in r ? ge(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
|
|
3
|
+
var y = (r, t, e) => fe(r, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
import { g as u, C as j, D as he, v as se, b as q, c as me, a as oe } from "./contextManager-Cx03mw7l.js";
|
|
5
|
+
import { r as ft } from "./contextManager-Cx03mw7l.js";
|
|
6
|
+
import { B as T, n as E, f as ye, g as ae, p as ce, a as de, b as Se, m as U, c as A, d as Ie, i as R, t as H, F as ve } from "./workerPoolSpanCapture-d-8ExI18.js";
|
|
7
|
+
import { e as mt, s as yt } from "./workerPoolSpanCapture-d-8ExI18.js";
|
|
8
|
+
import { C as $e, i as _, a as _e, h as P, b as be, c as Ne } from "./runtimeConfig-DndXTWki.js";
|
|
9
|
+
import { d as It, e as vt, s as $t } from "./runtimeConfig-DndXTWki.js";
|
|
10
10
|
import { createRequire as Fe } from "node:module";
|
|
11
|
-
import * as
|
|
12
|
-
import { readFileSync as
|
|
13
|
-
import { s as
|
|
14
|
-
import * as
|
|
15
|
-
import { glob as
|
|
16
|
-
import { threadId as
|
|
17
|
-
import { s as
|
|
18
|
-
class
|
|
11
|
+
import * as M from "fs";
|
|
12
|
+
import { readFileSync as De, appendFileSync as Pe } from "fs";
|
|
13
|
+
import { s as Ee } from "./source-map-Cr6YkjTd.js";
|
|
14
|
+
import * as F from "path";
|
|
15
|
+
import { glob as we } from "glob";
|
|
16
|
+
import { threadId as O } from "worker_threads";
|
|
17
|
+
import { s as bt, t as Nt, a as Ft } from "./funcSpanTransformer-Byqzu4B1.js";
|
|
18
|
+
class C extends T {
|
|
19
19
|
constructor() {
|
|
20
20
|
super(), this.setOperationName("IdentifyServiceDetails");
|
|
21
21
|
}
|
|
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
|
|
66
|
+
function Te(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 Ce extends
|
|
73
|
+
class Ce extends T {
|
|
66
74
|
constructor() {
|
|
67
75
|
super();
|
|
68
|
-
|
|
76
|
+
y(this, "serviceIdentifier", new C());
|
|
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)) Te(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 `
|
|
@@ -97,35 +105,35 @@ class Ce extends D {
|
|
|
97
105
|
}
|
|
98
106
|
}
|
|
99
107
|
class ue {
|
|
100
|
-
constructor(
|
|
101
|
-
|
|
102
|
-
this.apiKey =
|
|
108
|
+
constructor(t) {
|
|
109
|
+
y(this, "metadataTransmitter");
|
|
110
|
+
this.apiKey = t, this.metadataTransmitter = new Ce();
|
|
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 V extends
|
|
120
|
+
class V extends T {
|
|
113
121
|
constructor() {
|
|
114
122
|
super();
|
|
115
|
-
|
|
123
|
+
y(this, "serviceIdentifier", new C());
|
|
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 Ue extends T {
|
|
160
168
|
constructor() {
|
|
161
169
|
super();
|
|
162
|
-
|
|
163
|
-
|
|
170
|
+
y(this, "serviceIdentifier", new C());
|
|
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($e.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 `
|
|
@@ -213,59 +221,59 @@ class Te extends D {
|
|
|
213
221
|
`;
|
|
214
222
|
}
|
|
215
223
|
}
|
|
216
|
-
const
|
|
217
|
-
var
|
|
218
|
-
const x = "http:", G = "https:",
|
|
219
|
-
let
|
|
220
|
-
function
|
|
221
|
-
const
|
|
222
|
-
if (
|
|
223
|
-
let
|
|
224
|
-
|
|
224
|
+
const X = "getting request source code";
|
|
225
|
+
var k = ((r) => (r.UNKNOWN = "unknown", r.ANONYMOUS = "anonymous", r.NOT_CAPTURED = "not captured", r))(k || {});
|
|
226
|
+
const x = "http:", G = "https:", Re = Fe(import.meta.url);
|
|
227
|
+
let Y = !1;
|
|
228
|
+
function Oe() {
|
|
229
|
+
const r = u().sfDebug;
|
|
230
|
+
if (Y) return void (r && _("[patchNodeHttpInbound] Already installed, skipping."));
|
|
231
|
+
let t;
|
|
232
|
+
Y = !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 = Re("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 = j.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
|
|
262
|
+
return ye.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 Le extends V {
|
|
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 Ae extends T {
|
|
285
293
|
constructor() {
|
|
286
294
|
super();
|
|
287
|
-
|
|
295
|
+
y(this, "serviceIdentifier", new C());
|
|
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 ke extends T {
|
|
329
337
|
constructor() {
|
|
330
338
|
super();
|
|
331
|
-
|
|
339
|
+
y(this, "serviceIdentifier", new C());
|
|
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,203 @@ 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
363
|
const K = [400, 403];
|
|
356
|
-
class
|
|
357
|
-
constructor(
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
this.contextManager =
|
|
364
|
-
typeof
|
|
365
|
-
}),
|
|
366
|
-
}
|
|
367
|
-
extractIdsFromTraceHeader(
|
|
368
|
-
let
|
|
369
|
-
if (
|
|
364
|
+
class qe {
|
|
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 = j.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
|
-
|
|
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
|
+
if (t.includes("://")) return { originalPos: n };
|
|
398
|
+
const o = t + ".map";
|
|
390
399
|
try {
|
|
391
|
-
const d = JSON.parse(
|
|
392
|
-
let
|
|
393
|
-
|
|
400
|
+
const d = JSON.parse(De(o, "utf-8"));
|
|
401
|
+
let s = (await new Ee.SourceMapConsumer(d)).originalPositionFor({ line: e, column: i });
|
|
402
|
+
s.source && (n = s);
|
|
394
403
|
} catch (d) {
|
|
395
|
-
|
|
404
|
+
u().sfDebug && console.error(`Could not read/parse map file at ${o}:`, d);
|
|
396
405
|
}
|
|
397
|
-
return { originalPos:
|
|
398
|
-
}
|
|
399
|
-
captureFirstUserLines(
|
|
400
|
-
const
|
|
401
|
-
Error.stackTraceLimit = Math.max(o,
|
|
402
|
-
const d = new Error(
|
|
403
|
-
|
|
404
|
-
const
|
|
406
|
+
return { originalPos: n };
|
|
407
|
+
}
|
|
408
|
+
captureFirstUserLines(t, e = 10, i = !1) {
|
|
409
|
+
const n = u().sfDebug ? 10 : e, o = Error.stackTraceLimit;
|
|
410
|
+
Error.stackTraceLimit = Math.max(o, n);
|
|
411
|
+
const d = new Error(X);
|
|
412
|
+
X in Error && Error.captureStackTrace(d, this.captureFirstUserLines);
|
|
413
|
+
const s = d.stack || "";
|
|
405
414
|
Error.stackTraceLimit = o;
|
|
406
|
-
const c =
|
|
415
|
+
const c = s.split(`
|
|
407
416
|
`).slice(1), a = [];
|
|
408
|
-
for (const
|
|
409
|
-
if (!(
|
|
410
|
-
for (const
|
|
411
|
-
const
|
|
412
|
-
|
|
413
|
-
const { originalPos:
|
|
414
|
-
if (
|
|
415
|
-
|
|
416
|
-
const
|
|
417
|
-
|
|
417
|
+
for (const l of c)
|
|
418
|
+
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;
|
|
419
|
+
for (const l of a) {
|
|
420
|
+
const g = this.parseStackFrame(l);
|
|
421
|
+
g ? (async () => {
|
|
422
|
+
const { originalPos: f } = await this.getOriginalPosition(g.filePath, g.line, g.column);
|
|
423
|
+
if (f) {
|
|
424
|
+
u().sfDebug && console.log("[RequestInterceptor] First user code line:", f);
|
|
425
|
+
const h = { line: f.line?.toString() || k.UNKNOWN, column: f.column?.toString() || k.NOT_CAPTURED, name: f.name || k.NOT_CAPTURED, entrypoint: f.source, retryWithoutTraceId: i };
|
|
426
|
+
t.doSend(h);
|
|
418
427
|
}
|
|
419
|
-
})() :
|
|
428
|
+
})() : u().sfDebug && console.error("Could not parse stack line:", l);
|
|
420
429
|
}
|
|
421
430
|
}
|
|
422
|
-
addReentrancyGuardHeaders(
|
|
423
|
-
|
|
431
|
+
addReentrancyGuardHeaders(t) {
|
|
432
|
+
t.set(this.HEADER_LOG_GUARD, "true"), t.set(this.HEADER_PRINT_GUARD, "true"), t.set(this.HEADER_EXCEPTION_GUARD, "true");
|
|
424
433
|
}
|
|
425
|
-
shouldPropagateHeaders(
|
|
426
|
-
return !he.some((
|
|
434
|
+
shouldPropagateHeaders(t) {
|
|
435
|
+
return !he.some((e) => new RegExp(`^${e.replace(/\*/g, ".*")}$`).test(t));
|
|
427
436
|
}
|
|
428
|
-
addTracingHeaders(
|
|
429
|
-
const
|
|
430
|
-
return
|
|
437
|
+
addTracingHeaders(t, e) {
|
|
438
|
+
const i = new URL(e).hostname, n = this.shouldPropagateHeaders(i);
|
|
439
|
+
return n ? this.addTracingHeader(t, e) : u().sfDebug && console.error(`[RequestInterceptor] Excluded domain: ${i}`), n;
|
|
431
440
|
}
|
|
432
|
-
addTracingHeader(
|
|
433
|
-
const
|
|
434
|
-
if (
|
|
435
|
-
const
|
|
436
|
-
if (
|
|
441
|
+
addTracingHeader(t, e) {
|
|
442
|
+
const i = ae();
|
|
443
|
+
if (i) {
|
|
444
|
+
const s = ce(i);
|
|
445
|
+
if (s && s.sample_rate === 0) return void (u().sfDebug && console.log(`[RequestInterceptor] Function span tracking disabled (sample_rate=0), skipping tracing header for ${e}`));
|
|
437
446
|
}
|
|
438
|
-
const
|
|
439
|
-
|
|
447
|
+
const n = this.contextManager.getOrSetSfTraceId(), o = this.contextManager.getOrSetPageVisitUUID(), d = se();
|
|
448
|
+
t.set(this.HEADER_TRACING, `${n}/${o}/${d}`), u().sfDebug && console.log(`[RequestInterceptor] Added tracing header for ${e}`);
|
|
440
449
|
}
|
|
441
|
-
patchFetch(
|
|
442
|
-
const
|
|
443
|
-
typeof
|
|
450
|
+
patchFetch(t, e) {
|
|
451
|
+
const i = globalThis.fetch;
|
|
452
|
+
typeof i == "function" ? globalThis.fetch = async (n, o) => {
|
|
444
453
|
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
|
|
454
|
+
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);
|
|
455
|
+
this.captureFirstUserLines(t);
|
|
456
|
+
const s = Date.now();
|
|
448
457
|
let c;
|
|
449
|
-
typeof
|
|
450
|
-
d.set(
|
|
451
|
-
})) :
|
|
452
|
-
const a = new URL(c).hostname,
|
|
453
|
-
let
|
|
458
|
+
typeof n == "string" || n instanceof URL ? c = n.toString() : n instanceof Request ? (c = n.url, n.headers.forEach((p, m) => {
|
|
459
|
+
d.set(m, p);
|
|
460
|
+
})) : u().sfDebug && console.error("[Sailfish RequestInterceptor] Invalid fetch input."), u().sfDebug && console.log("[RequestInterceptor] Fetching request to:", c);
|
|
461
|
+
const a = new URL(c).hostname, l = new Headers(d), g = this.addTracingHeaders(d, c), f = { ...o, headers: d };
|
|
462
|
+
let h;
|
|
454
463
|
try {
|
|
455
464
|
let p = !1;
|
|
456
|
-
this.addTracingHeaders(
|
|
457
|
-
const
|
|
458
|
-
|
|
459
|
-
const { sessionId:
|
|
460
|
-
|
|
465
|
+
this.addTracingHeaders(l, c), h = await i(c, f), g && K.includes(h.status) ? (h = await i(c, { ...o, headers: l }), p = !0, this.captureFirstUserLines(t, 10, p)) : this.contextManager.addSupportedDomains(a);
|
|
466
|
+
const m = Date.now();
|
|
467
|
+
u().sfDebug && console.log(`[RequestInterceptor] Fetch completed: ${c}, Status: ${h.status}, Duration: ${m - s}ms`);
|
|
468
|
+
const { sessionId: I, pageVisitId: v, requestId: D } = this.extractIdsFromTraceHeader(d), $ = u(), b = { apiKey: $.apiKey, requestId: D, pageVisitId: v, recordingSessionId: I, serviceUuid: $.serviceUUID, timestampStart: s.toString(), timestampEnd: m.toString(), responseCode: h.status, success: !0, error: null, url: c, method: f.method || "GET", retryWithoutTraceId: p, parentSpanId: q() };
|
|
469
|
+
if ($.captureRequestHeaders) {
|
|
470
|
+
const S = {};
|
|
471
|
+
d.forEach((N, w) => {
|
|
472
|
+
S[w] = N;
|
|
473
|
+
}), b.requestHeaders = S;
|
|
474
|
+
}
|
|
475
|
+
if ($.captureResponseHeaders) {
|
|
476
|
+
const S = {};
|
|
477
|
+
h.headers.forEach((N, w) => {
|
|
478
|
+
S[w] = N;
|
|
479
|
+
}), b.responseHeaders = S;
|
|
480
|
+
}
|
|
481
|
+
if ($.captureRequestBody && o?.body) try {
|
|
482
|
+
const S = typeof o.body == "string" ? o.body : JSON.stringify(o.body);
|
|
483
|
+
b.requestBody = S.length > $.requestBodyLimitBytes ? S.substring(0, $.requestBodyLimitBytes) + "...[truncated]" : S;
|
|
484
|
+
} catch {
|
|
485
|
+
}
|
|
486
|
+
if ($.captureResponseBody) try {
|
|
487
|
+
const S = h.clone(), N = await S.text();
|
|
488
|
+
b.responseBody = N.length > $.responseBodyLimitBytes ? N.substring(0, $.responseBodyLimitBytes) + "...[truncated]" : N;
|
|
489
|
+
} catch {
|
|
490
|
+
}
|
|
491
|
+
return e.doSend(b), h;
|
|
461
492
|
} catch (p) {
|
|
462
|
-
const
|
|
463
|
-
|
|
493
|
+
const m = Date.now();
|
|
494
|
+
u().sfDebug && console.error(`[RequestInterceptor] Fetch failed: ${c}, Error: ${p}, Duration: ${m - s}ms`);
|
|
464
495
|
}
|
|
465
|
-
} :
|
|
496
|
+
} : u().sfDebug && console.error("[RequestInterceptor] Fetch not available.");
|
|
466
497
|
}
|
|
467
|
-
patchHttp(
|
|
468
|
-
if (
|
|
469
|
-
const
|
|
470
|
-
|
|
471
|
-
let
|
|
498
|
+
patchHttp(t, e) {
|
|
499
|
+
if (u().sfDebug && console.log("[RequestInterceptor] Initializing HTTP/HTTPS request patch..."), !P || typeof P.request != "function") return void (u().sfDebug && console.log("[RequestInterceptor] HTTP/HTTPS not available."));
|
|
500
|
+
const i = P.request.bind(P), n = P.request.bind(P);
|
|
501
|
+
P.request = function(o, d) {
|
|
502
|
+
let s;
|
|
472
503
|
try {
|
|
473
504
|
if (typeof o == "string") {
|
|
474
505
|
const a = new URL(o);
|
|
475
|
-
|
|
476
|
-
} else o instanceof URL ?
|
|
477
|
-
if (
|
|
478
|
-
const a = `${
|
|
479
|
-
this.addTracingHeaders(
|
|
480
|
-
} else
|
|
506
|
+
s = { protocol: a.protocol || x, hostname: a.hostname, path: a.pathname + a.search, headers: {} };
|
|
507
|
+
} else o instanceof URL ? s = { protocol: o.protocol || x, hostname: o.hostname, path: o.pathname + o.search, headers: {} } : (s = { ...o }, s.protocol || (s.protocol = x));
|
|
508
|
+
if (s.headers) {
|
|
509
|
+
const a = `${s.protocol}//${s.hostname}`;
|
|
510
|
+
this.addTracingHeaders(s.headers, a), this.captureFirstUserLines(t);
|
|
511
|
+
} else u().sfDebug && console.warn("[RequestInterceptor] No headers found in HTTP request options. Skipping header addition.");
|
|
481
512
|
} catch (a) {
|
|
482
|
-
throw
|
|
513
|
+
throw u().sfDebug && console.error("[RequestInterceptor] Error while processing HTTP request options:", a), a;
|
|
483
514
|
}
|
|
484
515
|
let c = !1;
|
|
485
|
-
return s
|
|
486
|
-
const
|
|
487
|
-
if (
|
|
488
|
-
|
|
489
|
-
const p = { ...
|
|
490
|
-
delete p.headers[this.HEADER_TRACING],
|
|
516
|
+
return i(s, (a) => {
|
|
517
|
+
const l = `${s.protocol}//${s.hostname}`;
|
|
518
|
+
if (s.headers && this.shouldPropagateHeaders(new URL(l).hostname) && K.includes(a.statusCode || 0)) {
|
|
519
|
+
s.hostname;
|
|
520
|
+
const p = { ...s, headers: { ...s.headers } };
|
|
521
|
+
delete p.headers[this.HEADER_TRACING], i(p, d), c = !0, this.captureFirstUserLines(t, 10, c);
|
|
491
522
|
}
|
|
492
|
-
const { sessionId:
|
|
493
|
-
|
|
523
|
+
const { sessionId: g, pageVisitId: f, requestId: h } = this.extractIdsFromTraceHeader(s.headers);
|
|
524
|
+
e.doSend({ apiKey: u().apiKey, requestId: h, pageVisitId: f, recordingSessionId: g, serviceUuid: u().serviceUUID, timestampStart: Date.now().toString(), timestampEnd: Date.now().toString(), responseCode: a.statusCode || 0, success: !!a.statusCode && a.statusCode < 400, error: null, url: l, method: s.method || "GET", retryWithoutTraceId: c, parentSpanId: q() }), d?.(a);
|
|
494
525
|
});
|
|
495
|
-
},
|
|
496
|
-
let
|
|
526
|
+
}, P.request = function(o, d) {
|
|
527
|
+
let s;
|
|
497
528
|
try {
|
|
498
529
|
if (typeof o == "string") {
|
|
499
530
|
const a = new URL(o);
|
|
500
|
-
|
|
501
|
-
} else o instanceof URL ?
|
|
502
|
-
if (
|
|
503
|
-
const a = `${
|
|
504
|
-
this.addTracingHeaders(
|
|
505
|
-
} else
|
|
531
|
+
s = { protocol: a.protocol || G, hostname: a.hostname, path: a.pathname + a.search, headers: {} };
|
|
532
|
+
} else o instanceof URL ? s = { protocol: o.protocol || G, hostname: o.hostname, path: o.pathname + o.search, headers: {} } : (s = { ...o }, s.protocol || (s.protocol = G));
|
|
533
|
+
if (s.headers) {
|
|
534
|
+
const a = `${s.protocol}//${s.hostname}`;
|
|
535
|
+
this.addTracingHeaders(s.headers, a);
|
|
536
|
+
} else u().sfDebug && console.warn("[RequestInterceptor] No headers found in HTTPS request options. Skipping header addition.");
|
|
506
537
|
} catch (a) {
|
|
507
|
-
throw
|
|
538
|
+
throw u().sfDebug && console.error("[RequestInterceptor] Error while processing HTTPS request options:", a), a;
|
|
508
539
|
}
|
|
509
540
|
let c = !1;
|
|
510
|
-
return
|
|
511
|
-
const
|
|
512
|
-
if (
|
|
513
|
-
const p = { ...
|
|
514
|
-
delete p.headers[this.HEADER_TRACING],
|
|
541
|
+
return n(s, (a) => {
|
|
542
|
+
const l = `${s.protocol}//${s.hostname}`;
|
|
543
|
+
if (s.headers && this.shouldPropagateHeaders(new URL(l).hostname) && K.includes(a.statusCode || 0)) {
|
|
544
|
+
const p = { ...s, headers: { ...s.headers } };
|
|
545
|
+
delete p.headers[this.HEADER_TRACING], n(p, d), c = !0, this.captureFirstUserLines(t, 10, c);
|
|
515
546
|
}
|
|
516
|
-
const { sessionId:
|
|
517
|
-
|
|
547
|
+
const { sessionId: g, pageVisitId: f, requestId: h } = this.extractIdsFromTraceHeader(s.headers);
|
|
548
|
+
e.doSend({ apiKey: u().apiKey, requestId: h, pageVisitId: f, recordingSessionId: g, serviceUuid: u().serviceUUID, timestampStart: Date.now().toString(), timestampEnd: Date.now().toString(), responseCode: a.statusCode || 0, success: !!a.statusCode && a.statusCode < 400, error: null, url: l, method: s.method || "GET", retryWithoutTraceId: c, parentSpanId: q() }), d?.(a);
|
|
518
549
|
});
|
|
519
|
-
},
|
|
550
|
+
}, u().sfDebug && console.log("✅ HTTP and HTTPS request methods patched globally.");
|
|
520
551
|
}
|
|
521
|
-
tryPatch(
|
|
552
|
+
tryPatch(t, e) {
|
|
522
553
|
try {
|
|
523
|
-
require.resolve(
|
|
554
|
+
require.resolve(e), t();
|
|
524
555
|
} catch {
|
|
525
556
|
}
|
|
526
557
|
}
|
|
@@ -528,7 +559,7 @@ class ke {
|
|
|
528
559
|
return [...this.contextManager.getExcludedDomains()];
|
|
529
560
|
}
|
|
530
561
|
}
|
|
531
|
-
class
|
|
562
|
+
class He extends V {
|
|
532
563
|
constructor() {
|
|
533
564
|
super(), this.setOperationName("UpdateServiceDetails");
|
|
534
565
|
}
|
|
@@ -536,7 +567,7 @@ class qe extends V {
|
|
|
536
567
|
this.sendAppIdentifier(), this.send();
|
|
537
568
|
}
|
|
538
569
|
async send() {
|
|
539
|
-
const
|
|
570
|
+
const t = `
|
|
540
571
|
${this.queryType} ${this.operationName}(
|
|
541
572
|
$apiKey: String!,
|
|
542
573
|
$serviceUuid: String!,
|
|
@@ -545,6 +576,14 @@ class qe extends V {
|
|
|
545
576
|
$serviceVersion: String,
|
|
546
577
|
$serviceAdditionalMetadata: JSON,
|
|
547
578
|
$gitSha: String!,
|
|
579
|
+
$gitOrg: String,
|
|
580
|
+
$gitRepo: String,
|
|
581
|
+
$gitProvider: String,
|
|
582
|
+
$serviceDisplayName: String,
|
|
583
|
+
$infrastructureType: String,
|
|
584
|
+
$infrastructureDetails: JSON,
|
|
585
|
+
$setupInterceptorsFile: String,
|
|
586
|
+
$setupInterceptorsLine: Int,
|
|
548
587
|
) {
|
|
549
588
|
${this.queryName}(
|
|
550
589
|
apiKey: $apiKey,
|
|
@@ -554,369 +593,395 @@ class qe extends V {
|
|
|
554
593
|
serviceVersion: $serviceVersion,
|
|
555
594
|
serviceAdditionalMetadata: $serviceAdditionalMetadata,
|
|
556
595
|
gitSha: $gitSha,
|
|
596
|
+
gitOrg: $gitOrg,
|
|
597
|
+
gitRepo: $gitRepo,
|
|
598
|
+
gitProvider: $gitProvider,
|
|
599
|
+
serviceDisplayName: $serviceDisplayName,
|
|
600
|
+
infrastructureType: $infrastructureType,
|
|
601
|
+
infrastructureDetails: $infrastructureDetails,
|
|
602
|
+
setupInterceptorsFile: $setupInterceptorsFile,
|
|
603
|
+
setupInterceptorsLine: $setupInterceptorsLine,
|
|
557
604
|
)
|
|
558
605
|
}
|
|
559
|
-
`,
|
|
560
|
-
|
|
606
|
+
`, 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 });
|
|
607
|
+
E(this.endpoint, this.operationName, t, i);
|
|
561
608
|
}
|
|
562
609
|
}
|
|
563
610
|
class Me {
|
|
564
|
-
constructor(
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
this.rootPaths =
|
|
611
|
+
constructor(t = [process.cwd()], e = !1) {
|
|
612
|
+
y(this, "rootPaths");
|
|
613
|
+
y(this, "fileConfigs", /* @__PURE__ */ new Map());
|
|
614
|
+
y(this, "functionConfigs", /* @__PURE__ */ new Map());
|
|
615
|
+
y(this, "directoryConfigs", /* @__PURE__ */ new Map());
|
|
616
|
+
y(this, "hasSailfishFiles", !1);
|
|
617
|
+
y(this, "runtimeModeEnabled", !1);
|
|
618
|
+
y(this, "debug");
|
|
619
|
+
this.rootPaths = t, this.debug = e || process.env.SF_DEBUG === "true";
|
|
573
620
|
}
|
|
574
621
|
async loadAllConfigs() {
|
|
575
622
|
this.debug && console.log("[FuncSpan ConfigLoader] Scanning for .sailfish files in:", this.rootPaths);
|
|
576
|
-
const
|
|
577
|
-
for (const
|
|
578
|
-
|
|
579
|
-
for (const
|
|
623
|
+
const t = [];
|
|
624
|
+
for (const e of this.rootPaths) M.existsSync(e) ? await this._walkDirectory(e, t) : this.debug && console.log(`[FuncSpan ConfigLoader] Root path does not exist: ${e}`);
|
|
625
|
+
t.length > 0 ? (this.hasSailfishFiles = !0, this.debug && (console.log(`[FuncSpan ConfigLoader] Found ${t.length} .sailfish files:`), t.forEach((e) => console.log(`[FuncSpan ConfigLoader] - ${e}`)))) : this.debug && console.log("[FuncSpan ConfigLoader] No .sailfish files found - function spans disabled by default");
|
|
626
|
+
for (const e of t) await this._loadConfigFile(e);
|
|
580
627
|
await this._resolveInheritance(), this.debug && console.log(`[FuncSpan ConfigLoader] Loaded ${this.fileConfigs.size} file configs, ${this.functionConfigs.size} function configs`);
|
|
581
628
|
}
|
|
582
|
-
getConfig(
|
|
583
|
-
const
|
|
584
|
-
let
|
|
585
|
-
if (
|
|
629
|
+
getConfig(t, e) {
|
|
630
|
+
const i = this.hasSailfishFiles ? Se() : de(), n = this._getDirectoryConfig(t), o = F.normalize(t), d = this.fileConfigs.get(o) || {};
|
|
631
|
+
let s = {};
|
|
632
|
+
if (e) {
|
|
586
633
|
const c = this.functionConfigs.get(o);
|
|
587
|
-
c && (
|
|
634
|
+
c && (s = c.get(e) || {});
|
|
588
635
|
}
|
|
589
|
-
return
|
|
636
|
+
return U(i, n, d, s);
|
|
590
637
|
}
|
|
591
638
|
hasRuntimeMode() {
|
|
592
639
|
return this.runtimeModeEnabled;
|
|
593
640
|
}
|
|
594
|
-
async _walkDirectory(
|
|
641
|
+
async _walkDirectory(t, e) {
|
|
595
642
|
try {
|
|
596
|
-
const
|
|
597
|
-
for (const
|
|
598
|
-
const o =
|
|
599
|
-
|
|
643
|
+
const i = M.readdirSync(t, { withFileTypes: !0 });
|
|
644
|
+
for (const n of i) {
|
|
645
|
+
const o = F.join(t, n.name);
|
|
646
|
+
n.isFile() && n.name === ".sailfish" ? e.push(o) : n.name === "node_modules" || n.isDirectory() && n.name.startsWith(".") && n.name !== ".sailfish" || n.isDirectory() && await this._walkDirectory(o, e);
|
|
600
647
|
}
|
|
601
|
-
} catch (
|
|
602
|
-
this.debug && console.error(`[FuncSpan ConfigLoader] Error walking directory ${
|
|
648
|
+
} catch (i) {
|
|
649
|
+
this.debug && console.error(`[FuncSpan ConfigLoader] Error walking directory ${t}:`, i);
|
|
603
650
|
}
|
|
604
651
|
}
|
|
605
|
-
async _loadConfigFile(
|
|
652
|
+
async _loadConfigFile(t) {
|
|
606
653
|
try {
|
|
607
|
-
const
|
|
608
|
-
let
|
|
654
|
+
const e = M.readFileSync(t, "utf-8"), i = F.dirname(t);
|
|
655
|
+
let n = null;
|
|
609
656
|
try {
|
|
610
|
-
|
|
657
|
+
n = JSON.parse(e);
|
|
611
658
|
} catch {
|
|
612
659
|
try {
|
|
613
|
-
|
|
614
|
-
} catch
|
|
615
|
-
|
|
660
|
+
n = require("toml").parse(e);
|
|
661
|
+
} catch {
|
|
662
|
+
try {
|
|
663
|
+
n = require("js-yaml").load(e);
|
|
664
|
+
} catch (o) {
|
|
665
|
+
return void (this.debug && console.error(`[FuncSpan ConfigLoader] Failed to parse ${t} as JSON, TOML, or YAML:`, o));
|
|
666
|
+
}
|
|
616
667
|
}
|
|
617
668
|
}
|
|
618
|
-
if (!
|
|
619
|
-
|
|
620
|
-
} catch (
|
|
621
|
-
this.debug && console.error(`[FuncSpan ConfigLoader] Error loading ${
|
|
669
|
+
if (!n) return;
|
|
670
|
+
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}`));
|
|
671
|
+
} catch (e) {
|
|
672
|
+
this.debug && console.error(`[FuncSpan ConfigLoader] Error loading ${t}:`, e);
|
|
622
673
|
}
|
|
623
674
|
}
|
|
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,
|
|
675
|
+
async _expandFileGlobs(t, e, i) {
|
|
676
|
+
for (const [n, o] of Object.entries(e)) try {
|
|
677
|
+
const d = F.join(t, n), s = await we(d, { absolute: !0, nodir: !0, ignore: ["**/node_modules/**", "**/.git/**"] });
|
|
678
|
+
this.debug && console.log(`[FuncSpan ConfigLoader] Pattern '${n}' matched ${s.length} files`);
|
|
679
|
+
for (const c of s) {
|
|
680
|
+
const a = F.normalize(c), l = U(i, o);
|
|
681
|
+
this.fileConfigs.set(a, l), this.debug && s.length <= 5 && console.log(`[FuncSpan ConfigLoader] - ${c}`);
|
|
631
682
|
}
|
|
632
683
|
} catch (d) {
|
|
633
|
-
this.debug && console.error(`[FuncSpan ConfigLoader] Error expanding glob '${
|
|
684
|
+
this.debug && console.error(`[FuncSpan ConfigLoader] Error expanding glob '${n}':`, d);
|
|
634
685
|
}
|
|
635
686
|
}
|
|
636
|
-
_storeFunctionConfigs(
|
|
637
|
-
for (const [
|
|
638
|
-
const d =
|
|
687
|
+
_storeFunctionConfigs(t, e, i) {
|
|
688
|
+
for (const [n, o] of Object.entries(e)) {
|
|
689
|
+
const d = n.split("::");
|
|
639
690
|
if (d.length !== 2) {
|
|
640
|
-
this.debug && console.warn(`[FuncSpan ConfigLoader] Invalid function pattern '${
|
|
691
|
+
this.debug && console.warn(`[FuncSpan ConfigLoader] Invalid function pattern '${n}' (expected format: 'file.ts::functionName')`);
|
|
641
692
|
continue;
|
|
642
693
|
}
|
|
643
|
-
const [
|
|
694
|
+
const [s, c] = d, a = F.normalize(F.join(t, s));
|
|
644
695
|
this.functionConfigs.has(a) || this.functionConfigs.set(a, /* @__PURE__ */ new Map());
|
|
645
|
-
const
|
|
646
|
-
|
|
696
|
+
const l = this.functionConfigs.get(a), g = U(i, o);
|
|
697
|
+
l.set(c, g), this.debug && console.log(`[FuncSpan ConfigLoader] Function config: ${a}::${c}`);
|
|
647
698
|
}
|
|
648
699
|
}
|
|
649
700
|
async _resolveInheritance() {
|
|
650
701
|
}
|
|
651
|
-
_getDirectoryConfig(
|
|
652
|
-
let
|
|
653
|
-
const
|
|
654
|
-
for (;
|
|
655
|
-
const
|
|
656
|
-
|
|
702
|
+
_getDirectoryConfig(t) {
|
|
703
|
+
let e = F.dirname(F.normalize(t));
|
|
704
|
+
const i = [];
|
|
705
|
+
for (; e && e !== F.dirname(e); ) {
|
|
706
|
+
const n = this.directoryConfigs.get(e);
|
|
707
|
+
n && i.unshift(n), e = F.dirname(e);
|
|
657
708
|
}
|
|
658
|
-
return
|
|
709
|
+
return i.reduce((n, o) => U(n, o), {});
|
|
659
710
|
}
|
|
660
711
|
}
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
712
|
+
const le = "__sf_globalConfigLoader";
|
|
713
|
+
function pe() {
|
|
714
|
+
return globalThis[le] ?? null;
|
|
664
715
|
}
|
|
665
|
-
function xe(
|
|
666
|
-
|
|
716
|
+
async function xe(r, t) {
|
|
717
|
+
const e = new Me(r, t);
|
|
718
|
+
(function(i) {
|
|
719
|
+
globalThis[le] = i;
|
|
720
|
+
})(e), await e.loadAllConfigs();
|
|
667
721
|
}
|
|
668
|
-
function Ge() {
|
|
669
|
-
|
|
722
|
+
function Ge(r, t) {
|
|
723
|
+
const e = pe();
|
|
724
|
+
return e ? e.getConfig(r, t) : (process.env.SF_DEBUG === "true" && console.log("[FuncSpan ConfigLoader] Config loader not initialized, using default config (disabled)"), de());
|
|
670
725
|
}
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
726
|
+
function Ke() {
|
|
727
|
+
return pe() !== null;
|
|
728
|
+
}
|
|
729
|
+
const We = ["readFile", "writeFile", "appendFile", "readdir", "stat", "lstat", "fstat", "access", "open", "close", "read", "write", "chmod", "mkdir", "rmdir", "unlink", "rename"], Z = ["lookup", "resolve", "resolve4", "resolve6", "resolveAny", "resolveMx", "resolveNs", "resolveTxt", "reverse"], Be = ["pbkdf2", "randomBytes", "scrypt", "generateKeyPair"], ze = ["gzip", "gunzip", "deflate", "inflate", "deflateRaw", "inflateRaw", "brotliCompress", "brotliDecompress"];
|
|
730
|
+
let ee = !1;
|
|
731
|
+
function Je(r) {
|
|
732
|
+
if (typeof r != "string") return !1;
|
|
733
|
+
const t = process.env.SF_FUNCSPAN_JSONL_FILE;
|
|
734
|
+
if (t && r.includes(t)) return !0;
|
|
735
|
+
const e = process.env.SF_WORKER_POOL_JSONL_FILE;
|
|
736
|
+
return !(!e || !r.includes(e));
|
|
679
737
|
}
|
|
680
|
-
let
|
|
681
|
-
function
|
|
682
|
-
if (typeof
|
|
683
|
-
if (
|
|
738
|
+
let te = !1;
|
|
739
|
+
function ne(r) {
|
|
740
|
+
if (typeof r != "string") return !1;
|
|
741
|
+
if (r === "localhost" || r === "127.0.0.1" || r === "::1") return !0;
|
|
684
742
|
try {
|
|
685
|
-
const
|
|
686
|
-
if (
|
|
743
|
+
const t = process.env.API_GRAPHQL_ENDPOINT;
|
|
744
|
+
if (t && r === new URL(t).hostname)
|
|
687
745
|
return !0;
|
|
688
746
|
} catch {
|
|
689
747
|
}
|
|
690
748
|
return !1;
|
|
691
749
|
}
|
|
692
|
-
function
|
|
693
|
-
if (!
|
|
694
|
-
let
|
|
750
|
+
function je() {
|
|
751
|
+
if (!te) try {
|
|
752
|
+
let r;
|
|
695
753
|
if (typeof require > "u") return void (process.env.SF_DEBUG === "true" && console.log("[WorkerPool] Skipping dns patching in pure ESM environment (require unavailable)"));
|
|
696
754
|
try {
|
|
697
|
-
|
|
698
|
-
} catch (
|
|
699
|
-
return void (process.env.SF_DEBUG === "true" && console.log("[WorkerPool] Failed to require dns module:",
|
|
755
|
+
r = require("node:dns");
|
|
756
|
+
} catch (t) {
|
|
757
|
+
return void (process.env.SF_DEBUG === "true" && console.log("[WorkerPool] Failed to require dns module:", t));
|
|
700
758
|
}
|
|
701
|
-
if (
|
|
702
|
-
Object.defineProperty(
|
|
703
|
-
for (const
|
|
704
|
-
const
|
|
705
|
-
|
|
706
|
-
return
|
|
707
|
-
}, Object.defineProperty(
|
|
759
|
+
if (r.__sf_worker_pool_patched__) return;
|
|
760
|
+
Object.defineProperty(r, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
761
|
+
for (const t of Z) if (typeof r[t] == "function") {
|
|
762
|
+
const e = r[t];
|
|
763
|
+
r[t] = function(...i) {
|
|
764
|
+
return ne(i[0]) ? e.apply(this, i) : typeof i[i.length - 1] == "function" ? A("dns", t, e, i, this) : e.apply(this, i);
|
|
765
|
+
}, Object.defineProperty(r[t], "name", { value: t, writable: !1 });
|
|
708
766
|
}
|
|
709
|
-
(function(
|
|
710
|
-
if (!
|
|
711
|
-
if (!
|
|
712
|
-
Object.defineProperty(
|
|
713
|
-
for (const
|
|
714
|
-
const
|
|
715
|
-
|
|
716
|
-
return
|
|
717
|
-
}, Object.defineProperty(
|
|
767
|
+
(function(t) {
|
|
768
|
+
if (!t.promises) return void (process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns.promises not available, skipping"));
|
|
769
|
+
if (!t.promises.__sf_worker_pool_patched__) {
|
|
770
|
+
Object.defineProperty(t.promises, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
771
|
+
for (const e of Z) if (typeof t.promises[e] == "function") {
|
|
772
|
+
const i = t.promises[e];
|
|
773
|
+
t.promises[e] = function(...n) {
|
|
774
|
+
return ne(n[0]) ? i.apply(this, n) : Ie("dns", e, i, n, this);
|
|
775
|
+
}, Object.defineProperty(t.promises[e], "name", { value: e, writable: !1 });
|
|
718
776
|
}
|
|
719
777
|
process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns.promises module patched successfully");
|
|
720
778
|
}
|
|
721
|
-
})(
|
|
722
|
-
} catch (
|
|
723
|
-
console.error("[WorkerPool] Error patching dns module:",
|
|
779
|
+
})(r), te = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns module patched successfully");
|
|
780
|
+
} catch (r) {
|
|
781
|
+
console.error("[WorkerPool] Error patching dns module:", r);
|
|
724
782
|
}
|
|
725
783
|
}
|
|
726
|
-
let
|
|
727
|
-
function
|
|
728
|
-
if (
|
|
729
|
-
const
|
|
730
|
-
|
|
731
|
-
if (!
|
|
732
|
-
const
|
|
733
|
-
if (
|
|
734
|
-
Object.defineProperty(
|
|
735
|
-
for (const
|
|
736
|
-
const
|
|
737
|
-
e
|
|
738
|
-
return
|
|
739
|
-
}, Object.defineProperty(e
|
|
784
|
+
let re = !1, ie = !1, z = !1;
|
|
785
|
+
function Ve() {
|
|
786
|
+
if (z) return;
|
|
787
|
+
const r = process.env.SF_DEBUG === "true";
|
|
788
|
+
r && console.log("[WorkerPool] Initializing worker pool patching..."), R("fs") && (r && console.log("[WorkerPool] Patching fs module..."), (function() {
|
|
789
|
+
if (!ee) try {
|
|
790
|
+
const t = require("node:fs");
|
|
791
|
+
if (t.__sf_worker_pool_patched__) return;
|
|
792
|
+
Object.defineProperty(t, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
793
|
+
for (const e of We) if (typeof t[e] == "function") {
|
|
794
|
+
const i = t[e];
|
|
795
|
+
t[e] = function(...n) {
|
|
796
|
+
return Je(n[0]) ? i.apply(this, n) : typeof n[n.length - 1] == "function" ? A("fs", e, i, n, this) : i.apply(this, n);
|
|
797
|
+
}, Object.defineProperty(t[e], "name", { value: e, writable: !1 });
|
|
740
798
|
}
|
|
741
|
-
|
|
742
|
-
} catch (
|
|
743
|
-
console.error("[WorkerPool] Error patching fs module:",
|
|
799
|
+
ee = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] fs module patched successfully");
|
|
800
|
+
} catch (t) {
|
|
801
|
+
console.error("[WorkerPool] Error patching fs module:", t);
|
|
744
802
|
}
|
|
745
|
-
})()),
|
|
746
|
-
if (!
|
|
747
|
-
const
|
|
748
|
-
if (
|
|
749
|
-
Object.defineProperty(
|
|
750
|
-
for (const
|
|
751
|
-
const
|
|
752
|
-
e
|
|
753
|
-
return typeof
|
|
754
|
-
}, Object.defineProperty(e
|
|
803
|
+
})()), R("dns") && (r && console.log("[WorkerPool] Patching dns module..."), je()), R("crypto") && (r && console.log("[WorkerPool] Patching crypto module..."), (function() {
|
|
804
|
+
if (!re) try {
|
|
805
|
+
const t = require("node:crypto");
|
|
806
|
+
if (t.__sf_worker_pool_patched__) return;
|
|
807
|
+
Object.defineProperty(t, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
808
|
+
for (const e of Be) if (typeof t[e] == "function") {
|
|
809
|
+
const i = t[e];
|
|
810
|
+
t[e] = function(...n) {
|
|
811
|
+
return typeof n[n.length - 1] == "function" ? A("crypto", e, i, n, this) : i.apply(this, n);
|
|
812
|
+
}, Object.defineProperty(t[e], "name", { value: e, writable: !1 });
|
|
755
813
|
}
|
|
756
|
-
|
|
757
|
-
} catch (
|
|
758
|
-
console.error("[WorkerPool] Error patching crypto module:",
|
|
814
|
+
re = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] crypto module patched successfully");
|
|
815
|
+
} catch (t) {
|
|
816
|
+
console.error("[WorkerPool] Error patching crypto module:", t);
|
|
759
817
|
}
|
|
760
|
-
})()),
|
|
761
|
-
if (!
|
|
762
|
-
const
|
|
763
|
-
if (
|
|
764
|
-
Object.defineProperty(
|
|
765
|
-
for (const
|
|
766
|
-
const
|
|
767
|
-
e
|
|
768
|
-
return typeof
|
|
769
|
-
}, Object.defineProperty(e
|
|
818
|
+
})()), R("zlib") && (r && console.log("[WorkerPool] Patching zlib module..."), (function() {
|
|
819
|
+
if (!ie) try {
|
|
820
|
+
const t = require("node:zlib");
|
|
821
|
+
if (t.__sf_worker_pool_patched__) return;
|
|
822
|
+
Object.defineProperty(t, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
823
|
+
for (const e of ze) if (typeof t[e] == "function") {
|
|
824
|
+
const i = t[e];
|
|
825
|
+
t[e] = function(...n) {
|
|
826
|
+
return typeof n[n.length - 1] == "function" ? A("zlib", e, i, n, this) : i.apply(this, n);
|
|
827
|
+
}, Object.defineProperty(t[e], "name", { value: e, writable: !1 });
|
|
770
828
|
}
|
|
771
|
-
|
|
772
|
-
} catch (
|
|
773
|
-
console.error("[WorkerPool] Error patching zlib module:",
|
|
829
|
+
ie = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] zlib module patched successfully");
|
|
830
|
+
} catch (t) {
|
|
831
|
+
console.error("[WorkerPool] Error patching zlib module:", t);
|
|
774
832
|
}
|
|
775
|
-
})()),
|
|
833
|
+
})()), z = !0, r && console.log("[WorkerPool] Worker pool patching initialized");
|
|
776
834
|
}
|
|
777
|
-
function
|
|
778
|
-
return
|
|
835
|
+
function Qe() {
|
|
836
|
+
return z;
|
|
779
837
|
}
|
|
780
|
-
let
|
|
781
|
-
function ot(
|
|
838
|
+
let J = !1, W = !1;
|
|
839
|
+
function ot(r) {
|
|
782
840
|
if (W) console.warn("[setupInterceptors] ⚠️ Recursive call detected and blocked!");
|
|
783
|
-
else if (!
|
|
841
|
+
else if (!J) {
|
|
784
842
|
W = !0;
|
|
785
843
|
try {
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
844
|
+
let t, e;
|
|
845
|
+
const i = new Error().stack;
|
|
846
|
+
if (i) {
|
|
847
|
+
const s = i.split(`
|
|
848
|
+
`)[2] || "", c = s.match(/\((.+):(\d+):\d+\)/) || s.match(/at (.+):(\d+):\d+/);
|
|
849
|
+
c && (t = c[1], e = parseInt(c[2], 10));
|
|
850
|
+
}
|
|
851
|
+
if (!r || !r.apiKey) {
|
|
852
|
+
const s = `The required API Key is not provided: ${JSON.stringify(r)}`;
|
|
853
|
+
console.error(s);
|
|
789
854
|
}
|
|
790
|
-
const { config:
|
|
791
|
-
if (e.sfDebug && console.log("Updated configuration after applying options:",
|
|
792
|
-
const
|
|
793
|
-
throw console.error(
|
|
855
|
+
const { config: n } = me(r);
|
|
856
|
+
if (t && (n.setupInterceptorsFile = t), e && (n.setupInterceptorsLine = e), n.sfDebug && console.log("Updated configuration after applying options:", n), !n.apiKey || !n.apiGraphqlEndpoint) {
|
|
857
|
+
const s = `The required config is not provided: ${JSON.stringify(n)}`;
|
|
858
|
+
throw console.error(s), new Error(s);
|
|
794
859
|
}
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
}), process.env.SF_WORKER_POOL_DISABLED === "true" ?
|
|
798
|
-
const
|
|
799
|
-
|
|
800
|
-
const
|
|
801
|
-
new
|
|
802
|
-
const
|
|
803
|
-
|
|
804
|
-
})(
|
|
805
|
-
const
|
|
806
|
-
|
|
860
|
+
Ke() || xe(void 0, n.sfDebug).catch((s) => {
|
|
861
|
+
n.sfDebug && console.error("[FuncSpan] Failed to initialize config loader:", s);
|
|
862
|
+
}), process.env.SF_WORKER_POOL_DISABLED === "true" ? n.sfDebug && console.log("[setupInterceptors] Worker pool patching DISABLED (SF_WORKER_POOL_DISABLED=true)") : Qe() || (Ve(), n.sfDebug && console.log("[setupInterceptors] Worker pool patching initialized (DNS tracking enabled)"));
|
|
863
|
+
const o = new V();
|
|
864
|
+
o.setServiceUUID(n.serviceUUID), be(o), (function(s = []) {
|
|
865
|
+
const c = new qe(s);
|
|
866
|
+
new Le().doSend(c.getExcludedDomains());
|
|
867
|
+
const a = new Ae(), l = new ke();
|
|
868
|
+
c.patchFetch(a, l), c.patchHttp(a, l);
|
|
869
|
+
})(n.domainsToNotPropagateHeadersTo);
|
|
870
|
+
const d = new Ue();
|
|
871
|
+
d.setServiceUUID(n.serviceUUID), Ne(d), Oe(), new He().send(), J = !0, n.sfDebug && console.log("[setupInterceptors] ✅ Initialization complete");
|
|
807
872
|
} finally {
|
|
808
873
|
W = !1;
|
|
809
874
|
}
|
|
810
875
|
}
|
|
811
876
|
}
|
|
812
|
-
function
|
|
813
|
-
return
|
|
877
|
+
function at() {
|
|
878
|
+
return J;
|
|
814
879
|
}
|
|
815
|
-
function
|
|
816
|
-
const
|
|
817
|
-
new ue(
|
|
880
|
+
function ct(r, t, e, i = !1) {
|
|
881
|
+
const n = u();
|
|
882
|
+
new ue(n.apiKey).identify(r, t, e, i);
|
|
818
883
|
}
|
|
819
|
-
function
|
|
820
|
-
const
|
|
821
|
-
new ue(
|
|
884
|
+
function dt(r, t = {}, e, i = !1) {
|
|
885
|
+
const n = u();
|
|
886
|
+
new ue(n.apiKey).addOrUpdateMetadata(r, t, e, i);
|
|
822
887
|
}
|
|
823
|
-
let
|
|
824
|
-
function
|
|
825
|
-
const
|
|
826
|
-
const d =
|
|
827
|
-
|
|
828
|
-
const c = (function(
|
|
829
|
-
const
|
|
830
|
-
if (
|
|
831
|
-
const
|
|
832
|
-
if (
|
|
888
|
+
let B = null;
|
|
889
|
+
function ut(r, t, e, i) {
|
|
890
|
+
const n = function(...o) {
|
|
891
|
+
const d = oe(), s = d?.sfDebug || !1;
|
|
892
|
+
s && console.log(`[FuncSpan] captureFunctionSpan wrapper called for ${e}::${t}`);
|
|
893
|
+
const c = (function(m, I) {
|
|
894
|
+
const v = ae();
|
|
895
|
+
if (v) {
|
|
896
|
+
const D = ce(v);
|
|
897
|
+
if (D) return process.env.SF_DEBUG === "true" && console.log(`[FuncSpan] Using HTTP header override for ${m}::${I}`), D;
|
|
833
898
|
}
|
|
834
899
|
try {
|
|
835
|
-
return
|
|
900
|
+
return Ge(m, I);
|
|
836
901
|
} catch {
|
|
837
902
|
return { sample_rate: process.env.SF_FUNCSPAN_SAMPLE_RATE ? parseFloat(process.env.SF_FUNCSPAN_SAMPLE_RATE) : 1, capture_arguments: !0, capture_return_value: !0, arg_limit_mb: 1, return_limit_mb: 1, enable_sampling: !1, autocapture_all_child_functions: !1, capture_sf_veritas: !1, parse_json_strings: !1 };
|
|
838
903
|
}
|
|
839
|
-
})(
|
|
840
|
-
if (
|
|
841
|
-
if (c.sample_rate === 0) return
|
|
842
|
-
|
|
843
|
-
const a =
|
|
844
|
-
a.setCurrentFunctionSpanId(
|
|
845
|
-
const
|
|
904
|
+
})(e, t);
|
|
905
|
+
if (s && console.log(`[FuncSpan] Config for ${e}::${t}:`, c), c.enable_sampling && c.sample_rate < 1 && Math.random() > c.sample_rate) return s && console.log(`[FuncSpan] Skipping ${t} due to sampling`), r.apply(this, o);
|
|
906
|
+
if (c.sample_rate === 0) return s && console.log(`[FuncSpan] Skipping ${t} - sample_rate is 0.0`), r.apply(this, o);
|
|
907
|
+
s && console.log(`[FuncSpan] Capturing function span for ${t}`);
|
|
908
|
+
const a = j.getInstance(), l = a.getCurrentFunctionSpanId(), g = se();
|
|
909
|
+
a.setCurrentFunctionSpanId(g);
|
|
910
|
+
const f = process.hrtime.bigint(), h = Date.now();
|
|
846
911
|
let p = null;
|
|
847
|
-
c.capture_arguments && (p = {},
|
|
848
|
-
|
|
849
|
-
}), p && c.arg_limit_mb > 0 && (p =
|
|
912
|
+
c.capture_arguments && (p = {}, i.paramNames.forEach((m, I) => {
|
|
913
|
+
I < o.length && (p[m] = o[I]);
|
|
914
|
+
}), p && c.arg_limit_mb > 0 && (p = H(p, c.arg_limit_mb)));
|
|
850
915
|
try {
|
|
851
|
-
const
|
|
852
|
-
if (
|
|
853
|
-
const
|
|
854
|
-
let
|
|
855
|
-
return c.capture_return_value && c.return_limit_mb > 0 && (
|
|
856
|
-
}, (
|
|
857
|
-
const
|
|
858
|
-
throw
|
|
916
|
+
const m = r.apply(this, o);
|
|
917
|
+
if (m && typeof m.then == "function") return l ? a.setCurrentFunctionSpanId(l) : a.clearCurrentFunctionSpanId(), m.then((b) => {
|
|
918
|
+
const S = process.hrtime.bigint(), N = Date.now(), w = Number(S - f);
|
|
919
|
+
let Q = null;
|
|
920
|
+
return c.capture_return_value && c.return_limit_mb > 0 && (Q = H(b, c.return_limit_mb)), L({ functionName: t, filePath: e, metadata: i, args: p, result: Q, error: null, duration: N - h, durationNs: w, startTimeNs: f.toString(), async: !0, spanId: g, parentSpanId: l, pid: process.pid, threadId: O }), b;
|
|
921
|
+
}, (b) => {
|
|
922
|
+
const S = process.hrtime.bigint(), N = Date.now(), w = Number(S - f);
|
|
923
|
+
throw L({ functionName: t, filePath: e, metadata: i, args: p, result: null, error: b?.message || String(b), duration: N - h, durationNs: w, startTimeNs: f.toString(), async: !0, spanId: g, parentSpanId: l, pid: process.pid, threadId: O }), b;
|
|
859
924
|
});
|
|
860
|
-
const
|
|
861
|
-
let
|
|
862
|
-
return c.capture_return_value && c.return_limit_mb > 0 && (
|
|
863
|
-
} catch (
|
|
864
|
-
const
|
|
865
|
-
throw
|
|
925
|
+
const I = process.hrtime.bigint(), v = Date.now(), D = Number(I - f);
|
|
926
|
+
let $ = null;
|
|
927
|
+
return c.capture_return_value && c.return_limit_mb > 0 && ($ = H(m, c.return_limit_mb)), L({ functionName: t, filePath: e, metadata: i, args: p, result: $, error: null, duration: v - h, durationNs: D, startTimeNs: f.toString(), async: !1, spanId: g, parentSpanId: l, pid: process.pid, threadId: O }), l ? a.setCurrentFunctionSpanId(l) : a.clearCurrentFunctionSpanId(), m;
|
|
928
|
+
} catch (m) {
|
|
929
|
+
const I = process.hrtime.bigint(), v = Date.now(), D = Number(I - f);
|
|
930
|
+
throw L({ functionName: t, filePath: e, metadata: i, args: p, result: null, error: m?.message || String(m), duration: v - h, durationNs: D, startTimeNs: f.toString(), async: !1, spanId: g, parentSpanId: l, pid: process.pid, threadId: O }), l ? a.setCurrentFunctionSpanId(l) : a.clearCurrentFunctionSpanId(), m;
|
|
866
931
|
}
|
|
867
932
|
};
|
|
868
|
-
Object.defineProperty(
|
|
869
|
-
for (const o in
|
|
870
|
-
return
|
|
933
|
+
Object.defineProperty(n, "name", { value: t, writable: !1 });
|
|
934
|
+
for (const o in r) r.hasOwnProperty(o) && (n[o] = r[o]);
|
|
935
|
+
return n;
|
|
871
936
|
}
|
|
872
|
-
function
|
|
873
|
-
const
|
|
874
|
-
|
|
875
|
-
const
|
|
937
|
+
function L(r) {
|
|
938
|
+
const t = oe(), e = t?.sfDebug || !1;
|
|
939
|
+
e && console.log("[FuncSpan] captureSpanData called for:", { function: r.functionName, file: r.filePath, duration: `${r.duration}ms`, async: r.async, error: r.error, spanId: r.spanId });
|
|
940
|
+
const i = { functionName: r.functionName, filePath: r.filePath, metadata: r.metadata, args: r.args, result: r.result, error: r.error, duration: r.duration, durationNs: r.durationNs, async: r.async, spanId: r.spanId, parentSpanId: r.parentSpanId };
|
|
876
941
|
process.env.SF_FUNCSPAN_CONSOLE_OUTPUT === "true" && console.log(`
|
|
877
|
-
📊 Function Span:`, { function: `${
|
|
878
|
-
const
|
|
879
|
-
if (
|
|
880
|
-
const o =
|
|
942
|
+
📊 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" });
|
|
943
|
+
const n = process.env.SF_FUNCSPAN_JSONL_FILE;
|
|
944
|
+
if (n) try {
|
|
945
|
+
const o = n === "true" || n === "1" ? "funcspans.jsonl" : n, d = Date.now(), s = process.hrtime.bigint(), c = BigInt(r.startTimeNs), a = Number(s - c) / 1e6, l = new Date(d - a).toISOString(), g = JSON.stringify({ timestamp: l, functionName: r.functionName, filePath: r.filePath, line: r.metadata.line, column: r.metadata.column, duration: r.duration, durationNs: r.durationNs, startTimeNs: r.startTimeNs, arguments: r.args, returnValue: r.error ? { error: String(r.error) } : r.result, spanId: r.spanId, parentSpanId: r.parentSpanId, async: r.async, pid: r.pid, threadId: r.threadId }) + `
|
|
881
946
|
`;
|
|
882
|
-
|
|
947
|
+
Pe(o, g, "utf-8");
|
|
883
948
|
} catch (o) {
|
|
884
949
|
console.error("[FuncSpan] Error writing to JSONL file:", o);
|
|
885
950
|
}
|
|
886
|
-
if (
|
|
887
|
-
(
|
|
951
|
+
if (e && console.log("[FuncSpan] Sending function span to transmitter:", i), process.env.SF_FUNCSPAN_SKIP_BACKEND !== "true") try {
|
|
952
|
+
(B || (B = new ve()), B).send([i]), e && console.log("[FuncSpan] Function span sent successfully");
|
|
888
953
|
} catch (o) {
|
|
889
|
-
|
|
954
|
+
e && console.error("[FuncSpan] Error sending function span:", o);
|
|
890
955
|
}
|
|
891
956
|
}
|
|
892
|
-
function lt(
|
|
893
|
-
return !!
|
|
957
|
+
function lt(r) {
|
|
958
|
+
return !!r.includes("captureFunctionSpan(") || !!r.includes("@sailfish-ai/sf-veritas") || !(!r.includes("/* @sailfish-instrumented */") && !r.includes("// @sailfish-instrumented"));
|
|
894
959
|
}
|
|
895
960
|
export {
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
961
|
+
j as ContextManager,
|
|
962
|
+
dt as addOrUpdateMetadata,
|
|
963
|
+
ut as captureFunctionSpan,
|
|
964
|
+
mt as clearFuncspanOverride,
|
|
900
965
|
q as getCurrentFunctionSpanId,
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
966
|
+
de as getDefaultConfig,
|
|
967
|
+
Se as getEnvConfig,
|
|
968
|
+
ae as getFuncspanOverride,
|
|
969
|
+
Ge as getGlobalConfig,
|
|
970
|
+
ct as identify,
|
|
971
|
+
xe as initializeConfigLoader,
|
|
972
|
+
Ve as initializeWorkerPoolPatching,
|
|
908
973
|
lt as isAlreadyInstrumented,
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
974
|
+
Ke as isConfigLoaderInitialized,
|
|
975
|
+
It as isProductionEnvironment,
|
|
976
|
+
vt as isRuntimeModeEnabled,
|
|
977
|
+
at as isSetupInterceptorsInitialized,
|
|
978
|
+
Qe as isWorkerPoolInitialized,
|
|
979
|
+
ce as parseHeaderOverride,
|
|
915
980
|
ft as runWithContext,
|
|
916
|
-
|
|
917
|
-
|
|
981
|
+
yt as setFuncspanOverride,
|
|
982
|
+
bt as setSkipTypeScriptPlugin,
|
|
918
983
|
ot as setupInterceptors,
|
|
919
|
-
|
|
920
|
-
|
|
984
|
+
$t as shouldEnableRuntimeHooks,
|
|
985
|
+
Nt as transformFunctionSpans,
|
|
921
986
|
Ft as transformFunctionSpansSync
|
|
922
987
|
};
|