@sailfish-ai/sf-veritas 0.2.4 → 0.2.6
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 +65 -8
- package/dist/plugins/funcspanWebpackPlugin.cjs +1 -1
- package/dist/plugins/funcspanWebpackPlugin.mjs +24 -24
- package/dist/runtime/register.cjs +1 -0
- package/dist/runtime/register.mjs +27 -0
- package/dist/sf-veritas.cjs +16 -52
- package/dist/sf-veritas.mjs +573 -811
- 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/plugins/funcspanWebpackPlugin.d.ts +20 -0
- package/dist/types/plugins/workerPoolTransformer.d.ts +42 -0
- package/dist/types/requestUtils.d.ts +1 -0
- package/dist/types/runtime/register.d.ts +56 -0
- package/dist/types/worker-pool-capture.d.ts +9 -0
- package/dist/types/workerPoolConfig.d.ts +22 -0
- package/dist/types/workerPoolSpanCapture.d.ts +36 -0
- package/dist/worker-pool-capture.cjs +1 -0
- package/dist/worker-pool-capture.mjs +4 -0
- package/dist/workerPoolSpanCapture-BOnYC4s3.js +705 -0
- package/dist/workerPoolSpanCapture-CNEouInA.cjs +83 -0
- package/package.json +17 -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,262 +1,25 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
function R(o, e, t) {
|
|
16
|
-
if (re.randomUUID && !o) return re.randomUUID();
|
|
17
|
-
const n = (o = o || {}).random ?? o.rng?.() ?? (function() {
|
|
18
|
-
if (!O) {
|
|
19
|
-
if (typeof crypto > "u" || !crypto.getRandomValues) throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
20
|
-
O = crypto.getRandomValues.bind(crypto);
|
|
21
|
-
}
|
|
22
|
-
return O(We);
|
|
23
|
-
})();
|
|
24
|
-
if (n.length < 16) throw new Error("Random bytes length must be >= 16");
|
|
25
|
-
return n[6] = 15 & n[6] | 64, n[8] = 63 & n[8] | 128, (function(i, s = 0) {
|
|
26
|
-
return (Z[i[s + 0]] + Z[i[s + 1]] + Z[i[s + 2]] + Z[i[s + 3]] + "-" + Z[i[s + 4]] + Z[i[s + 5]] + "-" + Z[i[s + 6]] + Z[i[s + 7]] + "-" + Z[i[s + 8]] + Z[i[s + 9]] + "-" + Z[i[s + 10]] + Z[i[s + 11]] + Z[i[s + 12]] + Z[i[s + 13]] + Z[i[s + 14]] + Z[i[s + 15]]).toLowerCase();
|
|
27
|
-
})(n);
|
|
28
|
-
}
|
|
29
|
-
class Fe {
|
|
30
|
-
constructor(e) {
|
|
31
|
-
C(this, "apiKey");
|
|
32
|
-
C(this, "apiGraphqlEndpoint");
|
|
33
|
-
C(this, "sfDebug");
|
|
34
|
-
C(this, "serviceIdentifier");
|
|
35
|
-
C(this, "serviceVersion");
|
|
36
|
-
C(this, "serviceUUID");
|
|
37
|
-
C(this, "serviceAdditionalMetadata");
|
|
38
|
-
C(this, "profilingModeEnabled");
|
|
39
|
-
C(this, "profilingMaxDepth");
|
|
40
|
-
C(this, "profilingMaxVariableSizeKb");
|
|
41
|
-
C(this, "domainsToNotPropagateHeadersTo");
|
|
42
|
-
C(this, "nodeModulesToCollectLocalVariablesOn");
|
|
43
|
-
C(this, "printConfigurationStatuses");
|
|
44
|
-
C(this, "logLevel");
|
|
45
|
-
C(this, "stackDepthLocals");
|
|
46
|
-
C(this, "stackDepthCodeTraceDepth");
|
|
47
|
-
C(this, "packageLibraryType");
|
|
48
|
-
C(this, "version");
|
|
49
|
-
C(this, "gitSha");
|
|
50
|
-
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 = R(), 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
|
-
}
|
|
53
|
-
getPackageVersion() {
|
|
54
|
-
return "0.1.15";
|
|
55
|
-
}
|
|
56
|
-
get serviceIdentificationReceived() {
|
|
57
|
-
return this._serviceIdentificationReceived;
|
|
58
|
-
}
|
|
59
|
-
setServiceIdentificationReceived(e) {
|
|
60
|
-
this._serviceIdentificationReceived = e;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
const me = Symbol.for("sailfish.sf_config");
|
|
64
|
-
function z() {
|
|
65
|
-
return globalThis[me];
|
|
66
|
-
}
|
|
67
|
-
function Ve(o) {
|
|
68
|
-
const e = z();
|
|
69
|
-
if (e) return { config: e };
|
|
70
|
-
const t = new Fe(o);
|
|
71
|
-
return (function(n) {
|
|
72
|
-
globalThis[me] = n;
|
|
73
|
-
})(t), t.sfDebug && console.log("[[getOrCreateConfig]] Created global config:", t), { config: t };
|
|
74
|
-
}
|
|
75
|
-
function l() {
|
|
76
|
-
const o = z();
|
|
77
|
-
if (!o) throw new Error("Configuration has not been initialized. Call getOrCreateConfig(options) first.");
|
|
78
|
-
return o;
|
|
79
|
-
}
|
|
80
|
-
const ae = Symbol.for("sf.ctx.storeAls"), W = globalThis, P = W[ae] ?? (W[ae] = new ie()), Ae = ["identitytoolkit.googleapis.com", "t.co", "*.twitter.com", "*.gravatar.com", "*.googleapis.com", "*.amazonaws.com", "*.smooch.io", "*.zendesk.com"], ce = Symbol.for("sf.ctx.als"), K = W[ce] ?? (W[ce] = new ie()), ge = Symbol.for("sf.ctx.sessionRegistry"), Y = W[ge] ?? (W[ge] = /* @__PURE__ */ new Map()), E = { handledExceptions: /* @__PURE__ */ new Set(), reentrancyGuardLoggingActive: !1, reentrancyGuardLoggingPreActive: !1, reentrancyGuardPrintActive: !1, reentrancyGuardPrintPreActive: !1, reentrancyGuardExceptionActive: !1, reentrancyGuardExceptionPreActive: !1, excludedDomains: new Set(Ae), supportedDomains: /* @__PURE__ */ new Set() }, V = class V {
|
|
81
|
-
constructor() {
|
|
82
|
-
}
|
|
83
|
-
current() {
|
|
84
|
-
return P.getStore();
|
|
85
|
-
}
|
|
86
|
-
ensureStore() {
|
|
87
|
-
const e = this.current();
|
|
88
|
-
if (e) return e;
|
|
89
|
-
const t = /* @__PURE__ */ new Map();
|
|
90
|
-
return P.enterWith(t), t;
|
|
91
|
-
}
|
|
92
|
-
runWith(e, t) {
|
|
93
|
-
const n = this.current() ?? /* @__PURE__ */ new Map(), i = new Map(n);
|
|
94
|
-
for (const [s, g] of Object.entries(e)) i.set(s, g);
|
|
95
|
-
return P.run(i, t);
|
|
96
|
-
}
|
|
97
|
-
static getInstance() {
|
|
98
|
-
return W[V.GLOBAL_MANAGER_SYMBOL] || (W[V.GLOBAL_MANAGER_SYMBOL] = new V()), W[V.GLOBAL_MANAGER_SYMBOL];
|
|
99
|
-
}
|
|
100
|
-
getCurrentContext() {
|
|
101
|
-
return K.getStore() || E;
|
|
102
|
-
}
|
|
103
|
-
setCurrentContext(e) {
|
|
104
|
-
const t = K.getStore() || E;
|
|
105
|
-
K.enterWith({ ...t, ...e });
|
|
106
|
-
}
|
|
107
|
-
ensureSession(e) {
|
|
108
|
-
let t = Y.get(e);
|
|
109
|
-
return t || (t = { ...E }, Y.set(e, t)), t;
|
|
110
|
-
}
|
|
111
|
-
getContextFor(e) {
|
|
112
|
-
return Y.get(e) ?? E;
|
|
113
|
-
}
|
|
114
|
-
updateContextFor(e, t) {
|
|
115
|
-
const n = this.ensureSession(e);
|
|
116
|
-
Y.set(e, { ...n, ...t });
|
|
117
|
-
}
|
|
118
|
-
runWithSession(e, t) {
|
|
119
|
-
const n = { ...this.ensureSession(e) };
|
|
120
|
-
return K.run(n, t);
|
|
121
|
-
}
|
|
122
|
-
deleteSession(e) {
|
|
123
|
-
Y.delete(e);
|
|
124
|
-
}
|
|
125
|
-
getTraceId() {
|
|
126
|
-
return this.getCurrentContext().traceId;
|
|
127
|
-
}
|
|
128
|
-
getPageVisitUUID() {
|
|
129
|
-
return this.getCurrentContext().pageVisitUUID;
|
|
130
|
-
}
|
|
131
|
-
setTraceId(e) {
|
|
132
|
-
this.setCurrentContext({ traceId: e });
|
|
133
|
-
}
|
|
134
|
-
setPageVisitUUID(e) {
|
|
135
|
-
this.setCurrentContext({ pageVisitUUID: e });
|
|
136
|
-
}
|
|
137
|
-
getCurrentFunctionSpanId() {
|
|
138
|
-
return this.getCurrentContext().currentFunctionSpanId;
|
|
139
|
-
}
|
|
140
|
-
setCurrentFunctionSpanId(e) {
|
|
141
|
-
this.setCurrentContext({ currentFunctionSpanId: e });
|
|
142
|
-
}
|
|
143
|
-
clearCurrentFunctionSpanId() {
|
|
144
|
-
this.setCurrentContext({ currentFunctionSpanId: void 0 });
|
|
145
|
-
}
|
|
146
|
-
getOrSetSfTraceId(e, t = !1) {
|
|
147
|
-
let n = this.getTraceId();
|
|
148
|
-
return n || (n = e || (t ? R() : `nonsession-applogs-v3/${l().apiKey}/${R()}`), this.setTraceId(n), l().sfDebug && console.log(" Created new trace ID:", n), n);
|
|
149
|
-
}
|
|
150
|
-
getOrSetPageVisitUUID() {
|
|
151
|
-
let e = this.getPageVisitUUID();
|
|
152
|
-
return e || (e = R(), this.setPageVisitUUID(e), l().sfDebug && console.log(" Created new page visit UUID:", e), e);
|
|
153
|
-
}
|
|
154
|
-
getHandledExceptions() {
|
|
155
|
-
return this.getCurrentContext().handledExceptions;
|
|
156
|
-
}
|
|
157
|
-
markExceptionHandled(e) {
|
|
158
|
-
const t = this.getHandledExceptions();
|
|
159
|
-
t.add(e), this.setCurrentContext({ handledExceptions: t });
|
|
160
|
-
}
|
|
161
|
-
hasHandledException(e) {
|
|
162
|
-
return this.getHandledExceptions().has(e);
|
|
163
|
-
}
|
|
164
|
-
resetHandledExceptions() {
|
|
165
|
-
this.setCurrentContext({ handledExceptions: /* @__PURE__ */ new Set() });
|
|
166
|
-
}
|
|
167
|
-
getExcludedDomains() {
|
|
168
|
-
return this.getCurrentContext().excludedDomains;
|
|
169
|
-
}
|
|
170
|
-
getSupportedDomains() {
|
|
171
|
-
return this.getCurrentContext().supportedDomains;
|
|
172
|
-
}
|
|
173
|
-
addSupportedDomains(e) {
|
|
174
|
-
this.getCurrentContext().supportedDomains.add(e.toLowerCase().trim());
|
|
175
|
-
}
|
|
176
|
-
setTraceIdFor(e, t) {
|
|
177
|
-
this.updateContextFor(e, { traceId: t });
|
|
178
|
-
}
|
|
179
|
-
setPageVisitUUIDFor(e, t) {
|
|
180
|
-
this.updateContextFor(e, { pageVisitUUID: t });
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
C(V, "GLOBAL_MANAGER_SYMBOL", Symbol.for("sf.ctx.manager"));
|
|
184
|
-
let G = V;
|
|
185
|
-
function it(o) {
|
|
186
|
-
const e = { ...G.getInstance().getCurrentContext() };
|
|
187
|
-
K.run(e, () => {
|
|
188
|
-
o();
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
function M() {
|
|
192
|
-
return G.getInstance().getCurrentFunctionSpanId();
|
|
193
|
-
}
|
|
194
|
-
class w {
|
|
195
|
-
constructor() {
|
|
196
|
-
C(this, "apiKey");
|
|
197
|
-
C(this, "endpoint");
|
|
198
|
-
C(this, "queryType", "mutation");
|
|
199
|
-
C(this, "operationName", "");
|
|
200
|
-
C(this, "serviceUUID", l().serviceUUID);
|
|
201
|
-
C(this, "contextManager");
|
|
202
|
-
this.apiKey = l().apiKey, this.endpoint = l().apiGraphqlEndpoint, this.contextManager = G.getInstance();
|
|
203
|
-
}
|
|
204
|
-
get queryName() {
|
|
205
|
-
return this.operationName ? this.operationName.charAt(0).toLowerCase() + this.operationName.slice(1) : "";
|
|
206
|
-
}
|
|
207
|
-
getDefaultVariables() {
|
|
208
|
-
const e = Date.now().toString(), t = this.contextManager.getOrSetSfTraceId(), n = this.contextManager.getCurrentFunctionSpanId();
|
|
209
|
-
return { apiKey: this.apiKey, serviceUuid: this.serviceUUID, sessionId: t, timestampMs: e, parentSpanId: n };
|
|
210
|
-
}
|
|
211
|
-
getVariables(e = {}) {
|
|
212
|
-
return { ...this.getDefaultVariables(), ...e };
|
|
213
|
-
}
|
|
214
|
-
setOperationName(e) {
|
|
215
|
-
this.operationName = e;
|
|
216
|
-
}
|
|
217
|
-
setEndpoint(e) {
|
|
218
|
-
this.endpoint = e;
|
|
219
|
-
}
|
|
220
|
-
setServiceUUID(e) {
|
|
221
|
-
this.serviceUUID = e;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
const we = fetch;
|
|
225
|
-
async function F(o, e, t, n) {
|
|
226
|
-
try {
|
|
227
|
-
const i = l();
|
|
228
|
-
let s;
|
|
229
|
-
try {
|
|
230
|
-
s = JSON.stringify({ query: t, variables: n, operationName: e });
|
|
231
|
-
} catch {
|
|
232
|
-
s = JSON.stringify({ query: t, operationName: e });
|
|
233
|
-
}
|
|
234
|
-
we(o, { method: "POST", headers: { "Content-Type": "application/json" }, body: s }).then(async (g) => {
|
|
235
|
-
if (!g.ok) return void (i.sfDebug && console.error(`GraphQL request failed with status ${g.status} for ${e}`));
|
|
236
|
-
const r = await g.json();
|
|
237
|
-
r.errors?.length ? (function(a, c, d) {
|
|
238
|
-
const I = a && typeof a == "object" && !Array.isArray(a) ? Object.keys(a)[0] : void 0;
|
|
239
|
-
console.error(I === "identifyServiceDetails" ? `IdentifyServiceDetails NOT sent successfully for service: UUID=${d.serviceUUID}` : `GraphQL request failed with errors: ${JSON.stringify(c)} for operation key ${I}`);
|
|
240
|
-
})(r.data, r.errors, i) : i.sfDebug && (function(a, c, d) {
|
|
241
|
-
const I = a && typeof a == "object" && !Array.isArray(a) ? Object.keys(a)[0] : void 0, h = a[I] || !1;
|
|
242
|
-
I === "identifyServiceDetails" && (d.setServiceIdentificationReceived(h), l().sfDebug && console.log(`IdentifyServiceDetails sent successfully for service: UUID=${d.serviceUUID}; serviceIdentificationReceived=${I === "identifyServiceDetails" ? h : "N/A"}`));
|
|
243
|
-
})(r.data, 0, i);
|
|
244
|
-
}).catch((g) => {
|
|
245
|
-
i.sfDebug && (console.error(`[RequestUtils] Fetch error for ${e} to ${o}:`, g), g.cause && console.error("[RequestUtils] Error cause:", g.cause));
|
|
246
|
-
});
|
|
247
|
-
} catch (i) {
|
|
248
|
-
l().sfDebug && console.error("Error sending data to GraphQL server:", i);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
class X extends w {
|
|
1
|
+
var Ae = Object.defineProperty;
|
|
2
|
+
var fe = (o, e, t) => e in o ? Ae(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
|
|
3
|
+
var A = (o, e, t) => fe(o, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { B as F, g as d, n as W, C as N, s as ye, a as Ze, D as Ge, b as le, p as de, v as Ie, d as $, e as ue, f as Se, m as R, c as _, h as Be, i as X, j as We, k as Ce, t as E, F as ve } from "./workerPoolSpanCapture-BOnYC4s3.js";
|
|
5
|
+
import { r as Ct } from "./workerPoolSpanCapture-BOnYC4s3.js";
|
|
6
|
+
import * as L from "fs";
|
|
7
|
+
import { readFileSync as pe, appendFileSync as Ne } from "fs";
|
|
8
|
+
import { s as me } from "./funcSpanTransformer-sqmZLAcs.js";
|
|
9
|
+
import { t as mt } from "./funcSpanTransformer-sqmZLAcs.js";
|
|
10
|
+
import { Worker as Fe, threadId as J } from "worker_threads";
|
|
11
|
+
import { createRequire as we } from "node:module";
|
|
12
|
+
import * as G from "path";
|
|
13
|
+
import { glob as Ve } from "glob";
|
|
14
|
+
class Y extends F {
|
|
252
15
|
constructor() {
|
|
253
16
|
super(), this.setOperationName("IdentifyServiceDetails");
|
|
254
17
|
}
|
|
255
18
|
async doSend(e) {
|
|
256
|
-
if (!
|
|
19
|
+
if (!d().serviceIdentificationReceived) try {
|
|
257
20
|
this.send();
|
|
258
21
|
} catch (t) {
|
|
259
|
-
|
|
22
|
+
d().sfDebug && console.error(" Error during service identification:", t);
|
|
260
23
|
}
|
|
261
24
|
}
|
|
262
25
|
async send() {
|
|
@@ -284,8 +47,8 @@ class X extends w {
|
|
|
284
47
|
gitSha: $gitSha,
|
|
285
48
|
)
|
|
286
49
|
}
|
|
287
|
-
`, t = this.getVariables({ serviceIdentifier:
|
|
288
|
-
|
|
50
|
+
`, t = this.getVariables({ serviceIdentifier: d().serviceIdentifier, serviceVersion: d().serviceVersion, library: d().packageLibraryType, version: d().version, serviceAdditionalMetadata: d().serviceAdditionalMetadata, gitSha: d().gitSha || "" });
|
|
51
|
+
W(this.endpoint, this.operationName, e, t);
|
|
289
52
|
}
|
|
290
53
|
}
|
|
291
54
|
function He(o) {
|
|
@@ -295,31 +58,31 @@ function He(o) {
|
|
|
295
58
|
return !1;
|
|
296
59
|
}
|
|
297
60
|
}
|
|
298
|
-
class
|
|
61
|
+
class Ye extends F {
|
|
299
62
|
constructor() {
|
|
300
63
|
super();
|
|
301
|
-
|
|
64
|
+
A(this, "serviceIdentifier", new Y());
|
|
302
65
|
this.setOperationName("CollectMetadata");
|
|
303
66
|
}
|
|
304
67
|
async sendAppIdentifier() {
|
|
305
68
|
this.serviceIdentifier.doSend({});
|
|
306
69
|
}
|
|
307
|
-
async doSend(t, n, i
|
|
308
|
-
this.sendAppIdentifier(), this.send(t, n, i
|
|
70
|
+
async doSend(t, s, n, i) {
|
|
71
|
+
this.sendAppIdentifier(), this.send(t, s, n, i);
|
|
309
72
|
}
|
|
310
|
-
async send(t, n, i
|
|
311
|
-
if (!
|
|
73
|
+
async send(t, s, n, i) {
|
|
74
|
+
if (!s && !i) throw new Error('Must pass in either traits or traits_json to "add_or_update_traits"');
|
|
312
75
|
let g = [];
|
|
313
|
-
if (!
|
|
314
|
-
const
|
|
315
|
-
const
|
|
316
|
-
if (
|
|
317
|
-
return { traitsJson: JSON.stringify(
|
|
318
|
-
})(
|
|
319
|
-
|
|
76
|
+
if (!i) {
|
|
77
|
+
const c = (function(a) {
|
|
78
|
+
const l = {}, I = [];
|
|
79
|
+
if (a) for (const [p, C] of Object.entries(a)) He(C) ? l[p] = C : I.push(p);
|
|
80
|
+
return { traitsJson: JSON.stringify(l), excludedFields: I };
|
|
81
|
+
})(s);
|
|
82
|
+
i = c.traitsJson, g = c.excludedFields;
|
|
320
83
|
}
|
|
321
|
-
const r = this.getVariables({ userId: t, traitsJson:
|
|
322
|
-
|
|
84
|
+
const r = this.getVariables({ userId: t, traitsJson: i, excludedFields: g, override: n, library: d().packageLibraryType, version: d().version });
|
|
85
|
+
W(this.endpoint, this.operationName, this.getQuery(), r);
|
|
323
86
|
}
|
|
324
87
|
getQuery() {
|
|
325
88
|
return `
|
|
@@ -329,23 +92,23 @@ class Re extends w {
|
|
|
329
92
|
`;
|
|
330
93
|
}
|
|
331
94
|
}
|
|
332
|
-
class
|
|
95
|
+
class he {
|
|
333
96
|
constructor(e) {
|
|
334
|
-
|
|
335
|
-
this.apiKey = e, this.metadataTransmitter = new
|
|
97
|
+
A(this, "metadataTransmitter");
|
|
98
|
+
this.apiKey = e, this.metadataTransmitter = new Ye();
|
|
336
99
|
}
|
|
337
|
-
identify(e, t,
|
|
338
|
-
t ||
|
|
100
|
+
identify(e, t, s, n = !1) {
|
|
101
|
+
t || s ? this.addOrUpdateMetadata(e, t, s, n) : this.addOrUpdateMetadata(e, {}, void 0, n);
|
|
339
102
|
}
|
|
340
|
-
addOrUpdateMetadata(e, t = {},
|
|
341
|
-
if (!t && !
|
|
342
|
-
|
|
103
|
+
addOrUpdateMetadata(e, t = {}, s, n = !1) {
|
|
104
|
+
if (!t && !s) throw new Error('Must pass in either traits or traitsJson to "addOrUpdateMetadata"');
|
|
105
|
+
d().sfDebug && console.log(" [[DEBUG - addOrUpdateMetadata]] Starting operation"), d().sfDebug && console.log(" addOrUpdateMetadata...SENDING DATA...", e, t, s), this.metadataTransmitter.doSend(e, t, n, s);
|
|
343
106
|
}
|
|
344
107
|
}
|
|
345
|
-
class
|
|
108
|
+
class Q extends F {
|
|
346
109
|
constructor() {
|
|
347
110
|
super();
|
|
348
|
-
|
|
111
|
+
A(this, "serviceIdentifier", new Y());
|
|
349
112
|
}
|
|
350
113
|
async sendAppIdentifier() {
|
|
351
114
|
this.serviceIdentifier.doSend({});
|
|
@@ -355,10 +118,10 @@ class oe extends w {
|
|
|
355
118
|
}
|
|
356
119
|
async send(t) {
|
|
357
120
|
try {
|
|
358
|
-
const
|
|
359
|
-
|
|
360
|
-
} catch (
|
|
361
|
-
|
|
121
|
+
const s = Array.isArray(t) ? t : [t, "default"], n = this.getVariables({ contents: s[0], level: s[1] });
|
|
122
|
+
W(this.endpoint, this.operationName, this.getQuery(), n);
|
|
123
|
+
} catch (s) {
|
|
124
|
+
d().sfDebug && console.error("🚨 Error in send():", s);
|
|
362
125
|
}
|
|
363
126
|
}
|
|
364
127
|
getQuery() {
|
|
@@ -385,121 +148,121 @@ class oe extends w {
|
|
|
385
148
|
`;
|
|
386
149
|
}
|
|
387
150
|
}
|
|
388
|
-
const
|
|
389
|
-
class
|
|
390
|
-
constructor({ file: e, line: t, function:
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
this.file = e, this.line = t, this.function =
|
|
151
|
+
const S = {};
|
|
152
|
+
class V {
|
|
153
|
+
constructor({ file: e, line: t, function: s, code: n, locals: i = {}, offender: g = !1, column: r }) {
|
|
154
|
+
A(this, "file");
|
|
155
|
+
A(this, "line");
|
|
156
|
+
A(this, "function");
|
|
157
|
+
A(this, "code");
|
|
158
|
+
A(this, "locals");
|
|
159
|
+
A(this, "offender");
|
|
160
|
+
A(this, "column");
|
|
161
|
+
this.file = e, this.line = t, this.function = s, this.code = n, this.locals = i, this.offender = g, this.column = r;
|
|
399
162
|
}
|
|
400
163
|
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,
|
|
164
|
+
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
165
|
return this.offender && (e.offender = this.offender), this.column !== void 0 && (e.column = this.column), e;
|
|
403
166
|
}
|
|
404
167
|
toJson() {
|
|
405
168
|
return JSON.stringify(this.toDict());
|
|
406
169
|
}
|
|
407
170
|
}
|
|
408
|
-
class
|
|
171
|
+
class k {
|
|
409
172
|
static encode(e) {
|
|
410
|
-
return e instanceof
|
|
173
|
+
return e instanceof V ? e.toDict() : Array.isArray(e) ? e.map((t) => k.encode(t)) : typeof e == "object" && e !== null ? JSON.stringify(e) : e;
|
|
411
174
|
}
|
|
412
175
|
static stringify(e) {
|
|
413
|
-
return JSON.stringify(
|
|
176
|
+
return JSON.stringify(k.encode(e), (t, s) => s instanceof V ? s.toDict() : s);
|
|
414
177
|
}
|
|
415
178
|
}
|
|
416
|
-
let B,
|
|
417
|
-
function
|
|
418
|
-
|
|
179
|
+
let B, w = 0;
|
|
180
|
+
function Re(o) {
|
|
181
|
+
d().sfDebug && console.log("Initializing Exception Interceptor...");
|
|
419
182
|
try {
|
|
420
183
|
const r = (function() {
|
|
421
184
|
if (B !== void 0) return B;
|
|
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 I = (
|
|
185
|
+
const c = process.env || {}, a = ne(c.SF_IS_LOCAL);
|
|
186
|
+
if (a !== void 0) return B = a;
|
|
187
|
+
const l = (c.SF_ENV || c.NODE_ENV || "").toLowerCase();
|
|
188
|
+
if (["local", "dev", "development"].includes(l)) return B = !0;
|
|
189
|
+
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((p) => !!c[p])) return B = !1;
|
|
190
|
+
const I = (S.hostname?.() || c.HOSTNAME || "").toLowerCase();
|
|
428
191
|
return I === "localhost" || I.endsWith(".local") || I.includes("local") ? B = !0 : B = !1;
|
|
429
192
|
})();
|
|
430
|
-
o?.setSupplementalFields?.({ isFromLocalService: r }), (async function(
|
|
431
|
-
if (
|
|
432
|
-
|
|
433
|
-
const
|
|
434
|
-
if (
|
|
193
|
+
o?.setSupplementalFields?.({ isFromLocalService: r }), (async function(c) {
|
|
194
|
+
if (te) return;
|
|
195
|
+
te = !0;
|
|
196
|
+
const a = process.env || {};
|
|
197
|
+
if (ne(a.SF_IS_LOCAL) === void 0)
|
|
435
198
|
try {
|
|
436
|
-
await (async function(
|
|
437
|
-
const I =
|
|
438
|
-
return (await Promise.allSettled([I,
|
|
439
|
-
})(150) && B && (B = !1,
|
|
199
|
+
await (async function(l) {
|
|
200
|
+
const I = D("http://169.254.169.254/latest/meta-data/", {}, l), p = D("http://metadata.google.internal/computeMetadata/v1/instance/", { "Metadata-Flavor": "Google" }, l), C = D("http://169.254.169.254/metadata/instance?api-version=2021-02-01", { Metadata: "true" }, l);
|
|
201
|
+
return (await Promise.allSettled([I, p, C])).some((u) => u.status === "fulfilled" && (u.value === "ok" || u.value === "http_error"));
|
|
202
|
+
})(150) && B && (B = !1, c?.setSupplementalFields?.({ isFromLocalService: !1 }));
|
|
440
203
|
} catch {
|
|
441
204
|
}
|
|
442
205
|
})(o).catch(() => {
|
|
443
206
|
});
|
|
444
207
|
} catch {
|
|
445
208
|
}
|
|
446
|
-
const e = new Ne(new URL("data:application/javascript;base64,aW1wb3J0IHsgU2Vzc2lvbiB9IGZyb20gImluc3BlY3Rvci9wcm9taXNlcyI7CmltcG9ydCB7IHBhcmVudFBvcnQsIHdvcmtlckRhdGEgfSBmcm9tICJ3b3JrZXJfdGhyZWFkcyI7CgpnbG9iYWwuc2ZEZWJ1ZyA9IHVuZGVmaW5lZDsKZ2xvYmFsLnN0YWNrRGVwdGhMb2NhbHMgPSB1bmRlZmluZWQ7Cmdsb2JhbC5ub2RlTW9kdWxlc1RvQ29sbGVjdExvY2FsVmFyaWFibGVzT24gPSB1bmRlZmluZWQ7CgovKioKICogUHJvY2Vzc2VzIGNhbGwgZnJhbWVzIGZyb20gYW4gZXhjZXB0aW9uIGFuZCBwb3N0cyB0aGVtIHZpYSB0aGUgV29ya2Vy4oCZcyBwYXJlbnRQb3J0LgogKgogKiBAcGFyYW0gc2Vz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saXQoIlxuIik7CiAgICAgICAgICAgIGNvZGUgPSBzb3VyY2VMaW5lc1tsb2NhdGlvbi5saW5lTnVtYmVyXSB8fCAiPG5vdCBjYXB0dXJlZD4iOwogICAgICAgICAgfSBjYXRjaCAoZXJyKSB7CiAgICAgICAgICAgIGlmIChnbG9iYWwuc2ZEZWJ1ZykgewogICAgICAgICAgICAgIGNvbnNvbGUuZXJyb3IoIltXb3JrZXJdIEZhaWxlZCB0byBmZXRjaCBzY3JpcHQgc291cmNlOiIsIGVycik7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIC8vIEZldGNoIGxvY2FsIHZhcmlhYmxlcyBpZiB0aGVyZSdzIGFuIG9iamVjdElkCiAgICAgICAgY29uc3QgbG9jYWxzID0gbG9jYWxTY29wZT8ub2JqZWN0Py5vYmplY3RJZAogICAgICAgICAgPyBhd2FpdCBmZXRjaExvY2FsVmFyaWFibGVzKHNlc3Npb24sIGxvY2FsU2NvcGUub2JqZWN0Lm9iamVjdElkKQogICAgICAgICAgOiB7fTsKCiAgICAgICAgcmV0dXJuIHsKICAgICAgICAgIGZ1bmN0aW9uOiBmdW5jdGlvbk5hbWUgfHwgIjxhbm9ueW1vdXM+IiwKICAgICAgICAgIGxvY2FscywKICAgICAgICAgIGZpbGUsCiAgICAgICAgICBsaW5lOiBsb2NhdGlvbj8ubGluZU51bWJlciB8fCAwLAogICAgICAgICAgY29kZSwKICAgICAgICB9OwogICAgICB9IGNhdGNoIChlcnJvcikgewogICAgICAgIGlmIChnbG9iYWwuc2ZEZWJ1ZykgewogICAgICAgICAgY29uc29sZS5lcnJvcigiW1dvcmtlcl0gRXJyb3IgcHJvY2Vzc2luZyBjYWxsIGZyYW1lOiIsIGVycm9yKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHsKICAgICAgICAgIGZ1bmN0aW9uOiAiPGVycm9yPiIsCiAgICAgICAgICBsb2NhbHM6IHt9LAogICAgICAgICAgZmlsZTogIjx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AgICB9IGVsc2UgewogICAgICAgICAgZmlsZSA9ICI8dW5rbm93bj4iOwogICAgICAgIH0KCiAgICAgICAgLy8gSWYgd2UgaGF2ZSBhIHZhbGlkIGxvY2F0aW9uIGFuZCBzY3JpcHRJZCwgZmV0Y2ggdGhlIGNvZGUgbGluZQogICAgICAgIGlmIChsb2NhdGlvbiAmJiBsb2NhdGlvbi5zY3JpcHRJZCkgewogICAgICAgICAgY29uc3Qgc2NyaXB0SWQgPSBsb2NhdGlvbi5zY3JpcHRJZDsKICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgIGNvbnN0IHsgc2NyaXB0U291cmNlIH0gPSBhd2FpdCBzZXNzaW9uLnBvc3QoCiAgICAgICAgICAgICAgIkRlYnVnZ2VyLmdldFNjcmlwdFNvdXJjZSIsCiAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgc2NyaXB0SWQsCiAgICAgICAgICAgICAgfSwKICAgICAgICAgICAgKTsKICAgICAgICAgICAgY29uc3Qgc291cmNlTGluZXMgPSBzY3JpcHRTb3VyY2Uuc3BsaXQoIlxuIik7CiAgICAgICAgICAgIGNvZGUgPSBzb3VyY2VMaW5lc1tsb2NhdGlvbi5saW5lTnVtYmVyXSB8fCAiPG5vdCBjYXB0dXJlZD4iOwogICAgICAgICAgfSBjYXRjaCAoZXJyKSB7CiAgICAgICAgICAgIGlmIChnbG9iYWwuc2ZEZWJ1ZykgewogICAgICAgICAgICAgIGNvbnNvbGUuZXJyb3IoIltXb3JrZXJdIEZhaWxlZCB0byBmZXRjaCBzY3JpcHQgc291cmNlOiIsIGVycik7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIC8vIEZldGNoIGxvY2FsIHZhcmlhYmxlcyBpZiB0aGVyZSdzIGFuIG9iamVjdElkCiAgICAgICAgY29uc3QgbG9jYWxzID0gbG9jYWxTY29wZT8ub2JqZWN0Py5vYmplY3RJZAogICAgICAgICAgPyBhd2FpdCBmZXRjaExvY2FsVmFyaWFibGVzKHNlc3Npb24sIGxvY2FsU2NvcGUub2JqZWN0Lm9iamVjdElkKQogICAgICAgICAgOiB7fTsKCiAgICAgICAgcmV0dXJuIHsKICAgICAgICAgIGZ1bmN0aW9uOiBmdW5jdGlvbk5hbWUgfHwgIjxhbm9ueW1vdXM+IiwKICAgICAgICAgIGxvY2FscywKICAgICAgICAgIGZpbGUsCiAgICAgICAgICBsaW5lOiBsb2NhdGlvbj8ubGluZU51bWJlciB8fCAwLAogICAgICAgICAgY29kZSwKICAgICAgICB9OwogICAgICB9IGNhdGNoIChlcnJvcikgewogICAgICAgIGlmIChnbG9iYWwuc2ZEZWJ1ZykgewogICAgICAgICAgY29uc29sZS5lcnJvcigiW1dvcmtlcl0gRXJyb3IgcHJvY2Vzc2luZyBjYWxsIGZyYW1lOiIsIGVycm9yKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHsKICAgICAgICAgIGZ1bmN0aW9uOiAiPGVycm9yPiIsCiAgICAgICAgICBsb2NhbHM6IHt9LAogICAgICAgICAgZmlsZTogIjx1bmtub3duPiIsCiAgICAgICAgICBsaW5lOiAwLAogICAgICAgICAgY29kZTogIjxub3QgY2FwdHVyZWQ+IiwKICAgICAgICB9OwogICAgICB9CiAgICB9KSwKICApOwogIC8vIFBvc3QgZXhjZXB0aW9uIGRhdGEKICBwYXJlbnRQb3J0Py5wb3N0TWVzc2FnZSh7IHR5cGU6ICJleGNlcHRpb24iLCBmcmFtZXMgfSk7Cn0KCi8qKgogKiBIYW5kbGVzIHRoZSAicGF1c2VkIiBzdGF0ZSBvZiB0aGUgZGVidWdnZXIgYW5kIHByb2Nlc3NlcyBleGNlcHRpb25zIG9yIHByb21pc2UgcmVqZWN0aW9ucy4KICogQHBhcmFtIHtTZXNzaW9ufSBzZXNzaW9uIC0gVGhlIGRlYnVnZ2luZyBzZXNzaW9uIGluc3RhbmNlLgogKiBAcGFyYW0ge29iamVjdH0gcGFyYW1zIC0gUGFyYW1ldGVycyBmcm9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iwgaWQsIHByb3AubmFtZSwgdmFyaWFibGVzKTsKICAgICAgICB9IGVsc2UgaWYgKHByb3A/LnZhbHVlKSB7CiAgICAgICAgICB1bnJvbGxPdGhlcihwcm9wLCB2YXJpYWJsZXMpOwogICAgICAgIH0KICAgICAgfQogICAgICByZXR1cm4gdmFyaWFibGVzOwogICAgfQogIH0gY2F0Y2ggKGVycikgewogICAgaWYgKGdsb2JhbC5zZkRlYnVnKSB7CiAgICAgIGNvbnNvbGUuZXJyb3IoIltXb3JrZXJdIEZhaWxlZCB0byBmZXRjaCBsb2NhbCB2YXJpYWJsZXM6IiwgZXJyKTsKICAgIH0KICAgIHJldHVybiB7fTsKICB9Cn0KCnN0YXJ0RGVidWdnZXIoKS5jYXRjaCgoZXJyb3IpID0+IHsKICBpZiAoZ2xvYmFsLnNmRGVidWcpIHsKICAgIGNvbnNvbGUuZXJyb3IoIltXb3JrZXJdIEZhaWxlZCB0byBzdGFydCBkZWJ1Z2dlcjoiLCBlcnJvcik7CiAgfQp9KTsKCi8vIEtlZXAgdGhlIHdvcmtlciBhbGl2ZQpzZXRJbnRlcnZhbCgoKSA9PiB7fSwgMTAwMDApOwo="), { workerData: { captureAllExceptions: !0 } });
|
|
447
210
|
let t = null;
|
|
448
|
-
const
|
|
211
|
+
const s = /* @__PURE__ */ new WeakMap();
|
|
449
212
|
e.on("message", (r) => {
|
|
450
|
-
if (typeof r == "string" &&
|
|
451
|
-
const { frames:
|
|
452
|
-
if (!
|
|
453
|
-
const
|
|
454
|
-
return
|
|
213
|
+
if (typeof r == "string" && d().sfDebug && console.log(`[Worker] ${r}`), r.readyToGetParameters && e.postMessage({ sfDebug: d().sfDebug, stackDepthLocals: d().stackDepthLocals, nodeModulesToCollectLocalVariablesOn: d().nodeModulesToCollectLocalVariablesOn }), r.type === "exception") {
|
|
214
|
+
const { frames: c } = r, a = t;
|
|
215
|
+
if (!a) return;
|
|
216
|
+
const l = s.get(a), I = (function(C) {
|
|
217
|
+
return C ? C.split(`
|
|
455
218
|
`).slice(1).map((u) => {
|
|
456
219
|
const m = /at (.+?) \((.+):(\d+):(\d+)\)/.exec(u) || /at (.+):(\d+):(\d+)/.exec(u);
|
|
457
220
|
if (m) {
|
|
458
|
-
const [,
|
|
459
|
-
return new
|
|
221
|
+
const [, h, Z, b, y] = m;
|
|
222
|
+
return new V({ function: h || "<anonymous>", locals: {}, file: Z || "<unknown>", line: parseInt(b, 10) || 0, code: "<not captured>", column: parseInt(y) || 0 });
|
|
460
223
|
}
|
|
461
|
-
return new
|
|
224
|
+
return new V({ function: "<unknown>", locals: {}, file: "<unknown>", line: 0, code: "<not captured>", column: 0 });
|
|
462
225
|
}) : [];
|
|
463
|
-
})(
|
|
226
|
+
})(a.stack), p = (function(C, u) {
|
|
464
227
|
const m = [];
|
|
465
|
-
let
|
|
466
|
-
for (let b = 0; b <
|
|
467
|
-
const
|
|
468
|
-
if (
|
|
469
|
-
for (let
|
|
470
|
-
const
|
|
471
|
-
if (
|
|
472
|
-
|
|
228
|
+
let h = -1, Z = -1;
|
|
229
|
+
for (let b = 0; b < C.length; b++) {
|
|
230
|
+
const y = Je(C[b].file);
|
|
231
|
+
if (Z = b, y !== "<unknown>") {
|
|
232
|
+
for (let f = 0; f < u.length; f++) {
|
|
233
|
+
const v = u[f];
|
|
234
|
+
if (be(v, y) || typeof v.file == "string" && v.file.includes(y)) {
|
|
235
|
+
h = f, w = 0, d().sfDebug && console.log(`✅ Matched Frame Found: ${y} @ Debugger Frame ${f}`);
|
|
473
236
|
break;
|
|
474
237
|
}
|
|
475
238
|
}
|
|
476
|
-
if (
|
|
239
|
+
if (h !== -1) break;
|
|
477
240
|
}
|
|
478
241
|
}
|
|
479
|
-
if (
|
|
480
|
-
|
|
242
|
+
if (h === -1) return w === 10 ? (w = 0, C) : (++w, d().sfDebug && console.log(`"❌ No matching frame found. Checking once again, Attempt N ${w}"`), []);
|
|
243
|
+
d().sfDebug && console.log(`🔄 Merging from matched index ${h} onward...`);
|
|
481
244
|
for (let b = 0; b < u.length; b++) {
|
|
482
|
-
const
|
|
483
|
-
m.push(new
|
|
245
|
+
const y = C[Z + b], f = u[h + b];
|
|
246
|
+
m.push(new V({ function: f?.function || y?.function || "<anonymous>", locals: f?.locals || y?.locals || {}, file: y?.file || f?.file || "<unknown>", line: f?.line || y?.line || 0, code: f?.code || y?.code || "<not captured>" }));
|
|
484
247
|
}
|
|
485
248
|
return m;
|
|
486
|
-
})(I,
|
|
487
|
-
if (
|
|
249
|
+
})(I, c || []);
|
|
250
|
+
if (p.length !== 0) {
|
|
488
251
|
t = null;
|
|
489
|
-
const
|
|
490
|
-
for (let
|
|
491
|
-
const
|
|
492
|
-
|
|
252
|
+
const C = d().stackDepthCodeTraceDepth, u = C === -1 ? p : p.slice(0, C + 1), m = Math.min(u.length, I.length);
|
|
253
|
+
for (let y = 0; y < m; y++) (async () => {
|
|
254
|
+
const f = Xe(u[y].file, I[y].line, I[y].column);
|
|
255
|
+
f && (f.content != null && (u[y].code = f.content), f.file != null && (u[y].file = f.file));
|
|
493
256
|
})();
|
|
494
257
|
o.setOperationName("CollectExceptions");
|
|
495
|
-
const
|
|
496
|
-
|
|
497
|
-
const
|
|
498
|
-
b ? (
|
|
499
|
-
|
|
500
|
-
})) : o.doSend(
|
|
501
|
-
o.doSend(
|
|
502
|
-
}) : o.doSend(
|
|
258
|
+
const h = a.message ? `${a.name}: ${a.message}` : a.name;
|
|
259
|
+
d().sfDebug && console.log("error message is : ", h);
|
|
260
|
+
const Z = N.getInstance(), b = s.get(a);
|
|
261
|
+
b ? (Z.setTraceIdFor(b, b), Z.runWithSession(b, () => {
|
|
262
|
+
Z.setTraceId(b), o.doSend(h, u);
|
|
263
|
+
})) : o.doSend(h, u), l ? N.getInstance().runWithSession(l, () => {
|
|
264
|
+
o.doSend(h, u);
|
|
265
|
+
}) : o.doSend(h, u);
|
|
503
266
|
}
|
|
504
267
|
}
|
|
505
268
|
}), e.on("error", (r) => {
|
|
@@ -507,115 +270,115 @@ function Ye(o) {
|
|
|
507
270
|
}), e.on("exit", (r) => {
|
|
508
271
|
console.error(`[Worker] Exited with code ${r}`);
|
|
509
272
|
}), e.unref();
|
|
510
|
-
const
|
|
273
|
+
const n = Error, i = /* @__PURE__ */ new Set();
|
|
511
274
|
function g(...r) {
|
|
512
|
-
const
|
|
513
|
-
Reflect.setPrototypeOf(
|
|
275
|
+
const c = Reflect.construct(n, r);
|
|
276
|
+
Reflect.setPrototypeOf(c, g.prototype);
|
|
514
277
|
try {
|
|
515
|
-
const
|
|
516
|
-
|
|
278
|
+
const l = N.getInstance().getTraceId();
|
|
279
|
+
s.set(c, l);
|
|
517
280
|
} catch {
|
|
518
281
|
}
|
|
519
|
-
|
|
520
|
-
const
|
|
282
|
+
n.captureStackTrace && n.captureStackTrace(c, g);
|
|
283
|
+
const a = `${c.message}:${c.stack?.split(`
|
|
521
284
|
`)[1]?.trim()}`;
|
|
522
|
-
if (!
|
|
523
|
-
|
|
524
|
-
const
|
|
525
|
-
|
|
285
|
+
if (!i.has(a)) {
|
|
286
|
+
i.add(a), t = c;
|
|
287
|
+
const l = N.getInstance().getTraceId();
|
|
288
|
+
s.set(c, l), e.postMessage({ type: "processException", error: c.message });
|
|
526
289
|
}
|
|
527
|
-
return
|
|
290
|
+
return c;
|
|
528
291
|
}
|
|
529
|
-
g.prototype = Object.create(
|
|
292
|
+
g.prototype = Object.create(n.prototype, { constructor: { value: g, enumerable: !1, writable: !0, configurable: !0 } }), Object.setPrototypeOf(g, n), globalThis.Error = g;
|
|
530
293
|
}
|
|
531
|
-
function
|
|
294
|
+
function ee(o) {
|
|
532
295
|
return o = (o = (o = o.replace(/^webpack:\/\/[^\/]+\/\.?\//, "")).replace(/^.*\/pages\//, "pages/")).replace(/\.(js|ts)$/, "");
|
|
533
296
|
}
|
|
534
|
-
function
|
|
535
|
-
const
|
|
536
|
-
|
|
537
|
-
const g =
|
|
538
|
-
return g ? g[1] :
|
|
297
|
+
function Xe(o, e, t) {
|
|
298
|
+
const s = (function(i) {
|
|
299
|
+
i.startsWith("at ") && (i = i.slice(3).trim());
|
|
300
|
+
const g = i.match(/^(.*?)(:\d+)+(\.map)?$/);
|
|
301
|
+
return g ? g[1] : i;
|
|
539
302
|
})(o);
|
|
540
|
-
if (!
|
|
541
|
-
const
|
|
303
|
+
if (!s || s === "<unknown>") return null;
|
|
304
|
+
const n = s + ".map";
|
|
542
305
|
try {
|
|
543
|
-
const
|
|
544
|
-
if (
|
|
545
|
-
const g = JSON.parse(
|
|
546
|
-
let r = new
|
|
547
|
-
if (
|
|
548
|
-
const
|
|
549
|
-
if (
|
|
306
|
+
const i = pe(n, "utf-8");
|
|
307
|
+
if (i) {
|
|
308
|
+
const g = JSON.parse(i);
|
|
309
|
+
let r = new me.SourceMapConsumer(g).originalPositionFor({ line: e, column: t });
|
|
310
|
+
if (s && r.source) {
|
|
311
|
+
const c = ee(s), a = g.sources.findIndex((l) => ee(l) === c);
|
|
312
|
+
if (a === -1) d().sfDebug && console.log(`Source file "${s}" not found in the source map.`);
|
|
550
313
|
else {
|
|
551
|
-
const
|
|
552
|
-
if (
|
|
553
|
-
return { content:
|
|
314
|
+
const l = g.sourcesContent[a], I = g.names.join(",");
|
|
315
|
+
if (l)
|
|
316
|
+
return { content: l.split(`
|
|
554
317
|
`).slice(r.line - 1, r.line + 20).join(`
|
|
555
318
|
`), name: I, file: r.source };
|
|
556
|
-
|
|
319
|
+
d().sfDebug && console.log(`No source content available for file "${s}".`);
|
|
557
320
|
}
|
|
558
321
|
}
|
|
559
322
|
return { content: g.sourcesContent[0], name: g.names[0], file: g.file };
|
|
560
323
|
}
|
|
561
|
-
} catch (
|
|
562
|
-
|
|
324
|
+
} catch (i) {
|
|
325
|
+
d().sfDebug && console.log(`Cant read/parse "${n}: Error - ".`, i);
|
|
563
326
|
}
|
|
564
327
|
return null;
|
|
565
328
|
}
|
|
566
|
-
function
|
|
329
|
+
function Je(o) {
|
|
567
330
|
return o?.split("/").pop() || "<unknown>";
|
|
568
331
|
}
|
|
569
|
-
function
|
|
332
|
+
function be(o, e) {
|
|
570
333
|
if (!o || typeof o != "object") return !1;
|
|
571
334
|
for (const t of Object.values(o))
|
|
572
|
-
if (typeof t == "string" && t.includes(e) || typeof t == "object" &&
|
|
335
|
+
if (typeof t == "string" && t.includes(e) || typeof t == "object" && be(t, e)) return !0;
|
|
573
336
|
return !1;
|
|
574
337
|
}
|
|
575
|
-
let
|
|
576
|
-
function
|
|
338
|
+
let te = !1;
|
|
339
|
+
function ne(o) {
|
|
577
340
|
if (!o) return;
|
|
578
341
|
const e = o.toLowerCase().trim();
|
|
579
342
|
return !!["1", "true", "yes", "on"].includes(e) || !["0", "false", "no", "off"].includes(e) && void 0;
|
|
580
343
|
}
|
|
581
|
-
function
|
|
582
|
-
return new Promise((
|
|
344
|
+
function D(o, e, t) {
|
|
345
|
+
return new Promise((s) => {
|
|
583
346
|
try {
|
|
584
|
-
const
|
|
585
|
-
g.resume(), g.statusCode && g.statusCode >= 200 && g.statusCode < 400 ?
|
|
347
|
+
const n = new URL(o), i = (n.protocol, S).request({ method: "GET", hostname: n.hostname, port: n.port || (n.protocol === "https:" ? 443 : 80), path: n.pathname + (n.search || ""), headers: e }, (g) => {
|
|
348
|
+
g.resume(), g.statusCode && g.statusCode >= 200 && g.statusCode < 400 ? s("ok") : s("http_error");
|
|
586
349
|
});
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
}),
|
|
350
|
+
i.on("error", () => s("error")), i.setTimeout(t, () => {
|
|
351
|
+
i.destroy(), s("timeout");
|
|
352
|
+
}), i.end();
|
|
590
353
|
} catch {
|
|
591
|
-
|
|
354
|
+
s("error");
|
|
592
355
|
}
|
|
593
356
|
});
|
|
594
357
|
}
|
|
595
|
-
class
|
|
358
|
+
class Ke extends F {
|
|
596
359
|
constructor() {
|
|
597
360
|
super();
|
|
598
|
-
|
|
599
|
-
|
|
361
|
+
A(this, "serviceIdentifier", new Y());
|
|
362
|
+
A(this, "supplementalFields", {});
|
|
600
363
|
this.setOperationName("CollectExceptions");
|
|
601
364
|
}
|
|
602
365
|
setSupplementalFields(t) {
|
|
603
366
|
this.supplementalFields = { ...this.supplementalFields, ...t };
|
|
604
367
|
}
|
|
605
368
|
normalizedSupplementalForGraphQL() {
|
|
606
|
-
const { isFromLocalService: t } = this.supplementalFields,
|
|
607
|
-
return t !== void 0 && (
|
|
369
|
+
const { isFromLocalService: t } = this.supplementalFields, s = {};
|
|
370
|
+
return t !== void 0 && (s.isFromLocalService = t), s;
|
|
608
371
|
}
|
|
609
372
|
async sendAppIdentifier() {
|
|
610
373
|
this.serviceIdentifier.doSend({});
|
|
611
374
|
}
|
|
612
|
-
async doSend(t,
|
|
613
|
-
this.sendAppIdentifier(), this.send(t,
|
|
375
|
+
async doSend(t, s) {
|
|
376
|
+
this.sendAppIdentifier(), this.send(t, s);
|
|
614
377
|
}
|
|
615
|
-
async send(t,
|
|
616
|
-
|
|
617
|
-
const
|
|
618
|
-
|
|
378
|
+
async send(t, s) {
|
|
379
|
+
d().sfDebug && console.log(" SENDING EXCEPTION...");
|
|
380
|
+
const n = JSON.stringify(k.encode(s)), i = this.normalizedSupplementalForGraphQL(), g = this.getVariables({ exceptionMessage: t, traceJson: n, reentrancyGuardPreactive: !1, library: d().packageLibraryType, version: d().version, ...i });
|
|
381
|
+
W(this.endpoint, this.operationName, this.getQuery(), g);
|
|
619
382
|
}
|
|
620
383
|
getQuery() {
|
|
621
384
|
return `
|
|
@@ -649,86 +412,44 @@ class Te extends w {
|
|
|
649
412
|
`;
|
|
650
413
|
}
|
|
651
414
|
}
|
|
652
|
-
const
|
|
653
|
-
var
|
|
654
|
-
const
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
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
|
-
}
|
|
661
|
-
function Se(o) {
|
|
662
|
-
try {
|
|
663
|
-
const e = o.split("-");
|
|
664
|
-
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
|
-
} catch (e) {
|
|
666
|
-
return console.error(`[FuncSpan] Failed to parse header override "${o}":`, e), null;
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
function H(o, e) {
|
|
670
|
-
if (!o) return e;
|
|
671
|
-
const t = o.toLowerCase();
|
|
672
|
-
return t === "true" || t === "1" || t === "yes";
|
|
673
|
-
}
|
|
674
|
-
const se = new ie();
|
|
675
|
-
function Je(o) {
|
|
676
|
-
se.enterWith(o);
|
|
677
|
-
}
|
|
678
|
-
function Ze() {
|
|
679
|
-
return se.getStore();
|
|
680
|
-
}
|
|
681
|
-
function Xe() {
|
|
682
|
-
se.enterWith(void 0);
|
|
683
|
-
}
|
|
684
|
-
function _(...o) {
|
|
685
|
-
const e = {};
|
|
686
|
-
for (const t of o) for (const n in t) t[n] !== void 0 && (e[n] = t[n]);
|
|
687
|
-
return e;
|
|
688
|
-
}
|
|
689
|
-
function ee(o, e) {
|
|
690
|
-
try {
|
|
691
|
-
const t = JSON.stringify(o).length / 1048576;
|
|
692
|
-
return t <= e ? o : { _truncated: !0, _originalSizeMB: t.toFixed(2), _limitMB: e, _preview: JSON.stringify(o).substring(0, 500) + "..." };
|
|
693
|
-
} catch {
|
|
694
|
-
return { _error: "Failed to serialize data", _type: typeof o };
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
let Ce = !1;
|
|
698
|
-
function Ee() {
|
|
699
|
-
const o = l().sfDebug;
|
|
700
|
-
if (Ce) return void (o && console.log("[patchNodeHttpInbound] Already installed, skipping."));
|
|
415
|
+
const oe = "getting request source code";
|
|
416
|
+
var z = ((o) => (o.UNKNOWN = "unknown", o.ANONYMOUS = "anonymous", o.NOT_CAPTURED = "not captured", o))(z || {});
|
|
417
|
+
const x = "http:", P = "https:", _e = we(import.meta.url);
|
|
418
|
+
let se = !1;
|
|
419
|
+
function ze() {
|
|
420
|
+
const o = d().sfDebug;
|
|
421
|
+
if (se) return void (o && console.log("[patchNodeHttpInbound] Already installed, skipping."));
|
|
701
422
|
let e;
|
|
702
|
-
|
|
423
|
+
se = !0;
|
|
703
424
|
try {
|
|
704
|
-
e =
|
|
705
|
-
} catch (
|
|
706
|
-
return void console.error("Failed to require node:http:",
|
|
425
|
+
e = _e("node:http"), o && console.log("[patchNodeHttpInbound] node:http required successfully.");
|
|
426
|
+
} catch (n) {
|
|
427
|
+
return void console.error("Failed to require node:http:", n);
|
|
707
428
|
}
|
|
708
429
|
if (!e?.Server?.prototype) return void (o && console.log("[patchNodeHttpInbound] http.Server.prototype not found."));
|
|
709
|
-
const t = e.Server.prototype,
|
|
710
|
-
|
|
711
|
-
if (
|
|
712
|
-
const g =
|
|
430
|
+
const t = e.Server.prototype, s = t.emit;
|
|
431
|
+
s && !t.__sf_inbound_patched__ ? (Object.defineProperty(t, "__sf_inbound_patched__", { value: !0, enumerable: !1, configurable: !1, writable: !1 }), o && console.log("[patchNodeHttpInbound] Patching http.Server.prototype.emit."), t.emit = function(n, ...i) {
|
|
432
|
+
if (n !== "request") return o && console.log(`[patchNodeHttpInbound] Passing through event: ${n}`), s.call(this, n, ...i);
|
|
433
|
+
const g = i[0], r = i[1], c = (function(C) {
|
|
713
434
|
const u = {};
|
|
714
|
-
if (!
|
|
715
|
-
for (const [m,
|
|
435
|
+
if (!C) return u;
|
|
436
|
+
for (const [m, h] of Object.entries(C)) h != null && (Array.isArray(h) ? u[m.toLowerCase()] = h.join(", ") : u[m.toLowerCase()] = String(h));
|
|
716
437
|
return u;
|
|
717
|
-
})(g?.headers),
|
|
718
|
-
o && (console.log("[patchNodeHttpInbound] Intercepted request event."), console.log("[patchNodeHttpInbound] Inbound headers:",
|
|
719
|
-
const I =
|
|
720
|
-
I.setTraceId(
|
|
721
|
-
const
|
|
722
|
-
return o && console.log("[patchNodeHttpInbound] Context traceId set:",
|
|
723
|
-
|
|
724
|
-
const
|
|
725
|
-
o && console.log("[patchNodeHttpInbound] Response finished/closed for traceId:", I.getTraceId()),
|
|
438
|
+
})(g?.headers), a = c["x-sf3-rid"], l = c["x-sf3-functionspancaptureoverride"];
|
|
439
|
+
o && (console.log("[patchNodeHttpInbound] Intercepted request event."), console.log("[patchNodeHttpInbound] Inbound headers:", c), console.log("[patchNodeHttpInbound] Trace header:", a), console.log("[patchNodeHttpInbound] FuncSpan override header:", l));
|
|
440
|
+
const I = N.getInstance();
|
|
441
|
+
I.setTraceId(a);
|
|
442
|
+
const p = I.getTraceId();
|
|
443
|
+
return o && console.log("[patchNodeHttpInbound] Context traceId set:", p), I.runWith({ inboundHeaders: c, ...a ? { traceId: a } : {} }, () => {
|
|
444
|
+
a && I.setTraceId(a), l && (ye(l), o && console.log("[patchNodeHttpInbound] FuncSpan override set:", l)), o && console.log("[patchNodeHttpInbound] Running request handler in context.");
|
|
445
|
+
const C = () => {
|
|
446
|
+
o && console.log("[patchNodeHttpInbound] Response finished/closed for traceId:", I.getTraceId()), l && (Ze(), o && console.log("[patchNodeHttpInbound] FuncSpan override cleared"));
|
|
726
447
|
};
|
|
727
|
-
return r.on("finish",
|
|
448
|
+
return r.on("finish", C), r.on("close", C), s.call(this, n, g, r);
|
|
728
449
|
});
|
|
729
450
|
}) : o && console.log("[patchNodeHttpInbound] Already patched, skipping.");
|
|
730
451
|
}
|
|
731
|
-
class
|
|
452
|
+
class ke extends Q {
|
|
732
453
|
constructor() {
|
|
733
454
|
super(), this.setOperationName("DomainsToNotPassHeaderTo");
|
|
734
455
|
}
|
|
@@ -748,14 +469,14 @@ class _e extends oe {
|
|
|
748
469
|
domains: $domains
|
|
749
470
|
)
|
|
750
471
|
}
|
|
751
|
-
`,
|
|
752
|
-
|
|
472
|
+
`, s = { apiKey: this.apiKey, serviceUuid: this.serviceUUID, domains: e };
|
|
473
|
+
W(this.endpoint, this.operationName, t, s);
|
|
753
474
|
}
|
|
754
475
|
}
|
|
755
|
-
class
|
|
476
|
+
class Ue extends F {
|
|
756
477
|
constructor() {
|
|
757
478
|
super();
|
|
758
|
-
|
|
479
|
+
A(this, "serviceIdentifier", new Y());
|
|
759
480
|
this.setOperationName("CollectNetworkHops");
|
|
760
481
|
}
|
|
761
482
|
async sendAppIdentifier() {
|
|
@@ -765,8 +486,8 @@ class De extends w {
|
|
|
765
486
|
this.sendAppIdentifier(), this.send(t);
|
|
766
487
|
}
|
|
767
488
|
async send(t) {
|
|
768
|
-
const { name:
|
|
769
|
-
|
|
489
|
+
const { name: s, column: n, line: i, entrypoint: g, retryWithoutTraceId: r } = t, c = this.getVariables({ name: s, column: n, line: i, entrypoint: g, retryWithoutTraceId: r });
|
|
490
|
+
W(this.endpoint, this.operationName, this.getQuery(), c);
|
|
770
491
|
}
|
|
771
492
|
getQuery() {
|
|
772
493
|
return `
|
|
@@ -796,10 +517,10 @@ class De extends w {
|
|
|
796
517
|
`;
|
|
797
518
|
}
|
|
798
519
|
}
|
|
799
|
-
class
|
|
520
|
+
class Te extends F {
|
|
800
521
|
constructor() {
|
|
801
522
|
super();
|
|
802
|
-
|
|
523
|
+
A(this, "serviceIdentifier", new Y());
|
|
803
524
|
this.setOperationName("CollectNetworkRequest");
|
|
804
525
|
}
|
|
805
526
|
async sendAppIdentifier() {
|
|
@@ -819,188 +540,188 @@ class $e extends w {
|
|
|
819
540
|
`;
|
|
820
541
|
}
|
|
821
542
|
async send(t) {
|
|
822
|
-
const
|
|
823
|
-
await
|
|
543
|
+
const s = { data: { ...t } };
|
|
544
|
+
await W(this.endpoint, this.operationName, this.getQuery(), s);
|
|
824
545
|
}
|
|
825
546
|
}
|
|
826
|
-
const
|
|
827
|
-
class
|
|
547
|
+
const O = [400, 403];
|
|
548
|
+
class $e {
|
|
828
549
|
constructor(e = []) {
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
this.contextManager =
|
|
550
|
+
A(this, "HEADER_TRACING", "X-Sf3-Rid");
|
|
551
|
+
A(this, "HEADER_LOG_GUARD", "reentrancy_guard_logging_preactive");
|
|
552
|
+
A(this, "HEADER_PRINT_GUARD", "reentrancy_guard_print_preactive");
|
|
553
|
+
A(this, "HEADER_EXCEPTION_GUARD", "reentrancy_guard_exception_preactive");
|
|
554
|
+
A(this, "contextManager");
|
|
555
|
+
this.contextManager = N.getInstance(), e?.forEach((t) => {
|
|
835
556
|
typeof t == "string" && t.trim() && this.contextManager.getExcludedDomains().add(t);
|
|
836
|
-
}),
|
|
557
|
+
}), d().sfDebug && console.log("[RequestInterceptor] Initialized with static excluded domains.");
|
|
837
558
|
}
|
|
838
559
|
extractIdsFromTraceHeader(e, t = this.HEADER_TRACING) {
|
|
839
|
-
let
|
|
840
|
-
if (e instanceof Headers)
|
|
560
|
+
let s;
|
|
561
|
+
if (e instanceof Headers) s = e.get(t) ?? void 0;
|
|
841
562
|
else {
|
|
842
|
-
const
|
|
843
|
-
for (const [g, r] of Object.entries(e)) if (g.toLowerCase() ===
|
|
844
|
-
|
|
563
|
+
const i = t.toLowerCase();
|
|
564
|
+
for (const [g, r] of Object.entries(e)) if (g.toLowerCase() === i) {
|
|
565
|
+
s = r;
|
|
845
566
|
break;
|
|
846
567
|
}
|
|
847
568
|
}
|
|
848
|
-
if (!
|
|
849
|
-
const
|
|
850
|
-
return
|
|
569
|
+
if (!s) return {};
|
|
570
|
+
const n = s.split("/").filter(Boolean);
|
|
571
|
+
return n.length < 3 ? {} : { sessionId: n[0], pageVisitId: n[1], requestId: n[n.length - 1] };
|
|
851
572
|
}
|
|
852
573
|
parseStackFrame(e) {
|
|
853
574
|
const t = /\((.*):(\d+):(\d+)\)$/.exec(e.trim());
|
|
854
575
|
if (!t) return null;
|
|
855
|
-
const [, n, i
|
|
856
|
-
return { filePath:
|
|
576
|
+
const [, s, n, i] = t;
|
|
577
|
+
return { filePath: s, line: parseInt(n, 10), column: parseInt(i, 10) };
|
|
857
578
|
}
|
|
858
|
-
async getOriginalPosition(e, t,
|
|
859
|
-
let
|
|
860
|
-
const
|
|
579
|
+
async getOriginalPosition(e, t, s) {
|
|
580
|
+
let n = { source: e, line: t, column: s, name: null };
|
|
581
|
+
const i = e + ".map";
|
|
861
582
|
try {
|
|
862
|
-
const g = JSON.parse(pe(
|
|
863
|
-
let r = (await new
|
|
864
|
-
r.source && (
|
|
583
|
+
const g = JSON.parse(pe(i, "utf-8"));
|
|
584
|
+
let r = (await new me.SourceMapConsumer(g)).originalPositionFor({ line: t, column: s });
|
|
585
|
+
r.source && (n = r);
|
|
865
586
|
} catch (g) {
|
|
866
|
-
|
|
587
|
+
d().sfDebug && console.error(`Could not read/parse map file at ${i}:`, g);
|
|
867
588
|
}
|
|
868
|
-
return { originalPos:
|
|
589
|
+
return { originalPos: n };
|
|
869
590
|
}
|
|
870
|
-
captureFirstUserLines(e, t = 10,
|
|
871
|
-
const
|
|
872
|
-
Error.stackTraceLimit = Math.max(
|
|
873
|
-
const g = new Error(
|
|
874
|
-
|
|
591
|
+
captureFirstUserLines(e, t = 10, s = !1) {
|
|
592
|
+
const n = d().sfDebug ? 10 : t, i = Error.stackTraceLimit;
|
|
593
|
+
Error.stackTraceLimit = Math.max(i, n);
|
|
594
|
+
const g = new Error(oe);
|
|
595
|
+
oe in Error && Error.captureStackTrace(g, this.captureFirstUserLines);
|
|
875
596
|
const r = g.stack || "";
|
|
876
|
-
Error.stackTraceLimit =
|
|
877
|
-
const
|
|
878
|
-
`).slice(1),
|
|
879
|
-
for (const
|
|
880
|
-
if (!(
|
|
881
|
-
for (const
|
|
882
|
-
const I = this.parseStackFrame(
|
|
597
|
+
Error.stackTraceLimit = i;
|
|
598
|
+
const c = r.split(`
|
|
599
|
+
`).slice(1), a = [];
|
|
600
|
+
for (const l of c)
|
|
601
|
+
if (!(l.includes("node:internal") || l.includes("internal/modules") || l.includes("internal/process") || l.includes("node_modules") || l.includes(".next/server/chunks") || l.includes("RequestInterceptor") || l.includes("contextManager") || l.includes("setupConfig")) && (a.push(l.trim()), a.length >= t)) break;
|
|
602
|
+
for (const l of a) {
|
|
603
|
+
const I = this.parseStackFrame(l);
|
|
883
604
|
I ? (async () => {
|
|
884
|
-
const { originalPos:
|
|
885
|
-
if (
|
|
886
|
-
|
|
887
|
-
const
|
|
888
|
-
e.doSend(
|
|
605
|
+
const { originalPos: p } = await this.getOriginalPosition(I.filePath, I.line, I.column);
|
|
606
|
+
if (p) {
|
|
607
|
+
d().sfDebug && console.log("[RequestInterceptor] First user code line:", p);
|
|
608
|
+
const C = { line: p.line?.toString() || z.UNKNOWN, column: p.column?.toString() || z.NOT_CAPTURED, name: p.name || z.NOT_CAPTURED, entrypoint: p.source, retryWithoutTraceId: s };
|
|
609
|
+
e.doSend(C);
|
|
889
610
|
}
|
|
890
|
-
})() :
|
|
611
|
+
})() : d().sfDebug && console.error("Could not parse stack line:", l);
|
|
891
612
|
}
|
|
892
613
|
}
|
|
893
614
|
addReentrancyGuardHeaders(e) {
|
|
894
615
|
e.set(this.HEADER_LOG_GUARD, "true"), e.set(this.HEADER_PRINT_GUARD, "true"), e.set(this.HEADER_EXCEPTION_GUARD, "true");
|
|
895
616
|
}
|
|
896
617
|
shouldPropagateHeaders(e) {
|
|
897
|
-
return !
|
|
618
|
+
return !Ge.some((t) => new RegExp(`^${t.replace(/\*/g, ".*")}$`).test(e));
|
|
898
619
|
}
|
|
899
620
|
addTracingHeaders(e, t) {
|
|
900
|
-
const
|
|
901
|
-
return
|
|
621
|
+
const s = new URL(t).hostname, n = this.shouldPropagateHeaders(s);
|
|
622
|
+
return n ? this.addTracingHeader(e, t) : d().sfDebug && console.error(`[RequestInterceptor] Excluded domain: ${s}`), n;
|
|
902
623
|
}
|
|
903
624
|
addTracingHeader(e, t) {
|
|
904
|
-
const
|
|
905
|
-
if (
|
|
906
|
-
const r =
|
|
907
|
-
if (r && r.sample_rate === 0) return void (
|
|
625
|
+
const s = le();
|
|
626
|
+
if (s) {
|
|
627
|
+
const r = de(s);
|
|
628
|
+
if (r && r.sample_rate === 0) return void (d().sfDebug && console.log(`[RequestInterceptor] Function span tracking disabled (sample_rate=0), skipping tracing header for ${t}`));
|
|
908
629
|
}
|
|
909
|
-
const
|
|
910
|
-
e.set(this.HEADER_TRACING, `${
|
|
630
|
+
const n = this.contextManager.getOrSetSfTraceId(), i = this.contextManager.getOrSetPageVisitUUID(), g = Ie();
|
|
631
|
+
e.set(this.HEADER_TRACING, `${n}/${i}/${g}`), d().sfDebug && console.log(`[RequestInterceptor] Added tracing header for ${t}`);
|
|
911
632
|
}
|
|
912
633
|
patchFetch(e, t) {
|
|
913
|
-
const
|
|
914
|
-
typeof
|
|
915
|
-
const g = new Headers(
|
|
916
|
-
if (g.get(this.HEADER_LOG_GUARD) === "true" || g.get(this.HEADER_PRINT_GUARD) === "true" || g.get(this.HEADER_EXCEPTION_GUARD) === "true") return n
|
|
634
|
+
const s = globalThis.fetch;
|
|
635
|
+
typeof s == "function" ? globalThis.fetch = async (n, i) => {
|
|
636
|
+
const g = new Headers(i?.headers);
|
|
637
|
+
if (g.get(this.HEADER_LOG_GUARD) === "true" || g.get(this.HEADER_PRINT_GUARD) === "true" || g.get(this.HEADER_EXCEPTION_GUARD) === "true") return s(n, i);
|
|
917
638
|
this.captureFirstUserLines(e);
|
|
918
639
|
const r = Date.now();
|
|
919
|
-
let
|
|
920
|
-
typeof
|
|
640
|
+
let c;
|
|
641
|
+
typeof n == "string" || n instanceof URL ? c = n.toString() : n instanceof Request ? (c = n.url, n.headers.forEach((u, m) => {
|
|
921
642
|
g.set(m, u);
|
|
922
|
-
})) :
|
|
923
|
-
const
|
|
924
|
-
let
|
|
643
|
+
})) : d().sfDebug && console.error("[Sailfish RequestInterceptor] Invalid fetch input."), d().sfDebug && console.log("[RequestInterceptor] Fetching request to:", c);
|
|
644
|
+
const a = new URL(c).hostname, l = new Headers(g), I = this.addTracingHeaders(g, c), p = { ...i, headers: g };
|
|
645
|
+
let C;
|
|
925
646
|
try {
|
|
926
647
|
let u = !1;
|
|
927
|
-
this.addTracingHeaders(
|
|
648
|
+
this.addTracingHeaders(l, c), C = await s(c, p), I && O.includes(C.status) ? (C = await s(c, { ...i, headers: l }), u = !0, this.captureFirstUserLines(e, 10, u)) : this.contextManager.addSupportedDomains(a);
|
|
928
649
|
const m = Date.now();
|
|
929
|
-
|
|
930
|
-
const { sessionId:
|
|
931
|
-
return t.doSend({ apiKey:
|
|
650
|
+
d().sfDebug && console.log(`[RequestInterceptor] Fetch completed: ${c}, Status: ${C.status}, Duration: ${m - r}ms`);
|
|
651
|
+
const { sessionId: h, pageVisitId: Z, requestId: b } = this.extractIdsFromTraceHeader(g);
|
|
652
|
+
return t.doSend({ apiKey: d().apiKey, requestId: b, pageVisitId: Z, recordingSessionId: h, serviceUuid: d().serviceUUID, timestampStart: r.toString(), timestampEnd: m.toString(), responseCode: C.status, success: !0, error: null, url: c, method: p.method || "GET", retryWithoutTraceId: u, parentSpanId: $() }), C;
|
|
932
653
|
} catch (u) {
|
|
933
654
|
const m = Date.now();
|
|
934
|
-
|
|
655
|
+
d().sfDebug && console.error(`[RequestInterceptor] Fetch failed: ${c}, Error: ${u}, Duration: ${m - r}ms`);
|
|
935
656
|
}
|
|
936
|
-
} :
|
|
657
|
+
} : d().sfDebug && console.error("[RequestInterceptor] Fetch not available.");
|
|
937
658
|
}
|
|
938
659
|
patchHttp(e, t) {
|
|
939
|
-
if (
|
|
940
|
-
const
|
|
941
|
-
|
|
660
|
+
if (d().sfDebug && console.log("[RequestInterceptor] Initializing HTTP/HTTPS request patch..."), !S || typeof S.request != "function") return void (d().sfDebug && console.log("[RequestInterceptor] HTTP/HTTPS not available."));
|
|
661
|
+
const s = S.request.bind(S), n = S.request.bind(S);
|
|
662
|
+
S.request = function(i, g) {
|
|
942
663
|
let r;
|
|
943
664
|
try {
|
|
944
|
-
if (typeof
|
|
945
|
-
const
|
|
946
|
-
r = { protocol:
|
|
947
|
-
} else
|
|
665
|
+
if (typeof i == "string") {
|
|
666
|
+
const a = new URL(i);
|
|
667
|
+
r = { protocol: a.protocol || x, hostname: a.hostname, path: a.pathname + a.search, headers: {} };
|
|
668
|
+
} else i instanceof URL ? r = { protocol: i.protocol || x, hostname: i.hostname, path: i.pathname + i.search, headers: {} } : (r = { ...i }, r.protocol || (r.protocol = x));
|
|
948
669
|
if (r.headers) {
|
|
949
|
-
const
|
|
950
|
-
this.addTracingHeaders(r.headers,
|
|
951
|
-
} else
|
|
952
|
-
} catch (
|
|
953
|
-
throw
|
|
670
|
+
const a = `${r.protocol}//${r.hostname}`;
|
|
671
|
+
this.addTracingHeaders(r.headers, a), this.captureFirstUserLines(e);
|
|
672
|
+
} else d().sfDebug && console.warn("[RequestInterceptor] No headers found in HTTP request options. Skipping header addition.");
|
|
673
|
+
} catch (a) {
|
|
674
|
+
throw d().sfDebug && console.error("[RequestInterceptor] Error while processing HTTP request options:", a), a;
|
|
954
675
|
}
|
|
955
|
-
let
|
|
956
|
-
return
|
|
957
|
-
const
|
|
958
|
-
if (r.headers && this.shouldPropagateHeaders(new URL(
|
|
676
|
+
let c = !1;
|
|
677
|
+
return s(r, (a) => {
|
|
678
|
+
const l = `${r.protocol}//${r.hostname}`;
|
|
679
|
+
if (r.headers && this.shouldPropagateHeaders(new URL(l).hostname) && O.includes(a.statusCode || 0)) {
|
|
959
680
|
r.hostname;
|
|
960
681
|
const u = { ...r, headers: { ...r.headers } };
|
|
961
|
-
delete u.headers[this.HEADER_TRACING],
|
|
682
|
+
delete u.headers[this.HEADER_TRACING], s(u, g), c = !0, this.captureFirstUserLines(e, 10, c);
|
|
962
683
|
}
|
|
963
|
-
const { sessionId: I, pageVisitId:
|
|
964
|
-
t.doSend({ apiKey:
|
|
684
|
+
const { sessionId: I, pageVisitId: p, requestId: C } = this.extractIdsFromTraceHeader(r.headers);
|
|
685
|
+
t.doSend({ apiKey: d().apiKey, requestId: C, pageVisitId: p, recordingSessionId: I, serviceUuid: d().serviceUUID, timestampStart: Date.now().toString(), timestampEnd: Date.now().toString(), responseCode: a.statusCode || 0, success: !!a.statusCode && a.statusCode < 400, error: null, url: l, method: r.method || "GET", retryWithoutTraceId: c, parentSpanId: $() }), g?.(a);
|
|
965
686
|
});
|
|
966
|
-
},
|
|
687
|
+
}, S.request = function(i, g) {
|
|
967
688
|
let r;
|
|
968
689
|
try {
|
|
969
|
-
if (typeof
|
|
970
|
-
const
|
|
971
|
-
r = { protocol:
|
|
972
|
-
} else
|
|
690
|
+
if (typeof i == "string") {
|
|
691
|
+
const a = new URL(i);
|
|
692
|
+
r = { protocol: a.protocol || P, hostname: a.hostname, path: a.pathname + a.search, headers: {} };
|
|
693
|
+
} else i instanceof URL ? r = { protocol: i.protocol || P, hostname: i.hostname, path: i.pathname + i.search, headers: {} } : (r = { ...i }, r.protocol || (r.protocol = P));
|
|
973
694
|
if (r.headers) {
|
|
974
|
-
const
|
|
975
|
-
this.addTracingHeaders(r.headers,
|
|
976
|
-
} else
|
|
977
|
-
} catch (
|
|
978
|
-
throw
|
|
695
|
+
const a = `${r.protocol}//${r.hostname}`;
|
|
696
|
+
this.addTracingHeaders(r.headers, a);
|
|
697
|
+
} else d().sfDebug && console.warn("[RequestInterceptor] No headers found in HTTPS request options. Skipping header addition.");
|
|
698
|
+
} catch (a) {
|
|
699
|
+
throw d().sfDebug && console.error("[RequestInterceptor] Error while processing HTTPS request options:", a), a;
|
|
979
700
|
}
|
|
980
|
-
let
|
|
981
|
-
return
|
|
982
|
-
const
|
|
983
|
-
if (r.headers && this.shouldPropagateHeaders(new URL(
|
|
701
|
+
let c = !1;
|
|
702
|
+
return n(r, (a) => {
|
|
703
|
+
const l = `${r.protocol}//${r.hostname}`;
|
|
704
|
+
if (r.headers && this.shouldPropagateHeaders(new URL(l).hostname) && O.includes(a.statusCode || 0)) {
|
|
984
705
|
const u = { ...r, headers: { ...r.headers } };
|
|
985
|
-
delete u.headers[this.HEADER_TRACING],
|
|
706
|
+
delete u.headers[this.HEADER_TRACING], n(u, g), c = !0, this.captureFirstUserLines(e, 10, c);
|
|
986
707
|
}
|
|
987
|
-
const { sessionId: I, pageVisitId:
|
|
988
|
-
t.doSend({ apiKey:
|
|
708
|
+
const { sessionId: I, pageVisitId: p, requestId: C } = this.extractIdsFromTraceHeader(r.headers);
|
|
709
|
+
t.doSend({ apiKey: d().apiKey, requestId: C, pageVisitId: p, recordingSessionId: I, serviceUuid: d().serviceUUID, timestampStart: Date.now().toString(), timestampEnd: Date.now().toString(), responseCode: a.statusCode || 0, success: !!a.statusCode && a.statusCode < 400, error: null, url: l, method: r.method || "GET", retryWithoutTraceId: c, parentSpanId: $() }), g?.(a);
|
|
989
710
|
});
|
|
990
|
-
},
|
|
711
|
+
}, d().sfDebug && console.log("✅ HTTP and HTTPS request methods patched globally.");
|
|
991
712
|
}
|
|
992
713
|
tryPatch(e, t) {
|
|
993
714
|
try {
|
|
994
715
|
require.resolve(t), e(), console.log(`[RequestInterceptor] Patched ${t}`);
|
|
995
|
-
} catch (
|
|
996
|
-
console.warn(`[RequestInterceptor] Could not patch ${t}: ${
|
|
716
|
+
} catch (s) {
|
|
717
|
+
console.warn(`[RequestInterceptor] Could not patch ${t}: ${s.message}`);
|
|
997
718
|
}
|
|
998
719
|
}
|
|
999
720
|
getExcludedDomains() {
|
|
1000
721
|
return [...this.contextManager.getExcludedDomains()];
|
|
1001
722
|
}
|
|
1002
723
|
}
|
|
1003
|
-
class
|
|
724
|
+
class Ee extends Q {
|
|
1004
725
|
constructor() {
|
|
1005
726
|
super(), this.setOperationName("UpdateServiceDetails");
|
|
1006
727
|
}
|
|
@@ -1028,293 +749,334 @@ class ze extends oe {
|
|
|
1028
749
|
gitSha: $gitSha,
|
|
1029
750
|
)
|
|
1030
751
|
}
|
|
1031
|
-
`, t = this.getVariables({ serviceIdentifier:
|
|
1032
|
-
|
|
752
|
+
`, t = this.getVariables({ serviceIdentifier: d().serviceIdentifier, serviceVersion: d().serviceVersion, serviceAdditionalMetadata: d().serviceAdditionalMetadata, gitSha: d().gitSha || "" });
|
|
753
|
+
W(this.endpoint, this.operationName, e, t);
|
|
1033
754
|
}
|
|
1034
755
|
}
|
|
1035
|
-
class
|
|
756
|
+
class Le {
|
|
1036
757
|
constructor(e = [process.cwd()], t = !1) {
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
758
|
+
A(this, "rootPaths");
|
|
759
|
+
A(this, "fileConfigs", /* @__PURE__ */ new Map());
|
|
760
|
+
A(this, "functionConfigs", /* @__PURE__ */ new Map());
|
|
761
|
+
A(this, "directoryConfigs", /* @__PURE__ */ new Map());
|
|
762
|
+
A(this, "hasSailfishFiles", !1);
|
|
763
|
+
A(this, "debug");
|
|
1043
764
|
this.rootPaths = e, this.debug = t || process.env.SF_DEBUG === "true";
|
|
1044
765
|
}
|
|
1045
766
|
async loadAllConfigs() {
|
|
1046
767
|
this.debug && console.log("[FuncSpan ConfigLoader] Scanning for .sailfish files in:", this.rootPaths);
|
|
1047
768
|
const e = [];
|
|
1048
|
-
for (const t of this.rootPaths)
|
|
769
|
+
for (const t of this.rootPaths) L.existsSync(t) ? await this._walkDirectory(t, e) : this.debug && console.log(`[FuncSpan ConfigLoader] Root path does not exist: ${t}`);
|
|
1049
770
|
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
771
|
for (const t of e) await this._loadConfigFile(t);
|
|
1051
772
|
await this._resolveInheritance(), this.debug && console.log(`[FuncSpan ConfigLoader] Loaded ${this.fileConfigs.size} file configs, ${this.functionConfigs.size} function configs`);
|
|
1052
773
|
}
|
|
1053
774
|
getConfig(e, t) {
|
|
1054
|
-
const
|
|
775
|
+
const s = this.hasSailfishFiles ? ue() : Se(), n = this._getDirectoryConfig(e), i = G.normalize(e), g = this.fileConfigs.get(i) || {};
|
|
1055
776
|
let r = {};
|
|
1056
777
|
if (t) {
|
|
1057
|
-
const
|
|
1058
|
-
|
|
778
|
+
const c = this.functionConfigs.get(i);
|
|
779
|
+
c && (r = c.get(t) || {});
|
|
1059
780
|
}
|
|
1060
|
-
return
|
|
781
|
+
return R(s, n, g, r);
|
|
1061
782
|
}
|
|
1062
783
|
async _walkDirectory(e, t) {
|
|
1063
784
|
try {
|
|
1064
|
-
const
|
|
1065
|
-
for (const
|
|
1066
|
-
const
|
|
1067
|
-
|
|
785
|
+
const s = L.readdirSync(e, { withFileTypes: !0 });
|
|
786
|
+
for (const n of s) {
|
|
787
|
+
const i = G.join(e, n.name);
|
|
788
|
+
n.isFile() && n.name === ".sailfish" ? t.push(i) : n.name === "node_modules" || n.isDirectory() && n.name.startsWith(".") && n.name !== ".sailfish" || n.isDirectory() && await this._walkDirectory(i, t);
|
|
1068
789
|
}
|
|
1069
|
-
} catch (
|
|
1070
|
-
this.debug && console.error(`[FuncSpan ConfigLoader] Error walking directory ${e}:`,
|
|
790
|
+
} catch (s) {
|
|
791
|
+
this.debug && console.error(`[FuncSpan ConfigLoader] Error walking directory ${e}:`, s);
|
|
1071
792
|
}
|
|
1072
793
|
}
|
|
1073
794
|
async _loadConfigFile(e) {
|
|
1074
795
|
try {
|
|
1075
|
-
const t =
|
|
1076
|
-
let
|
|
796
|
+
const t = L.readFileSync(e, "utf-8"), s = G.dirname(e);
|
|
797
|
+
let n = null;
|
|
1077
798
|
try {
|
|
1078
|
-
|
|
799
|
+
n = JSON.parse(t);
|
|
1079
800
|
} catch {
|
|
1080
801
|
try {
|
|
1081
|
-
|
|
1082
|
-
} catch (
|
|
1083
|
-
return void (this.debug && console.error(`[FuncSpan ConfigLoader] Failed to parse ${e} as JSON or YAML:`,
|
|
802
|
+
n = require("js-yaml").load(t);
|
|
803
|
+
} catch (i) {
|
|
804
|
+
return void (this.debug && console.error(`[FuncSpan ConfigLoader] Failed to parse ${e} as JSON or YAML:`, i));
|
|
1084
805
|
}
|
|
1085
806
|
}
|
|
1086
|
-
if (!
|
|
1087
|
-
|
|
807
|
+
if (!n) return;
|
|
808
|
+
n.default && this.directoryConfigs.set(s, n.default), n.files && await this._expandFileGlobs(s, n.files, n.default || {}), n.functions && this._storeFunctionConfigs(s, n.functions, n.default || {}), this.debug && (console.log(`[FuncSpan ConfigLoader] Loaded config from ${e}`), console.log(`[FuncSpan ConfigLoader] Directory: ${s}`), console.log(`[FuncSpan ConfigLoader] Has default: ${!!n.default}`), console.log(`[FuncSpan ConfigLoader] File patterns: ${Object.keys(n.files || {}).length}`), console.log(`[FuncSpan ConfigLoader] Functions: ${Object.keys(n.functions || {}).length}`));
|
|
1088
809
|
} catch (t) {
|
|
1089
810
|
this.debug && console.error(`[FuncSpan ConfigLoader] Error loading ${e}:`, t);
|
|
1090
811
|
}
|
|
1091
812
|
}
|
|
1092
|
-
async _expandFileGlobs(e, t,
|
|
1093
|
-
for (const [
|
|
1094
|
-
const g =
|
|
1095
|
-
this.debug && console.log(`[FuncSpan ConfigLoader] Pattern '${
|
|
1096
|
-
for (const
|
|
1097
|
-
const
|
|
1098
|
-
this.fileConfigs.set(
|
|
813
|
+
async _expandFileGlobs(e, t, s) {
|
|
814
|
+
for (const [n, i] of Object.entries(t)) try {
|
|
815
|
+
const g = G.join(e, n), r = await Ve(g, { absolute: !0, nodir: !0, ignore: ["**/node_modules/**", "**/.git/**"] });
|
|
816
|
+
this.debug && console.log(`[FuncSpan ConfigLoader] Pattern '${n}' matched ${r.length} files`);
|
|
817
|
+
for (const c of r) {
|
|
818
|
+
const a = G.normalize(c), l = R(s, i);
|
|
819
|
+
this.fileConfigs.set(a, l), this.debug && r.length <= 5 && console.log(`[FuncSpan ConfigLoader] - ${c}`);
|
|
1099
820
|
}
|
|
1100
821
|
} catch (g) {
|
|
1101
|
-
this.debug && console.error(`[FuncSpan ConfigLoader] Error expanding glob '${
|
|
822
|
+
this.debug && console.error(`[FuncSpan ConfigLoader] Error expanding glob '${n}':`, g);
|
|
1102
823
|
}
|
|
1103
824
|
}
|
|
1104
|
-
_storeFunctionConfigs(e, t,
|
|
1105
|
-
for (const [
|
|
1106
|
-
const g =
|
|
825
|
+
_storeFunctionConfigs(e, t, s) {
|
|
826
|
+
for (const [n, i] of Object.entries(t)) {
|
|
827
|
+
const g = n.split("::");
|
|
1107
828
|
if (g.length !== 2) {
|
|
1108
|
-
this.debug && console.warn(`[FuncSpan ConfigLoader] Invalid function pattern '${
|
|
829
|
+
this.debug && console.warn(`[FuncSpan ConfigLoader] Invalid function pattern '${n}' (expected format: 'file.ts::functionName')`);
|
|
1109
830
|
continue;
|
|
1110
831
|
}
|
|
1111
|
-
const [r,
|
|
1112
|
-
this.functionConfigs.has(
|
|
1113
|
-
const
|
|
1114
|
-
|
|
832
|
+
const [r, c] = g, a = G.normalize(G.join(e, r));
|
|
833
|
+
this.functionConfigs.has(a) || this.functionConfigs.set(a, /* @__PURE__ */ new Map());
|
|
834
|
+
const l = this.functionConfigs.get(a), I = R(s, i);
|
|
835
|
+
l.set(c, I), this.debug && console.log(`[FuncSpan ConfigLoader] Function config: ${a}::${c}`);
|
|
1115
836
|
}
|
|
1116
837
|
}
|
|
1117
838
|
async _resolveInheritance() {
|
|
1118
839
|
}
|
|
1119
840
|
_getDirectoryConfig(e) {
|
|
1120
|
-
let t =
|
|
1121
|
-
const
|
|
1122
|
-
for (; t && t !==
|
|
1123
|
-
const
|
|
1124
|
-
|
|
841
|
+
let t = G.dirname(G.normalize(e));
|
|
842
|
+
const s = [];
|
|
843
|
+
for (; t && t !== G.dirname(t); ) {
|
|
844
|
+
const n = this.directoryConfigs.get(t);
|
|
845
|
+
n && s.unshift(n), t = G.dirname(t);
|
|
1125
846
|
}
|
|
1126
|
-
return
|
|
847
|
+
return s.reduce((n, i) => R(n, i), {});
|
|
1127
848
|
}
|
|
1128
849
|
}
|
|
1129
|
-
let
|
|
1130
|
-
async function
|
|
1131
|
-
|
|
850
|
+
let H = null;
|
|
851
|
+
async function De(o, e) {
|
|
852
|
+
H = new Le(o, e), await H.loadAllConfigs();
|
|
1132
853
|
}
|
|
1133
|
-
function
|
|
1134
|
-
return
|
|
854
|
+
function xe(o, e) {
|
|
855
|
+
return H ? H.getConfig(o, e) : (process.env.SF_DEBUG === "true" && console.log("[FuncSpan ConfigLoader] Config loader not initialized, using env config for worker process"), ue());
|
|
1135
856
|
}
|
|
1136
857
|
function Pe() {
|
|
1137
|
-
return
|
|
858
|
+
return H !== null;
|
|
859
|
+
}
|
|
860
|
+
const Oe = ["readFile", "writeFile", "appendFile", "readdir", "stat", "lstat", "fstat", "access", "open", "close", "read", "write", "chmod", "mkdir", "rmdir", "unlink", "rename"], ie = ["lookup", "resolve", "resolve4", "resolve6", "resolveAny", "resolveMx", "resolveNs", "resolveTxt", "reverse"], je = ["pbkdf2", "randomBytes", "scrypt", "generateKeyPair"], Me = ["gzip", "gunzip", "deflate", "inflate", "deflateRaw", "inflateRaw", "brotliCompress", "brotliDecompress"];
|
|
861
|
+
let re = !1, ae = !1;
|
|
862
|
+
function Qe() {
|
|
863
|
+
if (!ae) try {
|
|
864
|
+
const o = require("node:dns");
|
|
865
|
+
if (o.__sf_worker_pool_patched__) return;
|
|
866
|
+
Object.defineProperty(o, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
867
|
+
for (const e of ie) if (typeof o[e] == "function") {
|
|
868
|
+
const t = o[e];
|
|
869
|
+
o[e] = function(...s) {
|
|
870
|
+
const n = s[0];
|
|
871
|
+
return typeof n == "string" && (n === "localhost" || n === "127.0.0.1") ? t.apply(this, s) : typeof s[s.length - 1] == "function" ? _("dns", e, t, s, this) : t.apply(this, s);
|
|
872
|
+
}, Object.defineProperty(o[e], "name", { value: e, writable: !1 });
|
|
873
|
+
}
|
|
874
|
+
(function(e) {
|
|
875
|
+
if (!e.promises) return void (process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns.promises not available, skipping"));
|
|
876
|
+
if (!e.promises.__sf_worker_pool_patched__) {
|
|
877
|
+
Object.defineProperty(e.promises, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
878
|
+
for (const t of ie) if (typeof e.promises[t] == "function") {
|
|
879
|
+
const s = e.promises[t];
|
|
880
|
+
e.promises[t] = function(...n) {
|
|
881
|
+
const i = n[0];
|
|
882
|
+
return typeof i != "string" || i !== "localhost" && i !== "127.0.0.1" ? Be("dns", t, s, n, this) : s.apply(this, n);
|
|
883
|
+
}, Object.defineProperty(e.promises[t], "name", { value: t, writable: !1 });
|
|
884
|
+
}
|
|
885
|
+
process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns.promises module patched successfully");
|
|
886
|
+
}
|
|
887
|
+
})(o), ae = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns module patched successfully");
|
|
888
|
+
} catch (o) {
|
|
889
|
+
console.error("[WorkerPool] Error patching dns module:", o);
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
let ce = !1, ge = !1, M = !1;
|
|
893
|
+
function qe() {
|
|
894
|
+
if (M) return;
|
|
895
|
+
const o = process.env.SF_DEBUG === "true";
|
|
896
|
+
o && console.log("[WorkerPool] Initializing worker pool patching..."), X("fs") && (o && console.log("[WorkerPool] Patching fs module..."), (function() {
|
|
897
|
+
if (!re) try {
|
|
898
|
+
const e = require("node:fs");
|
|
899
|
+
if (e.__sf_worker_pool_patched__) return;
|
|
900
|
+
Object.defineProperty(e, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
901
|
+
for (const t of Oe) if (typeof e[t] == "function") {
|
|
902
|
+
const s = e[t];
|
|
903
|
+
e[t] = function(...n) {
|
|
904
|
+
return typeof n[n.length - 1] == "function" ? _("fs", t, s, n, this) : s.apply(this, n);
|
|
905
|
+
}, Object.defineProperty(e[t], "name", { value: t, writable: !1 });
|
|
906
|
+
}
|
|
907
|
+
re = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] fs module patched successfully");
|
|
908
|
+
} catch (e) {
|
|
909
|
+
console.error("[WorkerPool] Error patching fs module:", e);
|
|
910
|
+
}
|
|
911
|
+
})()), X("dns") && (o && console.log("[WorkerPool] Patching dns module..."), Qe()), X("crypto") && (o && console.log("[WorkerPool] Patching crypto module..."), (function() {
|
|
912
|
+
if (!ce) try {
|
|
913
|
+
const e = require("node:crypto");
|
|
914
|
+
if (e.__sf_worker_pool_patched__) return;
|
|
915
|
+
Object.defineProperty(e, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
916
|
+
for (const t of je) if (typeof e[t] == "function") {
|
|
917
|
+
const s = e[t];
|
|
918
|
+
e[t] = function(...n) {
|
|
919
|
+
return typeof n[n.length - 1] == "function" ? _("crypto", t, s, n, this) : s.apply(this, n);
|
|
920
|
+
}, Object.defineProperty(e[t], "name", { value: t, writable: !1 });
|
|
921
|
+
}
|
|
922
|
+
ce = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] crypto module patched successfully");
|
|
923
|
+
} catch (e) {
|
|
924
|
+
console.error("[WorkerPool] Error patching crypto module:", e);
|
|
925
|
+
}
|
|
926
|
+
})()), X("zlib") && (o && console.log("[WorkerPool] Patching zlib module..."), (function() {
|
|
927
|
+
if (!ge) try {
|
|
928
|
+
const e = require("node:zlib");
|
|
929
|
+
if (e.__sf_worker_pool_patched__) return;
|
|
930
|
+
Object.defineProperty(e, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
931
|
+
for (const t of Me) if (typeof e[t] == "function") {
|
|
932
|
+
const s = e[t];
|
|
933
|
+
e[t] = function(...n) {
|
|
934
|
+
return typeof n[n.length - 1] == "function" ? _("zlib", t, s, n, this) : s.apply(this, n);
|
|
935
|
+
}, Object.defineProperty(e[t], "name", { value: t, writable: !1 });
|
|
936
|
+
}
|
|
937
|
+
ge = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] zlib module patched successfully");
|
|
938
|
+
} catch (e) {
|
|
939
|
+
console.error("[WorkerPool] Error patching zlib module:", e);
|
|
940
|
+
}
|
|
941
|
+
})()), M = !0, o && console.log("[WorkerPool] Worker pool patching initialized");
|
|
1138
942
|
}
|
|
1139
|
-
function
|
|
943
|
+
function et() {
|
|
944
|
+
return M;
|
|
945
|
+
}
|
|
946
|
+
function ct(o) {
|
|
1140
947
|
if (!o || !o.apiKey) {
|
|
1141
|
-
const
|
|
1142
|
-
console.error(
|
|
948
|
+
const n = `The required API Key is not provided: ${JSON.stringify(o)}`;
|
|
949
|
+
console.error(n);
|
|
1143
950
|
}
|
|
1144
|
-
const { config: e } =
|
|
951
|
+
const { config: e } = We(o);
|
|
1145
952
|
if (e.sfDebug && console.log("Updated configuration after applying options:", e), !e.apiKey || !e.apiGraphqlEndpoint) {
|
|
1146
|
-
const
|
|
1147
|
-
throw console.error(
|
|
1148
|
-
}
|
|
1149
|
-
Pe() ||
|
|
1150
|
-
e.sfDebug && console.error("[FuncSpan] Failed to initialize config loader:",
|
|
1151
|
-
});
|
|
1152
|
-
const t = new
|
|
1153
|
-
t.setServiceUUID(e.serviceUUID), (function(
|
|
1154
|
-
function
|
|
1155
|
-
|
|
953
|
+
const n = `The required config is not provided: ${JSON.stringify(e)}`;
|
|
954
|
+
throw console.error(n), new Error(n);
|
|
955
|
+
}
|
|
956
|
+
Pe() || De(void 0, e.sfDebug).catch((n) => {
|
|
957
|
+
e.sfDebug && console.error("[FuncSpan] Failed to initialize config loader:", n);
|
|
958
|
+
}), et() || (qe(), e.sfDebug && console.log("[setupInterceptors] Worker pool patching initialized (DNS tracking enabled)"));
|
|
959
|
+
const t = new Q();
|
|
960
|
+
t.setServiceUUID(e.serviceUUID), (function(n) {
|
|
961
|
+
function i(I, p) {
|
|
962
|
+
n.setOperationName("CollectLogs"), n.doSend([p, I]);
|
|
1156
963
|
}
|
|
1157
|
-
const g = console.log.bind(console), r = console.error.bind(console),
|
|
964
|
+
const g = console.log.bind(console), r = console.error.bind(console), c = console.warn.bind(console), a = console.info.bind(console), l = console.debug.bind(console);
|
|
1158
965
|
console.log = (...I) => {
|
|
1159
|
-
|
|
966
|
+
i("INFO", I.join(" ")), g(...I);
|
|
1160
967
|
}, console.error = (...I) => {
|
|
1161
|
-
|
|
968
|
+
i("ERROR", I.join(" ")), r(...I);
|
|
1162
969
|
}, console.warn = (...I) => {
|
|
1163
|
-
|
|
970
|
+
i("WARN", I.join(" ")), c(...I);
|
|
1164
971
|
}, console.info = (...I) => {
|
|
1165
|
-
|
|
1166
|
-
},
|
|
1167
|
-
|
|
972
|
+
i("INFO", I.join(" ")), a(...I);
|
|
973
|
+
}, d().logLevel === "DEBUG" && (console.debug = (...I) => {
|
|
974
|
+
i("DEBUG", I.join(" ")), l(...I);
|
|
1168
975
|
});
|
|
1169
|
-
})(t), (function(
|
|
1170
|
-
const
|
|
1171
|
-
new
|
|
1172
|
-
const g = new
|
|
1173
|
-
|
|
976
|
+
})(t), (function(n = []) {
|
|
977
|
+
const i = new $e(n);
|
|
978
|
+
new ke().doSend(i.getExcludedDomains());
|
|
979
|
+
const g = new Ue(), r = new Te();
|
|
980
|
+
i.patchFetch(g, r), i.patchHttp(g, r);
|
|
1174
981
|
})(e.domainsToNotPropagateHeadersTo);
|
|
1175
|
-
const
|
|
1176
|
-
|
|
1177
|
-
}
|
|
1178
|
-
function rt(o, e, t, n = !1) {
|
|
1179
|
-
const i = l();
|
|
1180
|
-
new be(i.apiKey).identify(o, e, t, n);
|
|
982
|
+
const s = new Ke();
|
|
983
|
+
s.setServiceUUID(e.serviceUUID), Re(s), ze(), new Ee().send();
|
|
1181
984
|
}
|
|
1182
|
-
function
|
|
1183
|
-
const
|
|
1184
|
-
new
|
|
985
|
+
function gt(o, e, t, s = !1) {
|
|
986
|
+
const n = d();
|
|
987
|
+
new he(n.apiKey).identify(o, e, t, s);
|
|
1185
988
|
}
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
}
|
|
1190
|
-
send(e) {
|
|
1191
|
-
const t = l().sfDebug;
|
|
1192
|
-
t && console.log(`[FunctionSpanTransmitter] Preparing to send ${e.length} function span(s)`);
|
|
1193
|
-
for (const n of e) try {
|
|
1194
|
-
let i;
|
|
1195
|
-
if (n.result !== void 0 && n.result !== null) {
|
|
1196
|
-
const g = typeof n.result;
|
|
1197
|
-
i = JSON.stringify({ type: g, has_value: !0, value: n.result });
|
|
1198
|
-
} else i = n.result === null ? JSON.stringify({ type: "null", has_value: !0, value: null }) : JSON.stringify({ type: "undefined", has_value: !1, value: null });
|
|
1199
|
-
const s = this.getVariables({ library: "JS/TS BACKEND", version: l().version, spanId: n.spanId, parentSpanId: n.parentSpanId, filePath: n.filePath, lineNumber: n.metadata.line, columnNumber: n.metadata.column, functionName: n.functionName, arguments: JSON.stringify(n.args || {}), returnValue: i, startTimeNs: (1e6 * Date.now() - 1e6 * n.duration).toString(), durationNs: (1e6 * n.duration).toString() });
|
|
1200
|
-
t && (console.log(`[FunctionSpanTransmitter] Sending GraphQL mutation to ${this.endpoint}`), console.log("[FunctionSpanTransmitter] Variables:", JSON.stringify(s, null, 2))), F(this.endpoint, this.operationName, this.getQuery(), s), t && console.log(`[FunctionSpanTransmitter] Queued function span for ${n.functionName}`);
|
|
1201
|
-
} catch (i) {
|
|
1202
|
-
console.error(`[FunctionSpanTransmitter] Error preparing function span for ${n.functionName}:`, i);
|
|
1203
|
-
}
|
|
1204
|
-
}
|
|
1205
|
-
getQuery() {
|
|
1206
|
-
return `
|
|
1207
|
-
${this.queryType} ${this.operationName}(
|
|
1208
|
-
$apiKey: String!,
|
|
1209
|
-
$serviceUuid: String!,
|
|
1210
|
-
$sessionId: String!,
|
|
1211
|
-
$timestampMs: String!,
|
|
1212
|
-
$parentSpanId: String,
|
|
1213
|
-
$library: String!,
|
|
1214
|
-
$version: String!,
|
|
1215
|
-
$spanId: String!,
|
|
1216
|
-
$filePath: String!,
|
|
1217
|
-
$lineNumber: Int!,
|
|
1218
|
-
$columnNumber: Int!,
|
|
1219
|
-
$functionName: String!,
|
|
1220
|
-
$arguments: String!,
|
|
1221
|
-
$returnValue: String,
|
|
1222
|
-
$startTimeNs: String!,
|
|
1223
|
-
$durationNs: String!
|
|
1224
|
-
) {
|
|
1225
|
-
${this.queryName}(
|
|
1226
|
-
apiKey: $apiKey,
|
|
1227
|
-
serviceUuid: $serviceUuid,
|
|
1228
|
-
sessionId: $sessionId,
|
|
1229
|
-
timestampMs: $timestampMs,
|
|
1230
|
-
parentSpanId: $parentSpanId,
|
|
1231
|
-
library: $library,
|
|
1232
|
-
version: $version,
|
|
1233
|
-
spanId: $spanId,
|
|
1234
|
-
filePath: $filePath,
|
|
1235
|
-
lineNumber: $lineNumber,
|
|
1236
|
-
columnNumber: $columnNumber,
|
|
1237
|
-
functionName: $functionName,
|
|
1238
|
-
arguments: $arguments,
|
|
1239
|
-
returnValue: $returnValue,
|
|
1240
|
-
startTimeNs: $startTimeNs,
|
|
1241
|
-
durationNs: $durationNs
|
|
1242
|
-
)
|
|
1243
|
-
}
|
|
1244
|
-
`;
|
|
1245
|
-
}
|
|
989
|
+
function lt(o, e = {}, t, s = !1) {
|
|
990
|
+
const n = d();
|
|
991
|
+
new he(n.apiKey).addOrUpdateMetadata(o, e, t, s);
|
|
1246
992
|
}
|
|
1247
|
-
let
|
|
1248
|
-
function
|
|
1249
|
-
const
|
|
1250
|
-
const g =
|
|
993
|
+
let j = null;
|
|
994
|
+
function dt(o, e, t, s) {
|
|
995
|
+
const n = function(...i) {
|
|
996
|
+
const g = Ce(), r = g?.sfDebug || !1;
|
|
1251
997
|
r && console.log(`[FuncSpan] captureFunctionSpan wrapper called for ${t}::${e}`);
|
|
1252
|
-
const
|
|
1253
|
-
const
|
|
1254
|
-
if (
|
|
1255
|
-
const
|
|
1256
|
-
if (
|
|
998
|
+
const c = (function(m, h) {
|
|
999
|
+
const Z = le();
|
|
1000
|
+
if (Z) {
|
|
1001
|
+
const b = de(Z);
|
|
1002
|
+
if (b) return process.env.SF_DEBUG === "true" && console.log(`[FuncSpan] Using HTTP header override for ${m}::${h}`), b;
|
|
1003
|
+
}
|
|
1004
|
+
try {
|
|
1005
|
+
return xe(m, h);
|
|
1006
|
+
} catch {
|
|
1007
|
+
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
1008
|
}
|
|
1258
|
-
return Oe(u, m);
|
|
1259
1009
|
})(t, e);
|
|
1260
|
-
if (r && console.log(`[FuncSpan] Config for ${t}::${e}:`,
|
|
1261
|
-
if (
|
|
1010
|
+
if (r && console.log(`[FuncSpan] Config for ${t}::${e}:`, c), c.enable_sampling && c.sample_rate < 1 && Math.random() > c.sample_rate) return r && console.log(`[FuncSpan] Skipping ${e} due to sampling`), o.apply(this, i);
|
|
1011
|
+
if (c.sample_rate === 0) return r && console.log(`[FuncSpan] Skipping ${e} - sample_rate is 0.0`), o.apply(this, i);
|
|
1262
1012
|
r && console.log(`[FuncSpan] Capturing function span for ${e}`);
|
|
1263
|
-
const
|
|
1264
|
-
|
|
1265
|
-
const
|
|
1266
|
-
let
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
}),
|
|
1013
|
+
const a = N.getInstance(), l = a.getCurrentFunctionSpanId(), I = Ie();
|
|
1014
|
+
a.setCurrentFunctionSpanId(I);
|
|
1015
|
+
const p = process.hrtime.bigint(), C = Date.now();
|
|
1016
|
+
let u = null;
|
|
1017
|
+
c.capture_arguments && (u = {}, s.paramNames.forEach((m, h) => {
|
|
1018
|
+
h < i.length && (u[m] = i[h]);
|
|
1019
|
+
}), u && c.arg_limit_mb > 0 && (u = E(u, c.arg_limit_mb)));
|
|
1270
1020
|
try {
|
|
1271
|
-
const
|
|
1272
|
-
if (
|
|
1273
|
-
const
|
|
1274
|
-
let
|
|
1275
|
-
return
|
|
1276
|
-
}, (
|
|
1277
|
-
const
|
|
1278
|
-
throw
|
|
1021
|
+
const m = o.apply(this, i);
|
|
1022
|
+
if (m && typeof m.then == "function") return l ? a.setCurrentFunctionSpanId(l) : a.clearCurrentFunctionSpanId(), m.then((f) => {
|
|
1023
|
+
const v = process.hrtime.bigint(), U = Date.now(), T = Number(v - p);
|
|
1024
|
+
let q = null;
|
|
1025
|
+
return c.capture_return_value && c.return_limit_mb > 0 && (q = E(f, c.return_limit_mb)), K({ functionName: e, filePath: t, metadata: s, args: u, result: q, error: null, duration: U - C, durationNs: T, startTimeNs: p.toString(), async: !0, spanId: I, parentSpanId: l, pid: process.pid, threadId: J }), f;
|
|
1026
|
+
}, (f) => {
|
|
1027
|
+
const v = process.hrtime.bigint(), U = Date.now(), T = Number(v - p);
|
|
1028
|
+
throw K({ functionName: e, filePath: t, metadata: s, args: u, result: null, error: f?.message || String(f), duration: U - C, durationNs: T, startTimeNs: p.toString(), async: !0, spanId: I, parentSpanId: l, pid: process.pid, threadId: J }), f;
|
|
1279
1029
|
});
|
|
1280
|
-
const
|
|
1281
|
-
let
|
|
1282
|
-
return
|
|
1283
|
-
} catch (
|
|
1284
|
-
const
|
|
1285
|
-
throw
|
|
1030
|
+
const h = process.hrtime.bigint(), Z = Date.now(), b = Number(h - p);
|
|
1031
|
+
let y = null;
|
|
1032
|
+
return c.capture_return_value && c.return_limit_mb > 0 && (y = E(m, c.return_limit_mb)), K({ functionName: e, filePath: t, metadata: s, args: u, result: y, error: null, duration: Z - C, durationNs: b, startTimeNs: p.toString(), async: !1, spanId: I, parentSpanId: l, pid: process.pid, threadId: J }), l ? a.setCurrentFunctionSpanId(l) : a.clearCurrentFunctionSpanId(), m;
|
|
1033
|
+
} catch (m) {
|
|
1034
|
+
const h = process.hrtime.bigint(), Z = Date.now(), b = Number(h - p);
|
|
1035
|
+
throw K({ functionName: e, filePath: t, metadata: s, args: u, result: null, error: m?.message || String(m), duration: Z - C, durationNs: b, startTimeNs: p.toString(), async: !1, spanId: I, parentSpanId: l, pid: process.pid, threadId: J }), l ? a.setCurrentFunctionSpanId(l) : a.clearCurrentFunctionSpanId(), m;
|
|
1286
1036
|
}
|
|
1287
1037
|
};
|
|
1288
|
-
Object.defineProperty(
|
|
1289
|
-
for (const
|
|
1290
|
-
return
|
|
1038
|
+
Object.defineProperty(n, "name", { value: e, writable: !1 });
|
|
1039
|
+
for (const i in o) o.hasOwnProperty(i) && (n[i] = o[i]);
|
|
1040
|
+
return n;
|
|
1291
1041
|
}
|
|
1292
|
-
function
|
|
1293
|
-
const e =
|
|
1042
|
+
function K(o) {
|
|
1043
|
+
const e = Ce(), t = e?.sfDebug || !1;
|
|
1294
1044
|
t && console.log("[FuncSpan] captureSpanData called for:", { function: o.functionName, file: o.filePath, duration: `${o.duration}ms`, async: o.async, error: o.error, spanId: o.spanId });
|
|
1295
|
-
const
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1045
|
+
const s = { functionName: o.functionName, filePath: o.filePath, metadata: o.metadata, args: o.args, result: o.result, error: o.error, duration: o.duration, durationNs: o.durationNs, async: o.async, spanId: o.spanId, parentSpanId: o.parentSpanId };
|
|
1046
|
+
process.env.SF_FUNCSPAN_CONSOLE_OUTPUT === "true" && console.log(`
|
|
1047
|
+
📊 Function Span:`, { function: `${o.functionName} (${o.filePath}:${o.metadata.line}:${o.metadata.column})`, duration: `${o.duration.toFixed(2)}ms`, arguments: o.args, result: o.error ? `Error: ${o.error}` : o.result, spanId: o.spanId, parentSpanId: o.parentSpanId || "none" });
|
|
1048
|
+
const n = process.env.SF_FUNCSPAN_JSONL_FILE;
|
|
1049
|
+
if (n) try {
|
|
1050
|
+
const i = n === "true" || n === "1" ? "funcspans.jsonl" : n, g = Date.now(), r = process.hrtime.bigint(), c = BigInt(o.startTimeNs), a = Number(r - c) / 1e6, l = new Date(g - a).toISOString(), I = JSON.stringify({ timestamp: l, functionName: o.functionName, filePath: o.filePath, line: o.metadata.line, column: o.metadata.column, duration: o.duration, durationNs: o.durationNs, startTimeNs: o.startTimeNs, arguments: o.args, returnValue: o.error ? { error: String(o.error) } : o.result, spanId: o.spanId, parentSpanId: o.parentSpanId, async: o.async, pid: o.pid, threadId: o.threadId }) + `
|
|
1051
|
+
`;
|
|
1052
|
+
Ne(i, I, "utf-8");
|
|
1053
|
+
} catch (i) {
|
|
1054
|
+
console.error("[FuncSpan] Error writing to JSONL file:", i);
|
|
1055
|
+
}
|
|
1056
|
+
if (t && console.log("[FuncSpan] Sending function span to transmitter:", s), process.env.SF_FUNCSPAN_SKIP_BACKEND !== "true") try {
|
|
1057
|
+
(j || (j = new ve()), j).send([s]), t && console.log("[FuncSpan] Function span sent successfully");
|
|
1299
1058
|
} catch (i) {
|
|
1300
|
-
console.error("[FuncSpan] Error sending function span:", i);
|
|
1059
|
+
t && console.error("[FuncSpan] Error sending function span:", i);
|
|
1301
1060
|
}
|
|
1302
1061
|
}
|
|
1303
1062
|
export {
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1063
|
+
N as ContextManager,
|
|
1064
|
+
lt as addOrUpdateMetadata,
|
|
1065
|
+
dt as captureFunctionSpan,
|
|
1066
|
+
Ze as clearFuncspanOverride,
|
|
1067
|
+
$ as getCurrentFunctionSpanId,
|
|
1068
|
+
Se as getDefaultConfig,
|
|
1069
|
+
ue as getEnvConfig,
|
|
1070
|
+
le as getFuncspanOverride,
|
|
1071
|
+
xe as getGlobalConfig,
|
|
1072
|
+
gt as identify,
|
|
1073
|
+
De as initializeConfigLoader,
|
|
1074
|
+
qe as initializeWorkerPoolPatching,
|
|
1315
1075
|
Pe as isConfigLoaderInitialized,
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1076
|
+
et as isWorkerPoolInitialized,
|
|
1077
|
+
de as parseHeaderOverride,
|
|
1078
|
+
Ct as runWithContext,
|
|
1079
|
+
ye as setFuncspanOverride,
|
|
1080
|
+
ct as setupInterceptors,
|
|
1081
|
+
mt as transformFunctionSpans
|
|
1320
1082
|
};
|