httptrace

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 15, 2023 License: Apache-2.0 Imports: 6 Imported by: 2

README

http trace

Build Status

HTTP Request trace, timing and request's information. Timing include dns, connect, tls, first response byte and so on.

events:

  • GetConn
  • DNSStart
  • DNSDone
  • ConnectStart
  • ConnectDone
  • TLSHandshakeStart
  • TLSHandshakeDone
  • GotConn
  • WroteHeaders
  • WroteRequest
  • GotFirstResponseByte
trace, ht := NewClientTrace()
ctx := context.Background()
ctx = httptrace.WithClientTrace(ctx, trace)
req, _ := http.NewRequest("GET", "https://www.baidu.com/", nil)

req = req.WithContext(ctx)
resp, _ := http.DefaultClient.Do(req)

ht.Finish()
stats := ht.Stats()
fmt.Println(stats)
fmt.Println(resp.Status)

Documentation

Index

Constants

View Source
const (
	TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256   uint16 = 0xcca8
	TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 uint16 = 0xcca9
	TLS_AES_128_GCM_SHA256                        uint16 = 0x1301
	TLS_AES_256_GCM_SHA384                        uint16 = 0x1302
	TLS_CHACHA20_POLY1305_SHA256                  uint16 = 0x1303
)

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTPTimelineStats

type HTTPTimelineStats struct {
	// dns lookup time
	DNSLookup time.Duration `json:"dnsLookup,omitempty"`
	// get connection time
	GetConnection time.Duration `json:"getConnection,omitempty"`
	// tcp connection time
	TCPConnection time.Duration `json:"tcpConnection,omitempty"`
	// tls handshake time
	TLSHandshake time.Duration `json:"tlsHandshake,omitempty"`
	// request body send time
	RequestSend time.Duration `json:"requestSend"`
	// server processing time
	ServerProcessing time.Duration `json:"serverProcessing,omitempty"`
	// content transfer time
	ContentTransfer time.Duration `json:"contentTransfer,omitempty"`
	// total time
	Total time.Duration `json:"total,omitempty"`
}

HTTPTimelineStats http timeline stats

func (*HTTPTimelineStats) String added in v1.0.3

func (stats *HTTPTimelineStats) String() string

String return http timeline stats's string

type HTTPTrace

type HTTPTrace struct {
	// http request host
	Host string `json:"host,omitempty"`
	// addrs of host
	Addrs []string `json:"addrs,omitempty"`
	// network type
	Network string `json:"network,omitempty"`
	// http request addr
	Addr string `json:"addr,omitempty"`
	// http local addr
	LocalAddr string `json:"localAddr,omitempty"`
	// tcp reused
	Reused bool `json:"reused,omitempty"`
	// tcp was idle
	WasIdle bool `json:"wasIdle,omitempty"`
	// tcp idle time
	IdleTime time.Duration `json:"idleTime,omitempty"`
	// http protocol
	Protocol string `json:"protocol,omitempty"`
	// tls version
	TLSVersion string `json:"tlsVersion,omitempty"`
	// tls resume
	TLSResume bool `json:"tlsResume,omitempty"`
	// tls cipher suite
	TLSCipherSuite string `json:"tlsCipherSuite,omitempty"`
	// tls certificate lst
	Certificates []tlsCertificate `json:"certificates,omitempty"`
	// OCSPStapled OCSP stapling
	OCSPStapled bool `json:"ocspStapled,omitempty"`
	// DNSCoalesced dns query coalesced
	DNSCoalesced bool `json:"dnsCoalesced"`

	// start time of request
	Start time.Time `json:"start,omitempty"`
	// get connection time of request
	GetConn time.Time `json:"getConn,omitempty"`
	// dns start time
	DNSStart time.Time `json:"dnsStart,omitempty"`
	// dns done time
	DNSDone time.Time `json:"dnsDone,omitempty"`
	// connect start time
	ConnectStart time.Time `json:"connectStart,omitempty"`
	// connect done time
	ConnectDone time.Time `json:"connectDone,omitempty"`
	// got connect time
	GotConnect time.Time `json:"gotConnect,omitempty"`
	// wrote headers time
	WroteHeaders time.Time `json:"wroteHeaders,omitempty"`
	// wrote request
	WroteRequest time.Time `json:"wroteRequest,omitempty"`
	// got first response byte time
	GotFirstResponseByte time.Time `json:"gotFirstResponseByte,omitempty"`
	// tls handshake start time
	TLSHandshakeStart time.Time `json:"tlsHandshakeStart,omitempty"`
	// tls handshake done time
	TLSHandshakeDone time.Time `json:"tlsHandshakeDone,omitempty"`
	// request done time
	Done time.Time `json:"done,omitempty"`
}

HTTPTrace http trace

func NewClientTrace

func NewClientTrace() (trace *httptrace.ClientTrace, ht *HTTPTrace)

NewClientTrace returns a new client trace

func (*HTTPTrace) Finish

func (ht *HTTPTrace) Finish()

Finish http trace

func (*HTTPTrace) Stats

func (ht *HTTPTrace) Stats() (stats *HTTPTimelineStats)

Stats returns the stats of time line

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL