fix: rename tracedPGxHooks to tracedSQLHooks

This commit is contained in:
DevMiner 2024-07-28 16:56:41 +02:00
parent 8bf2fa122d
commit d5cbb6a757

View file

@ -26,7 +26,7 @@ type dbCtxVal struct {
attrs []attribute.KeyValue attrs []attribute.KeyValue
} }
type tracedPgxHooks struct { type tracedSQLHooks struct {
dbType string dbType string
t *Telemetry t *Telemetry
@ -36,7 +36,7 @@ type tracedPgxHooks struct {
mDuration metric.Float64Histogram mDuration metric.Float64Histogram
} }
func (h *tracedPgxHooks) Before(ctx context.Context, query string, args ...interface{}) (context.Context, error) { func (h *tracedSQLHooks) Before(ctx context.Context, query string, args ...interface{}) (context.Context, error) {
cleanedQuery := strings.ReplaceAll(query, "\n", " ") cleanedQuery := strings.ReplaceAll(query, "\n", " ")
cleanedQuery = strings.ReplaceAll(cleanedQuery, "\t", " ") cleanedQuery = strings.ReplaceAll(cleanedQuery, "\t", " ")
cleanedQuery = strings.ReplaceAll(cleanedQuery, " ", " ") cleanedQuery = strings.ReplaceAll(cleanedQuery, " ", " ")
@ -78,7 +78,7 @@ func (h *tracedPgxHooks) Before(ctx context.Context, query string, args ...inter
}), nil }), nil
} }
func (h *tracedPgxHooks) After(ctx context.Context, query string, args ...interface{}) (context.Context, error) { func (h *tracedSQLHooks) After(ctx context.Context, query string, args ...interface{}) (context.Context, error) {
if s := SpanFromContext(ctx); s != nil { if s := SpanFromContext(ctx); s != nil {
s.End() s.End()
} }
@ -106,7 +106,7 @@ func (t *Telemetry) TraceSQL(driver driver.Driver, dbType string, printQueries b
log.Fatal().Err(err).Msg("failed to create request duration histogram") log.Fatal().Err(err).Msg("failed to create request duration histogram")
} }
return sqlhooks.Wrap(driver, &tracedPgxHooks{ return sqlhooks.Wrap(driver, &tracedSQLHooks{
dbType: dbType, dbType: dbType,
printQueries: printQueries, printQueries: printQueries,