cat query string at VALUES if is set to not log values in query

This commit is contained in:
Marek Goc 2024-11-14 20:30:18 +01:00
parent 1230538295
commit e6016ceed8

View File

@ -187,18 +187,17 @@ func (p *gormPlugin) after() gormHookFunc {
attrs = append(attrs, sys)
}
vars := tx.Statement.Vars
query := ""
if p.excludeQueryVars {
// Replace query variables with '?' to mask them
vars = make([]interface{}, len(tx.Statement.Vars))
for i := 0; i < len(vars); i++ {
vars[i] = "?"
// cat query at VALUES and add tree dots
pos := strings.Index(tx.Statement.SQL.String(), "VALUES (")
if pos != -1 {
query = tx.Statement.SQL.String()[:pos+len("VALUES ")] + " ..."
} else {
query = tx.Statement.SQL.String()
}
}
query := tx.Dialector.Explain(tx.Statement.SQL.String(), vars...)
attrs = append(attrs, semconv.DBStatementKey.String(p.formatQuery(query)))
if tx.Statement.Table != "" {
attrs = append(attrs, semconv.DBSQLTableKey.String(tx.Statement.Table))