We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Patched task factory in AsyncioIntegration loses task result.
### How do you use Sentry?

Sentry Saas (sentry.io)

### Version

1.14.0

### Steps to Reproduce

```python
import asyncio
import sentry_sdk
from sentry_sdk.integrations.asyncio import AsyncioIntegration

async def add(a, b):
    return a + b

async def main():
    sentry_sdk.init('dsn', integrations=[AsyncioIntegration()])
    result = await asyncio.create_task(add(1, 2))
    assert result == 3, result

asyncio.run(main())
```

### Expected Result

No `AssertionError`.

### Actual Result

```python
    assert result == 3, result
AssertionError: None
```

Patched task factory always loses task result.

--- 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 MYPY
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 MYPY:
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: () -> None
36                 hub = Hub(Hub.current)
37                 with hub:
38                     with hub.start_span(op=OP.FUNCTION, description=coro.__qualname__):
39                         try:
40                             await coro
41                         except Exception:
42                             reraise(*_capture_exception(hub))
43 
44             # Trying to use user set task factory (if there is one)
45             if orig_task_factory:
46                 return orig_task_factory(loop, _coro_creating_hub_and_span())  # type: ignore
47 
48             # The default task factory in `asyncio` does not have its own function
49             # but is just a couple of lines in `asyncio.base_events.create_task()`
50             # Those lines are copied here.
51 
52             # WARNING:
53             # If the default behavior of the task creation in asyncio changes,
54             # this will break!
55             task = Task(_coro_creating_hub_and_span(), loop=loop)
56             if task._source_traceback:  # type: ignore
57                 del task._source_traceback[-1]  # type: ignore
58 
59             return task
60 
61         loop.set_task_factory(_sentry_task_factory)
62     except RuntimeError:
63         # When there is no running loop, we have nothing to patch.
64         pass
65 
66 
67 def _capture_exception(hub):
68     # type: (Hub) -> ExcInfo
69     exc_info = sys.exc_info()
70 
71     integration = hub.get_integration(AsyncioIntegration)
72     if integration is not None:
73         # If an integration is there, a client has to be there.
74         client = hub.client  # type: Any
75 
76         event, hint = event_from_exception(
77             exc_info,
78             client_options=client.options,
79             mechanism={"type": "asyncio", "handled": False},
80         )
81         hub.capture_event(event, hint=hint)
82 
83     return exc_info
84 
85 
86 class AsyncioIntegration(Integration):
87     identifier = "asyncio"
88 
89     @staticmethod
90     def setup_once():
91         # type: () -> None
92         patch_asyncio()
93
```
--- 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()

```

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
@@ -32,15 +32,19 @@
             # type: (Any, Any) -> Any
 
             async def _coro_creating_hub_and_span():
-                # type: () -> None
+                # type: () -> Any
                 hub = Hub(Hub.current)
+                result = None
+
                 with hub:
                     with hub.start_span(op=OP.FUNCTION, description=coro.__qualname__):
                         try:
-                            await coro
+                            result = await coro
                         except Exception:
                             reraise(*_capture_exception(hub))
 
+                return result
+
             # Trying to use user set task factory (if there is one)
             if orig_task_factory:
                 return orig_task_factory(loop, _coro_creating_hub_and_span())  # type: ignore

{"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@@ -32,15 +32,19 @@\n             # type: (Any, Any) -> Any\n \n             async def _coro_creating_hub_and_span():\n-                # type: () -> None\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-                            await coro\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())  # type: ignore\n", "issue": "Patched task factory in AsyncioIntegration loses task result.\n### How do you use Sentry?\n\nSentry Saas (sentry.io)\n\n### Version\n\n1.14.0\n\n### Steps to Reproduce\n\n```python\r\nimport asyncio\r\nimport sentry_sdk\r\nfrom sentry_sdk.integrations.asyncio import AsyncioIntegration\r\n\r\nasync def add(a, b):\r\n    return a + b\r\n\r\nasync def main():\r\n    sentry_sdk.init('dsn', integrations=[AsyncioIntegration()])\r\n    result = await asyncio.create_task(add(1, 2))\r\n    assert result == 3, result\r\n\r\nasyncio.run(main())\r\n```\n\n### Expected Result\n\nNo `AssertionError`.\n\n### Actual Result\n\n```python\r\n    assert result == 3, result\r\nAssertionError: None\r\n```\r\n\r\nPatched task factory always loses task result.\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 MYPY\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 MYPY:\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: () -> None\n                hub = Hub(Hub.current)\n                with hub:\n                    with hub.start_span(op=OP.FUNCTION, description=coro.__qualname__):\n                        try:\n                            await coro\n                        except Exception:\n                            reraise(*_capture_exception(hub))\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())  # type: ignore\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 MYPY\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 MYPY:\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())  # type: ignore\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"}]}