-
Notifications
You must be signed in to change notification settings - Fork 743
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
base: main
Are you sure you want to change the base?
Conversation
def test_host_fastapi_call(self): | ||
client = TestClient(self._app, base_url="https://testserver2") | ||
client.get("/") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should add some assertions here, especially for HTTP_ROUTE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! The thing is I don't really understand how spans are working in the test above 😊 Can you give me a rough idea of how to start?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @frankie567 , some of the instrumentor tests are using a TestBase that can set up an in-memory span exporter. The test above uses this to get spans from an instrumented client then check its attributes.
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. |
@@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||
- `opentelemetry-instrumentation-botocore` Use `cloud.region` instead of `aws.region` span attribute as per semantic conventions. | |||
([#3474](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3474)) | |||
|
|||
### Fixed | |||
|
|||
- `opentelemetry-instrumentation-starlette` Fixes a crash when host-based routing is used ([#3507](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3507/)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These needs to be moved to unreleased
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)