@autter/runtime-node 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +106 -16
- package/dist/chunk-3TJHUCZ6.js +1680 -0
- package/dist/chunk-GI47WGRR.cjs +779 -0
- package/dist/chunk-L6SRL65J.cjs +202 -0
- package/dist/chunk-L7HWKMCZ.js +779 -0
- package/dist/chunk-P4VRTFAV.cjs +1680 -0
- package/dist/chunk-ZS4WQJQR.js +202 -0
- package/dist/cli.cjs +40 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +40 -0
- package/dist/index.cjs +1272 -1141
- package/dist/index.d.cts +420 -42
- package/dist/index.d.ts +420 -42
- package/dist/index.js +1083 -917
- package/dist/sinks-RFV76lF1.d.cts +313 -0
- package/dist/sinks-RFV76lF1.d.ts +313 -0
- package/dist/testing.cjs +121 -0
- package/dist/testing.d.cts +57 -0
- package/dist/testing.d.ts +57 -0
- package/dist/testing.js +121 -0
- package/package.json +16 -5
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunkGI47WGRRcjs = require('./chunk-GI47WGRR.cjs');
|
|
9
|
+
|
|
10
|
+
// src/doctor.ts
|
|
11
|
+
var _fs = require('fs');
|
|
12
|
+
var _path = require('path');
|
|
13
|
+
var SDK_PACKAGES = ["@autter/runtime-node", "@autter/runtime-next", "@autter/runtime-browser"];
|
|
14
|
+
var DEFAULT_ENDPOINT = "https://otlp.autter.dev";
|
|
15
|
+
function resolveEndpoint(flag, env = process.env) {
|
|
16
|
+
return (flag || env.AUTTER_ENDPOINT || env.AUTTER_RUNTIME_ENDPOINT || env.OTEL_EXPORTER_OTLP_ENDPOINT || DEFAULT_ENDPOINT).replace(/\/$/, "");
|
|
17
|
+
}
|
|
18
|
+
function installedSdks(cwd) {
|
|
19
|
+
const found = /* @__PURE__ */ new Map();
|
|
20
|
+
for (let dir = cwd; ; dir = _path.dirname.call(void 0, dir)) {
|
|
21
|
+
for (const name of SDK_PACKAGES) {
|
|
22
|
+
if (found.has(name)) continue;
|
|
23
|
+
const file = _path.join.call(void 0, dir, "node_modules", ...name.split("/"), "package.json");
|
|
24
|
+
if (!_fs.existsSync.call(void 0, file)) continue;
|
|
25
|
+
try {
|
|
26
|
+
const version = JSON.parse(_fs.readFileSync.call(void 0, file, "utf8")).version;
|
|
27
|
+
if (typeof version === "string") found.set(name, version);
|
|
28
|
+
} catch (e) {
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (_path.dirname.call(void 0, dir) === dir) break;
|
|
32
|
+
}
|
|
33
|
+
if (!found.has(_chunkGI47WGRRcjs.SDK_IDENTITY.name)) found.set(_chunkGI47WGRRcjs.SDK_IDENTITY.name, _chunkGI47WGRRcjs.SDK_IDENTITY.version);
|
|
34
|
+
return [...found].map(([name, version]) => ({ name, version }));
|
|
35
|
+
}
|
|
36
|
+
function featuresInUse(sdks) {
|
|
37
|
+
return _chunkGI47WGRRcjs.COMPAT_MANIFEST.features.filter(
|
|
38
|
+
(feature) => sdks.some((sdk) => {
|
|
39
|
+
const min = feature.sdks[sdk.name];
|
|
40
|
+
return min !== void 0 && _chunkGI47WGRRcjs.versionAtLeast.call(void 0, sdk.version, min) === true;
|
|
41
|
+
})
|
|
42
|
+
).map((feature) => feature.id);
|
|
43
|
+
}
|
|
44
|
+
async function checkKey(endpoint, key, timeoutMs) {
|
|
45
|
+
const res = await _chunkGI47WGRRcjs.compatRequest.call(void 0, "POST", `${endpoint}/v1/traces`, {
|
|
46
|
+
body: JSON.stringify({ resourceSpans: [] }),
|
|
47
|
+
headers: { authorization: `Bearer ${key}` },
|
|
48
|
+
unref: false,
|
|
49
|
+
timeoutMs
|
|
50
|
+
});
|
|
51
|
+
if (!res) return "unknown";
|
|
52
|
+
if (res.status >= 200 && res.status < 300) return "accepted";
|
|
53
|
+
if (res.status === 401) return "rejected";
|
|
54
|
+
if (res.status === 403) return "client_key";
|
|
55
|
+
if (res.status === 503) return "storage_unavailable";
|
|
56
|
+
return "unknown";
|
|
57
|
+
}
|
|
58
|
+
async function runDoctor(options = {}) {
|
|
59
|
+
const endpoint = resolveEndpoint(options.endpoint);
|
|
60
|
+
const timeoutMs = _nullishCoalesce(options.timeoutMs, () => ( 5e3));
|
|
61
|
+
const sdks = installedSdks(_nullishCoalesce(options.cwd, () => ( process.cwd())));
|
|
62
|
+
const features = _optionalChain([options, 'access', _ => _.features, 'optionalAccess', _2 => _2.length]) ? options.features : featuresInUse(sdks);
|
|
63
|
+
const routes = [
|
|
64
|
+
...new Set(
|
|
65
|
+
features.map((id) => _optionalChain([_chunkGI47WGRRcjs.COMPAT_MANIFEST, 'access', _3 => _3.features, 'access', _4 => _4.find, 'call', _5 => _5((f) => f.id === id), 'optionalAccess', _6 => _6.route])).filter((route) => Boolean(route))
|
|
66
|
+
)
|
|
67
|
+
];
|
|
68
|
+
const { info, error } = await _chunkGI47WGRRcjs.fetchIngesterCompat.call(void 0, endpoint, { probeRoutes: routes, unref: false, timeoutMs });
|
|
69
|
+
const issues = [];
|
|
70
|
+
const seen = /* @__PURE__ */ new Set();
|
|
71
|
+
const add = (issue) => {
|
|
72
|
+
const key2 = `${issue.feature}:${issue.kind}:${issue.component}`;
|
|
73
|
+
if (!seen.has(key2)) {
|
|
74
|
+
seen.add(key2);
|
|
75
|
+
issues.push(issue);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
_chunkGI47WGRRcjs.evaluateCompat.call(void 0, { features, ingester: info }).forEach(add);
|
|
79
|
+
for (const sdk of sdks) {
|
|
80
|
+
if (_optionalChain([options, 'access', _7 => _7.features, 'optionalAccess', _8 => _8.length])) {
|
|
81
|
+
_chunkGI47WGRRcjs.evaluateCompat.call(void 0, { features: options.features, ingester: null, sdk }).forEach(add);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const key = options.key ? await checkKey(endpoint, options.key, timeoutMs) : void 0;
|
|
85
|
+
const featureRows = features.flatMap((id) => {
|
|
86
|
+
const feature = _chunkGI47WGRRcjs.COMPAT_MANIFEST.features.find((f) => f.id === id);
|
|
87
|
+
if (!feature) return [];
|
|
88
|
+
const bad = issues.some((issue) => issue.feature === id);
|
|
89
|
+
const known = _optionalChain([info, 'optionalAccess', _9 => _9.version]) != null || feature.route !== void 0 && _optionalChain([info, 'optionalAccess', _10 => _10.routes, 'optionalAccess', _11 => _11[feature.route]]) !== void 0;
|
|
90
|
+
return [{ id, title: feature.title, status: bad ? "incompatible" : known ? "ok" : "unknown" }];
|
|
91
|
+
});
|
|
92
|
+
const exitCode = !info ? 2 : issues.length || key === "rejected" || key === "client_key" || key === "storage_unavailable" ? 1 : 0;
|
|
93
|
+
return {
|
|
94
|
+
endpoint,
|
|
95
|
+
sdks,
|
|
96
|
+
ingester: info,
|
|
97
|
+
...error && !info ? { ingesterError: error } : {},
|
|
98
|
+
...key ? { key } : {},
|
|
99
|
+
features: featureRows,
|
|
100
|
+
issues,
|
|
101
|
+
exitCode
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function formatDoctorReport(report) {
|
|
105
|
+
const lines = [];
|
|
106
|
+
lines.push(`Autter Runtime doctor`);
|
|
107
|
+
lines.push(` endpoint ${report.endpoint}`);
|
|
108
|
+
for (const sdk of report.sdks) lines.push(` sdk ${sdk.name}@${sdk.version}`);
|
|
109
|
+
if (!report.ingester) {
|
|
110
|
+
lines.push(` ingester unreachable or unidentified (${_nullishCoalesce(report.ingesterError, () => ( "unknown error"))})`);
|
|
111
|
+
} else if (report.ingester.version) {
|
|
112
|
+
lines.push(` ingester @autter/otlp-ingester@${report.ingester.version}`);
|
|
113
|
+
const schema = report.ingester.schema;
|
|
114
|
+
if (schema) {
|
|
115
|
+
lines.push(
|
|
116
|
+
` schema ${schema.status}${schema.applied.length ? ` (level ${schema.applied[schema.applied.length - 1]})` : ""}`
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
} else {
|
|
120
|
+
lines.push(` ingester 1.4.0 or older (no /v1/compat endpoint; upgrade for a full report)`);
|
|
121
|
+
}
|
|
122
|
+
if (report.key) {
|
|
123
|
+
const text = {
|
|
124
|
+
accepted: "accepted",
|
|
125
|
+
rejected: "REJECTED (401): check AUTTER_RUNTIME_KEY",
|
|
126
|
+
client_key: "is a client/browser key; server SDKs need a server key",
|
|
127
|
+
storage_unavailable: "accepted, but the ingester's ClickHouse is unavailable (503)",
|
|
128
|
+
unknown: "could not be verified"
|
|
129
|
+
}[report.key];
|
|
130
|
+
lines.push(` key ${text}`);
|
|
131
|
+
}
|
|
132
|
+
if (report.features.length) {
|
|
133
|
+
lines.push("", "Features");
|
|
134
|
+
for (const feature of report.features) {
|
|
135
|
+
const mark = feature.status === "ok" ? "ok " : feature.status === "incompatible" ? "FAIL" : "?? ";
|
|
136
|
+
lines.push(` ${mark} ${feature.title} (${feature.id})`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (report.issues.length) {
|
|
140
|
+
lines.push("", "Problems");
|
|
141
|
+
for (const issue of report.issues) lines.push(` - ${issue.message}`);
|
|
142
|
+
}
|
|
143
|
+
lines.push(
|
|
144
|
+
"",
|
|
145
|
+
report.exitCode === 0 ? "Compatible." : report.exitCode === 1 ? "Incompatible: see the problems above." : "Could not check the ingester. Pass --endpoint <url> (or set AUTTER_ENDPOINT)."
|
|
146
|
+
);
|
|
147
|
+
return lines.join("\n");
|
|
148
|
+
}
|
|
149
|
+
var DOCTOR_USAGE = `Usage: npx @autter/runtime-node doctor [options]
|
|
150
|
+
|
|
151
|
+
Checks that your Autter SDKs, ingester and ClickHouse schema versions match.
|
|
152
|
+
|
|
153
|
+
Options:
|
|
154
|
+
--endpoint <url> Ingester base URL (default: $AUTTER_ENDPOINT, $OTEL_EXPORTER_OTLP_ENDPOINT, or ${DEFAULT_ENDPOINT})
|
|
155
|
+
--key <key> Also verify an ingest key (default: $AUTTER_RUNTIME_KEY)
|
|
156
|
+
--features <a,b> Only check these features (${_chunkGI47WGRRcjs.COMPAT_MANIFEST.features.map((f) => f.id).join(", ")})
|
|
157
|
+
--json Machine-readable output
|
|
158
|
+
--timeout <ms> Per-request timeout (default 5000)
|
|
159
|
+
|
|
160
|
+
Exit codes: 0 compatible, 1 mismatch or rejected key, 2 ingester unreachable.`;
|
|
161
|
+
function parseDoctorArgs(argv, env = process.env) {
|
|
162
|
+
const options = {};
|
|
163
|
+
for (let i = 0; i < argv.length; i++) {
|
|
164
|
+
const arg = argv[i];
|
|
165
|
+
const [flag, inline] = arg.includes("=") ? [arg.slice(0, arg.indexOf("=")), arg.slice(arg.indexOf("=") + 1)] : [arg, void 0];
|
|
166
|
+
const value = () => _nullishCoalesce(inline, () => ( argv[++i]));
|
|
167
|
+
switch (flag) {
|
|
168
|
+
case "-h":
|
|
169
|
+
case "--help":
|
|
170
|
+
return { help: true };
|
|
171
|
+
case "--endpoint":
|
|
172
|
+
options.endpoint = value();
|
|
173
|
+
break;
|
|
174
|
+
case "--key":
|
|
175
|
+
options.key = value();
|
|
176
|
+
break;
|
|
177
|
+
case "--features":
|
|
178
|
+
options.features = (_nullishCoalesce(value(), () => ( ""))).split(",").map((f) => f.trim()).filter(Boolean);
|
|
179
|
+
break;
|
|
180
|
+
case "--json":
|
|
181
|
+
options.json = true;
|
|
182
|
+
break;
|
|
183
|
+
case "--timeout": {
|
|
184
|
+
const ms = Number(value());
|
|
185
|
+
if (!Number.isFinite(ms) || ms <= 0) return { error: "--timeout needs a positive number of ms" };
|
|
186
|
+
options.timeoutMs = ms;
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
default:
|
|
190
|
+
return { error: `unknown option ${arg}` };
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (!options.key && env.AUTTER_RUNTIME_KEY) options.key = env.AUTTER_RUNTIME_KEY;
|
|
194
|
+
return options;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
exports.runDoctor = runDoctor; exports.formatDoctorReport = formatDoctorReport; exports.DOCTOR_USAGE = DOCTOR_USAGE; exports.parseDoctorArgs = parseDoctorArgs;
|