Skip to content

Commit 428f1de

Browse files
chore(django): Disable middleware spans by default (#5219)
Closes #5062.
1 parent 8417165 commit 428f1de

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

sentry_sdk/integrations/django/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class DjangoIntegration(Integration):
130130
def __init__(
131131
self,
132132
transaction_style="url", # type: str
133-
middleware_spans=True, # type: bool
133+
middleware_spans=False, # type: bool
134134
signals_spans=True, # type: bool
135135
cache_spans=False, # type: bool
136136
db_transaction_spans=False, # type: bool

tests/integrations/django/test_basic.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ def test_render_spans_queryset_in_data(sentry_init, client, capture_events):
10231023
def test_middleware_spans(sentry_init, client, capture_events, render_span_tree):
10241024
sentry_init(
10251025
integrations=[
1026-
DjangoIntegration(signals_spans=False),
1026+
DjangoIntegration(middleware_spans=True, signals_spans=False),
10271027
],
10281028
traces_sample_rate=1.0,
10291029
)
@@ -1040,7 +1040,7 @@ def test_middleware_spans(sentry_init, client, capture_events, render_span_tree)
10401040
def test_middleware_spans_disabled(sentry_init, client, capture_events):
10411041
sentry_init(
10421042
integrations=[
1043-
DjangoIntegration(middleware_spans=False, signals_spans=False),
1043+
DjangoIntegration(signals_spans=False),
10441044
],
10451045
traces_sample_rate=1.0,
10461046
)
@@ -1180,8 +1180,9 @@ def test_csrf(sentry_init, client):
11801180

11811181

11821182
@pytest.mark.skipif(DJANGO_VERSION < (2, 0), reason="Requires Django > 2.0")
1183+
@pytest.mark.parametrize("middleware_spans", [False, True])
11831184
def test_custom_urlconf_middleware(
1184-
settings, sentry_init, client, capture_events, render_span_tree
1185+
settings, sentry_init, client, capture_events, render_span_tree, middleware_spans
11851186
):
11861187
"""
11871188
Some middlewares (for instance in django-tenants) overwrite request.urlconf.
@@ -1192,7 +1193,10 @@ def test_custom_urlconf_middleware(
11921193
settings.MIDDLEWARE.insert(0, urlconf)
11931194
client.application.load_middleware()
11941195

1195-
sentry_init(integrations=[DjangoIntegration()], traces_sample_rate=1.0)
1196+
sentry_init(
1197+
integrations=[DjangoIntegration(middleware_spans=middleware_spans)],
1198+
traces_sample_rate=1.0,
1199+
)
11961200
events = capture_events()
11971201

11981202
content, status, _headers = unpack_werkzeug_response(client.get("/custom/ok"))
@@ -1201,7 +1205,8 @@ def test_custom_urlconf_middleware(
12011205

12021206
event = events.pop(0)
12031207
assert event["transaction"] == "/custom/ok"
1204-
assert "custom_urlconf_middleware" in render_span_tree(event)
1208+
if middleware_spans:
1209+
assert "custom_urlconf_middleware" in render_span_tree(event)
12051210

12061211
_content, status, _headers = unpack_werkzeug_response(client.get("/custom/exc"))
12071212
assert status.lower() == "500 internal server error"
@@ -1210,7 +1215,8 @@ def test_custom_urlconf_middleware(
12101215
assert error_event["transaction"] == "/custom/exc"
12111216
assert error_event["exception"]["values"][-1]["mechanism"]["type"] == "django"
12121217
assert transaction_event["transaction"] == "/custom/exc"
1213-
assert "custom_urlconf_middleware" in render_span_tree(transaction_event)
1218+
if middleware_spans:
1219+
assert "custom_urlconf_middleware" in render_span_tree(transaction_event)
12141220

12151221
settings.MIDDLEWARE.pop(0)
12161222

0 commit comments

Comments
 (0)