fix fastapi instrumentation tests for version 0.91 (#1710)

This commit is contained in:
Akochavi
2023-03-07 16:59:24 +02:00
committed by GitHub
parent 135280e539
commit e5d9ac5755
5 changed files with 11 additions and 13 deletions

View File

@ -16,7 +16,7 @@
| [opentelemetry-instrumentation-django](./opentelemetry-instrumentation-django) | django >= 1.10 | Yes
| [opentelemetry-instrumentation-elasticsearch](./opentelemetry-instrumentation-elasticsearch) | elasticsearch >= 2.0 | No
| [opentelemetry-instrumentation-falcon](./opentelemetry-instrumentation-falcon) | falcon >= 1.4.1, < 4.0.0 | Yes
| [opentelemetry-instrumentation-fastapi](./opentelemetry-instrumentation-fastapi) | fastapi <= 0.90.1 | Yes
| [opentelemetry-instrumentation-fastapi](./opentelemetry-instrumentation-fastapi) | fastapi ~= 0.58 | Yes
| [opentelemetry-instrumentation-flask](./opentelemetry-instrumentation-flask) | flask >= 1.0, < 3.0 | Yes
| [opentelemetry-instrumentation-grpc](./opentelemetry-instrumentation-grpc) | grpcio ~= 1.27 | No
| [opentelemetry-instrumentation-httpx](./opentelemetry-instrumentation-httpx) | httpx >= 0.18.0 | No

View File

@ -34,7 +34,7 @@ dependencies = [
[project.optional-dependencies]
instruments = [
"fastapi <= 0.90.1",
"fastapi ~= 0.58",
]
test = [
"opentelemetry-instrumentation-fastapi[instruments]",

View File

@ -13,6 +13,6 @@
# limitations under the License.
_instruments = ("fastapi <= 0.90.1",)
_instruments = ("fastapi ~= 0.58",)
_supports_metrics = True

View File

@ -17,6 +17,7 @@ from timeit import default_timer
from unittest.mock import patch
import fastapi
from fastapi.middleware.httpsredirect import HTTPSRedirectMiddleware
from fastapi.responses import JSONResponse
from fastapi.testclient import TestClient
@ -87,6 +88,7 @@ class TestFastAPIManualInstrumentation(TestBase):
self.exclude_patch.start()
self._instrumentor = otel_fastapi.FastAPIInstrumentor()
self._app = self._create_app()
self._app.add_middleware(HTTPSRedirectMiddleware)
self._client = TestClient(self._app)
def tearDown(self):
@ -110,12 +112,8 @@ class TestFastAPIManualInstrumentation(TestBase):
self._client.get("/foobar")
spans = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans), 3)
# pylint: disable=import-outside-toplevel
from fastapi.middleware.httpsredirect import HTTPSRedirectMiddleware
self._app.add_middleware(HTTPSRedirectMiddleware)
self._instrumentor.uninstrument_app(self._app)
print(self._app.user_middleware[0].cls)
self.assertFalse(
isinstance(
self._app.user_middleware[0].cls, OpenTelemetryMiddleware
@ -212,18 +210,18 @@ class TestFastAPIManualInstrumentation(TestBase):
duration = max(round((default_timer() - start) * 1000), 0)
expected_duration_attributes = {
"http.method": "GET",
"http.host": "testserver",
"http.scheme": "http",
"http.host": "testserver:443",
"http.scheme": "https",
"http.flavor": "1.1",
"http.server_name": "testserver",
"net.host.port": 80,
"net.host.port": 443,
"http.status_code": 200,
"http.target": "/foobar",
}
expected_requests_count_attributes = {
"http.method": "GET",
"http.host": "testserver",
"http.scheme": "http",
"http.host": "testserver:443",
"http.scheme": "https",
"http.flavor": "1.1",
"http.server_name": "testserver",
}

View File

@ -69,7 +69,7 @@ libraries = {
"instrumentation": "opentelemetry-instrumentation-falcon==0.38b0.dev",
},
"fastapi": {
"library": "fastapi <= 0.90.1",
"library": "fastapi ~= 0.58",
"instrumentation": "opentelemetry-instrumentation-fastapi==0.38b0.dev",
},
"flask": {