Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/django/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 12 additions & 6 deletions tests/integrations/django/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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,
)
Expand Down Expand Up @@ -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.
Expand All @@ -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"))
Expand All @@ -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"
Expand All @@ -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)

Expand Down