Expose Conn.preparedStatements to TraceQueryStart
- Dominant language
- Go
- Stars
- 14.3k
- Forks
- 1.1k
- Avg merge
- 6d 9h
- Merged PRs (30d)
- 11
Description
**Is your feature request related to a problem? Please describe.**
I'm currently writing a custom Prometheus tracer, and I want to expose the following:
- query
- duration
- success/failure
I tried doing so using `TraceQueryStart` / `TraceQueryEnd` following the example provided in `tracelog`. I noticed that in `TraceQueryStart`, when trying to access `data.SQL`, we only get `pgx_0`, `pgx_1`, etc. (we're using the stdlib adapter)
**Describe the solution you'd like**
I'd like [`Conn.preparedStatements`](https://github.com/jackc/pgx/blob/master/conn.go#L70) to be exposed to `TraceQueryStart`.
Either directly:
```diff
- preparedStatements map[string]*pgconn.StatementDescription
+ PreparedStatements map[string]*pgconn.StatementDescription
```
or indirectly:
```go
func (c *Conn) GetPreparedStatement(name string) *pgconn.StatementDescription {
return c.preparedStatements
}
```
**Describe alternatives you've considered**
An alternative I have in mind is to implement `TracePrepareStart` to keep a map[name]sql on my side but it's a bit annoying, and I'm not sure `name` is unique across all conns when using a pool
**Additional context**
Contributor guide
Research direction
Start with conn.go's preparedStatements and the TraceQueryStart/TraceQueryEnd hooks, then compare the stdlib adapter path with the tracelog example. Done means TraceQueryStart can associate generated prepared-statement names with their original SQL without requiring a separate per-pool map; the chosen API should be validated against the existing tracing behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, postgresql
- Domain
- databases, observability
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100