Skip to content

Commit

Permalink
Add rows affected as a span attribute (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
keitwb authored Jan 26, 2023
1 parent 7160c8e commit 9a35ce0
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"github.com/exaring/otelpgx/internal"
)

var RowsAffectedKey = attribute.Key("pgx.rows_affected")

// Tracer is a wrapper around the pgx tracer interfaces which instrument
// queries.
type Tracer struct {
Expand Down Expand Up @@ -127,6 +129,8 @@ func (t *Tracer) TraceQueryEnd(ctx context.Context, _ *pgx.Conn, data pgx.TraceQ
span := trace.SpanFromContext(ctx)
recordError(span, data.Err)

span.SetAttributes(RowsAffectedKey.Int(int(data.CommandTag.RowsAffected())))

span.End()
}

Expand Down Expand Up @@ -158,6 +162,8 @@ func (t *Tracer) TraceCopyFromEnd(ctx context.Context, _ *pgx.Conn, data pgx.Tra
span := trace.SpanFromContext(ctx)
recordError(span, data.Err)

span.SetAttributes(RowsAffectedKey.Int(int(data.CommandTag.RowsAffected())))

span.End()
}

Expand Down

0 comments on commit 9a35ce0

Please sign in to comment.