SDK for instrumenting Go applications for AWS X-Ray
More information about AWS X-Ray can be found at the product website.
The outbound request is traced
import "github.com/goguardian/aws-xray-go/xray"
func main() {
ctx := xray.NewContext("service-name", nil)
defer xray.Close(ctx)
http := xray.GetHTTPClient(ctx)
http.Get("http://127.0.0.1:3000")
}
All inbound requests will be traced
import (
"log"
"net/http"
"github.com/goguardian/aws-xray-go/xray"
)
func main() {
http.HandleFunc("/", xray.Middleware("service-name", handler))
http.ListenAndServe(":3000", nil)
}
func handler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("hiya"))
}
The sampling configuration can be modified using xray.SetSampler
. The default settings are to sample all of the first ten requests of any second and five percent of all other requests that second.
import "github.com/goguardian/aws-xray-go/xray"
func example() {
fixedTarget := 10 // First ten requests per second
fallbackRate := 0.05 // Five percent of all other requests
xray.SetSampler(fixedTarget, fallbackRate)
}