Documentation ¶
Overview ¶
Package mux provides tracing functions for tracing the gorilla/mux package (https://github.com/gorilla/mux).
Example ¶
package main import ( "net/http" muxtrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/gorilla/mux" ) func handler(w http.ResponseWriter, _ *http.Request) { w.Write([]byte("Hello World!\n")) } func main() { mux := muxtrace.NewRouter() mux.HandleFunc("/", handler) http.ListenAndServe(":8080", mux) }
Output:
Example (WithServiceName) ¶
package main import ( "net/http" muxtrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/gorilla/mux" ) func handler(w http.ResponseWriter, _ *http.Request) { w.Write([]byte("Hello World!\n")) } func main() { mux := muxtrace.NewRouter(muxtrace.WithServiceName("mux.route")) mux.HandleFunc("/", handler) http.ListenAndServe(":8080", mux) }
Output:
Index ¶
- type Router
- type RouterOption
- func NoDebugStack() RouterOption
- func WithAnalytics(on bool) RouterOption
- func WithAnalyticsRate(rate float64) RouterOption
- func WithHeaderTags(headers []string) RouterOption
- func WithIgnoreRequest(f func(*http.Request) bool) RouterOption
- func WithQueryParams() RouterOption
- func WithResourceNamer(namer func(router *Router, req *http.Request) string) RouterOption
- func WithServiceName(name string) RouterOption
- func WithSpanOptions(opts ...ddtrace.StartSpanOption) RouterOption
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Router ¶ added in v1.0.0
Router registers routes to be matched and dispatches a handler.
func NewRouter ¶ added in v1.0.0
func NewRouter(opts ...RouterOption) *Router
NewRouter returns a new router instance traced with the global tracer.
func WrapRouter ¶ added in v1.60.2
func WrapRouter(router *mux.Router, opts ...RouterOption) *Router
WrapRouter returns the given router wrapped with the tracing of the HTTP requests and responses served by the router.
func (*Router) ServeHTTP ¶ added in v1.0.0
func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP dispatches the request to the handler whose pattern most closely matches the request URL. We only need to rewrite this function to be able to trace all the incoming requests to the underlying multiplexer
func (*Router) SkipClean ¶ added in v1.0.0
SkipClean defines the path cleaning behaviour for new routes. The initial value is false. Users should be careful about which routes are not cleaned
When true, if the route path is "/path//to", it will remain with the double slash. This is helpful if you have a route like: /fetch/http://xkcd.com/534/
When false, the path will be cleaned, so /fetch/http://xkcd.com/534/ will become /fetch/http/xkcd.com/534
func (*Router) StrictSlash ¶ added in v1.0.0
StrictSlash defines the trailing slash behavior for new routes. The initial value is false.
When true, if the route path is "/path/", accessing "/path" will perform a redirect to the former and vice versa. In other words, your application will always see the path as specified in the route.
When false, if the route path is "/path", accessing "/path/" will not match this route and vice versa.
The re-direct is a HTTP 301 (Moved Permanently). Note that when this is set for routes with a non-idempotent method (e.g. POST, PUT), the subsequent re-directed request will be made as a GET by most clients. Use middleware or client settings to modify this behaviour as needed.
Special case: when a route sets a path prefix using the PathPrefix() method, strict slash is ignored for that route because the redirect behavior can't be determined from a prefix alone. However, any subrouters created from that route inherit the original StrictSlash setting.
func (*Router) UseEncodedPath ¶ added in v1.0.0
UseEncodedPath tells the router to match the encoded original path to the routes. For eg. "/path/foo%2Fbar/to" will match the path "/path/{var}/to".
If not called, the router will match the unencoded path to the routes. For eg. "/path/foo%2Fbar/to" will match the path "/path/foo/bar/to"
type RouterOption ¶ added in v1.0.0
type RouterOption func(*routerConfig)
RouterOption represents an option that can be passed to NewRouter.
func NoDebugStack ¶ added in v1.24.0
func NoDebugStack() RouterOption
NoDebugStack prevents stack traces from being attached to spans finishing with an error. This is useful in situations where errors are frequent and performance is critical.
func WithAnalytics ¶ added in v1.11.0
func WithAnalytics(on bool) RouterOption
WithAnalytics enables Trace Analytics for all started spans.
func WithAnalyticsRate ¶ added in v1.11.0
func WithAnalyticsRate(rate float64) RouterOption
WithAnalyticsRate sets the sampling rate for Trace Analytics events correlated to started spans.
func WithHeaderTags ¶ added in v1.60.2
func WithHeaderTags(headers []string) RouterOption
WithHeaderTags enables the integration to attach HTTP request headers as span tags. Warning: Using this feature can risk exposing sensitive data such as authorization tokens to Datadog. Special headers can not be sub-selected. E.g., an entire Cookie header would be transmitted, without the ability to choose specific Cookies.
func WithIgnoreRequest ¶ added in v1.60.2
func WithIgnoreRequest(f func(*http.Request) bool) RouterOption
WithIgnoreRequest holds the function to use for determining if the incoming HTTP request tracing should be skipped.
func WithQueryParams ¶ added in v1.60.2
func WithQueryParams() RouterOption
WithQueryParams specifies that the integration should attach request query parameters as APM tags. Warning: using this feature can risk exposing sensitive data such as authorization tokens to Datadog.
func WithResourceNamer ¶ added in v1.24.0
func WithResourceNamer(namer func(router *Router, req *http.Request) string) RouterOption
WithResourceNamer specifies a quantizing function which will be used to obtain the resource name for a given request.
func WithServiceName ¶ added in v1.0.0
func WithServiceName(name string) RouterOption
WithServiceName sets the given service name for the router.
func WithSpanOptions ¶ added in v1.2.1
func WithSpanOptions(opts ...ddtrace.StartSpanOption) RouterOption
WithSpanOptions applies the given set of options to the spans started by the router.