Skip to content

Commit 35756b6

Browse files
committed
chore(exchanger): add round trip duration to error message
1 parent 5326983 commit 35756b6

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

internal/exchanger/exchanger.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package exchanger
33
import (
44
"context"
55
"fmt"
6+
"time"
67

78
"github.com/miekg/dns"
89
)
@@ -31,16 +32,17 @@ func (e *Exchanger) Exchange(ctx context.Context, network string, request *dns.M
3132
}
3233
dnsConn := &dns.Conn{Conn: netConn}
3334

34-
response, _, err = e.client.ExchangeWithConnContext(ctx, request, dnsConn)
35+
response, roundTripDuration, err := e.client.ExchangeWithConnContext(ctx, request, dnsConn)
3536

3637
closeErr := dnsConn.Close()
3738
if closeErr != nil {
3839
e.warner.Warn("cannot close " + e.dialer.String() + " connection: " + closeErr.Error())
3940
}
4041

4142
if err != nil {
42-
return nil, fmt.Errorf("exchanging over %s connection for request %s: %w",
43-
e.dialer, extractRequestQuestion(request), err)
43+
roundTripMilliseconds := roundTripDuration.Round(time.Millisecond).Milliseconds()
44+
return nil, fmt.Errorf("exchanging over %s connection (%dms) for request %s: %w",
45+
e.dialer, roundTripMilliseconds, extractRequestQuestion(request), err)
4446
}
4547

4648
return response, nil

0 commit comments

Comments
 (0)