-
Notifications
You must be signed in to change notification settings - Fork 521
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
fix(opentelemetry-instrumentation-asgi): Correct http.url attribute generation #2477
base: main
Are you sure you want to change the base?
Conversation
4271c3e
to
ffe44f8
Compare
pylint forced me to split the fastapi instrumentation tests, therefore I made a split into two files |
pipeline is already running 100% green within my fork, so its safe to approve workflows |
...tation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py
Outdated
Show resolved
Hide resolved
...tation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py
Outdated
Show resolved
Hide resolved
@samuelcolvin any chance you could take a look at this? |
I'll check this today. |
@Kludex it would be great if you can take a look at this, thanks |
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 don't think that amount of explanation is needed, besides a link to the docs, or issue on asgiref, but besides that... All good. 👍
…e generation even with sub apps (fixes open-telemetry#2476) - modify the instrumentation logic - add unittests on starlette instrumentation - add unittests on fastapi instrumentation
ffe44f8
to
1970a3f
Compare
Changed the comments to prevent non required verbosity :) |
Refactored as suggested and rebased to main |
@@ -485,6 +580,58 @@ def tearDown(self): | |||
self._instrumentor.uninstrument() | |||
super().tearDown() | |||
|
|||
def test_sub_app_fastapi_call(self): |
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.
If this is the very same code of the TestAutoInstrumentation method we should probably rethink the inheritance of these tests cases
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.
something like this unless we are supposed to rerun the same tests many times:
diff --git a/instrumentation/opentelemetry-instrumentation-fastapi/tests/test_fastapi_instrumentation.py b/instrumentation/opentelemetry-instrumentation-fastapi/tests/test_fastapi_instrumentation.py
index 4269dfa2..9c396c66 100644
--- a/instrumentation/opentelemetry-instrumentation-fastapi/tests/test_fastapi_instrumentation.py
+++ b/instrumentation/opentelemetry-instrumentation-fastapi/tests/test_fastapi_instrumentation.py
@@ -61,7 +61,7 @@ _recommended_attrs = {
}
-class TestFastAPIManualInstrumentation(TestBase):
+class TestBaseFastAPI:
def _create_app(self):
app = self._create_fastapi_app()
self._instrumentor.instrument_app(
@@ -109,6 +109,30 @@ class TestFastAPIManualInstrumentation(TestBase):
self._instrumentor.uninstrument()
self._instrumentor.uninstrument_app(self._app)
+ @staticmethod
+ def _create_fastapi_app():
+ app = fastapi.FastAPI()
+
+ @app.get("/foobar")
+ async def _():
+ return {"message": "hello world"}
+
+ @app.get("/user/{username}")
+ async def _(username: str):
+ return {"message": username}
+
+ @app.get("/exclude/{param}")
+ async def _(param: str):
+ return {"message": param}
+
+ @app.get("/healthzz")
+ async def _():
+ return {"message": "ok"}
+
+ return app
+
+
+class TestFastAPIManualInstrumentation(TestBaseFastAPI, TestBase):
def test_instrument_app_with_instrument(self):
if not isinstance(self, TestAutoInstrumentation):
self._instrumentor.instrument()
@@ -310,30 +334,8 @@ class TestFastAPIManualInstrumentation(TestBase):
if isinstance(point, NumberDataPoint):
self.assertEqual(point.value, 0)
- @staticmethod
- def _create_fastapi_app():
- app = fastapi.FastAPI()
-
- @app.get("/foobar")
- async def _():
- return {"message": "hello world"}
-
- @app.get("/user/{username}")
- async def _(username: str):
- return {"message": username}
-
- @app.get("/exclude/{param}")
- async def _(param: str):
- return {"message": param}
-
- @app.get("/healthzz")
- async def _():
- return {"message": "ok"}
-
- return app
-
-class TestFastAPIManualInstrumentationHooks(TestFastAPIManualInstrumentation):
+class TestFastAPIManualInstrumentationHooks(TestBaseFastAPI, TestBase):
_server_request_hook = None
_client_request_hook = None
_client_response_hook = None
@@ -383,7 +385,7 @@ class TestFastAPIManualInstrumentationHooks(TestFastAPIManualInstrumentation):
)
-class TestAutoInstrumentation(TestFastAPIManualInstrumentation):
+class TestAutoInstrumentation(TestBaseFastAPI, TestBase):
"""Test the auto-instrumented variant
Extending the manual instrumentation as most test cases apply
@@ -445,7 +447,7 @@ class TestAutoInstrumentation(TestFastAPIManualInstrumentation):
super().tearDown()
-class TestAutoInstrumentationHooks(TestFastAPIManualInstrumentationHooks):
+class TestAutoInstrumentationHooks(TestBaseFastAPI, TestBase):
"""
Test the auto-instrumented variant for request and response hooks
Description
Correct http.url and http.target attribute generation even with sub apps (fixes #2476)
Fixes #2476
Type of change
Please delete options that are not relevant.
From my point of view existing logic won't break. Simply attributes generated will change according to their correct intended values.
How Has This Been Tested?
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.