|
18 | 18 |
|
19 | 19 | from starlette import applications |
20 | 20 | from starlette.responses import PlainTextResponse |
21 | | -from starlette.routing import Mount, Route |
| 21 | +from starlette.routing import Host, Mount, Route |
22 | 22 | from starlette.testclient import TestClient |
23 | 23 | from starlette.websockets import WebSocket |
24 | 24 |
|
@@ -140,6 +140,24 @@ def test_sub_app_starlette_call(self): |
140 | 140 | span.attributes[HTTP_URL], |
141 | 141 | ) |
142 | 142 |
|
| 143 | + def test_host_starlette_call(self): |
| 144 | + client = TestClient(self._app, base_url="http://testserver2") |
| 145 | + client.get("/home") |
| 146 | + spans = self.memory_exporter.get_finished_spans() |
| 147 | + |
| 148 | + spans_with_http_attributes = [ |
| 149 | + span |
| 150 | + for span in spans |
| 151 | + if (HTTP_URL in span.attributes or HTTP_TARGET in span.attributes) |
| 152 | + ] |
| 153 | + |
| 154 | + for span in spans_with_http_attributes: |
| 155 | + self.assertEqual("/home", span.attributes[HTTP_TARGET]) |
| 156 | + self.assertEqual( |
| 157 | + "http://testserver2/home", |
| 158 | + span.attributes[HTTP_URL], |
| 159 | + ) |
| 160 | + |
143 | 161 | def test_starlette_route_attribute_added(self): |
144 | 162 | """Ensure that starlette routes are used as the span name.""" |
145 | 163 | self._client.get("/user/123") |
@@ -294,6 +312,7 @@ def sub_home(_): |
294 | 312 | Route("/user/{username}", home), |
295 | 313 | Route("/healthzz", health), |
296 | 314 | Mount("/sub", app=sub_app), |
| 315 | + Host("testserver2", sub_app), |
297 | 316 | ], |
298 | 317 | ) |
299 | 318 |
|
|
0 commit comments