Skip to content

Propagate FastAPI exceptions to framework handlers - #146

Merged
vrslev merged 3 commits into
mainfrom
bugfix/VA-7612-fastapi-exception-propagation
Aug 26, 2026
Merged

Propagate FastAPI exceptions to framework handlers#146
vrslev merged 3 commits into
mainfrom
bugfix/VA-7612-fastapi-exception-propagation

Conversation

@vrslev

@vrslevvrslev commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Stop converting escaping FastAPI exceptions into blank 500 responses.
  • Re-raise them so Starlette/FastAPI exception handlers and automatic Sentry integration receive the original exception.
  • Keep normal and handled-response access logging unchanged; escaping exceptions are left to the outer framework error boundary to avoid duplicate Sentry events and inaccurate pre-handler status logging.
  • Give every FastStream message its own Sentry isolation scope across the complete subscriber lifecycle, including the built-in critical error log.
  • Cover both brokers configured during bootstrap and brokers attached from FastStream startup hooks.
  • Do not add HTTPX or HTTPX2 instrumentor configuration; Microbootstrap continues to auto-load both installed OpenTelemetry entry points.

Verification

  • Full test suite: 203 passed, 99% coverage.
  • FastStream bootstrapper suite: 9 passed; the changed module reached 100% coverage.
  • The concurrent-message regression test verifies each automatic FastStream error log sees its own conversation tag and the parent scope remains clean.
  • The FastAPI Sentry regression test asserts exactly one exception event with its traceback.
  • Ruff format/check passed.
  • MyPy passed.
  • git diff --check passed.
  • GitHub Python 3.10-3.14 matrix: 17 checks passed, 0 failed.

Compatibility

TestClient with raise_server_exceptions=True now propagates unhandled exceptions as Starlette normally does. Production Starlette still renders its configured 500 response, and custom Exception/500 handlers are no longer bypassed.

FastStream message-local Sentry data no longer leaks into concurrent or subsequent messages. Global Sentry scope data remains inherited. The isolation boundary applies to both existing and startup-configured brokers.

Dependency

Front VA-7612 automatic Sentry capture depends on the patch release from this PR; service code does not call capture_exception.

Jira: https://jira.raiffeisen.ru/browse/VA-7612

@vrslevvrslev self-assigned this Aug 26, 2026
@codecov

codecovBot commented Aug 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

FlagCoverage Δ
unittests98.96% <100.00%> (+0.17%)⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing linesCoverage Δ
microbootstrap/bootstrappers/faststream.py100.00% <100.00%> (ø)
microbootstrap/middlewares/fastapi.py100.00% <100.00%> (+9.09%)⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vrslevvrslev changed the title Propagate FastAPI exceptions to framework handlersVA-7612: Propagate FastAPI exceptions to framework handlersAug 26, 2026
@vrslev
vrslev marked this pull request as ready for review August 26, 2026 10:37
@vrslev
vrslev merged commit 5ec6ce1 into mainAug 26, 2026
18 checks passed
@vrslev
vrslev deleted the bugfix/VA-7612-fastapi-exception-propagation branch August 26, 2026 10:38
@vrslevvrslev changed the title VA-7612: Propagate FastAPI exceptions to framework handlersPropagate FastAPI exceptions to framework handlersAug 26, 2026
Sign up for freeto 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.

1 participant

@vrslev