Lower Level Tracing
Nobody has claimed this yet.
- 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've been tracing PGX since before any of the tracing methods existed. The new APIs are excellent but still seem to leave a gap. Specifically I want to trace the arguments but in some cases there can be arbitrarily complex encoding through `pgtype` etc. so it'd be nice to be able to add a trace to see not just see the original Go struct but the value it encodes into.
While I could use the `*pgtype.Map` to try to encode each value I would have to know details like their oid that aren't available until you reach lower level parts of the API like `pgconn`. Therefore I'd like to ask for some way to support this tracing.
**Describe the solution you'd like**
There are roughly two approaches I can see. Something like `TraceExecParams`, `TraceQueryParams` etc. could help but my only concern is that I'd also have to do my best to force the text encoding in order to render it the easiest. Just by reading [QueryExecMode](https://pkg.go.dev/github.com/jackc/pgx/v5#QueryExecMode) or similar I'm unsure if I could leverage any of them to force a text encoding more often and extra roundtrips sound unappealing.
The most direct API that would help me specifically would be an API like this:
```ts
newArgs, _ := pgx.RawArguments(originalArgs, pgtype.TextFormatCode)
for _, arg := range newArgs {
if arg.IsBinary {
// Do something reasonable. I know it's impossible to encode everything in text but I honestly don't know how to handle tracing binary arguments
} else {
fmt.Println("Got string argument", arg)
}
}
pgx.Query(ctx, sql, pgx.RawArgs(newArgs))
```
This only works because my tracing already works by reimplementing `pgx.Conn` as an interface (since it predates the existing tracing) but I understand that's probably a less broadly useful API.
**Describe alternatives you've considered**
Either doubling up on the encoding by using available the `pgtype` code or the rather unappealing idea of avoiding doubling up encoding by making my own abstraction around `pgconn`.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the existing tracing APIs, QueryExecMode, pgtype.Map, and the lower-level pgconn encoding path mentioned in the issue. The work is complete when an agreed API exposes encoded query arguments for tracing, including a defined treatment of binary values, without requiring undesirable extra round trips or duplicate encoding.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, postgresql
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100