Skip to content

Commit aa74727

Browse files
committed
opentelemetry-instrumentation-aiohttp-client: add tests verifying isolation of metric attributes
1 parent 18755c2 commit aa74727

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,52 @@ async def request_handler(request):
828828
self._assert_spans([], 0)
829829
self._assert_metrics(0)
830830

831+
def test_metric_attributes_isolation(self):
832+
async def success_handler(request):
833+
assert "traceparent" in request.headers
834+
return aiohttp.web.Response(status=HTTPStatus.OK)
835+
836+
async def timeout_handler(request):
837+
await asyncio.sleep(60)
838+
assert "traceparent" in request.headers
839+
return aiohttp.web.Response(status=HTTPStatus.OK)
840+
841+
success_host, success_port = self._http_request(
842+
trace_config=aiohttp_client.create_trace_config(),
843+
url="/success",
844+
request_handler=success_handler,
845+
)
846+
847+
timeout_host, timeout_port = self._http_request(
848+
trace_config=aiohttp_client.create_trace_config(),
849+
url="/timeout",
850+
request_handler=timeout_handler,
851+
timeout=aiohttp.ClientTimeout(sock_read=0.01),
852+
)
853+
854+
metrics = self._assert_metrics(1)
855+
duration_dp_attributes = [
856+
dict(dp.attributes) for dp in metrics[0].data.data_points
857+
]
858+
self.assertEqual(
859+
[
860+
{
861+
HTTP_METHOD: "GET",
862+
HTTP_HOST: success_host,
863+
HTTP_STATUS_CODE: int(HTTPStatus.OK),
864+
NET_PEER_NAME: success_host,
865+
NET_PEER_PORT: success_port,
866+
},
867+
{
868+
HTTP_METHOD: "GET",
869+
HTTP_HOST: timeout_host,
870+
NET_PEER_NAME: timeout_host,
871+
NET_PEER_PORT: timeout_port,
872+
},
873+
],
874+
duration_dp_attributes,
875+
)
876+
831877

832878
class TestAioHttpClientInstrumentor(TestBase):
833879
URL = "/test-path"

0 commit comments

Comments
 (0)