diff options
author | Jaana Burcu Dogan <jbd@google.com> | 2016-09-23 15:42:50 -0700 |
---|---|---|
committer | Jaana Burcu Dogan <jbd@google.com> | 2016-10-04 20:47:06 +0000 |
commit | cc9ef2355eceeb5ab0d21e129980e81fe3f39958 (patch) | |
tree | 23d75024b8e4213f1ece5f332ed7a2276ec048ce /content/http-tracing/trace.go | |
parent | 508b508cdf14a82bee0c8aa0547eb22b36822079 (diff) |
content: add introducing http tracing post
Updates golang/go#17152.
Change-Id: I08d4174ba62f6dc4028bd17a911b92fc373b81e4
Reviewed-on: https://go-review.googlesource.com/29685
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Andrew Gerrand <adg@golang.org>
Diffstat (limited to 'content/http-tracing/trace.go')
-rw-r--r-- | content/http-tracing/trace.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/content/http-tracing/trace.go b/content/http-tracing/trace.go new file mode 100644 index 0000000..2d6d75e --- /dev/null +++ b/content/http-tracing/trace.go @@ -0,0 +1,28 @@ +// +build OMIT + +package main + +import ( + "fmt" + "log" + "net/http" + "net/http/httptrace" +) + +func trace() { + // START OMIT + req, _ := http.NewRequest("GET", "http://example.com", nil) + trace := &httptrace.ClientTrace{ + DNSDone: func(dnsInfo httptrace.DNSDoneInfo) { + fmt.Printf("DNS Info: %+v\n", dnsInfo) + }, + GotConn: func(connInfo httptrace.GotConnInfo) { + fmt.Printf("Got Conn: %+v\n", connInfo) + }, + } + req = req.WithContext(httptrace.WithClientTrace(req.Context(), trace)) + if _, err := http.DefaultTransport.RoundTrip(req); err != nil { + log.Fatal(err) + } + // STOP OMIT +} |