instahttprouter

package module
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: MIT Imports: 4 Imported by: 1

README

Instana instrumentation for github.com/julienschmidt/httprouter

This module contains middleware to instrument HTTP services written with github.com/julienschmidt/httprouter.

GoDoc

Installation

To add the module to your go.mod file run the following command in your project directory:

$ go get github.com/instana/go-sensor/instrumentation/instahttprouter

Usage

// Create a sensor
sensor := instana.NewSensor("my-web-server")

// Create router and wrap it with Instana
r := instahttprouter.Wrap(httprouter.New(), sensor)

// Define handlers
r.GET("/foo", func(writer http.ResponseWriter, request *http.Request, params httprouter.Params) {})
r.Handle(http.MethodPost, "/foo/:id", func(writer http.ResponseWriter, request *http.Request, params httprouter.Params) {})

// There is no need to additionally instrument your handlers with instana.TracingHandlerFunc(), since
// the instrumented router takes care of this during the registration process.
r.HandlerFunc(http.MethodDelete, "/foo/:id", func(writer http.ResponseWriter, request *http.Request) {})

// ...

Full example

Documentation

Index

Constants

View Source
const Version = "1.13.0"

Version is the instrumentation module semantic version

Variables

This section is empty.

Functions

This section is empty.

Types

type WrappedRouter added in v1.1.0

type WrappedRouter struct {
	*httprouter.Router
	// contains filtered or unexported fields
}

func Wrap

Wrap returns an instrumented instance of a httprouter.Router that instruments HTTP handlers with Instana upon registration.

func (*WrappedRouter) DELETE added in v1.1.0

func (r *WrappedRouter) DELETE(path string, handle httprouter.Handle)

DELETE is a shortcut for router.Handle(http.MethodDelete, path, handle)

func (*WrappedRouter) GET added in v1.1.0

func (r *WrappedRouter) GET(path string, handle httprouter.Handle)

GET is a shortcut for router.Handle(http.MethodGet, path, handle)

func (*WrappedRouter) HEAD added in v1.1.0

func (r *WrappedRouter) HEAD(path string, handle httprouter.Handle)

HEAD is a shortcut for router.Handle(http.MethodHead, path, handle)

func (*WrappedRouter) Handle added in v1.1.0

func (r *WrappedRouter) Handle(method, path string, handle httprouter.Handle)

Handle instruments and registers a new request handle with the given path and method.

For details please refer to the (*httprouter.Router).Handle() documentation: https://pkg.go.dev/github.com/julienschmidt/httprouter#Router.Handle

func (*WrappedRouter) Handler added in v1.1.0

func (r *WrappedRouter) Handler(method, path string, handler http.Handler)

Handler is an adapter which allows the usage of an uninstrumented http.Handler as a request handle. The Params are available in the request context under ParamsKey.

func (*WrappedRouter) HandlerFunc added in v1.1.0

func (r *WrappedRouter) HandlerFunc(method, path string, handler http.HandlerFunc)

HandlerFunc is an adapter which allows the usage of an uninstrumented http.HandlerFunc as a request handle.

func (*WrappedRouter) OPTIONS added in v1.1.0

func (r *WrappedRouter) OPTIONS(path string, handle httprouter.Handle)

OPTIONS is a shortcut for router.Handle(http.MethodOptions, path, handle)

func (*WrappedRouter) PATCH added in v1.1.0

func (r *WrappedRouter) PATCH(path string, handle httprouter.Handle)

PATCH is a shortcut for router.Handle(http.MethodPatch, path, handle)

func (*WrappedRouter) POST added in v1.1.0

func (r *WrappedRouter) POST(path string, handle httprouter.Handle)

POST is a shortcut for router.Handle(http.MethodPost, path, handle)

func (*WrappedRouter) PUT added in v1.1.0

func (r *WrappedRouter) PUT(path string, handle httprouter.Handle)

PUT is a shortcut for router.Handle(http.MethodPut, path, handle)

Jump to

Keyboard shortcuts

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