Hi!
I was looking to add a custom logging filter to my aiohttp server during exception that are catched here.
It's useful and easy to do, but, it occurs that, in my custom logging filter, I can't find contextvars that I have created in my request handler task.
Two things caused this problem:
Python documentation on Tasks here. One important thing is that they reset contextvars.
To summarize:
aiohttp logging exception
+ ^
| |
| asyncio.create_task(handle_request()) | contextvars didn't go up again
| | (it's fixed now)
| |
v |
Sentry |
+ |
| |
| asyncio.create_task(handle_request()) | contextvars don't go up
| |
v |
I set contextvars +---------------------+
Exception
As long as the issue is not fixed in Sentry, I still can't use contextvars to log custom data using the standard Python logging library.
The only solution is to disable Sentry, then logging works OK with contextvars.
Any idea how to fix this in Sentry-aiohttp code?
I'd be happy to open a PR, but I'm not familiar enough with Sentry code, or Python in general, thus I need some help at least.
Hi!
I was looking to add a custom logging filter to my aiohttp server during exception that are catched here.
It's useful and easy to do, but, it occurs that, in my custom logging filter, I can't find contextvars that I have created in my request handler task.
Two things caused this problem:
→ This was fixed in aio-libs/aiohttp@9997cae (because users asked to be able to access
contextvars-- like us). It was even backported to aiohttp version 3.7.Python documentation on Tasks here. One important thing is that they reset contextvars.
To summarize:
As long as the issue is not fixed in Sentry, I still can't use
contextvarsto log custom data using the standard Pythonlogginglibrary.The only solution is to disable Sentry, then logging works OK with contextvars.
Any idea how to fix this in Sentry-aiohttp code?
I'd be happy to open a PR, but I'm not familiar enough with Sentry code, or Python in general, thus I need some help at least.