prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  AttributeError: 'async_generator_athrow' object has no attribute '__qualname__'
  ### How do you use Sentry?
  
  Sentry Saas (sentry.io)
  
  ### Version
  
  1.19.1
  
  ### Steps to Reproduce
  
  I'm trying to use the `asyncio` integration like this:
  
  ```python
  sentry_sdk.init(dsn=os.environ.get("SENTRY_DSN"), traces_sample_rate=0.1, integrations=[AsyncioIntegration()])
  ```
  
  I keep on getting a traceback that seems to be a Sentry-specific issue.
  
  ### Expected Result
  
  No tracebacks repeatedly occur
  
  ### Actual Result
  
  I see this traceback repeatedly printed in the logs:
  
  ```python
  Task exception was never retrieved
  future: <Task finished name='Task-1512' coro=<patch_asyncio.<locals>._sentry_task_factory.<locals>._coro_creating_hub_and_span() done, defined at /usr/local/lib/python3.9/site-packages/sentry_sdk/integrations/asyncio.py:34> exception=AttributeError("'async_generator_athrow' object has no attribute '__qualname__'")>
  Traceback (most recent call last):
    File "/usr/local/lib/python3.9/site-packages/sentry_sdk/integrations/asyncio.py", line 40, in _coro_creating_hub_and_span
      with hub.start_span(op=OP.FUNCTION, description=coro.__qualname__):
  AttributeError: 'async_generator_athrow' object has no attribute '__qualname__'
  ```
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `sentry_sdk/integrations/asyncio.py`
  Content:
  ```
  1 from __future__ import absolute_import
  2 import sys
  3 
  4 from sentry_sdk._compat import reraise
  5 from sentry_sdk.consts import OP
  6 from sentry_sdk.hub import Hub
  7 from sentry_sdk.integrations import Integration, DidNotEnable
  8 from sentry_sdk._types import TYPE_CHECKING
  9 from sentry_sdk.utils import event_from_exception
  10 
  11 try:
  12     import asyncio
  13     from asyncio.tasks import Task
  14 except ImportError:
  15     raise DidNotEnable("asyncio not available")
  16 
  17 
  18 if TYPE_CHECKING:
  19     from typing import Any
  20 
  21     from sentry_sdk._types import ExcInfo
  22 
  23 
  24 def patch_asyncio():
  25     # type: () -> None
  26     orig_task_factory = None
  27     try:
  28         loop = asyncio.get_running_loop()
  29         orig_task_factory = loop.get_task_factory()
  30 
  31         def _sentry_task_factory(loop, coro):
  32             # type: (Any, Any) -> Any
  33 
  34             async def _coro_creating_hub_and_span():
  35                 # type: () -> Any
  36                 hub = Hub(Hub.current)
  37                 result = None
  38 
  39                 with hub:
  40                     with hub.start_span(op=OP.FUNCTION, description=coro.__qualname__):
  41                         try:
  42                             result = await coro
  43                         except Exception:
  44                             reraise(*_capture_exception(hub))
  45 
  46                 return result
  47 
  48             # Trying to use user set task factory (if there is one)
  49             if orig_task_factory:
  50                 return orig_task_factory(loop, _coro_creating_hub_and_span())
  51 
  52             # The default task factory in `asyncio` does not have its own function
  53             # but is just a couple of lines in `asyncio.base_events.create_task()`
  54             # Those lines are copied here.
  55 
  56             # WARNING:
  57             # If the default behavior of the task creation in asyncio changes,
  58             # this will break!
  59             task = Task(_coro_creating_hub_and_span(), loop=loop)
  60             if task._source_traceback:  # type: ignore
  61                 del task._source_traceback[-1]  # type: ignore
  62 
  63             return task
  64 
  65         loop.set_task_factory(_sentry_task_factory)
  66     except RuntimeError:
  67         # When there is no running loop, we have nothing to patch.
  68         pass
  69 
  70 
  71 def _capture_exception(hub):
  72     # type: (Hub) -> ExcInfo
  73     exc_info = sys.exc_info()
  74 
  75     integration = hub.get_integration(AsyncioIntegration)
  76     if integration is not None:
  77         # If an integration is there, a client has to be there.
  78         client = hub.client  # type: Any
  79 
  80         event, hint = event_from_exception(
  81             exc_info,
  82             client_options=client.options,
  83             mechanism={"type": "asyncio", "handled": False},
  84         )
  85         hub.capture_event(event, hint=hint)
  86 
  87     return exc_info
  88 
  89 
  90 class AsyncioIntegration(Integration):
  91     identifier = "asyncio"
  92 
  93     @staticmethod
  94     def setup_once():
  95         # type: () -> None
  96         patch_asyncio()
  97
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/sentry_sdk/integrations/asyncio.py b/sentry_sdk/integrations/asyncio.py
  --- a/sentry_sdk/integrations/asyncio.py
  +++ b/sentry_sdk/integrations/asyncio.py
  @@ -21,6 +21,15 @@
       from sentry_sdk._types import ExcInfo
   
   
  +def get_name(coro):
  +    # type: (Any) -> str
  +    return (
  +        getattr(coro, "__qualname__", None)
  +        or getattr(coro, "__name__", None)
  +        or "coroutine without __name__"
  +    )
  +
  +
   def patch_asyncio():
       # type: () -> None
       orig_task_factory = None
  @@ -37,7 +46,7 @@
                   result = None
   
                   with hub:
  -                    with hub.start_span(op=OP.FUNCTION, description=coro.__qualname__):
  +                    with hub.start_span(op=OP.FUNCTION, description=get_name(coro)):
                           try:
                               result = await coro
                           except Exception:
  
verification_info: {"golden_diff": "diff --git a/sentry_sdk/integrations/asyncio.py b/sentry_sdk/integrations/asyncio.py\n--- a/sentry_sdk/integrations/asyncio.py\n+++ b/sentry_sdk/integrations/asyncio.py\n@@ -21,6 +21,15 @@\n     from sentry_sdk._types import ExcInfo\n \n \n+def get_name(coro):\n+    # type: (Any) -> str\n+    return (\n+        getattr(coro, \"__qualname__\", None)\n+        or getattr(coro, \"__name__\", None)\n+        or \"coroutine without __name__\"\n+    )\n+\n+\n def patch_asyncio():\n     # type: () -> None\n     orig_task_factory = None\n@@ -37,7 +46,7 @@\n                 result = None\n \n                 with hub:\n-                    with hub.start_span(op=OP.FUNCTION, description=coro.__qualname__):\n+                    with hub.start_span(op=OP.FUNCTION, description=get_name(coro)):\n                         try:\n                             result = await coro\n                         except Exception:\n", "issue": "AttributeError: 'async_generator_athrow' object has no attribute '__qualname__'\n### How do you use Sentry?\r\n\r\nSentry Saas (sentry.io)\r\n\r\n### Version\r\n\r\n1.19.1\r\n\r\n### Steps to Reproduce\r\n\r\nI'm trying to use the `asyncio` integration like this:\r\n\r\n```python\r\nsentry_sdk.init(dsn=os.environ.get(\"SENTRY_DSN\"), traces_sample_rate=0.1, integrations=[AsyncioIntegration()])\r\n```\r\n\r\nI keep on getting a traceback that seems to be a Sentry-specific issue.\r\n\r\n### Expected Result\r\n\r\nNo tracebacks repeatedly occur\r\n\r\n### Actual Result\r\n\r\nI see this traceback repeatedly printed in the logs:\r\n\r\n```python\r\nTask exception was never retrieved\r\nfuture: <Task finished name='Task-1512' coro=<patch_asyncio.<locals>._sentry_task_factory.<locals>._coro_creating_hub_and_span() done, defined at /usr/local/lib/python3.9/site-packages/sentry_sdk/integrations/asyncio.py:34> exception=AttributeError(\"'async_generator_athrow' object has no attribute '__qualname__'\")>\r\nTraceback (most recent call last):\r\n  File \"/usr/local/lib/python3.9/site-packages/sentry_sdk/integrations/asyncio.py\", line 40, in _coro_creating_hub_and_span\r\n    with hub.start_span(op=OP.FUNCTION, description=coro.__qualname__):\r\nAttributeError: 'async_generator_athrow' object has no attribute '__qualname__'\r\n```\n", "before_files": [{"content": "from __future__ import absolute_import\nimport sys\n\nfrom sentry_sdk._compat import reraise\nfrom sentry_sdk.consts import OP\nfrom sentry_sdk.hub import Hub\nfrom sentry_sdk.integrations import Integration, DidNotEnable\nfrom sentry_sdk._types import TYPE_CHECKING\nfrom sentry_sdk.utils import event_from_exception\n\ntry:\n    import asyncio\n    from asyncio.tasks import Task\nexcept ImportError:\n    raise DidNotEnable(\"asyncio not available\")\n\n\nif TYPE_CHECKING:\n    from typing import Any\n\n    from sentry_sdk._types import ExcInfo\n\n\ndef patch_asyncio():\n    # type: () -> None\n    orig_task_factory = None\n    try:\n        loop = asyncio.get_running_loop()\n        orig_task_factory = loop.get_task_factory()\n\n        def _sentry_task_factory(loop, coro):\n            # type: (Any, Any) -> Any\n\n            async def _coro_creating_hub_and_span():\n                # type: () -> Any\n                hub = Hub(Hub.current)\n                result = None\n\n                with hub:\n                    with hub.start_span(op=OP.FUNCTION, description=coro.__qualname__):\n                        try:\n                            result = await coro\n                        except Exception:\n                            reraise(*_capture_exception(hub))\n\n                return result\n\n            # Trying to use user set task factory (if there is one)\n            if orig_task_factory:\n                return orig_task_factory(loop, _coro_creating_hub_and_span())\n\n            # The default task factory in `asyncio` does not have its own function\n            # but is just a couple of lines in `asyncio.base_events.create_task()`\n            # Those lines are copied here.\n\n            # WARNING:\n            # If the default behavior of the task creation in asyncio changes,\n            # this will break!\n            task = Task(_coro_creating_hub_and_span(), loop=loop)\n            if task._source_traceback:  # type: ignore\n                del task._source_traceback[-1]  # type: ignore\n\n            return task\n\n        loop.set_task_factory(_sentry_task_factory)\n    except RuntimeError:\n        # When there is no running loop, we have nothing to patch.\n        pass\n\n\ndef _capture_exception(hub):\n    # type: (Hub) -> ExcInfo\n    exc_info = sys.exc_info()\n\n    integration = hub.get_integration(AsyncioIntegration)\n    if integration is not None:\n        # If an integration is there, a client has to be there.\n        client = hub.client  # type: Any\n\n        event, hint = event_from_exception(\n            exc_info,\n            client_options=client.options,\n            mechanism={\"type\": \"asyncio\", \"handled\": False},\n        )\n        hub.capture_event(event, hint=hint)\n\n    return exc_info\n\n\nclass AsyncioIntegration(Integration):\n    identifier = \"asyncio\"\n\n    @staticmethod\n    def setup_once():\n        # type: () -> None\n        patch_asyncio()\n", "path": "sentry_sdk/integrations/asyncio.py"}], "after_files": [{"content": "from __future__ import absolute_import\nimport sys\n\nfrom sentry_sdk._compat import reraise\nfrom sentry_sdk.consts import OP\nfrom sentry_sdk.hub import Hub\nfrom sentry_sdk.integrations import Integration, DidNotEnable\nfrom sentry_sdk._types import TYPE_CHECKING\nfrom sentry_sdk.utils import event_from_exception\n\ntry:\n    import asyncio\n    from asyncio.tasks import Task\nexcept ImportError:\n    raise DidNotEnable(\"asyncio not available\")\n\n\nif TYPE_CHECKING:\n    from typing import Any\n\n    from sentry_sdk._types import ExcInfo\n\n\ndef get_name(coro):\n    # type: (Any) -> str\n    return (\n        getattr(coro, \"__qualname__\", None)\n        or getattr(coro, \"__name__\", None)\n        or \"coroutine without __name__\"\n    )\n\n\ndef patch_asyncio():\n    # type: () -> None\n    orig_task_factory = None\n    try:\n        loop = asyncio.get_running_loop()\n        orig_task_factory = loop.get_task_factory()\n\n        def _sentry_task_factory(loop, coro):\n            # type: (Any, Any) -> Any\n\n            async def _coro_creating_hub_and_span():\n                # type: () -> Any\n                hub = Hub(Hub.current)\n                result = None\n\n                with hub:\n                    with hub.start_span(op=OP.FUNCTION, description=get_name(coro)):\n                        try:\n                            result = await coro\n                        except Exception:\n                            reraise(*_capture_exception(hub))\n\n                return result\n\n            # Trying to use user set task factory (if there is one)\n            if orig_task_factory:\n                return orig_task_factory(loop, _coro_creating_hub_and_span())\n\n            # The default task factory in `asyncio` does not have its own function\n            # but is just a couple of lines in `asyncio.base_events.create_task()`\n            # Those lines are copied here.\n\n            # WARNING:\n            # If the default behavior of the task creation in asyncio changes,\n            # this will break!\n            task = Task(_coro_creating_hub_and_span(), loop=loop)\n            if task._source_traceback:  # type: ignore\n                del task._source_traceback[-1]  # type: ignore\n\n            return task\n\n        loop.set_task_factory(_sentry_task_factory)\n    except RuntimeError:\n        # When there is no running loop, we have nothing to patch.\n        pass\n\n\ndef _capture_exception(hub):\n    # type: (Hub) -> ExcInfo\n    exc_info = sys.exc_info()\n\n    integration = hub.get_integration(AsyncioIntegration)\n    if integration is not None:\n        # If an integration is there, a client has to be there.\n        client = hub.client  # type: Any\n\n        event, hint = event_from_exception(\n            exc_info,\n            client_options=client.options,\n            mechanism={\"type\": \"asyncio\", \"handled\": False},\n        )\n        hub.capture_event(event, hint=hint)\n\n    return exc_info\n\n\nclass AsyncioIntegration(Integration):\n    identifier = \"asyncio\"\n\n    @staticmethod\n    def setup_once():\n        # type: () -> None\n        patch_asyncio()\n", "path": "sentry_sdk/integrations/asyncio.py"}]}