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
+3
View File
@@ -1,5 +1,6 @@
import { dev } from "$app/environment";
import { configure, getConsoleSink, type LogRecord } from "@logtape/logtape";
import { requestContext } from "$lib/server/context";
interface RailwayLogEntry {
timestamp: string;
@@ -10,12 +11,14 @@ interface RailwayLogEntry {
}
function railwayFormatter(record: LogRecord): string {
const ctx = requestContext.getStore();
const categoryTarget = record.category.join(":");
const entry: RailwayLogEntry = {
timestamp: new Date().toISOString(),
level: record.level.toLowerCase(),
message: record.message.join(" "),
target: categoryTarget ? `bun:${categoryTarget}` : "bun",
...(ctx?.requestId && { req_id: ctx.requestId }),
};
if (record.properties && Object.keys(record.properties).length > 0) {