Skip to content

starlette/fastapi: fix error on host-based routing #3507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

frankie567
Copy link

@frankie567 frankie567 commented May 16, 2025

Description

Handle case where the Starlette/FastAPI app uses a hosted-based routing. In this case, there is no path attribute to read from the routing class. Therefore, fallback to the path present in scope. The fix is inspired from what Sentry did to fix a similar bug: https://github.com/getsentry/sentry-python/blob/312f85739af27bb9665f61fedd9a589178a67000/sentry_sdk/integrations/starlette.py#L696-L700

Fixes #3506

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Added basic unit tests to assess the instrument not longer crashes when a host-based route is called.

Note

I've not added assertions regarding the collected spans/traces, wasn't really sure where to start. But happy to improve that with some guidance :)

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • [ ] Documentation has been updated (not relevant)

Copy link

linux-foundation-easycla bot commented May 16, 2025

CLA Signed


The committers listed above are authorized under a signed CLA.

@frankie567 frankie567 requested a review from a team as a code owner May 16, 2025 11:13
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.

Starlette/FastAPI: host-based routing raises AttributeError
1 participant