feat: structured access logging and distributed log tracing#2053
Open
hansent wants to merge 1 commit intofeat/model-cold-start-and-id-response-headersfrom
Open
feat: structured access logging and distributed log tracing#2053hansent wants to merge 1 commit intofeat/model-cold-start-and-id-response-headersfrom
hansent wants to merge 1 commit intofeat/model-cold-start-and-id-response-headersfrom
Conversation
- Add structured access log middleware (gated behind API_LOGGING_ENABLED) that emits JSON log entries with method, path, status_code, request_id, and all response header values (processing_time, model_cold_start, model_id, workflow_id, workspace_id) - Add execution_id to structlog output so every log entry across all services includes the distributed trace ID when set - Suppress uvicorn's default access logger when structured logging is active to avoid duplicate unstructured entries - Propagate ASGI correlation_id into worker threads so logs from workflow steps running in ThreadPoolExecutor include request_id - Add execution_id to CORS expose_headers for browser client access Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
API_LOGGING_ENABLED) replacing uvicorn's unstructured access log with JSON entries containingmethod,path,status_code,request_id, and all response header valuesexecution_idto structlog output so every log entry includes the distributed trace ID — enables cross-service log correlation when using remote workflow executioncorrelation_idinto worker threads so logs from workflow steps inThreadPoolExecutorincluderequest_idexecution_idto CORSexpose_headersHow tracing works
Within a service: All logs (including from worker threads) now include
request_idfor per-request correlation.Across services (CPU primary → GPU workers): All logs include
execution_idwhich is already forwarded to remote workers via SDK headers. Search GCP logs byexecution_idto see all entries across all services for a request.Example structured access log entry (GCP)
{ "message": "access", "severity": "INFO", "request_id": "a1b2c3d4e5f6", "execution_id": "1740631234567890123_abc1", "method": "POST", "path": "/model-id/1", "status_code": 200, "processing_time": "1.234", "model_cold_start": "false", "model_id": "model-id/1", "workspace_id": "my-workspace" }Test plan
API_LOGGING_ENABLED=True→ verify structured JSON access log with all fieldsapi_keynever appears in logs🤖 Generated with Claude Code