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