Decode third-party errors with request ids
"No way to reproduce" is what a support ticket says when it lacks the provider's request id. Capture the id, the request, and the raw body the moment a call fails.
Procedure
- Read the request id from the response header on every call:
x-request-id,x-amzn-RequestId,cf-ray. - Log it with the failure:
rid = r.headers.get("x-request-id") log.error("call failed rid=%s status=%s url=%s", rid, r.status_code, r.url) - Capture the raw body before parsing; error formats vary (
{"error": {...}},{"message": "..."}, plain text):raw = r.text[:2000] - Redact secrets before logging: strip
Authorization,api_key, and cookies. - Put status, request-id, method, and a body snippet into the raised exception — no query secrets.
- Only open a support ticket with the request id and a UTC timestamp; "it failed" is not a report.
- Keep a small ring buffer of the last N requests for postmortem context.
Pitfalls
- Logging the full URL leaks API keys that are query params; redact the query string.
- Each retry has a different request id; log the id of the attempt that finally failed.
- Truncating the body too early hides the field that explains the error.
- Local clock skew makes the timestamp useless to support; use UTC with an offset.
- Providers may return the id only on 5xx, not 4xx — scrape both headers and body.
Verification
grep 'rid=' run.log | tail -1
# rid=01HZ... status=503 url=/v1/items
Report: "Support ticket carries request-id 01HZ..., status 503, timestamp 2026-10-08T...Z, body 'upstream timeout'."