From 82ed887e8a50fae986d541932347b299bc059611 Mon Sep 17 00:00:00 2001 From: matveyZholudev <75423685+matveyZholudev@users.noreply.github.com> Date: Wed, 20 Jan 2021 18:54:29 +0300 Subject: [PATCH] =?UTF-8?q?don=E2=80=99t=20send=20sql=20query=20with=20the?= =?UTF-8?q?=20trace=20to=20the=20jaeger=20agent=20(#4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tracing.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/tracing.go b/tracing.go index ee4dcd2..7ad4495 100644 --- a/tracing.go +++ b/tracing.go @@ -9,14 +9,13 @@ import ( ) const ( - operationNameExec = "pq.Exec" - operationNameQuery = "pq.Query" - operationNameQueryRow = "pq.QueryRow" + operationNameExec = "pq.Exec" + operationNameQuery = "pq.Query" + operationNameQueryRow = "pq.QueryRow" operationNameTransaction = "pq.Transaction" - errLogKeyEvent = "event" - errLogKeyMessage = "message" - errLogValueErr = "error" - logKeySql = "sql" + errLogKeyEvent = "event" + errLogKeyMessage = "message" + errLogValueErr = "error" ) type tracingAdapter struct { @@ -41,7 +40,7 @@ func (ta *tracingAdapter) Transaction(ctx context.Context, f func(context.Contex } func (ta *tracingAdapter) Exec(ctx context.Context, sql string, args ...interface{}) (result RowsAffected, err error) { - span, spanCtx := startSpan(ctx, sql, operationNameExec) + span, spanCtx := startSpan(ctx, operationNameExec) rowsAffected, err := ta.Executor.Exec(spanCtx, sql, args...) @@ -55,7 +54,7 @@ func (ta *tracingAdapter) Exec(ctx context.Context, sql string, args ...interfac } func (ta *tracingAdapter) Query(ctx context.Context, sql string, args ...interface{}) (Rows, error) { - span, spanCtx := startSpan(ctx, sql, operationNameQuery) + span, spanCtx := startSpan(ctx, operationNameQuery) rows, err := ta.Executor.Query(spanCtx, sql, args...) @@ -68,7 +67,7 @@ func (ta *tracingAdapter) Query(ctx context.Context, sql string, args ...interfa } func (ta *tracingAdapter) QueryRow(ctx context.Context, sql string, args ...interface{}) Row { - span, spanCtx := startSpan(ctx, sql, operationNameQueryRow) + span, spanCtx := startSpan(ctx, operationNameQueryRow) row := ta.Executor.QueryRow(spanCtx, sql, args...) @@ -85,8 +84,7 @@ func traceErr(err error, span opentracing.Span) { ) } -func startSpan(ctx context.Context, sql string, name string) (opentracing.Span, context.Context) { +func startSpan(ctx context.Context, name string) (opentracing.Span, context.Context) { span, spanCtx := opentracing.StartSpanFromContext(ctx, name) - span.LogFields(log.String(logKeySql, sql)) return span, spanCtx }