-
Notifications
You must be signed in to change notification settings - Fork 766
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
frankie567
wants to merge
2
commits into
open-telemetry:main
Choose a base branch
from
frankie567:fix/3506
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+53
−3
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
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)