diff --git a/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware_asgi.py b/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware_asgi.py index 784f8e24ec..a78501bcb8 100644 --- a/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware_asgi.py +++ b/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware_asgi.py @@ -23,6 +23,7 @@ from django.test import SimpleTestCase from django.test.utils import setup_test_environment, teardown_test_environment +from opentelemetry import trace as trace_api from opentelemetry.instrumentation.django import ( DjangoInstrumentor, _DjangoMiddleware, @@ -424,6 +425,16 @@ async def test_tracer_provider_traced(self): span.resource.attributes["resource-key"], "resource-value" ) + async def test_no_op_tracer_provider(self): + _django_instrumentor.uninstrument() + _django_instrumentor.instrument( + tracer_provider=trace_api.NoOpTracerProvider() + ) + + await self.async_client.post("/traced/") + spans = self.exporter.get_finished_spans() + self.assertEqual(len(spans), 0) + @patch.dict( "os.environ",