You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Integration for asyncio has a invalid signature for loop create_task function -- _sentry_task_factory #1993
File "/home/andrei/.cache/pypoetry/virtualenvs/candles-cache-Yse3-3EP-py3.11/lib/python3.11/site-packages/aiorun.py", line 393, in run
loop.run_until_complete(loop.shutdown_asyncgens())
File "uvloop/loop.pyx", line 1487, in uvloop.loop.Loop.run_until_complete
File "/home/andrei/.pyenv/versions/3.11.2/lib/python3.11/asyncio/tasks.py", line 649, in ensure_future
return _ensure_future(coro_or_future, loop=loop)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/andrei/.pyenv/versions/3.11.2/lib/python3.11/asyncio/tasks.py", line 670, in _ensure_future
return loop.create_task(coro_or_future)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "uvloop/loop.pyx", line 1431, in uvloop.loop.Loop.create_task
TypeError: patch_asyncio.<locals>._sentry_task_factory() got an unexpected keyword argument 'context'
sys:1: RuntimeWarning: coroutine 'Loop.shutdown_asyncgens' was never awaited
Thanks for bringing this up. Yes, our Python 3.11 support is not yet perfect. So we will look into this. (but we have a lot on our plates right now, so dont hold your breath)
But if you (or anyone else) what to give it a try, we are always happy to accept PRs
This issue has gone three weeks without activity. In another week, I will close it.
But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!
"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀
Hi @monosans and @andrewshkovskii, it looks like the reason your error is occurring is because you are calling the sentry_sdk.init from within the async main function instead of calling it as soon as possible when your application starts, as we recommend in our documentation.
Is there any reason why you need to be initializing the Sentry SDK from within the async main function? If not, I would suggest rewriting your code as follows, since it appears to stop your error from occurring:
Thank you for brining our attention to the changed method signatures, though. Even though it does not seem to be the cause of your error, we should probably still fix our code to match the new method signatures from Python 3.11.
the reason your error is occurring is because you are calling the sentry_sdk.init from within the async main function instead of calling it as soon as possible
Thanks, that helped.
But here's the interesting thing. This issue only occurs when using uvloop and only on Python 3.11. If you don't use uvloop or use Python below 3.11, everything works, even if you initialize sentry in an async function.
I did some more investigation into this issue, and it appears that I was incorrect earlier; your error is indeed caused by the method signature that we use in the SDK not matching the new signature for Python 3.11. The reason that moving the sentry_sdk.init call stopped the error from occurring is because moving this call out of the async function actually prevents the SDK from instrumenting asyncio properly. So none of the relevant SDK code ever gets called, meaning that we don't observe your error, but also the SDK will fail to report information that we would expect to gather from the asyncio integration. This is clearly a bug, since we should be instrumenting asyncio even when Sentry is being initialized outside an async function (especially because this is how our documentation states that the SDK should be initialized), and I will be creating an issue to document the bug so we can fix it.
So, for now, I would recommend that you move the Sentry SDK initialization call back into the async function to ensure that asyncio gets instrumented properly and all the events you are supposed to observe get captured. We will let you know once we have a fix for this issue.
If you don't use uvloop or use Python below 3.11, everything works, even if you initialize sentry in an async function.
While investigating, I discovered that the error also occurs without uvloop when you call asyncio.create_task with the context variable set to a value other than None.
Activity
antonpirker commentedon Apr 11, 2023
Hey @andrewshkovskii !
Thanks for bringing this up. Yes, our Python 3.11 support is not yet perfect. So we will look into this. (but we have a lot on our plates right now, so dont hold your breath)
But if you (or anyone else) what to give it a try, we are always happy to accept PRs
github-actions commentedon May 3, 2023
This issue has gone three weeks without activity. In another week, I will close it.
But! If you comment or otherwise update it, I will reset the clock, and if you label it
Status: BacklogorStatus: In Progress, I will leave it alone ... forever!"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀
szokeasaurusrex commentedon Aug 14, 2023
Hi @andrewshkovskii, can you please provide the exact steps/code to reproduce the error message that you observed? I am having trouble reproducing it
monosans commentedon Aug 15, 2023
szokeasaurusrex commentedon Aug 16, 2023
Hi @monosans and @andrewshkovskii, it looks like the reason your error is occurring is because you are calling the
sentry_sdk.initfrom within theasync mainfunction instead of calling it as soon as possible when your application starts, as we recommend in our documentation.Is there any reason why you need to be initializing the Sentry SDK from within the
async mainfunction? If not, I would suggest rewriting your code as follows, since it appears to stop your error from occurring:Thank you for brining our attention to the changed method signatures, though. Even though it does not seem to be the cause of your error, we should probably still fix our code to match the new method signatures from Python 3.11.
monosans commentedon Aug 16, 2023
Thanks, that helped.
But here's the interesting thing. This issue only occurs when using uvloop and only on Python 3.11. If you don't use uvloop or use Python below 3.11, everything works, even if you initialize sentry in an async function.
szokeasaurusrex commentedon Aug 16, 2023
I did some more investigation into this issue, and it appears that I was incorrect earlier; your error is indeed caused by the method signature that we use in the SDK not matching the new signature for Python 3.11. The reason that moving the
sentry_sdk.initcall stopped the error from occurring is because moving this call out of theasyncfunction actually prevents the SDK from instrumentingasyncioproperly. So none of the relevant SDK code ever gets called, meaning that we don't observe your error, but also the SDK will fail to report information that we would expect to gather from theasynciointegration. This is clearly a bug, since we should be instrumentingasyncioeven when Sentry is being initialized outside anasyncfunction (especially because this is how our documentation states that the SDK should be initialized), and I will be creating an issue to document the bug so we can fix it.So, for now, I would recommend that you move the Sentry SDK initialization call back into the
asyncfunction to ensure thatasynciogets instrumented properly and all the events you are supposed to observe get captured. We will let you know once we have a fix for this issue.While investigating, I discovered that the error also occurs without uvloop when you call
asyncio.create_taskwith thecontextvariable set to a value other thanNone.