diff --git a/sentry_sdk/integrations/django/__init__.py b/sentry_sdk/integrations/django/__init__.py index 5a808a53cb..41aaecc71a 100644 --- a/sentry_sdk/integrations/django/__init__.py +++ b/sentry_sdk/integrations/django/__init__.py @@ -130,7 +130,7 @@ class DjangoIntegration(Integration): def __init__( self, transaction_style="url", # type: str - middleware_spans=True, # type: bool + middleware_spans=False, # type: bool signals_spans=True, # type: bool cache_spans=False, # type: bool db_transaction_spans=False, # type: bool diff --git a/tests/integrations/django/test_basic.py b/tests/integrations/django/test_basic.py index bbe29c7238..1c6bb141bd 100644 --- a/tests/integrations/django/test_basic.py +++ b/tests/integrations/django/test_basic.py @@ -1023,7 +1023,7 @@ def test_render_spans_queryset_in_data(sentry_init, client, capture_events): def test_middleware_spans(sentry_init, client, capture_events, render_span_tree): sentry_init( integrations=[ - DjangoIntegration(signals_spans=False), + DjangoIntegration(middleware_spans=True, signals_spans=False), ], traces_sample_rate=1.0, ) @@ -1040,7 +1040,7 @@ def test_middleware_spans(sentry_init, client, capture_events, render_span_tree) def test_middleware_spans_disabled(sentry_init, client, capture_events): sentry_init( integrations=[ - DjangoIntegration(middleware_spans=False, signals_spans=False), + DjangoIntegration(signals_spans=False), ], traces_sample_rate=1.0, ) @@ -1180,8 +1180,9 @@ def test_csrf(sentry_init, client): @pytest.mark.skipif(DJANGO_VERSION < (2, 0), reason="Requires Django > 2.0") +@pytest.mark.parametrize("middleware_spans", [False, True]) def test_custom_urlconf_middleware( - settings, sentry_init, client, capture_events, render_span_tree + settings, sentry_init, client, capture_events, render_span_tree, middleware_spans ): """ Some middlewares (for instance in django-tenants) overwrite request.urlconf. @@ -1192,7 +1193,10 @@ def test_custom_urlconf_middleware( settings.MIDDLEWARE.insert(0, urlconf) client.application.load_middleware() - sentry_init(integrations=[DjangoIntegration()], traces_sample_rate=1.0) + sentry_init( + integrations=[DjangoIntegration(middleware_spans=middleware_spans)], + traces_sample_rate=1.0, + ) events = capture_events() content, status, _headers = unpack_werkzeug_response(client.get("/custom/ok")) @@ -1201,7 +1205,8 @@ def test_custom_urlconf_middleware( event = events.pop(0) assert event["transaction"] == "/custom/ok" - assert "custom_urlconf_middleware" in render_span_tree(event) + if middleware_spans: + assert "custom_urlconf_middleware" in render_span_tree(event) _content, status, _headers = unpack_werkzeug_response(client.get("/custom/exc")) assert status.lower() == "500 internal server error" @@ -1210,7 +1215,8 @@ def test_custom_urlconf_middleware( assert error_event["transaction"] == "/custom/exc" assert error_event["exception"]["values"][-1]["mechanism"]["type"] == "django" assert transaction_event["transaction"] == "/custom/exc" - assert "custom_urlconf_middleware" in render_span_tree(transaction_event) + if middleware_spans: + assert "custom_urlconf_middleware" in render_span_tree(transaction_event) settings.MIDDLEWARE.pop(0)