Skip to content

Conversation

@alexander-alderman-webb
Copy link
Contributor

@alexander-alderman-webbalexander-alderman-webb commented Nov 13, 2025

Description

Copy metadata when wrapping coroutines in the patched asyncio task factory. Uses the functools.update_wrapper() function that is also used internally by functools.wraps(). Unlike when wrapping functions, less metadata is available on coroutines, so _wrap_coroutine() is equivalent to functools.wraps() with fewer attributes copied.

CPython copies __name__ and __qualname__ from function to coroutine: https://github.com/python/cpython/blob/a8733cbc7328dbeeed50e82ef13abb197d511c46/Objects/genobject.c#L1410.

As functools.update_wrapper() checks for the existence of properties first, copying metadata will not result in an AttributeError if metadata is not available. See the docs https://docs.python.org/3/library/functools.html#functools.update_wrapper

A small script to generate a task destroyed error.

importasyncioimportsentry_sdkfromsentry_sdk.integrations.asyncioimportAsyncioIntegrationDSN="..."asyncdefworker(): awaitasyncio.sleep(10) asyncdeftask(): sentry_sdk.init( dsn=DSN, integrations=[AsyncioIntegration()], debug=True, ) asyncio.create_task(worker()) if__name__=="__main__": loop=asyncio.new_event_loop() asyncio.set_event_loop(loop) loop.run_until_complete(task()) loop.close()

Issues

The SDK no longer overwrites coroutine metadata included in destroyed errors as reported in #5072.

Reminders

@codecov
Copy link

codecovbot commented Nov 13, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.97%. Comparing base (9e14920) to head (1111a21).
⚠️ Report is 28 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@ Coverage Diff @@## master #5105 +/- ## ========================================== + Coverage 83.95% 83.97% +0.01%  ========================================== Files 180 180 Lines 18010 18182 +172 Branches 3203 3231 +28 ========================================== + Hits 15120 15268 +148 - Misses 1915 1923 +8 - Partials 975 991 +16 
Files with missing linesCoverage Δ
sentry_sdk/integrations/asyncio.py87.30% <100.00%> (+0.86%)⬆️

... and 19 files with indirect coverage changes

@alexander-alderman-webbalexander-alderman-webb marked this pull request as ready for review November 24, 2025 08:29
@alexander-alderman-webbalexander-alderman-webb merged commit ca19d63 into masterNov 24, 2025
133 checks passed
@alexander-alderman-webbalexander-alderman-webb deleted the webb/wrap-coroutine branch November 24, 2025 08:42
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@alexander-alderman-webb@sentrivana