Skip to content

fix(fastapi): use effective_route_context path for prefixed routers#6572

Merged
ericapisani merged 1 commit into
masterfrom
py-2530-fastapi-strawberry-tox-fix
Jun 15, 2026
Merged

fix(fastapi): use effective_route_context path for prefixed routers#6572
ericapisani merged 1 commit into
masterfrom
py-2530-fastapi-strawberry-tox-fix

Conversation

@ericapisani

Copy link
Copy Markdown
Member

FastAPI >= 0.137 stores the prefix-resolved path in scope["fastapi"]["effective_route_context"] instead of scope["route"].path, so transactions/segments were showing the unprefixed /users/{user_id} instead of the full /api/users/{user_id} for routers mounted with a prefix.

This fix prefers effective_route_context.path when available, falling back to route.path for older FastAPI versions.

Fixes PY-2530
Fixes #6571

The fix handles the case where FastAPI >= 0.137 stores the
prefix-resolved path in scope["fastapi"]["effective_route_context"] instead of scope["route"].path, so transactions/segments now show the full /api/users/{user_id} path instead of the unprefixed
/users/{user_id}.

Additionally, in the case of the `strawberry` framework without a specified path, this would fallback to using `generic FastAPI request` instead of using the prefix provided in the router (like `graphql` in the test cases.

Fixes PY-2530
Fixes #6571
@linear-code

linear-code Bot commented Jun 15, 2026

Copy link
Copy Markdown

PY-2530

@ericapisani

Copy link
Copy Markdown
Member Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 784e401. Configure here.

@ericapisani ericapisani marked this pull request as ready for review June 15, 2026 14:59
@ericapisani ericapisani requested a review from a team as a code owner June 15, 2026 14:59
@github-actions

Copy link
Copy Markdown
Contributor

Codecov Results 📊

90590 passed | ⏭️ 6031 skipped | Total: 96621 | Pass Rate: 93.76% | Execution Time: 320m 11s

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +96530
Passed Tests 📈 +90505
Failed Tests 📉 -4
Skipped Tests 📈 +6029

➖ Removed Tests (4)

View removed tests
  • test_transaction_no_operation_name[True-True-async_app_client_factory-True-framework_integrations0]
    • File: tests.integrations.strawberry.test_strawberry
  • test_transaction_no_operation_name[True-False-async_app_client_factory-True-framework_integrations0]
    • File: tests.integrations.strawberry.test_strawberry
  • test_transaction_no_operation_name[False-True-async_app_client_factory-True-framework_integrations0]
    • File: tests.integrations.strawberry.test_strawberry
  • test_transaction_no_operation_name[False-False-async_app_client_factory-True-framework_integrations0]
    • File: tests.integrations.strawberry.test_strawberry

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 2421 uncovered lines.
✅ Project coverage is 89.75%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
sentry_sdk/integrations/fastapi.py 100.00% ⚠️ 1 partials
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    29.67%    89.75%   +60.08%
==========================================
  Files          192       192         —
  Lines        23615     23619        +4
  Branches      8130      8132        +2
==========================================
+ Hits          7007     21198    +14191
- Misses       16608      2421    -14187
- Partials       654      1340      +686

Generated by Codecov Action

@ericapisani ericapisani merged commit 72d972c into master Jun 15, 2026
144 checks passed
@ericapisani ericapisani deleted the py-2530-fastapi-strawberry-tox-fix branch June 15, 2026 15:14
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.

Update _set_transaction_name_and_source in fastapi to handle changes in fastapi v0.137

2 participants