Skip to content

SDK for instrumenting Go applications for AWS X-Ray

License

Notifications You must be signed in to change notification settings

roylee0704/aws-xray-go

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go SDK for AWX X-Ray

SDK for instrumenting Go applications for AWS X-Ray

AWS X-Ray

More information about AWS X-Ray can be found at the product website.

Getting Started

Client Example

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")
}

Server Example

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"))
}

Sampling

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)
}

About

SDK for instrumenting Go applications for AWS X-Ray

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%