Documentation ¶
Overview ¶
Package httprouter provides functions to trace the julienschmidt/httprouter package (https://github.com/julienschmidt/httprouter).
Example ¶
package main import ( "fmt" "log" "net/http" "github.com/julienschmidt/httprouter" httptrace "git.proto.group/protoobp/pobp-trace-go/contrib/julienschmidt/httprouter" ) func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { fmt.Fprint(w, "Welcome!\n") } func Hello(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { fmt.Fprintf(w, "hello, %s!\n", ps.ByName("name")) } func main() { router := httptrace.New() router.GET("/", Index) router.GET("/hello/:name", Hello) log.Fatal(http.ListenAndServe(":8080", router)) }
Output:
Example (WithServiceName) ¶
package main import ( "fmt" "log" "net/http" "github.com/julienschmidt/httprouter" httptrace "git.proto.group/protoobp/pobp-trace-go/contrib/julienschmidt/httprouter" ) func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { fmt.Fprint(w, "Welcome!\n") } func Hello(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { fmt.Fprintf(w, "hello, %s!\n", ps.ByName("name")) } func main() { router := httptrace.New(httptrace.WithServiceName("http.router")) router.GET("/", Index) router.GET("/hello/:name", Hello) log.Fatal(http.ListenAndServe(":8080", router)) }
Output:
Example (WithSpanOpts) ¶
package main import ( "fmt" "log" "net/http" "github.com/julienschmidt/httprouter" httptrace "git.proto.group/protoobp/pobp-trace-go/contrib/julienschmidt/httprouter" "git.proto.group/protoobp/pobp-trace-go/pobptrace/ext" "git.proto.group/protoobp/pobp-trace-go/pobptrace/tracer" ) func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { fmt.Fprint(w, "Welcome!\n") } func Hello(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { fmt.Fprintf(w, "hello, %s!\n", ps.ByName("name")) } func main() { router := httptrace.New( httptrace.WithServiceName("http.router"), httptrace.WithSpanOptions( tracer.Tag(ext.SamplingPriority, ext.PriorityUserKeep), ), ) router.GET("/", Index) router.GET("/hello/:name", Hello) log.Fatal(http.ListenAndServe(":8080", router)) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Router ¶
type Router struct { *httprouter.Router // contains filtered or unexported fields }
Router is a traced version of httprouter.Router.
type RouterOption ¶
type RouterOption func(*routerConfig)
RouterOption represents an option that can be passed to New.
func WithAnalytics ¶
func WithAnalytics(on bool) RouterOption
WithAnalytics enables Trace Analytics for all started spans.
func WithAnalyticsRate ¶
func WithAnalyticsRate(rate float64) RouterOption
WithAnalyticsRate sets the sampling rate for Trace Analytics events correlated to started spans.
func WithServiceName ¶
func WithServiceName(name string) RouterOption
WithServiceName sets the given service name for the returned router.
func WithSpanOptions ¶
func WithSpanOptions(opts ...pobptrace.StartSpanOption) RouterOption
WithSpanOptions applies the given set of options to the span started by the router.
Click to show internal directories.
Click to hide internal directories.