@sailfish-ai/sf-veritas 0.2.6 → 0.2.9
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-CEPhVu9T.js +197 -0
- package/dist/contextManager-CGINtRN5.cjs +1 -0
- package/dist/funcSpanTransformer-B9WWl-g1.cjs +1 -0
- package/dist/funcSpanTransformer-CWNEWRxq.js +225 -0
- package/dist/plugins/funcspanEsbuildPlugin.cjs +1 -1
- package/dist/plugins/funcspanEsbuildPlugin.mjs +17 -11
- package/dist/plugins/funcspanRollupPlugin.cjs +1 -1
- package/dist/plugins/funcspanRollupPlugin.mjs +13 -8
- package/dist/plugins/funcspanTscPlugin.cjs +1 -1
- package/dist/plugins/funcspanTscPlugin.mjs +19 -14
- package/dist/plugins/funcspanVitePlugin.cjs +1 -1
- package/dist/plugins/funcspanVitePlugin.mjs +15 -10
- 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 +22 -17
- package/dist/runtime/funcspanRegister.cjs +276 -0
- package/dist/runtimeConfig-CpQ27dZD.cjs +8 -0
- package/dist/runtimeConfig-emBNO3lJ.js +350 -0
- package/dist/sf-veritas.cjs +18 -18
- package/dist/sf-veritas.mjs +461 -620
- package/dist/source-map-Cr6YkjTd.js +631 -0
- package/dist/source-map-rHHEdpre.cjs +1 -0
- package/dist/types/dataTransmitter.d.ts +1 -0
- package/dist/types/funcSpanConfig.d.ts +8 -0
- package/dist/types/funcSpanConfigLoader.d.ts +10 -0
- package/dist/types/index.d.ts +4 -2
- package/dist/types/logHandler.d.ts +5 -0
- package/dist/types/plugins/funcSpanTransformer.d.ts +13 -0
- package/dist/types/runtime/instrumentationDetector.d.ts +33 -0
- package/dist/types/runtime/runtimeConfig.d.ts +48 -0
- package/dist/types/sourceLocation.d.ts +30 -0
- package/dist/types/unifiedInterceptor.d.ts +4 -0
- package/dist/worker-pool-capture.cjs +1 -1
- package/dist/worker-pool-capture.mjs +1 -1
- package/dist/workerPoolSpanCapture-B5KN-q4b.js +528 -0
- package/dist/workerPoolSpanCapture-Dg_WGjmO.cjs +86 -0
- package/package.json +5 -2
- package/dist/funcSpanTransformer-TjdooSrw.cjs +0 -1
- package/dist/funcSpanTransformer-sqmZLAcs.js +0 -750
- package/dist/workerPoolSpanCapture-BOnYC4s3.js +0 -705
- package/dist/workerPoolSpanCapture-CNEouInA.cjs +0 -83
package/dist/sf-veritas.mjs
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
|
-
var
|
|
2
|
-
var fe = (
|
|
3
|
-
var
|
|
4
|
-
import {
|
|
5
|
-
import { r as
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import {
|
|
14
|
-
|
|
1
|
+
var pe = Object.defineProperty;
|
|
2
|
+
var fe = (n, e, t) => e in n ? pe(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
|
|
3
|
+
var S = (n, e, t) => fe(n, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { g as l, C as J, D as he, v as ie, b as q, c as ge, a as ae } from "./contextManager-CEPhVu9T.js";
|
|
5
|
+
import { r as ft } from "./contextManager-CEPhVu9T.js";
|
|
6
|
+
import { B as D, n as F, f as me, g as ce, p as de, a as le, b as Se, m as P, c as R, d as ye, i as C, t as M, F as Ie } from "./workerPoolSpanCapture-B5KN-q4b.js";
|
|
7
|
+
import { e as gt, s as mt } from "./workerPoolSpanCapture-B5KN-q4b.js";
|
|
8
|
+
import { C as _e, i as _, a as $e, h as b, b as ve, c as be } from "./runtimeConfig-emBNO3lJ.js";
|
|
9
|
+
import { e as yt, d as It, s as _t } from "./runtimeConfig-emBNO3lJ.js";
|
|
10
|
+
import { createRequire as Fe } from "node:module";
|
|
11
|
+
import * as H from "fs";
|
|
12
|
+
import { readFileSync as Ne, appendFileSync as De } from "fs";
|
|
13
|
+
import { s as we } from "./source-map-Cr6YkjTd.js";
|
|
14
|
+
import * as $ from "path";
|
|
15
|
+
import { glob as Ee } from "glob";
|
|
16
|
+
import { threadId as T } from "worker_threads";
|
|
17
|
+
import { s as vt, t as bt, a as Ft } from "./funcSpanTransformer-CWNEWRxq.js";
|
|
18
|
+
class E extends D {
|
|
15
19
|
constructor() {
|
|
16
20
|
super(), this.setOperationName("IdentifyServiceDetails");
|
|
17
21
|
}
|
|
18
22
|
async doSend(e) {
|
|
19
|
-
if (!
|
|
23
|
+
if (!l().serviceIdentificationReceived) try {
|
|
20
24
|
this.send();
|
|
21
25
|
} catch (t) {
|
|
22
|
-
|
|
26
|
+
l().sfDebug && console.error(" Error during service identification:", t);
|
|
23
27
|
}
|
|
24
28
|
}
|
|
25
29
|
async send() {
|
|
@@ -47,42 +51,42 @@ class Y extends F {
|
|
|
47
51
|
gitSha: $gitSha,
|
|
48
52
|
)
|
|
49
53
|
}
|
|
50
|
-
`, t = this.getVariables({ serviceIdentifier:
|
|
51
|
-
|
|
54
|
+
`, t = this.getVariables({ serviceIdentifier: l().serviceIdentifier, serviceVersion: l().serviceVersion, library: l().packageLibraryType, version: l().version, serviceAdditionalMetadata: l().serviceAdditionalMetadata, gitSha: l().gitSha || "" });
|
|
55
|
+
F(this.endpoint, this.operationName, e, t);
|
|
52
56
|
}
|
|
53
57
|
}
|
|
54
|
-
function
|
|
58
|
+
function Pe(n) {
|
|
55
59
|
try {
|
|
56
|
-
return JSON.stringify(
|
|
60
|
+
return JSON.stringify(n), !0;
|
|
57
61
|
} catch {
|
|
58
62
|
return !1;
|
|
59
63
|
}
|
|
60
64
|
}
|
|
61
|
-
class
|
|
65
|
+
class Ce extends D {
|
|
62
66
|
constructor() {
|
|
63
67
|
super();
|
|
64
|
-
|
|
68
|
+
S(this, "serviceIdentifier", new E());
|
|
65
69
|
this.setOperationName("CollectMetadata");
|
|
66
70
|
}
|
|
67
71
|
async sendAppIdentifier() {
|
|
68
72
|
this.serviceIdentifier.doSend({});
|
|
69
73
|
}
|
|
70
|
-
async doSend(t, s,
|
|
71
|
-
this.sendAppIdentifier(), this.send(t, s,
|
|
74
|
+
async doSend(t, s, r, o) {
|
|
75
|
+
this.sendAppIdentifier(), this.send(t, s, r, o);
|
|
72
76
|
}
|
|
73
|
-
async send(t, s,
|
|
74
|
-
if (!s && !
|
|
75
|
-
let
|
|
76
|
-
if (!
|
|
77
|
+
async send(t, s, r, o) {
|
|
78
|
+
if (!s && !o) throw new Error('Must pass in either traits or traits_json to "add_or_update_traits"');
|
|
79
|
+
let d = [];
|
|
80
|
+
if (!o) {
|
|
77
81
|
const c = (function(a) {
|
|
78
|
-
const
|
|
79
|
-
if (a) for (const [
|
|
80
|
-
return { traitsJson: JSON.stringify(
|
|
82
|
+
const u = {}, f = [];
|
|
83
|
+
if (a) for (const [h, m] of Object.entries(a)) Pe(m) ? u[h] = m : f.push(h);
|
|
84
|
+
return { traitsJson: JSON.stringify(u), excludedFields: f };
|
|
81
85
|
})(s);
|
|
82
|
-
|
|
86
|
+
o = c.traitsJson, d = c.excludedFields;
|
|
83
87
|
}
|
|
84
|
-
const
|
|
85
|
-
|
|
88
|
+
const i = this.getVariables({ userId: t, traitsJson: o, excludedFields: d, override: r, library: l().packageLibraryType, version: l().version });
|
|
89
|
+
F(this.endpoint, this.operationName, this.getQuery(), i);
|
|
86
90
|
}
|
|
87
91
|
getQuery() {
|
|
88
92
|
return `
|
|
@@ -92,23 +96,23 @@ class Ye extends F {
|
|
|
92
96
|
`;
|
|
93
97
|
}
|
|
94
98
|
}
|
|
95
|
-
class
|
|
99
|
+
class ue {
|
|
96
100
|
constructor(e) {
|
|
97
|
-
|
|
98
|
-
this.apiKey = e, this.metadataTransmitter = new
|
|
101
|
+
S(this, "metadataTransmitter");
|
|
102
|
+
this.apiKey = e, this.metadataTransmitter = new Ce();
|
|
99
103
|
}
|
|
100
|
-
identify(e, t, s,
|
|
101
|
-
t || s ? this.addOrUpdateMetadata(e, t, s,
|
|
104
|
+
identify(e, t, s, r = !1) {
|
|
105
|
+
t || s ? this.addOrUpdateMetadata(e, t, s, r) : this.addOrUpdateMetadata(e, {}, void 0, r);
|
|
102
106
|
}
|
|
103
|
-
addOrUpdateMetadata(e, t = {}, s,
|
|
107
|
+
addOrUpdateMetadata(e, t = {}, s, r = !1) {
|
|
104
108
|
if (!t && !s) throw new Error('Must pass in either traits or traitsJson to "addOrUpdateMetadata"');
|
|
105
|
-
|
|
109
|
+
l().sfDebug && console.log(" [[DEBUG - addOrUpdateMetadata]] Starting operation"), l().sfDebug && console.log(" addOrUpdateMetadata...SENDING DATA...", e, t, s), this.metadataTransmitter.doSend(e, t, r, s);
|
|
106
110
|
}
|
|
107
111
|
}
|
|
108
|
-
class
|
|
112
|
+
class V extends D {
|
|
109
113
|
constructor() {
|
|
110
114
|
super();
|
|
111
|
-
|
|
115
|
+
S(this, "serviceIdentifier", new E());
|
|
112
116
|
}
|
|
113
117
|
async sendAppIdentifier() {
|
|
114
118
|
this.serviceIdentifier.doSend({});
|
|
@@ -118,10 +122,10 @@ class Q extends F {
|
|
|
118
122
|
}
|
|
119
123
|
async send(t) {
|
|
120
124
|
try {
|
|
121
|
-
const s = Array.isArray(t) ? t : [t, "default"],
|
|
122
|
-
|
|
125
|
+
const s = Array.isArray(t) ? t : [t, "default", null, null], r = this.getVariables({ contents: s[0], level: s[1], sourceFile: s[2] || void 0, sourceLine: s[3] || void 0 });
|
|
126
|
+
F(this.endpoint, this.operationName, this.getQuery(), r);
|
|
123
127
|
} catch (s) {
|
|
124
|
-
|
|
128
|
+
l().sfDebug && console.error("🚨 Error in send():", s);
|
|
125
129
|
}
|
|
126
130
|
}
|
|
127
131
|
getQuery() {
|
|
@@ -133,7 +137,9 @@ class Q extends F {
|
|
|
133
137
|
$timestampMs: String!,
|
|
134
138
|
$level: String!,
|
|
135
139
|
$contents: String!,
|
|
136
|
-
$parentSpanId: String
|
|
140
|
+
$parentSpanId: String,
|
|
141
|
+
$sourceFile: String,
|
|
142
|
+
$sourceLine: Int
|
|
137
143
|
) {
|
|
138
144
|
${this.queryName}(
|
|
139
145
|
apiKey: $apiKey,
|
|
@@ -142,224 +148,19 @@ class Q extends F {
|
|
|
142
148
|
timestampMs: $timestampMs,
|
|
143
149
|
level: $level,
|
|
144
150
|
contents: $contents,
|
|
145
|
-
parentSpanId: $parentSpanId
|
|
151
|
+
parentSpanId: $parentSpanId,
|
|
152
|
+
sourceFile: $sourceFile,
|
|
153
|
+
sourceLine: $sourceLine
|
|
146
154
|
)
|
|
147
155
|
}
|
|
148
156
|
`;
|
|
149
157
|
}
|
|
150
158
|
}
|
|
151
|
-
|
|
152
|
-
class V {
|
|
153
|
-
constructor({ file: e, line: t, function: s, code: n, locals: i = {}, offender: g = !1, column: r }) {
|
|
154
|
-
A(this, "file");
|
|
155
|
-
A(this, "line");
|
|
156
|
-
A(this, "function");
|
|
157
|
-
A(this, "code");
|
|
158
|
-
A(this, "locals");
|
|
159
|
-
A(this, "offender");
|
|
160
|
-
A(this, "column");
|
|
161
|
-
this.file = e, this.line = t, this.function = s, this.code = n, this.locals = i, this.offender = g, this.column = r;
|
|
162
|
-
}
|
|
163
|
-
toDict() {
|
|
164
|
-
const e = { file: this.file, line: this.line, function: this.function, code: this.code, locals: Object.fromEntries(Object.entries(this.locals).map(([t, s]) => [t, String(s)])) };
|
|
165
|
-
return this.offender && (e.offender = this.offender), this.column !== void 0 && (e.column = this.column), e;
|
|
166
|
-
}
|
|
167
|
-
toJson() {
|
|
168
|
-
return JSON.stringify(this.toDict());
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
class k {
|
|
172
|
-
static encode(e) {
|
|
173
|
-
return e instanceof V ? e.toDict() : Array.isArray(e) ? e.map((t) => k.encode(t)) : typeof e == "object" && e !== null ? JSON.stringify(e) : e;
|
|
174
|
-
}
|
|
175
|
-
static stringify(e) {
|
|
176
|
-
return JSON.stringify(k.encode(e), (t, s) => s instanceof V ? s.toDict() : s);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
let B, w = 0;
|
|
180
|
-
function Re(o) {
|
|
181
|
-
d().sfDebug && console.log("Initializing Exception Interceptor...");
|
|
182
|
-
try {
|
|
183
|
-
const r = (function() {
|
|
184
|
-
if (B !== void 0) return B;
|
|
185
|
-
const c = process.env || {}, a = ne(c.SF_IS_LOCAL);
|
|
186
|
-
if (a !== void 0) return B = a;
|
|
187
|
-
const l = (c.SF_ENV || c.NODE_ENV || "").toLowerCase();
|
|
188
|
-
if (["local", "dev", "development"].includes(l)) return B = !0;
|
|
189
|
-
if (["KUBERNETES_SERVICE_HOST", "AWS_EXECUTION_ENV", "ECS_CONTAINER_METADATA_URI", "ECS_CONTAINER_METADATA_URI_V4", "GAE_ENV", "K_SERVICE", "GOOGLE_CLOUD_PROJECT", "WEBSITE_INSTANCE_ID", "VERCEL", "NETLIFY", "DYNO", "RENDER", "FLY_APP_NAME", "RAILWAY_STATIC_URL", "CF_PAGES", "CLOUDFLARE"].some((p) => !!c[p])) return B = !1;
|
|
190
|
-
const I = (S.hostname?.() || c.HOSTNAME || "").toLowerCase();
|
|
191
|
-
return I === "localhost" || I.endsWith(".local") || I.includes("local") ? B = !0 : B = !1;
|
|
192
|
-
})();
|
|
193
|
-
o?.setSupplementalFields?.({ isFromLocalService: r }), (async function(c) {
|
|
194
|
-
if (te) return;
|
|
195
|
-
te = !0;
|
|
196
|
-
const a = process.env || {};
|
|
197
|
-
if (ne(a.SF_IS_LOCAL) === void 0)
|
|
198
|
-
try {
|
|
199
|
-
await (async function(l) {
|
|
200
|
-
const I = D("http://169.254.169.254/latest/meta-data/", {}, l), p = D("http://metadata.google.internal/computeMetadata/v1/instance/", { "Metadata-Flavor": "Google" }, l), C = D("http://169.254.169.254/metadata/instance?api-version=2021-02-01", { Metadata: "true" }, l);
|
|
201
|
-
return (await Promise.allSettled([I, p, C])).some((u) => u.status === "fulfilled" && (u.value === "ok" || u.value === "http_error"));
|
|
202
|
-
})(150) && B && (B = !1, c?.setSupplementalFields?.({ isFromLocalService: !1 }));
|
|
203
|
-
} catch {
|
|
204
|
-
}
|
|
205
|
-
})(o).catch(() => {
|
|
206
|
-
});
|
|
207
|
-
} catch {
|
|
208
|
-
}
|
|
209
|
-
const e = new Fe(new URL("data:application/javascript;base64,aW1wb3J0IHsgU2Vzc2lvbiB9IGZyb20gImluc3BlY3Rvci9wcm9taXNlcyI7CmltcG9ydCB7IHBhcmVudFBvcnQsIHdvcmtlckRhdGEgfSBmcm9tICJ3b3JrZXJfdGhyZWFkcyI7CgpnbG9iYWwuc2ZEZWJ1ZyA9IHVuZGVmaW5lZDsKZ2xvYmFsLnN0YWNrRGVwdGhMb2NhbHMgPSB1bmRlZmluZWQ7Cmdsb2JhbC5ub2RlTW9kdWxlc1RvQ29sbGVjdExvY2FsVmFyaWFibGVzT24gPSB1bmRlZmluZWQ7CgovKioKICogUHJvY2Vzc2VzIGNhbGwgZnJhbWVzIGZyb20gYW4gZXhjZXB0aW9uIGFuZCBwb3N0cyB0aGVtIHZpYSB0aGUgV29ya2Vy4oCZcyBwYXJlbnRQb3J0LgogKgogKiBAcGFyYW0gc2Vzc2lvbiAtIFRoZSBEZXZUb29scyBzZXNzaW9uIG9yIHNpbWlsYXIgb2JqZWN0IHlvdSB1c2UgdG8gcXVlcnkgZm9yIHNjcmlwdCBzb3VyY2VzLgogKiBAcGFyYW0gY2FsbEZyYW1lcyAtIEFuIGFycmF5IG9mIGNhbGwgZnJhbWUgb2JqZWN0cy4KICogQHBhcmFtIGRlc2NyaXB0aW9uTGluZXMgLSBBbiBhcnJheSBvZiBsaW5lcyBmcm9tIHRoZSBlcnJvcuKAmXMgZGVzY3JpcHRpb24sIGVhY2ggdHlwaWNhbGx5IGJlZ2lubmluZyB3aXRoICJhdCAiLgogKiBAcmV0dXJucyB7UHJvbWlzZTx2b2lk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AgICAgfSBlbHNlIGlmIChkZXNjcmlwdGlvbkxpbmVzW2luZGV4XSkgewogICAgICAgICAgZmlsZSA9IGRlc2NyaXB0aW9uTGluZXNbaW5kZXhdLnRyaW0oKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZmlsZSA9ICI8dW5rbm93bj4iOwogICAgICAgIH0KCiAgICAgICAgLy8gSWYgd2UgaGF2ZSBhIHZhbGlkIGxvY2F0aW9uIGFuZCBzY3JpcHRJZCwgZmV0Y2ggdGhlIGNvZGUgbGluZQogICAgICAgIGlmIChsb2NhdGlvbiAmJiBsb2NhdGlvbi5zY3JpcHRJZCkgewogICAgICAgICAgY29uc3Qgc2NyaXB0SWQgPSBsb2NhdGlvbi5zY3JpcHRJZDsKICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgIGNvbnN0IHsgc2NyaXB0U291cmNlIH0gPSBhd2FpdCBzZXNzaW9uLnBvc3QoCiAgICAgICAgICAgICAgIkRlYnVnZ2VyLmdldFNjcmlwdFNvdXJjZSIsCiAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgc2NyaXB0SWQsCiAgICAgICAgICAgICAgfSwKICAgICAgICAgICAgKTsKICAgICAgICAgICAgY29uc3Qgc291cmNlTGluZXMgPSBzY3JpcHRTb3VyY2Uuc3BsaXQoIlxuIik7CiAgICAgICAgICAgIGNvZGUgPSBzb3VyY2VMaW5lc1tsb2NhdGlvbi5saW5lTnVtYmVyXSB8fCAiPG5vdCBjYXB0dXJlZD4iOwogICAgICAgICAgfSBjYXRjaCAoZXJyKSB7CiAgICAgICAgICAgIGlmIChnbG9iYWwuc2ZEZWJ1ZykgewogICAgICAgICAgICAgIGNvbnNvbGUuZXJyb3IoIltXb3JrZXJdIEZhaWxlZCB0byBmZXRjaCBzY3JpcHQgc291cmNlOiIsIGVycik7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIC8vIEZldGNoIGxvY2FsIHZhcmlhYmxlcyBpZiB0aGVyZSdzIGFuIG9iamVjdElkCiAgICAgICAgY29uc3QgbG9jYWxzID0gbG9jYWxTY29wZT8ub2JqZWN0Py5vYmplY3RJZAogICAgICAgICAgPyBhd2FpdCBmZXRjaExvY2FsVmFyaWFibGVzKHNlc3Npb24sIGxvY2FsU2NvcGUub2JqZWN0Lm9iamVjdElkKQogICAgICAgICAgOiB7fTsKCiAgICAgICAgcmV0dXJuIHsKICAgICAgICAgIGZ1bmN0aW9uOiBmdW5jdGlvbk5hbWUgfHwgIjxhbm9ueW1vdXM+IiwKICAgICAgICAgIGxvY2FscywKICAgICAgICAgIGZpbGUsCiAgICAgICAgICBsaW5lOiBsb2NhdGlvbj8ubGluZU51bWJlciB8fCAwLAogICAgICAgICAgY29kZSwKICAgICAgICB9OwogICAgICB9IGNhdGNoIChlcnJvcikgewogICAgICAgIGlmIChnbG9iYWwuc2ZEZWJ1ZykgewogICAgICAgICAgY29uc29sZS5lcnJvcigiW1dvcmtlcl0gRXJyb3IgcHJvY2Vzc2luZyBjYWxsIGZyYW1lOiIsIGVycm9yKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHsKICAgICAgICAgIGZ1bmN0aW9uOiAiPGVycm9yPiIsCiAgICAgICAgICBsb2NhbHM6IHt9LAogICAgICAgICAgZmlsZTogIjx1bmtub3duPiIsCiAgICAgICAgICBsaW5lOiAwLAogICAgICAgICAgY29kZTogIjxub3QgY2FwdHVyZWQ+IiwKICAgICAgICB9OwogICAgICB9CiAgICB9KSwKICApOwogIC8vIFBvc3QgZXhjZXB0aW9uIGRhdGEKICBwYXJlbnRQb3J0Py5wb3N0TWVzc2FnZSh7IHR5cGU6ICJleGNlcHRpb24iLCBmcmFtZXMgfSk7Cn0KCi8qKgogKiBIYW5kbGVzIHRoZSAicGF1c2VkIiBzdGF0ZSBvZiB0aGUgZGVidWdnZXIgYW5kIHByb2Nlc3NlcyBleGNlcHRpb25zIG9yIHByb21pc2UgcmVqZWN0aW9ucy4KICogQHBhcmFtIHtTZ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mplY3QiCiAgICAgICAgKSB7CiAgICAgICAgICBjb25zdCBpZCA9IHByb3AudmFsdWUub2JqZWN0SWQ7CiAgICAgICAgICBhd2FpdCB1bnJvbGxPYmplY3Qoc2Vzc2lvbiwgaWQsIHByb3AubmFtZSwgdmFyaWFibGVzKTsKICAgICAgICB9IGVsc2UgaWYgKHByb3A/LnZhbHVlKSB7CiAgICAgICAgICB1bnJvbGxPdGhlcihwcm9wLCB2YXJpYWJsZXMpOwogICAgICAgIH0KICAgICAgfQogICAgICByZXR1cm4gdmFyaWFibGVzOwogICAgfQogIH0gY2F0Y2ggKGVycikgewogICAgaWYgKGdsb2JhbC5zZkRlYnVnKSB7CiAgICAgIGNvbnNvbGUuZXJyb3IoIltXb3JrZXJdIEZhaWxlZCB0byBmZXRjaCBsb2NhbCB2YXJpYWJsZXM6IiwgZXJyKTsKICAgIH0KICAgIHJldHVybiB7fTsKICB9Cn0KCnN0YXJ0RGVidWdnZXIoKS5jYXRjaCgoZXJyb3IpID0+IHsKICBpZiAoZ2xvYmFsLnNmRGVidWcpIHsKICAgIGNvbnNvbGUuZXJyb3IoIltXb3JrZXJdIEZhaWxlZCB0byBzdGFydCBkZWJ1Z2dlcjoiLCBlcnJvcik7CiAgfQp9KTsKCi8vIEtlZXAgdGhlIHdvcmtlciBhbGl2ZQpzZXRJbnRlcnZhbCgoKSA9PiB7fSwgMTAwMDApOwo="), { workerData: { captureAllExceptions: !0 } });
|
|
210
|
-
let t = null;
|
|
211
|
-
const s = /* @__PURE__ */ new WeakMap();
|
|
212
|
-
e.on("message", (r) => {
|
|
213
|
-
if (typeof r == "string" && d().sfDebug && console.log(`[Worker] ${r}`), r.readyToGetParameters && e.postMessage({ sfDebug: d().sfDebug, stackDepthLocals: d().stackDepthLocals, nodeModulesToCollectLocalVariablesOn: d().nodeModulesToCollectLocalVariablesOn }), r.type === "exception") {
|
|
214
|
-
const { frames: c } = r, a = t;
|
|
215
|
-
if (!a) return;
|
|
216
|
-
const l = s.get(a), I = (function(C) {
|
|
217
|
-
return C ? C.split(`
|
|
218
|
-
`).slice(1).map((u) => {
|
|
219
|
-
const m = /at (.+?) \((.+):(\d+):(\d+)\)/.exec(u) || /at (.+):(\d+):(\d+)/.exec(u);
|
|
220
|
-
if (m) {
|
|
221
|
-
const [, h, Z, b, y] = m;
|
|
222
|
-
return new V({ function: h || "<anonymous>", locals: {}, file: Z || "<unknown>", line: parseInt(b, 10) || 0, code: "<not captured>", column: parseInt(y) || 0 });
|
|
223
|
-
}
|
|
224
|
-
return new V({ function: "<unknown>", locals: {}, file: "<unknown>", line: 0, code: "<not captured>", column: 0 });
|
|
225
|
-
}) : [];
|
|
226
|
-
})(a.stack), p = (function(C, u) {
|
|
227
|
-
const m = [];
|
|
228
|
-
let h = -1, Z = -1;
|
|
229
|
-
for (let b = 0; b < C.length; b++) {
|
|
230
|
-
const y = Je(C[b].file);
|
|
231
|
-
if (Z = b, y !== "<unknown>") {
|
|
232
|
-
for (let f = 0; f < u.length; f++) {
|
|
233
|
-
const v = u[f];
|
|
234
|
-
if (be(v, y) || typeof v.file == "string" && v.file.includes(y)) {
|
|
235
|
-
h = f, w = 0, d().sfDebug && console.log(`✅ Matched Frame Found: ${y} @ Debugger Frame ${f}`);
|
|
236
|
-
break;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
if (h !== -1) break;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
if (h === -1) return w === 10 ? (w = 0, C) : (++w, d().sfDebug && console.log(`"❌ No matching frame found. Checking once again, Attempt N ${w}"`), []);
|
|
243
|
-
d().sfDebug && console.log(`🔄 Merging from matched index ${h} onward...`);
|
|
244
|
-
for (let b = 0; b < u.length; b++) {
|
|
245
|
-
const y = C[Z + b], f = u[h + b];
|
|
246
|
-
m.push(new V({ function: f?.function || y?.function || "<anonymous>", locals: f?.locals || y?.locals || {}, file: y?.file || f?.file || "<unknown>", line: f?.line || y?.line || 0, code: f?.code || y?.code || "<not captured>" }));
|
|
247
|
-
}
|
|
248
|
-
return m;
|
|
249
|
-
})(I, c || []);
|
|
250
|
-
if (p.length !== 0) {
|
|
251
|
-
t = null;
|
|
252
|
-
const C = d().stackDepthCodeTraceDepth, u = C === -1 ? p : p.slice(0, C + 1), m = Math.min(u.length, I.length);
|
|
253
|
-
for (let y = 0; y < m; y++) (async () => {
|
|
254
|
-
const f = Xe(u[y].file, I[y].line, I[y].column);
|
|
255
|
-
f && (f.content != null && (u[y].code = f.content), f.file != null && (u[y].file = f.file));
|
|
256
|
-
})();
|
|
257
|
-
o.setOperationName("CollectExceptions");
|
|
258
|
-
const h = a.message ? `${a.name}: ${a.message}` : a.name;
|
|
259
|
-
d().sfDebug && console.log("error message is : ", h);
|
|
260
|
-
const Z = N.getInstance(), b = s.get(a);
|
|
261
|
-
b ? (Z.setTraceIdFor(b, b), Z.runWithSession(b, () => {
|
|
262
|
-
Z.setTraceId(b), o.doSend(h, u);
|
|
263
|
-
})) : o.doSend(h, u), l ? N.getInstance().runWithSession(l, () => {
|
|
264
|
-
o.doSend(h, u);
|
|
265
|
-
}) : o.doSend(h, u);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}), e.on("error", (r) => {
|
|
269
|
-
console.error("[Worker Error]", r);
|
|
270
|
-
}), e.on("exit", (r) => {
|
|
271
|
-
console.error(`[Worker] Exited with code ${r}`);
|
|
272
|
-
}), e.unref();
|
|
273
|
-
const n = Error, i = /* @__PURE__ */ new Set();
|
|
274
|
-
function g(...r) {
|
|
275
|
-
const c = Reflect.construct(n, r);
|
|
276
|
-
Reflect.setPrototypeOf(c, g.prototype);
|
|
277
|
-
try {
|
|
278
|
-
const l = N.getInstance().getTraceId();
|
|
279
|
-
s.set(c, l);
|
|
280
|
-
} catch {
|
|
281
|
-
}
|
|
282
|
-
n.captureStackTrace && n.captureStackTrace(c, g);
|
|
283
|
-
const a = `${c.message}:${c.stack?.split(`
|
|
284
|
-
`)[1]?.trim()}`;
|
|
285
|
-
if (!i.has(a)) {
|
|
286
|
-
i.add(a), t = c;
|
|
287
|
-
const l = N.getInstance().getTraceId();
|
|
288
|
-
s.set(c, l), e.postMessage({ type: "processException", error: c.message });
|
|
289
|
-
}
|
|
290
|
-
return c;
|
|
291
|
-
}
|
|
292
|
-
g.prototype = Object.create(n.prototype, { constructor: { value: g, enumerable: !1, writable: !0, configurable: !0 } }), Object.setPrototypeOf(g, n), globalThis.Error = g;
|
|
293
|
-
}
|
|
294
|
-
function ee(o) {
|
|
295
|
-
return o = (o = (o = o.replace(/^webpack:\/\/[^\/]+\/\.?\//, "")).replace(/^.*\/pages\//, "pages/")).replace(/\.(js|ts)$/, "");
|
|
296
|
-
}
|
|
297
|
-
function Xe(o, e, t) {
|
|
298
|
-
const s = (function(i) {
|
|
299
|
-
i.startsWith("at ") && (i = i.slice(3).trim());
|
|
300
|
-
const g = i.match(/^(.*?)(:\d+)+(\.map)?$/);
|
|
301
|
-
return g ? g[1] : i;
|
|
302
|
-
})(o);
|
|
303
|
-
if (!s || s === "<unknown>") return null;
|
|
304
|
-
const n = s + ".map";
|
|
305
|
-
try {
|
|
306
|
-
const i = pe(n, "utf-8");
|
|
307
|
-
if (i) {
|
|
308
|
-
const g = JSON.parse(i);
|
|
309
|
-
let r = new me.SourceMapConsumer(g).originalPositionFor({ line: e, column: t });
|
|
310
|
-
if (s && r.source) {
|
|
311
|
-
const c = ee(s), a = g.sources.findIndex((l) => ee(l) === c);
|
|
312
|
-
if (a === -1) d().sfDebug && console.log(`Source file "${s}" not found in the source map.`);
|
|
313
|
-
else {
|
|
314
|
-
const l = g.sourcesContent[a], I = g.names.join(",");
|
|
315
|
-
if (l)
|
|
316
|
-
return { content: l.split(`
|
|
317
|
-
`).slice(r.line - 1, r.line + 20).join(`
|
|
318
|
-
`), name: I, file: r.source };
|
|
319
|
-
d().sfDebug && console.log(`No source content available for file "${s}".`);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
return { content: g.sourcesContent[0], name: g.names[0], file: g.file };
|
|
323
|
-
}
|
|
324
|
-
} catch (i) {
|
|
325
|
-
d().sfDebug && console.log(`Cant read/parse "${n}: Error - ".`, i);
|
|
326
|
-
}
|
|
327
|
-
return null;
|
|
328
|
-
}
|
|
329
|
-
function Je(o) {
|
|
330
|
-
return o?.split("/").pop() || "<unknown>";
|
|
331
|
-
}
|
|
332
|
-
function be(o, e) {
|
|
333
|
-
if (!o || typeof o != "object") return !1;
|
|
334
|
-
for (const t of Object.values(o))
|
|
335
|
-
if (typeof t == "string" && t.includes(e) || typeof t == "object" && be(t, e)) return !0;
|
|
336
|
-
return !1;
|
|
337
|
-
}
|
|
338
|
-
let te = !1;
|
|
339
|
-
function ne(o) {
|
|
340
|
-
if (!o) return;
|
|
341
|
-
const e = o.toLowerCase().trim();
|
|
342
|
-
return !!["1", "true", "yes", "on"].includes(e) || !["0", "false", "no", "off"].includes(e) && void 0;
|
|
343
|
-
}
|
|
344
|
-
function D(o, e, t) {
|
|
345
|
-
return new Promise((s) => {
|
|
346
|
-
try {
|
|
347
|
-
const n = new URL(o), i = (n.protocol, S).request({ method: "GET", hostname: n.hostname, port: n.port || (n.protocol === "https:" ? 443 : 80), path: n.pathname + (n.search || ""), headers: e }, (g) => {
|
|
348
|
-
g.resume(), g.statusCode && g.statusCode >= 200 && g.statusCode < 400 ? s("ok") : s("http_error");
|
|
349
|
-
});
|
|
350
|
-
i.on("error", () => s("error")), i.setTimeout(t, () => {
|
|
351
|
-
i.destroy(), s("timeout");
|
|
352
|
-
}), i.end();
|
|
353
|
-
} catch {
|
|
354
|
-
s("error");
|
|
355
|
-
}
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
class Ke extends F {
|
|
159
|
+
class Te extends D {
|
|
359
160
|
constructor() {
|
|
360
161
|
super();
|
|
361
|
-
|
|
362
|
-
|
|
162
|
+
S(this, "serviceIdentifier", new E());
|
|
163
|
+
S(this, "supplementalFields", {});
|
|
363
164
|
this.setOperationName("CollectExceptions");
|
|
364
165
|
}
|
|
365
166
|
setSupplementalFields(t) {
|
|
@@ -376,9 +177,9 @@ class Ke extends F {
|
|
|
376
177
|
this.sendAppIdentifier(), this.send(t, s);
|
|
377
178
|
}
|
|
378
179
|
async send(t, s) {
|
|
379
|
-
|
|
380
|
-
const
|
|
381
|
-
|
|
180
|
+
l().sfDebug && console.log(" SENDING EXCEPTION...");
|
|
181
|
+
const r = JSON.stringify(_e.encode(s)), o = this.normalizedSupplementalForGraphQL(), d = this.getVariables({ exceptionMessage: t, traceJson: r, reentrancyGuardPreactive: !1, library: l().packageLibraryType, version: l().version, ...o });
|
|
182
|
+
F(this.endpoint, this.operationName, this.getQuery(), d);
|
|
382
183
|
}
|
|
383
184
|
getQuery() {
|
|
384
185
|
return `
|
|
@@ -412,44 +213,51 @@ class Ke extends F {
|
|
|
412
213
|
`;
|
|
413
214
|
}
|
|
414
215
|
}
|
|
415
|
-
const
|
|
416
|
-
var
|
|
417
|
-
const x = "http:",
|
|
418
|
-
let
|
|
419
|
-
function
|
|
420
|
-
const
|
|
421
|
-
if (
|
|
216
|
+
const Y = "getting request source code";
|
|
217
|
+
var A = ((n) => (n.UNKNOWN = "unknown", n.ANONYMOUS = "anonymous", n.NOT_CAPTURED = "not captured", n))(A || {});
|
|
218
|
+
const x = "http:", G = "https:", Ue = Fe(import.meta.url);
|
|
219
|
+
let Z = !1;
|
|
220
|
+
function Re() {
|
|
221
|
+
const n = l().sfDebug;
|
|
222
|
+
if (Z) return void (n && _("[patchNodeHttpInbound] Already installed, skipping."));
|
|
422
223
|
let e;
|
|
423
|
-
|
|
224
|
+
Z = !0;
|
|
424
225
|
try {
|
|
425
|
-
e =
|
|
426
|
-
} catch (
|
|
427
|
-
return void
|
|
226
|
+
e = Ue("node:http"), n && _("[patchNodeHttpInbound] node:http required successfully.");
|
|
227
|
+
} catch (r) {
|
|
228
|
+
return void $e("Failed to require node:http:", r);
|
|
428
229
|
}
|
|
429
|
-
if (!e?.Server?.prototype) return void (
|
|
230
|
+
if (!e?.Server?.prototype) return void (n && _("[patchNodeHttpInbound] http.Server.prototype not found."));
|
|
430
231
|
const t = e.Server.prototype, s = t.emit;
|
|
431
|
-
s && !t.__sf_inbound_patched__ ? (Object.defineProperty(t, "__sf_inbound_patched__", { value: !0, enumerable: !1, configurable: !1, writable: !1 }),
|
|
432
|
-
if (
|
|
433
|
-
const
|
|
434
|
-
const
|
|
435
|
-
if (!
|
|
436
|
-
for (const [
|
|
437
|
-
return
|
|
438
|
-
})(
|
|
439
|
-
|
|
440
|
-
const
|
|
441
|
-
|
|
442
|
-
const
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
232
|
+
s && !t.__sf_inbound_patched__ ? (Object.defineProperty(t, "__sf_inbound_patched__", { value: !0, enumerable: !1, configurable: !1, writable: !1 }), n && _("[patchNodeHttpInbound] Patching http.Server.prototype.emit."), t.emit = function(r, ...o) {
|
|
233
|
+
if (r !== "request") return n && _(`[patchNodeHttpInbound] Passing through event: ${r}`), s.call(this, r, ...o);
|
|
234
|
+
const d = o[0], i = o[1], c = (function(p) {
|
|
235
|
+
const g = {};
|
|
236
|
+
if (!p) return g;
|
|
237
|
+
for (const [y, I] of Object.entries(p)) I != null && (Array.isArray(I) ? g[y.toLowerCase()] = I.join(", ") : g[y.toLowerCase()] = String(I));
|
|
238
|
+
return g;
|
|
239
|
+
})(d?.headers), a = c["x-sf3-rid"], u = c["x-sf3-functionspancaptureoverride"];
|
|
240
|
+
n && (_("[patchNodeHttpInbound] Intercepted request event."), _("[patchNodeHttpInbound] Inbound headers:", c), _("[patchNodeHttpInbound] Trace header:", a), _("[patchNodeHttpInbound] FuncSpan override header:", u));
|
|
241
|
+
const f = J.getInstance();
|
|
242
|
+
f.setTraceId(a);
|
|
243
|
+
const h = f.getTraceId();
|
|
244
|
+
n && _("[patchNodeHttpInbound] Context traceId set:", h);
|
|
245
|
+
const m = () => f.runWith({ inboundHeaders: c, ...a ? { traceId: a } : {} }, () => {
|
|
246
|
+
a && f.setTraceId(a), n && _("[patchNodeHttpInbound] Running request handler in context.");
|
|
247
|
+
const p = () => {
|
|
248
|
+
n && _("[patchNodeHttpInbound] Response finished/closed for traceId:", f.getTraceId());
|
|
447
249
|
};
|
|
448
|
-
return
|
|
250
|
+
return i.on("finish", p), i.on("close", p), s.call(this, r, d, i);
|
|
449
251
|
});
|
|
450
|
-
|
|
252
|
+
if (!u) return m();
|
|
253
|
+
try {
|
|
254
|
+
return me.run(u, () => m());
|
|
255
|
+
} catch {
|
|
256
|
+
return m();
|
|
257
|
+
}
|
|
258
|
+
}) : n && _("[patchNodeHttpInbound] Already patched, skipping.");
|
|
451
259
|
}
|
|
452
|
-
class
|
|
260
|
+
class Ae extends V {
|
|
453
261
|
constructor() {
|
|
454
262
|
super(), this.setOperationName("DomainsToNotPassHeaderTo");
|
|
455
263
|
}
|
|
@@ -470,13 +278,13 @@ class ke extends Q {
|
|
|
470
278
|
)
|
|
471
279
|
}
|
|
472
280
|
`, s = { apiKey: this.apiKey, serviceUuid: this.serviceUUID, domains: e };
|
|
473
|
-
|
|
281
|
+
F(this.endpoint, this.operationName, t, s);
|
|
474
282
|
}
|
|
475
283
|
}
|
|
476
|
-
class
|
|
284
|
+
class Oe extends D {
|
|
477
285
|
constructor() {
|
|
478
286
|
super();
|
|
479
|
-
|
|
287
|
+
S(this, "serviceIdentifier", new E());
|
|
480
288
|
this.setOperationName("CollectNetworkHops");
|
|
481
289
|
}
|
|
482
290
|
async sendAppIdentifier() {
|
|
@@ -486,8 +294,8 @@ class Ue extends F {
|
|
|
486
294
|
this.sendAppIdentifier(), this.send(t);
|
|
487
295
|
}
|
|
488
296
|
async send(t) {
|
|
489
|
-
const { name: s, column:
|
|
490
|
-
|
|
297
|
+
const { name: s, column: r, line: o, entrypoint: d, retryWithoutTraceId: i } = t, c = this.getVariables({ name: s, column: r, line: o, entrypoint: d, retryWithoutTraceId: i });
|
|
298
|
+
F(this.endpoint, this.operationName, this.getQuery(), c);
|
|
491
299
|
}
|
|
492
300
|
getQuery() {
|
|
493
301
|
return `
|
|
@@ -517,10 +325,10 @@ class Ue extends F {
|
|
|
517
325
|
`;
|
|
518
326
|
}
|
|
519
327
|
}
|
|
520
|
-
class
|
|
328
|
+
class Le extends D {
|
|
521
329
|
constructor() {
|
|
522
330
|
super();
|
|
523
|
-
|
|
331
|
+
S(this, "serviceIdentifier", new E());
|
|
524
332
|
this.setOperationName("CollectNetworkRequest");
|
|
525
333
|
}
|
|
526
334
|
async sendAppIdentifier() {
|
|
@@ -541,174 +349,174 @@ class Te extends F {
|
|
|
541
349
|
}
|
|
542
350
|
async send(t) {
|
|
543
351
|
const s = { data: { ...t } };
|
|
544
|
-
await
|
|
352
|
+
await F(this.endpoint, this.operationName, this.getQuery(), s);
|
|
545
353
|
}
|
|
546
354
|
}
|
|
547
|
-
const
|
|
548
|
-
class
|
|
355
|
+
const K = [400, 403];
|
|
356
|
+
class ke {
|
|
549
357
|
constructor(e = []) {
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
this.contextManager =
|
|
358
|
+
S(this, "HEADER_TRACING", "X-Sf3-Rid");
|
|
359
|
+
S(this, "HEADER_LOG_GUARD", "reentrancy_guard_logging_preactive");
|
|
360
|
+
S(this, "HEADER_PRINT_GUARD", "reentrancy_guard_print_preactive");
|
|
361
|
+
S(this, "HEADER_EXCEPTION_GUARD", "reentrancy_guard_exception_preactive");
|
|
362
|
+
S(this, "contextManager");
|
|
363
|
+
this.contextManager = J.getInstance(), e?.forEach((t) => {
|
|
556
364
|
typeof t == "string" && t.trim() && this.contextManager.getExcludedDomains().add(t);
|
|
557
|
-
}),
|
|
365
|
+
}), l().sfDebug && console.log("[RequestInterceptor] Initialized with static excluded domains.");
|
|
558
366
|
}
|
|
559
367
|
extractIdsFromTraceHeader(e, t = this.HEADER_TRACING) {
|
|
560
368
|
let s;
|
|
561
369
|
if (e instanceof Headers) s = e.get(t) ?? void 0;
|
|
562
370
|
else {
|
|
563
|
-
const
|
|
564
|
-
for (const [
|
|
565
|
-
s =
|
|
371
|
+
const o = t.toLowerCase();
|
|
372
|
+
for (const [d, i] of Object.entries(e)) if (d.toLowerCase() === o) {
|
|
373
|
+
s = i;
|
|
566
374
|
break;
|
|
567
375
|
}
|
|
568
376
|
}
|
|
569
377
|
if (!s) return {};
|
|
570
|
-
const
|
|
571
|
-
return
|
|
378
|
+
const r = s.split("/").filter(Boolean);
|
|
379
|
+
return r.length < 3 ? {} : { sessionId: r[0], pageVisitId: r[1], requestId: r[r.length - 1] };
|
|
572
380
|
}
|
|
573
381
|
parseStackFrame(e) {
|
|
574
382
|
const t = /\((.*):(\d+):(\d+)\)$/.exec(e.trim());
|
|
575
383
|
if (!t) return null;
|
|
576
|
-
const [, s,
|
|
577
|
-
return { filePath: s, line: parseInt(
|
|
384
|
+
const [, s, r, o] = t;
|
|
385
|
+
return { filePath: s, line: parseInt(r, 10), column: parseInt(o, 10) };
|
|
578
386
|
}
|
|
579
387
|
async getOriginalPosition(e, t, s) {
|
|
580
|
-
let
|
|
581
|
-
const
|
|
388
|
+
let r = { source: e, line: t, column: s, name: null };
|
|
389
|
+
const o = e + ".map";
|
|
582
390
|
try {
|
|
583
|
-
const
|
|
584
|
-
let
|
|
585
|
-
|
|
586
|
-
} catch (
|
|
587
|
-
|
|
391
|
+
const d = JSON.parse(Ne(o, "utf-8"));
|
|
392
|
+
let i = (await new we.SourceMapConsumer(d)).originalPositionFor({ line: t, column: s });
|
|
393
|
+
i.source && (r = i);
|
|
394
|
+
} catch (d) {
|
|
395
|
+
l().sfDebug && console.error(`Could not read/parse map file at ${o}:`, d);
|
|
588
396
|
}
|
|
589
|
-
return { originalPos:
|
|
397
|
+
return { originalPos: r };
|
|
590
398
|
}
|
|
591
399
|
captureFirstUserLines(e, t = 10, s = !1) {
|
|
592
|
-
const
|
|
593
|
-
Error.stackTraceLimit = Math.max(
|
|
594
|
-
const
|
|
595
|
-
|
|
596
|
-
const
|
|
597
|
-
Error.stackTraceLimit =
|
|
598
|
-
const c =
|
|
400
|
+
const r = l().sfDebug ? 10 : t, o = Error.stackTraceLimit;
|
|
401
|
+
Error.stackTraceLimit = Math.max(o, r);
|
|
402
|
+
const d = new Error(Y);
|
|
403
|
+
Y in Error && Error.captureStackTrace(d, this.captureFirstUserLines);
|
|
404
|
+
const i = d.stack || "";
|
|
405
|
+
Error.stackTraceLimit = o;
|
|
406
|
+
const c = i.split(`
|
|
599
407
|
`).slice(1), a = [];
|
|
600
|
-
for (const
|
|
601
|
-
if (!(
|
|
602
|
-
for (const
|
|
603
|
-
const
|
|
604
|
-
|
|
605
|
-
const { originalPos:
|
|
606
|
-
if (
|
|
607
|
-
|
|
608
|
-
const
|
|
609
|
-
e.doSend(
|
|
408
|
+
for (const u of c)
|
|
409
|
+
if (!(u.includes("node:internal") || u.includes("internal/modules") || u.includes("internal/process") || u.includes("node_modules") || u.includes(".next/server/chunks") || u.includes("RequestInterceptor") || u.includes("contextManager") || u.includes("setupConfig")) && (a.push(u.trim()), a.length >= t)) break;
|
|
410
|
+
for (const u of a) {
|
|
411
|
+
const f = this.parseStackFrame(u);
|
|
412
|
+
f ? (async () => {
|
|
413
|
+
const { originalPos: h } = await this.getOriginalPosition(f.filePath, f.line, f.column);
|
|
414
|
+
if (h) {
|
|
415
|
+
l().sfDebug && console.log("[RequestInterceptor] First user code line:", h);
|
|
416
|
+
const m = { line: h.line?.toString() || A.UNKNOWN, column: h.column?.toString() || A.NOT_CAPTURED, name: h.name || A.NOT_CAPTURED, entrypoint: h.source, retryWithoutTraceId: s };
|
|
417
|
+
e.doSend(m);
|
|
610
418
|
}
|
|
611
|
-
})() :
|
|
419
|
+
})() : l().sfDebug && console.error("Could not parse stack line:", u);
|
|
612
420
|
}
|
|
613
421
|
}
|
|
614
422
|
addReentrancyGuardHeaders(e) {
|
|
615
423
|
e.set(this.HEADER_LOG_GUARD, "true"), e.set(this.HEADER_PRINT_GUARD, "true"), e.set(this.HEADER_EXCEPTION_GUARD, "true");
|
|
616
424
|
}
|
|
617
425
|
shouldPropagateHeaders(e) {
|
|
618
|
-
return !
|
|
426
|
+
return !he.some((t) => new RegExp(`^${t.replace(/\*/g, ".*")}$`).test(e));
|
|
619
427
|
}
|
|
620
428
|
addTracingHeaders(e, t) {
|
|
621
|
-
const s = new URL(t).hostname,
|
|
622
|
-
return
|
|
429
|
+
const s = new URL(t).hostname, r = this.shouldPropagateHeaders(s);
|
|
430
|
+
return r ? this.addTracingHeader(e, t) : l().sfDebug && console.error(`[RequestInterceptor] Excluded domain: ${s}`), r;
|
|
623
431
|
}
|
|
624
432
|
addTracingHeader(e, t) {
|
|
625
|
-
const s =
|
|
433
|
+
const s = ce();
|
|
626
434
|
if (s) {
|
|
627
|
-
const
|
|
628
|
-
if (
|
|
435
|
+
const i = de(s);
|
|
436
|
+
if (i && i.sample_rate === 0) return void (l().sfDebug && console.log(`[RequestInterceptor] Function span tracking disabled (sample_rate=0), skipping tracing header for ${t}`));
|
|
629
437
|
}
|
|
630
|
-
const
|
|
631
|
-
e.set(this.HEADER_TRACING, `${
|
|
438
|
+
const r = this.contextManager.getOrSetSfTraceId(), o = this.contextManager.getOrSetPageVisitUUID(), d = ie();
|
|
439
|
+
e.set(this.HEADER_TRACING, `${r}/${o}/${d}`), l().sfDebug && console.log(`[RequestInterceptor] Added tracing header for ${t}`);
|
|
632
440
|
}
|
|
633
441
|
patchFetch(e, t) {
|
|
634
442
|
const s = globalThis.fetch;
|
|
635
|
-
typeof s == "function" ? globalThis.fetch = async (
|
|
636
|
-
const
|
|
637
|
-
if (
|
|
443
|
+
typeof s == "function" ? globalThis.fetch = async (r, o) => {
|
|
444
|
+
const d = new Headers(o?.headers);
|
|
445
|
+
if (d.get(this.HEADER_LOG_GUARD) === "true" || d.get(this.HEADER_PRINT_GUARD) === "true" || d.get(this.HEADER_EXCEPTION_GUARD) === "true") return s(r, o);
|
|
638
446
|
this.captureFirstUserLines(e);
|
|
639
|
-
const
|
|
447
|
+
const i = Date.now();
|
|
640
448
|
let c;
|
|
641
|
-
typeof
|
|
642
|
-
|
|
643
|
-
})) :
|
|
644
|
-
const a = new URL(c).hostname,
|
|
645
|
-
let
|
|
449
|
+
typeof r == "string" || r instanceof URL ? c = r.toString() : r instanceof Request ? (c = r.url, r.headers.forEach((p, g) => {
|
|
450
|
+
d.set(g, p);
|
|
451
|
+
})) : l().sfDebug && console.error("[Sailfish RequestInterceptor] Invalid fetch input."), l().sfDebug && console.log("[RequestInterceptor] Fetching request to:", c);
|
|
452
|
+
const a = new URL(c).hostname, u = new Headers(d), f = this.addTracingHeaders(d, c), h = { ...o, headers: d };
|
|
453
|
+
let m;
|
|
646
454
|
try {
|
|
647
|
-
let
|
|
648
|
-
this.addTracingHeaders(
|
|
649
|
-
const
|
|
650
|
-
|
|
651
|
-
const { sessionId:
|
|
652
|
-
return t.doSend({ apiKey:
|
|
653
|
-
} catch (
|
|
654
|
-
const
|
|
655
|
-
|
|
455
|
+
let p = !1;
|
|
456
|
+
this.addTracingHeaders(u, c), m = await s(c, h), f && K.includes(m.status) ? (m = await s(c, { ...o, headers: u }), p = !0, this.captureFirstUserLines(e, 10, p)) : this.contextManager.addSupportedDomains(a);
|
|
457
|
+
const g = Date.now();
|
|
458
|
+
l().sfDebug && console.log(`[RequestInterceptor] Fetch completed: ${c}, Status: ${m.status}, Duration: ${g - i}ms`);
|
|
459
|
+
const { sessionId: y, pageVisitId: I, requestId: v } = this.extractIdsFromTraceHeader(d);
|
|
460
|
+
return t.doSend({ apiKey: l().apiKey, requestId: v, pageVisitId: I, recordingSessionId: y, serviceUuid: l().serviceUUID, timestampStart: i.toString(), timestampEnd: g.toString(), responseCode: m.status, success: !0, error: null, url: c, method: h.method || "GET", retryWithoutTraceId: p, parentSpanId: q() }), m;
|
|
461
|
+
} catch (p) {
|
|
462
|
+
const g = Date.now();
|
|
463
|
+
l().sfDebug && console.error(`[RequestInterceptor] Fetch failed: ${c}, Error: ${p}, Duration: ${g - i}ms`);
|
|
656
464
|
}
|
|
657
|
-
} :
|
|
465
|
+
} : l().sfDebug && console.error("[RequestInterceptor] Fetch not available.");
|
|
658
466
|
}
|
|
659
467
|
patchHttp(e, t) {
|
|
660
|
-
if (
|
|
661
|
-
const s =
|
|
662
|
-
|
|
663
|
-
let
|
|
468
|
+
if (l().sfDebug && console.log("[RequestInterceptor] Initializing HTTP/HTTPS request patch..."), !b || typeof b.request != "function") return void (l().sfDebug && console.log("[RequestInterceptor] HTTP/HTTPS not available."));
|
|
469
|
+
const s = b.request.bind(b), r = b.request.bind(b);
|
|
470
|
+
b.request = function(o, d) {
|
|
471
|
+
let i;
|
|
664
472
|
try {
|
|
665
|
-
if (typeof
|
|
666
|
-
const a = new URL(
|
|
667
|
-
|
|
668
|
-
} else
|
|
669
|
-
if (
|
|
670
|
-
const a = `${
|
|
671
|
-
this.addTracingHeaders(
|
|
672
|
-
} else
|
|
473
|
+
if (typeof o == "string") {
|
|
474
|
+
const a = new URL(o);
|
|
475
|
+
i = { protocol: a.protocol || x, hostname: a.hostname, path: a.pathname + a.search, headers: {} };
|
|
476
|
+
} else o instanceof URL ? i = { protocol: o.protocol || x, hostname: o.hostname, path: o.pathname + o.search, headers: {} } : (i = { ...o }, i.protocol || (i.protocol = x));
|
|
477
|
+
if (i.headers) {
|
|
478
|
+
const a = `${i.protocol}//${i.hostname}`;
|
|
479
|
+
this.addTracingHeaders(i.headers, a), this.captureFirstUserLines(e);
|
|
480
|
+
} else l().sfDebug && console.warn("[RequestInterceptor] No headers found in HTTP request options. Skipping header addition.");
|
|
673
481
|
} catch (a) {
|
|
674
|
-
throw
|
|
482
|
+
throw l().sfDebug && console.error("[RequestInterceptor] Error while processing HTTP request options:", a), a;
|
|
675
483
|
}
|
|
676
484
|
let c = !1;
|
|
677
|
-
return s(
|
|
678
|
-
const
|
|
679
|
-
if (
|
|
680
|
-
|
|
681
|
-
const
|
|
682
|
-
delete
|
|
485
|
+
return s(i, (a) => {
|
|
486
|
+
const u = `${i.protocol}//${i.hostname}`;
|
|
487
|
+
if (i.headers && this.shouldPropagateHeaders(new URL(u).hostname) && K.includes(a.statusCode || 0)) {
|
|
488
|
+
i.hostname;
|
|
489
|
+
const p = { ...i, headers: { ...i.headers } };
|
|
490
|
+
delete p.headers[this.HEADER_TRACING], s(p, d), c = !0, this.captureFirstUserLines(e, 10, c);
|
|
683
491
|
}
|
|
684
|
-
const { sessionId:
|
|
685
|
-
t.doSend({ apiKey:
|
|
492
|
+
const { sessionId: f, pageVisitId: h, requestId: m } = this.extractIdsFromTraceHeader(i.headers);
|
|
493
|
+
t.doSend({ apiKey: l().apiKey, requestId: m, pageVisitId: h, recordingSessionId: f, serviceUuid: l().serviceUUID, timestampStart: Date.now().toString(), timestampEnd: Date.now().toString(), responseCode: a.statusCode || 0, success: !!a.statusCode && a.statusCode < 400, error: null, url: u, method: i.method || "GET", retryWithoutTraceId: c, parentSpanId: q() }), d?.(a);
|
|
686
494
|
});
|
|
687
|
-
},
|
|
688
|
-
let
|
|
495
|
+
}, b.request = function(o, d) {
|
|
496
|
+
let i;
|
|
689
497
|
try {
|
|
690
|
-
if (typeof
|
|
691
|
-
const a = new URL(
|
|
692
|
-
|
|
693
|
-
} else
|
|
694
|
-
if (
|
|
695
|
-
const a = `${
|
|
696
|
-
this.addTracingHeaders(
|
|
697
|
-
} else
|
|
498
|
+
if (typeof o == "string") {
|
|
499
|
+
const a = new URL(o);
|
|
500
|
+
i = { protocol: a.protocol || G, hostname: a.hostname, path: a.pathname + a.search, headers: {} };
|
|
501
|
+
} else o instanceof URL ? i = { protocol: o.protocol || G, hostname: o.hostname, path: o.pathname + o.search, headers: {} } : (i = { ...o }, i.protocol || (i.protocol = G));
|
|
502
|
+
if (i.headers) {
|
|
503
|
+
const a = `${i.protocol}//${i.hostname}`;
|
|
504
|
+
this.addTracingHeaders(i.headers, a);
|
|
505
|
+
} else l().sfDebug && console.warn("[RequestInterceptor] No headers found in HTTPS request options. Skipping header addition.");
|
|
698
506
|
} catch (a) {
|
|
699
|
-
throw
|
|
507
|
+
throw l().sfDebug && console.error("[RequestInterceptor] Error while processing HTTPS request options:", a), a;
|
|
700
508
|
}
|
|
701
509
|
let c = !1;
|
|
702
|
-
return
|
|
703
|
-
const
|
|
704
|
-
if (
|
|
705
|
-
const
|
|
706
|
-
delete
|
|
510
|
+
return r(i, (a) => {
|
|
511
|
+
const u = `${i.protocol}//${i.hostname}`;
|
|
512
|
+
if (i.headers && this.shouldPropagateHeaders(new URL(u).hostname) && K.includes(a.statusCode || 0)) {
|
|
513
|
+
const p = { ...i, headers: { ...i.headers } };
|
|
514
|
+
delete p.headers[this.HEADER_TRACING], r(p, d), c = !0, this.captureFirstUserLines(e, 10, c);
|
|
707
515
|
}
|
|
708
|
-
const { sessionId:
|
|
709
|
-
t.doSend({ apiKey:
|
|
516
|
+
const { sessionId: f, pageVisitId: h, requestId: m } = this.extractIdsFromTraceHeader(i.headers);
|
|
517
|
+
t.doSend({ apiKey: l().apiKey, requestId: m, pageVisitId: h, recordingSessionId: f, serviceUuid: l().serviceUUID, timestampStart: Date.now().toString(), timestampEnd: Date.now().toString(), responseCode: a.statusCode || 0, success: !!a.statusCode && a.statusCode < 400, error: null, url: u, method: i.method || "GET", retryWithoutTraceId: c, parentSpanId: q() }), d?.(a);
|
|
710
518
|
});
|
|
711
|
-
},
|
|
519
|
+
}, l().sfDebug && console.log("✅ HTTP and HTTPS request methods patched globally.");
|
|
712
520
|
}
|
|
713
521
|
tryPatch(e, t) {
|
|
714
522
|
try {
|
|
@@ -721,7 +529,7 @@ class $e {
|
|
|
721
529
|
return [...this.contextManager.getExcludedDomains()];
|
|
722
530
|
}
|
|
723
531
|
}
|
|
724
|
-
class
|
|
532
|
+
class qe extends V {
|
|
725
533
|
constructor() {
|
|
726
534
|
super(), this.setOperationName("UpdateServiceDetails");
|
|
727
535
|
}
|
|
@@ -749,43 +557,47 @@ class Ee extends Q {
|
|
|
749
557
|
gitSha: $gitSha,
|
|
750
558
|
)
|
|
751
559
|
}
|
|
752
|
-
`, t = this.getVariables({ serviceIdentifier:
|
|
753
|
-
|
|
560
|
+
`, t = this.getVariables({ serviceIdentifier: l().serviceIdentifier, serviceVersion: l().serviceVersion, serviceAdditionalMetadata: l().serviceAdditionalMetadata, gitSha: l().gitSha || "" });
|
|
561
|
+
F(this.endpoint, this.operationName, e, t);
|
|
754
562
|
}
|
|
755
563
|
}
|
|
756
|
-
class
|
|
564
|
+
class Me {
|
|
757
565
|
constructor(e = [process.cwd()], t = !1) {
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
566
|
+
S(this, "rootPaths");
|
|
567
|
+
S(this, "fileConfigs", /* @__PURE__ */ new Map());
|
|
568
|
+
S(this, "functionConfigs", /* @__PURE__ */ new Map());
|
|
569
|
+
S(this, "directoryConfigs", /* @__PURE__ */ new Map());
|
|
570
|
+
S(this, "hasSailfishFiles", !1);
|
|
571
|
+
S(this, "runtimeModeEnabled", !1);
|
|
572
|
+
S(this, "debug");
|
|
764
573
|
this.rootPaths = e, this.debug = t || process.env.SF_DEBUG === "true";
|
|
765
574
|
}
|
|
766
575
|
async loadAllConfigs() {
|
|
767
576
|
this.debug && console.log("[FuncSpan ConfigLoader] Scanning for .sailfish files in:", this.rootPaths);
|
|
768
577
|
const e = [];
|
|
769
|
-
for (const t of this.rootPaths)
|
|
578
|
+
for (const t of this.rootPaths) H.existsSync(t) ? await this._walkDirectory(t, e) : this.debug && console.log(`[FuncSpan ConfigLoader] Root path does not exist: ${t}`);
|
|
770
579
|
e.length > 0 ? (this.hasSailfishFiles = !0, this.debug && (console.log(`[FuncSpan ConfigLoader] Found ${e.length} .sailfish files:`), e.forEach((t) => console.log(`[FuncSpan ConfigLoader] - ${t}`)))) : this.debug && console.log("[FuncSpan ConfigLoader] No .sailfish files found - function spans disabled by default");
|
|
771
580
|
for (const t of e) await this._loadConfigFile(t);
|
|
772
581
|
await this._resolveInheritance(), this.debug && console.log(`[FuncSpan ConfigLoader] Loaded ${this.fileConfigs.size} file configs, ${this.functionConfigs.size} function configs`);
|
|
773
582
|
}
|
|
774
583
|
getConfig(e, t) {
|
|
775
|
-
const s = this.hasSailfishFiles ?
|
|
776
|
-
let
|
|
584
|
+
const s = this.hasSailfishFiles ? le() : Se(), r = this._getDirectoryConfig(e), o = $.normalize(e), d = this.fileConfigs.get(o) || {};
|
|
585
|
+
let i = {};
|
|
777
586
|
if (t) {
|
|
778
|
-
const c = this.functionConfigs.get(
|
|
779
|
-
c && (
|
|
587
|
+
const c = this.functionConfigs.get(o);
|
|
588
|
+
c && (i = c.get(t) || {});
|
|
780
589
|
}
|
|
781
|
-
return
|
|
590
|
+
return P(s, r, d, i);
|
|
591
|
+
}
|
|
592
|
+
hasRuntimeMode() {
|
|
593
|
+
return this.runtimeModeEnabled;
|
|
782
594
|
}
|
|
783
595
|
async _walkDirectory(e, t) {
|
|
784
596
|
try {
|
|
785
|
-
const s =
|
|
786
|
-
for (const
|
|
787
|
-
const
|
|
788
|
-
|
|
597
|
+
const s = H.readdirSync(e, { withFileTypes: !0 });
|
|
598
|
+
for (const r of s) {
|
|
599
|
+
const o = $.join(e, r.name);
|
|
600
|
+
r.isFile() && r.name === ".sailfish" ? t.push(o) : r.name === "node_modules" || r.isDirectory() && r.name.startsWith(".") && r.name !== ".sailfish" || r.isDirectory() && await this._walkDirectory(o, t);
|
|
789
601
|
}
|
|
790
602
|
} catch (s) {
|
|
791
603
|
this.debug && console.error(`[FuncSpan ConfigLoader] Error walking directory ${e}:`, s);
|
|
@@ -793,290 +605,319 @@ class Le {
|
|
|
793
605
|
}
|
|
794
606
|
async _loadConfigFile(e) {
|
|
795
607
|
try {
|
|
796
|
-
const t =
|
|
797
|
-
let
|
|
608
|
+
const t = H.readFileSync(e, "utf-8"), s = $.dirname(e);
|
|
609
|
+
let r = null;
|
|
798
610
|
try {
|
|
799
|
-
|
|
611
|
+
r = JSON.parse(t);
|
|
800
612
|
} catch {
|
|
801
613
|
try {
|
|
802
|
-
|
|
803
|
-
} catch (
|
|
804
|
-
return void (this.debug && console.error(`[FuncSpan ConfigLoader] Failed to parse ${e} as JSON or YAML:`,
|
|
614
|
+
r = require("js-yaml").load(t);
|
|
615
|
+
} catch (o) {
|
|
616
|
+
return void (this.debug && console.error(`[FuncSpan ConfigLoader] Failed to parse ${e} as JSON or YAML:`, o));
|
|
805
617
|
}
|
|
806
618
|
}
|
|
807
|
-
if (!
|
|
808
|
-
|
|
619
|
+
if (!r) return;
|
|
620
|
+
r.runtime_mode === !0 && (this.runtimeModeEnabled = !0, this.debug && console.log(`[FuncSpan ConfigLoader] Runtime mode ENABLED in ${e}`)), r.default && this.directoryConfigs.set(s, r.default), r.files && await this._expandFileGlobs(s, r.files, r.default || {}), r.functions && this._storeFunctionConfigs(s, r.functions, r.default || {}), this.debug && (console.log(`[FuncSpan ConfigLoader] Loaded config from ${e}`), console.log(`[FuncSpan ConfigLoader] Directory: ${s}`), console.log(`[FuncSpan ConfigLoader] Has default: ${!!r.default}`), console.log(`[FuncSpan ConfigLoader] File patterns: ${Object.keys(r.files || {}).length}`), console.log(`[FuncSpan ConfigLoader] Functions: ${Object.keys(r.functions || {}).length}`));
|
|
809
621
|
} catch (t) {
|
|
810
622
|
this.debug && console.error(`[FuncSpan ConfigLoader] Error loading ${e}:`, t);
|
|
811
623
|
}
|
|
812
624
|
}
|
|
813
625
|
async _expandFileGlobs(e, t, s) {
|
|
814
|
-
for (const [
|
|
815
|
-
const
|
|
816
|
-
this.debug && console.log(`[FuncSpan ConfigLoader] Pattern '${
|
|
817
|
-
for (const c of
|
|
818
|
-
const a =
|
|
819
|
-
this.fileConfigs.set(a,
|
|
626
|
+
for (const [r, o] of Object.entries(t)) try {
|
|
627
|
+
const d = $.join(e, r), i = await Ee(d, { absolute: !0, nodir: !0, ignore: ["**/node_modules/**", "**/.git/**"] });
|
|
628
|
+
this.debug && console.log(`[FuncSpan ConfigLoader] Pattern '${r}' matched ${i.length} files`);
|
|
629
|
+
for (const c of i) {
|
|
630
|
+
const a = $.normalize(c), u = P(s, o);
|
|
631
|
+
this.fileConfigs.set(a, u), this.debug && i.length <= 5 && console.log(`[FuncSpan ConfigLoader] - ${c}`);
|
|
820
632
|
}
|
|
821
|
-
} catch (
|
|
822
|
-
this.debug && console.error(`[FuncSpan ConfigLoader] Error expanding glob '${
|
|
633
|
+
} catch (d) {
|
|
634
|
+
this.debug && console.error(`[FuncSpan ConfigLoader] Error expanding glob '${r}':`, d);
|
|
823
635
|
}
|
|
824
636
|
}
|
|
825
637
|
_storeFunctionConfigs(e, t, s) {
|
|
826
|
-
for (const [
|
|
827
|
-
const
|
|
828
|
-
if (
|
|
829
|
-
this.debug && console.warn(`[FuncSpan ConfigLoader] Invalid function pattern '${
|
|
638
|
+
for (const [r, o] of Object.entries(t)) {
|
|
639
|
+
const d = r.split("::");
|
|
640
|
+
if (d.length !== 2) {
|
|
641
|
+
this.debug && console.warn(`[FuncSpan ConfigLoader] Invalid function pattern '${r}' (expected format: 'file.ts::functionName')`);
|
|
830
642
|
continue;
|
|
831
643
|
}
|
|
832
|
-
const [
|
|
644
|
+
const [i, c] = d, a = $.normalize($.join(e, i));
|
|
833
645
|
this.functionConfigs.has(a) || this.functionConfigs.set(a, /* @__PURE__ */ new Map());
|
|
834
|
-
const
|
|
835
|
-
|
|
646
|
+
const u = this.functionConfigs.get(a), f = P(s, o);
|
|
647
|
+
u.set(c, f), this.debug && console.log(`[FuncSpan ConfigLoader] Function config: ${a}::${c}`);
|
|
836
648
|
}
|
|
837
649
|
}
|
|
838
650
|
async _resolveInheritance() {
|
|
839
651
|
}
|
|
840
652
|
_getDirectoryConfig(e) {
|
|
841
|
-
let t =
|
|
653
|
+
let t = $.dirname($.normalize(e));
|
|
842
654
|
const s = [];
|
|
843
|
-
for (; t && t !==
|
|
844
|
-
const
|
|
845
|
-
|
|
655
|
+
for (; t && t !== $.dirname(t); ) {
|
|
656
|
+
const r = this.directoryConfigs.get(t);
|
|
657
|
+
r && s.unshift(r), t = $.dirname(t);
|
|
846
658
|
}
|
|
847
|
-
return s.reduce((
|
|
659
|
+
return s.reduce((r, o) => P(r, o), {});
|
|
848
660
|
}
|
|
849
661
|
}
|
|
850
|
-
let
|
|
851
|
-
async function
|
|
852
|
-
|
|
662
|
+
let w = null;
|
|
663
|
+
async function He(n, e) {
|
|
664
|
+
w = new Me(n, e), await w.loadAllConfigs();
|
|
665
|
+
}
|
|
666
|
+
function xe(n, e) {
|
|
667
|
+
return w ? w.getConfig(n, e) : (process.env.SF_DEBUG === "true" && console.log("[FuncSpan ConfigLoader] Config loader not initialized, using env config for worker process"), le());
|
|
853
668
|
}
|
|
854
|
-
function
|
|
855
|
-
return
|
|
669
|
+
function Ge() {
|
|
670
|
+
return w !== null;
|
|
856
671
|
}
|
|
857
|
-
|
|
858
|
-
|
|
672
|
+
const Ke = ["readFile", "writeFile", "appendFile", "readdir", "stat", "lstat", "fstat", "access", "open", "close", "read", "write", "chmod", "mkdir", "rmdir", "unlink", "rename"], ee = ["lookup", "resolve", "resolve4", "resolve6", "resolveAny", "resolveMx", "resolveNs", "resolveTxt", "reverse"], We = ["pbkdf2", "randomBytes", "scrypt", "generateKeyPair"], ze = ["gzip", "gunzip", "deflate", "inflate", "deflateRaw", "inflateRaw", "brotliCompress", "brotliDecompress"];
|
|
673
|
+
let te = !1;
|
|
674
|
+
function je(n) {
|
|
675
|
+
if (typeof n != "string") return !1;
|
|
676
|
+
const e = process.env.SF_FUNCSPAN_JSONL_FILE;
|
|
677
|
+
if (e && n.includes(e)) return !0;
|
|
678
|
+
const t = process.env.SF_WORKER_POOL_JSONL_FILE;
|
|
679
|
+
return !(!t || !n.includes(t));
|
|
680
|
+
}
|
|
681
|
+
let ne = !1;
|
|
682
|
+
function re(n) {
|
|
683
|
+
if (typeof n != "string") return !1;
|
|
684
|
+
if (n === "localhost" || n === "127.0.0.1" || n === "::1") return !0;
|
|
685
|
+
try {
|
|
686
|
+
const e = process.env.API_GRAPHQL_ENDPOINT;
|
|
687
|
+
if (e && n === new URL(e).hostname)
|
|
688
|
+
return !0;
|
|
689
|
+
} catch {
|
|
690
|
+
}
|
|
691
|
+
return !1;
|
|
859
692
|
}
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
693
|
+
function Be() {
|
|
694
|
+
if (!ne) try {
|
|
695
|
+
let n;
|
|
696
|
+
if (typeof require > "u") return void (process.env.SF_DEBUG === "true" && console.log("[WorkerPool] Skipping dns patching in pure ESM environment (require unavailable)"));
|
|
697
|
+
try {
|
|
698
|
+
n = require("node:dns");
|
|
699
|
+
} catch (e) {
|
|
700
|
+
return void (process.env.SF_DEBUG === "true" && console.log("[WorkerPool] Failed to require dns module:", e));
|
|
701
|
+
}
|
|
702
|
+
if (n.__sf_worker_pool_patched__) return;
|
|
703
|
+
Object.defineProperty(n, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
704
|
+
for (const e of ee) if (typeof n[e] == "function") {
|
|
705
|
+
const t = n[e];
|
|
706
|
+
n[e] = function(...s) {
|
|
707
|
+
return re(s[0]) ? t.apply(this, s) : typeof s[s.length - 1] == "function" ? R("dns", e, t, s, this) : t.apply(this, s);
|
|
708
|
+
}, Object.defineProperty(n[e], "name", { value: e, writable: !1 });
|
|
873
709
|
}
|
|
874
710
|
(function(e) {
|
|
875
711
|
if (!e.promises) return void (process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns.promises not available, skipping"));
|
|
876
712
|
if (!e.promises.__sf_worker_pool_patched__) {
|
|
877
713
|
Object.defineProperty(e.promises, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
878
|
-
for (const t of
|
|
714
|
+
for (const t of ee) if (typeof e.promises[t] == "function") {
|
|
879
715
|
const s = e.promises[t];
|
|
880
|
-
e.promises[t] = function(...
|
|
881
|
-
|
|
882
|
-
return typeof i != "string" || i !== "localhost" && i !== "127.0.0.1" ? Be("dns", t, s, n, this) : s.apply(this, n);
|
|
716
|
+
e.promises[t] = function(...r) {
|
|
717
|
+
return re(r[0]) ? s.apply(this, r) : ye("dns", t, s, r, this);
|
|
883
718
|
}, Object.defineProperty(e.promises[t], "name", { value: t, writable: !1 });
|
|
884
719
|
}
|
|
885
720
|
process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns.promises module patched successfully");
|
|
886
721
|
}
|
|
887
|
-
})(
|
|
888
|
-
} catch (
|
|
889
|
-
console.error("[WorkerPool] Error patching dns module:",
|
|
722
|
+
})(n), ne = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] dns module patched successfully");
|
|
723
|
+
} catch (n) {
|
|
724
|
+
console.error("[WorkerPool] Error patching dns module:", n);
|
|
890
725
|
}
|
|
891
726
|
}
|
|
892
|
-
let
|
|
893
|
-
function
|
|
894
|
-
if (
|
|
895
|
-
const
|
|
896
|
-
|
|
897
|
-
if (!
|
|
727
|
+
let se = !1, oe = !1, j = !1;
|
|
728
|
+
function Je() {
|
|
729
|
+
if (j) return;
|
|
730
|
+
const n = process.env.SF_DEBUG === "true";
|
|
731
|
+
n && console.log("[WorkerPool] Initializing worker pool patching..."), C("fs") && (n && console.log("[WorkerPool] Patching fs module..."), (function() {
|
|
732
|
+
if (!te) try {
|
|
898
733
|
const e = require("node:fs");
|
|
899
734
|
if (e.__sf_worker_pool_patched__) return;
|
|
900
735
|
Object.defineProperty(e, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
901
|
-
for (const t of
|
|
736
|
+
for (const t of Ke) if (typeof e[t] == "function") {
|
|
902
737
|
const s = e[t];
|
|
903
|
-
e[t] = function(...
|
|
904
|
-
return typeof
|
|
738
|
+
e[t] = function(...r) {
|
|
739
|
+
return je(r[0]) ? s.apply(this, r) : typeof r[r.length - 1] == "function" ? R("fs", t, s, r, this) : s.apply(this, r);
|
|
905
740
|
}, Object.defineProperty(e[t], "name", { value: t, writable: !1 });
|
|
906
741
|
}
|
|
907
|
-
|
|
742
|
+
te = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] fs module patched successfully");
|
|
908
743
|
} catch (e) {
|
|
909
744
|
console.error("[WorkerPool] Error patching fs module:", e);
|
|
910
745
|
}
|
|
911
|
-
})()),
|
|
912
|
-
if (!
|
|
746
|
+
})()), C("dns") && (n && console.log("[WorkerPool] Patching dns module..."), Be()), C("crypto") && (n && console.log("[WorkerPool] Patching crypto module..."), (function() {
|
|
747
|
+
if (!se) try {
|
|
913
748
|
const e = require("node:crypto");
|
|
914
749
|
if (e.__sf_worker_pool_patched__) return;
|
|
915
750
|
Object.defineProperty(e, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
916
|
-
for (const t of
|
|
751
|
+
for (const t of We) if (typeof e[t] == "function") {
|
|
917
752
|
const s = e[t];
|
|
918
|
-
e[t] = function(...
|
|
919
|
-
return typeof
|
|
753
|
+
e[t] = function(...r) {
|
|
754
|
+
return typeof r[r.length - 1] == "function" ? R("crypto", t, s, r, this) : s.apply(this, r);
|
|
920
755
|
}, Object.defineProperty(e[t], "name", { value: t, writable: !1 });
|
|
921
756
|
}
|
|
922
|
-
|
|
757
|
+
se = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] crypto module patched successfully");
|
|
923
758
|
} catch (e) {
|
|
924
759
|
console.error("[WorkerPool] Error patching crypto module:", e);
|
|
925
760
|
}
|
|
926
|
-
})()),
|
|
927
|
-
if (!
|
|
761
|
+
})()), C("zlib") && (n && console.log("[WorkerPool] Patching zlib module..."), (function() {
|
|
762
|
+
if (!oe) try {
|
|
928
763
|
const e = require("node:zlib");
|
|
929
764
|
if (e.__sf_worker_pool_patched__) return;
|
|
930
765
|
Object.defineProperty(e, "__sf_worker_pool_patched__", { value: !0, enumerable: !1, writable: !1, configurable: !1 });
|
|
931
|
-
for (const t of
|
|
766
|
+
for (const t of ze) if (typeof e[t] == "function") {
|
|
932
767
|
const s = e[t];
|
|
933
|
-
e[t] = function(...
|
|
934
|
-
return typeof
|
|
768
|
+
e[t] = function(...r) {
|
|
769
|
+
return typeof r[r.length - 1] == "function" ? R("zlib", t, s, r, this) : s.apply(this, r);
|
|
935
770
|
}, Object.defineProperty(e[t], "name", { value: t, writable: !1 });
|
|
936
771
|
}
|
|
937
|
-
|
|
772
|
+
oe = !0, process.env.SF_DEBUG === "true" && console.log("[WorkerPool] zlib module patched successfully");
|
|
938
773
|
} catch (e) {
|
|
939
774
|
console.error("[WorkerPool] Error patching zlib module:", e);
|
|
940
775
|
}
|
|
941
|
-
})()),
|
|
776
|
+
})()), j = !0, n && console.log("[WorkerPool] Worker pool patching initialized");
|
|
942
777
|
}
|
|
943
|
-
function
|
|
944
|
-
return
|
|
778
|
+
function Ve() {
|
|
779
|
+
return j;
|
|
945
780
|
}
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
781
|
+
let B = !1, W = !1;
|
|
782
|
+
function ot(n) {
|
|
783
|
+
if (W) console.warn("[setupInterceptors] ⚠️ Recursive call detected and blocked!");
|
|
784
|
+
else if (!B) {
|
|
785
|
+
W = !0;
|
|
786
|
+
try {
|
|
787
|
+
if (!n || !n.apiKey) {
|
|
788
|
+
const r = `The required API Key is not provided: ${JSON.stringify(n)}`;
|
|
789
|
+
console.error(r);
|
|
790
|
+
}
|
|
791
|
+
const { config: e } = ge(n);
|
|
792
|
+
if (e.sfDebug && console.log("Updated configuration after applying options:", e), !e.apiKey || !e.apiGraphqlEndpoint) {
|
|
793
|
+
const r = `The required config is not provided: ${JSON.stringify(e)}`;
|
|
794
|
+
throw console.error(r), new Error(r);
|
|
795
|
+
}
|
|
796
|
+
Ge() || He(void 0, e.sfDebug).catch((r) => {
|
|
797
|
+
e.sfDebug && console.error("[FuncSpan] Failed to initialize config loader:", r);
|
|
798
|
+
}), process.env.SF_WORKER_POOL_DISABLED === "true" ? e.sfDebug && console.log("[setupInterceptors] Worker pool patching DISABLED (SF_WORKER_POOL_DISABLED=true)") : Ve() || (Je(), e.sfDebug && console.log("[setupInterceptors] Worker pool patching initialized (DNS tracking enabled)"));
|
|
799
|
+
const t = new V();
|
|
800
|
+
t.setServiceUUID(e.serviceUUID), ve(t), (function(r = []) {
|
|
801
|
+
const o = new ke(r);
|
|
802
|
+
new Ae().doSend(o.getExcludedDomains());
|
|
803
|
+
const d = new Oe(), i = new Le();
|
|
804
|
+
o.patchFetch(d, i), o.patchHttp(d, i);
|
|
805
|
+
})(e.domainsToNotPropagateHeadersTo);
|
|
806
|
+
const s = new Te();
|
|
807
|
+
s.setServiceUUID(e.serviceUUID), be(s), Re(), new qe().send(), B = !0, e.sfDebug && console.log("[setupInterceptors] ✅ Initialization complete");
|
|
808
|
+
} finally {
|
|
809
|
+
W = !1;
|
|
963
810
|
}
|
|
964
|
-
|
|
965
|
-
console.log = (...I) => {
|
|
966
|
-
i("INFO", I.join(" ")), g(...I);
|
|
967
|
-
}, console.error = (...I) => {
|
|
968
|
-
i("ERROR", I.join(" ")), r(...I);
|
|
969
|
-
}, console.warn = (...I) => {
|
|
970
|
-
i("WARN", I.join(" ")), c(...I);
|
|
971
|
-
}, console.info = (...I) => {
|
|
972
|
-
i("INFO", I.join(" ")), a(...I);
|
|
973
|
-
}, d().logLevel === "DEBUG" && (console.debug = (...I) => {
|
|
974
|
-
i("DEBUG", I.join(" ")), l(...I);
|
|
975
|
-
});
|
|
976
|
-
})(t), (function(n = []) {
|
|
977
|
-
const i = new $e(n);
|
|
978
|
-
new ke().doSend(i.getExcludedDomains());
|
|
979
|
-
const g = new Ue(), r = new Te();
|
|
980
|
-
i.patchFetch(g, r), i.patchHttp(g, r);
|
|
981
|
-
})(e.domainsToNotPropagateHeadersTo);
|
|
982
|
-
const s = new Ke();
|
|
983
|
-
s.setServiceUUID(e.serviceUUID), Re(s), ze(), new Ee().send();
|
|
811
|
+
}
|
|
984
812
|
}
|
|
985
|
-
function
|
|
986
|
-
|
|
987
|
-
new he(n.apiKey).identify(o, e, t, s);
|
|
813
|
+
function it() {
|
|
814
|
+
return B;
|
|
988
815
|
}
|
|
989
|
-
function
|
|
990
|
-
const
|
|
991
|
-
new
|
|
816
|
+
function at(n, e, t, s = !1) {
|
|
817
|
+
const r = l();
|
|
818
|
+
new ue(r.apiKey).identify(n, e, t, s);
|
|
992
819
|
}
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
820
|
+
function ct(n, e = {}, t, s = !1) {
|
|
821
|
+
const r = l();
|
|
822
|
+
new ue(r.apiKey).addOrUpdateMetadata(n, e, t, s);
|
|
823
|
+
}
|
|
824
|
+
let z = null;
|
|
825
|
+
function dt(n, e, t, s) {
|
|
826
|
+
const r = function(...o) {
|
|
827
|
+
const d = ae(), i = d?.sfDebug || !1;
|
|
828
|
+
i && console.log(`[FuncSpan] captureFunctionSpan wrapper called for ${t}::${e}`);
|
|
829
|
+
const c = (function(g, y) {
|
|
830
|
+
const I = ce();
|
|
831
|
+
if (I) {
|
|
832
|
+
const v = de(I);
|
|
833
|
+
if (v) return process.env.SF_DEBUG === "true" && console.log(`[FuncSpan] Using HTTP header override for ${g}::${y}`), v;
|
|
1003
834
|
}
|
|
1004
835
|
try {
|
|
1005
|
-
return xe(
|
|
836
|
+
return xe(g, y);
|
|
1006
837
|
} catch {
|
|
1007
838
|
return { sample_rate: process.env.SF_FUNCSPAN_SAMPLE_RATE ? parseFloat(process.env.SF_FUNCSPAN_SAMPLE_RATE) : 1, capture_arguments: !0, capture_return_value: !0, arg_limit_mb: 1, return_limit_mb: 1, enable_sampling: !1, autocapture_all_child_functions: !1, capture_sf_veritas: !1, parse_json_strings: !1 };
|
|
1008
839
|
}
|
|
1009
840
|
})(t, e);
|
|
1010
|
-
if (
|
|
1011
|
-
if (c.sample_rate === 0) return
|
|
1012
|
-
|
|
1013
|
-
const a =
|
|
1014
|
-
a.setCurrentFunctionSpanId(
|
|
1015
|
-
const
|
|
1016
|
-
let
|
|
1017
|
-
c.capture_arguments && (
|
|
1018
|
-
|
|
1019
|
-
}),
|
|
841
|
+
if (i && console.log(`[FuncSpan] Config for ${t}::${e}:`, c), c.enable_sampling && c.sample_rate < 1 && Math.random() > c.sample_rate) return i && console.log(`[FuncSpan] Skipping ${e} due to sampling`), n.apply(this, o);
|
|
842
|
+
if (c.sample_rate === 0) return i && console.log(`[FuncSpan] Skipping ${e} - sample_rate is 0.0`), n.apply(this, o);
|
|
843
|
+
i && console.log(`[FuncSpan] Capturing function span for ${e}`);
|
|
844
|
+
const a = J.getInstance(), u = a.getCurrentFunctionSpanId(), f = ie();
|
|
845
|
+
a.setCurrentFunctionSpanId(f);
|
|
846
|
+
const h = process.hrtime.bigint(), m = Date.now();
|
|
847
|
+
let p = null;
|
|
848
|
+
c.capture_arguments && (p = {}, s.paramNames.forEach((g, y) => {
|
|
849
|
+
y < o.length && (p[g] = o[y]);
|
|
850
|
+
}), p && c.arg_limit_mb > 0 && (p = M(p, c.arg_limit_mb)));
|
|
1020
851
|
try {
|
|
1021
|
-
const
|
|
1022
|
-
if (
|
|
1023
|
-
const
|
|
1024
|
-
let
|
|
1025
|
-
return c.capture_return_value && c.return_limit_mb > 0 && (
|
|
1026
|
-
}, (
|
|
1027
|
-
const
|
|
1028
|
-
throw
|
|
852
|
+
const g = n.apply(this, o);
|
|
853
|
+
if (g && typeof g.then == "function") return u ? a.setCurrentFunctionSpanId(u) : a.clearCurrentFunctionSpanId(), g.then((N) => {
|
|
854
|
+
const O = process.hrtime.bigint(), L = Date.now(), k = Number(O - h);
|
|
855
|
+
let X = null;
|
|
856
|
+
return c.capture_return_value && c.return_limit_mb > 0 && (X = M(N, c.return_limit_mb)), U({ functionName: e, filePath: t, metadata: s, args: p, result: X, error: null, duration: L - m, durationNs: k, startTimeNs: h.toString(), async: !0, spanId: f, parentSpanId: u, pid: process.pid, threadId: T }), N;
|
|
857
|
+
}, (N) => {
|
|
858
|
+
const O = process.hrtime.bigint(), L = Date.now(), k = Number(O - h);
|
|
859
|
+
throw U({ functionName: e, filePath: t, metadata: s, args: p, result: null, error: N?.message || String(N), duration: L - m, durationNs: k, startTimeNs: h.toString(), async: !0, spanId: f, parentSpanId: u, pid: process.pid, threadId: T }), N;
|
|
1029
860
|
});
|
|
1030
|
-
const
|
|
1031
|
-
let
|
|
1032
|
-
return c.capture_return_value && c.return_limit_mb > 0 && (
|
|
1033
|
-
} catch (
|
|
1034
|
-
const
|
|
1035
|
-
throw
|
|
861
|
+
const y = process.hrtime.bigint(), I = Date.now(), v = Number(y - h);
|
|
862
|
+
let Q = null;
|
|
863
|
+
return c.capture_return_value && c.return_limit_mb > 0 && (Q = M(g, c.return_limit_mb)), U({ functionName: e, filePath: t, metadata: s, args: p, result: Q, error: null, duration: I - m, durationNs: v, startTimeNs: h.toString(), async: !1, spanId: f, parentSpanId: u, pid: process.pid, threadId: T }), u ? a.setCurrentFunctionSpanId(u) : a.clearCurrentFunctionSpanId(), g;
|
|
864
|
+
} catch (g) {
|
|
865
|
+
const y = process.hrtime.bigint(), I = Date.now(), v = Number(y - h);
|
|
866
|
+
throw U({ functionName: e, filePath: t, metadata: s, args: p, result: null, error: g?.message || String(g), duration: I - m, durationNs: v, startTimeNs: h.toString(), async: !1, spanId: f, parentSpanId: u, pid: process.pid, threadId: T }), u ? a.setCurrentFunctionSpanId(u) : a.clearCurrentFunctionSpanId(), g;
|
|
1036
867
|
}
|
|
1037
868
|
};
|
|
1038
|
-
Object.defineProperty(
|
|
1039
|
-
for (const
|
|
1040
|
-
return
|
|
1041
|
-
}
|
|
1042
|
-
function
|
|
1043
|
-
const e =
|
|
1044
|
-
t && console.log("[FuncSpan] captureSpanData called for:", { function:
|
|
1045
|
-
const s = { functionName:
|
|
869
|
+
Object.defineProperty(r, "name", { value: e, writable: !1 });
|
|
870
|
+
for (const o in n) n.hasOwnProperty(o) && (r[o] = n[o]);
|
|
871
|
+
return r;
|
|
872
|
+
}
|
|
873
|
+
function U(n) {
|
|
874
|
+
const e = ae(), t = e?.sfDebug || !1;
|
|
875
|
+
t && console.log("[FuncSpan] captureSpanData called for:", { function: n.functionName, file: n.filePath, duration: `${n.duration}ms`, async: n.async, error: n.error, spanId: n.spanId });
|
|
876
|
+
const s = { functionName: n.functionName, filePath: n.filePath, metadata: n.metadata, args: n.args, result: n.result, error: n.error, duration: n.duration, durationNs: n.durationNs, async: n.async, spanId: n.spanId, parentSpanId: n.parentSpanId };
|
|
1046
877
|
process.env.SF_FUNCSPAN_CONSOLE_OUTPUT === "true" && console.log(`
|
|
1047
|
-
📊 Function Span:`, { function: `${
|
|
1048
|
-
const
|
|
1049
|
-
if (
|
|
1050
|
-
const
|
|
878
|
+
📊 Function Span:`, { function: `${n.functionName} (${n.filePath}:${n.metadata.line}:${n.metadata.column})`, duration: `${n.duration.toFixed(2)}ms`, arguments: n.args, result: n.error ? `Error: ${n.error}` : n.result, spanId: n.spanId, parentSpanId: n.parentSpanId || "none" });
|
|
879
|
+
const r = process.env.SF_FUNCSPAN_JSONL_FILE;
|
|
880
|
+
if (r) try {
|
|
881
|
+
const o = r === "true" || r === "1" ? "funcspans.jsonl" : r, d = Date.now(), i = process.hrtime.bigint(), c = BigInt(n.startTimeNs), a = Number(i - c) / 1e6, u = new Date(d - a).toISOString(), f = JSON.stringify({ timestamp: u, functionName: n.functionName, filePath: n.filePath, line: n.metadata.line, column: n.metadata.column, duration: n.duration, durationNs: n.durationNs, startTimeNs: n.startTimeNs, arguments: n.args, returnValue: n.error ? { error: String(n.error) } : n.result, spanId: n.spanId, parentSpanId: n.parentSpanId, async: n.async, pid: n.pid, threadId: n.threadId }) + `
|
|
1051
882
|
`;
|
|
1052
|
-
|
|
1053
|
-
} catch (
|
|
1054
|
-
console.error("[FuncSpan] Error writing to JSONL file:",
|
|
883
|
+
De(o, f, "utf-8");
|
|
884
|
+
} catch (o) {
|
|
885
|
+
console.error("[FuncSpan] Error writing to JSONL file:", o);
|
|
1055
886
|
}
|
|
1056
887
|
if (t && console.log("[FuncSpan] Sending function span to transmitter:", s), process.env.SF_FUNCSPAN_SKIP_BACKEND !== "true") try {
|
|
1057
|
-
(
|
|
1058
|
-
} catch (
|
|
1059
|
-
t && console.error("[FuncSpan] Error sending function span:",
|
|
888
|
+
(z || (z = new Ie()), z).send([s]), t && console.log("[FuncSpan] Function span sent successfully");
|
|
889
|
+
} catch (o) {
|
|
890
|
+
t && console.error("[FuncSpan] Error sending function span:", o);
|
|
1060
891
|
}
|
|
1061
892
|
}
|
|
893
|
+
function lt(n) {
|
|
894
|
+
return !!n.includes("captureFunctionSpan(") || !!n.includes("@sailfish-ai/sf-veritas") || !(!n.includes("/* @sailfish-instrumented */") && !n.includes("// @sailfish-instrumented"));
|
|
895
|
+
}
|
|
1062
896
|
export {
|
|
1063
|
-
|
|
1064
|
-
|
|
897
|
+
J as ContextManager,
|
|
898
|
+
ct as addOrUpdateMetadata,
|
|
1065
899
|
dt as captureFunctionSpan,
|
|
1066
|
-
|
|
1067
|
-
|
|
900
|
+
gt as clearFuncspanOverride,
|
|
901
|
+
q as getCurrentFunctionSpanId,
|
|
1068
902
|
Se as getDefaultConfig,
|
|
1069
|
-
|
|
1070
|
-
|
|
903
|
+
le as getEnvConfig,
|
|
904
|
+
ce as getFuncspanOverride,
|
|
1071
905
|
xe as getGlobalConfig,
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
906
|
+
at as identify,
|
|
907
|
+
He as initializeConfigLoader,
|
|
908
|
+
Je as initializeWorkerPoolPatching,
|
|
909
|
+
lt as isAlreadyInstrumented,
|
|
910
|
+
Ge as isConfigLoaderInitialized,
|
|
911
|
+
yt as isProductionEnvironment,
|
|
912
|
+
It as isRuntimeModeEnabled,
|
|
913
|
+
it as isSetupInterceptorsInitialized,
|
|
914
|
+
Ve as isWorkerPoolInitialized,
|
|
1077
915
|
de as parseHeaderOverride,
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
916
|
+
ft as runWithContext,
|
|
917
|
+
mt as setFuncspanOverride,
|
|
918
|
+
vt as setSkipTypeScriptPlugin,
|
|
919
|
+
ot as setupInterceptors,
|
|
920
|
+
_t as shouldEnableRuntimeHooks,
|
|
921
|
+
bt as transformFunctionSpans,
|
|
922
|
+
Ft as transformFunctionSpansSync
|
|
1082
923
|
};
|