Skip to content

Commit

Permalink
fix fastapi instrumentation tests for version 0.91 (#1710)
Browse files Browse the repository at this point in the history
  • Loading branch information
Akochavi authored Mar 7, 2023
1 parent 135280e commit e5d9ac5
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion instrumentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dependencies = [

[project.optional-dependencies]
instruments = [
"fastapi <= 0.90.1",
"fastapi ~= 0.58",
]
test = [
"opentelemetry-instrumentation-fastapi[instruments]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
# limitations under the License.


_instruments = ("fastapi <= 0.90.1",)
_instruments = ("fastapi ~= 0.58",)

_supports_metrics = True
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from unittest.mock import patch

import fastapi
from fastapi.middleware.httpsredirect import HTTPSRedirectMiddleware
from fastapi.responses import JSONResponse
from fastapi.testclient import TestClient

Expand Down Expand Up @@ -87,6 +88,7 @@ def setUp(self):
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):
Expand All @@ -110,12 +112,8 @@ def test_uninstrument_app(self):
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
Expand Down Expand Up @@ -212,18 +210,18 @@ def test_basic_metric_success(self):
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",
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"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": {
Expand Down

0 comments on commit e5d9ac5

Please sign in to comment.