Merge pull request #55 from diegosouzapw/feat/unified-test-logging

feat(logging): unified Logger + Proxy logging for all test flows
This commit is contained in:
Diego Rodrigues de Sa e Souza
2026-02-16 18:19:26 -03:00
committed by GitHub
2 changed files with 40 additions and 1 deletions

View File

@@ -99,9 +99,12 @@ export async function POST(request) {
}
/**
* Get the base URL for internal requests
* Get the base URL for internal requests (VPS-safe: respects reverse proxy headers)
*/
function getBaseUrl(request) {
const fwdHost = request.headers.get("x-forwarded-host");
const fwdProto = request.headers.get("x-forwarded-proto") || "https";
if (fwdHost) return `${fwdProto}://${fwdHost}`;
const url = new URL(request.url);
return `${url.protocol}//${url.host}`;
}

View File

@@ -6,6 +6,8 @@ import { validateProviderApiKey } from "@/lib/providers/validation";
import { getCliRuntimeStatus } from "@/shared/services/cliRuntime";
// Use the shared open-sse token refresh with built-in dedup/race-condition cache
import { getAccessToken } from "@omniroute/open-sse/services/tokenRefresh.js";
import { saveCallLog } from "@/lib/usageDb.js";
import { logProxyEvent } from "@/lib/proxyLogger.js";
// OAuth provider test endpoints
const OAUTH_TEST_CONFIG = {
@@ -575,6 +577,40 @@ export async function testSingleConnection(connectionId) {
await syncToCloudIfEnabled();
}
// Log to Logger tab (call_logs table)
try {
saveCallLog({
method: "POST",
path: "/api/providers/test",
status: result.valid ? 200 : result.statusCode || 401,
model: "connection-test",
provider: connection.provider,
connectionId,
duration: latencyMs,
error: result.valid ? null : result.error || null,
sourceFormat: "test",
targetFormat: "test",
}).catch(() => {});
} catch {}
// Log to Proxy tab (proxy_logs table)
try {
logProxyEvent({
status: result.valid ? "success" : "error",
proxy: null,
level: "provider-test",
levelId: null,
provider: connection.provider,
targetUrl: `${connection.provider}/connection-test`,
latencyMs,
error: result.valid ? null : result.error || null,
connectionId,
comboId: null,
account: connectionId?.slice(0, 8) || null,
tlsFingerprint: false,
});
} catch {}
return {
valid: result.valid,
error: result.error,