Skip to content

Commit

Permalink
GH #370 Capture remote address in trace info
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm committed Sep 9, 2020
1 parent 29cc550 commit ae3d649
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 7 additions & 0 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,8 @@ func (r *Request) TraceInfo() TraceInfo {
RetryAttempt: r.RetryAttempt,
}

// Calculate the total time accordingly,
// when connection is reused
if ct.gotConnInfo.Reused {
ti.TotalTime = ct.endTime.Sub(ct.getConn)
} else {
Expand All @@ -607,6 +609,11 @@ func (r *Request) TraceInfo() TraceInfo {
ti.ResponseTime = ct.endTime.Sub(ct.gotFirstResponseByte)
}

// Capture remote address info when connection is non-nil
if ct.gotConnInfo.Conn != nil {
ti.RemoteAddr = ct.gotConnInfo.Conn.RemoteAddr()
}

return ti
}

Expand Down
6 changes: 5 additions & 1 deletion trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package resty
import (
"context"
"crypto/tls"
"net"
"net/http/httptrace"
"time"
)
Expand Down Expand Up @@ -58,10 +59,13 @@ type TraceInfo struct {
// RetryAttempt is to represent the retry attempt made during a Resty
// request execution flow when using the Resty retry feature.
RetryAttempt int

// RemoteAddr returns the remote network address.
RemoteAddr net.Addr
}

//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// CientTrace struct and its methods
// ClientTrace struct and its methods
//_______________________________________________________________________

// tracer struct maps the `httptrace.ClientTrace` hooks into Fields
Expand Down

0 comments on commit ae3d649

Please sign in to comment.