From 32c5de88692f53b0caf49156a3493e9eba8faddf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Einar=20Nor=C3=B0fj=C3=B6r=C3=B0?= Date: Tue, 21 May 2024 02:05:50 -0400 Subject: [PATCH] fix: emit rows affected attribute (#33) Before this commit the `pgx.rows_affected` attribute would only be emitted in case of error. The commit flips the check such that we emit it when an error has not occurred. --- tracer.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tracer.go b/tracer.go index b4058e1..255c83e 100644 --- a/tracer.go +++ b/tracer.go @@ -169,7 +169,7 @@ func (t *Tracer) TraceQueryEnd(ctx context.Context, _ *pgx.Conn, data pgx.TraceQ span := trace.SpanFromContext(ctx) recordError(span, data.Err) - if data.Err != nil { + if data.Err == nil { span.SetAttributes(RowsAffectedKey.Int64(data.CommandTag.RowsAffected())) } @@ -204,7 +204,7 @@ func (t *Tracer) TraceCopyFromEnd(ctx context.Context, _ *pgx.Conn, data pgx.Tra span := trace.SpanFromContext(ctx) recordError(span, data.Err) - if data.Err != nil { + if data.Err == nil { span.SetAttributes(RowsAffectedKey.Int64(data.CommandTag.RowsAffected())) }