From e5777ac20543c1bb2203ea2e1051cffb3f550a60 Mon Sep 17 00:00:00 2001 From: James Abley Date: Wed, 19 Nov 2025 16:23:46 +0000 Subject: [PATCH] feat: support tracing TLS handshake times This had to wait until go 1.8 came out for the new functionality to be added to the core libraries. This was introduced in https://github.com/golang/go/commit/abdd73cc43f9187e8918879944ec0dacbc912b5c and Go 1.8 came out in February 2017. Sorry @jonty! Fixes #1. --- main.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/main.go b/main.go index 77f0c54..58f482b 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "crypto/tls" "encoding/json" "fmt" "io" @@ -115,6 +116,8 @@ type TimingContext struct { ConnectStart float64 `json:"connectStart"` ConnectDone float64 `json:"connectDone"` WroteRequest float64 `json:"wroteRequest"` + TLSHandshakeStart float64 `json:"tlsHandshakeStart"` + TLSHandshakeDone float64 `json:"tlsHandshakeDone"` Total float64 `json:"total"` } @@ -202,6 +205,12 @@ func doIt(URL string) (*TimingContext, error) { ConnectStart: func(network, addr string) { timingContext.ConnectStart = timingContext.Elapsed() }, ConnectDone: func(network, addr string, err error) { timingContext.ConnectDone = timingContext.Elapsed() }, WroteRequest: func(e httptrace.WroteRequestInfo) { timingContext.WroteRequest = timingContext.Elapsed() }, + TLSHandshakeStart: func() { timingContext.TLSHandshakeStart = timingContext.Elapsed() }, + TLSHandshakeDone: func(_cs tls.ConnectionState, err error) { + if err == nil { + timingContext.TLSHandshakeDone = timingContext.Elapsed() + } + }, })) res, err := client.Do(req)