http

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2018 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package http provides functions to trace the net/http package (https://golang.org/pkg/net/http).

Example
package main

import (
	"net/http"

	httptrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/net/http"
)

func main() {
	mux := httptrace.NewServeMux()
	mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("Hello World!\n"))
	})
	http.ListenAndServe(":8080", mux)
}
Output:

Example (WithServiceName)
package main

import (
	"net/http"

	httptrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/net/http"
)

func main() {
	mux := httptrace.NewServeMux(httptrace.WithServiceName("my-service"))
	mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("Hello World!\n"))
	})
	http.ListenAndServe(":8080", mux)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func WrapClient added in v1.4.0

func WrapClient(c *http.Client, opts ...RoundTripperOption) *http.Client

WrapClient modifies the given client's transport to augment it with tracing and returns it.

func WrapHandler added in v1.0.0

func WrapHandler(h http.Handler, service, resource string) http.Handler

WrapHandler wraps an http.Handler with tracing using the given service and resource.

func WrapRoundTripper added in v1.2.0

func WrapRoundTripper(rt http.RoundTripper, opts ...RoundTripperOption) http.RoundTripper

WrapRoundTripper returns a new RoundTripper which traces all requests sent over the transport.

Types

type MuxOption added in v1.0.0

type MuxOption func(*muxConfig)

MuxOption represents an option that can be passed to NewServeMux.

func WithServiceName added in v1.0.0

func WithServiceName(name string) MuxOption

WithServiceName sets the given service name for the returned ServeMux.

type RoundTripperAfterFunc added in v1.2.0

type RoundTripperAfterFunc func(*http.Response, ddtrace.Span)

A RoundTripperAfterFunc can be used to modify a span after an http RoundTrip is made. It is possible for the http Response to be nil.

type RoundTripperBeforeFunc added in v1.2.0

type RoundTripperBeforeFunc func(*http.Request, ddtrace.Span)

A RoundTripperBeforeFunc can be used to modify a span before an http RoundTrip is made.

type RoundTripperOption added in v1.2.0

type RoundTripperOption func(*roundTripperConfig)

A RoundTripperOption represents an option that can be passed to WrapRoundTripper.

func WithAfter added in v1.2.0

WithAfter adds a RoundTripperAfterFunc to the RoundTripper config.

func WithBefore added in v1.2.0

WithBefore adds a RoundTripperBeforeFunc to the RoundTripper config.

type ServeMux

type ServeMux struct {
	*http.ServeMux
	// contains filtered or unexported fields
}

ServeMux is an HTTP request multiplexer that traces all the incoming requests.

func NewServeMux

func NewServeMux(opts ...MuxOption) *ServeMux

NewServeMux allocates and returns an http.ServeMux augmented with the global tracer.

func (*ServeMux) ServeHTTP

func (mux *ServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP dispatches the request to the handler whose pattern most closely matches the request URL. We only need to rewrite this function to be able to trace all the incoming requests to the underlying multiplexer

Directories

Path Synopsis
module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL