Skip to content

feat(observability): structured JSON logs for the sandbox manager and log sanitization (#487) - #490

Merged
ArthurCRodrigues merged 2 commits into
mainfrom
feat/487
Nov 21, 2026
Merged

ArthurCRodrigues merged 2 commits into
mainfrom
feat/487

Conversation

@jaoppb

@jaoppb jaoppb commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #487
Part of webtech-network/prisma-infrastructure#92

Summary

  • One log format for both services. The formatter, request context and request middleware moved to sandbox_manager/structured_logging.py; web/config/logging.py imports it. Every line carries service, env and request_id. trace_id/span_id appear only when set; AG-3 ([Observability][AG-3] Instrument autograder-api & autograder-sandbox-manager with OpenTelemetry + Cut Release #489) will set them.
  • Sandbox manager: reads JSON_LOGS, LOG_LEVEL, SERVICE_NAME (default autograder-sandbox-manager) and APP_ENV. It starts as a Uvicorn factory (--factory sandbox_manager.api:create_app), so importing the module configures nothing and Uvicorn's first lines are already JSON. The module-level sandbox_manager.api:app is gone; prisma-infrastructure uses the image CMD.
  • Request lines: both services log one http_request_completed/http_request_failed line (logger http.request) per request. The line has method, the route template as path (<unmatched> when no route matched), status and duration_ms. Uvicorn's access line is off.
  • Request ids: X-Request-ID is kept only when it matches [A-Za-z0-9._:-]{1,128}; otherwise it is replaced. The response echoes it, and RemoteSandboxClient forwards it. The durable worker uses the grading attempt id as the request id.

Log audit: what no longer reaches a log

  • Sandbox handle IDs, which are bearer-like capabilities. They leaked through the raw /sandboxes/{id}/... paths in Uvicorn access lines, through urllib3/httpx URL logs, and through the chained requests exception in tracebacks (the client now raises from None).
  • Student external_user_id in /submissions/user/{id}, client IP:port and query strings.
  • The AI prompts, which contain student code. These were logged at DEBUG by our own code and by the openai SDK. AI provider error messages are gone too: the provider raises from None, and the Docker host now drops its client on PROVIDER_UNAVAILABLE instead of checking the error's cause.
  • S3 signed headers (botocore at DEBUG). The urllib3, httpx, httpcore, openai, botocore, boto3 and s3transfer loggers log warnings only, even at LOG_LEVEL=DEBUG.

There is no generic regex scrubber: each leak is fixed where it originates, and Alloy redaction (ADR-001 D7) is the defense in depth.

Out of scope

Verification

  • make test and make test-web pass locally (1689 + 499 tests).
  • New tests: tests/unit/sandbox/test_structured_logging.py, tests/web/test_request_logging.py, and a test for the AI provider's logs.
  • Two local-only failures, not caused by this change:
    • Pylint E1136 on untouched SQLAlchemy models, under local Python 3.13.18 (CI uses 3.13.11).
    • A botocore ~/.aws login-provider failure in test_fixture_provider. It passes with the AWS config isolated.
  • Multi-lens review (code-quality, security, observability, testing, devops) approved in round 2.

🤖 Generated with Claude Code

Copilot AI balanced review requested due to automatic review settings November 21, 2026 16:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@jaoppb jaoppb changed the title feat/487 feat(observability): structured JSON logs for the sandbox manager and log sanitization (#487) Nov 21, 2026
@ArthurCRodrigues

Copy link
Copy Markdown
Member

@jaoppb your PR is completely broken.

@jaoppb

jaoppb commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator Author

@jaoppb your PR is completely broken.

will fix it, waiting for the tokens limit to reset

… log sanitization (#487)

- One shared formatter, request context and request middleware
  (sandbox_manager/structured_logging.py) used by the API and the sandbox
  manager: service, env, request_id, and trace_id/span_id only when set.
- The sandbox manager reads JSON_LOGS, LOG_LEVEL, SERVICE_NAME
  (autograder-sandbox-manager) and APP_ENV and starts as a Uvicorn factory,
  so every line, from the first, is structured.
- Request lines log the route template, never the raw path, query string or
  client address; Uvicorn's access line is off and the URL-bearing lines of
  urllib3/httpx are capped at WARNING (sandbox handles are capabilities,
  user ids identify students).
- X-Request-ID is accepted only when well-formed, echoed, and forwarded by
  RemoteSandboxClient; the durable worker uses the attempt id.
- The AI provider no longer logs prompts (student code) or provider messages.
- Request-dumping libraries (urllib3, httpx, httpcore, openai, botocore,
  boto3, s3transfer) log warnings only, even at LOG_LEVEL=DEBUG.
- Sandbox transport errors and AI provider failures no longer chain the
  library exception whose message held the handle URL or the request; the
  Docker host drops its AI client on PROVIDER_UNAVAILABLE instead of
  inspecting the cause.
- Request lines use the "http.request" logger in both services.
- Tests: failed-request line, transport traceback, AI provider logs,
  environment settings, the image's factory command.
@ArthurCRodrigues
ArthurCRodrigues merged commit d4f00a6 into main Nov 21, 2026
7 checks passed
@ArthurCRodrigues
ArthurCRodrigues deleted the feat/487 branch November 21, 2026 23:07
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.

[Observability][AG-1] Sanitize Logs & Emit Structured JSON Logs from autograder-sandbox-manager

3 participants