httptrace

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 2, 2020 License: Apache-2.0 Imports: 5 Imported by: 2

README

http trace

Build Status

HTTP Request trace, timing and requset's informations. Timing include dns, connect, tls, first reponse byte and so on.

trace, ht := NewClientTrace()
ctx := context.Background()
ctx = httptrace.WithClientTrace(ctx, trace)
req, _ := http.NewRequest("GET", "https://www.baidu.com/", nil)

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 {
	DNSLookup        time.Duration `json:"dnsLookup,omitempty"`
	TCPConnection    time.Duration `json:"tcpConnection,omitempty"`
	TLSHandshake     time.Duration `json:"tlsHandshake,omitempty"`
	ServerProcessing time.Duration `json:"serverProcessing,omitempty"`
	ContentTransfer  time.Duration `json:"contentTransfer,omitempty"`
	Total            time.Duration `json:"total,omitempty"`
}

HTTPTimelineStats http timeline stats

type HTTPTrace

type HTTPTrace struct {
	// 因为timeout的设置有可能导致 trace 读写并存,因此需要锁
	sync.RWMutex
	Host           string           `json:"host,omitempty"`
	Addrs          []string         `json:"addrs,omitempty"`
	Network        string           `json:"network,omitempty"`
	Addr           string           `json:"addr,omitempty"`
	Reused         bool             `json:"reused,omitempty"`
	TCPReused      bool             `json:"tcpReused,omitempty"`
	WasIdle        bool             `json:"wasIdle,omitempty"`
	IdleTime       time.Duration    `json:"idleTime,omitempty"`
	Protocol       string           `json:"protocol,omitempty"`
	TLSVersion     string           `json:"tlsVersion,omitempty"`
	TLSResume      bool             `json:"tlsResume,omitempty"`
	TLSCipherSuite string           `json:"tlsCipherSuite,omitempty"`
	Certificates   []tlsCertificate `json:"certificates,omitempty"`

	Start                time.Time `json:"start,omitempty"`
	DNSStart             time.Time `json:"dnsStart,omitempty"`
	DNSDone              time.Time `json:"dnsDone,omitempty"`
	ConnectStart         time.Time `json:"connectStart,omitempty"`
	ConnectDone          time.Time `json:"connectDone,omitempty"`
	GotConnect           time.Time `json:"gotConnect,omitempty"`
	GotFirstResponseByte time.Time `json:"gotFirstResponseByte,omitempty"`
	TLSHandshakeStart    time.Time `json:"tlsHandshakeStart,omitempty"`
	TLSHandshakeDone     time.Time `json:"tlsHandshakeDone,omitempty"`
	Done                 time.Time `json:"done,omitempty"`
}

HTTPTrace http trace

func NewClientTrace

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

NewClientTrace http client trace

func (*HTTPTrace) Finish

func (ht *HTTPTrace) Finish()

Finish http trace finish

func (*HTTPTrace) Stats

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

Stats get the stats of time line

Jump to

Keyboard shortcuts

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