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
8 changes: 6 additions & 2 deletions sentry_sdk/integrations/asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@ def _sentry_task_factory(loop, coro):
# 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
Expand Down
16 changes: 16 additions & 0 deletions tests/integrations/asyncio/test_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,19 @@ async def test_exception(
assert error_event["exception"]["values"][0]["value"] == "division by zero"
assert error_event["exception"]["values"][0]["mechanism"]["handled"] is False
assert error_event["exception"]["values"][0]["mechanism"]["type"] == "asyncio"


@minimum_python_36
@pytest.mark.asyncio
async def test_task_result(sentry_init):
sentry_init(
integrations=[
AsyncioIntegration(),
],
)

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

result = await asyncio.create_task(add(1, 2))
assert result == 3, result