chi

package module
v2.7.4 Latest Latest
Warning

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

Go to latest
Published: May 1, 2026 License: Apache-2.0, BSD-3-Clause Imports: 11 Imported by: 3

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)
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.WithService("chi-server")))

// Set up some endpoints.
router.Get("/", handler)

// And start gathering request traces
http.ListenAndServe(":8080", router)

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(opts ...Option) func(next http.Handler) http.Handler

Middleware returns middleware that will trace incoming requests.

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option describes options for the Chi.v5 integration.

type OptionFn

type OptionFn func(*config)

OptionFn represents options applicable to Middleware.

func WithAnalytics

func WithAnalytics(on bool) OptionFn

WithAnalytics enables Trace Analytics for all started spans.

func WithAnalyticsRate

func WithAnalyticsRate(rate float64) OptionFn

WithAnalyticsRate sets the sampling rate for Trace Analytics events correlated to started spans.

func WithHeaderTags

func WithHeaderTags(headers []string) OptionFn

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

func WithIgnoreRequest(fn func(r *http.Request) bool) OptionFn

WithIgnoreRequest specifies a function to use for determining if the incoming HTTP request tracing should be skipped.

func WithModifyResourceName

func WithModifyResourceName(fn func(resourceName string) string) OptionFn

WithModifyResourceName specifies a function to use to modify the resource name.

func WithNoAppsec

func WithNoAppsec(disabled bool) OptionFn

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

func WithResourceNamer(fn func(r *http.Request) string) OptionFn

WithResourceNamer specifies a function to use for determining the resource name of the span.

func WithResponseHeaderCopier

func WithResponseHeaderCopier(f func(http.ResponseWriter) http.Header) OptionFn

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 WithService

func WithService(name string) OptionFn

WithService sets the given service name for the router.

func WithSpanOptions

func WithSpanOptions(opts ...tracer.StartSpanOption) OptionFn

WithSpanOptions applies the given set of options to the spans started by the router.

func WithStatusCheck

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

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