Bump version to 0.1.3; enhance logging with correlation_id for better error tracing and add request lifecycle middleware

This commit is contained in:
Guangfei.Zhao
2026-07-23 22:50:52 +08:00
parent ac79dd0618
commit bba1cc2f56
10 changed files with 220 additions and 4 deletions
+29
View File
@@ -29,7 +29,9 @@ nexus-claude-api/
__main__.py
cli.py
config.py
diagnostics.py
errors.py
logging_config.py
models.py
nexus_client.py
server.py
@@ -212,6 +214,28 @@ Status mapping:
- Nexus throttling: `429`
- Nexus network/timeout: `502` or `504`
- unexpected server error: `500`
- client disconnected: `499` (logged only, not sent)
## Observability
All errors are logged to the daily log file with a `correlation_id` for tracing.
Request lifecycle middleware logs:
- `request_complete` with method, path, status, and duration_ms for every `/v1/messages` request.
- `client_disconnected` when the client drops connection mid-request or mid-stream.
- `unhandled_exception` with traceback for unexpected errors (returns 500).
Error logging at point of origin:
- `nexus_client_error` (WARNING): Nexus API returned an error (4xx/5xx) with error code, message, HTTP status, and request ID.
- `nexus_botocore_error` (WARNING): Network/transport failure (timeout, DNS, connection reset).
- `stream_nexus_error` (WARNING): Error during streaming response iteration.
- `stream_client_disconnected` (INFO): Client closed connection during streaming.
- `validation_error` (WARNING): Malformed request that failed pydantic validation.
- `nexus_error` (WARNING): NexusClaudeError in non-streaming response path.
Diagnostics summarize each request (model, stream flag, message count, content block types, tool info) without logging secrets, prompt text, or base64 data.
## Testing
@@ -234,6 +258,11 @@ Route tests:
- `POST /v1/messages` non-stream
- `POST /v1/messages` stream
- `POST /v1/messages/count_tokens`
- Validation errors are logged with correlation_id.
- Nexus errors (non-stream) are logged with status and type.
- Nexus errors (stream) are logged as `stream_nexus_error`.
- Request completion is logged with duration_ms.
- Unexpected exceptions return 500 and are logged.
CLI tests: