From e6016ceed8918954d3a27757f66b5faf06a59028 Mon Sep 17 00:00:00 2001 From: Marek Goc Date: Thu, 14 Nov 2024 20:30:18 +0100 Subject: [PATCH] cat query string at VALUES if is set to not log values in query --- pkg/gorm_tracing/middleware.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/pkg/gorm_tracing/middleware.go b/pkg/gorm_tracing/middleware.go index b538ca9..deffcdd 100644 --- a/pkg/gorm_tracing/middleware.go +++ b/pkg/gorm_tracing/middleware.go @@ -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))