sentry-python icon indicating copy to clipboard operation
sentry-python copied to clipboard

Different exception title [anyio 4.0]

Open NullOsama opened this issue 2 years ago • 16 comments

How do you use Sentry?

Sentry Saas (sentry.io)

Version

1.29.2

Steps to Reproduce

I'm not sure if it's something I did recently but the errors started to all have the same generic title ExceptionGroup unhandled errors in a TaskGroup

Expected Result

The way I expected the error to be shown is how it was before as shown in the following screenshots. sentry

image

Actual Result

image

The previous screenshot shows how is the exception shown which is very different from what it was before and it doesn't show specific information about the actual error. BTW, these screenshots are of the same error but something happened that made it look like the later pic.

NullOsama avatar Sep 03 '23 07:09 NullOsama

This issue was resolved after I downgraded anyio from 4.0.0 to 3.7.1

NullOsama avatar Sep 05 '23 07:09 NullOsama

I think Sentry should probably handle these in a nicer way

rushilsrivastava avatar Sep 08 '23 22:09 rushilsrivastava

I agree with @rushilsrivastava Downgrading anyio may mitigate this issue at hand, but its not a good solution. Sentry should be able to work with the new anyio versions

jacobowitz avatar Sep 11 '23 09:09 jacobowitz

@NullOsama could you please re-open the issue?

b0g3r avatar Sep 20 '23 15:09 b0g3r

I saw the same when updating to anyio 4. This could still be handled a lot better by Sentry. It's very difficult to find the main error in this output.

nickderobertis avatar Nov 29 '23 00:11 nickderobertis

Hi @rushilsrivastava, @jacobowitz, @b0g3r, @nickderobertis, are any of you still observing this issue? If so, I will gladly reopen it 🙂

szokeasaurusrex avatar Jun 03 '24 18:06 szokeasaurusrex

are any of you still observing this issue? If so, I will gladly reopen it 🙂

Yes, this still happens on newer version of anyio

rushilsrivastava avatar Jun 03 '24 21:06 rushilsrivastava

@rushilsrivastava Thanks for that info, I have reopened this issue on our backlog.

Exactly which versions of anyio are you experiencing the problems with? And, how do I reproduce the issue?

szokeasaurusrex avatar Jun 07 '24 14:06 szokeasaurusrex

Same over here with both anyio 4.4.0 and 4.3.0 with sentry-sdk 2.4.0 .

gustiando avatar Jun 13 '24 16:06 gustiando

So if I got this right, this is happening with anyio version 4.0.0 and above. Took a look at the changelog, these two points look relevant:

  • BACKWARDS INCOMPATIBLE Replaced AnyIO’s own ExceptionGroup class with the PEP 654 BaseExceptionGroup and ExceptionGroup
  • BACKWARDS INCOMPATIBLE Changes to cancellation semantics:
    • Any exceptions raising out of a task groups are now nested inside an ExceptionGroup (or BaseExceptionGroup if one or more BaseException were included)
    • Fixed task group not raising a cancellation exception on asyncio at exit if no child tasks were spawned and an outer cancellation scope had been cancelled before
    • Ensured that exiting a TaskGroup always hits a yield point, regardless of whether there are running child tasks to be waited on
    • On asyncio, cancel scopes will defer cancelling tasks that are scheduled to resume with a finished future
    • On asyncio and Python 3.9/3.10, cancel scopes now only suppress cancellation exceptions if the cancel message matches the scope
    • Task groups on all backends now raise a single cancellation exception when an outer cancel scope is cancelled, and no exceptions other than cancellation exceptions are raised in the group

It looks like anyio changed the semantics of the exceptions raised.

Is the problem that the "good" exception y'all would like to see is still there, but hidden somewhere in the exception group?

If someone could provide a small example to repro to help us understand the issue better, that'd help a lot.

sentrivana avatar Jun 17 '24 12:06 sentrivana

@antonpirker forgive me, what's the plan here?

I see that it's been removed from the milestone by you, care to provide some context?

bruno-gelb avatar Jun 21 '24 12:06 bruno-gelb

Hey @bruno-gelb ! I just removed all our milestones because we kind of did not use them the correct way. There has been no change in priority for this, we just do not use milestones anymore. Sorry for any confusion that might have caused.

antonpirker avatar Jun 24 '24 08:06 antonpirker

tested "pin anyio to <4" fix and it worked for me.

bruno-gelb avatar Jun 25 '24 17:06 bruno-gelb

tl;dr for this issue:

  1. With anyio version 4.0.0 anyio is using Pythons ExceptionGroups instead of a custom exception group implementation they used earlier.
  2. Sentry handles exception groups different than simple exceptions to show how the exceptions in an exception group are related.
  3. You (the persons in this thread) do not like how the exception group is displayed in Sentry.

antonpirker avatar Jun 27 '24 07:06 antonpirker

Gathering feedback

To everyone in the thread (also the ones that only "thumb up" on comments:

  1. Can you find your error in the exception group?
  2. How can we improve the exception group display? Any ideas?
  3. Is data missing you used to see before?
  4. any other ideas on how to make things better?

antonpirker avatar Jun 27 '24 07:06 antonpirker

  1. only the top level error message (one-liner), the rest of the traceback is missing
  2. fix Sentry event title (it should display something useful like ZeroDivisionError: division by zero, not Exception group: unhandled errors in TaskGroup (1 sub-exception)
  3. also fix Sentry event traceback (now it's missing. Instead of traceback for the original exception it's some asyncio / anyio internal gibberish now)

bruno-gelb avatar Jun 27 '24 08:06 bruno-gelb

Hello, a bit more context for Sentry devs :

I get this:

Image Image Image

Note the absence of a stack trace on the ZeroDivisionError - I barely even see it mentioned.

I would expect something more like the following (see "spoiler" tag after code block) - except ideally with handled set to false - the reason it's true here is because I manually called sentry_sdk.capture_exception() from a artificial/unwanted global try/except block, ie

            try:
                await super().async_run('trio')

            except Exception:
                sentry_sdk.capture_exception()
                raise
The result:

Image Image Image

Thanks in advance! :-)

EDIT: I had already seen https://github.com/getsentry/sentry/issues/37716 which gave me hope in the first place, but no cigar - my versions should be OK - the issue says « It will also be included in the next Sentry Self-Hosted release (23.6.0, est. June 2023). » , and my versions are as follow (although note I'm not entirely done upgrading my server yet, I stopped at the last hard stop):

Image Image

So Python sentry-sdk 2.27.0, self-hosted Sentry 24.8.0.

Cheaterman avatar May 02 '25 18:05 Cheaterman

This problem should be fixed by #4164. However, since this change affects how issues are grouped in Sentry, it is a breaking change, and so it will only be released in the next major (3.0.0).

We plan to release an alpha version of 3.0.0 soon (hopefully this week or next). There is no timeline yet for when we will release a stable version.

szokeasaurusrex avatar May 05 '25 13:05 szokeasaurusrex

Thanks a lot for your answer! Can't wait to see it with my own eyes :-) godspeed Sentry team & contributors!

Cheaterman avatar May 05 '25 17:05 Cheaterman