Skip to content

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
@xrmx xrmx moved this to Reviewed PR that needs fixing in @xrmx's Python PR digest May 21, 2025
@xrmx
Copy link
Contributor

xrmx commented Jun 30, 2025

Hey @frankie567, do you plan to update the PR after review?

@frankie567
Copy link
Author

@xrmx Yes, sorry, got a bit busy lately; but I'll try to finish this by next week.

@frankie567
Copy link
Author

@xrmx Sorry this has took forever, but I finally managed to complete this PR. I added assertions to the tests, as you requested; and fixed the CHANGELOG.

@xrmx xrmx moved this from Reviewed PR that needs fixing to Ready for review in @xrmx's Python PR digest Aug 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Ready for review
Development

Successfully merging this pull request may close these issues.

Starlette/FastAPI: host-based routing raises AttributeError
4 participants