- Notifications
You must be signed in to change notification settings - Fork 789
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
xrmx reviewed May 21, 2025
instrumentation/opentelemetry-instrumentation-fastapi/tests/test_fastapi_instrumentation.py Show resolved Hide resolved
Hey @frankie567, do you plan to update the PR after review? |
@xrmx Yes, sorry, got a bit busy lately; but I'll try to finish this by next week. |
xrmx reviewed Jun 30, 2025
@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. |
emdneto reviewed Aug 27, 2025
.../opentelemetry-instrumentation-fastapi/src/opentelemetry/instrumentation/fastapi/__init__.py Show resolved Hide resolved
instrumentation/opentelemetry-instrumentation-starlette/tests/test_starlette_instrumentation.py Outdated Show resolved Hide resolved
xrmx reviewed Aug 28, 2025
instrumentation/opentelemetry-instrumentation-starlette/tests/test_starlette_instrumentation.py Outdated Show resolved Hide resolved
…test_starlette_instrumentation.py
emdneto approved these changes Aug 29, 2025
xrmx approved these changes Aug 29, 2025
xrmx reviewed Aug 29, 2025
zhirafovod pushed a commit to zhirafovod/opentelemetry-python-contrib that referenced this pull request Sep 15, 2025
* starlette/fastapi: fix error on host-based routing Fix open-telemetry#3506 * Update CHANGELOG.md * Update instrumentation/opentelemetry-instrumentation-starlette/tests/test_starlette_instrumentation.py * Update CHANGELOG.md --------- Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com> Co-authored-by: Emídio Neto <9735060+emdneto@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
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 inscope
. 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-L700Fixes #3506
Type of change
Please delete options that are not relevant.
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?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.
[ ] Documentation has been updated(not relevant)