Documentation
¶
Overview ¶
Package negroni provides helper functions for tracing the urfave/negroni package (https://github.com/urfave/negroni).
Package negroni provides helper functions for tracing the urfave/negroni package (https://github.com/urfave/negroni).
Example ¶
package main
import (
"net/http"
"github.com/urfave/negroni"
negronitrace "git.proto.group/protoobp/pobp-trace-go/contrib/urfave/negroni"
"git.proto.group/protoobp/pobp-trace-go/pobptrace/tracer"
)
func handler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
w.Write([]byte("Hello World!\n"))
}
func main() {
// Start the tracer
tracer.Start()
defer tracer.Stop()
// Create a negroni Router
n := negroni.New()
// Use the tracer middleware with the default service name "negroni.router".
n.Use(negronitrace.Middleware())
// Set up some endpoints.
mux := http.NewServeMux()
mux.HandleFunc("/", handler)
n.UseHandler(mux)
// And start gathering request traces
http.ListenAndServe(":8080", n)
}
Output:
Example (WithServiceName) ¶
package main
import (
"net/http"
"github.com/urfave/negroni"
negronitrace "git.proto.group/protoobp/pobp-trace-go/contrib/urfave/negroni"
"git.proto.group/protoobp/pobp-trace-go/pobptrace/tracer"
)
func handler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
w.Write([]byte("Hello World!\n"))
}
func main() {
// Start the tracer
tracer.Start()
defer tracer.Stop()
// Create a negroni Router
n := negroni.New()
// Use the tracer middleware with your desired service name.
n.Use(negronitrace.Middleware(negronitrace.WithServiceName("negroni-server")))
// Set up some endpoints.
mux := http.NewServeMux()
mux.HandleFunc("/", handler)
n.UseHandler(mux)
// And start gathering request traces
http.ListenAndServe(":8080", n)
}
Output:
Index ¶
- type DatadogMiddleware
- type Option
- func WithAnalytics(on bool) Option
- func WithAnalyticsRate(rate float64) Option
- func WithResourceNamer(namer func(r *http.Request) string) Option
- func WithServiceName(name string) Option
- func WithSpanOptions(opts ...pobptrace.StartSpanOption) Option
- func WithStatusCheck(fn func(statusCode int) bool) Option
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DatadogMiddleware ¶
type DatadogMiddleware struct {
// contains filtered or unexported fields
}
func Middleware ¶
func Middleware(opts ...Option) *DatadogMiddleware
Middleware create the negroni middleware that will trace incoming requests
func (*DatadogMiddleware) ServeHTTP ¶
func (m *DatadogMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
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 WithResourceNamer ¶
WithResourceNamer specifies a function which will be used to obtain a resource name for a given negroni request, using the request's context.
func WithServiceName ¶
WithServiceName sets the given service name for the router.
func WithSpanOptions ¶
func WithSpanOptions(opts ...pobptrace.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.