Skip to content

Comments

feat: structlog core migration + fix flaky middleware tests (#215)#219

Merged
arthurfantaci merged 2 commits intomainfrom
rc/structlog-core
Feb 22, 2026
Merged

feat: structlog core migration + fix flaky middleware tests (#215)#219
arthurfantaci merged 2 commits intomainfrom
rc/structlog-core

Conversation

@arthurfantaci
Copy link
Owner

Summary

  • structlog migration: Migrate 14 core application modules from stdlib logging to structlog for structured console/JSON logging (Phase 3a)
  • Fix fix: flaky test_middleware.py errors when run in full suite #215: Convert 2 async test fixtures to sync in test_middleware.py — eliminates event loop dependency that caused flaky errors in full suite
  • Test infrastructure: Add _reset_structlog and _clear_singleton_caches autouse fixtures; migrate test_config.py caplog tests to structlog.testing.capture_logs()

Modules migrated (14)

api.py, config.py, neo4j_client.py, routes/{search,chat,handlers,feedback}.py, middleware/{rate_limit,size_limit,timeout,tracing}.py, core/{retrieval,text2cypher,routing}.py

Out of scope (Phase 3b)

observability.py, guardrails/*, auth/*, evaluation/*, core/agentic/*, graph.py, prompts/catalog.py

Key design decisions

  • PositionalArgumentsFormatter enables zero-touch migration (no call-site changes for printf-style logs)
  • LOG_FORMAT=json env var switches to JSON output for Railway
  • Minimal logging.basicConfig(WARNING, force=True) bridge for unmigrated stdlib loggers

Test plan

  • 813 tests passing locally, 0 errors
  • ruff check . clean
  • ruff format --check . clean
  • ty check advisory (pre-existing, not new)
  • Flaky test_middleware.py tests now pass reliably in full suite
  • CI: Lint, Test, Type Check, Validate Prompts, Vercel Preview

Closes #215

🤖 Generated with Claude Code

arthurfantaci and others added 2 commits February 22, 2026 18:09
Migrate 14 application modules from stdlib logging to structlog for
structured console/JSON logging. Fix #215 by converting async test
fixtures to sync (direct dict population eliminates event loop dependency).

- Add structlog>=24.0.0 dependency
- Configure structlog in api.py lifespan with PositionalArgumentsFormatter
  for zero-touch printf-style log call compatibility
- Console/JSON output toggle via LOG_FORMAT env var
- Keep minimal stdlib basicConfig(WARNING) for unmigrated modules (Phase 3b)
- Add _reset_structlog + _clear_singleton_caches autouse test fixtures
- Migrate test_config.py caplog tests to structlog.testing.capture_logs()

Closes #215

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
feat: structlog core migration + fix flaky middleware tests (#215)
@vercel
Copy link

vercel bot commented Feb 22, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
frontend Ready Ready Preview, Comment Feb 22, 2026 11:10pm

Request Review

@codecov
Copy link

codecov bot commented Feb 22, 2026

Codecov Report

❌ Patch coverage is 82.75862% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
backend/src/requirements_graphrag_api/api.py 0.00% 3 Missing ⚠️
...kend/src/requirements_graphrag_api/neo4j_client.py 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@arthurfantaci arthurfantaci merged commit b8d16f6 into main Feb 22, 2026
6 of 7 checks passed
@arthurfantaci arthurfantaci deleted the rc/structlog-core branch February 22, 2026 23:12
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.

fix: flaky test_middleware.py errors when run in full suite

1 participant