# Request: Can we get a c-api hook into PyContext\_Enter and PyContext\_Exit

**URL:** <https://discuss.python.org/t/request-can-we-get-a-c-api-hook-into-pycontext-enter-and-pycontext-exit/51730>\
**Category:** Async-SIG\
**Tags:** asyncio\
**Created:** [April 23, 2024, 6:05pm UTC](https://discuss.python.org/t/request-can-we-get-a-c-api-hook-into-pycontext-enter-and-pycontext-exit/51730 "2024-04-23T18:05:49Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![brettlangdon](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/brettlangdon/32/12344_2.png) [@brettlangdon](https://discuss.python.org/u/brettlangdon)\
**Post date:** [May 9, 2024, 3:02pm UTC](https://discuss.python.org/t/request-can-we-get-a-c-api-hook-into-pycontext-enter-and-pycontext-exit/51730/5 "2024-05-09T15:02:10Z")

</div>

This is similar to a topic I started in the Ideas section, and I was just about to try and start conversations again for it. Maybe the context I have is useful for this discussion?

(this is less about context enter/exit, but more for task enter/exit, so understand if we aren’t really in the same ballpark here)

> [@Add asyncio monitoring hooks](https://discuss.python.org/t/add-asyncio-monitoring-hooks/26426):
>
> [Similar previous discussion](https://discuss.python.org/t/adding-monitoring-hooks-to-the-event-loop/3448) As an APM vendor (Datadog), I’d love to be able to provide deeper insights/metrics about the asyncio event loop for our customers. Some of the metrics I have been thinking about so far are: Over the lifetime of the process total number of tasks created/finished total number of context switches min/avg/p95/p99/max/etc blocking time per-task run Per-task total number of context switches total blocking vs idle time I’d also like to be able to associate the per…

---

_[View the full topic](https://discuss.python.org/t/request-can-we-get-a-c-api-hook-into-pycontext-enter-and-pycontext-exit/51730)._
