Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sentry spamming RequestAborted on async django 5 #11719

Open
dima-kov opened this issue Jun 26, 2024 · 5 comments
Open

Sentry spamming RequestAborted on async django 5 #11719

dima-kov opened this issue Jun 26, 2024 · 5 comments

Comments

@dima-kov
Copy link

dima-kov commented Jun 26, 2024

How do you use Sentry?

Sentry Saas (sentry.io)

Version

sentry-sdk==2.6.0
django==5.0.6

Steps to Reproduce

  1. django app on completely async stack;
  2. sentry configuration:
sentry_sdk.init(
    dsn=SENTRY_DSN,
    traces_sample_rate=1.0 if ENV == Envs.Prod.value else 0.1,
    profiles_sample_rate=1.0,
    environment=ENV.value,
    send_default_pii=True,
    integrations=[
        DjangoIntegration(
            transaction_style="url",
            middleware_spans=True,
            signals_spans=False,
            cache_spans=False,
        ),
        AsyncioIntegration(),
    ],
)
  1. run app with uvicorn via asgi: python -m uvicorn myproject.asgi:application
  2. openning any view, accessing any admin url - sends RequestAborted error to sentry UI:
RequestAborted: null
  File "django/core/handlers/asgi.py", line 245, in listen_for_disconnect
    raise RequestAborted()

As we look into django code: https://github.com/django/django/blob/bcd255cd5ca0a1e686d276cca71f45ec400d84a2/django/core/handlers/asgi.py#L195-L202, raising this exception is expected for every http request, and is handled by django https://github.com/django/django/blob/bcd255cd5ca0a1e686d276cca71f45ec400d84a2/django/core/handlers/asgi.py#L209-L211 so we do not need to send errors on that.

Do you plan to fix this issue?

Expected Result

no error sent to sentry

Actual Result

Screenshot 2024-06-26 at 17 03 09 Screenshot 2024-06-26 at 17 03 36
@sentrivana
Copy link
Contributor

Hey @dima-kov, thanks for reporting. Yeah this should not be reported. While we're working on a fix, in the meantime you can filter the error out by defining a custom before_send, see https://docs.sentry.io/platforms/python/configuration/options/#before-send

@sentrivana
Copy link
Contributor

Ok I see what the problem is now. The DjangoIntegration is working correctly, ignoring the error as it should. It's the AsyncioIntegration that intercepts and reports the error. So disabling the integration is another possible temp solution.

@sentrivana
Copy link
Contributor

For the time being, the custom before_send is the way to go here. The asyncio integration wraps all tasks indiscriminately and will report any exceptions that happened in a task and were not handled. It doesn't have the context to see that the exception is then ignored higher up.

So even though technically speaking both integrations are working as expected, the out of the box experience is definitely improvement worthy. What we could do is have a predefined denylist of exceptions to ignore in the AsyncioIntegration.

@dima-kov
Copy link
Author

Would be great to update docs to describe the problem and potential fix example (before send)

@getsantry
Copy link
Contributor

getsantry bot commented Nov 4, 2024

Assigning to @getsentry/support for routing ⏲️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

4 participants