feat: add request ID propagation from Rust to Bun with structured logging

- Forward x-request-id header through proxy and API calls
- Store RequestId in request extensions for downstream access
- Add AsyncLocalStorage context to correlate logs across async boundaries
- Improve migration logging to show pending changes before applying
- Reduce noise in logs (common OG images, health checks)
This commit is contained in:
2026-01-13 16:42:14 -06:00
parent 6d8766d3a6
commit a6cc0b8e66
13 changed files with 173 additions and 53 deletions
+13 -6
View File
@@ -6,13 +6,20 @@ const API_SOCKET = "/tmp/api.sock";
const PORT = process.env.PORT || "8080";
const LOG_JSON = process.env.LOG_JSON || "true";
function tryUnlink(path: string) {
try {
unlinkSync(path);
} catch (e) {
// ENOENT is expected (socket doesn't exist yet), other errors are unexpected
if (e instanceof Error && "code" in e && e.code !== "ENOENT") {
console.error(`Failed to cleanup ${path}: ${e.message}`);
}
}
}
function cleanup() {
try {
unlinkSync(BUN_SOCKET);
} catch {}
try {
unlinkSync(API_SOCKET);
} catch {}
tryUnlink(BUN_SOCKET);
tryUnlink(API_SOCKET);
}
// Cleanup on signals