fix: 遥测改用 TELEMETRY_ENDPOINT,不复用 hookUrl
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
fd018ccd6a
commit
c3523d002e
|
|
@ -38,3 +38,8 @@ ONEBOUND_KEYWORD_SEARCH_ENDPOINT=http://localhost:3202/api/v1/tasks/keyword-sear
|
||||||
# Auth(由 auth-rt 自动处理,配置见 ~/.openclaw/.env)
|
# Auth(由 auth-rt 自动处理,配置见 ~/.openclaw/.env)
|
||||||
# 只需在 ~/.openclaw/.env 中设置 CLIENT_KEY=sk_xxx
|
# 只需在 ~/.openclaw/.env 中设置 CLIENT_KEY=sk_xxx
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# 遥测(可选)— 上报 skill 执行结果到服务端 Loki,用于调试
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# TELEMETRY_ENDPOINT=http://localhost:3202/api/v1/tasks/telemetry
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,6 @@
|
||||||
import { resolve } from 'path';
|
import { resolve } from 'path';
|
||||||
import type { Command } from '../src/types.ts';
|
import type { Command } from '../src/types.ts';
|
||||||
import { run } from '../src/index.ts';
|
import { run } from '../src/index.ts';
|
||||||
import { createSkillClient } from '../src/auth-cli.ts';
|
|
||||||
|
|
||||||
const SKILL_NAME = 'video-product-snapshot';
|
const SKILL_NAME = 'video-product-snapshot';
|
||||||
|
|
||||||
// Load .env from skill root (does not override existing env vars)
|
// Load .env from skill root (does not override existing env vars)
|
||||||
|
|
@ -52,14 +50,14 @@ Config: ~/.openclaw/.env (CLIENT_KEY), skill .env (VISION_API_KEY)
|
||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function reportHook(
|
function reportTelemetry(payload: object): void {
|
||||||
hookUrl: string,
|
const endpoint = process.env.TELEMETRY_ENDPOINT;
|
||||||
hookToken: string | undefined,
|
if (!endpoint) return;
|
||||||
payload: object,
|
fetch(endpoint, {
|
||||||
): Promise<void> {
|
method: 'POST',
|
||||||
const headers: Record<string, string> = { 'Content-Type': 'application/json' };
|
headers: { 'Content-Type': 'application/json' },
|
||||||
if (hookToken) headers['Authorization'] = `Bearer ${hookToken}`;
|
body: JSON.stringify(payload),
|
||||||
await fetch(hookUrl, { method: 'POST', headers, body: JSON.stringify(payload) });
|
}).catch(() => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main(): Promise<void> {
|
async function main(): Promise<void> {
|
||||||
|
|
@ -81,19 +79,6 @@ async function main(): Promise<void> {
|
||||||
if (positionals.length < 1) { printUsage(); process.exit(1); }
|
if (positionals.length < 1) { printUsage(); process.exit(1); }
|
||||||
|
|
||||||
const command = positionals[0] as Command;
|
const command = positionals[0] as Command;
|
||||||
|
|
||||||
// Exchange CLIENT_KEY for session — gives us hookUrl for telemetry
|
|
||||||
let hookUrl: string | undefined;
|
|
||||||
let hookToken: string | undefined;
|
|
||||||
try {
|
|
||||||
const client = createSkillClient({ dryRun });
|
|
||||||
const session = await client.session();
|
|
||||||
hookUrl = session.hookUrl;
|
|
||||||
hookToken = session.hookToken;
|
|
||||||
} catch {
|
|
||||||
// Auth failure is non-fatal for telemetry; skill still runs
|
|
||||||
}
|
|
||||||
|
|
||||||
const startMs = Date.now();
|
const startMs = Date.now();
|
||||||
let result: Awaited<ReturnType<typeof run>>;
|
let result: Awaited<ReturnType<typeof run>>;
|
||||||
|
|
||||||
|
|
@ -101,29 +86,13 @@ async function main(): Promise<void> {
|
||||||
result = await run(command, positionals.slice(1), dryRun);
|
result = await run(command, positionals.slice(1), dryRun);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const error = err instanceof Error ? err.message : String(err);
|
const error = err instanceof Error ? err.message : String(err);
|
||||||
const failed = { status: 'failed' as const, command, dryRun, error };
|
console.log(JSON.stringify({ status: 'failed', command, dryRun, error }, null, 2));
|
||||||
console.log(JSON.stringify(failed, null, 2));
|
if (!dryRun) reportTelemetry({ skill: SKILL_NAME, command, status: 'failed', durationMs: Date.now() - startMs, error });
|
||||||
|
|
||||||
if (hookUrl && !dryRun) {
|
|
||||||
reportHook(hookUrl, hookToken, {
|
|
||||||
skill: SKILL_NAME, command, status: 'failed',
|
|
||||||
durationMs: Date.now() - startMs, error,
|
|
||||||
}).catch(() => {});
|
|
||||||
}
|
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(JSON.stringify(result, null, 2));
|
console.log(JSON.stringify(result, null, 2));
|
||||||
|
if (!dryRun) reportTelemetry({ skill: SKILL_NAME, command, status: result.status, durationMs: Date.now() - startMs, error: (result as any).error });
|
||||||
if (hookUrl && !dryRun) {
|
|
||||||
reportHook(hookUrl, hookToken, {
|
|
||||||
skill: SKILL_NAME,
|
|
||||||
command,
|
|
||||||
status: result.status,
|
|
||||||
durationMs: Date.now() - startMs,
|
|
||||||
error: (result as any).error,
|
|
||||||
}).catch(() => {});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main().catch((err) => {
|
main().catch((err) => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue