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
3 changes: 3 additions & 0 deletions sentry_sdk/integrations/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ async def inner():
except HTTPException as e:
span.set_http_status(e.status_code)
raise
except asyncio.CancelledError:
Comment thread
untitaker marked this conversation as resolved.
Resolved
span.set_status("cancelled")
raise
except Exception:
# This will probably map to a 500 but seems like we
# have no way to tell. Do not set span status.
Expand Down
25 changes: 25 additions & 0 deletions tests/integrations/aiohttp/test_aiohttp.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import asyncio
import json
from contextlib import suppress

from aiohttp import web
from aiohttp.client import ServerDisconnectedError

from sentry_sdk.integrations.aiohttp import AioHttpIntegration

Expand Down Expand Up @@ -120,6 +123,28 @@ async def hello(request):
assert not events


async def test_cancelled_error_not_captured(
sentry_init, aiohttp_client, loop, capture_events
):
sentry_init(integrations=[AioHttpIntegration()])

async def hello(request):
raise asyncio.CancelledError()

app = web.Application()
app.router.add_get("/", hello)

events = capture_events()
client = await aiohttp_client(app)

with suppress(ServerDisconnectedError):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use pytest.raises here unless you are saying this error does not happen all the time

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've used suppress to avoid testing aiohttp here.

At the moment, ServerDisconnectedError is always raised, but this behavior can be changed in the future and will cause tests to fail even though sentry-python operates normally.

But, if you'd like to use pytest.raises instead, let me know :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, let's stick with this

# Intended `aiohttp` interaction: server will disconnect if it
# encounters `asyncio.CancelledError`
await client.get("/")

assert not events


async def test_half_initialized(sentry_init, aiohttp_client, loop, capture_events):
sentry_init(integrations=[AioHttpIntegration()])
sentry_init()
Expand Down