Documentation ¶
Overview ¶
Package muxtrace provides tracing functions for the Gorilla Mux framework.
Example ¶
package main import ( "fmt" "net/http" "github.com/DataDog/dd-trace-go/tracer" "github.com/DataDog/dd-trace-go/tracer/contrib/gorilla/muxtrace" "github.com/gorilla/mux" ) // handler is a simple handlerFunc that logs some data from the span // that is injected into the requests' context. func handler(w http.ResponseWriter, r *http.Request) { span := tracer.SpanFromContextDefault(r.Context()) fmt.Printf("tracing service:%s resource:%s", span.Service, span.Resource) w.Write([]byte("hello world")) } func main() { router := mux.NewRouter() muxTracer := muxtrace.NewMuxTracer("my-web-app", tracer.DefaultTracer) // Add traced routes directly. muxTracer.HandleFunc(router, "/users", handler) // and subroutes as well. subrouter := router.PathPrefix("/user").Subrouter() muxTracer.HandleFunc(subrouter, "/view", handler) muxTracer.HandleFunc(subrouter, "/create", handler) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetRequestSpan ¶
GetRequestSpan will return the span associated with the given request. It will return nil/false if it doesn't exist.
Types ¶
type MuxTracer ¶
type MuxTracer struct {
// contains filtered or unexported fields
}
MuxTracer is used to trace requests in a mux server.
func NewMuxTracer ¶
NewMuxTracer creates a MuxTracer for the given service and tracer.
func (*MuxTracer) HandleFunc ¶
func (m *MuxTracer) HandleFunc(router *mux.Router, pattern string, handler http.HandlerFunc) *mux.Route
HandleFunc will add a traced version of the given handler to the router.
func (*MuxTracer) TraceHandleFunc ¶
func (m *MuxTracer) TraceHandleFunc(handler http.HandlerFunc) http.HandlerFunc
TraceHandleFunc will return a HandlerFunc that will wrap tracing around the given handler func.
Click to show internal directories.
Click to hide internal directories.