https://github.com/urjitbhatia/tracer
Annotate a golang http request to trace time taken at various steps
https://github.com/urjitbhatia/tracer
golang http httptracer tracing
Last synced: about 1 month ago
JSON representation
Annotate a golang http request to trace time taken at various steps
- Host: GitHub
- URL: https://github.com/urjitbhatia/tracer
- Owner: urjitbhatia
- License: mit
- Created: 2018-08-10T04:14:55.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-08-10T07:19:48.000Z (almost 8 years ago)
- Last Synced: 2026-05-24T03:33:30.156Z (about 1 month ago)
- Topics: golang, http, httptracer, tracing
- Language: Go
- Size: 8.79 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tracer
Annotate a golang http request to trace time taken at various steps.
Heavily inspired by https://github.com/davecheney/httpstat :)
Note: Just as any other instrumentation tool, don't keep this running in production forever without understanding the cost. If you are doing a lot of requests, this might have some (tiny) impact.
# Usage:
```golang
import "github.com/urjitbhatia/tracer"
req, _ := http.NewRequest(http.MethodGet, "http://golang.org", body)
req, tr = tracer.AsTraceableReq(req)
// ...
resp, err := client.Do(req)
if err != nil {
log.Fatalf("failed to read response: %v", err)
}
body := readResponseBody(req, resp)
resp.Body.Close()
// Important to call this to calculate total time taken, otherwise it will be negative
tr.Finish()
// ..
log.Printlf("Tracer stats: %v", tr)
```
```
2018/08/10 06:23:48 Tracer stats: {"total":1.917301,"dnsLookup":0.526224, "tcpDialed":0.170330, "connSetup":0.684807, "preTransfer":1.211031, "ttfb":1.917138, "serverProcessing":0.706107, "contentTransfer":0.000162}
```
##### If you see bugs, please feel free to post issues.