Documentation ¶
Overview ¶
Package chi provides tracing functions for tracing the go-chi/chi package (https://github.com/go-chi/chi).
Example ¶
package main import ( "net/http" "github.com/go-chi/chi" chitrace "github.com/gdfragoso/dd-trace-go/contrib/go-chi/chi" "github.com/gdfragoso/dd-trace-go/ddtrace/tracer" ) func handler(w http.ResponseWriter, _ *http.Request) { w.Write([]byte("Hello World!\n")) } func main() { // Start the tracer tracer.Start() defer tracer.Stop() // Create a chi Router router := chi.NewRouter() // Use the tracer middleware with the default service name "chi.router". router.Use(chitrace.Middleware()) // Set up some endpoints. router.Get("/", handler) // And start gathering request traces http.ListenAndServe(":8080", router) }
Output:
Example (WithServiceName) ¶
package main import ( "net/http" "github.com/go-chi/chi" chitrace "github.com/gdfragoso/dd-trace-go/contrib/go-chi/chi" "github.com/gdfragoso/dd-trace-go/ddtrace/tracer" ) func handler(w http.ResponseWriter, _ *http.Request) { w.Write([]byte("Hello World!\n")) } func main() { // Start the tracer tracer.Start() defer tracer.Stop() // Create a chi Router router := chi.NewRouter() // Use the tracer middleware with your desired service name. router.Use(chitrace.Middleware(chitrace.WithServiceName("chi-server"))) // Set up some endpoints. router.Get("/", handler) // And start gathering request traces http.ListenAndServe(":8080", router) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Option ¶
type Option func(*config)
Option represents an option that can be passed to NewRouter.
func WithAnalytics ¶
WithAnalytics enables Trace Analytics for all started spans.
func WithAnalyticsRate ¶
WithAnalyticsRate sets the sampling rate for Trace Analytics events correlated to started spans.
func WithIgnoreRequest ¶
WithIgnoreRequest specifies a function to use for determining if the incoming HTTP request tracing should be skipped.
func WithServiceName ¶
WithServiceName sets the given service name for the router.
func WithSpanOptions ¶
func WithSpanOptions(opts ...ddtrace.StartSpanOption) Option
WithSpanOptions applies the given set of options to the spans started by the router.
func WithStatusCheck ¶
WithStatusCheck specifies a function fn which reports whether the passed statusCode should be considered an error.