|
40 | 40 | from opentelemetry.instrumentation.aiohttp_client import ( |
41 | 41 | AioHttpClientInstrumentor, |
42 | 42 | ) |
43 | | -from opentelemetry.instrumentation.utils import suppress_instrumentation |
| 43 | +from opentelemetry.instrumentation.utils import ( |
| 44 | + suppress_http_instrumentation, |
| 45 | + suppress_instrumentation, |
| 46 | +) |
44 | 47 | from opentelemetry.semconv._incubating.attributes.http_attributes import ( |
45 | 48 | HTTP_HOST, |
46 | 49 | HTTP_METHOD, |
@@ -1068,33 +1071,60 @@ async def uninstrument_request(server: aiohttp.test_utils.TestServer): |
1068 | 1071 | self._assert_spans(1) |
1069 | 1072 |
|
1070 | 1073 | def test_suppress_instrumentation(self): |
1071 | | - with suppress_instrumentation(): |
1072 | | - run_with_test_server( |
1073 | | - self.get_default_request(), self.URL, self.default_handler |
1074 | | - ) |
1075 | | - self._assert_spans(0) |
| 1074 | + for suppress_ctx in ( |
| 1075 | + suppress_instrumentation, |
| 1076 | + suppress_http_instrumentation, |
| 1077 | + ): |
| 1078 | + with self.subTest(suppress_ctx=suppress_ctx.__name__): |
| 1079 | + with suppress_ctx(): |
| 1080 | + run_with_test_server( |
| 1081 | + self.get_default_request(), |
| 1082 | + self.URL, |
| 1083 | + self.default_handler, |
| 1084 | + ) |
| 1085 | + self._assert_spans(0) |
| 1086 | + self._assert_metrics(0) |
1076 | 1087 |
|
1077 | 1088 | @staticmethod |
1078 | | - async def suppressed_request(server: aiohttp.test_utils.TestServer): |
1079 | | - async with aiohttp.test_utils.TestClient(server) as client: |
1080 | | - with suppress_instrumentation(): |
1081 | | - await client.get(TestAioHttpClientInstrumentor.URL) |
| 1089 | + def make_suppressed_request(suppress_ctx): |
| 1090 | + async def suppressed_request(server: aiohttp.test_utils.TestServer): |
| 1091 | + async with aiohttp.test_utils.TestClient(server) as client: |
| 1092 | + with suppress_ctx(): |
| 1093 | + await client.get(TestAioHttpClientInstrumentor.URL) |
| 1094 | + |
| 1095 | + return suppressed_request |
1082 | 1096 |
|
1083 | 1097 | def test_suppress_instrumentation_after_creation(self): |
1084 | | - run_with_test_server( |
1085 | | - self.suppressed_request, self.URL, self.default_handler |
1086 | | - ) |
1087 | | - self._assert_spans(0) |
| 1098 | + for suppress_ctx in ( |
| 1099 | + suppress_instrumentation, |
| 1100 | + suppress_http_instrumentation, |
| 1101 | + ): |
| 1102 | + with self.subTest(suppress_ctx=suppress_ctx.__name__): |
| 1103 | + run_with_test_server( |
| 1104 | + self.make_suppressed_request(suppress_ctx), |
| 1105 | + self.URL, |
| 1106 | + self.default_handler, |
| 1107 | + ) |
| 1108 | + self._assert_spans(0) |
| 1109 | + self._assert_metrics(0) |
1088 | 1110 |
|
1089 | 1111 | def test_suppress_instrumentation_with_server_exception(self): |
1090 | 1112 | # pylint:disable=unused-argument |
1091 | 1113 | async def raising_handler(request): |
1092 | 1114 | raise aiohttp.web.HTTPFound(location=self.URL) |
1093 | 1115 |
|
1094 | | - run_with_test_server( |
1095 | | - self.suppressed_request, self.URL, raising_handler |
1096 | | - ) |
1097 | | - self._assert_spans(0) |
| 1116 | + for suppress_ctx in ( |
| 1117 | + suppress_instrumentation, |
| 1118 | + suppress_http_instrumentation, |
| 1119 | + ): |
| 1120 | + with self.subTest(suppress_ctx=suppress_ctx.__name__): |
| 1121 | + run_with_test_server( |
| 1122 | + self.make_suppressed_request(suppress_ctx), |
| 1123 | + self.URL, |
| 1124 | + raising_handler, |
| 1125 | + ) |
| 1126 | + self._assert_spans(0) |
| 1127 | + self._assert_metrics(0) |
1098 | 1128 |
|
1099 | 1129 | def test_url_filter(self): |
1100 | 1130 | def strip_query_params(url: yarl.URL) -> str: |
|
0 commit comments