Skip to content

Commit e5d9ac5

Browse files
authored
fix fastapi instrumentation tests for version 0.91 (#1710)
1 parent 135280e commit e5d9ac5

File tree

5 files changed

+11
-13
lines changed

5 files changed

+11
-13
lines changed

instrumentation/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
| [opentelemetry-instrumentation-django](./opentelemetry-instrumentation-django) | django >= 1.10 | Yes
1717
| [opentelemetry-instrumentation-elasticsearch](./opentelemetry-instrumentation-elasticsearch) | elasticsearch >= 2.0 | No
1818
| [opentelemetry-instrumentation-falcon](./opentelemetry-instrumentation-falcon) | falcon >= 1.4.1, < 4.0.0 | Yes
19-
| [opentelemetry-instrumentation-fastapi](./opentelemetry-instrumentation-fastapi) | fastapi <= 0.90.1 | Yes
19+
| [opentelemetry-instrumentation-fastapi](./opentelemetry-instrumentation-fastapi) | fastapi ~= 0.58 | Yes
2020
| [opentelemetry-instrumentation-flask](./opentelemetry-instrumentation-flask) | flask >= 1.0, < 3.0 | Yes
2121
| [opentelemetry-instrumentation-grpc](./opentelemetry-instrumentation-grpc) | grpcio ~= 1.27 | No
2222
| [opentelemetry-instrumentation-httpx](./opentelemetry-instrumentation-httpx) | httpx >= 0.18.0 | No

instrumentation/opentelemetry-instrumentation-fastapi/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ dependencies = [
3434

3535
[project.optional-dependencies]
3636
instruments = [
37-
"fastapi <= 0.90.1",
37+
"fastapi ~= 0.58",
3838
]
3939
test = [
4040
"opentelemetry-instrumentation-fastapi[instruments]",

instrumentation/opentelemetry-instrumentation-fastapi/src/opentelemetry/instrumentation/fastapi/package.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
# limitations under the License.
1414

1515

16-
_instruments = ("fastapi <= 0.90.1",)
16+
_instruments = ("fastapi ~= 0.58",)
1717

1818
_supports_metrics = True

instrumentation/opentelemetry-instrumentation-fastapi/tests/test_fastapi_instrumentation.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from unittest.mock import patch
1818

1919
import fastapi
20+
from fastapi.middleware.httpsredirect import HTTPSRedirectMiddleware
2021
from fastapi.responses import JSONResponse
2122
from fastapi.testclient import TestClient
2223

@@ -87,6 +88,7 @@ def setUp(self):
8788
self.exclude_patch.start()
8889
self._instrumentor = otel_fastapi.FastAPIInstrumentor()
8990
self._app = self._create_app()
91+
self._app.add_middleware(HTTPSRedirectMiddleware)
9092
self._client = TestClient(self._app)
9193

9294
def tearDown(self):
@@ -110,12 +112,8 @@ def test_uninstrument_app(self):
110112
self._client.get("/foobar")
111113
spans = self.memory_exporter.get_finished_spans()
112114
self.assertEqual(len(spans), 3)
113-
# pylint: disable=import-outside-toplevel
114-
from fastapi.middleware.httpsredirect import HTTPSRedirectMiddleware
115115

116-
self._app.add_middleware(HTTPSRedirectMiddleware)
117116
self._instrumentor.uninstrument_app(self._app)
118-
print(self._app.user_middleware[0].cls)
119117
self.assertFalse(
120118
isinstance(
121119
self._app.user_middleware[0].cls, OpenTelemetryMiddleware
@@ -212,18 +210,18 @@ def test_basic_metric_success(self):
212210
duration = max(round((default_timer() - start) * 1000), 0)
213211
expected_duration_attributes = {
214212
"http.method": "GET",
215-
"http.host": "testserver",
216-
"http.scheme": "http",
213+
"http.host": "testserver:443",
214+
"http.scheme": "https",
217215
"http.flavor": "1.1",
218216
"http.server_name": "testserver",
219-
"net.host.port": 80,
217+
"net.host.port": 443,
220218
"http.status_code": 200,
221219
"http.target": "/foobar",
222220
}
223221
expected_requests_count_attributes = {
224222
"http.method": "GET",
225-
"http.host": "testserver",
226-
"http.scheme": "http",
223+
"http.host": "testserver:443",
224+
"http.scheme": "https",
227225
"http.flavor": "1.1",
228226
"http.server_name": "testserver",
229227
}

opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"instrumentation": "opentelemetry-instrumentation-falcon==0.38b0.dev",
7070
},
7171
"fastapi": {
72-
"library": "fastapi <= 0.90.1",
72+
"library": "fastapi ~= 0.58",
7373
"instrumentation": "opentelemetry-instrumentation-fastapi==0.38b0.dev",
7474
},
7575
"flask": {

0 commit comments

Comments
 (0)