@sailfish-ai/sf-veritas 0.2.16 → 0.2.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/contextManager-C-sqFxpi.js +267 -0
- package/dist/contextManager-wMuxqwl9.cjs +1 -0
- package/dist/funcSpanTransformer-D0W2t41q.cjs +1 -0
- package/dist/funcSpanTransformer-S_WeAt_m.js +251 -0
- package/dist/plugins/funcspanEsbuildPlugin.cjs +1 -1
- package/dist/plugins/funcspanEsbuildPlugin.mjs +2 -2
- package/dist/plugins/funcspanRollupPlugin.cjs +1 -1
- package/dist/plugins/funcspanRollupPlugin.mjs +2 -2
- package/dist/plugins/funcspanTscPlugin.cjs +1 -1
- package/dist/plugins/funcspanTscPlugin.mjs +2 -2
- package/dist/plugins/funcspanVitePlugin.cjs +1 -1
- package/dist/plugins/funcspanVitePlugin.mjs +2 -2
- package/dist/plugins/funcspanWebpackLoader.cjs +1 -1
- package/dist/plugins/funcspanWebpackLoader.mjs +1 -1
- package/dist/plugins/funcspanWebpackPlugin.cjs +1 -1
- package/dist/plugins/funcspanWebpackPlugin.mjs +1 -1
- package/dist/runtimeConfig-B8LSswM8.cjs +9 -0
- package/dist/runtimeConfig-GwWjhV9M.js +379 -0
- package/dist/sf-veritas.cjs +13 -13
- package/dist/sf-veritas.mjs +277 -286
- package/dist/types/debuggerWorker.d.ts +2 -2
- package/dist/types/generated/worker-data.d.ts +1 -1
- package/dist/types/setupConfig.d.ts +5 -0
- package/dist/types/utils.d.ts +7 -0
- package/dist/worker-pool-capture.cjs +1 -1
- package/dist/worker-pool-capture.mjs +1 -1
- package/dist/{workerPoolSpanCapture-COwiNikM.cjs → workerPoolSpanCapture-B3yge78T.cjs} +2 -2
- package/dist/{workerPoolSpanCapture-d-8ExI18.js → workerPoolSpanCapture-DqBbNQLv.js} +26 -22
- package/package.json +9 -2
- package/dist/contextManager-Cx03mw7l.js +0 -258
- package/dist/contextManager-CxQqBCEA.cjs +0 -1
- package/dist/funcSpanTransformer-Byqzu4B1.js +0 -231
- package/dist/funcSpanTransformer-CDh0o-AP.cjs +0 -1
- package/dist/runtimeConfig-DndXTWki.js +0 -353
- package/dist/runtimeConfig-TWzqPe1S.cjs +0 -8
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
var L = Object.defineProperty;
|
|
2
|
+
var P = (n, e, t) => e in n ? L(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
|
|
3
|
+
var s = (n, e, t) => P(n, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { AsyncLocalStorage as D } from "async_hooks";
|
|
5
|
+
import { execFile as U } from "child_process";
|
|
6
|
+
import { existsSync as f } from "fs";
|
|
7
|
+
import * as x from "fs/promises";
|
|
8
|
+
import * as R from "os";
|
|
9
|
+
const a = [];
|
|
10
|
+
for (let n = 0; n < 256; ++n) a.push((n + 256).toString(16).slice(1));
|
|
11
|
+
let S;
|
|
12
|
+
const b = new Uint8Array(16), N = { randomUUID: typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto) };
|
|
13
|
+
function h(n, e, t) {
|
|
14
|
+
if (N.randomUUID && !n) return N.randomUUID();
|
|
15
|
+
const r = (n = n || {}).random ?? n.rng?.() ?? (function() {
|
|
16
|
+
if (!S) {
|
|
17
|
+
if (typeof crypto > "u" || !crypto.getRandomValues) throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
18
|
+
S = crypto.getRandomValues.bind(crypto);
|
|
19
|
+
}
|
|
20
|
+
return S(b);
|
|
21
|
+
})();
|
|
22
|
+
if (r.length < 16) throw new Error("Random bytes length must be >= 16");
|
|
23
|
+
return r[6] = 15 & r[6] | 64, r[8] = 63 & r[8] | 128, (function(i, o = 0) {
|
|
24
|
+
return (a[i[o + 0]] + a[i[o + 1]] + a[i[o + 2]] + a[i[o + 3]] + "-" + a[i[o + 4]] + a[i[o + 5]] + "-" + a[i[o + 6]] + a[i[o + 7]] + "-" + a[i[o + 8]] + a[i[o + 9]] + "-" + a[i[o + 10]] + a[i[o + 11]] + a[i[o + 12]] + a[i[o + 13]] + a[i[o + 14]] + a[i[o + 15]]).toLowerCase();
|
|
25
|
+
})(r);
|
|
26
|
+
}
|
|
27
|
+
class V {
|
|
28
|
+
constructor(e) {
|
|
29
|
+
s(this, "apiKey");
|
|
30
|
+
s(this, "apiGraphqlEndpoint");
|
|
31
|
+
s(this, "sfDebug");
|
|
32
|
+
s(this, "serviceIdentifier");
|
|
33
|
+
s(this, "serviceVersion");
|
|
34
|
+
s(this, "serviceUUID");
|
|
35
|
+
s(this, "serviceAdditionalMetadata");
|
|
36
|
+
s(this, "profilingModeEnabled");
|
|
37
|
+
s(this, "profilingMaxDepth");
|
|
38
|
+
s(this, "profilingMaxVariableSizeKb");
|
|
39
|
+
s(this, "domainsToNotPropagateHeadersTo");
|
|
40
|
+
s(this, "nodeModulesToCollectLocalVariablesOn");
|
|
41
|
+
s(this, "printConfigurationStatuses");
|
|
42
|
+
s(this, "logLevel");
|
|
43
|
+
s(this, "stackDepthLocals");
|
|
44
|
+
s(this, "stackDepthCodeTraceDepth");
|
|
45
|
+
s(this, "packageLibraryType");
|
|
46
|
+
s(this, "version");
|
|
47
|
+
s(this, "gitSha");
|
|
48
|
+
s(this, "gitOrg");
|
|
49
|
+
s(this, "gitRepo");
|
|
50
|
+
s(this, "gitProvider");
|
|
51
|
+
s(this, "serviceDisplayName");
|
|
52
|
+
s(this, "infrastructureType");
|
|
53
|
+
s(this, "infrastructureDetails");
|
|
54
|
+
s(this, "setupInterceptorsFile");
|
|
55
|
+
s(this, "setupInterceptorsLine");
|
|
56
|
+
s(this, "logIgnoreRegex");
|
|
57
|
+
s(this, "captureRequestHeaders");
|
|
58
|
+
s(this, "captureResponseHeaders");
|
|
59
|
+
s(this, "captureRequestBody");
|
|
60
|
+
s(this, "captureResponseBody");
|
|
61
|
+
s(this, "requestBodyLimitBytes");
|
|
62
|
+
s(this, "responseBodyLimitBytes");
|
|
63
|
+
s(this, "_serviceIdentificationReceived", !1);
|
|
64
|
+
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 = h(), this.serviceVersion = e?.serviceVersion || process.env.SERVICE_VERSION, this.gitSha = e?.gitSha || process.env.GIT_SHA || process.env.VERCEL_GIT_COMMIT_SHA, this.gitOrg = e?.gitOrg || process.env.GIT_ORG || process.env.VERCEL_GIT_REPO_OWNER, this.gitRepo = e?.gitRepo || process.env.GIT_REPO || process.env.VERCEL_GIT_REPO_SLUG, this.gitProvider = e?.gitProvider || process.env.GIT_PROVIDER, this.serviceDisplayName = e?.serviceDisplayName || process.env.SERVICE_DISPLAY_NAME, 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();
|
|
65
|
+
const t = (function() {
|
|
66
|
+
return process.env.KUBERNETES_SERVICE_HOST || f("/var/run/secrets/kubernetes.io/serviceaccount/token") ? { type: "Kubernetes", details: { namespace: process.env.POD_NAMESPACE || "", podName: process.env.HOSTNAME || "", nodeName: process.env.NODE_NAME || "" } } : process.env.AWS_LAMBDA_FUNCTION_NAME ? { type: "AWS Lambda", details: { functionName: process.env.AWS_LAMBDA_FUNCTION_NAME || "", region: process.env.AWS_REGION || "", runtime: process.env.AWS_EXECUTION_ENV || "" } } : process.env.AWS_EXECUTION_ENV ? { type: "AWS", details: { executionEnv: process.env.AWS_EXECUTION_ENV || "", region: process.env.AWS_REGION || "" } } : process.env.GOOGLE_CLOUD_PROJECT ? { type: "Google Cloud", details: { project: process.env.GOOGLE_CLOUD_PROJECT || "" } } : process.env.AZURE_FUNCTIONS_ENVIRONMENT ? { type: "Azure Functions", details: { environment: process.env.AZURE_FUNCTIONS_ENVIRONMENT || "" } } : process.env.VERCEL ? { type: "Vercel", details: { env: process.env.VERCEL_ENV || "", region: process.env.VERCEL_REGION || "" } } : process.env.NETLIFY ? { type: "Netlify", details: {} } : process.env.FLY_APP_NAME ? { type: "Fly.io", details: { appName: process.env.FLY_APP_NAME || "", region: process.env.FLY_REGION || "" } } : process.env.RENDER_SERVICE_ID ? { type: "Render", details: { serviceId: process.env.RENDER_SERVICE_ID || "" } } : process.env.RAILWAY_ENVIRONMENT ? { type: "Railway", details: { environment: process.env.RAILWAY_ENVIRONMENT || "" } } : f("/.dockerenv") ? { type: "Docker", details: {} } : { type: "Unknown", details: { os: R.platform(), arch: R.arch(), nodeVersion: process.version } };
|
|
67
|
+
})();
|
|
68
|
+
this.infrastructureType = t.type, this.infrastructureDetails = t.details;
|
|
69
|
+
const r = process.env.SF_LOG_IGNORE_REGEX;
|
|
70
|
+
if (r) try {
|
|
71
|
+
this.logIgnoreRegex = new RegExp(r);
|
|
72
|
+
} catch {
|
|
73
|
+
}
|
|
74
|
+
this.captureRequestHeaders = process.env.SF_NETWORKHOP_CAPTURE_REQUEST_HEADERS === "true", this.captureResponseHeaders = process.env.SF_NETWORKHOP_CAPTURE_RESPONSE_HEADERS === "true", this.captureRequestBody = process.env.SF_NETWORKHOP_CAPTURE_REQUEST_BODY === "true", this.captureResponseBody = process.env.SF_NETWORKHOP_CAPTURE_RESPONSE_BODY === "true";
|
|
75
|
+
const i = parseInt(process.env.SF_NETWORKHOP_REQUEST_LIMIT_MB || "1", 10);
|
|
76
|
+
this.requestBodyLimitBytes = 1024 * (isNaN(i) ? 1 : i) * 1024;
|
|
77
|
+
const o = parseInt(process.env.SF_NETWORKHOP_RESPONSE_LIMIT_MB || "1", 10);
|
|
78
|
+
this.responseBodyLimitBytes = 1024 * (isNaN(o) ? 1 : o) * 1024;
|
|
79
|
+
}
|
|
80
|
+
getPackageVersion() {
|
|
81
|
+
return "0.2.14";
|
|
82
|
+
}
|
|
83
|
+
get serviceIdentificationReceived() {
|
|
84
|
+
return this._serviceIdentificationReceived;
|
|
85
|
+
}
|
|
86
|
+
setServiceIdentificationReceived(e) {
|
|
87
|
+
this._serviceIdentificationReceived = e;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
async function B(n) {
|
|
91
|
+
if (!(n.gitOrg && n.gitRepo && n.gitProvider)) try {
|
|
92
|
+
const e = await (async function() {
|
|
93
|
+
let t = "";
|
|
94
|
+
try {
|
|
95
|
+
t = await new Promise((r, i) => {
|
|
96
|
+
U("git", ["remote", "get-url", "origin"], { timeout: 3e3 }, (o, p) => {
|
|
97
|
+
o ? i(o) : r((p || "").trim());
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
} catch {
|
|
101
|
+
try {
|
|
102
|
+
const r = (await x.readFile(".git/config", "utf-8")).match(/\[remote "origin"\][^[]*url\s*=\s*(.+)/m);
|
|
103
|
+
r && (t = r[1].trim());
|
|
104
|
+
} catch {
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return t ? (function(r) {
|
|
108
|
+
let i, o, p;
|
|
109
|
+
if (r.includes("github.com") ? i = "github" : r.includes("gitlab.com") ? i = "gitlab" : r.includes("bitbucket.org") && (i = "bitbucket"), r.startsWith("https://") || r.startsWith("http://")) {
|
|
110
|
+
const d = r.split("/");
|
|
111
|
+
d.length >= 5 && (o = d[3], p = d[4].replace(/\.git$/, ""));
|
|
112
|
+
} else {
|
|
113
|
+
const d = r.indexOf(":");
|
|
114
|
+
if (d > 0) {
|
|
115
|
+
const _ = r.substring(d + 1).replace(/\.git$/, "").split("/");
|
|
116
|
+
_.length >= 2 && (o = _[0], p = _[1]);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return { org: o, repo: p, provider: i };
|
|
120
|
+
})(t) : {};
|
|
121
|
+
})();
|
|
122
|
+
n.gitOrg || (n.gitOrg = e.org), n.gitRepo || (n.gitRepo = e.repo), n.gitProvider || (n.gitProvider = e.provider);
|
|
123
|
+
} catch {
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const m = Symbol.for("sailfish.sf_config");
|
|
127
|
+
function y() {
|
|
128
|
+
return globalThis[m];
|
|
129
|
+
}
|
|
130
|
+
function W(n) {
|
|
131
|
+
const e = y();
|
|
132
|
+
if (e) return { config: e };
|
|
133
|
+
const t = new V(n);
|
|
134
|
+
return (function(r) {
|
|
135
|
+
globalThis[m] = r;
|
|
136
|
+
})(t), t.sfDebug && console.log("[[getOrCreateConfig]] Created global config:", t), { config: t };
|
|
137
|
+
}
|
|
138
|
+
function v() {
|
|
139
|
+
const n = y();
|
|
140
|
+
if (!n) throw new Error("Configuration has not been initialized. Call getOrCreateConfig(options) first.");
|
|
141
|
+
return n;
|
|
142
|
+
}
|
|
143
|
+
const O = Symbol.for("sf.ctx.storeAls"), c = globalThis, C = c[O] ?? (c[O] = new D()), M = ["identitytoolkit.googleapis.com", "t.co", "*.twitter.com", "*.gravatar.com", "*.googleapis.com", "*.amazonaws.com", "*.smooch.io", "*.zendesk.com"], T = Symbol.for("sf.ctx.als"), E = c[T] ?? (c[T] = new D()), A = Symbol.for("sf.ctx.sessionRegistry"), g = c[A] ?? (c[A] = /* @__PURE__ */ new Map()), l = { handledExceptions: /* @__PURE__ */ new Set(), reentrancyGuardLoggingActive: !1, reentrancyGuardLoggingPreActive: !1, reentrancyGuardPrintActive: !1, reentrancyGuardPrintPreActive: !1, reentrancyGuardExceptionActive: !1, reentrancyGuardExceptionPreActive: !1, excludedDomains: new Set(M), supportedDomains: /* @__PURE__ */ new Set() }, u = class u {
|
|
144
|
+
constructor() {
|
|
145
|
+
}
|
|
146
|
+
current() {
|
|
147
|
+
return C.getStore();
|
|
148
|
+
}
|
|
149
|
+
ensureStore() {
|
|
150
|
+
const e = this.current();
|
|
151
|
+
if (e) return e;
|
|
152
|
+
const t = /* @__PURE__ */ new Map();
|
|
153
|
+
return C.enterWith(t), t;
|
|
154
|
+
}
|
|
155
|
+
runWith(e, t) {
|
|
156
|
+
const r = this.current() ?? /* @__PURE__ */ new Map(), i = new Map(r);
|
|
157
|
+
for (const [o, p] of Object.entries(e)) i.set(o, p);
|
|
158
|
+
return C.run(i, t);
|
|
159
|
+
}
|
|
160
|
+
static getInstance() {
|
|
161
|
+
return c[u.GLOBAL_MANAGER_SYMBOL] || (c[u.GLOBAL_MANAGER_SYMBOL] = new u()), c[u.GLOBAL_MANAGER_SYMBOL];
|
|
162
|
+
}
|
|
163
|
+
getCurrentContext() {
|
|
164
|
+
return E.getStore() || l;
|
|
165
|
+
}
|
|
166
|
+
setCurrentContext(e) {
|
|
167
|
+
const t = E.getStore() || l;
|
|
168
|
+
E.enterWith({ ...t, ...e });
|
|
169
|
+
}
|
|
170
|
+
ensureSession(e) {
|
|
171
|
+
let t = g.get(e);
|
|
172
|
+
return t || (t = { ...l }, g.set(e, t)), t;
|
|
173
|
+
}
|
|
174
|
+
getContextFor(e) {
|
|
175
|
+
return g.get(e) ?? l;
|
|
176
|
+
}
|
|
177
|
+
updateContextFor(e, t) {
|
|
178
|
+
const r = this.ensureSession(e);
|
|
179
|
+
g.set(e, { ...r, ...t });
|
|
180
|
+
}
|
|
181
|
+
runWithSession(e, t) {
|
|
182
|
+
const r = { ...this.ensureSession(e) };
|
|
183
|
+
return E.run(r, t);
|
|
184
|
+
}
|
|
185
|
+
deleteSession(e) {
|
|
186
|
+
g.delete(e);
|
|
187
|
+
}
|
|
188
|
+
getTraceId() {
|
|
189
|
+
return this.getCurrentContext().traceId;
|
|
190
|
+
}
|
|
191
|
+
getPageVisitUUID() {
|
|
192
|
+
return this.getCurrentContext().pageVisitUUID;
|
|
193
|
+
}
|
|
194
|
+
setTraceId(e) {
|
|
195
|
+
this.setCurrentContext({ traceId: e });
|
|
196
|
+
}
|
|
197
|
+
setPageVisitUUID(e) {
|
|
198
|
+
this.setCurrentContext({ pageVisitUUID: e });
|
|
199
|
+
}
|
|
200
|
+
getCurrentFunctionSpanId() {
|
|
201
|
+
return this.getCurrentContext().currentFunctionSpanId;
|
|
202
|
+
}
|
|
203
|
+
setCurrentFunctionSpanId(e) {
|
|
204
|
+
this.setCurrentContext({ currentFunctionSpanId: e });
|
|
205
|
+
}
|
|
206
|
+
clearCurrentFunctionSpanId() {
|
|
207
|
+
this.setCurrentContext({ currentFunctionSpanId: void 0 });
|
|
208
|
+
}
|
|
209
|
+
getOrSetSfTraceId(e, t = !1) {
|
|
210
|
+
let r = this.getTraceId();
|
|
211
|
+
return r || (r = e || (t ? h() : `nonsession-applogs-v3/${v().apiKey}/${h()}`), this.setTraceId(r), v().sfDebug && console.log(" Created new trace ID:", r), r);
|
|
212
|
+
}
|
|
213
|
+
getOrSetPageVisitUUID() {
|
|
214
|
+
let e = this.getPageVisitUUID();
|
|
215
|
+
return e || (e = h(), this.setPageVisitUUID(e), v().sfDebug && console.log(" Created new page visit UUID:", e), e);
|
|
216
|
+
}
|
|
217
|
+
getHandledExceptions() {
|
|
218
|
+
return this.getCurrentContext().handledExceptions;
|
|
219
|
+
}
|
|
220
|
+
markExceptionHandled(e) {
|
|
221
|
+
const t = this.getHandledExceptions();
|
|
222
|
+
t.add(e), this.setCurrentContext({ handledExceptions: t });
|
|
223
|
+
}
|
|
224
|
+
hasHandledException(e) {
|
|
225
|
+
return this.getHandledExceptions().has(e);
|
|
226
|
+
}
|
|
227
|
+
resetHandledExceptions() {
|
|
228
|
+
this.setCurrentContext({ handledExceptions: /* @__PURE__ */ new Set() });
|
|
229
|
+
}
|
|
230
|
+
getExcludedDomains() {
|
|
231
|
+
return this.getCurrentContext().excludedDomains;
|
|
232
|
+
}
|
|
233
|
+
getSupportedDomains() {
|
|
234
|
+
return this.getCurrentContext().supportedDomains;
|
|
235
|
+
}
|
|
236
|
+
addSupportedDomains(e) {
|
|
237
|
+
this.getCurrentContext().supportedDomains.add(e.toLowerCase().trim());
|
|
238
|
+
}
|
|
239
|
+
setTraceIdFor(e, t) {
|
|
240
|
+
this.updateContextFor(e, { traceId: t });
|
|
241
|
+
}
|
|
242
|
+
setPageVisitUUIDFor(e, t) {
|
|
243
|
+
this.updateContextFor(e, { pageVisitUUID: t });
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
s(u, "GLOBAL_MANAGER_SYMBOL", Symbol.for("sf.ctx.manager"));
|
|
247
|
+
let I = u;
|
|
248
|
+
function k(n) {
|
|
249
|
+
const e = { ...I.getInstance().getCurrentContext() };
|
|
250
|
+
E.run(e, () => {
|
|
251
|
+
n();
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
function K() {
|
|
255
|
+
return I.getInstance().getCurrentFunctionSpanId();
|
|
256
|
+
}
|
|
257
|
+
export {
|
|
258
|
+
I as C,
|
|
259
|
+
M as D,
|
|
260
|
+
y as a,
|
|
261
|
+
K as b,
|
|
262
|
+
W as c,
|
|
263
|
+
B as d,
|
|
264
|
+
v as g,
|
|
265
|
+
k as r,
|
|
266
|
+
h as v
|
|
267
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const D=require("async_hooks"),m=require("child_process"),v=require("fs"),P=require("fs/promises"),U=require("os");function A(n){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const t in n)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(n,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>n[t]})}}return e.default=n,Object.freeze(e)}const b=A(P),f=A(U),o=[];for(let n=0;n<256;++n)o.push((n+256).toString(16).slice(1));let I;const x=new Uint8Array(16),O={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function l(n,e,t){if(O.randomUUID&&!n)return O.randomUUID();const r=(n=n||{}).random??n.rng?.()??(function(){if(!I){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");I=crypto.getRandomValues.bind(crypto)}return I(x)})();if(r.length<16)throw new Error("Random bytes length must be >= 16");return r[6]=15&r[6]|64,r[8]=63&r[8]|128,(function(s,i=0){return(o[s[i+0]]+o[s[i+1]]+o[s[i+2]]+o[s[i+3]]+"-"+o[s[i+4]]+o[s[i+5]]+"-"+o[s[i+6]]+o[s[i+7]]+"-"+o[s[i+8]]+o[s[i+9]]+"-"+o[s[i+10]]+o[s[i+11]]+o[s[i+12]]+o[s[i+13]]+o[s[i+14]]+o[s[i+15]]).toLowerCase()})(r)}class M{apiKey;apiGraphqlEndpoint;sfDebug;serviceIdentifier;serviceVersion;serviceUUID;serviceAdditionalMetadata;profilingModeEnabled;profilingMaxDepth;profilingMaxVariableSizeKb;domainsToNotPropagateHeadersTo;nodeModulesToCollectLocalVariablesOn;printConfigurationStatuses;logLevel;stackDepthLocals;stackDepthCodeTraceDepth;packageLibraryType;version;gitSha;gitOrg;gitRepo;gitProvider;serviceDisplayName;infrastructureType;infrastructureDetails;setupInterceptorsFile;setupInterceptorsLine;logIgnoreRegex;captureRequestHeaders;captureResponseHeaders;captureRequestBody;captureResponseBody;requestBodyLimitBytes;responseBodyLimitBytes;_serviceIdentificationReceived=!1;constructor(e){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=l(),this.serviceVersion=e?.serviceVersion||process.env.SERVICE_VERSION,this.gitSha=e?.gitSha||process.env.GIT_SHA||process.env.VERCEL_GIT_COMMIT_SHA,this.gitOrg=e?.gitOrg||process.env.GIT_ORG||process.env.VERCEL_GIT_REPO_OWNER,this.gitRepo=e?.gitRepo||process.env.GIT_REPO||process.env.VERCEL_GIT_REPO_SLUG,this.gitProvider=e?.gitProvider||process.env.GIT_PROVIDER,this.serviceDisplayName=e?.serviceDisplayName||process.env.SERVICE_DISPLAY_NAME,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();const t=(function(){return process.env.KUBERNETES_SERVICE_HOST||v.existsSync("/var/run/secrets/kubernetes.io/serviceaccount/token")?{type:"Kubernetes",details:{namespace:process.env.POD_NAMESPACE||"",podName:process.env.HOSTNAME||"",nodeName:process.env.NODE_NAME||""}}:process.env.AWS_LAMBDA_FUNCTION_NAME?{type:"AWS Lambda",details:{functionName:process.env.AWS_LAMBDA_FUNCTION_NAME||"",region:process.env.AWS_REGION||"",runtime:process.env.AWS_EXECUTION_ENV||""}}:process.env.AWS_EXECUTION_ENV?{type:"AWS",details:{executionEnv:process.env.AWS_EXECUTION_ENV||"",region:process.env.AWS_REGION||""}}:process.env.GOOGLE_CLOUD_PROJECT?{type:"Google Cloud",details:{project:process.env.GOOGLE_CLOUD_PROJECT||""}}:process.env.AZURE_FUNCTIONS_ENVIRONMENT?{type:"Azure Functions",details:{environment:process.env.AZURE_FUNCTIONS_ENVIRONMENT||""}}:process.env.VERCEL?{type:"Vercel",details:{env:process.env.VERCEL_ENV||"",region:process.env.VERCEL_REGION||""}}:process.env.NETLIFY?{type:"Netlify",details:{}}:process.env.FLY_APP_NAME?{type:"Fly.io",details:{appName:process.env.FLY_APP_NAME||"",region:process.env.FLY_REGION||""}}:process.env.RENDER_SERVICE_ID?{type:"Render",details:{serviceId:process.env.RENDER_SERVICE_ID||""}}:process.env.RAILWAY_ENVIRONMENT?{type:"Railway",details:{environment:process.env.RAILWAY_ENVIRONMENT||""}}:v.existsSync("/.dockerenv")?{type:"Docker",details:{}}:{type:"Unknown",details:{os:f.platform(),arch:f.arch(),nodeVersion:process.version}}})();this.infrastructureType=t.type,this.infrastructureDetails=t.details;const r=process.env.SF_LOG_IGNORE_REGEX;if(r)try{this.logIgnoreRegex=new RegExp(r)}catch{}this.captureRequestHeaders=process.env.SF_NETWORKHOP_CAPTURE_REQUEST_HEADERS==="true",this.captureResponseHeaders=process.env.SF_NETWORKHOP_CAPTURE_RESPONSE_HEADERS==="true",this.captureRequestBody=process.env.SF_NETWORKHOP_CAPTURE_REQUEST_BODY==="true",this.captureResponseBody=process.env.SF_NETWORKHOP_CAPTURE_RESPONSE_BODY==="true";const s=parseInt(process.env.SF_NETWORKHOP_REQUEST_LIMIT_MB||"1",10);this.requestBodyLimitBytes=1024*(isNaN(s)?1:s)*1024;const i=parseInt(process.env.SF_NETWORKHOP_RESPONSE_LIMIT_MB||"1",10);this.responseBodyLimitBytes=1024*(isNaN(i)?1:i)*1024}getPackageVersion(){return"0.2.14"}get serviceIdentificationReceived(){return this._serviceIdentificationReceived}setServiceIdentificationReceived(e){this._serviceIdentificationReceived=e}}const y=Symbol.for("sailfish.sf_config");function C(){return globalThis[y]}function h(){const n=C();if(!n)throw new Error("Configuration has not been initialized. Call getOrCreateConfig(options) first.");return n}const R=Symbol.for("sf.ctx.storeAls"),a=globalThis,S=a[R]??(a[R]=new D.AsyncLocalStorage),L=["identitytoolkit.googleapis.com","t.co","*.twitter.com","*.gravatar.com","*.googleapis.com","*.amazonaws.com","*.smooch.io","*.zendesk.com"],N=Symbol.for("sf.ctx.als"),g=a[N]??(a[N]=new D.AsyncLocalStorage),T=Symbol.for("sf.ctx.sessionRegistry"),d=a[T]??(a[T]=new Map),E={handledExceptions:new Set,reentrancyGuardLoggingActive:!1,reentrancyGuardLoggingPreActive:!1,reentrancyGuardPrintActive:!1,reentrancyGuardPrintPreActive:!1,reentrancyGuardExceptionActive:!1,reentrancyGuardExceptionPreActive:!1,excludedDomains:new Set(L),supportedDomains:new Set};class c{static GLOBAL_MANAGER_SYMBOL=Symbol.for("sf.ctx.manager");constructor(){}current(){return S.getStore()}ensureStore(){const e=this.current();if(e)return e;const t=new Map;return S.enterWith(t),t}runWith(e,t){const r=this.current()??new Map,s=new Map(r);for(const[i,p]of Object.entries(e))s.set(i,p);return S.run(s,t)}static getInstance(){return a[c.GLOBAL_MANAGER_SYMBOL]||(a[c.GLOBAL_MANAGER_SYMBOL]=new c),a[c.GLOBAL_MANAGER_SYMBOL]}getCurrentContext(){return g.getStore()||E}setCurrentContext(e){const t=g.getStore()||E;g.enterWith({...t,...e})}ensureSession(e){let t=d.get(e);return t||(t={...E},d.set(e,t)),t}getContextFor(e){return d.get(e)??E}updateContextFor(e,t){const r=this.ensureSession(e);d.set(e,{...r,...t})}runWithSession(e,t){const r={...this.ensureSession(e)};return g.run(r,t)}deleteSession(e){d.delete(e)}getTraceId(){return this.getCurrentContext().traceId}getPageVisitUUID(){return this.getCurrentContext().pageVisitUUID}setTraceId(e){this.setCurrentContext({traceId:e})}setPageVisitUUID(e){this.setCurrentContext({pageVisitUUID:e})}getCurrentFunctionSpanId(){return this.getCurrentContext().currentFunctionSpanId}setCurrentFunctionSpanId(e){this.setCurrentContext({currentFunctionSpanId:e})}clearCurrentFunctionSpanId(){this.setCurrentContext({currentFunctionSpanId:void 0})}getOrSetSfTraceId(e,t=!1){let r=this.getTraceId();return r||(r=e||(t?l():`nonsession-applogs-v3/${h().apiKey}/${l()}`),this.setTraceId(r),h().sfDebug&&console.log(" Created new trace ID:",r),r)}getOrSetPageVisitUUID(){let e=this.getPageVisitUUID();return e||(e=l(),this.setPageVisitUUID(e),h().sfDebug&&console.log(" Created new page visit UUID:",e),e)}getHandledExceptions(){return this.getCurrentContext().handledExceptions}markExceptionHandled(e){const t=this.getHandledExceptions();t.add(e),this.setCurrentContext({handledExceptions:t})}hasHandledException(e){return this.getHandledExceptions().has(e)}resetHandledExceptions(){this.setCurrentContext({handledExceptions:new Set})}getExcludedDomains(){return this.getCurrentContext().excludedDomains}getSupportedDomains(){return this.getCurrentContext().supportedDomains}addSupportedDomains(e){this.getCurrentContext().supportedDomains.add(e.toLowerCase().trim())}setTraceIdFor(e,t){this.updateContextFor(e,{traceId:t})}setPageVisitUUIDFor(e,t){this.updateContextFor(e,{pageVisitUUID:t})}}exports.ContextManager=c,exports.DEFAULT_DOMAINS_TO_EXCLUDE=L,exports.backfillGitInfoAsync=async function(n){if(!(n.gitOrg&&n.gitRepo&&n.gitProvider))try{const e=await(async function(){let t="";try{t=await new Promise((r,s)=>{m.execFile("git",["remote","get-url","origin"],{timeout:3e3},(i,p)=>{i?s(i):r((p||"").trim())})})}catch{try{const r=(await b.readFile(".git/config","utf-8")).match(/\[remote "origin"\][^[]*url\s*=\s*(.+)/m);r&&(t=r[1].trim())}catch{}}return t?(function(r){let s,i,p;if(r.includes("github.com")?s="github":r.includes("gitlab.com")?s="gitlab":r.includes("bitbucket.org")&&(s="bitbucket"),r.startsWith("https://")||r.startsWith("http://")){const u=r.split("/");u.length>=5&&(i=u[3],p=u[4].replace(/\.git$/,""))}else{const u=r.indexOf(":");if(u>0){const _=r.substring(u+1).replace(/\.git$/,"").split("/");_.length>=2&&(i=_[0],p=_[1])}}return{org:i,repo:p,provider:s}})(t):{}})();n.gitOrg||(n.gitOrg=e.org),n.gitRepo||(n.gitRepo=e.repo),n.gitProvider||(n.gitProvider=e.provider)}catch{}},exports.getConfig=h,exports.getCurrentFunctionSpanId=function(){return c.getInstance().getCurrentFunctionSpanId()},exports.getGlobalConfigUnsafe=C,exports.getOrCreateConfig=function(n){const e=C();if(e)return{config:e};const t=new M(n);return(function(r){globalThis[y]=r})(t),t.sfDebug&&console.log("[[getOrCreateConfig]] Created global config:",t),{config:t}},exports.runWithContext=function(n){const e={...c.getInstance().getCurrentContext()};g.run(e,()=>{n()})},exports.v4=l;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const O=require("@babel/parser"),w=require("@babel/traverse"),D=require("@babel/generator"),V=require("@babel/types"),F=require("path"),B=require("fs"),J=require("./source-map-rHHEdpre.cjs");function H(a){const i=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const o in a)if(o!=="default"){const E=Object.getOwnPropertyDescriptor(a,o);Object.defineProperty(i,o,E.get?E:{enumerable:!0,get:()=>a[o]})}}return i.default=a,Object.freeze(i)}const e=H(V),_=new Set(["register","setupInterceptors","initializeConfigLoader","initializeWorkerPoolPatching"]),A=[/instrumentation\.(ts|js|tsx|jsx)$/,/unifiedInterceptor\.(ts|js)$/];let M=!1;const N=w.default||w,G=D.default||D;function $(a){const i=[];for(const o of a)e.isIdentifier(o)?i.push(o.name):e.isRestElement(o)&&e.isIdentifier(o.argument)?i.push(`...${o.argument.name}`):e.isAssignmentPattern(o)&&e.isIdentifier(o.left)?i.push(o.left.name):e.isAssignmentPattern(o)&&e.isObjectPattern(o.left)?i.push(q(o.left)):e.isAssignmentPattern(o)&&e.isArrayPattern(o.left)?i.push(K(o.left)):e.isObjectPattern(o)?i.push(q(o)):e.isArrayPattern(o)?i.push(K(o)):i.push("_");return i}function q(a){return`{${a.properties.map(i=>e.isRestElement(i)?`...${e.isIdentifier(i.argument)?i.argument.name:"_"}`:e.isObjectProperty(i)&&e.isIdentifier(i.key)?i.key.name:"_").join(", ")}}`}function K(a){return`[${a.elements.map(i=>i===null?"_":e.isIdentifier(i)?i.name:e.isRestElement(i)&&e.isIdentifier(i.argument)?`...${i.argument.name}`:"_").join(", ")}]`}function R(a){let i=!1;return N(a,{ImportDeclaration(o){e.isStringLiteral(o.node.source)&&o.node.source.value==="@sailfish-ai/sf-veritas"&&o.node.specifiers.some(E=>e.isImportSpecifier(E)&&e.isIdentifier(E.imported)&&E.imported.name==="captureFunctionSpan")&&(i=!0,o.stop())},VariableDeclarator(o){if(e.isObjectPattern(o.node.id)&&e.isCallExpression(o.node.init)&&e.isIdentifier(o.node.init.callee)&&o.node.init.callee.name==="require"){const E=o.node.init.arguments;E.length>0&&e.isStringLiteral(E[0])&&E[0].value==="@sailfish-ai/sf-veritas"&&o.node.id.properties.some(k=>e.isObjectProperty(k)&&e.isIdentifier(k.key)&&k.key.name==="captureFunctionSpan")&&(i=!0,o.stop())}}}),i}function z(a){let i=!1;return N(a,{CallExpression(o){e.isIdentifier(o.node.callee)&&o.node.callee.name==="require"&&(i=!0,o.stop())},MemberExpression(o){!e.isIdentifier(o.node.object)||o.node.object.name!=="module"&&o.node.object.name!=="exports"||(i=!0,o.stop())}}),i}exports.setSkipTypeScriptPlugin=function(a){M=a},exports.transformFunctionSpans=async function(a,i,o={}){const{projectRoot:E=process.cwd(),includeNodeModules:k=[],debug:c=!1}=o;if(i.includes("node_modules")&&!k.some(n=>i.includes(`node_modules/${n}`)))return{code:a,modified:!1,functionsWrapped:0};if(i.includes("sf-veritas")||i.includes("@sailfish-ai")||i.includes("jsts-backend")||i.includes("jsts-frontend"))return c&&console.log(`[FuncSpan Transform] SKIPPING sf-veritas internal file: ${i}`),{code:a,modified:!1,functionsWrapped:0};if(A.some(n=>n.test(i)))return c&&console.log(`[FuncSpan Transform] SKIPPING instrumentation entry point file: ${i}`),{code:a,modified:!1,functionsWrapped:0};const T=F.relative(E,i).replace(/\\/g,"/");let h;c&&console.log(`[FuncSpan Transform] Processing: ${T}`);try{h=O.parse(a,{sourceType:"module",plugins:["typescript","jsx","decorators-legacy","classProperties","objectRestSpread","asyncGenerators","dynamicImport","optionalCatchBinding","optionalChaining","nullishCoalescingOperator"]})}catch(n){return c&&console.error(`[FuncSpan Transform] Parse error in ${T}:`,n),{code:a,modified:!1,functionsWrapped:0}}let v=null,W=null;try{const n=B.readFileSync(`${i}.map`,"utf-8");v=await new J.sourceMapExports.SourceMapConsumer(JSON.parse(n))}catch{}const L=(n,t)=>{if(v){const r=v.originalPositionFor({line:n,column:t});if(r.line!==null&&r.column!==null)return!W&&r.source&&(W=r.source),{line:r.line,column:r.column,source:r.source||void 0}}return{line:n,column:t}};let x=!1,j=0;const g=new Set;if(N(h,{FunctionDeclaration(n){const t=n.node.id?.name;if(!t)return;if(_.has(t))return void(c&&console.log(`[FuncSpan Transform] SKIPPING entry point function: ${t}`));const r=`decl_${t}`;if(g.has(r))return;c&&console.log(`[FuncSpan Transform] Wrapping function declaration: ${t}`);const s=n.node.loc?.start.line??0,l=n.node.loc?.start.column??0,d=L(s,l),{line:m,column:p}=d;let u=i;d.source&&(u=F.resolve(F.dirname(i),d.source)),!c||m===s&&p===l||console.log(`[FuncSpan Transform] Mapped ${s}:${l} → ${m}:${p} in ${u}`);const y=$(n.node.params),f=e.callExpression(e.identifier("captureFunctionSpan"),[e.identifier(t),e.stringLiteral(t),e.stringLiteral(u),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(m)),e.objectProperty(e.identifier("column"),e.numericLiteral(p)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(y.map(S=>e.stringLiteral(S))))])]),b=e.expressionStatement(e.assignmentExpression("=",e.identifier(t),f));n.insertAfter(b),x=!0,j++,g.add(r)},VariableDeclarator(n){const t=n.node.id,r=n.node.init;if(!e.isIdentifier(t)||!r||!e.isFunctionExpression(r)&&!e.isArrowFunctionExpression(r))return;const s=t.name;if(_.has(s))return void(c&&console.log(`[FuncSpan Transform] SKIPPING entry point function: ${s}`));const l=`var_${s}`;if(g.has(l))return;c&&console.log(`[FuncSpan Transform] Wrapping variable function: ${s}`);const d=r.loc?.start.line??0,m=r.loc?.start.column??0,p=L(d,m),{line:u,column:y}=p;let f=i;p.source&&(f=F.resolve(F.dirname(i),p.source)),!c||u===d&&y===m||console.log(`[FuncSpan Transform] Mapped ${d}:${m} → ${u}:${y} in ${f}`);const b=$(r.params),S=e.callExpression(e.identifier("captureFunctionSpan"),[r,e.stringLiteral(s),e.stringLiteral(f),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(u)),e.objectProperty(e.identifier("column"),e.numericLiteral(y)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(b.map(P=>e.stringLiteral(P))))])]);n.node.init=S,x=!0,j++,g.add(l)},ClassMethod(n){if(n.node.kind==="constructor"||n.node.kind==="get"||n.node.kind==="set")return;const t=e.isIdentifier(n.node.key)?n.node.key.name:"anonymous";let r=!1;if(n.traverse({Super(){r=!0},ClassDeclaration(I){I.skip()},ClassExpression(I){I.skip()}}),r)return void(c&&console.log(`[FuncSpan Transform] SKIPPING class method with super: ${t}`));const s=`method_${t}_${n.node.start}`;if(g.has(s))return;c&&console.log(`[FuncSpan Transform] Wrapping class method: ${t}`);const l=n.node.loc?.start.line??0,d=n.node.loc?.start.column??0,m=L(l,d),{line:p,column:u}=m,y=i,f=$(n.node.params),b=n.node.body,S=e.functionExpression(null,n.node.params,b,n.node.generator,n.node.async),P=e.callExpression(e.identifier("captureFunctionSpan"),[S,e.stringLiteral(t),e.stringLiteral(y),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(p)),e.objectProperty(e.identifier("column"),e.numericLiteral(u)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(f.map(I=>e.stringLiteral(I))))])]),C=e.blockStatement([e.returnStatement(e.callExpression(e.memberExpression(P,e.identifier("call")),[e.thisExpression(),e.spreadElement(e.identifier("arguments"))]))]);n.node.body=C,x=!0,j++,g.add(s)},ObjectMethod(n){if(n.node.kind==="get"||n.node.kind==="set")return;const t=e.isIdentifier(n.node.key)?n.node.key.name:e.isStringLiteral(n.node.key)?n.node.key.value:"anonymous",r=`objmethod_${t}_${n.node.start}`;if(g.has(r))return;c&&console.log(`[FuncSpan Transform] Wrapping object method: ${t}`);const s=n.node.loc?.start.line??0,l=n.node.loc?.start.column??0,d=L(s,l),{line:m,column:p}=d;let u=i;d.source&&(u=F.resolve(F.dirname(i),d.source));const y=$(n.node.params),f=e.functionExpression(e.identifier(t),n.node.params,n.node.body,n.node.generator,n.node.async),b=e.callExpression(e.identifier("captureFunctionSpan"),[f,e.stringLiteral(t),e.stringLiteral(u),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(m)),e.objectProperty(e.identifier("column"),e.numericLiteral(p)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(y.map(P=>e.stringLiteral(P))))])]),S=e.objectProperty(n.node.key,b,n.node.computed,!1);n.replaceWith(S),x=!0,j++,g.add(r)},ClassProperty(n){const t=n.node.key,r=n.node.value;if(!e.isIdentifier(t)||!r||!e.isFunctionExpression(r)&&!e.isArrowFunctionExpression(r))return;const s=t.name,l=`classprop_${s}_${n.node.start}`;if(g.has(l))return;c&&console.log(`[FuncSpan Transform] Wrapping class property function: ${s}`);const d=r.loc?.start.line??0,m=r.loc?.start.column??0,p=L(d,m),{line:u,column:y}=p;let f=i;p.source&&(f=F.resolve(F.dirname(i),p.source));const b=$(r.params),S=e.callExpression(e.identifier("captureFunctionSpan"),[r,e.stringLiteral(s),e.stringLiteral(f),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(u)),e.objectProperty(e.identifier("column"),e.numericLiteral(y)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(b.map(P=>e.stringLiteral(P))))])]);n.node.value=S,x=!0,j++,g.add(l)},ObjectProperty(n){const t=n.node.key,r=n.node.value;if(!e.isIdentifier(t)&&!e.isStringLiteral(t)||!r||!e.isFunctionExpression(r)&&!e.isArrowFunctionExpression(r))return;const s=e.isIdentifier(t)?t.name:t.value,l=`objprop_${s}_${n.node.start}`;if(g.has(l))return;c&&console.log(`[FuncSpan Transform] Wrapping object property function: ${s}`);const d=r.loc?.start.line??0,m=r.loc?.start.column??0,p=L(d,m),{line:u,column:y}=p;let f=i;p.source&&(f=F.resolve(F.dirname(i),p.source));const b=$(r.params),S=e.callExpression(e.identifier("captureFunctionSpan"),[r,e.stringLiteral(s),e.stringLiteral(f),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(u)),e.objectProperty(e.identifier("column"),e.numericLiteral(y)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(b.map(P=>e.stringLiteral(P))))])]);n.node.value=S,x=!0,j++,g.add(l)}}),x&&!R(h))if(z(h)){const n=e.variableDeclaration("const",[e.variableDeclarator(e.objectPattern([e.objectProperty(e.identifier("captureFunctionSpan"),e.identifier("captureFunctionSpan"),!1,!0)]),e.callExpression(e.identifier("require"),[e.stringLiteral("@sailfish-ai/sf-veritas")]))]);h.program.body.unshift(n)}else{const n=e.importDeclaration([e.importSpecifier(e.identifier("captureFunctionSpan"),e.identifier("captureFunctionSpan"))],e.stringLiteral("@sailfish-ai/sf-veritas"));h.program.body.unshift(n)}if(j>0){const n=G(h,{retainLines:!0,compact:!1,sourceMaps:!0,sourceFileName:i},a);return c&&console.log(`[FuncSpan Transform] ✅ Wrapped ${j} functions in ${T}`),{code:n.code,map:n.map,modified:!0,functionsWrapped:j}}return{code:a,modified:!1,functionsWrapped:0}},exports.transformFunctionSpansSync=function(a,i,o={}){const{projectRoot:E=process.cwd(),includeNodeModules:k=[],debug:c=!1,parseAsJavaScript:T=!1}=o;if(i.includes("node_modules")&&!k.some(n=>i.includes(`node_modules/${n}`)))return{code:a,modified:!1,functionsWrapped:0};if(i.includes("sf-veritas")||i.includes("@sailfish-ai")||i.includes("jsts-backend")||i.includes("jsts-frontend"))return c&&console.log(`[FuncSpan Transform] SKIPPING sf-veritas internal file: ${i}`),{code:a,modified:!1,functionsWrapped:0};if(A.some(n=>n.test(i)))return c&&console.log(`[FuncSpan Transform] SKIPPING instrumentation entry point file: ${i}`),{code:a,modified:!1,functionsWrapped:0};const h=F.relative(E,i).replace(/\\/g,"/");let v;c&&console.log(`[FuncSpan Transform] Processing: ${h}`);const W=["jsx","decorators-legacy","classProperties","objectRestSpread","asyncGenerators","dynamicImport","optionalCatchBinding","optionalChaining","nullishCoalescingOperator"];M||T||W.unshift("typescript");try{v=O.parse(a,{sourceType:"module",plugins:W})}catch(n){return c&&console.error(`[FuncSpan Transform] Parse error in ${h}:`,n),{code:a,modified:!1,functionsWrapped:0}}const L=(n,t)=>({line:n,column:t});let x=!1,j=0;const g=new Set;if(N(v,{FunctionDeclaration(n){const t=n.node.id?.name;if(!t)return;if(_.has(t))return void(c&&console.log(`[FuncSpan Transform] SKIPPING entry point function: ${t}`));const r=`decl_${t}`;if(g.has(r))return;c&&console.log(`[FuncSpan Transform] Wrapping function declaration: ${t}`);const s=n.node.loc?.start.line??0,l=n.node.loc?.start.column??0,d=L(s,l),{line:m,column:p}=d,u=i,y=$(n.node.params),f=e.callExpression(e.identifier("captureFunctionSpan"),[e.identifier(t),e.stringLiteral(t),e.stringLiteral(u),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(m)),e.objectProperty(e.identifier("column"),e.numericLiteral(p)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(y.map(S=>e.stringLiteral(S))))])]),b=e.expressionStatement(e.assignmentExpression("=",e.identifier(t),f));n.insertAfter(b),x=!0,j++,g.add(r)},VariableDeclarator(n){const t=n.node.id,r=n.node.init;if(!e.isIdentifier(t)||!r||!e.isFunctionExpression(r)&&!e.isArrowFunctionExpression(r))return;const s=t.name;if(_.has(s))return void(c&&console.log(`[FuncSpan Transform] SKIPPING entry point function: ${s}`));const l=`var_${s}`;if(g.has(l))return;c&&console.log(`[FuncSpan Transform] Wrapping variable function: ${s}`);const d=r.loc?.start.line??0,m=r.loc?.start.column??0,p=L(d,m),{line:u,column:y}=p,f=i,b=$(r.params),S=e.callExpression(e.identifier("captureFunctionSpan"),[r,e.stringLiteral(s),e.stringLiteral(f),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(u)),e.objectProperty(e.identifier("column"),e.numericLiteral(y)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(b.map(P=>e.stringLiteral(P))))])]);n.node.init=S,x=!0,j++,g.add(l)},ClassMethod(n){if(n.node.kind==="constructor"||n.node.kind==="get"||n.node.kind==="set")return;const t=e.isIdentifier(n.node.key)?n.node.key.name:"anonymous";let r=!1;if(n.traverse({Super(){r=!0},ClassDeclaration(I){I.skip()},ClassExpression(I){I.skip()}}),r)return void(c&&console.log(`[FuncSpan Transform] SKIPPING class method with super: ${t}`));const s=`method_${t}_${n.node.start}`;if(g.has(s))return;c&&console.log(`[FuncSpan Transform] Wrapping class method: ${t}`);const l=n.node.loc?.start.line??0,d=n.node.loc?.start.column??0,m=L(l,d),{line:p,column:u}=m,y=i,f=$(n.node.params),b=n.node.body,S=e.functionExpression(null,n.node.params,b,n.node.generator,n.node.async),P=e.callExpression(e.identifier("captureFunctionSpan"),[S,e.stringLiteral(t),e.stringLiteral(y),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(p)),e.objectProperty(e.identifier("column"),e.numericLiteral(u)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(f.map(I=>e.stringLiteral(I))))])]),C=e.blockStatement([e.returnStatement(e.callExpression(e.memberExpression(P,e.identifier("call")),[e.thisExpression(),e.spreadElement(e.identifier("arguments"))]))]);n.node.body=C,x=!0,j++,g.add(s)},ObjectMethod(n){if(n.node.kind==="get"||n.node.kind==="set")return;const t=e.isIdentifier(n.node.key)?n.node.key.name:e.isStringLiteral(n.node.key)?n.node.key.value:"anonymous",r=`objmethod_${t}_${n.node.start}`;if(g.has(r))return;c&&console.log(`[FuncSpan Transform] Wrapping object method: ${t}`);const s=n.node.loc?.start.line??0,l=n.node.loc?.start.column??0,d=L(s,l),{line:m,column:p}=d,u=i,y=$(n.node.params),f=e.functionExpression(e.identifier(t),n.node.params,n.node.body,n.node.generator,n.node.async),b=e.callExpression(e.identifier("captureFunctionSpan"),[f,e.stringLiteral(t),e.stringLiteral(u),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(m)),e.objectProperty(e.identifier("column"),e.numericLiteral(p)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(y.map(P=>e.stringLiteral(P))))])]),S=e.objectProperty(n.node.key,b,n.node.computed,!1);n.replaceWith(S),x=!0,j++,g.add(r)},ClassProperty(n){const t=n.node.key,r=n.node.value;if(!e.isIdentifier(t)||!r||!e.isFunctionExpression(r)&&!e.isArrowFunctionExpression(r))return;const s=t.name,l=`classprop_${s}_${n.node.start}`;if(g.has(l))return;c&&console.log(`[FuncSpan Transform] Wrapping class property function: ${s}`);const d=r.loc?.start.line??0,m=r.loc?.start.column??0,p=L(d,m),{line:u,column:y}=p,f=i,b=$(r.params),S=e.callExpression(e.identifier("captureFunctionSpan"),[r,e.stringLiteral(s),e.stringLiteral(f),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(u)),e.objectProperty(e.identifier("column"),e.numericLiteral(y)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(b.map(P=>e.stringLiteral(P))))])]);n.node.value=S,x=!0,j++,g.add(l)},ObjectProperty(n){const t=n.node.key,r=n.node.value;if(!e.isIdentifier(t)&&!e.isStringLiteral(t)||!r||!e.isFunctionExpression(r)&&!e.isArrowFunctionExpression(r))return;const s=e.isIdentifier(t)?t.name:t.value,l=`objprop_${s}_${n.node.start}`;if(g.has(l))return;c&&console.log(`[FuncSpan Transform] Wrapping object property function: ${s}`);const d=r.loc?.start.line??0,m=r.loc?.start.column??0,p=L(d,m),{line:u,column:y}=p,f=i,b=$(r.params),S=e.callExpression(e.identifier("captureFunctionSpan"),[r,e.stringLiteral(s),e.stringLiteral(f),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(u)),e.objectProperty(e.identifier("column"),e.numericLiteral(y)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(b.map(P=>e.stringLiteral(P))))])]);n.node.value=S,x=!0,j++,g.add(l)}}),x&&!R(v))if(z(v)){const n=e.variableDeclaration("const",[e.variableDeclarator(e.objectPattern([e.objectProperty(e.identifier("captureFunctionSpan"),e.identifier("captureFunctionSpan"),!1,!0)]),e.callExpression(e.identifier("require"),[e.stringLiteral("@sailfish-ai/sf-veritas")]))]);v.program.body.unshift(n)}else{const n=e.importDeclaration([e.importSpecifier(e.identifier("captureFunctionSpan"),e.identifier("captureFunctionSpan"))],e.stringLiteral("@sailfish-ai/sf-veritas"));v.program.body.unshift(n)}if(j>0){const n=G(v,{retainLines:!0,compact:!1,sourceMaps:!0,sourceFileName:i},a);return c&&console.log(`[FuncSpan Transform] ✅ Wrapped ${j} functions in ${h}`),{code:n.code,map:n.map,modified:!0,functionsWrapped:j}}return{code:a,modified:!1,functionsWrapped:0}};
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { parse as O } from "@babel/parser";
|
|
2
|
+
import A from "@babel/traverse";
|
|
3
|
+
import D from "@babel/generator";
|
|
4
|
+
import * as e from "@babel/types";
|
|
5
|
+
import { relative as K, resolve as W, dirname as _ } from "path";
|
|
6
|
+
import { readFileSync as J } from "fs";
|
|
7
|
+
import { s as H } from "./source-map-Cr6YkjTd.js";
|
|
8
|
+
const N = /* @__PURE__ */ new Set(["register", "setupInterceptors", "initializeConfigLoader", "initializeWorkerPoolPatching"]), R = [/instrumentation\.(ts|js|tsx|jsx)$/, /unifiedInterceptor\.(ts|js)$/];
|
|
9
|
+
let q = !1;
|
|
10
|
+
function ne(u) {
|
|
11
|
+
q = u;
|
|
12
|
+
}
|
|
13
|
+
const C = A.default || A, V = D.default || D;
|
|
14
|
+
async function ie(u, i, o = {}) {
|
|
15
|
+
const { projectRoot: $ = process.cwd(), includeNodeModules: v = [], debug: a = !1 } = o;
|
|
16
|
+
if (i.includes("node_modules") && !v.some((n) => i.includes(`node_modules/${n}`))) return { code: u, modified: !1, functionsWrapped: 0 };
|
|
17
|
+
if (i.includes("sf-veritas") || i.includes("@sailfish-ai") || i.includes("jsts-backend") || i.includes("jsts-frontend")) return a && console.log(`[FuncSpan Transform] SKIPPING sf-veritas internal file: ${i}`), { code: u, modified: !1, functionsWrapped: 0 };
|
|
18
|
+
if (R.some((n) => n.test(i))) return a && console.log(`[FuncSpan Transform] SKIPPING instrumentation entry point file: ${i}`), { code: u, modified: !1, functionsWrapped: 0 };
|
|
19
|
+
const k = K($, i).replace(/\\/g, "/");
|
|
20
|
+
let F;
|
|
21
|
+
a && console.log(`[FuncSpan Transform] Processing: ${k}`);
|
|
22
|
+
try {
|
|
23
|
+
F = O(u, { sourceType: "module", plugins: ["typescript", "jsx", "decorators-legacy", "classProperties", "objectRestSpread", "asyncGenerators", "dynamicImport", "optionalCatchBinding", "optionalChaining", "nullishCoalescingOperator"] });
|
|
24
|
+
} catch (n) {
|
|
25
|
+
return a && console.error(`[FuncSpan Transform] Parse error in ${k}:`, n), { code: u, modified: !1, functionsWrapped: 0 };
|
|
26
|
+
}
|
|
27
|
+
let h = null, T = null;
|
|
28
|
+
try {
|
|
29
|
+
const n = J(`${i}.map`, "utf-8");
|
|
30
|
+
h = await new H.SourceMapConsumer(JSON.parse(n));
|
|
31
|
+
} catch {
|
|
32
|
+
}
|
|
33
|
+
const L = (n, t) => {
|
|
34
|
+
if (h) {
|
|
35
|
+
const r = h.originalPositionFor({ line: n, column: t });
|
|
36
|
+
if (r.line !== null && r.column !== null) return !T && r.source && (T = r.source), { line: r.line, column: r.column, source: r.source || void 0 };
|
|
37
|
+
}
|
|
38
|
+
return { line: n, column: t };
|
|
39
|
+
};
|
|
40
|
+
let x = !1, S = 0;
|
|
41
|
+
const g = /* @__PURE__ */ new Set();
|
|
42
|
+
if (C(F, { FunctionDeclaration(n) {
|
|
43
|
+
const t = n.node.id?.name;
|
|
44
|
+
if (!t) return;
|
|
45
|
+
if (N.has(t)) return void (a && console.log(`[FuncSpan Transform] SKIPPING entry point function: ${t}`));
|
|
46
|
+
const r = `decl_${t}`;
|
|
47
|
+
if (g.has(r)) return;
|
|
48
|
+
a && console.log(`[FuncSpan Transform] Wrapping function declaration: ${t}`);
|
|
49
|
+
const s = n.node.loc?.start.line ?? 0, c = n.node.loc?.start.column ?? 0, p = L(s, c), { line: m, column: l } = p;
|
|
50
|
+
let d = i;
|
|
51
|
+
p.source && (d = W(_(i), p.source)), !a || m === s && l === c || console.log(`[FuncSpan Transform] Mapped ${s}:${c} → ${m}:${l} in ${d}`);
|
|
52
|
+
const y = E(n.node.params), f = e.callExpression(e.identifier("captureFunctionSpan"), [e.identifier(t), e.stringLiteral(t), e.stringLiteral(d), e.objectExpression([e.objectProperty(e.identifier("line"), e.numericLiteral(m)), e.objectProperty(e.identifier("column"), e.numericLiteral(l)), e.objectProperty(e.identifier("paramNames"), e.arrayExpression(y.map((j) => e.stringLiteral(j))))])]), b = e.expressionStatement(e.assignmentExpression("=", e.identifier(t), f));
|
|
53
|
+
n.insertAfter(b), x = !0, S++, g.add(r);
|
|
54
|
+
}, VariableDeclarator(n) {
|
|
55
|
+
const t = n.node.id, r = n.node.init;
|
|
56
|
+
if (!e.isIdentifier(t) || !r || !e.isFunctionExpression(r) && !e.isArrowFunctionExpression(r)) return;
|
|
57
|
+
const s = t.name;
|
|
58
|
+
if (N.has(s)) return void (a && console.log(`[FuncSpan Transform] SKIPPING entry point function: ${s}`));
|
|
59
|
+
const c = `var_${s}`;
|
|
60
|
+
if (g.has(c)) return;
|
|
61
|
+
a && console.log(`[FuncSpan Transform] Wrapping variable function: ${s}`);
|
|
62
|
+
const p = r.loc?.start.line ?? 0, m = r.loc?.start.column ?? 0, l = L(p, m), { line: d, column: y } = l;
|
|
63
|
+
let f = i;
|
|
64
|
+
l.source && (f = W(_(i), l.source)), !a || d === p && y === m || console.log(`[FuncSpan Transform] Mapped ${p}:${m} → ${d}:${y} in ${f}`);
|
|
65
|
+
const b = E(r.params), j = e.callExpression(e.identifier("captureFunctionSpan"), [r, e.stringLiteral(s), e.stringLiteral(f), e.objectExpression([e.objectProperty(e.identifier("line"), e.numericLiteral(d)), e.objectProperty(e.identifier("column"), e.numericLiteral(y)), e.objectProperty(e.identifier("paramNames"), e.arrayExpression(b.map((P) => e.stringLiteral(P))))])]);
|
|
66
|
+
n.node.init = j, x = !0, S++, g.add(c);
|
|
67
|
+
}, ClassMethod(n) {
|
|
68
|
+
if (n.node.kind === "constructor" || n.node.kind === "get" || n.node.kind === "set") return;
|
|
69
|
+
const t = e.isIdentifier(n.node.key) ? n.node.key.name : "anonymous";
|
|
70
|
+
let r = !1;
|
|
71
|
+
if (n.traverse({ Super() {
|
|
72
|
+
r = !0;
|
|
73
|
+
}, ClassDeclaration(I) {
|
|
74
|
+
I.skip();
|
|
75
|
+
}, ClassExpression(I) {
|
|
76
|
+
I.skip();
|
|
77
|
+
} }), r) return void (a && console.log(`[FuncSpan Transform] SKIPPING class method with super: ${t}`));
|
|
78
|
+
const s = `method_${t}_${n.node.start}`;
|
|
79
|
+
if (g.has(s)) return;
|
|
80
|
+
a && console.log(`[FuncSpan Transform] Wrapping class method: ${t}`);
|
|
81
|
+
const c = n.node.loc?.start.line ?? 0, p = n.node.loc?.start.column ?? 0, m = L(c, p), { line: l, column: d } = m, y = i, f = E(n.node.params), b = n.node.body, j = e.functionExpression(null, n.node.params, b, n.node.generator, n.node.async), P = e.callExpression(e.identifier("captureFunctionSpan"), [j, e.stringLiteral(t), e.stringLiteral(y), e.objectExpression([e.objectProperty(e.identifier("line"), e.numericLiteral(l)), e.objectProperty(e.identifier("column"), e.numericLiteral(d)), e.objectProperty(e.identifier("paramNames"), e.arrayExpression(f.map((I) => e.stringLiteral(I))))])]), w = e.blockStatement([e.returnStatement(e.callExpression(e.memberExpression(P, e.identifier("call")), [e.thisExpression(), e.spreadElement(e.identifier("arguments"))]))]);
|
|
82
|
+
n.node.body = w, x = !0, S++, g.add(s);
|
|
83
|
+
}, ObjectMethod(n) {
|
|
84
|
+
if (n.node.kind === "get" || n.node.kind === "set") return;
|
|
85
|
+
const t = e.isIdentifier(n.node.key) ? n.node.key.name : e.isStringLiteral(n.node.key) ? n.node.key.value : "anonymous", r = `objmethod_${t}_${n.node.start}`;
|
|
86
|
+
if (g.has(r)) return;
|
|
87
|
+
a && console.log(`[FuncSpan Transform] Wrapping object method: ${t}`);
|
|
88
|
+
const s = n.node.loc?.start.line ?? 0, c = n.node.loc?.start.column ?? 0, p = L(s, c), { line: m, column: l } = p;
|
|
89
|
+
let d = i;
|
|
90
|
+
p.source && (d = W(_(i), p.source));
|
|
91
|
+
const y = E(n.node.params), f = e.functionExpression(e.identifier(t), n.node.params, n.node.body, n.node.generator, n.node.async), b = e.callExpression(e.identifier("captureFunctionSpan"), [f, e.stringLiteral(t), e.stringLiteral(d), e.objectExpression([e.objectProperty(e.identifier("line"), e.numericLiteral(m)), e.objectProperty(e.identifier("column"), e.numericLiteral(l)), e.objectProperty(e.identifier("paramNames"), e.arrayExpression(y.map((P) => e.stringLiteral(P))))])]), j = e.objectProperty(n.node.key, b, n.node.computed, !1);
|
|
92
|
+
n.replaceWith(j), x = !0, S++, g.add(r);
|
|
93
|
+
}, ClassProperty(n) {
|
|
94
|
+
const t = n.node.key, r = n.node.value;
|
|
95
|
+
if (!e.isIdentifier(t) || !r || !e.isFunctionExpression(r) && !e.isArrowFunctionExpression(r)) return;
|
|
96
|
+
const s = t.name, c = `classprop_${s}_${n.node.start}`;
|
|
97
|
+
if (g.has(c)) return;
|
|
98
|
+
a && console.log(`[FuncSpan Transform] Wrapping class property function: ${s}`);
|
|
99
|
+
const p = r.loc?.start.line ?? 0, m = r.loc?.start.column ?? 0, l = L(p, m), { line: d, column: y } = l;
|
|
100
|
+
let f = i;
|
|
101
|
+
l.source && (f = W(_(i), l.source));
|
|
102
|
+
const b = E(r.params), j = e.callExpression(e.identifier("captureFunctionSpan"), [r, e.stringLiteral(s), e.stringLiteral(f), e.objectExpression([e.objectProperty(e.identifier("line"), e.numericLiteral(d)), e.objectProperty(e.identifier("column"), e.numericLiteral(y)), e.objectProperty(e.identifier("paramNames"), e.arrayExpression(b.map((P) => e.stringLiteral(P))))])]);
|
|
103
|
+
n.node.value = j, x = !0, S++, g.add(c);
|
|
104
|
+
}, ObjectProperty(n) {
|
|
105
|
+
const t = n.node.key, r = n.node.value;
|
|
106
|
+
if (!e.isIdentifier(t) && !e.isStringLiteral(t) || !r || !e.isFunctionExpression(r) && !e.isArrowFunctionExpression(r)) return;
|
|
107
|
+
const s = e.isIdentifier(t) ? t.name : t.value, c = `objprop_${s}_${n.node.start}`;
|
|
108
|
+
if (g.has(c)) return;
|
|
109
|
+
a && console.log(`[FuncSpan Transform] Wrapping object property function: ${s}`);
|
|
110
|
+
const p = r.loc?.start.line ?? 0, m = r.loc?.start.column ?? 0, l = L(p, m), { line: d, column: y } = l;
|
|
111
|
+
let f = i;
|
|
112
|
+
l.source && (f = W(_(i), l.source));
|
|
113
|
+
const b = E(r.params), j = e.callExpression(e.identifier("captureFunctionSpan"), [r, e.stringLiteral(s), e.stringLiteral(f), e.objectExpression([e.objectProperty(e.identifier("line"), e.numericLiteral(d)), e.objectProperty(e.identifier("column"), e.numericLiteral(y)), e.objectProperty(e.identifier("paramNames"), e.arrayExpression(b.map((P) => e.stringLiteral(P))))])]);
|
|
114
|
+
n.node.value = j, x = !0, S++, g.add(c);
|
|
115
|
+
} }), x && !z(F)) if (B(F)) {
|
|
116
|
+
const n = e.variableDeclaration("const", [e.variableDeclarator(e.objectPattern([e.objectProperty(e.identifier("captureFunctionSpan"), e.identifier("captureFunctionSpan"), !1, !0)]), e.callExpression(e.identifier("require"), [e.stringLiteral("@sailfish-ai/sf-veritas")]))]);
|
|
117
|
+
F.program.body.unshift(n);
|
|
118
|
+
} else {
|
|
119
|
+
const n = e.importDeclaration([e.importSpecifier(e.identifier("captureFunctionSpan"), e.identifier("captureFunctionSpan"))], e.stringLiteral("@sailfish-ai/sf-veritas"));
|
|
120
|
+
F.program.body.unshift(n);
|
|
121
|
+
}
|
|
122
|
+
if (S > 0) {
|
|
123
|
+
const n = V(F, { retainLines: !0, compact: !1, sourceMaps: !0, sourceFileName: i }, u);
|
|
124
|
+
return a && console.log(`[FuncSpan Transform] ✅ Wrapped ${S} functions in ${k}`), { code: n.code, map: n.map, modified: !0, functionsWrapped: S };
|
|
125
|
+
}
|
|
126
|
+
return { code: u, modified: !1, functionsWrapped: 0 };
|
|
127
|
+
}
|
|
128
|
+
function re(u, i, o = {}) {
|
|
129
|
+
const { projectRoot: $ = process.cwd(), includeNodeModules: v = [], debug: a = !1, parseAsJavaScript: k = !1 } = o;
|
|
130
|
+
if (i.includes("node_modules") && !v.some((n) => i.includes(`node_modules/${n}`))) return { code: u, modified: !1, functionsWrapped: 0 };
|
|
131
|
+
if (i.includes("sf-veritas") || i.includes("@sailfish-ai") || i.includes("jsts-backend") || i.includes("jsts-frontend")) return a && console.log(`[FuncSpan Transform] SKIPPING sf-veritas internal file: ${i}`), { code: u, modified: !1, functionsWrapped: 0 };
|
|
132
|
+
if (R.some((n) => n.test(i))) return a && console.log(`[FuncSpan Transform] SKIPPING instrumentation entry point file: ${i}`), { code: u, modified: !1, functionsWrapped: 0 };
|
|
133
|
+
const F = K($, i).replace(/\\/g, "/");
|
|
134
|
+
let h;
|
|
135
|
+
a && console.log(`[FuncSpan Transform] Processing: ${F}`);
|
|
136
|
+
const T = ["jsx", "decorators-legacy", "classProperties", "objectRestSpread", "asyncGenerators", "dynamicImport", "optionalCatchBinding", "optionalChaining", "nullishCoalescingOperator"];
|
|
137
|
+
q || k || T.unshift("typescript");
|
|
138
|
+
try {
|
|
139
|
+
h = O(u, { sourceType: "module", plugins: T });
|
|
140
|
+
} catch (n) {
|
|
141
|
+
return a && console.error(`[FuncSpan Transform] Parse error in ${F}:`, n), { code: u, modified: !1, functionsWrapped: 0 };
|
|
142
|
+
}
|
|
143
|
+
const L = (n, t) => ({ line: n, column: t });
|
|
144
|
+
let x = !1, S = 0;
|
|
145
|
+
const g = /* @__PURE__ */ new Set();
|
|
146
|
+
if (C(h, { FunctionDeclaration(n) {
|
|
147
|
+
const t = n.node.id?.name;
|
|
148
|
+
if (!t) return;
|
|
149
|
+
if (N.has(t)) return void (a && console.log(`[FuncSpan Transform] SKIPPING entry point function: ${t}`));
|
|
150
|
+
const r = `decl_${t}`;
|
|
151
|
+
if (g.has(r)) return;
|
|
152
|
+
a && console.log(`[FuncSpan Transform] Wrapping function declaration: ${t}`);
|
|
153
|
+
const s = n.node.loc?.start.line ?? 0, c = n.node.loc?.start.column ?? 0, p = L(s, c), { line: m, column: l } = p, d = i, y = E(n.node.params), f = e.callExpression(e.identifier("captureFunctionSpan"), [e.identifier(t), e.stringLiteral(t), e.stringLiteral(d), e.objectExpression([e.objectProperty(e.identifier("line"), e.numericLiteral(m)), e.objectProperty(e.identifier("column"), e.numericLiteral(l)), e.objectProperty(e.identifier("paramNames"), e.arrayExpression(y.map((j) => e.stringLiteral(j))))])]), b = e.expressionStatement(e.assignmentExpression("=", e.identifier(t), f));
|
|
154
|
+
n.insertAfter(b), x = !0, S++, g.add(r);
|
|
155
|
+
}, VariableDeclarator(n) {
|
|
156
|
+
const t = n.node.id, r = n.node.init;
|
|
157
|
+
if (!e.isIdentifier(t) || !r || !e.isFunctionExpression(r) && !e.isArrowFunctionExpression(r)) return;
|
|
158
|
+
const s = t.name;
|
|
159
|
+
if (N.has(s)) return void (a && console.log(`[FuncSpan Transform] SKIPPING entry point function: ${s}`));
|
|
160
|
+
const c = `var_${s}`;
|
|
161
|
+
if (g.has(c)) return;
|
|
162
|
+
a && console.log(`[FuncSpan Transform] Wrapping variable function: ${s}`);
|
|
163
|
+
const p = r.loc?.start.line ?? 0, m = r.loc?.start.column ?? 0, l = L(p, m), { line: d, column: y } = l, f = i, b = E(r.params), j = e.callExpression(e.identifier("captureFunctionSpan"), [r, e.stringLiteral(s), e.stringLiteral(f), e.objectExpression([e.objectProperty(e.identifier("line"), e.numericLiteral(d)), e.objectProperty(e.identifier("column"), e.numericLiteral(y)), e.objectProperty(e.identifier("paramNames"), e.arrayExpression(b.map((P) => e.stringLiteral(P))))])]);
|
|
164
|
+
n.node.init = j, x = !0, S++, g.add(c);
|
|
165
|
+
}, ClassMethod(n) {
|
|
166
|
+
if (n.node.kind === "constructor" || n.node.kind === "get" || n.node.kind === "set") return;
|
|
167
|
+
const t = e.isIdentifier(n.node.key) ? n.node.key.name : "anonymous";
|
|
168
|
+
let r = !1;
|
|
169
|
+
if (n.traverse({ Super() {
|
|
170
|
+
r = !0;
|
|
171
|
+
}, ClassDeclaration(I) {
|
|
172
|
+
I.skip();
|
|
173
|
+
}, ClassExpression(I) {
|
|
174
|
+
I.skip();
|
|
175
|
+
} }), r) return void (a && console.log(`[FuncSpan Transform] SKIPPING class method with super: ${t}`));
|
|
176
|
+
const s = `method_${t}_${n.node.start}`;
|
|
177
|
+
if (g.has(s)) return;
|
|
178
|
+
a && console.log(`[FuncSpan Transform] Wrapping class method: ${t}`);
|
|
179
|
+
const c = n.node.loc?.start.line ?? 0, p = n.node.loc?.start.column ?? 0, m = L(c, p), { line: l, column: d } = m, y = i, f = E(n.node.params), b = n.node.body, j = e.functionExpression(null, n.node.params, b, n.node.generator, n.node.async), P = e.callExpression(e.identifier("captureFunctionSpan"), [j, e.stringLiteral(t), e.stringLiteral(y), e.objectExpression([e.objectProperty(e.identifier("line"), e.numericLiteral(l)), e.objectProperty(e.identifier("column"), e.numericLiteral(d)), e.objectProperty(e.identifier("paramNames"), e.arrayExpression(f.map((I) => e.stringLiteral(I))))])]), w = e.blockStatement([e.returnStatement(e.callExpression(e.memberExpression(P, e.identifier("call")), [e.thisExpression(), e.spreadElement(e.identifier("arguments"))]))]);
|
|
180
|
+
n.node.body = w, x = !0, S++, g.add(s);
|
|
181
|
+
}, ObjectMethod(n) {
|
|
182
|
+
if (n.node.kind === "get" || n.node.kind === "set") return;
|
|
183
|
+
const t = e.isIdentifier(n.node.key) ? n.node.key.name : e.isStringLiteral(n.node.key) ? n.node.key.value : "anonymous", r = `objmethod_${t}_${n.node.start}`;
|
|
184
|
+
if (g.has(r)) return;
|
|
185
|
+
a && console.log(`[FuncSpan Transform] Wrapping object method: ${t}`);
|
|
186
|
+
const s = n.node.loc?.start.line ?? 0, c = n.node.loc?.start.column ?? 0, p = L(s, c), { line: m, column: l } = p, d = i, y = E(n.node.params), f = e.functionExpression(e.identifier(t), n.node.params, n.node.body, n.node.generator, n.node.async), b = e.callExpression(e.identifier("captureFunctionSpan"), [f, e.stringLiteral(t), e.stringLiteral(d), e.objectExpression([e.objectProperty(e.identifier("line"), e.numericLiteral(m)), e.objectProperty(e.identifier("column"), e.numericLiteral(l)), e.objectProperty(e.identifier("paramNames"), e.arrayExpression(y.map((P) => e.stringLiteral(P))))])]), j = e.objectProperty(n.node.key, b, n.node.computed, !1);
|
|
187
|
+
n.replaceWith(j), x = !0, S++, g.add(r);
|
|
188
|
+
}, ClassProperty(n) {
|
|
189
|
+
const t = n.node.key, r = n.node.value;
|
|
190
|
+
if (!e.isIdentifier(t) || !r || !e.isFunctionExpression(r) && !e.isArrowFunctionExpression(r)) return;
|
|
191
|
+
const s = t.name, c = `classprop_${s}_${n.node.start}`;
|
|
192
|
+
if (g.has(c)) return;
|
|
193
|
+
a && console.log(`[FuncSpan Transform] Wrapping class property function: ${s}`);
|
|
194
|
+
const p = r.loc?.start.line ?? 0, m = r.loc?.start.column ?? 0, l = L(p, m), { line: d, column: y } = l, f = i, b = E(r.params), j = e.callExpression(e.identifier("captureFunctionSpan"), [r, e.stringLiteral(s), e.stringLiteral(f), e.objectExpression([e.objectProperty(e.identifier("line"), e.numericLiteral(d)), e.objectProperty(e.identifier("column"), e.numericLiteral(y)), e.objectProperty(e.identifier("paramNames"), e.arrayExpression(b.map((P) => e.stringLiteral(P))))])]);
|
|
195
|
+
n.node.value = j, x = !0, S++, g.add(c);
|
|
196
|
+
}, ObjectProperty(n) {
|
|
197
|
+
const t = n.node.key, r = n.node.value;
|
|
198
|
+
if (!e.isIdentifier(t) && !e.isStringLiteral(t) || !r || !e.isFunctionExpression(r) && !e.isArrowFunctionExpression(r)) return;
|
|
199
|
+
const s = e.isIdentifier(t) ? t.name : t.value, c = `objprop_${s}_${n.node.start}`;
|
|
200
|
+
if (g.has(c)) return;
|
|
201
|
+
a && console.log(`[FuncSpan Transform] Wrapping object property function: ${s}`);
|
|
202
|
+
const p = r.loc?.start.line ?? 0, m = r.loc?.start.column ?? 0, l = L(p, m), { line: d, column: y } = l, f = i, b = E(r.params), j = e.callExpression(e.identifier("captureFunctionSpan"), [r, e.stringLiteral(s), e.stringLiteral(f), e.objectExpression([e.objectProperty(e.identifier("line"), e.numericLiteral(d)), e.objectProperty(e.identifier("column"), e.numericLiteral(y)), e.objectProperty(e.identifier("paramNames"), e.arrayExpression(b.map((P) => e.stringLiteral(P))))])]);
|
|
203
|
+
n.node.value = j, x = !0, S++, g.add(c);
|
|
204
|
+
} }), x && !z(h)) if (B(h)) {
|
|
205
|
+
const n = e.variableDeclaration("const", [e.variableDeclarator(e.objectPattern([e.objectProperty(e.identifier("captureFunctionSpan"), e.identifier("captureFunctionSpan"), !1, !0)]), e.callExpression(e.identifier("require"), [e.stringLiteral("@sailfish-ai/sf-veritas")]))]);
|
|
206
|
+
h.program.body.unshift(n);
|
|
207
|
+
} else {
|
|
208
|
+
const n = e.importDeclaration([e.importSpecifier(e.identifier("captureFunctionSpan"), e.identifier("captureFunctionSpan"))], e.stringLiteral("@sailfish-ai/sf-veritas"));
|
|
209
|
+
h.program.body.unshift(n);
|
|
210
|
+
}
|
|
211
|
+
if (S > 0) {
|
|
212
|
+
const n = V(h, { retainLines: !0, compact: !1, sourceMaps: !0, sourceFileName: i }, u);
|
|
213
|
+
return a && console.log(`[FuncSpan Transform] ✅ Wrapped ${S} functions in ${F}`), { code: n.code, map: n.map, modified: !0, functionsWrapped: S };
|
|
214
|
+
}
|
|
215
|
+
return { code: u, modified: !1, functionsWrapped: 0 };
|
|
216
|
+
}
|
|
217
|
+
function E(u) {
|
|
218
|
+
const i = [];
|
|
219
|
+
for (const o of u) e.isIdentifier(o) ? i.push(o.name) : e.isRestElement(o) && e.isIdentifier(o.argument) ? i.push(`...${o.argument.name}`) : e.isAssignmentPattern(o) && e.isIdentifier(o.left) ? i.push(o.left.name) : e.isAssignmentPattern(o) && e.isObjectPattern(o.left) ? i.push(G(o.left)) : e.isAssignmentPattern(o) && e.isArrayPattern(o.left) ? i.push(M(o.left)) : e.isObjectPattern(o) ? i.push(G(o)) : e.isArrayPattern(o) ? i.push(M(o)) : i.push("_");
|
|
220
|
+
return i;
|
|
221
|
+
}
|
|
222
|
+
function G(u) {
|
|
223
|
+
return `{${u.properties.map((i) => e.isRestElement(i) ? `...${e.isIdentifier(i.argument) ? i.argument.name : "_"}` : e.isObjectProperty(i) && e.isIdentifier(i.key) ? i.key.name : "_").join(", ")}}`;
|
|
224
|
+
}
|
|
225
|
+
function M(u) {
|
|
226
|
+
return `[${u.elements.map((i) => i === null ? "_" : e.isIdentifier(i) ? i.name : e.isRestElement(i) && e.isIdentifier(i.argument) ? `...${i.argument.name}` : "_").join(", ")}]`;
|
|
227
|
+
}
|
|
228
|
+
function z(u) {
|
|
229
|
+
let i = !1;
|
|
230
|
+
return C(u, { ImportDeclaration(o) {
|
|
231
|
+
e.isStringLiteral(o.node.source) && o.node.source.value === "@sailfish-ai/sf-veritas" && o.node.specifiers.some(($) => e.isImportSpecifier($) && e.isIdentifier($.imported) && $.imported.name === "captureFunctionSpan") && (i = !0, o.stop());
|
|
232
|
+
}, VariableDeclarator(o) {
|
|
233
|
+
if (e.isObjectPattern(o.node.id) && e.isCallExpression(o.node.init) && e.isIdentifier(o.node.init.callee) && o.node.init.callee.name === "require") {
|
|
234
|
+
const $ = o.node.init.arguments;
|
|
235
|
+
$.length > 0 && e.isStringLiteral($[0]) && $[0].value === "@sailfish-ai/sf-veritas" && o.node.id.properties.some((v) => e.isObjectProperty(v) && e.isIdentifier(v.key) && v.key.name === "captureFunctionSpan") && (i = !0, o.stop());
|
|
236
|
+
}
|
|
237
|
+
} }), i;
|
|
238
|
+
}
|
|
239
|
+
function B(u) {
|
|
240
|
+
let i = !1;
|
|
241
|
+
return C(u, { CallExpression(o) {
|
|
242
|
+
e.isIdentifier(o.node.callee) && o.node.callee.name === "require" && (i = !0, o.stop());
|
|
243
|
+
}, MemberExpression(o) {
|
|
244
|
+
!e.isIdentifier(o.node.object) || o.node.object.name !== "module" && o.node.object.name !== "exports" || (i = !0, o.stop());
|
|
245
|
+
} }), i;
|
|
246
|
+
}
|
|
247
|
+
export {
|
|
248
|
+
re as a,
|
|
249
|
+
ne as s,
|
|
250
|
+
ie as t
|
|
251
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const d=require("fs"),r=require("../funcSpanTransformer-
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const d=require("fs"),r=require("../funcSpanTransformer-D0W2t41q.cjs"),c=require("../runtimeConfig-B8LSswM8.cjs");function l(o={}){try{if(c.shouldEnableRuntimeHooks())return console.warn("[FuncSpan Esbuild Plugin] Runtime mode active - build plugin DISABLED to prevent double-instrumentation"),{name:"sailfish-funcspan-esbuild-disabled",setup(){}}}catch{}const{enabled:a=!0,includeNodeModules:i=[],debug:t=!1}=o;return{name:"sailfish-funcspan-esbuild",setup(u){a&&(u.onLoad({filter:/\.(js|ts|jsx|tsx)$/},async e=>{if(e.path.includes("node_modules")&&!i.some(n=>e.path.includes(`node_modules/${n}`))||e.path.includes("@sailfish-ai/sf-veritas")||e.path.includes("jsts-backend/dist"))return null;try{const n=d.readFileSync(e.path,"utf-8"),s=await r.transformFunctionSpans(n,e.path,{projectRoot:process.cwd(),includeNodeModules:i,debug:t});if(s.modified)return{contents:s.code,loader:e.path.endsWith(".ts")||e.path.endsWith(".tsx")?"ts":"js"}}catch(n){t&&console.error(`[FuncSpan Esbuild] Error transforming ${e.path}:`,n)}return null}),t&&console.log("[FuncSpan Esbuild] Plugin initialized"))}}}exports.default=l,exports.funcspanEsbuildPlugin=l;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFileSync as l } from "fs";
|
|
2
|
-
import { t as d } from "../funcSpanTransformer-
|
|
3
|
-
import { s as r } from "../runtimeConfig-
|
|
2
|
+
import { t as d } from "../funcSpanTransformer-S_WeAt_m.js";
|
|
3
|
+
import { s as r } from "../runtimeConfig-GwWjhV9M.js";
|
|
4
4
|
function h(o = {}) {
|
|
5
5
|
try {
|
|
6
6
|
if (r()) return console.warn("[FuncSpan Esbuild Plugin] Runtime mode active - build plugin DISABLED to prevent double-instrumentation"), { name: "sailfish-funcspan-esbuild-disabled", setup() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=require("../funcSpanTransformer-
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=require("../funcSpanTransformer-D0W2t41q.cjs"),a=require("../runtimeConfig-B8LSswM8.cjs");function s(o={}){try{if(a.shouldEnableRuntimeHooks())return console.warn("[FuncSpan Rollup Plugin] Runtime mode active - build plugin DISABLED to prevent double-instrumentation"),{name:"sailfish-funcspan-rollup-disabled"}}catch{}const{enabled:t=!0,includeNodeModules:l=[],debug:u=!1}=o;return{name:"sailfish-funcspan-rollup",async transform(r,e){if(!t||!e.match(/\.(js|ts|jsx|tsx)$/)||e.includes("node_modules")&&!l.some(n=>e.includes(`node_modules/${n}`))||e.includes("@sailfish-ai/sf-veritas")||e.includes("jsts-backend/dist"))return null;try{const n=await i.transformFunctionSpans(r,e,{projectRoot:process.cwd(),includeNodeModules:l,debug:u});if(n.modified)return{code:n.code,map:n.map||null}}catch(n){u&&console.error(`[FuncSpan Rollup] Error transforming ${e}:`,n)}return null}}}exports.default=s,exports.funcspanRollupPlugin=s;
|