Add configurable `event_hooks` for the `httpx` layer for observability or `logging`
- Dominant language
- Python
- Stars
- 17
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
**Is your feature request related to a problem? Please describe.**
While thinking about this problem for another platform we maintain, I came across [event_hooks](https://www.python-httpx.org/advanced/event-hooks/) in `httpx`.
We should make this configurable for the `gallagher` clients in case the user wants to add observability or `logging` for their implementation.
I don't believe the library should bother implementing the logging as a solution, it can provide reference implementations but not a solution.
**Describe the solution you'd like**
Modify the API so the developer can pass hooks into the initialisation which are called by the `httpx` layer upon requests placed and responses received.
In the case of `httpx` these work as interceptors where the developer can add additional headers etc.
Note that we will have to find a reliable mechanism to identify requests so we can perform operations like logging the body against other metadata, see also #2
**Describe alternatives you've considered**
NA
**Additional context**
For example the OpenAI python client allows you to pass in a configured `httpx` client
```python
import httpx
client = openai.OpenAI(
http_client=httpx.Client(
event_hooks={
"request": [print],
"response": [print]
}
)
)
```
we could follow a similar pattern and allow the developer to configure their `gallagher` API client and let them handle the result of the `request` and `responses`
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.