negroni

package
v1.59.5 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2024 License: Apache-2.0, BSD-3-Clause, Apache-2.0 Imports: 15 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"

	negronitrace "github.com/nowfred/dd-trace-go/contrib/urfave/negroni"
	"github.com/nowfred/dd-trace-go/ddtrace/tracer"

	"github.com/urfave/negroni"
)

func handler(w http.ResponseWriter, _ *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"

	negronitrace "github.com/nowfred/dd-trace-go/contrib/urfave/negroni"
	"github.com/nowfred/dd-trace-go/ddtrace/tracer"

	"github.com/urfave/negroni"
)

func handler(w http.ResponseWriter, _ *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 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 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