Skip to content

Commit

Permalink
don’t send sql query with the trace to the jaeger agent (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
matveyZholudev authored Jan 20, 2021
1 parent ff536e7 commit 82ed887
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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...)

Expand All @@ -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...)

Expand All @@ -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...)

Expand All @@ -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
}

0 comments on commit 82ed887

Please sign in to comment.