jackc / jackc/pgx

Request for adding preparedStatement name into logged query data

Open
#1,119 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
14.3k
Forks
1.1k
Avg merge
6d 9h
Merged PRs (30d)
11

Description

Hihi, I'm new to github so please bear with me and let me know if I should have done things differently...

Currently I'm running an app using pgx and I'm adding trace telemetry to honeycomb.

Yay: [conn.Exec](https://github.com/jackc/pgx/blob/master/conn.go#L424) seems to log out the preparedStatement name as sql.
Boo: query only logs the sqlQuery, but not the named preparedStatement (see below).

It would be fantastic to be able to see visually in honeycomb `PreparedStatementQueryName`. I know I can regex the SQL, but it just feels dirty.

```
myApp -> pgxpool.pool.Query
[pgxpool.pool.Query](https://github.com/jackc/pgx/blob/master/pgxpool/pool.go#L496)
[pgxpool.conn.Query](https://github.com/jackc/pgx/blob/master/pgxpool/conn.go#L54)
[conn.Query](https://github.com/jackc/pgx/blob/master/conn.go#L599)
[conn.getRows](https://github.com/jackc/pgx/blob/master/conn.go#L551) // Here we get the rows and set row.sql = sql, which is the preparedStatement DB func name.
[conn.Query](https://github.com/jackc/pgx/blob/master/conn.go#L646) // Here we set the rows.sql as sd.sql, which is the actual sqlQuery
[rows.Close](https://github.com/jackc/pgx/blob/master/rows.go#L146) // And finally we log, but only with data that includes the sqlQuery
```

It seems to me that rows.sql is only used for logging, but there would most likely always be a demand for having the query.

I would suggest:
1. adding name as a [row parameter](https://github.com/jackc/pgx/blob/master/rows.go#L105)
2. adding it to the [data that gets logged out](https://github.com/jackc/pgx/blob/master/rows.go#L146).

If this seems reasonable then I'm all for creating a PR myself with proposed changes.

Thanks a bunch - Húni

Contributor guide

Open the contributing guide

Research direction

Start with rows.go around the row parameter and rows.Close logging, then trace conn.getRows and conn.Query as linked in the issue. Check how the prepared-statement name and SQL query are assigned. Done means logged query data includes the prepared-statement name without losing the SQL query.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, postgresql
Domain
backend, databases
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.