Documentation ¶
Overview ¶
Package chi provides tracing functions for tracing the go-chi/chi/v5 package (https://github.com/go-chi/chi).
Example ¶
// 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) ¶
// 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 ¶
- func Middleware(opts ...Option) func(next http.Handler) http.Handler
- type Option
- func WithAnalytics(on bool) Option
- func WithAnalyticsRate(rate float64) Option
- func WithHeaderTags(headers []string) Option
- func WithIgnoreRequest(fn func(r *http.Request) bool) Option
- func WithModifyResourceName(fn func(resourceName string) string) Option
- func WithNoAppsec(disabled bool) Option
- func WithResourceNamer(fn func(r *http.Request) string) Option
- func WithResponseHeaderCopier(f func(http.ResponseWriter) http.Header) Option
- func WithServiceName(name string) Option
- func WithSpanOptions(opts ...ddtrace.StartSpanOption) Option
- func WithStatusCheck(fn func(statusCode int) bool) Option
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 WithHeaderTags ¶ added in v1.53.0
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.36.0
WithIgnoreRequest specifies a function to use for determining if the incoming HTTP request tracing should be skipped.
func WithModifyResourceName ¶ added in v1.48.0
WithModifyResourceName specifies a function to use to modify the resource name.
func WithNoAppsec ¶ added in v1.63.0
WithNoAppsec opts this router out of AppSec management. This allows a particular router to bypass appsec, while the rest of the application is still being monitored/managed. This has not effect if AppSec is not enabled globally (e.g, via the DD_APPSEC_ENABLED environment variable).
func WithResourceNamer ¶ added in v1.52.0
WithResourceNamer specifies a function to use for determining the resource name of the span.
func WithResponseHeaderCopier ¶ added in v1.63.0
func WithResponseHeaderCopier(f func(http.ResponseWriter) http.Header) Option
WithResponseHeaderCopier provides a function to fetch the response headers from the http.ResponseWriter. This allows for custom implementations as needed if you over-ride the default http.ResponseWriter, such as to add synchronization. Provided functions may elect to return a copy of the http.Header map instead of a reference to the original (e.g: to not risk breaking synchronization). This is currently only used by AppSec.
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.