@sailfish-ai/sf-veritas 0.2.4 → 0.2.5
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 +120 -0
- package/dist/funcSpanTransformer-TjdooSrw.cjs +1 -0
- package/dist/funcSpanTransformer-sqmZLAcs.js +750 -0
- package/dist/plugins/funcspanEsbuildPlugin.cjs +1 -1
- package/dist/plugins/funcspanEsbuildPlugin.mjs +1 -1
- package/dist/plugins/funcspanRollupPlugin.cjs +1 -1
- package/dist/plugins/funcspanRollupPlugin.mjs +1 -1
- package/dist/plugins/funcspanTscPlugin.cjs +1 -1
- package/dist/plugins/funcspanTscPlugin.mjs +1 -1
- package/dist/plugins/funcspanVitePlugin.cjs +1 -1
- package/dist/plugins/funcspanVitePlugin.mjs +1 -1
- package/dist/plugins/funcspanWebpackLoader.cjs +1 -1
- package/dist/plugins/funcspanWebpackLoader.mjs +1 -1
- package/dist/runtime/register.cjs +1 -0
- package/dist/runtime/register.mjs +27 -0
- package/dist/sf-veritas.cjs +61 -15
- package/dist/sf-veritas.mjs +1065 -628
- package/dist/types/functionSpanTransmitter.d.ts +15 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/patches/workerPool/argumentCapture.d.ts +47 -0
- package/dist/types/patches/workerPool/index.d.ts +19 -0
- package/dist/types/patches/workerPool/patchCrypto.d.ts +9 -0
- package/dist/types/patches/workerPool/patchDns.d.ts +10 -0
- package/dist/types/patches/workerPool/patchFs.d.ts +9 -0
- package/dist/types/patches/workerPool/patchZlib.d.ts +9 -0
- package/dist/types/patches/workerPool/workerPoolTypes.d.ts +70 -0
- package/dist/types/requestUtils.d.ts +1 -0
- package/dist/types/runtime/register.d.ts +56 -0
- package/dist/types/workerPoolConfig.d.ts +22 -0
- package/dist/types/workerPoolSpanCapture.d.ts +36 -0
- package/package.json +12 -1
- package/dist/funcSpanTransformer-CTddGtUV.cjs +0 -1
- package/dist/funcSpanTransformer-coYDqcrs.js +0 -136
- package/dist/source-map-Cr6YkjTd.js +0 -631
- package/dist/source-map-rHHEdpre.cjs +0 -1
package/dist/sf-veritas.mjs
CHANGED
|
@@ -1,32 +1,34 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var C = (
|
|
4
|
-
import { AsyncLocalStorage as
|
|
5
|
-
import * as
|
|
6
|
-
import { readFileSync as
|
|
7
|
-
import { s as
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
var Pe = Object.defineProperty;
|
|
2
|
+
var ze = (n, e, t) => e in n ? Pe(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
|
|
3
|
+
var C = (n, e, t) => ze(n, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { AsyncLocalStorage as pe, AsyncResource as Oe } from "async_hooks";
|
|
5
|
+
import * as te from "fs";
|
|
6
|
+
import { readFileSync as Re, appendFileSync as Te } from "fs";
|
|
7
|
+
import { s as He } from "./funcSpanTransformer-sqmZLAcs.js";
|
|
8
|
+
import { t as Xt } from "./funcSpanTransformer-sqmZLAcs.js";
|
|
9
|
+
import { Worker as xe, threadId as T } from "worker_threads";
|
|
10
|
+
import { createRequire as Me } from "node:module";
|
|
11
|
+
import * as G from "path";
|
|
12
|
+
import { glob as je } from "glob";
|
|
13
|
+
const N = [];
|
|
14
|
+
for (let n = 0; n < 256; ++n) N.push((n + 256).toString(16).slice(1));
|
|
15
|
+
let ne;
|
|
16
|
+
const Qe = new Uint8Array(16), fe = { randomUUID: typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto) };
|
|
17
|
+
function w(n, e, t) {
|
|
18
|
+
if (fe.randomUUID && !n) return fe.randomUUID();
|
|
19
|
+
const s = (n = n || {}).random ?? n.rng?.() ?? (function() {
|
|
20
|
+
if (!ne) {
|
|
19
21
|
if (typeof crypto > "u" || !crypto.getRandomValues) throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
20
|
-
|
|
22
|
+
ne = crypto.getRandomValues.bind(crypto);
|
|
21
23
|
}
|
|
22
|
-
return
|
|
24
|
+
return ne(Qe);
|
|
23
25
|
})();
|
|
24
|
-
if (
|
|
25
|
-
return
|
|
26
|
-
return (
|
|
27
|
-
})(
|
|
26
|
+
if (s.length < 16) throw new Error("Random bytes length must be >= 16");
|
|
27
|
+
return s[6] = 15 & s[6] | 64, s[8] = 63 & s[8] | 128, (function(r, a = 0) {
|
|
28
|
+
return (N[r[a + 0]] + N[r[a + 1]] + N[r[a + 2]] + N[r[a + 3]] + "-" + N[r[a + 4]] + N[r[a + 5]] + "-" + N[r[a + 6]] + N[r[a + 7]] + "-" + N[r[a + 8]] + N[r[a + 9]] + "-" + N[r[a + 10]] + N[r[a + 11]] + N[r[a + 12]] + N[r[a + 13]] + N[r[a + 14]] + N[r[a + 15]]).toLowerCase();
|
|
29
|
+
})(s);
|
|
28
30
|
}
|
|
29
|
-
class
|
|
31
|
+
class qe {
|
|
30
32
|
constructor(e) {
|
|
31
33
|
C(this, "apiKey");
|
|
32
34
|
C(this, "apiGraphqlEndpoint");
|
|
@@ -48,7 +50,7 @@ class Fe {
|
|
|
48
50
|
C(this, "version");
|
|
49
51
|
C(this, "gitSha");
|
|
50
52
|
C(this, "_serviceIdentificationReceived", !1);
|
|
51
|
-
this.apiKey = e.apiKey, this.apiGraphqlEndpoint = e?.apiGraphqlEndpoint || process.env.SAILFISH_GRAPHQL_ENDPOINT || "https://api-service.sailfishqa.com/graphql/", this.sfDebug = e?.debug === !0 || process.env.SF_DEBUG === "true", this.serviceIdentifier = e?.serviceIdentifier || process.env.SERVICE_IDENTIFIER, this.serviceUUID =
|
|
53
|
+
this.apiKey = e.apiKey, this.apiGraphqlEndpoint = e?.apiGraphqlEndpoint || process.env.SAILFISH_GRAPHQL_ENDPOINT || "https://api-service.sailfishqa.com/graphql/", this.sfDebug = e?.debug === !0 || process.env.SF_DEBUG === "true", this.serviceIdentifier = e?.serviceIdentifier || process.env.SERVICE_IDENTIFIER, this.serviceUUID = w(), this.serviceVersion = e?.serviceVersion || process.env.SERVICE_VERSION, this.gitSha = e?.gitSha || process.env.GIT_SHA || process.env.VERCEL_GIT_COMMIT_SHA, this.serviceAdditionalMetadata = e?.serviceAdditionalMetadata || {}, this.profilingModeEnabled = e?.profilingModeEnabled ?? !1, this.profilingMaxDepth = e?.profilingMaxDepth ?? 5, this.profilingMaxVariableSizeKb = e?.profilingMaxVariableSizeKb ?? 25, this.domainsToNotPropagateHeadersTo = e?.domainsToNotPropagateHeadersTo || [], this.nodeModulesToCollectLocalVariablesOn = e?.nodeModulesToCollectLocalVariablesOn || ["_all_"], this.printConfigurationStatuses = process.env.PRINT_CONFIGURATION_STATUSES || "true", this.logLevel = process.env.LOG_LEVEL || "INFO", this.stackDepthLocals = process.env.SAILFISH_EXCEPTION_STACK_DEPTH_LOCALS !== void 0 ? parseInt(process.env.SAILFISH_EXCEPTION_STACK_DEPTH_LOCALS, 10) : 5, isNaN(this.stackDepthLocals) && (this.stackDepthLocals = -1), this.stackDepthCodeTraceDepth = process.env.SAILFISH_EXCEPTION_STACK_DEPTH_CODE_TRACE_DEPTH !== void 0 ? parseInt(process.env.SAILFISH_EXCEPTION_STACK_DEPTH_CODE_TRACE_DEPTH, 10) : -1, isNaN(this.stackDepthCodeTraceDepth) && (this.stackDepthCodeTraceDepth = -1), this.packageLibraryType = "JS/TS BACKEND", this.version = this.getPackageVersion();
|
|
52
54
|
}
|
|
53
55
|
getPackageVersion() {
|
|
54
56
|
return "0.1.15";
|
|
@@ -60,67 +62,67 @@ class Fe {
|
|
|
60
62
|
this._serviceIdentificationReceived = e;
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
|
-
const
|
|
64
|
-
function
|
|
65
|
-
return globalThis[
|
|
65
|
+
const $e = Symbol.for("sailfish.sf_config");
|
|
66
|
+
function H() {
|
|
67
|
+
return globalThis[$e];
|
|
66
68
|
}
|
|
67
|
-
function
|
|
68
|
-
const e =
|
|
69
|
+
function et(n) {
|
|
70
|
+
const e = H();
|
|
69
71
|
if (e) return { config: e };
|
|
70
|
-
const t = new
|
|
71
|
-
return (function(
|
|
72
|
-
globalThis[
|
|
72
|
+
const t = new qe(n);
|
|
73
|
+
return (function(s) {
|
|
74
|
+
globalThis[$e] = s;
|
|
73
75
|
})(t), t.sfDebug && console.log("[[getOrCreateConfig]] Created global config:", t), { config: t };
|
|
74
76
|
}
|
|
75
|
-
function
|
|
76
|
-
const
|
|
77
|
-
if (!
|
|
78
|
-
return
|
|
77
|
+
function d() {
|
|
78
|
+
const n = H();
|
|
79
|
+
if (!n) throw new Error("Configuration has not been initialized. Call getOrCreateConfig(options) first.");
|
|
80
|
+
return n;
|
|
79
81
|
}
|
|
80
|
-
const
|
|
82
|
+
const be = Symbol.for("sf.ctx.storeAls"), _ = globalThis, re = _[be] ?? (_[be] = new pe()), Ue = ["identitytoolkit.googleapis.com", "t.co", "*.twitter.com", "*.gravatar.com", "*.googleapis.com", "*.amazonaws.com", "*.smooch.io", "*.zendesk.com"], Ae = Symbol.for("sf.ctx.als"), k = _[Ae] ?? (_[Ae] = new pe()), ye = Symbol.for("sf.ctx.sessionRegistry"), K = _[ye] ?? (_[ye] = /* @__PURE__ */ new Map()), L = { handledExceptions: /* @__PURE__ */ new Set(), reentrancyGuardLoggingActive: !1, reentrancyGuardLoggingPreActive: !1, reentrancyGuardPrintActive: !1, reentrancyGuardPrintPreActive: !1, reentrancyGuardExceptionActive: !1, reentrancyGuardExceptionPreActive: !1, excludedDomains: new Set(Ue), supportedDomains: /* @__PURE__ */ new Set() }, R = class R {
|
|
81
83
|
constructor() {
|
|
82
84
|
}
|
|
83
85
|
current() {
|
|
84
|
-
return
|
|
86
|
+
return re.getStore();
|
|
85
87
|
}
|
|
86
88
|
ensureStore() {
|
|
87
89
|
const e = this.current();
|
|
88
90
|
if (e) return e;
|
|
89
91
|
const t = /* @__PURE__ */ new Map();
|
|
90
|
-
return
|
|
92
|
+
return re.enterWith(t), t;
|
|
91
93
|
}
|
|
92
94
|
runWith(e, t) {
|
|
93
|
-
const
|
|
94
|
-
for (const [
|
|
95
|
-
return
|
|
95
|
+
const s = this.current() ?? /* @__PURE__ */ new Map(), r = new Map(s);
|
|
96
|
+
for (const [a, o] of Object.entries(e)) r.set(a, o);
|
|
97
|
+
return re.run(r, t);
|
|
96
98
|
}
|
|
97
99
|
static getInstance() {
|
|
98
|
-
return
|
|
100
|
+
return _[R.GLOBAL_MANAGER_SYMBOL] || (_[R.GLOBAL_MANAGER_SYMBOL] = new R()), _[R.GLOBAL_MANAGER_SYMBOL];
|
|
99
101
|
}
|
|
100
102
|
getCurrentContext() {
|
|
101
|
-
return
|
|
103
|
+
return k.getStore() || L;
|
|
102
104
|
}
|
|
103
105
|
setCurrentContext(e) {
|
|
104
|
-
const t =
|
|
105
|
-
|
|
106
|
+
const t = k.getStore() || L;
|
|
107
|
+
k.enterWith({ ...t, ...e });
|
|
106
108
|
}
|
|
107
109
|
ensureSession(e) {
|
|
108
|
-
let t =
|
|
109
|
-
return t || (t = { ...
|
|
110
|
+
let t = K.get(e);
|
|
111
|
+
return t || (t = { ...L }, K.set(e, t)), t;
|
|
110
112
|
}
|
|
111
113
|
getContextFor(e) {
|
|
112
|
-
return
|
|
114
|
+
return K.get(e) ?? L;
|
|
113
115
|
}
|
|
114
116
|
updateContextFor(e, t) {
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
+
const s = this.ensureSession(e);
|
|
118
|
+
K.set(e, { ...s, ...t });
|
|
117
119
|
}
|
|
118
120
|
runWithSession(e, t) {
|
|
119
|
-
const
|
|
120
|
-
return
|
|
121
|
+
const s = { ...this.ensureSession(e) };
|
|
122
|
+
return k.run(s, t);
|
|
121
123
|
}
|
|
122
124
|
deleteSession(e) {
|
|
123
|
-
|
|
125
|
+
K.delete(e);
|
|
124
126
|
}
|
|
125
127
|
getTraceId() {
|
|
126
128
|
return this.getCurrentContext().traceId;
|
|
@@ -144,12 +146,12 @@ const ae = Symbol.for("sf.ctx.storeAls"), W = globalThis, P = W[ae] ?? (W[ae] =
|
|
|
144
146
|
this.setCurrentContext({ currentFunctionSpanId: void 0 });
|
|
145
147
|
}
|
|
146
148
|
getOrSetSfTraceId(e, t = !1) {
|
|
147
|
-
let
|
|
148
|
-
return
|
|
149
|
+
let s = this.getTraceId();
|
|
150
|
+
return s || (s = e || (t ? w() : `nonsession-applogs-v3/${d().apiKey}/${w()}`), this.setTraceId(s), d().sfDebug && console.log(" Created new trace ID:", s), s);
|
|
149
151
|
}
|
|
150
152
|
getOrSetPageVisitUUID() {
|
|
151
153
|
let e = this.getPageVisitUUID();
|
|
152
|
-
return e || (e =
|
|
154
|
+
return e || (e = w(), this.setPageVisitUUID(e), d().sfDebug && console.log(" Created new page visit UUID:", e), e);
|
|
153
155
|
}
|
|
154
156
|
getHandledExceptions() {
|
|
155
157
|
return this.getCurrentContext().handledExceptions;
|
|
@@ -180,33 +182,33 @@ const ae = Symbol.for("sf.ctx.storeAls"), W = globalThis, P = W[ae] ?? (W[ae] =
|
|
|
180
182
|
this.updateContextFor(e, { pageVisitUUID: t });
|
|
181
183
|
}
|
|
182
184
|
};
|
|
183
|
-
C(
|
|
184
|
-
let
|
|
185
|
-
function
|
|
186
|
-
const e = { ...
|
|
187
|
-
|
|
188
|
-
|
|
185
|
+
C(R, "GLOBAL_MANAGER_SYMBOL", Symbol.for("sf.ctx.manager"));
|
|
186
|
+
let v = R;
|
|
187
|
+
function $t(n) {
|
|
188
|
+
const e = { ...v.getInstance().getCurrentContext() };
|
|
189
|
+
k.run(e, () => {
|
|
190
|
+
n();
|
|
189
191
|
});
|
|
190
192
|
}
|
|
191
|
-
function
|
|
192
|
-
return
|
|
193
|
+
function oe() {
|
|
194
|
+
return v.getInstance().getCurrentFunctionSpanId();
|
|
193
195
|
}
|
|
194
|
-
class
|
|
196
|
+
class $ {
|
|
195
197
|
constructor() {
|
|
196
198
|
C(this, "apiKey");
|
|
197
199
|
C(this, "endpoint");
|
|
198
200
|
C(this, "queryType", "mutation");
|
|
199
201
|
C(this, "operationName", "");
|
|
200
|
-
C(this, "serviceUUID",
|
|
202
|
+
C(this, "serviceUUID", d().serviceUUID);
|
|
201
203
|
C(this, "contextManager");
|
|
202
|
-
this.apiKey =
|
|
204
|
+
this.apiKey = d().apiKey, this.endpoint = d().apiGraphqlEndpoint, this.contextManager = v.getInstance();
|
|
203
205
|
}
|
|
204
206
|
get queryName() {
|
|
205
207
|
return this.operationName ? this.operationName.charAt(0).toLowerCase() + this.operationName.slice(1) : "";
|
|
206
208
|
}
|
|
207
209
|
getDefaultVariables() {
|
|
208
|
-
const e = Date.now().toString(), t = this.contextManager.getOrSetSfTraceId(),
|
|
209
|
-
return { apiKey: this.apiKey, serviceUuid: this.serviceUUID, sessionId: t, timestampMs: e, parentSpanId:
|
|
210
|
+
const e = Date.now().toString(), t = this.contextManager.getOrSetSfTraceId(), s = this.contextManager.getCurrentFunctionSpanId();
|
|
211
|
+
return { apiKey: this.apiKey, serviceUuid: this.serviceUUID, sessionId: t, timestampMs: e, parentSpanId: s };
|
|
210
212
|
}
|
|
211
213
|
getVariables(e = {}) {
|
|
212
214
|
return { ...this.getDefaultVariables(), ...e };
|
|
@@ -221,42 +223,43 @@ class w {
|
|
|
221
223
|
this.serviceUUID = e;
|
|
222
224
|
}
|
|
223
225
|
}
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
+
const tt = fetch;
|
|
227
|
+
let P = !1;
|
|
228
|
+
async function W(n, e, t, s) {
|
|
226
229
|
try {
|
|
227
|
-
const
|
|
228
|
-
let
|
|
230
|
+
const r = d();
|
|
231
|
+
let a;
|
|
229
232
|
try {
|
|
230
|
-
|
|
233
|
+
a = JSON.stringify({ query: t, variables: s, operationName: e });
|
|
231
234
|
} catch {
|
|
232
|
-
|
|
235
|
+
a = JSON.stringify({ query: t, operationName: e });
|
|
233
236
|
}
|
|
234
|
-
|
|
235
|
-
if (!
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
const
|
|
239
|
-
console.error(
|
|
240
|
-
})(
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
})(
|
|
244
|
-
}).catch((
|
|
245
|
-
|
|
237
|
+
P = !0, tt(n, { method: "POST", headers: { "Content-Type": "application/json" }, body: a }).then(async (o) => {
|
|
238
|
+
if (P = !1, !o.ok) return void (r.sfDebug && console.error(`GraphQL request failed with status ${o.status} for ${e}`));
|
|
239
|
+
const i = await o.json();
|
|
240
|
+
i.errors?.length ? (function(c, l, g) {
|
|
241
|
+
const u = c && typeof c == "object" && !Array.isArray(c) ? Object.keys(c)[0] : void 0;
|
|
242
|
+
console.error(u === "identifyServiceDetails" ? `IdentifyServiceDetails NOT sent successfully for service: UUID=${g.serviceUUID}` : `GraphQL request failed with errors: ${JSON.stringify(l)} for operation key ${u}`);
|
|
243
|
+
})(i.data, i.errors, r) : r.sfDebug && (function(c, l, g) {
|
|
244
|
+
const u = c && typeof c == "object" && !Array.isArray(c) ? Object.keys(c)[0] : void 0, I = c[u] || !1;
|
|
245
|
+
u === "identifyServiceDetails" && (g.setServiceIdentificationReceived(I), d().sfDebug && console.log(`IdentifyServiceDetails sent successfully for service: UUID=${g.serviceUUID}; serviceIdentificationReceived=${u === "identifyServiceDetails" ? I : "N/A"}`));
|
|
246
|
+
})(i.data, 0, r);
|
|
247
|
+
}).catch((o) => {
|
|
248
|
+
P = !1, r.sfDebug && (console.error(`[RequestUtils] Fetch error for ${e} to ${n}:`, o), o.cause && console.error("[RequestUtils] Error cause:", o.cause));
|
|
246
249
|
});
|
|
247
|
-
} catch (
|
|
248
|
-
|
|
250
|
+
} catch (r) {
|
|
251
|
+
P = !1, d().sfDebug && console.error("Error sending data to GraphQL server:", r);
|
|
249
252
|
}
|
|
250
253
|
}
|
|
251
|
-
class X extends
|
|
254
|
+
class X extends $ {
|
|
252
255
|
constructor() {
|
|
253
256
|
super(), this.setOperationName("IdentifyServiceDetails");
|
|
254
257
|
}
|
|
255
258
|
async doSend(e) {
|
|
256
|
-
if (!
|
|
259
|
+
if (!d().serviceIdentificationReceived) try {
|
|
257
260
|
this.send();
|
|
258
261
|
} catch (t) {
|
|
259
|
-
|
|
262
|
+
d().sfDebug && console.error(" Error during service identification:", t);
|
|
260
263
|
}
|
|
261
264
|
}
|
|
262
265
|
async send() {
|
|
@@ -284,18 +287,18 @@ class X extends w {
|
|
|
284
287
|
gitSha: $gitSha,
|
|
285
288
|
)
|
|
286
289
|
}
|
|
287
|
-
`, t = this.getVariables({ serviceIdentifier:
|
|
288
|
-
|
|
290
|
+
`, t = this.getVariables({ serviceIdentifier: d().serviceIdentifier, serviceVersion: d().serviceVersion, library: d().packageLibraryType, version: d().version, serviceAdditionalMetadata: d().serviceAdditionalMetadata, gitSha: d().gitSha || "" });
|
|
291
|
+
W(this.endpoint, this.operationName, e, t);
|
|
289
292
|
}
|
|
290
293
|
}
|
|
291
|
-
function
|
|
294
|
+
function nt(n) {
|
|
292
295
|
try {
|
|
293
|
-
return JSON.stringify(
|
|
296
|
+
return JSON.stringify(n), !0;
|
|
294
297
|
} catch {
|
|
295
298
|
return !1;
|
|
296
299
|
}
|
|
297
300
|
}
|
|
298
|
-
class
|
|
301
|
+
class rt extends $ {
|
|
299
302
|
constructor() {
|
|
300
303
|
super();
|
|
301
304
|
C(this, "serviceIdentifier", new X());
|
|
@@ -304,22 +307,22 @@ class Re extends w {
|
|
|
304
307
|
async sendAppIdentifier() {
|
|
305
308
|
this.serviceIdentifier.doSend({});
|
|
306
309
|
}
|
|
307
|
-
async doSend(t,
|
|
308
|
-
this.sendAppIdentifier(), this.send(t,
|
|
309
|
-
}
|
|
310
|
-
async send(t,
|
|
311
|
-
if (!
|
|
312
|
-
let
|
|
313
|
-
if (!
|
|
314
|
-
const
|
|
315
|
-
const
|
|
316
|
-
if (
|
|
317
|
-
return { traitsJson: JSON.stringify(
|
|
318
|
-
})(
|
|
319
|
-
|
|
310
|
+
async doSend(t, s, r, a) {
|
|
311
|
+
this.sendAppIdentifier(), this.send(t, s, r, a);
|
|
312
|
+
}
|
|
313
|
+
async send(t, s, r, a) {
|
|
314
|
+
if (!s && !a) throw new Error('Must pass in either traits or traits_json to "add_or_update_traits"');
|
|
315
|
+
let o = [];
|
|
316
|
+
if (!a) {
|
|
317
|
+
const c = (function(l) {
|
|
318
|
+
const g = {}, u = [];
|
|
319
|
+
if (l) for (const [I, m] of Object.entries(l)) nt(m) ? g[I] = m : u.push(I);
|
|
320
|
+
return { traitsJson: JSON.stringify(g), excludedFields: u };
|
|
321
|
+
})(s);
|
|
322
|
+
a = c.traitsJson, o = c.excludedFields;
|
|
320
323
|
}
|
|
321
|
-
const
|
|
322
|
-
|
|
324
|
+
const i = this.getVariables({ userId: t, traitsJson: a, excludedFields: o, override: r, library: d().packageLibraryType, version: d().version });
|
|
325
|
+
W(this.endpoint, this.operationName, this.getQuery(), i);
|
|
323
326
|
}
|
|
324
327
|
getQuery() {
|
|
325
328
|
return `
|
|
@@ -329,20 +332,20 @@ class Re extends w {
|
|
|
329
332
|
`;
|
|
330
333
|
}
|
|
331
334
|
}
|
|
332
|
-
class
|
|
335
|
+
class Ke {
|
|
333
336
|
constructor(e) {
|
|
334
337
|
C(this, "metadataTransmitter");
|
|
335
|
-
this.apiKey = e, this.metadataTransmitter = new
|
|
338
|
+
this.apiKey = e, this.metadataTransmitter = new rt();
|
|
336
339
|
}
|
|
337
|
-
identify(e, t,
|
|
338
|
-
t ||
|
|
340
|
+
identify(e, t, s, r = !1) {
|
|
341
|
+
t || s ? this.addOrUpdateMetadata(e, t, s, r) : this.addOrUpdateMetadata(e, {}, void 0, r);
|
|
339
342
|
}
|
|
340
|
-
addOrUpdateMetadata(e, t = {},
|
|
341
|
-
if (!t && !
|
|
342
|
-
|
|
343
|
+
addOrUpdateMetadata(e, t = {}, s, r = !1) {
|
|
344
|
+
if (!t && !s) throw new Error('Must pass in either traits or traitsJson to "addOrUpdateMetadata"');
|
|
345
|
+
d().sfDebug && console.log(" [[DEBUG - addOrUpdateMetadata]] Starting operation"), d().sfDebug && console.log(" addOrUpdateMetadata...SENDING DATA...", e, t, s), this.metadataTransmitter.doSend(e, t, r, s);
|
|
343
346
|
}
|
|
344
347
|
}
|
|
345
|
-
class
|
|
348
|
+
class Ie extends $ {
|
|
346
349
|
constructor() {
|
|
347
350
|
super();
|
|
348
351
|
C(this, "serviceIdentifier", new X());
|
|
@@ -355,10 +358,10 @@ class oe extends w {
|
|
|
355
358
|
}
|
|
356
359
|
async send(t) {
|
|
357
360
|
try {
|
|
358
|
-
const
|
|
359
|
-
|
|
360
|
-
} catch (
|
|
361
|
-
|
|
361
|
+
const s = Array.isArray(t) ? t : [t, "default"], r = this.getVariables({ contents: s[0], level: s[1] });
|
|
362
|
+
W(this.endpoint, this.operationName, this.getQuery(), r);
|
|
363
|
+
} catch (s) {
|
|
364
|
+
d().sfDebug && console.error("🚨 Error in send():", s);
|
|
362
365
|
}
|
|
363
366
|
}
|
|
364
367
|
getQuery() {
|
|
@@ -385,9 +388,9 @@ class oe extends w {
|
|
|
385
388
|
`;
|
|
386
389
|
}
|
|
387
390
|
}
|
|
388
|
-
const
|
|
389
|
-
class
|
|
390
|
-
constructor({ file: e, line: t, function:
|
|
391
|
+
const B = {};
|
|
392
|
+
class Y {
|
|
393
|
+
constructor({ file: e, line: t, function: s, code: r, locals: a = {}, offender: o = !1, column: i }) {
|
|
391
394
|
C(this, "file");
|
|
392
395
|
C(this, "line");
|
|
393
396
|
C(this, "function");
|
|
@@ -395,204 +398,204 @@ class T {
|
|
|
395
398
|
C(this, "locals");
|
|
396
399
|
C(this, "offender");
|
|
397
400
|
C(this, "column");
|
|
398
|
-
this.file = e, this.line = t, this.function =
|
|
401
|
+
this.file = e, this.line = t, this.function = s, this.code = r, this.locals = a, this.offender = o, this.column = i;
|
|
399
402
|
}
|
|
400
403
|
toDict() {
|
|
401
|
-
const e = { file: this.file, line: this.line, function: this.function, code: this.code, locals: Object.fromEntries(Object.entries(this.locals).map(([t,
|
|
404
|
+
const e = { file: this.file, line: this.line, function: this.function, code: this.code, locals: Object.fromEntries(Object.entries(this.locals).map(([t, s]) => [t, String(s)])) };
|
|
402
405
|
return this.offender && (e.offender = this.offender), this.column !== void 0 && (e.column = this.column), e;
|
|
403
406
|
}
|
|
404
407
|
toJson() {
|
|
405
408
|
return JSON.stringify(this.toDict());
|
|
406
409
|
}
|
|
407
410
|
}
|
|
408
|
-
class
|
|
411
|
+
class Q {
|
|
409
412
|
static encode(e) {
|
|
410
|
-
return e instanceof
|
|
413
|
+
return e instanceof Y ? e.toDict() : Array.isArray(e) ? e.map((t) => Q.encode(t)) : typeof e == "object" && e !== null ? JSON.stringify(e) : e;
|
|
411
414
|
}
|
|
412
415
|
static stringify(e) {
|
|
413
|
-
return JSON.stringify(
|
|
416
|
+
return JSON.stringify(Q.encode(e), (t, s) => s instanceof Y ? s.toDict() : s);
|
|
414
417
|
}
|
|
415
418
|
}
|
|
416
|
-
let
|
|
417
|
-
function
|
|
418
|
-
|
|
419
|
+
let F, E = 0;
|
|
420
|
+
function ot(n) {
|
|
421
|
+
d().sfDebug && console.log("Initializing Exception Interceptor...");
|
|
419
422
|
try {
|
|
420
|
-
const
|
|
421
|
-
if (
|
|
422
|
-
const
|
|
423
|
-
if (
|
|
424
|
-
const
|
|
425
|
-
if (["local", "dev", "development"].includes(
|
|
426
|
-
if (["KUBERNETES_SERVICE_HOST", "AWS_EXECUTION_ENV", "ECS_CONTAINER_METADATA_URI", "ECS_CONTAINER_METADATA_URI_V4", "GAE_ENV", "K_SERVICE", "GOOGLE_CLOUD_PROJECT", "WEBSITE_INSTANCE_ID", "VERCEL", "NETLIFY", "DYNO", "RENDER", "FLY_APP_NAME", "RAILWAY_STATIC_URL", "CF_PAGES", "CLOUDFLARE"].some((
|
|
427
|
-
const
|
|
428
|
-
return
|
|
423
|
+
const i = (function() {
|
|
424
|
+
if (F !== void 0) return F;
|
|
425
|
+
const c = process.env || {}, l = ve(c.SF_IS_LOCAL);
|
|
426
|
+
if (l !== void 0) return F = l;
|
|
427
|
+
const g = (c.SF_ENV || c.NODE_ENV || "").toLowerCase();
|
|
428
|
+
if (["local", "dev", "development"].includes(g)) return F = !0;
|
|
429
|
+
if (["KUBERNETES_SERVICE_HOST", "AWS_EXECUTION_ENV", "ECS_CONTAINER_METADATA_URI", "ECS_CONTAINER_METADATA_URI_V4", "GAE_ENV", "K_SERVICE", "GOOGLE_CLOUD_PROJECT", "WEBSITE_INSTANCE_ID", "VERCEL", "NETLIFY", "DYNO", "RENDER", "FLY_APP_NAME", "RAILWAY_STATIC_URL", "CF_PAGES", "CLOUDFLARE"].some((I) => !!c[I])) return F = !1;
|
|
430
|
+
const u = (B.hostname?.() || c.HOSTNAME || "").toLowerCase();
|
|
431
|
+
return u === "localhost" || u.endsWith(".local") || u.includes("local") ? F = !0 : F = !1;
|
|
429
432
|
})();
|
|
430
|
-
|
|
431
|
-
if (
|
|
432
|
-
|
|
433
|
-
const
|
|
434
|
-
if (
|
|
433
|
+
n?.setSupplementalFields?.({ isFromLocalService: i }), (async function(c) {
|
|
434
|
+
if (Ne) return;
|
|
435
|
+
Ne = !0;
|
|
436
|
+
const l = process.env || {};
|
|
437
|
+
if (ve(l.SF_IS_LOCAL) === void 0)
|
|
435
438
|
try {
|
|
436
|
-
await (async function(
|
|
437
|
-
const
|
|
438
|
-
return (await Promise.allSettled([
|
|
439
|
-
})(150) &&
|
|
439
|
+
await (async function(g) {
|
|
440
|
+
const u = se("http://169.254.169.254/latest/meta-data/", {}, g), I = se("http://metadata.google.internal/computeMetadata/v1/instance/", { "Metadata-Flavor": "Google" }, g), m = se("http://169.254.169.254/metadata/instance?api-version=2021-02-01", { Metadata: "true" }, g);
|
|
441
|
+
return (await Promise.allSettled([u, I, m])).some((p) => p.status === "fulfilled" && (p.value === "ok" || p.value === "http_error"));
|
|
442
|
+
})(150) && F && (F = !1, c?.setSupplementalFields?.({ isFromLocalService: !1 }));
|
|
440
443
|
} catch {
|
|
441
444
|
}
|
|
442
|
-
})(
|
|
445
|
+
})(n).catch(() => {
|
|
443
446
|
});
|
|
444
447
|
} catch {
|
|
445
448
|
}
|
|
446
|
-
const e = new Ne(new URL("data:application/javascript;base64,aW1wb3J0IHsgU2Vzc2lvbiB9IGZyb20gImluc3BlY3Rvci9wcm9taXNlcyI7CmltcG9ydCB7IHBhcmVudFBvcnQsIHdvcmtlckRhdGEgfSBmcm9tICJ3b3JrZXJfdGhyZWFkcyI7CgpnbG9iYWwuc2ZEZWJ1ZyA9IHVuZGVmaW5lZDsKZ2xvYmFsLnN0YWNrRGVwdGhMb2NhbHMgPSB1bmRlZmluZWQ7Cmdsb2JhbC5ub2RlTW9kdWxlc1RvQ29sbGVjdExvY2FsVmFyaWFibGVzT24gPSB1bmRlZmluZWQ7CgovKioKICogUHJvY2Vzc2VzIGNhbGwgZnJhbWVzIGZyb20gYW4gZXhjZXB0aW9uIGFuZCBwb3N0cyB0aGVtIHZpYSB0aGUgV29ya2Vy4oCZcyBwYXJlbnRQb3J0LgogKgogKiBAcGFyYW0gc2Vzc2lvbiAtIFRoZSBEZXZUb29scyBzZXNzaW9uIG9yIHNpbWlsYXIgb2JqZWN0IHlvdSB1c2UgdG8gcXVlcnkgZm9yIHNjcmlwdCBzb3VyY2VzLgogKiBAcGFyYW0gY2FsbEZyYW1lcyAtIEFuIGFycmF5IG9mIGNhbGwgZnJhbWUgb2JqZWN0cy4KICogQHBhcmFtIGRlc2NyaXB0aW9uTGluZXMgLSBBbiBhcnJheSBvZiBsaW5lcyBmcm9tIHRoZSBlcnJvcuKAmXMgZGVzY3JpcHRpb24sIGVhY2ggdHlwaWNhbGx5IGJlZ2lubmluZyB3aXRoICJhdCAiLgogKiBAcmV0dXJucyB7UHJvbWlzZTx2b2lkPn0KICovCmV4cG9ydCBhc3luYyBmdW5jdGlvbiBwcm9jZXNzQ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4XSkgewogICAgICAgICAgZmlsZSA9IGRlc2NyaXB0aW9uTGluZXNbaW5kZXhdLnRyaW0oKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZmlsZSA9ICI8dW5rbm93bj4iOwogICAgICAgIH0KCiAgICAgICAgLy8gSWYgd2UgaGF2ZSBhIHZhbGlkIGxvY2F0aW9uIGFuZCBzY3JpcHRJZCwgZmV0Y2ggdGhlIGNvZGUgbGluZQogICAgICAgIGlmIChsb2NhdGlvbiAmJiBsb2NhdGlvbi5zY3JpcHRJZCkgewogICAgICAgICAgY29uc3Qgc2NyaXB0SWQgPSBsb2NhdGlvbi5zY3JpcHRJZDsKICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgIGNvbnN0IHsgc2NyaXB0U291cmNlIH0gPSBhd2FpdCBzZXNzaW9uLnBvc3QoCiAgICAgICAgICAgICAgIkRlYnVnZ2VyLmdldFNjcmlwdFNvdXJjZSIsCiAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgc2NyaXB0SWQsCiAgICAgICAgICAgICAgfSwKICAgICAgICAgICAgKTsKICAgICAgICAgICAgY29uc3Qgc291cmNlTGluZXMgPSBzY3JpcHRTb3VyY2Uuc3BsaXQoIlxuIik7CiAgICAgICAgICAgIGNvZGUgPSBzb3VyY2VMaW5lc1tsb2NhdGlvbi5saW5lTnVtYmVyXSB8fCAiPG5vdCBjYXB0dXJlZD4iOwogICAgICAgICAgfSBjYXRjaCAoZXJyKSB7CiAgICAgICAgICAgIGlmIChnbG9iYWwuc2ZEZWJ1ZykgewogICAgICAgICAgICAgIGNvbnNvbGUuZXJyb3IoIltXb3JrZXJdIEZhaWxlZCB0byBmZXRjaCBzY3JpcHQgc291cmNlOiIsIGVycik7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIC8vIEZldGNoIGxvY2FsIHZhcmlhYmxlcyBpZiB0aGVyZSdzIGFuIG9iamVjdElkCiAgICAgICAgY29uc3QgbG9jYWxzID0gbG9jYWxTY29wZT8ub2JqZWN0Py5vYmplY3RJZAogICAgICAgICAgPyBhd2FpdCBmZXRjaExvY2FsVmFyaWFibGVzKHNlc3Npb24sIGxvY2FsU2NvcGUub2JqZWN0Lm9iamVjdElkKQogICAgICAgICAgOiB7fTsKCiAgICAgICAgcmV0dXJuIHsKICAgICAgICAgIGZ1bmN0aW9uOiBmdW5jdGlvbk5hbWUgfHwgIjxhbm9ueW1vdXM+IiwKICAgICAgICAgIGxvY2FscywKICAgICAgICAgIGZpbGUsCiAgICAgICAgICBsaW5lOiBsb2NhdGlvbj8ubGluZU51bWJlciB8fCAwLAogICAgICAgICAgY29kZSwKICAgICAgICB9OwogICAgICB9IGNhdGNoIChlcnJvcikgewogICAgICAgIGlmIChnbG9iYWwuc2ZEZWJ1ZykgewogICAgICAgICAgY29uc29sZS5lcnJvcigiW1dvcmtlcl0gRXJyb3IgcHJvY2Vzc2luZyBjYWxsIGZyYW1lOiIsIGVycm9yKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHsKICAgICAgICAgIGZ1bmN0aW9uOiAiPGVycm9yPiIsCiAgICAgICAgICBsb2NhbHM6IHt9LAogICAgICAgICAgZmlsZTogIjx1bmtub3duPiIsCiAgICAgICAgICBsaW5lOiAwLAogICAgICAgICAgY29kZTogIjxub3QgY2FwdHVyZWQ+IiwKICAgICAgICB9OwogICAgICB9CiAgICB9KSwKICApOwogIC8vIFBvc3QgZXhjZXB0aW9uIGRhdGEKICBwYXJlbnRQb3J0Py5wb3N0TWVzc2FnZSh7IHR5cGU6ICJleGNlcHRpb24iLCBmcmFtZXMgfSk7Cn0KCi8qKgogKiBIYW5kbGVzIHRoZSAicGF1c2VkIiBzdGF0ZSBvZiB0aGUgZGVidWdnZXIgYW5kIHByb2Nlc3NlcyBleGNlcHRpb25zIG9yIHByb21pc2UgcmVqZWN0aW9ucy4KICogQHBhcmFtIHtTZXNzaW9ufSBzZXNzaW9uIC0gVGhlIGRlYnVnZ2luZyBzZXN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Byb3AudmFsdWUub2JqZWN0SWQ7CiAgICAgICAgICBhd2FpdCB1bnJvbGxPYmplY3Qoc2Vzc2lvbiwgaWQsIHByb3AubmFtZSwgdmFyaWFibGVzKTsKICAgICAgICB9IGVsc2UgaWYgKHByb3A/LnZhbHVlKSB7CiAgICAgICAgICB1bnJvbGxPdGhlcihwcm9wLCB2YXJpYWJsZXMpOwogICAgICAgIH0KICAgICAgfQogICAgICByZXR1cm4gdmFyaWFibGVzOwogICAgfQogIH0gY2F0Y2ggKGVycikgewogICAgaWYgKGdsb2JhbC5zZkRlYnVnKSB7CiAgICAgIGNvbnNvbGUuZXJyb3IoIltXb3JrZXJdIEZhaWxlZCB0byBmZXRjaCBsb2NhbCB2YXJpYWJsZXM6IiwgZXJyKTsKICAgIH0KICAgIHJldHVybiB7fTsKICB9Cn0KCnN0YXJ0RGVidWdnZXIoKS5jYXRjaCgoZXJyb3IpID0+IHsKICBpZiAoZ2xvYmFsLnNmRGVidWcpIHsKICAgIGNvbnNvbGUuZXJyb3IoIltXb3JrZXJdIEZhaWxlZCB0byBzdGFydCBkZWJ1Z2dlcjoiLCBlcnJvcik7CiAgfQp9KTsKCi8vIEtlZXAgdGhlIHdvcmtlciBhbGl2ZQpzZXRJbnRlcnZhbCgoKSA9PiB7fSwgMTAwMDApOwo="), { workerData: { captureAllExceptions: !0 } });
|
|
449
|
+
const e = new xe(new URL("data:application/javascript;base64,aW1wb3J0IHsgU2Vzc2lvbiB9IGZyb20gImluc3BlY3Rvci9wcm9taXNlcyI7CmltcG9ydCB7IHBhcmVudFBvcnQsIHdvcmtlckRhdGEgfSBmcm9tICJ3b3JrZXJfdGhyZWFkcyI7CgpnbG9iYWwuc2ZEZWJ1ZyA9IHVuZGVmaW5lZDsKZ2xvYmFsLnN0YWNrRGVwdGhMb2NhbHMgPSB1bmRlZmluZWQ7Cmdsb2JhbC5ub2RlTW9kdWxlc1RvQ29sbGVjdExvY2FsVmFyaWFibGVzT24gPSB1bmRlZmluZWQ7C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ZSIsCiAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgc2NyaXB0SWQsCiAgICAgICAgICAgICAgfSwKICAgICAgICAgICAgKTsKICAgICAgICAgICAgY29uc3Qgc291cmNlTGluZXMgPSBzY3JpcHRTb3VyY2Uuc3BsaXQoIlxuIik7CiAgICAgICAgICAgIGNvZGUgPSBzb3VyY2VMaW5lc1tsb2NhdGlvbi5saW5lTnVtYmVyXSB8fCAiPG5vdCBjYXB0dXJlZD4iOwogICAgICAgICAgfSBjYXRjaCAoZXJyKSB7CiAgICAgICAgICAgIGlmIChnbG9iYWwuc2ZEZWJ1ZykgewogICAgICAgICAgICAgIGNvbnNvbGUuZXJyb3IoIltXb3JrZXJdIEZhaWxlZCB0byBmZXRjaCBzY3JpcHQgc291cmNlOiIsIGVycik7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIC8vIEZldGNoIGxvY2FsIHZhcmlhYmxlcyBpZiB0aGVyZSdzIGFuIG9iamVjdElkCiAgICAgICAgY29uc3QgbG9jYWxzID0gbG9jYWxTY29wZT8ub2JqZWN0Py5vYmplY3RJZAogICAgICAgICAgPyBhd2FpdCBmZXRjaExvY2FsVmFyaWFibGVzKHNlc3Npb24sIGxvY2FsU2NvcGUub2JqZWN0Lm9iamVjdElkKQogICAgICAgICAgOiB7fTsKCiAgICAgICAgcmV0dXJuIHsKICAgICAgICAgIGZ1bmN0aW9uOiBmdW5jdGlvbk5hbWUgfHwgIjxhbm9ueW1vdXM+IiwKICAgICAgICAgIGxvY2FscywKICAgICAgICAgIGZpbGUsCiAgICAgICAgICBsaW5lOiBsb2NhdGlvbj8ubGluZU51bWJlciB8fCAwLAogICAgICAgICAgY29kZSwKICAgICAgICB9OwogICAgICB9IGNhdGNoIChlcnJvcikgewogICAgICAgIGlmIChnbG9iYWwuc2ZEZWJ1ZykgewogICAgICAgICAgY29uc29sZS5lcnJvcigiW1dvcmtlcl0gRXJyb3IgcHJvY2Vzc2luZyBj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GVOYW1lKSA9PgogICAgICAgICAgZmlyc3RGcmFtZUxpbmUuaW5jbHVkZXMoYCR7bW9kdWxlTmFtZX1gKSwKICAgICAgICApOwoKICAgICAgICBpZiAoIWlzRnJvbUFsbG93ZWROb2RlTW9kdWxlKSB7CiAgICAgICAgICAvLyBOb3QgZnJvbSBhbiBhbGxvd2VkIG5vZGUgbW9kdWxlID0+IHJldHVybiBlYXJseQogICAgICAgICAgaWYgKGdsb2JhbC5zZkRlYnVnKSB7CiAgICAgICAgICAgIGNvbnNvbGUubG9nKAogICAgICAgICAgICAgICJbV29ya2VyXSBFcnJvciBhcHBlYXJzIHRvIGJlIHRyaWdnZXJlZCBmcm9tIG5vbi1hcHBsaWNhdGlvbiBzb3VyY2VzOyBpZ25vcmluZy4iLAogICAgICAgICAgICApOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuOwogICAgICAgIH0KICAgICAgICAvLyBPdGhlcndpc2UsIGl0J3MgZnJvbSBhbiBhbGxvd2VkIG5vZGUgbW9kdWxlLCBzbyBjb250aW51ZQogICAgICB9IGVsc2UgewogICAgICAgIC8vIElmIHRoZSBsaXN0IGlzIGVtcHR5LCBwcmVzZXJ2ZSBleGlzdGluZyBiZWhhdmlvciBhbmQgaWdub3JlIG5vbi1hcHBsaWNhdGlvbiBlcnJvcnMKICAgICAgICBpZiAoZ2xvYmFsLnNmRGVidWcpIHsKICAgICAgICAgIGNvbnNvbGUubG9nKAogICAgICAgICAgICAiW1dvcmtlcl0gRXJyb3IgYXBwZWFycyB0byBiZSB0cmlnZ2VyZWQgZnJvbSBub24tYXBwbGljYXRpb24gc291cmNlczsgaWdub3JpbmcuIiwKICAgICAgICAgICk7CiAgICAgICAgfQogICAgICAgIHJldHVybjsKICAgICAgfQogICAgfQoKICAgIC8vIElmIHdlIHJlYWNoIHRoaXMgcG9pbnQsIHRoZSBlcnJvciBpcyBlaXRoZXIgZnJvbSBhcHAgY29kZSwgb3IgZnJvbSBhIG5vZGUgbW9kdWxlIG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ZiAoZ2xvYmFsLnNmRGVidWcpIHsKICAgIGNvbnNvbGUuZXJyb3IoIltXb3JrZXJdIEZhaWxlZCB0byBzdGFydCBkZWJ1Z2dlcjoiLCBlcnJvcik7CiAgfQp9KTsKCi8vIEtlZXAgdGhlIHdvcmtlciBhbGl2ZQpzZXRJbnRlcnZhbCgoKSA9PiB7fSwgMTAwMDApOwo="), { workerData: { captureAllExceptions: !0 } });
|
|
447
450
|
let t = null;
|
|
448
|
-
const
|
|
449
|
-
e.on("message", (
|
|
450
|
-
if (typeof
|
|
451
|
-
const { frames:
|
|
452
|
-
if (!
|
|
453
|
-
const
|
|
454
|
-
return
|
|
455
|
-
`).slice(1).map((
|
|
456
|
-
const
|
|
457
|
-
if (
|
|
458
|
-
const [,
|
|
459
|
-
return new
|
|
451
|
+
const s = /* @__PURE__ */ new WeakMap();
|
|
452
|
+
e.on("message", (i) => {
|
|
453
|
+
if (typeof i == "string" && d().sfDebug && console.log(`[Worker] ${i}`), i.readyToGetParameters && e.postMessage({ sfDebug: d().sfDebug, stackDepthLocals: d().stackDepthLocals, nodeModulesToCollectLocalVariablesOn: d().nodeModulesToCollectLocalVariablesOn }), i.type === "exception") {
|
|
454
|
+
const { frames: c } = i, l = t;
|
|
455
|
+
if (!l) return;
|
|
456
|
+
const g = s.get(l), u = (function(m) {
|
|
457
|
+
return m ? m.split(`
|
|
458
|
+
`).slice(1).map((p) => {
|
|
459
|
+
const h = /at (.+?) \((.+):(\d+):(\d+)\)/.exec(p) || /at (.+):(\d+):(\d+)/.exec(p);
|
|
460
|
+
if (h) {
|
|
461
|
+
const [, f, S, b, y] = h;
|
|
462
|
+
return new Y({ function: f || "<anonymous>", locals: {}, file: S || "<unknown>", line: parseInt(b, 10) || 0, code: "<not captured>", column: parseInt(y) || 0 });
|
|
460
463
|
}
|
|
461
|
-
return new
|
|
464
|
+
return new Y({ function: "<unknown>", locals: {}, file: "<unknown>", line: 0, code: "<not captured>", column: 0 });
|
|
462
465
|
}) : [];
|
|
463
|
-
})(
|
|
464
|
-
const
|
|
465
|
-
let
|
|
466
|
-
for (let b = 0; b <
|
|
467
|
-
const
|
|
468
|
-
if (
|
|
469
|
-
for (let
|
|
470
|
-
const
|
|
471
|
-
if (
|
|
472
|
-
|
|
466
|
+
})(l.stack), I = (function(m, p) {
|
|
467
|
+
const h = [];
|
|
468
|
+
let f = -1, S = -1;
|
|
469
|
+
for (let b = 0; b < m.length; b++) {
|
|
470
|
+
const y = it(m[b].file);
|
|
471
|
+
if (S = b, y !== "<unknown>") {
|
|
472
|
+
for (let A = 0; A < p.length; A++) {
|
|
473
|
+
const Z = p[A];
|
|
474
|
+
if (Ee(Z, y) || typeof Z.file == "string" && Z.file.includes(y)) {
|
|
475
|
+
f = A, E = 0, d().sfDebug && console.log(`✅ Matched Frame Found: ${y} @ Debugger Frame ${A}`);
|
|
473
476
|
break;
|
|
474
477
|
}
|
|
475
478
|
}
|
|
476
|
-
if (
|
|
479
|
+
if (f !== -1) break;
|
|
477
480
|
}
|
|
478
481
|
}
|
|
479
|
-
if (
|
|
480
|
-
|
|
481
|
-
for (let b = 0; b <
|
|
482
|
-
const
|
|
483
|
-
|
|
482
|
+
if (f === -1) return E === 10 ? (E = 0, m) : (++E, d().sfDebug && console.log(`"❌ No matching frame found. Checking once again, Attempt N ${E}"`), []);
|
|
483
|
+
d().sfDebug && console.log(`🔄 Merging from matched index ${f} onward...`);
|
|
484
|
+
for (let b = 0; b < p.length; b++) {
|
|
485
|
+
const y = m[S + b], A = p[f + b];
|
|
486
|
+
h.push(new Y({ function: A?.function || y?.function || "<anonymous>", locals: A?.locals || y?.locals || {}, file: y?.file || A?.file || "<unknown>", line: A?.line || y?.line || 0, code: A?.code || y?.code || "<not captured>" }));
|
|
484
487
|
}
|
|
485
|
-
return
|
|
486
|
-
})(
|
|
487
|
-
if (
|
|
488
|
+
return h;
|
|
489
|
+
})(u, c || []);
|
|
490
|
+
if (I.length !== 0) {
|
|
488
491
|
t = null;
|
|
489
|
-
const
|
|
490
|
-
for (let
|
|
491
|
-
const
|
|
492
|
-
|
|
492
|
+
const m = d().stackDepthCodeTraceDepth, p = m === -1 ? I : I.slice(0, m + 1), h = Math.min(p.length, u.length);
|
|
493
|
+
for (let y = 0; y < h; y++) (async () => {
|
|
494
|
+
const A = st(p[y].file, u[y].line, u[y].column);
|
|
495
|
+
A && (A.content != null && (p[y].code = A.content), A.file != null && (p[y].file = A.file));
|
|
493
496
|
})();
|
|
494
|
-
|
|
495
|
-
const
|
|
496
|
-
|
|
497
|
-
const
|
|
498
|
-
b ? (
|
|
499
|
-
|
|
500
|
-
})) :
|
|
501
|
-
|
|
502
|
-
}) :
|
|
497
|
+
n.setOperationName("CollectExceptions");
|
|
498
|
+
const f = l.message ? `${l.name}: ${l.message}` : l.name;
|
|
499
|
+
d().sfDebug && console.log("error message is : ", f);
|
|
500
|
+
const S = v.getInstance(), b = s.get(l);
|
|
501
|
+
b ? (S.setTraceIdFor(b, b), S.runWithSession(b, () => {
|
|
502
|
+
S.setTraceId(b), n.doSend(f, p);
|
|
503
|
+
})) : n.doSend(f, p), g ? v.getInstance().runWithSession(g, () => {
|
|
504
|
+
n.doSend(f, p);
|
|
505
|
+
}) : n.doSend(f, p);
|
|
503
506
|
}
|
|
504
507
|
}
|
|
505
|
-
}), e.on("error", (
|
|
506
|
-
console.error("[Worker Error]",
|
|
507
|
-
}), e.on("exit", (
|
|
508
|
-
console.error(`[Worker] Exited with code ${
|
|
508
|
+
}), e.on("error", (i) => {
|
|
509
|
+
console.error("[Worker Error]", i);
|
|
510
|
+
}), e.on("exit", (i) => {
|
|
511
|
+
console.error(`[Worker] Exited with code ${i}`);
|
|
509
512
|
}), e.unref();
|
|
510
|
-
const
|
|
511
|
-
function
|
|
512
|
-
const
|
|
513
|
-
Reflect.setPrototypeOf(
|
|
513
|
+
const r = Error, a = /* @__PURE__ */ new Set();
|
|
514
|
+
function o(...i) {
|
|
515
|
+
const c = Reflect.construct(r, i);
|
|
516
|
+
Reflect.setPrototypeOf(c, o.prototype);
|
|
514
517
|
try {
|
|
515
|
-
const
|
|
516
|
-
|
|
518
|
+
const g = v.getInstance().getTraceId();
|
|
519
|
+
s.set(c, g);
|
|
517
520
|
} catch {
|
|
518
521
|
}
|
|
519
|
-
|
|
520
|
-
const
|
|
522
|
+
r.captureStackTrace && r.captureStackTrace(c, o);
|
|
523
|
+
const l = `${c.message}:${c.stack?.split(`
|
|
521
524
|
`)[1]?.trim()}`;
|
|
522
|
-
if (!
|
|
523
|
-
|
|
524
|
-
const
|
|
525
|
-
|
|
525
|
+
if (!a.has(l)) {
|
|
526
|
+
a.add(l), t = c;
|
|
527
|
+
const g = v.getInstance().getTraceId();
|
|
528
|
+
s.set(c, g), e.postMessage({ type: "processException", error: c.message });
|
|
526
529
|
}
|
|
527
|
-
return
|
|
530
|
+
return c;
|
|
528
531
|
}
|
|
529
|
-
|
|
532
|
+
o.prototype = Object.create(r.prototype, { constructor: { value: o, enumerable: !1, writable: !0, configurable: !0 } }), Object.setPrototypeOf(o, r), globalThis.Error = o;
|
|
530
533
|
}
|
|
531
|
-
function
|
|
532
|
-
return
|
|
534
|
+
function Se(n) {
|
|
535
|
+
return n = (n = (n = n.replace(/^webpack:\/\/[^\/]+\/\.?\//, "")).replace(/^.*\/pages\//, "pages/")).replace(/\.(js|ts)$/, "");
|
|
533
536
|
}
|
|
534
|
-
function
|
|
535
|
-
const
|
|
536
|
-
|
|
537
|
-
const
|
|
538
|
-
return
|
|
539
|
-
})(
|
|
540
|
-
if (!
|
|
541
|
-
const
|
|
537
|
+
function st(n, e, t) {
|
|
538
|
+
const s = (function(a) {
|
|
539
|
+
a.startsWith("at ") && (a = a.slice(3).trim());
|
|
540
|
+
const o = a.match(/^(.*?)(:\d+)+(\.map)?$/);
|
|
541
|
+
return o ? o[1] : a;
|
|
542
|
+
})(n);
|
|
543
|
+
if (!s || s === "<unknown>") return null;
|
|
544
|
+
const r = s + ".map";
|
|
542
545
|
try {
|
|
543
|
-
const
|
|
544
|
-
if (
|
|
545
|
-
const
|
|
546
|
-
let
|
|
547
|
-
if (
|
|
548
|
-
const
|
|
549
|
-
if (
|
|
546
|
+
const a = Re(r, "utf-8");
|
|
547
|
+
if (a) {
|
|
548
|
+
const o = JSON.parse(a);
|
|
549
|
+
let i = new He.SourceMapConsumer(o).originalPositionFor({ line: e, column: t });
|
|
550
|
+
if (s && i.source) {
|
|
551
|
+
const c = Se(s), l = o.sources.findIndex((g) => Se(g) === c);
|
|
552
|
+
if (l === -1) d().sfDebug && console.log(`Source file "${s}" not found in the source map.`);
|
|
550
553
|
else {
|
|
551
|
-
const
|
|
552
|
-
if (
|
|
553
|
-
return { content:
|
|
554
|
-
`).slice(
|
|
555
|
-
`), name:
|
|
556
|
-
|
|
554
|
+
const g = o.sourcesContent[l], u = o.names.join(",");
|
|
555
|
+
if (g)
|
|
556
|
+
return { content: g.split(`
|
|
557
|
+
`).slice(i.line - 1, i.line + 20).join(`
|
|
558
|
+
`), name: u, file: i.source };
|
|
559
|
+
d().sfDebug && console.log(`No source content available for file "${s}".`);
|
|
557
560
|
}
|
|
558
561
|
}
|
|
559
|
-
return { content:
|
|
562
|
+
return { content: o.sourcesContent[0], name: o.names[0], file: o.file };
|
|
560
563
|
}
|
|
561
|
-
} catch (
|
|
562
|
-
|
|
564
|
+
} catch (a) {
|
|
565
|
+
d().sfDebug && console.log(`Cant read/parse "${r}: Error - ".`, a);
|
|
563
566
|
}
|
|
564
567
|
return null;
|
|
565
568
|
}
|
|
566
|
-
function
|
|
567
|
-
return
|
|
569
|
+
function it(n) {
|
|
570
|
+
return n?.split("/").pop() || "<unknown>";
|
|
568
571
|
}
|
|
569
|
-
function
|
|
570
|
-
if (!
|
|
571
|
-
for (const t of Object.values(
|
|
572
|
-
if (typeof t == "string" && t.includes(e) || typeof t == "object" &&
|
|
572
|
+
function Ee(n, e) {
|
|
573
|
+
if (!n || typeof n != "object") return !1;
|
|
574
|
+
for (const t of Object.values(n))
|
|
575
|
+
if (typeof t == "string" && t.includes(e) || typeof t == "object" && Ee(t, e)) return !0;
|
|
573
576
|
return !1;
|
|
574
577
|
}
|
|
575
|
-
let
|
|
576
|
-
function
|
|
577
|
-
if (!
|
|
578
|
-
const e =
|
|
578
|
+
let Ne = !1;
|
|
579
|
+
function ve(n) {
|
|
580
|
+
if (!n) return;
|
|
581
|
+
const e = n.toLowerCase().trim();
|
|
579
582
|
return !!["1", "true", "yes", "on"].includes(e) || !["0", "false", "no", "off"].includes(e) && void 0;
|
|
580
583
|
}
|
|
581
|
-
function
|
|
582
|
-
return new Promise((
|
|
584
|
+
function se(n, e, t) {
|
|
585
|
+
return new Promise((s) => {
|
|
583
586
|
try {
|
|
584
|
-
const
|
|
585
|
-
|
|
587
|
+
const r = new URL(n), a = (r.protocol, B).request({ method: "GET", hostname: r.hostname, port: r.port || (r.protocol === "https:" ? 443 : 80), path: r.pathname + (r.search || ""), headers: e }, (o) => {
|
|
588
|
+
o.resume(), o.statusCode && o.statusCode >= 200 && o.statusCode < 400 ? s("ok") : s("http_error");
|
|
586
589
|
});
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
}),
|
|
590
|
+
a.on("error", () => s("error")), a.setTimeout(t, () => {
|
|
591
|
+
a.destroy(), s("timeout");
|
|
592
|
+
}), a.end();
|
|
590
593
|
} catch {
|
|
591
|
-
|
|
594
|
+
s("error");
|
|
592
595
|
}
|
|
593
596
|
});
|
|
594
597
|
}
|
|
595
|
-
class
|
|
598
|
+
class at extends $ {
|
|
596
599
|
constructor() {
|
|
597
600
|
super();
|
|
598
601
|
C(this, "serviceIdentifier", new X());
|
|
@@ -603,19 +606,19 @@ class Te extends w {
|
|
|
603
606
|
this.supplementalFields = { ...this.supplementalFields, ...t };
|
|
604
607
|
}
|
|
605
608
|
normalizedSupplementalForGraphQL() {
|
|
606
|
-
const { isFromLocalService: t } = this.supplementalFields,
|
|
607
|
-
return t !== void 0 && (
|
|
609
|
+
const { isFromLocalService: t } = this.supplementalFields, s = {};
|
|
610
|
+
return t !== void 0 && (s.isFromLocalService = t), s;
|
|
608
611
|
}
|
|
609
612
|
async sendAppIdentifier() {
|
|
610
613
|
this.serviceIdentifier.doSend({});
|
|
611
614
|
}
|
|
612
|
-
async doSend(t,
|
|
613
|
-
this.sendAppIdentifier(), this.send(t,
|
|
615
|
+
async doSend(t, s) {
|
|
616
|
+
this.sendAppIdentifier(), this.send(t, s);
|
|
614
617
|
}
|
|
615
|
-
async send(t,
|
|
616
|
-
|
|
617
|
-
const
|
|
618
|
-
|
|
618
|
+
async send(t, s) {
|
|
619
|
+
d().sfDebug && console.log(" SENDING EXCEPTION...");
|
|
620
|
+
const r = JSON.stringify(Q.encode(s)), a = this.normalizedSupplementalForGraphQL(), o = this.getVariables({ exceptionMessage: t, traceJson: r, reentrancyGuardPreactive: !1, library: d().packageLibraryType, version: d().version, ...a });
|
|
621
|
+
W(this.endpoint, this.operationName, this.getQuery(), o);
|
|
619
622
|
}
|
|
620
623
|
getQuery() {
|
|
621
624
|
return `
|
|
@@ -649,86 +652,87 @@ class Te extends w {
|
|
|
649
652
|
`;
|
|
650
653
|
}
|
|
651
654
|
}
|
|
652
|
-
const
|
|
653
|
-
var
|
|
654
|
-
const
|
|
655
|
-
function
|
|
656
|
-
return { capture_arguments:
|
|
655
|
+
const Ge = "getting request source code";
|
|
656
|
+
var M = ((n) => (n.UNKNOWN = "unknown", n.ANONYMOUS = "anonymous", n.NOT_CAPTURED = "not captured", n))(M || {});
|
|
657
|
+
const ie = "http:", ae = "https:";
|
|
658
|
+
function ke() {
|
|
659
|
+
return { capture_arguments: U(process.env.SF_FUNCSPAN_CAPTURE_ARGUMENTS, !0), capture_return_value: U(process.env.SF_FUNCSPAN_CAPTURE_RETURN_VALUE, !0), arg_limit_mb: parseInt(process.env.SF_FUNCSPAN_ARG_LIMIT_MB || "1", 10), return_limit_mb: parseInt(process.env.SF_FUNCSPAN_RETURN_LIMIT_MB || "1", 10), autocapture_all_child_functions: U(process.env.SF_FUNCSPAN_AUTOCAPTURE_ALL_CHILD_FUNCTIONS, !1), sample_rate: parseFloat(process.env.SF_FUNCSPAN_SAMPLE_RATE || "1.0"), enable_sampling: U(process.env.SF_FUNCSPAN_ENABLE_SAMPLING, !1), capture_sf_veritas: U(process.env.SF_FUNCSPAN_CAPTURE_SF_VERITAS, !1), parse_json_strings: U(process.env.SF_FUNCSPAN_PARSE_JSON_STRINGS, !1) };
|
|
657
660
|
}
|
|
658
|
-
function
|
|
661
|
+
function Ut() {
|
|
659
662
|
return { capture_arguments: !1, capture_return_value: !1, arg_limit_mb: 1, return_limit_mb: 1, autocapture_all_child_functions: !1, sample_rate: 0, enable_sampling: !1, capture_sf_veritas: !1, parse_json_strings: !1 };
|
|
660
663
|
}
|
|
661
|
-
function
|
|
664
|
+
function Ye(n) {
|
|
662
665
|
try {
|
|
663
|
-
const e =
|
|
666
|
+
const e = n.split("-");
|
|
664
667
|
return e.length !== 9 ? (console.error(`[FuncSpan] Invalid header format: expected 9 parts, got ${e.length}`), null) : { capture_arguments: e[0] === "1", capture_return_value: e[1] === "1", arg_limit_mb: parseInt(e[2], 10), return_limit_mb: parseInt(e[3], 10), autocapture_all_child_functions: e[4] === "1", sample_rate: parseFloat(e[5]), enable_sampling: e[6] === "1", capture_sf_veritas: e[7] === "1", parse_json_strings: e[8] === "1" };
|
|
665
668
|
} catch (e) {
|
|
666
|
-
return console.error(`[FuncSpan] Failed to parse header override "${
|
|
669
|
+
return console.error(`[FuncSpan] Failed to parse header override "${n}":`, e), null;
|
|
667
670
|
}
|
|
668
671
|
}
|
|
669
|
-
function
|
|
670
|
-
if (!
|
|
671
|
-
const t =
|
|
672
|
+
function U(n, e) {
|
|
673
|
+
if (!n) return e;
|
|
674
|
+
const t = n.toLowerCase();
|
|
672
675
|
return t === "true" || t === "1" || t === "yes";
|
|
673
676
|
}
|
|
674
|
-
const
|
|
675
|
-
function
|
|
676
|
-
|
|
677
|
+
const Ce = new pe();
|
|
678
|
+
function ct(n) {
|
|
679
|
+
Ce.enterWith(n);
|
|
677
680
|
}
|
|
678
|
-
function
|
|
679
|
-
return
|
|
681
|
+
function Je() {
|
|
682
|
+
return Ce.getStore();
|
|
680
683
|
}
|
|
681
|
-
function
|
|
682
|
-
|
|
684
|
+
function lt() {
|
|
685
|
+
Ce.enterWith(void 0);
|
|
683
686
|
}
|
|
684
|
-
function
|
|
687
|
+
function z(...n) {
|
|
685
688
|
const e = {};
|
|
686
|
-
for (const t of
|
|
689
|
+
for (const t of n) for (const s in t) t[s] !== void 0 && (e[s] = t[s]);
|
|
687
690
|
return e;
|
|
688
691
|
}
|
|
689
|
-
function
|
|
692
|
+
function J(n, e) {
|
|
690
693
|
try {
|
|
691
|
-
const t = JSON.stringify(
|
|
692
|
-
return t <= e ?
|
|
694
|
+
const t = JSON.stringify(n).length / 1048576;
|
|
695
|
+
return t <= e ? n : { _truncated: !0, _originalSizeMB: t.toFixed(2), _limitMB: e, _preview: JSON.stringify(n).substring(0, 500) + "..." };
|
|
693
696
|
} catch {
|
|
694
|
-
return { _error: "Failed to serialize data", _type: typeof
|
|
697
|
+
return { _error: "Failed to serialize data", _type: typeof n };
|
|
695
698
|
}
|
|
696
699
|
}
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
700
|
+
const gt = Me(import.meta.url);
|
|
701
|
+
let Ze = !1;
|
|
702
|
+
function dt() {
|
|
703
|
+
const n = d().sfDebug;
|
|
704
|
+
if (Ze) return void (n && console.log("[patchNodeHttpInbound] Already installed, skipping."));
|
|
701
705
|
let e;
|
|
702
|
-
|
|
706
|
+
Ze = !0;
|
|
703
707
|
try {
|
|
704
|
-
e =
|
|
705
|
-
} catch (
|
|
706
|
-
return void console.error("Failed to require node:http:",
|
|
707
|
-
}
|
|
708
|
-
if (!e?.Server?.prototype) return void (
|
|
709
|
-
const t = e.Server.prototype,
|
|
710
|
-
|
|
711
|
-
if (
|
|
712
|
-
const
|
|
713
|
-
const
|
|
714
|
-
if (!
|
|
715
|
-
for (const [
|
|
716
|
-
return
|
|
717
|
-
})(
|
|
718
|
-
|
|
719
|
-
const
|
|
720
|
-
|
|
721
|
-
const
|
|
722
|
-
return
|
|
723
|
-
|
|
724
|
-
const
|
|
725
|
-
|
|
708
|
+
e = gt("node:http"), n && console.log("[patchNodeHttpInbound] node:http required successfully.");
|
|
709
|
+
} catch (r) {
|
|
710
|
+
return void console.error("Failed to require node:http:", r);
|
|
711
|
+
}
|
|
712
|
+
if (!e?.Server?.prototype) return void (n && console.log("[patchNodeHttpInbound] http.Server.prototype not found."));
|
|
713
|
+
const t = e.Server.prototype, s = t.emit;
|
|
714
|
+
s && !t.__sf_inbound_patched__ ? (Object.defineProperty(t, "__sf_inbound_patched__", { value: !0, enumerable: !1, configurable: !1, writable: !1 }), n && console.log("[patchNodeHttpInbound] Patching http.Server.prototype.emit."), t.emit = function(r, ...a) {
|
|
715
|
+
if (r !== "request") return n && console.log(`[patchNodeHttpInbound] Passing through event: ${r}`), s.call(this, r, ...a);
|
|
716
|
+
const o = a[0], i = a[1], c = (function(m) {
|
|
717
|
+
const p = {};
|
|
718
|
+
if (!m) return p;
|
|
719
|
+
for (const [h, f] of Object.entries(m)) f != null && (Array.isArray(f) ? p[h.toLowerCase()] = f.join(", ") : p[h.toLowerCase()] = String(f));
|
|
720
|
+
return p;
|
|
721
|
+
})(o?.headers), l = c["x-sf3-rid"], g = c["x-sf3-functionspancaptureoverride"];
|
|
722
|
+
n && (console.log("[patchNodeHttpInbound] Intercepted request event."), console.log("[patchNodeHttpInbound] Inbound headers:", c), console.log("[patchNodeHttpInbound] Trace header:", l), console.log("[patchNodeHttpInbound] FuncSpan override header:", g));
|
|
723
|
+
const u = v.getInstance();
|
|
724
|
+
u.setTraceId(l);
|
|
725
|
+
const I = u.getTraceId();
|
|
726
|
+
return n && console.log("[patchNodeHttpInbound] Context traceId set:", I), u.runWith({ inboundHeaders: c, ...l ? { traceId: l } : {} }, () => {
|
|
727
|
+
l && u.setTraceId(l), g && (ct(g), n && console.log("[patchNodeHttpInbound] FuncSpan override set:", g)), n && console.log("[patchNodeHttpInbound] Running request handler in context.");
|
|
728
|
+
const m = () => {
|
|
729
|
+
n && console.log("[patchNodeHttpInbound] Response finished/closed for traceId:", u.getTraceId()), g && (lt(), n && console.log("[patchNodeHttpInbound] FuncSpan override cleared"));
|
|
726
730
|
};
|
|
727
|
-
return
|
|
731
|
+
return i.on("finish", m), i.on("close", m), s.call(this, r, o, i);
|
|
728
732
|
});
|
|
729
|
-
}) :
|
|
733
|
+
}) : n && console.log("[patchNodeHttpInbound] Already patched, skipping.");
|
|
730
734
|
}
|
|
731
|
-
class
|
|
735
|
+
class ut extends Ie {
|
|
732
736
|
constructor() {
|
|
733
737
|
super(), this.setOperationName("DomainsToNotPassHeaderTo");
|
|
734
738
|
}
|
|
@@ -748,11 +752,11 @@ class _e extends oe {
|
|
|
748
752
|
domains: $domains
|
|
749
753
|
)
|
|
750
754
|
}
|
|
751
|
-
`,
|
|
752
|
-
|
|
755
|
+
`, s = { apiKey: this.apiKey, serviceUuid: this.serviceUUID, domains: e };
|
|
756
|
+
W(this.endpoint, this.operationName, t, s);
|
|
753
757
|
}
|
|
754
758
|
}
|
|
755
|
-
class
|
|
759
|
+
class pt extends $ {
|
|
756
760
|
constructor() {
|
|
757
761
|
super();
|
|
758
762
|
C(this, "serviceIdentifier", new X());
|
|
@@ -765,8 +769,8 @@ class De extends w {
|
|
|
765
769
|
this.sendAppIdentifier(), this.send(t);
|
|
766
770
|
}
|
|
767
771
|
async send(t) {
|
|
768
|
-
const { name:
|
|
769
|
-
|
|
772
|
+
const { name: s, column: r, line: a, entrypoint: o, retryWithoutTraceId: i } = t, c = this.getVariables({ name: s, column: r, line: a, entrypoint: o, retryWithoutTraceId: i });
|
|
773
|
+
W(this.endpoint, this.operationName, this.getQuery(), c);
|
|
770
774
|
}
|
|
771
775
|
getQuery() {
|
|
772
776
|
return `
|
|
@@ -796,7 +800,7 @@ class De extends w {
|
|
|
796
800
|
`;
|
|
797
801
|
}
|
|
798
802
|
}
|
|
799
|
-
class
|
|
803
|
+
class It extends $ {
|
|
800
804
|
constructor() {
|
|
801
805
|
super();
|
|
802
806
|
C(this, "serviceIdentifier", new X());
|
|
@@ -819,188 +823,188 @@ class $e extends w {
|
|
|
819
823
|
`;
|
|
820
824
|
}
|
|
821
825
|
async send(t) {
|
|
822
|
-
const
|
|
823
|
-
await
|
|
826
|
+
const s = { data: { ...t } };
|
|
827
|
+
await W(this.endpoint, this.operationName, this.getQuery(), s);
|
|
824
828
|
}
|
|
825
829
|
}
|
|
826
|
-
const
|
|
827
|
-
class
|
|
830
|
+
const ce = [400, 403];
|
|
831
|
+
class Ct {
|
|
828
832
|
constructor(e = []) {
|
|
829
833
|
C(this, "HEADER_TRACING", "X-Sf3-Rid");
|
|
830
834
|
C(this, "HEADER_LOG_GUARD", "reentrancy_guard_logging_preactive");
|
|
831
835
|
C(this, "HEADER_PRINT_GUARD", "reentrancy_guard_print_preactive");
|
|
832
836
|
C(this, "HEADER_EXCEPTION_GUARD", "reentrancy_guard_exception_preactive");
|
|
833
837
|
C(this, "contextManager");
|
|
834
|
-
this.contextManager =
|
|
838
|
+
this.contextManager = v.getInstance(), e?.forEach((t) => {
|
|
835
839
|
typeof t == "string" && t.trim() && this.contextManager.getExcludedDomains().add(t);
|
|
836
|
-
}),
|
|
840
|
+
}), d().sfDebug && console.log("[RequestInterceptor] Initialized with static excluded domains.");
|
|
837
841
|
}
|
|
838
842
|
extractIdsFromTraceHeader(e, t = this.HEADER_TRACING) {
|
|
839
|
-
let
|
|
840
|
-
if (e instanceof Headers)
|
|
843
|
+
let s;
|
|
844
|
+
if (e instanceof Headers) s = e.get(t) ?? void 0;
|
|
841
845
|
else {
|
|
842
|
-
const
|
|
843
|
-
for (const [
|
|
844
|
-
|
|
846
|
+
const a = t.toLowerCase();
|
|
847
|
+
for (const [o, i] of Object.entries(e)) if (o.toLowerCase() === a) {
|
|
848
|
+
s = i;
|
|
845
849
|
break;
|
|
846
850
|
}
|
|
847
851
|
}
|
|
848
|
-
if (!
|
|
849
|
-
const
|
|
850
|
-
return
|
|
852
|
+
if (!s) return {};
|
|
853
|
+
const r = s.split("/").filter(Boolean);
|
|
854
|
+
return r.length < 3 ? {} : { sessionId: r[0], pageVisitId: r[1], requestId: r[r.length - 1] };
|
|
851
855
|
}
|
|
852
856
|
parseStackFrame(e) {
|
|
853
857
|
const t = /\((.*):(\d+):(\d+)\)$/.exec(e.trim());
|
|
854
858
|
if (!t) return null;
|
|
855
|
-
const [,
|
|
856
|
-
return { filePath:
|
|
859
|
+
const [, s, r, a] = t;
|
|
860
|
+
return { filePath: s, line: parseInt(r, 10), column: parseInt(a, 10) };
|
|
857
861
|
}
|
|
858
|
-
async getOriginalPosition(e, t,
|
|
859
|
-
let
|
|
860
|
-
const
|
|
862
|
+
async getOriginalPosition(e, t, s) {
|
|
863
|
+
let r = { source: e, line: t, column: s, name: null };
|
|
864
|
+
const a = e + ".map";
|
|
861
865
|
try {
|
|
862
|
-
const
|
|
863
|
-
let
|
|
864
|
-
|
|
865
|
-
} catch (
|
|
866
|
-
|
|
866
|
+
const o = JSON.parse(Re(a, "utf-8"));
|
|
867
|
+
let i = (await new He.SourceMapConsumer(o)).originalPositionFor({ line: t, column: s });
|
|
868
|
+
i.source && (r = i);
|
|
869
|
+
} catch (o) {
|
|
870
|
+
d().sfDebug && console.error(`Could not read/parse map file at ${a}:`, o);
|
|
867
871
|
}
|
|
868
|
-
return { originalPos:
|
|
869
|
-
}
|
|
870
|
-
captureFirstUserLines(e, t = 10,
|
|
871
|
-
const
|
|
872
|
-
Error.stackTraceLimit = Math.max(
|
|
873
|
-
const
|
|
874
|
-
|
|
875
|
-
const
|
|
876
|
-
Error.stackTraceLimit =
|
|
877
|
-
const
|
|
878
|
-
`).slice(1),
|
|
879
|
-
for (const
|
|
880
|
-
if (!(
|
|
881
|
-
for (const
|
|
882
|
-
const
|
|
883
|
-
|
|
884
|
-
const { originalPos:
|
|
885
|
-
if (
|
|
886
|
-
|
|
887
|
-
const
|
|
888
|
-
e.doSend(
|
|
872
|
+
return { originalPos: r };
|
|
873
|
+
}
|
|
874
|
+
captureFirstUserLines(e, t = 10, s = !1) {
|
|
875
|
+
const r = d().sfDebug ? 10 : t, a = Error.stackTraceLimit;
|
|
876
|
+
Error.stackTraceLimit = Math.max(a, r);
|
|
877
|
+
const o = new Error(Ge);
|
|
878
|
+
Ge in Error && Error.captureStackTrace(o, this.captureFirstUserLines);
|
|
879
|
+
const i = o.stack || "";
|
|
880
|
+
Error.stackTraceLimit = a;
|
|
881
|
+
const c = i.split(`
|
|
882
|
+
`).slice(1), l = [];
|
|
883
|
+
for (const g of c)
|
|
884
|
+
if (!(g.includes("node:internal") || g.includes("internal/modules") || g.includes("internal/process") || g.includes("node_modules") || g.includes(".next/server/chunks") || g.includes("RequestInterceptor") || g.includes("contextManager") || g.includes("setupConfig")) && (l.push(g.trim()), l.length >= t)) break;
|
|
885
|
+
for (const g of l) {
|
|
886
|
+
const u = this.parseStackFrame(g);
|
|
887
|
+
u ? (async () => {
|
|
888
|
+
const { originalPos: I } = await this.getOriginalPosition(u.filePath, u.line, u.column);
|
|
889
|
+
if (I) {
|
|
890
|
+
d().sfDebug && console.log("[RequestInterceptor] First user code line:", I);
|
|
891
|
+
const m = { line: I.line?.toString() || M.UNKNOWN, column: I.column?.toString() || M.NOT_CAPTURED, name: I.name || M.NOT_CAPTURED, entrypoint: I.source, retryWithoutTraceId: s };
|
|
892
|
+
e.doSend(m);
|
|
889
893
|
}
|
|
890
|
-
})() :
|
|
894
|
+
})() : d().sfDebug && console.error("Could not parse stack line:", g);
|
|
891
895
|
}
|
|
892
896
|
}
|
|
893
897
|
addReentrancyGuardHeaders(e) {
|
|
894
898
|
e.set(this.HEADER_LOG_GUARD, "true"), e.set(this.HEADER_PRINT_GUARD, "true"), e.set(this.HEADER_EXCEPTION_GUARD, "true");
|
|
895
899
|
}
|
|
896
900
|
shouldPropagateHeaders(e) {
|
|
897
|
-
return !
|
|
901
|
+
return !Ue.some((t) => new RegExp(`^${t.replace(/\*/g, ".*")}$`).test(e));
|
|
898
902
|
}
|
|
899
903
|
addTracingHeaders(e, t) {
|
|
900
|
-
const
|
|
901
|
-
return
|
|
904
|
+
const s = new URL(t).hostname, r = this.shouldPropagateHeaders(s);
|
|
905
|
+
return r ? this.addTracingHeader(e, t) : d().sfDebug && console.error(`[RequestInterceptor] Excluded domain: ${s}`), r;
|
|
902
906
|
}
|
|
903
907
|
addTracingHeader(e, t) {
|
|
904
|
-
const
|
|
905
|
-
if (
|
|
906
|
-
const
|
|
907
|
-
if (
|
|
908
|
+
const s = Je();
|
|
909
|
+
if (s) {
|
|
910
|
+
const i = Ye(s);
|
|
911
|
+
if (i && i.sample_rate === 0) return void (d().sfDebug && console.log(`[RequestInterceptor] Function span tracking disabled (sample_rate=0), skipping tracing header for ${t}`));
|
|
908
912
|
}
|
|
909
|
-
const
|
|
910
|
-
e.set(this.HEADER_TRACING, `${
|
|
913
|
+
const r = this.contextManager.getOrSetSfTraceId(), a = this.contextManager.getOrSetPageVisitUUID(), o = w();
|
|
914
|
+
e.set(this.HEADER_TRACING, `${r}/${a}/${o}`), d().sfDebug && console.log(`[RequestInterceptor] Added tracing header for ${t}`);
|
|
911
915
|
}
|
|
912
916
|
patchFetch(e, t) {
|
|
913
|
-
const
|
|
914
|
-
typeof
|
|
915
|
-
const
|
|
916
|
-
if (
|
|
917
|
+
const s = globalThis.fetch;
|
|
918
|
+
typeof s == "function" ? globalThis.fetch = async (r, a) => {
|
|
919
|
+
const o = new Headers(a?.headers);
|
|
920
|
+
if (o.get(this.HEADER_LOG_GUARD) === "true" || o.get(this.HEADER_PRINT_GUARD) === "true" || o.get(this.HEADER_EXCEPTION_GUARD) === "true") return s(r, a);
|
|
917
921
|
this.captureFirstUserLines(e);
|
|
918
|
-
const
|
|
919
|
-
let
|
|
920
|
-
typeof
|
|
921
|
-
|
|
922
|
-
})) :
|
|
923
|
-
const
|
|
924
|
-
let
|
|
922
|
+
const i = Date.now();
|
|
923
|
+
let c;
|
|
924
|
+
typeof r == "string" || r instanceof URL ? c = r.toString() : r instanceof Request ? (c = r.url, r.headers.forEach((p, h) => {
|
|
925
|
+
o.set(h, p);
|
|
926
|
+
})) : d().sfDebug && console.error("[Sailfish RequestInterceptor] Invalid fetch input."), d().sfDebug && console.log("[RequestInterceptor] Fetching request to:", c);
|
|
927
|
+
const l = new URL(c).hostname, g = new Headers(o), u = this.addTracingHeaders(o, c), I = { ...a, headers: o };
|
|
928
|
+
let m;
|
|
925
929
|
try {
|
|
926
|
-
let
|
|
927
|
-
this.addTracingHeaders(
|
|
928
|
-
const
|
|
929
|
-
|
|
930
|
-
const { sessionId:
|
|
931
|
-
return t.doSend({ apiKey:
|
|
932
|
-
} catch (
|
|
933
|
-
const
|
|
934
|
-
|
|
930
|
+
let p = !1;
|
|
931
|
+
this.addTracingHeaders(g, c), m = await s(c, I), u && ce.includes(m.status) ? (m = await s(c, { ...a, headers: g }), p = !0, this.captureFirstUserLines(e, 10, p)) : this.contextManager.addSupportedDomains(l);
|
|
932
|
+
const h = Date.now();
|
|
933
|
+
d().sfDebug && console.log(`[RequestInterceptor] Fetch completed: ${c}, Status: ${m.status}, Duration: ${h - i}ms`);
|
|
934
|
+
const { sessionId: f, pageVisitId: S, requestId: b } = this.extractIdsFromTraceHeader(o);
|
|
935
|
+
return t.doSend({ apiKey: d().apiKey, requestId: b, pageVisitId: S, recordingSessionId: f, serviceUuid: d().serviceUUID, timestampStart: i.toString(), timestampEnd: h.toString(), responseCode: m.status, success: !0, error: null, url: c, method: I.method || "GET", retryWithoutTraceId: p, parentSpanId: oe() }), m;
|
|
936
|
+
} catch (p) {
|
|
937
|
+
const h = Date.now();
|
|
938
|
+
d().sfDebug && console.error(`[RequestInterceptor] Fetch failed: ${c}, Error: ${p}, Duration: ${h - i}ms`);
|
|
935
939
|
}
|
|
936
|
-
} :
|
|
940
|
+
} : d().sfDebug && console.error("[RequestInterceptor] Fetch not available.");
|
|
937
941
|
}
|
|
938
942
|
patchHttp(e, t) {
|
|
939
|
-
if (
|
|
940
|
-
const
|
|
941
|
-
|
|
942
|
-
let
|
|
943
|
+
if (d().sfDebug && console.log("[RequestInterceptor] Initializing HTTP/HTTPS request patch..."), !B || typeof B.request != "function") return void (d().sfDebug && console.log("[RequestInterceptor] HTTP/HTTPS not available."));
|
|
944
|
+
const s = B.request.bind(B), r = B.request.bind(B);
|
|
945
|
+
B.request = function(a, o) {
|
|
946
|
+
let i;
|
|
943
947
|
try {
|
|
944
|
-
if (typeof
|
|
945
|
-
const
|
|
946
|
-
|
|
947
|
-
} else
|
|
948
|
-
if (
|
|
949
|
-
const
|
|
950
|
-
this.addTracingHeaders(
|
|
951
|
-
} else
|
|
952
|
-
} catch (
|
|
953
|
-
throw
|
|
948
|
+
if (typeof a == "string") {
|
|
949
|
+
const l = new URL(a);
|
|
950
|
+
i = { protocol: l.protocol || ie, hostname: l.hostname, path: l.pathname + l.search, headers: {} };
|
|
951
|
+
} else a instanceof URL ? i = { protocol: a.protocol || ie, hostname: a.hostname, path: a.pathname + a.search, headers: {} } : (i = { ...a }, i.protocol || (i.protocol = ie));
|
|
952
|
+
if (i.headers) {
|
|
953
|
+
const l = `${i.protocol}//${i.hostname}`;
|
|
954
|
+
this.addTracingHeaders(i.headers, l), this.captureFirstUserLines(e);
|
|
955
|
+
} else d().sfDebug && console.warn("[RequestInterceptor] No headers found in HTTP request options. Skipping header addition.");
|
|
956
|
+
} catch (l) {
|
|
957
|
+
throw d().sfDebug && console.error("[RequestInterceptor] Error while processing HTTP request options:", l), l;
|
|
954
958
|
}
|
|
955
|
-
let
|
|
956
|
-
return
|
|
957
|
-
const
|
|
958
|
-
if (
|
|
959
|
-
|
|
960
|
-
const
|
|
961
|
-
delete
|
|
959
|
+
let c = !1;
|
|
960
|
+
return s(i, (l) => {
|
|
961
|
+
const g = `${i.protocol}//${i.hostname}`;
|
|
962
|
+
if (i.headers && this.shouldPropagateHeaders(new URL(g).hostname) && ce.includes(l.statusCode || 0)) {
|
|
963
|
+
i.hostname;
|
|
964
|
+
const p = { ...i, headers: { ...i.headers } };
|
|
965
|
+
delete p.headers[this.HEADER_TRACING], s(p, o), c = !0, this.captureFirstUserLines(e, 10, c);
|
|
962
966
|
}
|
|
963
|
-
const { sessionId:
|
|
964
|
-
t.doSend({ apiKey:
|
|
967
|
+
const { sessionId: u, pageVisitId: I, requestId: m } = this.extractIdsFromTraceHeader(i.headers);
|
|
968
|
+
t.doSend({ apiKey: d().apiKey, requestId: m, pageVisitId: I, recordingSessionId: u, serviceUuid: d().serviceUUID, timestampStart: Date.now().toString(), timestampEnd: Date.now().toString(), responseCode: l.statusCode || 0, success: !!l.statusCode && l.statusCode < 400, error: null, url: g, method: i.method || "GET", retryWithoutTraceId: c, parentSpanId: oe() }), o?.(l);
|
|
965
969
|
});
|
|
966
|
-
},
|
|
967
|
-
let
|
|
970
|
+
}, B.request = function(a, o) {
|
|
971
|
+
let i;
|
|
968
972
|
try {
|
|
969
|
-
if (typeof
|
|
970
|
-
const
|
|
971
|
-
|
|
972
|
-
} else
|
|
973
|
-
if (
|
|
974
|
-
const
|
|
975
|
-
this.addTracingHeaders(
|
|
976
|
-
} else
|
|
977
|
-
} catch (
|
|
978
|
-
throw
|
|
973
|
+
if (typeof a == "string") {
|
|
974
|
+
const l = new URL(a);
|
|
975
|
+
i = { protocol: l.protocol || ae, hostname: l.hostname, path: l.pathname + l.search, headers: {} };
|
|
976
|
+
} else a instanceof URL ? i = { protocol: a.protocol || ae, hostname: a.hostname, path: a.pathname + a.search, headers: {} } : (i = { ...a }, i.protocol || (i.protocol = ae));
|
|
977
|
+
if (i.headers) {
|
|
978
|
+
const l = `${i.protocol}//${i.hostname}`;
|
|
979
|
+
this.addTracingHeaders(i.headers, l);
|
|
980
|
+
} else d().sfDebug && console.warn("[RequestInterceptor] No headers found in HTTPS request options. Skipping header addition.");
|
|
981
|
+
} catch (l) {
|
|
982
|
+
throw d().sfDebug && console.error("[RequestInterceptor] Error while processing HTTPS request options:", l), l;
|
|
979
983
|
}
|
|
980
|
-
let
|
|
981
|
-
return i
|
|
982
|
-
const
|
|
983
|
-
if (
|
|
984
|
-
const
|
|
985
|
-
delete
|
|
984
|
+
let c = !1;
|
|
985
|
+
return r(i, (l) => {
|
|
986
|
+
const g = `${i.protocol}//${i.hostname}`;
|
|
987
|
+
if (i.headers && this.shouldPropagateHeaders(new URL(g).hostname) && ce.includes(l.statusCode || 0)) {
|
|
988
|
+
const p = { ...i, headers: { ...i.headers } };
|
|
989
|
+
delete p.headers[this.HEADER_TRACING], r(p, o), c = !0, this.captureFirstUserLines(e, 10, c);
|
|
986
990
|
}
|
|
987
|
-
const { sessionId:
|
|
988
|
-
t.doSend({ apiKey:
|
|
991
|
+
const { sessionId: u, pageVisitId: I, requestId: m } = this.extractIdsFromTraceHeader(i.headers);
|
|
992
|
+
t.doSend({ apiKey: d().apiKey, requestId: m, pageVisitId: I, recordingSessionId: u, serviceUuid: d().serviceUUID, timestampStart: Date.now().toString(), timestampEnd: Date.now().toString(), responseCode: l.statusCode || 0, success: !!l.statusCode && l.statusCode < 400, error: null, url: g, method: i.method || "GET", retryWithoutTraceId: c, parentSpanId: oe() }), o?.(l);
|
|
989
993
|
});
|
|
990
|
-
},
|
|
994
|
+
}, d().sfDebug && console.log("✅ HTTP and HTTPS request methods patched globally.");
|
|
991
995
|
}
|
|
992
996
|
tryPatch(e, t) {
|
|
993
997
|
try {
|
|
994
998
|
require.resolve(t), e(), console.log(`[RequestInterceptor] Patched ${t}`);
|
|
995
|
-
} catch (
|
|
996
|
-
console.warn(`[RequestInterceptor] Could not patch ${t}: ${
|
|
999
|
+
} catch (s) {
|
|
1000
|
+
console.warn(`[RequestInterceptor] Could not patch ${t}: ${s.message}`);
|
|
997
1001
|
}
|
|
998
1002
|
}
|
|
999
1003
|
getExcludedDomains() {
|
|
1000
1004
|
return [...this.contextManager.getExcludedDomains()];
|
|
1001
1005
|
}
|
|
1002
1006
|
}
|
|
1003
|
-
class
|
|
1007
|
+
class mt extends Ie {
|
|
1004
1008
|
constructor() {
|
|
1005
1009
|
super(), this.setOperationName("UpdateServiceDetails");
|
|
1006
1010
|
}
|
|
@@ -1028,11 +1032,11 @@ class ze extends oe {
|
|
|
1028
1032
|
gitSha: $gitSha,
|
|
1029
1033
|
)
|
|
1030
1034
|
}
|
|
1031
|
-
`, t = this.getVariables({ serviceIdentifier:
|
|
1032
|
-
|
|
1035
|
+
`, t = this.getVariables({ serviceIdentifier: d().serviceIdentifier, serviceVersion: d().serviceVersion, serviceAdditionalMetadata: d().serviceAdditionalMetadata, gitSha: d().gitSha || "" });
|
|
1036
|
+
W(this.endpoint, this.operationName, e, t);
|
|
1033
1037
|
}
|
|
1034
1038
|
}
|
|
1035
|
-
class
|
|
1039
|
+
class ht {
|
|
1036
1040
|
constructor(e = [process.cwd()], t = !1) {
|
|
1037
1041
|
C(this, "rootPaths");
|
|
1038
1042
|
C(this, "fileConfigs", /* @__PURE__ */ new Map());
|
|
@@ -1045,163 +1049,391 @@ class xe {
|
|
|
1045
1049
|
async loadAllConfigs() {
|
|
1046
1050
|
this.debug && console.log("[FuncSpan ConfigLoader] Scanning for .sailfish files in:", this.rootPaths);
|
|
1047
1051
|
const e = [];
|
|
1048
|
-
for (const t of this.rootPaths)
|
|
1052
|
+
for (const t of this.rootPaths) te.existsSync(t) ? await this._walkDirectory(t, e) : this.debug && console.log(`[FuncSpan ConfigLoader] Root path does not exist: ${t}`);
|
|
1049
1053
|
e.length > 0 ? (this.hasSailfishFiles = !0, this.debug && (console.log(`[FuncSpan ConfigLoader] Found ${e.length} .sailfish files:`), e.forEach((t) => console.log(`[FuncSpan ConfigLoader] - ${t}`)))) : this.debug && console.log("[FuncSpan ConfigLoader] No .sailfish files found - function spans disabled by default");
|
|
1050
1054
|
for (const t of e) await this._loadConfigFile(t);
|
|
1051
1055
|
await this._resolveInheritance(), this.debug && console.log(`[FuncSpan ConfigLoader] Loaded ${this.fileConfigs.size} file configs, ${this.functionConfigs.size} function configs`);
|
|
1052
1056
|
}
|
|
1053
1057
|
getConfig(e, t) {
|
|
1054
|
-
const
|
|
1055
|
-
let
|
|
1058
|
+
const s = this.hasSailfishFiles ? ke() : { capture_arguments: !1, capture_return_value: !1, arg_limit_mb: 1, return_limit_mb: 1, autocapture_all_child_functions: !1, sample_rate: 0, enable_sampling: !1, capture_sf_veritas: !1, parse_json_strings: !1 }, r = this._getDirectoryConfig(e), a = G.normalize(e), o = this.fileConfigs.get(a) || {};
|
|
1059
|
+
let i = {};
|
|
1056
1060
|
if (t) {
|
|
1057
|
-
const
|
|
1058
|
-
|
|
1061
|
+
const c = this.functionConfigs.get(a);
|
|
1062
|
+
c && (i = c.get(t) || {});
|
|
1059
1063
|
}
|
|
1060
|
-
return
|
|
1064
|
+
return z(s, r, o, i);
|
|
1061
1065
|
}
|
|
1062
1066
|
async _walkDirectory(e, t) {
|
|
1063
1067
|
try {
|
|
1064
|
-
const
|
|
1065
|
-
for (const
|
|
1066
|
-
const
|
|
1067
|
-
|
|
1068
|
+
const s = te.readdirSync(e, { withFileTypes: !0 });
|
|
1069
|
+
for (const r of s) {
|
|
1070
|
+
const a = G.join(e, r.name);
|
|
1071
|
+
r.isFile() && r.name === ".sailfish" ? t.push(a) : r.name === "node_modules" || r.isDirectory() && r.name.startsWith(".") && r.name !== ".sailfish" || r.isDirectory() && await this._walkDirectory(a, t);
|
|
1068
1072
|
}
|
|
1069
|
-
} catch (
|
|
1070
|
-
this.debug && console.error(`[FuncSpan ConfigLoader] Error walking directory ${e}:`,
|
|
1073
|
+
} catch (s) {
|
|
1074
|
+
this.debug && console.error(`[FuncSpan ConfigLoader] Error walking directory ${e}:`, s);
|
|
1071
1075
|
}
|
|
1072
1076
|
}
|
|
1073
1077
|
async _loadConfigFile(e) {
|
|
1074
1078
|
try {
|
|
1075
|
-
const t =
|
|
1076
|
-
let
|
|
1079
|
+
const t = te.readFileSync(e, "utf-8"), s = G.dirname(e);
|
|
1080
|
+
let r = null;
|
|
1077
1081
|
try {
|
|
1078
|
-
|
|
1082
|
+
r = JSON.parse(t);
|
|
1079
1083
|
} catch {
|
|
1080
1084
|
try {
|
|
1081
|
-
|
|
1082
|
-
} catch (
|
|
1083
|
-
return void (this.debug && console.error(`[FuncSpan ConfigLoader] Failed to parse ${e} as JSON or YAML:`,
|
|
1085
|
+
r = require("js-yaml").load(t);
|
|
1086
|
+
} catch (a) {
|
|
1087
|
+
return void (this.debug && console.error(`[FuncSpan ConfigLoader] Failed to parse ${e} as JSON or YAML:`, a));
|
|
1084
1088
|
}
|
|
1085
1089
|
}
|
|
1086
|
-
if (!
|
|
1087
|
-
|
|
1090
|
+
if (!r) return;
|
|
1091
|
+
r.default && this.directoryConfigs.set(s, r.default), r.files && await this._expandFileGlobs(s, r.files, r.default || {}), r.functions && this._storeFunctionConfigs(s, r.functions, r.default || {}), this.debug && (console.log(`[FuncSpan ConfigLoader] Loaded config from ${e}`), console.log(`[FuncSpan ConfigLoader] Directory: ${s}`), console.log(`[FuncSpan ConfigLoader] Has default: ${!!r.default}`), console.log(`[FuncSpan ConfigLoader] File patterns: ${Object.keys(r.files || {}).length}`), console.log(`[FuncSpan ConfigLoader] Functions: ${Object.keys(r.functions || {}).length}`));
|
|
1088
1092
|
} catch (t) {
|
|
1089
1093
|
this.debug && console.error(`[FuncSpan ConfigLoader] Error loading ${e}:`, t);
|
|
1090
1094
|
}
|
|
1091
1095
|
}
|
|
1092
|
-
async _expandFileGlobs(e, t,
|
|
1093
|
-
for (const [
|
|
1094
|
-
const
|
|
1095
|
-
this.debug && console.log(`[FuncSpan ConfigLoader] Pattern '${
|
|
1096
|
-
for (const
|
|
1097
|
-
const
|
|
1098
|
-
this.fileConfigs.set(
|
|
1096
|
+
async _expandFileGlobs(e, t, s) {
|
|
1097
|
+
for (const [r, a] of Object.entries(t)) try {
|
|
1098
|
+
const o = G.join(e, r), i = await je(o, { absolute: !0, nodir: !0, ignore: ["**/node_modules/**", "**/.git/**"] });
|
|
1099
|
+
this.debug && console.log(`[FuncSpan ConfigLoader] Pattern '${r}' matched ${i.length} files`);
|
|
1100
|
+
for (const c of i) {
|
|
1101
|
+
const l = G.normalize(c), g = z(s, a);
|
|
1102
|
+
this.fileConfigs.set(l, g), this.debug && i.length <= 5 && console.log(`[FuncSpan ConfigLoader] - ${c}`);
|
|
1099
1103
|
}
|
|
1100
|
-
} catch (
|
|
1101
|
-
this.debug && console.error(`[FuncSpan ConfigLoader] Error expanding glob '${
|
|
1104
|
+
} catch (o) {
|
|
1105
|
+
this.debug && console.error(`[FuncSpan ConfigLoader] Error expanding glob '${r}':`, o);
|
|
1102
1106
|
}
|
|
1103
1107
|
}
|
|
1104
|
-
_storeFunctionConfigs(e, t,
|
|
1105
|
-
for (const [
|
|
1106
|
-
const
|
|
1107
|
-
if (
|
|
1108
|
-
this.debug && console.warn(`[FuncSpan ConfigLoader] Invalid function pattern '${
|
|
1108
|
+
_storeFunctionConfigs(e, t, s) {
|
|
1109
|
+
for (const [r, a] of Object.entries(t)) {
|
|
1110
|
+
const o = r.split("::");
|
|
1111
|
+
if (o.length !== 2) {
|
|
1112
|
+
this.debug && console.warn(`[FuncSpan ConfigLoader] Invalid function pattern '${r}' (expected format: 'file.ts::functionName')`);
|
|
1109
1113
|
continue;
|
|
1110
1114
|
}
|
|
1111
|
-
const [
|
|
1112
|
-
this.functionConfigs.has(
|
|
1113
|
-
const
|
|
1114
|
-
|
|
1115
|
+
const [i, c] = o, l = G.normalize(G.join(e, i));
|
|
1116
|
+
this.functionConfigs.has(l) || this.functionConfigs.set(l, /* @__PURE__ */ new Map());
|
|
1117
|
+
const g = this.functionConfigs.get(l), u = z(s, a);
|
|
1118
|
+
g.set(c, u), this.debug && console.log(`[FuncSpan ConfigLoader] Function config: ${l}::${c}`);
|
|
1115
1119
|
}
|
|
1116
1120
|
}
|
|
1117
1121
|
async _resolveInheritance() {
|
|
1118
1122
|
}
|
|
1119
1123
|
_getDirectoryConfig(e) {
|
|
1120
|
-
let t =
|
|
1121
|
-
const
|
|
1122
|
-
for (; t && t !==
|
|
1123
|
-
const
|
|
1124
|
-
|
|
1124
|
+
let t = G.dirname(G.normalize(e));
|
|
1125
|
+
const s = [];
|
|
1126
|
+
for (; t && t !== G.dirname(t); ) {
|
|
1127
|
+
const r = this.directoryConfigs.get(t);
|
|
1128
|
+
r && s.unshift(r), t = G.dirname(t);
|
|
1125
1129
|
}
|
|
1126
|
-
return
|
|
1130
|
+
return s.reduce((r, a) => z(r, a), {});
|
|
1127
1131
|
}
|
|
1128
1132
|
}
|
|
1129
|
-
let
|
|
1130
|
-
async function
|
|
1131
|
-
|
|
1133
|
+
let D = null;
|
|
1134
|
+
async function ft(n, e) {
|
|
1135
|
+
D = new ht(n, e), await D.loadAllConfigs();
|
|
1132
1136
|
}
|
|
1133
|
-
function
|
|
1134
|
-
return
|
|
1137
|
+
function bt(n, e) {
|
|
1138
|
+
return D ? D.getConfig(n, e) : (process.env.SF_DEBUG === "true" && console.log("[FuncSpan ConfigLoader] Config loader not initialized, using env config for worker process"), ke());
|
|
1135
1139
|
}
|
|
1136
|
-
function
|
|
1137
|
-
return
|
|
1140
|
+
function At() {
|
|
1141
|
+
return D !== null;
|
|
1138
1142
|
}
|
|
1139
|
-
function
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
const
|
|
1145
|
-
if (
|
|
1146
|
-
|
|
1147
|
-
|
|
1143
|
+
function V(n, e) {
|
|
1144
|
+
const t = process.env[n];
|
|
1145
|
+
return t === void 0 ? e : t === "true" || t === "1";
|
|
1146
|
+
}
|
|
1147
|
+
function Be(n, e) {
|
|
1148
|
+
const t = process.env[n];
|
|
1149
|
+
if (t === void 0) return e;
|
|
1150
|
+
const s = parseFloat(t);
|
|
1151
|
+
return isNaN(s) ? e : s;
|
|
1152
|
+
}
|
|
1153
|
+
function me() {
|
|
1154
|
+
return { enabled: V("SF_WORKER_POOL_ENABLED", !0), trackFs: V("SF_WORKER_POOL_TRACK_FS", !1), trackDns: V("SF_WORKER_POOL_TRACK_DNS", !0), trackCrypto: V("SF_WORKER_POOL_TRACK_CRYPTO", !1), trackZlib: V("SF_WORKER_POOL_TRACK_ZLIB", !1), captureArguments: V("SF_WORKER_POOL_CAPTURE_ARGUMENTS", !0), captureReturnValue: V("SF_WORKER_POOL_CAPTURE_RETURN_VALUE", !0), argLimitMb: Be("SF_WORKER_POOL_ARG_LIMIT_MB", 1), returnLimitMb: Be("SF_WORKER_POOL_RETURN_LIMIT_MB", 1) };
|
|
1155
|
+
}
|
|
1156
|
+
function O(n) {
|
|
1157
|
+
const e = me();
|
|
1158
|
+
if (!e.enabled) return !1;
|
|
1159
|
+
switch (n) {
|
|
1160
|
+
case "fs":
|
|
1161
|
+
return e.trackFs;
|
|
1162
|
+
case "dns":
|
|
1163
|
+
return e.trackDns;
|
|
1164
|
+
case "crypto":
|
|
1165
|
+
return e.trackCrypto;
|
|
1166
|
+
case "zlib":
|
|
1167
|
+
return e.trackZlib;
|
|
1168
|
+
default:
|
|
1169
|
+
return !1;
|
|
1148
1170
|
}
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1171
|
+
}
|
|
1172
|
+
function De(n, e, t, s) {
|
|
1173
|
+
let r;
|
|
1174
|
+
try {
|
|
1175
|
+
switch (n) {
|
|
1176
|
+
case "fs":
|
|
1177
|
+
r = (function(a, o) {
|
|
1178
|
+
const i = {};
|
|
1179
|
+
switch (a) {
|
|
1180
|
+
case "readFile":
|
|
1181
|
+
case "writeFile":
|
|
1182
|
+
case "appendFile":
|
|
1183
|
+
i.path = String(o[0] || ""), o[1] && typeof o[1] == "object" ? (i.encoding = o[1].encoding || null, i.flag = o[1].flag || null) : typeof o[1] == "string" && (i.encoding = o[1]), a !== "writeFile" && a !== "appendFile" || (Buffer.isBuffer(o[1]) ? (i.dataType = "Buffer", i.dataSize = o[1].length) : typeof o[1] == "string" && (i.dataType = "string", i.dataSize = o[1].length));
|
|
1184
|
+
break;
|
|
1185
|
+
case "readdir":
|
|
1186
|
+
case "stat":
|
|
1187
|
+
case "lstat":
|
|
1188
|
+
case "access":
|
|
1189
|
+
case "chmod":
|
|
1190
|
+
case "mkdir":
|
|
1191
|
+
case "rmdir":
|
|
1192
|
+
case "unlink":
|
|
1193
|
+
i.path = String(o[0] || ""), o[1] && typeof o[1] == "object" && (i.options = { ...o[1] }, delete i.options.callback);
|
|
1194
|
+
break;
|
|
1195
|
+
case "rename":
|
|
1196
|
+
i.oldPath = String(o[0] || ""), i.newPath = String(o[1] || "");
|
|
1197
|
+
break;
|
|
1198
|
+
case "open":
|
|
1199
|
+
i.path = String(o[0] || ""), i.flags = o[1], i.mode = o[2];
|
|
1200
|
+
break;
|
|
1201
|
+
case "close":
|
|
1202
|
+
case "fstat":
|
|
1203
|
+
i.fd = o[0];
|
|
1204
|
+
break;
|
|
1205
|
+
case "read":
|
|
1206
|
+
case "write":
|
|
1207
|
+
i.fd = o[0], Buffer.isBuffer(o[1]) && (i.bufferSize = o[1].length), i.offset = o[2], i.length = o[3], i.position = o[4];
|
|
1208
|
+
break;
|
|
1209
|
+
default:
|
|
1210
|
+
i.argsCount = o.length - 1;
|
|
1211
|
+
}
|
|
1212
|
+
return i;
|
|
1213
|
+
})(e, t);
|
|
1214
|
+
break;
|
|
1215
|
+
case "dns":
|
|
1216
|
+
r = (function(a, o) {
|
|
1217
|
+
const i = {};
|
|
1218
|
+
switch (a) {
|
|
1219
|
+
case "lookup":
|
|
1220
|
+
i.hostname = String(o[0] || ""), typeof o[1] == "object" ? (i.family = o[1].family, i.all = o[1].all) : typeof o[1] == "number" && (i.family = o[1]);
|
|
1221
|
+
break;
|
|
1222
|
+
case "resolve":
|
|
1223
|
+
case "resolve4":
|
|
1224
|
+
case "resolve6":
|
|
1225
|
+
case "resolveAny":
|
|
1226
|
+
case "resolveMx":
|
|
1227
|
+
case "resolveNs":
|
|
1228
|
+
case "resolveTxt":
|
|
1229
|
+
i.hostname = String(o[0] || "");
|
|
1230
|
+
break;
|
|
1231
|
+
case "reverse":
|
|
1232
|
+
i.ip = String(o[0] || "");
|
|
1233
|
+
break;
|
|
1234
|
+
default:
|
|
1235
|
+
i.argsCount = o.length - 1;
|
|
1236
|
+
}
|
|
1237
|
+
return i;
|
|
1238
|
+
})(e, t);
|
|
1239
|
+
break;
|
|
1240
|
+
case "crypto":
|
|
1241
|
+
r = (function(a, o) {
|
|
1242
|
+
const i = {};
|
|
1243
|
+
switch (a) {
|
|
1244
|
+
case "pbkdf2":
|
|
1245
|
+
i.passwordType = typeof o[0], i.saltType = typeof o[1], i.iterations = o[2], i.keylen = o[3], i.digest = o[4];
|
|
1246
|
+
break;
|
|
1247
|
+
case "scrypt":
|
|
1248
|
+
i.passwordType = typeof o[0], i.saltType = typeof o[1], i.keylen = o[2], typeof o[3] == "object" && (i.N = o[3].N, i.r = o[3].r, i.p = o[3].p);
|
|
1249
|
+
break;
|
|
1250
|
+
case "randomBytes":
|
|
1251
|
+
i.size = o[0];
|
|
1252
|
+
break;
|
|
1253
|
+
case "generateKeyPair":
|
|
1254
|
+
i.type = o[0], typeof o[1] == "object" && (i.modulusLength = o[1].modulusLength, i.namedCurve = o[1].namedCurve);
|
|
1255
|
+
break;
|
|
1256
|
+
default:
|
|
1257
|
+
i.argsCount = o.length - 1;
|
|
1258
|
+
}
|
|
1259
|
+
return i;
|
|
1260
|
+
})(e, t);
|
|
1261
|
+
break;
|
|
1262
|
+
case "zlib":
|
|
1263
|
+
r = (function(a, o) {
|
|
1264
|
+
const i = {};
|
|
1265
|
+
return Buffer.isBuffer(o[0]) ? (i.inputType = "Buffer", i.inputSize = o[0].length) : typeof o[0] == "string" ? (i.inputType = "string", i.inputSize = o[0].length) : i.inputType = typeof o[0], o[1] && typeof o[1] == "object" && typeof o[1] != "function" && (i.options = { ...o[1] }), i;
|
|
1266
|
+
})(0, t);
|
|
1267
|
+
break;
|
|
1268
|
+
default:
|
|
1269
|
+
return null;
|
|
1156
1270
|
}
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
s("ERROR", I.join(" ")), r(...I);
|
|
1162
|
-
}, console.warn = (...I) => {
|
|
1163
|
-
s("WARN", I.join(" ")), a(...I);
|
|
1164
|
-
}, console.info = (...I) => {
|
|
1165
|
-
s("INFO", I.join(" ")), c(...I);
|
|
1166
|
-
}, l().logLevel === "DEBUG" && (console.debug = (...I) => {
|
|
1167
|
-
s("DEBUG", I.join(" ")), d(...I);
|
|
1168
|
-
});
|
|
1169
|
-
})(t), (function(i = []) {
|
|
1170
|
-
const s = new Le(i);
|
|
1171
|
-
new _e().doSend(s.getExcludedDomains());
|
|
1172
|
-
const g = new De(), r = new $e();
|
|
1173
|
-
s.patchFetch(g, r), s.patchHttp(g, r);
|
|
1174
|
-
})(e.domainsToNotPropagateHeadersTo);
|
|
1175
|
-
const n = new Te();
|
|
1176
|
-
n.setServiceUUID(e.serviceUUID), Ye(n), Ee(), new ze().send();
|
|
1271
|
+
return s > 0 ? J(r, s) : r;
|
|
1272
|
+
} catch {
|
|
1273
|
+
return { error: "Failed to capture arguments", argsCount: t.length - 1 };
|
|
1274
|
+
}
|
|
1177
1275
|
}
|
|
1178
|
-
function
|
|
1179
|
-
|
|
1180
|
-
|
|
1276
|
+
function Xe(n, e, t, s) {
|
|
1277
|
+
let r;
|
|
1278
|
+
try {
|
|
1279
|
+
switch (n) {
|
|
1280
|
+
case "fs":
|
|
1281
|
+
r = (function(a, o) {
|
|
1282
|
+
if (!o) return null;
|
|
1283
|
+
switch (a) {
|
|
1284
|
+
case "readFile":
|
|
1285
|
+
return Buffer.isBuffer(o) ? { type: "Buffer", size: o.length } : typeof o == "string" ? { type: "string", size: o.length } : { type: typeof o };
|
|
1286
|
+
case "readdir":
|
|
1287
|
+
return { count: Array.isArray(o) ? o.length : 0, items: o };
|
|
1288
|
+
case "stat":
|
|
1289
|
+
case "lstat":
|
|
1290
|
+
case "fstat":
|
|
1291
|
+
return { size: o.size, mode: o.mode, isFile: o.isFile(), isDirectory: o.isDirectory() };
|
|
1292
|
+
case "open":
|
|
1293
|
+
return { fd: o };
|
|
1294
|
+
case "read":
|
|
1295
|
+
return { bytesRead: o };
|
|
1296
|
+
case "write":
|
|
1297
|
+
return { bytesWritten: o };
|
|
1298
|
+
default:
|
|
1299
|
+
return o;
|
|
1300
|
+
}
|
|
1301
|
+
})(e, t);
|
|
1302
|
+
break;
|
|
1303
|
+
case "dns":
|
|
1304
|
+
r = (function(a, o) {
|
|
1305
|
+
if (!o) return null;
|
|
1306
|
+
switch (a) {
|
|
1307
|
+
case "lookup":
|
|
1308
|
+
return Array.isArray(o) ? { count: o.length, addresses: o } : o;
|
|
1309
|
+
case "resolve":
|
|
1310
|
+
case "resolve4":
|
|
1311
|
+
case "resolve6":
|
|
1312
|
+
case "resolveAny":
|
|
1313
|
+
case "resolveMx":
|
|
1314
|
+
case "resolveNs":
|
|
1315
|
+
case "resolveTxt":
|
|
1316
|
+
return { count: Array.isArray(o) ? o.length : 0, records: o };
|
|
1317
|
+
case "reverse":
|
|
1318
|
+
return { hostnames: o };
|
|
1319
|
+
default:
|
|
1320
|
+
return o;
|
|
1321
|
+
}
|
|
1322
|
+
})(e, t);
|
|
1323
|
+
break;
|
|
1324
|
+
case "crypto":
|
|
1325
|
+
r = (function(a, o) {
|
|
1326
|
+
if (!o) return null;
|
|
1327
|
+
switch (a) {
|
|
1328
|
+
case "pbkdf2":
|
|
1329
|
+
case "scrypt":
|
|
1330
|
+
case "randomBytes":
|
|
1331
|
+
return Buffer.isBuffer(o) ? { type: "Buffer", size: o.length } : { type: typeof o };
|
|
1332
|
+
case "generateKeyPair":
|
|
1333
|
+
return { hasPublicKey: !!o?.publicKey, hasPrivateKey: !!o?.privateKey };
|
|
1334
|
+
default:
|
|
1335
|
+
return o;
|
|
1336
|
+
}
|
|
1337
|
+
})(e, t);
|
|
1338
|
+
break;
|
|
1339
|
+
case "zlib":
|
|
1340
|
+
r = (function(a, o) {
|
|
1341
|
+
return o ? Buffer.isBuffer(o) ? { type: "Buffer", size: o.length } : typeof o == "string" ? { type: "string", size: o.length } : { type: typeof o } : null;
|
|
1342
|
+
})(0, t);
|
|
1343
|
+
break;
|
|
1344
|
+
default:
|
|
1345
|
+
return null;
|
|
1346
|
+
}
|
|
1347
|
+
return s > 0 ? J(r, s) : r;
|
|
1348
|
+
} catch {
|
|
1349
|
+
return { error: "Failed to capture result", type: typeof t };
|
|
1350
|
+
}
|
|
1181
1351
|
}
|
|
1182
|
-
function
|
|
1183
|
-
|
|
1184
|
-
new be(i.apiKey).addOrUpdateMetadata(o, e, t, n);
|
|
1352
|
+
function yt(n) {
|
|
1353
|
+
return n.operationType === "worker_pool";
|
|
1185
1354
|
}
|
|
1186
|
-
class
|
|
1355
|
+
class Le extends $ {
|
|
1187
1356
|
constructor() {
|
|
1188
1357
|
super(), this.operationName = "CollectFunctionSpans";
|
|
1189
1358
|
}
|
|
1190
1359
|
send(e) {
|
|
1191
|
-
const t =
|
|
1360
|
+
const t = d().sfDebug;
|
|
1192
1361
|
t && console.log(`[FunctionSpanTransmitter] Preparing to send ${e.length} function span(s)`);
|
|
1193
|
-
for (const
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1362
|
+
for (const s of e) try {
|
|
1363
|
+
if (yt(s)) {
|
|
1364
|
+
this.sendWorkerPoolSpan(s, t);
|
|
1365
|
+
continue;
|
|
1366
|
+
}
|
|
1367
|
+
const r = s;
|
|
1368
|
+
let a;
|
|
1369
|
+
if (r.result !== void 0 && r.result !== null) {
|
|
1370
|
+
const i = typeof r.result;
|
|
1371
|
+
a = JSON.stringify({ type: i, has_value: !0, value: r.result });
|
|
1372
|
+
} else a = r.result === null ? JSON.stringify({ type: "null", has_value: !0, value: null }) : JSON.stringify({ type: "undefined", has_value: !1, value: null });
|
|
1373
|
+
const o = this.getVariables({ library: "JS/TS BACKEND", version: d().version, spanId: r.spanId, parentSpanId: r.parentSpanId, filePath: r.filePath, lineNumber: r.metadata.line, columnNumber: r.metadata.column, functionName: r.functionName, arguments: JSON.stringify(r.args || {}), returnValue: a, startTimeNs: (1e6 * Date.now() - 1e6 * r.duration).toString(), durationNs: (1e6 * r.duration).toString() });
|
|
1374
|
+
t && (console.log(`[FunctionSpanTransmitter] Sending GraphQL mutation to ${this.endpoint}`), console.log("[FunctionSpanTransmitter] Variables:", JSON.stringify(o, null, 2))), W(this.endpoint, this.operationName, this.getQuery(), o), t && console.log(`[FunctionSpanTransmitter] Queued function span for ${r.functionName}`);
|
|
1375
|
+
} catch (r) {
|
|
1376
|
+
console.error(`[FunctionSpanTransmitter] Error preparing function span for ${s.functionName}:`, r);
|
|
1203
1377
|
}
|
|
1204
1378
|
}
|
|
1379
|
+
sendWorkerPoolSpan(e, t) {
|
|
1380
|
+
try {
|
|
1381
|
+
let s;
|
|
1382
|
+
if (e.result !== void 0 && e.result !== null) {
|
|
1383
|
+
const a = typeof e.result;
|
|
1384
|
+
s = JSON.stringify({ type: a, has_value: !0, value: e.result });
|
|
1385
|
+
} else s = e.result === null ? JSON.stringify({ type: "null", has_value: !0, value: null }) : JSON.stringify({ type: "undefined", has_value: !1, value: null });
|
|
1386
|
+
const r = this.getVariables({ library: "JS/TS BACKEND", version: d().version, spanId: e.spanId, operationName: e.operationName, moduleName: e.moduleName, methodName: e.methodName, startTimeNs: e.startTimeNs, durationNs: e.durationNs, arguments: JSON.stringify(e.args || {}), returnValue: s, error: e.error, pid: e.pid, threadId: e.threadId });
|
|
1387
|
+
t && (console.log(`[FunctionSpanTransmitter] Sending worker pool span: ${e.operationName}`), console.log("[FunctionSpanTransmitter] Variables:", JSON.stringify(r, null, 2))), W(this.endpoint, "CollectWorkerPoolSpans", this.getWorkerPoolQuery(), r), t && console.log(`[FunctionSpanTransmitter] Queued worker pool span for ${e.operationName}`);
|
|
1388
|
+
} catch (s) {
|
|
1389
|
+
console.error(`[FunctionSpanTransmitter] Error preparing worker pool span for ${e.operationName}:`, s);
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
getWorkerPoolQuery() {
|
|
1393
|
+
return `
|
|
1394
|
+
mutation CollectWorkerPoolSpans(
|
|
1395
|
+
$apiKey: String!,
|
|
1396
|
+
$serviceUuid: String!,
|
|
1397
|
+
$sessionId: String!,
|
|
1398
|
+
$timestampMs: String!,
|
|
1399
|
+
$library: String!,
|
|
1400
|
+
$version: String!,
|
|
1401
|
+
$spanId: String!,
|
|
1402
|
+
$operationName: String!,
|
|
1403
|
+
$moduleName: String!,
|
|
1404
|
+
$methodName: String!,
|
|
1405
|
+
$startTimeNs: String!,
|
|
1406
|
+
$durationNs: String!,
|
|
1407
|
+
$parentSpanId: String,
|
|
1408
|
+
$arguments: String,
|
|
1409
|
+
$returnValue: String,
|
|
1410
|
+
$error: String,
|
|
1411
|
+
$pid: Int,
|
|
1412
|
+
$threadId: Int
|
|
1413
|
+
) {
|
|
1414
|
+
collectWorkerPoolSpans(
|
|
1415
|
+
apiKey: $apiKey,
|
|
1416
|
+
serviceUuid: $serviceUuid,
|
|
1417
|
+
sessionId: $sessionId,
|
|
1418
|
+
timestampMs: $timestampMs,
|
|
1419
|
+
library: $library,
|
|
1420
|
+
version: $version,
|
|
1421
|
+
spanId: $spanId,
|
|
1422
|
+
operationName: $operationName,
|
|
1423
|
+
moduleName: $moduleName,
|
|
1424
|
+
methodName: $methodName,
|
|
1425
|
+
startTimeNs: $startTimeNs,
|
|
1426
|
+
durationNs: $durationNs,
|
|
1427
|
+
parentSpanId: $parentSpanId,
|
|
1428
|
+
arguments: $arguments,
|
|
1429
|
+
returnValue: $returnValue,
|
|
1430
|
+
error: $error,
|
|
1431
|
+
pid: $pid,
|
|
1432
|
+
threadId: $threadId
|
|
1433
|
+
)
|
|
1434
|
+
}
|
|
1435
|
+
`;
|
|
1436
|
+
}
|
|
1205
1437
|
getQuery() {
|
|
1206
1438
|
return `
|
|
1207
1439
|
${this.queryType} ${this.operationName}(
|
|
@@ -1244,77 +1476,282 @@ class Me extends w {
|
|
|
1244
1476
|
`;
|
|
1245
1477
|
}
|
|
1246
1478
|
}
|
|
1247
|
-
let
|
|
1248
|
-
function
|
|
1249
|
-
const
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1479
|
+
let le = null;
|
|
1480
|
+
function j(n, e, t, s, r) {
|
|
1481
|
+
const a = H(), o = a?.sfDebug || !1;
|
|
1482
|
+
o && console.log(`[WorkerPool] Capturing ${n}.${e}`);
|
|
1483
|
+
const i = me(), c = v.getInstance().getCurrentFunctionSpanId(), l = w();
|
|
1484
|
+
o && console.log(`[WorkerPool] Span ID: ${l}, Parent: ${c || "none"}`);
|
|
1485
|
+
const g = new Oe("WorkerPoolOperation"), u = process.hrtime.bigint();
|
|
1486
|
+
let I = null;
|
|
1487
|
+
i.captureArguments && (I = De(n, e, s, i.argLimitMb));
|
|
1488
|
+
const m = s.findIndex((f) => typeof f == "function");
|
|
1489
|
+
if (m === -1) return o && console.log(`[WorkerPool] No callback found for ${n}.${e}`), t.apply(r, s);
|
|
1490
|
+
const p = s[m], h = [...s];
|
|
1491
|
+
return h[m] = function(f, ...S) {
|
|
1492
|
+
const b = process.hrtime.bigint() - u, y = Number(b) / 1e6;
|
|
1493
|
+
p(f, ...S), g.runInAsyncScope(() => {
|
|
1494
|
+
o && console.log(`[WorkerPool] ${n}.${e} completed in ${y.toFixed(3)}ms (${b}ns)`);
|
|
1495
|
+
let A = null, Z = null;
|
|
1496
|
+
f ? Z = f?.message || String(f) : i.captureReturnValue && S.length > 0 && (A = Xe(n, e, S[0], i.returnLimitMb)), de({ operationType: "worker_pool", operationName: `${n}.${e}`, moduleName: n, methodName: e, duration: y, durationNs: b.toString(), startTimeNs: u.toString(), args: I, result: A, error: Z, spanId: l, parentSpanId: c, pid: process.pid, threadId: T });
|
|
1497
|
+
}), g.emitDestroy();
|
|
1498
|
+
}, t.apply(r, h);
|
|
1499
|
+
}
|
|
1500
|
+
function St(n, e, t, s, r) {
|
|
1501
|
+
const a = H(), o = a?.sfDebug || !1;
|
|
1502
|
+
o && console.log(`[WorkerPool] Capturing ${n}.${e} (Promise)`);
|
|
1503
|
+
const i = me(), c = v.getInstance().getCurrentFunctionSpanId(), l = w();
|
|
1504
|
+
o && console.log(`[WorkerPool] Span ID: ${l}, Parent: ${c || "none"}`);
|
|
1505
|
+
const g = process.hrtime.bigint();
|
|
1506
|
+
let u = null;
|
|
1507
|
+
return i.captureArguments && (u = De(n, e, s, i.argLimitMb)), t.apply(r, s).then((I) => {
|
|
1508
|
+
const m = process.hrtime.bigint() - g, p = Number(m) / 1e6;
|
|
1509
|
+
o && console.log(`[WorkerPool] ${n}.${e} completed in ${p.toFixed(3)}ms (${m}ns)`);
|
|
1510
|
+
let h = null;
|
|
1511
|
+
return i.captureReturnValue && (h = Xe(n, e, I, i.returnLimitMb)), de({ operationType: "worker_pool", operationName: `${n}.${e}`, moduleName: n, methodName: e, duration: p, durationNs: m.toString(), startTimeNs: g.toString(), args: u, result: h, error: null, spanId: l, parentSpanId: c, pid: process.pid, threadId: T }), I;
|
|
1512
|
+
}, (I) => {
|
|
1513
|
+
const m = process.hrtime.bigint() - g, p = Number(m) / 1e6;
|
|
1514
|
+
throw o && console.log(`[WorkerPool] ${n}.${e} failed in ${p.toFixed(3)}ms: ${I?.message || I}`), de({ operationType: "worker_pool", operationName: `${n}.${e}`, moduleName: n, methodName: e, duration: p, durationNs: m.toString(), startTimeNs: g.toString(), args: u, result: null, error: I?.message || String(I), spanId: l, parentSpanId: c, pid: process.pid, threadId: T }), I;
|
|
1515
|
+
});
|
|
1516
|
+
}
|
|
1517
|
+
function de(n) {
|
|
1518
|
+
const e = H(), t = e?.sfDebug || !1;
|
|
1519
|
+
t && console.log("[WorkerPool] Capturing span:", { operation: n.operationName, duration: `${n.duration}ms`, error: n.error, spanId: n.spanId, parentSpanId: n.parentSpanId }), process.env.SF_FUNCSPAN_CONSOLE_OUTPUT === "true" && console.log(`
|
|
1520
|
+
⚙️ Worker Pool Operation:`, { operation: n.operationName, duration: `${n.duration.toFixed(2)}ms`, arguments: n.args, result: n.error ? `Error: ${n.error}` : n.result, spanId: n.spanId, parentSpanId: n.parentSpanId || "none" });
|
|
1521
|
+
const s = process.env.SF_FUNCSPAN_JSONL_FILE;
|
|
1522
|
+
if (s) try {
|
|
1523
|
+
const r = s === "true" || s === "1" ? "funcspans.jsonl" : s, a = Date.now(), o = process.hrtime.bigint(), i = BigInt(n.startTimeNs), c = Number(o - i) / 1e6, l = new Date(a - c).toISOString(), g = JSON.stringify({ timestamp: l, operationType: n.operationType, operationName: n.operationName, moduleName: n.moduleName, methodName: n.methodName, duration: n.duration, durationNs: n.durationNs, startTimeNs: n.startTimeNs, arguments: n.args, returnValue: n.error ? { error: String(n.error) } : n.result, spanId: n.spanId, parentSpanId: n.parentSpanId, pid: n.pid, threadId: n.threadId }) + `
|
|
1524
|
+
`;
|
|
1525
|
+
Te(r, g, "utf-8");
|
|
1526
|
+
} catch (r) {
|
|
1527
|
+
console.error("[WorkerPool] Error writing to JSONL file:", r);
|
|
1528
|
+
}
|
|
1529
|
+
if (t && console.log("[WorkerPool] Sending span to transmitter"), process.env.SF_FUNCSPAN_SKIP_BACKEND !== "true") try {
|
|
1530
|
+
(le || (le = new Le()), le).send([n]), t && console.log("[WorkerPool] Span sent successfully");
|
|
1531
|
+
} catch (r) {
|
|
1532
|
+
t && console.error("[WorkerPool] Error sending span:", r);
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
const Nt = ["readFile", "writeFile", "appendFile", "readdir", "stat", "lstat", "fstat", "access", "open", "close", "read", "write", "chmod", "mkdir", "rmdir", "unlink", "rename"], We = ["lookup", "resolve", "resolve4", "resolve6", "resolveAny", "resolveMx", "resolveNs", "resolveTxt", "reverse"], vt = ["pbkdf2", "randomBytes", "scrypt", "generateKeyPair"], Gt = ["gzip", "gunzip", "deflate", "inflate", "deflateRaw", "inflateRaw", "brotliCompress", "brotliDecompress"];
|
|
1536
|
+
let Fe = !1, _e = !1;
|
|
1537
|
+
function Zt() {
|
|
1538
|
+
if (!_e) try {
|
|
1539
|
+
const n = require("node:dns");
|
|
1540
|
+
if (n.__sf_worker_pool_patched__) return;
|
|
1541
|
+
Object.defineProperty(n, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
1542
|
+
for (const e of We) if (typeof n[e] == "function") {
|
|
1543
|
+
const t = n[e];
|
|
1544
|
+
n[e] = function(...s) {
|
|
1545
|
+
const r = s[0];
|
|
1546
|
+
return typeof r == "string" && (r === "localhost" || r === "127.0.0.1") ? t.apply(this, s) : typeof s[s.length - 1] == "function" ? j("dns", e, t, s, this) : t.apply(this, s);
|
|
1547
|
+
}, Object.defineProperty(n[e], "name", { value: e, writable: !1 });
|
|
1548
|
+
}
|
|
1549
|
+
(function(e) {
|
|
1550
|
+
if (!e.promises) return void (process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns.promises not available, skipping"));
|
|
1551
|
+
if (!e.promises.__sf_worker_pool_patched__) {
|
|
1552
|
+
Object.defineProperty(e.promises, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
1553
|
+
for (const t of We) if (typeof e.promises[t] == "function") {
|
|
1554
|
+
const s = e.promises[t];
|
|
1555
|
+
e.promises[t] = function(...r) {
|
|
1556
|
+
const a = r[0];
|
|
1557
|
+
return typeof a != "string" || a !== "localhost" && a !== "127.0.0.1" ? St("dns", t, s, r, this) : s.apply(this, r);
|
|
1558
|
+
}, Object.defineProperty(e.promises[t], "name", { value: t, writable: !1 });
|
|
1559
|
+
}
|
|
1560
|
+
process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns.promises module patched successfully");
|
|
1561
|
+
}
|
|
1562
|
+
})(n), _e = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns module patched successfully");
|
|
1563
|
+
} catch (n) {
|
|
1564
|
+
console.error("[WorkerPool] Error patching dns module:", n);
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
let we = !1, Ve = !1, ue = !1;
|
|
1568
|
+
function Bt() {
|
|
1569
|
+
if (ue) return;
|
|
1570
|
+
const n = process.env.SF_DEBUG === "true";
|
|
1571
|
+
n && console.log("[WorkerPool] Initializing worker pool patching..."), O("fs") && (n && console.log("[WorkerPool] Patching fs module..."), (function() {
|
|
1572
|
+
if (!Fe) try {
|
|
1573
|
+
const e = require("node:fs");
|
|
1574
|
+
if (e.__sf_worker_pool_patched__) return;
|
|
1575
|
+
Object.defineProperty(e, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
1576
|
+
for (const t of Nt) if (typeof e[t] == "function") {
|
|
1577
|
+
const s = e[t];
|
|
1578
|
+
e[t] = function(...r) {
|
|
1579
|
+
return typeof r[r.length - 1] == "function" ? j("fs", t, s, r, this) : s.apply(this, r);
|
|
1580
|
+
}, Object.defineProperty(e[t], "name", { value: t, writable: !1 });
|
|
1581
|
+
}
|
|
1582
|
+
Fe = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] fs module patched successfully");
|
|
1583
|
+
} catch (e) {
|
|
1584
|
+
console.error("[WorkerPool] Error patching fs module:", e);
|
|
1585
|
+
}
|
|
1586
|
+
})()), O("dns") && (n && console.log("[WorkerPool] Patching dns module..."), Zt()), O("crypto") && (n && console.log("[WorkerPool] Patching crypto module..."), (function() {
|
|
1587
|
+
if (!we) try {
|
|
1588
|
+
const e = require("node:crypto");
|
|
1589
|
+
if (e.__sf_worker_pool_patched__) return;
|
|
1590
|
+
Object.defineProperty(e, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
1591
|
+
for (const t of vt) if (typeof e[t] == "function") {
|
|
1592
|
+
const s = e[t];
|
|
1593
|
+
e[t] = function(...r) {
|
|
1594
|
+
return typeof r[r.length - 1] == "function" ? j("crypto", t, s, r, this) : s.apply(this, r);
|
|
1595
|
+
}, Object.defineProperty(e[t], "name", { value: t, writable: !1 });
|
|
1596
|
+
}
|
|
1597
|
+
we = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] crypto module patched successfully");
|
|
1598
|
+
} catch (e) {
|
|
1599
|
+
console.error("[WorkerPool] Error patching crypto module:", e);
|
|
1600
|
+
}
|
|
1601
|
+
})()), O("zlib") && (n && console.log("[WorkerPool] Patching zlib module..."), (function() {
|
|
1602
|
+
if (!Ve) try {
|
|
1603
|
+
const e = require("node:zlib");
|
|
1604
|
+
if (e.__sf_worker_pool_patched__) return;
|
|
1605
|
+
Object.defineProperty(e, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
1606
|
+
for (const t of Gt) if (typeof e[t] == "function") {
|
|
1607
|
+
const s = e[t];
|
|
1608
|
+
e[t] = function(...r) {
|
|
1609
|
+
return typeof r[r.length - 1] == "function" ? j("zlib", t, s, r, this) : s.apply(this, r);
|
|
1610
|
+
}, Object.defineProperty(e[t], "name", { value: t, writable: !1 });
|
|
1611
|
+
}
|
|
1612
|
+
Ve = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] zlib module patched successfully");
|
|
1613
|
+
} catch (e) {
|
|
1614
|
+
console.error("[WorkerPool] Error patching zlib module:", e);
|
|
1615
|
+
}
|
|
1616
|
+
})()), ue = !0, n && console.log("[WorkerPool] Worker pool patching initialized");
|
|
1617
|
+
}
|
|
1618
|
+
function Wt() {
|
|
1619
|
+
return ue;
|
|
1620
|
+
}
|
|
1621
|
+
function Kt(n) {
|
|
1622
|
+
if (!n || !n.apiKey) {
|
|
1623
|
+
const r = `The required API Key is not provided: ${JSON.stringify(n)}`;
|
|
1624
|
+
console.error(r);
|
|
1625
|
+
}
|
|
1626
|
+
const { config: e } = et(n);
|
|
1627
|
+
if (e.sfDebug && console.log("Updated configuration after applying options:", e), !e.apiKey || !e.apiGraphqlEndpoint) {
|
|
1628
|
+
const r = `The required config is not provided: ${JSON.stringify(e)}`;
|
|
1629
|
+
throw console.error(r), new Error(r);
|
|
1630
|
+
}
|
|
1631
|
+
At() || ft(void 0, e.sfDebug).catch((r) => {
|
|
1632
|
+
e.sfDebug && console.error("[FuncSpan] Failed to initialize config loader:", r);
|
|
1633
|
+
}), Wt() || (Bt(), e.sfDebug && console.log("[setupInterceptors] Worker pool patching initialized (DNS tracking enabled)"));
|
|
1634
|
+
const t = new Ie();
|
|
1635
|
+
t.setServiceUUID(e.serviceUUID), (function(r) {
|
|
1636
|
+
function a(u, I) {
|
|
1637
|
+
r.setOperationName("CollectLogs"), r.doSend([I, u]);
|
|
1638
|
+
}
|
|
1639
|
+
const o = console.log.bind(console), i = console.error.bind(console), c = console.warn.bind(console), l = console.info.bind(console), g = console.debug.bind(console);
|
|
1640
|
+
console.log = (...u) => {
|
|
1641
|
+
a("INFO", u.join(" ")), o(...u);
|
|
1642
|
+
}, console.error = (...u) => {
|
|
1643
|
+
a("ERROR", u.join(" ")), i(...u);
|
|
1644
|
+
}, console.warn = (...u) => {
|
|
1645
|
+
a("WARN", u.join(" ")), c(...u);
|
|
1646
|
+
}, console.info = (...u) => {
|
|
1647
|
+
a("INFO", u.join(" ")), l(...u);
|
|
1648
|
+
}, d().logLevel === "DEBUG" && (console.debug = (...u) => {
|
|
1649
|
+
a("DEBUG", u.join(" ")), g(...u);
|
|
1650
|
+
});
|
|
1651
|
+
})(t), (function(r = []) {
|
|
1652
|
+
const a = new Ct(r);
|
|
1653
|
+
new ut().doSend(a.getExcludedDomains());
|
|
1654
|
+
const o = new pt(), i = new It();
|
|
1655
|
+
a.patchFetch(o, i), a.patchHttp(o, i);
|
|
1656
|
+
})(e.domainsToNotPropagateHeadersTo);
|
|
1657
|
+
const s = new at();
|
|
1658
|
+
s.setServiceUUID(e.serviceUUID), ot(s), dt(), new mt().send();
|
|
1659
|
+
}
|
|
1660
|
+
function Et(n, e, t, s = !1) {
|
|
1661
|
+
const r = d();
|
|
1662
|
+
new Ke(r.apiKey).identify(n, e, t, s);
|
|
1663
|
+
}
|
|
1664
|
+
function kt(n, e = {}, t, s = !1) {
|
|
1665
|
+
const r = d();
|
|
1666
|
+
new Ke(r.apiKey).addOrUpdateMetadata(n, e, t, s);
|
|
1667
|
+
}
|
|
1668
|
+
let ge = null;
|
|
1669
|
+
function Yt(n, e, t, s) {
|
|
1670
|
+
const r = function(...a) {
|
|
1671
|
+
const o = H(), i = o?.sfDebug || !1;
|
|
1672
|
+
i && console.log(`[FuncSpan] captureFunctionSpan wrapper called for ${t}::${e}`);
|
|
1673
|
+
const c = (function(h, f) {
|
|
1674
|
+
const S = Je();
|
|
1675
|
+
if (S) {
|
|
1676
|
+
const b = Ye(S);
|
|
1677
|
+
if (b) return process.env.SF_DEBUG === "true" && console.log(`[FuncSpan] Using HTTP header override for ${h}::${f}`), b;
|
|
1678
|
+
}
|
|
1679
|
+
try {
|
|
1680
|
+
return bt(h, f);
|
|
1681
|
+
} catch {
|
|
1682
|
+
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 };
|
|
1257
1683
|
}
|
|
1258
|
-
return Oe(u, m);
|
|
1259
1684
|
})(t, e);
|
|
1260
|
-
if (
|
|
1261
|
-
if (
|
|
1262
|
-
|
|
1263
|
-
const
|
|
1264
|
-
|
|
1265
|
-
const
|
|
1685
|
+
if (i && console.log(`[FuncSpan] Config for ${t}::${e}:`, c), c.enable_sampling && c.sample_rate < 1 && Math.random() > c.sample_rate) return i && console.log(`[FuncSpan] Skipping ${e} due to sampling`), n.apply(this, a);
|
|
1686
|
+
if (c.sample_rate === 0) return i && console.log(`[FuncSpan] Skipping ${e} - sample_rate is 0.0`), n.apply(this, a);
|
|
1687
|
+
i && console.log(`[FuncSpan] Capturing function span for ${e}`);
|
|
1688
|
+
const l = v.getInstance(), g = l.getCurrentFunctionSpanId(), u = w();
|
|
1689
|
+
l.setCurrentFunctionSpanId(u);
|
|
1690
|
+
const I = process.hrtime.bigint(), m = Date.now();
|
|
1266
1691
|
let p = null;
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
}), p &&
|
|
1692
|
+
c.capture_arguments && (p = {}, s.paramNames.forEach((h, f) => {
|
|
1693
|
+
f < a.length && (p[h] = a[f]);
|
|
1694
|
+
}), p && c.arg_limit_mb > 0 && (p = J(p, c.arg_limit_mb)));
|
|
1270
1695
|
try {
|
|
1271
|
-
const
|
|
1272
|
-
if (
|
|
1273
|
-
const
|
|
1274
|
-
let
|
|
1275
|
-
return
|
|
1276
|
-
}, (
|
|
1277
|
-
const
|
|
1278
|
-
throw
|
|
1696
|
+
const h = n.apply(this, a);
|
|
1697
|
+
if (h && typeof h.then == "function") return g ? l.setCurrentFunctionSpanId(g) : l.clearCurrentFunctionSpanId(), h.then((A) => {
|
|
1698
|
+
const Z = process.hrtime.bigint(), q = Date.now(), ee = Number(Z - I);
|
|
1699
|
+
let he = null;
|
|
1700
|
+
return c.capture_return_value && c.return_limit_mb > 0 && (he = J(A, c.return_limit_mb)), x({ functionName: e, filePath: t, metadata: s, args: p, result: he, error: null, duration: q - m, durationNs: ee, startTimeNs: I.toString(), async: !0, spanId: u, parentSpanId: g, pid: process.pid, threadId: T }), A;
|
|
1701
|
+
}, (A) => {
|
|
1702
|
+
const Z = process.hrtime.bigint(), q = Date.now(), ee = Number(Z - I);
|
|
1703
|
+
throw x({ functionName: e, filePath: t, metadata: s, args: p, result: null, error: A?.message || String(A), duration: q - m, durationNs: ee, startTimeNs: I.toString(), async: !0, spanId: u, parentSpanId: g, pid: process.pid, threadId: T }), A;
|
|
1279
1704
|
});
|
|
1280
|
-
const
|
|
1281
|
-
let
|
|
1282
|
-
return
|
|
1283
|
-
} catch (
|
|
1284
|
-
const
|
|
1285
|
-
throw
|
|
1705
|
+
const f = process.hrtime.bigint(), S = Date.now(), b = Number(f - I);
|
|
1706
|
+
let y = null;
|
|
1707
|
+
return c.capture_return_value && c.return_limit_mb > 0 && (y = J(h, c.return_limit_mb)), x({ functionName: e, filePath: t, metadata: s, args: p, result: y, error: null, duration: S - m, durationNs: b, startTimeNs: I.toString(), async: !1, spanId: u, parentSpanId: g, pid: process.pid, threadId: T }), g ? l.setCurrentFunctionSpanId(g) : l.clearCurrentFunctionSpanId(), h;
|
|
1708
|
+
} catch (h) {
|
|
1709
|
+
const f = process.hrtime.bigint(), S = Date.now(), b = Number(f - I);
|
|
1710
|
+
throw x({ functionName: e, filePath: t, metadata: s, args: p, result: null, error: h?.message || String(h), duration: S - m, durationNs: b, startTimeNs: I.toString(), async: !1, spanId: u, parentSpanId: g, pid: process.pid, threadId: T }), g ? l.setCurrentFunctionSpanId(g) : l.clearCurrentFunctionSpanId(), h;
|
|
1286
1711
|
}
|
|
1287
1712
|
};
|
|
1288
|
-
Object.defineProperty(
|
|
1289
|
-
for (const
|
|
1290
|
-
return
|
|
1713
|
+
Object.defineProperty(r, "name", { value: e, writable: !1 });
|
|
1714
|
+
for (const a in n) n.hasOwnProperty(a) && (r[a] = n[a]);
|
|
1715
|
+
return r;
|
|
1291
1716
|
}
|
|
1292
|
-
function
|
|
1293
|
-
const e =
|
|
1294
|
-
t && console.log("[FuncSpan] captureSpanData called for:", { function:
|
|
1295
|
-
const
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1717
|
+
function x(n) {
|
|
1718
|
+
const e = H(), t = e?.sfDebug || !1;
|
|
1719
|
+
t && console.log("[FuncSpan] captureSpanData called for:", { function: n.functionName, file: n.filePath, duration: `${n.duration}ms`, async: n.async, error: n.error, spanId: n.spanId });
|
|
1720
|
+
const s = { functionName: n.functionName, filePath: n.filePath, metadata: n.metadata, args: n.args, result: n.result, error: n.error, duration: n.duration, durationNs: n.durationNs, async: n.async, spanId: n.spanId, parentSpanId: n.parentSpanId };
|
|
1721
|
+
process.env.SF_FUNCSPAN_CONSOLE_OUTPUT === "true" && console.log(`
|
|
1722
|
+
📊 Function Span:`, { function: `${n.functionName} (${n.filePath}:${n.metadata.line}:${n.metadata.column})`, duration: `${n.duration.toFixed(2)}ms`, arguments: n.args, result: n.error ? `Error: ${n.error}` : n.result, spanId: n.spanId, parentSpanId: n.parentSpanId || "none" });
|
|
1723
|
+
const r = process.env.SF_FUNCSPAN_JSONL_FILE;
|
|
1724
|
+
if (r) try {
|
|
1725
|
+
const a = r === "true" || r === "1" ? "funcspans.jsonl" : r, o = Date.now(), i = process.hrtime.bigint(), c = BigInt(n.startTimeNs), l = Number(i - c) / 1e6, g = new Date(o - l).toISOString(), u = JSON.stringify({ timestamp: g, functionName: n.functionName, filePath: n.filePath, line: n.metadata.line, column: n.metadata.column, duration: n.duration, durationNs: n.durationNs, startTimeNs: n.startTimeNs, arguments: n.args, returnValue: n.error ? { error: String(n.error) } : n.result, spanId: n.spanId, parentSpanId: n.parentSpanId, async: n.async, pid: n.pid, threadId: n.threadId }) + `
|
|
1726
|
+
`;
|
|
1727
|
+
Te(a, u, "utf-8");
|
|
1728
|
+
} catch (a) {
|
|
1729
|
+
console.error("[FuncSpan] Error writing to JSONL file:", a);
|
|
1730
|
+
}
|
|
1731
|
+
if (t && console.log("[FuncSpan] Sending function span to transmitter:", s), process.env.SF_FUNCSPAN_SKIP_BACKEND !== "true") try {
|
|
1732
|
+
(ge || (ge = new Le()), ge).send([s]), t && console.log("[FuncSpan] Function span sent successfully");
|
|
1733
|
+
} catch (a) {
|
|
1734
|
+
t && console.error("[FuncSpan] Error sending function span:", a);
|
|
1301
1735
|
}
|
|
1302
1736
|
}
|
|
1303
1737
|
export {
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1738
|
+
v as ContextManager,
|
|
1739
|
+
kt as addOrUpdateMetadata,
|
|
1740
|
+
Yt as captureFunctionSpan,
|
|
1741
|
+
lt as clearFuncspanOverride,
|
|
1742
|
+
oe as getCurrentFunctionSpanId,
|
|
1743
|
+
Ut as getDefaultConfig,
|
|
1744
|
+
ke as getEnvConfig,
|
|
1745
|
+
Je as getFuncspanOverride,
|
|
1746
|
+
bt as getGlobalConfig,
|
|
1747
|
+
Et as identify,
|
|
1748
|
+
ft as initializeConfigLoader,
|
|
1749
|
+
Bt as initializeWorkerPoolPatching,
|
|
1750
|
+
At as isConfigLoaderInitialized,
|
|
1751
|
+
Wt as isWorkerPoolInitialized,
|
|
1752
|
+
Ye as parseHeaderOverride,
|
|
1753
|
+
$t as runWithContext,
|
|
1754
|
+
ct as setFuncspanOverride,
|
|
1755
|
+
Kt as setupInterceptors,
|
|
1756
|
+
Xt as transformFunctionSpans
|
|
1320
1757
|
};
|