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