Skip to content

Commit

Permalink
Fix typo in defer calls
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-normand committed May 5, 2022
1 parent 2f85370 commit a962c9c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
8 changes: 4 additions & 4 deletions contrib/database/sql/conn.go
Expand Up @@ -66,7 +66,7 @@ func (tc *tracedConn) PrepareContext(ctx context.Context, query string) (stmt dr
sqlCommentCarrier := tracer.SQLCommentCarrier{DiscardDynamicTags: true}
span := tc.tryStartTrace(ctx, queryTypePrepare, query, start, &sqlCommentCarrier, err)
if span != nil {
go func() {
defer func() {
span.Finish(tracer.WithError(err))
}()
}
Expand All @@ -80,7 +80,7 @@ func (tc *tracedConn) PrepareContext(ctx context.Context, query string) (stmt dr
sqlCommentCarrier := tracer.SQLCommentCarrier{DiscardDynamicTags: true}
span := tc.tryStartTrace(ctx, queryTypePrepare, query, start, &sqlCommentCarrier, err)
if span != nil {
go func() {
defer func() {
span.Finish(tracer.WithError(err))
}()
}
Expand Down Expand Up @@ -148,7 +148,7 @@ func (tc *tracedConn) QueryContext(ctx context.Context, query string, args []dri
sqlCommentCarrier := tracer.SQLCommentCarrier{}
span := tc.tryStartTrace(ctx, queryTypeQuery, query, start, &sqlCommentCarrier, err)
if span != nil {
go func() {
defer func() {
span.Finish(tracer.WithError(err))
}()
}
Expand All @@ -169,7 +169,7 @@ func (tc *tracedConn) QueryContext(ctx context.Context, query string, args []dri
sqlCommentCarrier := tracer.SQLCommentCarrier{}
span := tc.tryStartTrace(ctx, queryTypeQuery, query, start, &sqlCommentCarrier, err)
if span != nil {
go func() {
defer func() {
span.Finish(tracer.WithError(err))
}()
}
Expand Down
9 changes: 7 additions & 2 deletions contrib/database/sql/stmt.go
Expand Up @@ -9,6 +9,7 @@ import (
"context"
"database/sql/driver"
"errors"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
"time"
)

Expand All @@ -25,9 +26,13 @@ type tracedStmt struct {
// Close sends a span before closing a statement
func (s *tracedStmt) Close() (err error) {
start := time.Now()
span := s.tryStartTrace(s.ctx, queryTypeClose, "", start, nil, err)
if span != nil {
defer func() {
span.Finish(tracer.WithError(err))
}()
}
err = s.Stmt.Close()
s.tryTrace(s.ctx, queryTypeClose, "", start, err)

return err
}

Expand Down
1 change: 0 additions & 1 deletion ddtrace/mocktracer/mockspan.go
Expand Up @@ -216,7 +216,6 @@ func (s *mockspan) Finish(opts ...ddtrace.FinishOption) {
s.finished = true
s.finishTime = t
s.tracer.addFinishedSpan(s)
//fmt.Printf("Finished span with type %v\n", s.Tag("sql.query_type"))
}

// String implements fmt.Stringer.
Expand Down

0 comments on commit a962c9c

Please sign in to comment.