chi

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2024 License: Apache-2.0, BSD-3-Clause, Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package chi provides tracing functions for tracing the go-chi/chi package (https://github.com/go-chi/chi).

Example
package main

import (
	"net/http"

	chitrace "github.com/0angelic0/dd-trace-go/contrib/go-chi/chi"
	"github.com/0angelic0/dd-trace-go/ddtrace/tracer"

	"github.com/go-chi/chi"
)

func handler(w http.ResponseWriter, _ *http.Request) {
	w.Write([]byte("Hello World!\n"))
}

func main() {
	// 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)
package main

import (
	"net/http"

	chitrace "github.com/0angelic0/dd-trace-go/contrib/go-chi/chi"
	"github.com/0angelic0/dd-trace-go/ddtrace/tracer"

	"github.com/go-chi/chi"
)

func handler(w http.ResponseWriter, _ *http.Request) {
	w.Write([]byte("Hello World!\n"))
}

func main() {
	// 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

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 func(*config)

Option represents an option that can be passed to NewRouter.

func WithAnalytics

func WithAnalytics(on bool) Option

WithAnalytics enables Trace Analytics for all started spans.

func WithAnalyticsRate

func WithAnalyticsRate(rate float64) Option

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

func WithHeaderTags

func WithHeaderTags(headers []string) Option

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

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

func WithResourceNamer

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

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

func WithServiceName

func WithServiceName(name string) Option

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

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

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