|
20 | 20 | import weakref as _weakref
|
21 | 21 | from contextlib import ExitStack
|
22 | 22 | from timeit import default_timer
|
23 |
| -from typing import Any, cast |
| 23 | +from typing import Any, Final, cast |
24 | 24 | from unittest.mock import Mock, call, patch
|
25 | 25 |
|
26 | 26 | import fastapi
|
@@ -341,15 +341,29 @@ def test_sub_app_fastapi_call(self):
|
341 | 341 | span.attributes[HTTP_URL],
|
342 | 342 | )
|
343 | 343 |
|
344 |
| - |
345 | 344 | def test_custom_api_router(self):
|
346 | 345 | """
|
347 | 346 | This test is to ensure that custom API routers the OpenTelemetryMiddleware does not cause issues with
|
348 | 347 | custom API routers that depend on non-standard fields on the ASGI scope.
|
349 | 348 | """
|
350 |
| - resp = self._client.get("/custom-router/success") |
351 |
| - self.assertEqual(resp.status_code, 200) |
352 |
| - |
| 349 | + resp: Final = self._client.get("/custom-router/success") |
| 350 | + spans: Final = self.memory_exporter.get_finished_spans() |
| 351 | + expected_span_attributes: Final = { |
| 352 | + HTTP_TARGET: "/custom-router/success", |
| 353 | + HTTP_URL: "https://testserver/", |
| 354 | + } |
| 355 | + self.assertEqual(200, resp.status_code) |
| 356 | + self.assertTrue( |
| 357 | + all( |
| 358 | + all( |
| 359 | + ( |
| 360 | + span.attributes[attribute] == expected |
| 361 | + for attribute, expected in expected_span_attributes.items() |
| 362 | + ) |
| 363 | + ) |
| 364 | + for span in spans |
| 365 | + ) |
| 366 | + ) |
353 | 367 |
|
354 | 368 | def test_host_fastapi_call(self):
|
355 | 369 | client = TestClient(self._app, base_url="https://testserver2:443")
|
|
0 commit comments