Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

feat/msp/runtime: PG_QUERY_LOGGING=true for local dev query logging#63164

Merged
bobheadxi merged 1 commit into
mainfrom
msp-localdev-query-logging
Jun 11, 2024
Merged

feat/msp/runtime: PG_QUERY_LOGGING=true for local dev query logging#63164
bobheadxi merged 1 commit into
mainfrom
msp-localdev-query-logging

Conversation

@bobheadxi

Copy link
Copy Markdown
Member

Closes https://linear.app/sourcegraph/issue/CORE-168

Test plan

[enterprise-...l] DEBUG pgx.devtracer.enterprise-portal contract/postgresql.go:157 pgx.QueryStart
[enterprise-...l] ---
[enterprise-...l] SELECT count(*) FROM pg_indexes WHERE tablename = $1 AND indexname = $2 AND schemaname = CURRENT_SCHEMA()
[enterprise-...l] ---
[enterprise-...l]  {"args": ["{\"1082\":1,\"1114\":1,\"1184\":1,\"16\":1,\"17\":1,\"20\":1,\"21\":1,\"23\":1,\"26\":1,\"28\":1,\"29\":1,\"700\":1,\"701\":1}", "\"permissions\"", "\"idx_permissions_namespace\""]}
[enterprise-...l] DEBUG pgx.devtracer.enterprise-portal contract/postgresql.go:163 pgx.QueryEnd {"commandTag": "SELECT 1", "error": "<nil>"}
[enterprise-...l] DEBUG pgx.devtracer.enterprise-portal contract/postgresql.go:157 pgx.QueryStart
[enterprise-...l] ---
[enterprise-...l] SELECT count(*) FROM pg_indexes WHERE tablename = $1 AND indexname = $2 AND schemaname = CURRENT_SCHEMA()
[enterprise-...l] ---
[enterprise-...l]  {"args": ["{\"1082\":1,\"1114\":1,\"1184\":1,\"16\":1,\"17\":1,\"20\":1,\"21\":1,\"23\":1,\"26\":1,\"28\":1,\"29\":1,\"700\":1,\"701\":1}", "\"permissions\"", "\"idx_permissions_subject\""]}

Changelog

  • MSP runtime users can now set PG_QUERY_LOGGING=true to dump queries and arguments from database interactions at DEBUG level in local dev.

@bobheadxi bobheadxi requested review from a team and unknwon June 7, 2024 19:35
@cla-bot cla-bot Bot added the cla-signed label Jun 7, 2024
func (t pgxLocalDevTracer) TraceQueryStart(ctx context.Context, _ *pgx.Conn, data pgx.TraceQueryStartData) context.Context {
var args []string
for _, arg := range data.Args {
data, _ := json.Marshal(arg)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be funky for some data types, though not sure how to work around that

@unknwon unknwon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!


if logQueries {
logger := log.Scoped(fmt.Sprintf("pgx.devtracer.%s", database))
logger.Warn("enabling query logging")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger.Warn("enabling query logging")
logger.Info("enabling query logging")

Given this always local dev, I feel like Info is more appropriate.

@bobheadxi bobheadxi merged commit 42d7ba7 into main Jun 11, 2024
@bobheadxi bobheadxi deleted the msp-localdev-query-logging branch June 11, 2024 18:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants