Extend instrumentation capabilities.
- Dominant language
- Go
- Stars
- 14.3k
- Forks
- 1.1k
- Avg merge
- 6d 9h
- Merged PRs (30d)
- 11
Description
Hi,
I've tried to add some Prometheus-based instrumentation into an application that uses `pgxpool` and found lack of things which should help me. In general, I'd like to implement basic metrics such as total number of queries executed and queries durations and then extend metrics with driver-specific things based on `Stat` struct. But only one thing I could made is a just total number of transactions (not queries).
It would be great if functionality of pgxpool will be extended in the following way:
1. Context can be transferred from `BeforeAcquire` to `AfterRelease` function - it will make possible to measure time of connection were used.
2. Return to `AfterRelease` some information about executed query, such as error/success status, bytes sent/received, text of the statement may be, something else...
3. Inside of `AfterRelease`, allow to get access to pool's `Stat` struct - it may helps to expose driver-specific stats into metrics.
I consider these things may not be easy to implement, but it can be very useful for application-side instrumentation.
Also, I'd like to mention an approach used in [Redis driver](https://github.com/go-redis/redis). It uses [Hook](https://github.com/go-redis/redis/blob/master/redis.go#L22) interface which provides `BeforeProcess` and `AfterProcess` methods which can be used to get information about executed commands (from `Cmder` struct). Using this methods I made verbose metrics that helps to understand Redis workload from application's point of view.
Regards, Alexey
Contributor guide
Research direction
Start by reading the pgxpool BeforeAcquire and AfterRelease callbacks and the Stat struct to understand the current instrumentation boundaries. Compare the linked Redis Hook approach, then define and validate support for connection timing, query outcome details, and pool statistics in application metrics.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, postgresql, prometheus
- Domain
- backend, databases, observability
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100