negroni

package
v1.40.1 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2022 License: Apache-2.0, BSD-3-Clause, Apache-2.0 Imports: 11 Imported by: 0

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 "gopkg.in/DataDog/dd-trace-go.v1/contrib/urfave/negroni"
	"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/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 "gopkg.in/DataDog/dd-trace-go.v1/contrib/urfave/negroni"
	"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/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

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
}

DatadogMiddleware returns middleware that will trace incoming requests.

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

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 WithResourceNamer

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

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

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