From ccde7f1d4955ae3e0861392d65ce01affd9cf43f Mon Sep 17 00:00:00 2001 From: dgoscn Date: Mon, 27 Jan 2025 20:14:23 -0300 Subject: [PATCH] NoOpTracerProvider test case for httpx instrumentation --- .../tests/test_httpx_integration.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/instrumentation/opentelemetry-instrumentation-httpx/tests/test_httpx_integration.py b/instrumentation/opentelemetry-instrumentation-httpx/tests/test_httpx_integration.py index 148fe27893..93942a0a02 100644 --- a/instrumentation/opentelemetry-instrumentation-httpx/tests/test_httpx_integration.py +++ b/instrumentation/opentelemetry-instrumentation-httpx/tests/test_httpx_integration.py @@ -1292,6 +1292,26 @@ def test_basic_multiple(self): self.perform_request(self.URL, client=self.client2) self.assert_span(num_spans=2) + async def test_no_op_tracer_provider(self): + HTTPXClientInstrumentor().uninstrument() + HTTPXClientInstrumentor().instrument( + tracer_provider=trace.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) + + def test_no_op_tracer_provider_sync(self): + HTTPXClientInstrumentor().uninstrument() + HTTPXClientInstrumentor().instrument( + tracer_provider=trace.NoOpTracerProvider() + ) + with httpx.Client() as client: + client.get("http://test.com") + spans = self.memory_exporter.get_finished_spans() + self.assertEqual(len(spans), 0) + def test_async_response_hook_does_nothing_if_not_coroutine(self): HTTPXClientInstrumentor().instrument( tracer_provider=self.tracer_provider,