From d327a1dada46dac410bdaf5354636a679adc41c4 Mon Sep 17 00:00:00 2001 From: "Peri, Suryanarayana" Date: Tue, 18 Jun 2024 14:07:09 +0530 Subject: [PATCH 1/3] httpx_issue_979 - Audit and test otel instrumentation for httpx Signed-off-by: Peri, Suryanarayana --- .../tests/test_httpx_integration.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/instrumentation/opentelemetry-instrumentation-httpx/tests/test_httpx_integration.py b/instrumentation/opentelemetry-instrumentation-httpx/tests/test_httpx_integration.py index 011b5e57d2..69c2b7f542 100644 --- a/instrumentation/opentelemetry-instrumentation-httpx/tests/test_httpx_integration.py +++ b/instrumentation/opentelemetry-instrumentation-httpx/tests/test_httpx_integration.py @@ -56,6 +56,7 @@ from opentelemetry.test.mock_textmap import MockTextMapPropagator from opentelemetry.test.test_base import TestBase from opentelemetry.trace import StatusCode +from opentelemetry import trace as trace_api if typing.TYPE_CHECKING: from opentelemetry.instrumentation.httpx import ( @@ -1214,3 +1215,14 @@ def test_basic_multiple(self): self.perform_request(self.URL, client=self.client) self.perform_request(self.URL, client=self.client2) self.assert_span(num_spans=2) + + def test_no_op_tracer_provider(self): + HTTPXClientInstrumentor().uninstrument() + HTTPXClientInstrumentor().instrument( + tracer_provider=trace_api.NoOpTracerProvider() + ) + async with httpx.AsyncClient() as client: + await client.get('http://test.com') + + spans = self.memory_exporter.get_finished_spans() + self.assertEqual(len(spans), 0) From 51b2910b2b0c9ce343d014afe94320acce2fdbb4 Mon Sep 17 00:00:00 2001 From: "Peri, Suryanarayana" Date: Tue, 23 Jul 2024 16:12:17 +0530 Subject: [PATCH 2/3] httpx_issue_979 - Linter issue corrected Signed-off-by: Peri, Suryanarayana --- .../tests/test_httpx_integration.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-httpx/tests/test_httpx_integration.py b/instrumentation/opentelemetry-instrumentation-httpx/tests/test_httpx_integration.py index 69c2b7f542..31f3926055 100644 --- a/instrumentation/opentelemetry-instrumentation-httpx/tests/test_httpx_integration.py +++ b/instrumentation/opentelemetry-instrumentation-httpx/tests/test_httpx_integration.py @@ -1216,13 +1216,12 @@ def test_basic_multiple(self): self.perform_request(self.URL, client=self.client2) self.assert_span(num_spans=2) - def test_no_op_tracer_provider(self): + async def test_no_op_tracer_provider(self): HTTPXClientInstrumentor().uninstrument() HTTPXClientInstrumentor().instrument( tracer_provider=trace_api.NoOpTracerProvider() ) - async with httpx.AsyncClient() as client: + async with httpx.AsyncClient() as client: await client.get('http://test.com') - spans = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans), 0) From 102a8cad1877cda60f6d101c6fac57269f472a0f Mon Sep 17 00:00:00 2001 From: "Peri, Suryanarayana" Date: Thu, 1 Aug 2024 18:58:00 +0530 Subject: [PATCH 3/3] httpx_issue_979 - Linter correction - use of double quote instead of single quote for the client url Signed-off-by: Peri, Suryanarayana --- .../tests/test_httpx_integration.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-httpx/tests/test_httpx_integration.py b/instrumentation/opentelemetry-instrumentation-httpx/tests/test_httpx_integration.py index 31f3926055..7f6045a818 100644 --- a/instrumentation/opentelemetry-instrumentation-httpx/tests/test_httpx_integration.py +++ b/instrumentation/opentelemetry-instrumentation-httpx/tests/test_httpx_integration.py @@ -56,7 +56,6 @@ from opentelemetry.test.mock_textmap import MockTextMapPropagator from opentelemetry.test.test_base import TestBase from opentelemetry.trace import StatusCode -from opentelemetry import trace as trace_api if typing.TYPE_CHECKING: from opentelemetry.instrumentation.httpx import ( @@ -1219,9 +1218,9 @@ def test_basic_multiple(self): async def test_no_op_tracer_provider(self): HTTPXClientInstrumentor().uninstrument() HTTPXClientInstrumentor().instrument( - tracer_provider=trace_api.NoOpTracerProvider() + tracer_provider=trace.NoOpTracerProvider() ) async with httpx.AsyncClient() as client: - await client.get('http://test.com') + await client.get("http://test.com") spans = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans), 0)