9
9
"context"
10
10
"crypto/tls"
11
11
"fmt"
12
- "net"
13
12
"net/http/httptrace"
14
13
"time"
15
14
)
@@ -19,45 +18,45 @@ import (
19
18
type TraceInfo struct {
20
19
// DNSLookup is the duration that transport took to perform
21
20
// DNS lookup.
22
- DNSLookup time.Duration
21
+ DNSLookup time.Duration `json:"dns_lookup_time"`
23
22
24
23
// ConnTime is the duration it took to obtain a successful connection.
25
- ConnTime time.Duration
24
+ ConnTime time.Duration `json:"connection_time"`
26
25
27
26
// TCPConnTime is the duration it took to obtain the TCP connection.
28
- TCPConnTime time.Duration
27
+ TCPConnTime time.Duration `json:"tcp_connection_time"`
29
28
30
29
// TLSHandshake is the duration of the TLS handshake.
31
- TLSHandshake time.Duration
30
+ TLSHandshake time.Duration `json:"tls_handshake_time"`
32
31
33
32
// ServerTime is the server's duration for responding to the first byte.
34
- ServerTime time.Duration
33
+ ServerTime time.Duration `json:"server_time"`
35
34
36
35
// ResponseTime is the duration since the first response byte from the server to
37
36
// request completion.
38
- ResponseTime time.Duration
37
+ ResponseTime time.Duration `json:"response_time"`
39
38
40
39
// TotalTime is the duration of the total time request taken end-to-end.
41
- TotalTime time.Duration
40
+ TotalTime time.Duration `json:"total_time"`
42
41
43
42
// IsConnReused is whether this connection has been previously
44
43
// used for another HTTP request.
45
- IsConnReused bool
44
+ IsConnReused bool `json:"is_connection_reused"`
46
45
47
46
// IsConnWasIdle is whether this connection was obtained from an
48
47
// idle pool.
49
- IsConnWasIdle bool
48
+ IsConnWasIdle bool `json:"is_connection_was_idle"`
50
49
51
50
// ConnIdleTime is the duration how long the connection that was previously
52
51
// idle, if IsConnWasIdle is true.
53
- ConnIdleTime time.Duration
52
+ ConnIdleTime time.Duration `json:"connection_idle_time"`
54
53
55
54
// RequestAttempt is to represent the request attempt made during a Resty
56
55
// request execution flow, including retry count.
57
- RequestAttempt int
56
+ RequestAttempt int `json:"request_attempt"`
58
57
59
58
// RemoteAddr returns the remote network address.
60
- RemoteAddr net. Addr
59
+ RemoteAddr string `json:"remote_address"`
61
60
}
62
61
63
62
// String method returns string representation of request trace information.
@@ -80,6 +79,21 @@ func (ti TraceInfo) String() string {
80
79
ti .RemoteAddr )
81
80
}
82
81
82
+ // JSON method returns the JSON string of request trace information
83
+ func (ti TraceInfo ) JSON () string {
84
+ buf := acquireBuffer ()
85
+ defer releaseBuffer (buf )
86
+ _ = encodeJSON (buf , ti )
87
+ return buf .String ()
88
+ }
89
+
90
+ // Clone method returns the clone copy of [TraceInfo]
91
+ func (ti TraceInfo ) Clone () * TraceInfo {
92
+ ti2 := new (TraceInfo )
93
+ * ti2 = ti
94
+ return ti2
95
+ }
96
+
83
97
// clientTrace struct maps the [httptrace.ClientTrace] hooks into Fields
84
98
// with the same naming for easy understanding. Plus additional insights
85
99
// [Request].
0 commit comments