mux

package
v1.74.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2025 License: Apache-2.0, BSD-3-Clause, Apache-2.0 Imports: 5 Imported by: 60

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

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Router

type Router = v2.Router

Router registers routes to be matched and dispatches a handler.

func NewRouter

func NewRouter(opts ...RouterOption) *Router

NewRouter returns a new router instance traced with the global tracer.

func WrapRouter added in v1.37.0

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.

type RouterOption

type RouterOption = v2.RouterOption

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.30.0

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.29.0

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.30.0

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

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.

func WithStatusCheck added in v1.73.0

func WithStatusCheck(fn func(statusCode int) bool) RouterOption

WithStatusCheck specifies a function fn which reports whether the passed statusCode should be considered an error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL