Skip to content

feat(relay): log non-429/403 upstream errors to KV for debugging#23

Open
iceteaSA wants to merge 1 commit into
cortexkit:mainfrom
iceteaSA:feat/relay-kv-error-logging
Open

feat(relay): log non-429/403 upstream errors to KV for debugging#23
iceteaSA wants to merge 1 commit into
cortexkit:mainfrom
iceteaSA:feat/relay-kv-error-logging

Conversation

@iceteaSA
Copy link
Copy Markdown

Summary

Adds logUpstreamError() to the relay worker script. When the upstream Anthropic API returns 4xx/5xx (excluding 429 and 403, which are expected during normal rate-limiting), the error details are written to the RELAY_STATE KV namespace with a 7-day TTL.

What's logged

  • HTTP status and status text
  • Response body (first 50KB)
  • Response headers
  • Transport mode (http/websocket)
  • Session affinity
  • Request ID and body size

Where it's called

  • WebSocket handler — after upstream fetch, before streaming response back
  • HTTP handler — after upstream fetch, before returning response

Why

Debugging production relay issues currently requires live wrangler tail access. This provides a persistent, queryable error log via KV that survives disconnects and can be inspected hours/days later.

429 and 403 are excluded because they're normal rate-limit and auth responses that would flood the log.

Testing

All 214 tests pass. The logging is fire-and-forget via ctx.waitUntil — no impact on response latency.

Adds logUpstreamError() to the worker script that writes error details
to KV with 7-day TTL when the upstream Anthropic API returns 4xx/5xx
(excluding 429 and 403 which are expected during normal operation).

Logs include: status, headers, response body preview, transport mode,
and affinity. Helps diagnose production issues without needing live
Worker tail access.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant