negroni

package module
v0.0.0-...-7ebff8f Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: Apache-2.0, BSD-3-Clause Imports: 14 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/DataDog/dd-trace-go/v2/contrib/urfave/negroni"
	"github.com/DataDog/dd-trace-go/v2/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/DataDog/dd-trace-go/v2/contrib/urfave/negroni"
	"github.com/DataDog/dd-trace-go/v2/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.WithService("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 interface {
	// contains filtered or unexported methods
}

Option describes options for the Negroni 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 WithResourceNamer

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

WithResourceNamer specifies a function which will be used to obtain a resource name for a given negroni request, using the request's context.

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