pphttprouter

package module
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

README

pphttprouter

This package instruments the julienschmidt/httprouter package.

Installation

$ go get github.com/pinpoint-apm/pinpoint-go-agent/plugin/httprouter
import "github.com/pinpoint-apm/pinpoint-go-agent/plugin/httprouter"

Usage

PkgGoDev

This package instruments inbound requests handled by a httprouter.Router. Use New() to trace all handlers:

r := pphttprouter.New()
r.GET("/", Index)

Use WrapHandle to select the handlers you want to track:

r := httprouter.New()
r.GET("/hello/:name", pphttprouter.WrapHandle(hello))

For each request, a pinpoint.Tracer is stored in the request context. By using the pinpoint.FromContext function, this tracer can be obtained in your handler. Alternatively, the context of the request may be propagated where the context that contains the pinpoint.Tracer is required.

import (
    "github.com/julienschmidt/httprouter"
    "github.com/pinpoint-apm/pinpoint-go-agent"
    "github.com/pinpoint-apm/pinpoint-go-agent/plugin/httprouter"
)

func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
    tracer := pinpoint.FromContext(r.Context())
    func() {
        defer tracer.NewSpanEvent("func_1").EndSpanEvent()
        time.Sleep(1 * time.Second)
    }()

    fmt.Fprint(w, "Welcome!\n")
}

func main() {
    ... //setup agent

    router := pphttprouter.New()
    router.GET("/", Index)
    http.ListenAndServe(":8000", router)
}

Full Example Source

This package supports URL Statistics feature. It aggregates response times, successes and failures for each router pattern. But, WrapHandle function doesn't support URL Statistics feature.

Config Options

Documentation

Overview

Package pphttprouter instruments the julienschmidt/httprouter package (https://github.com/julienschmidt/httprouter).

This package instruments inbound requests handled by a httprouter.Router. Use New() to trace all handlers:

r := pphttprouter.New()
r.GET("/", Index)
r.GET("/hello/:name", Hello)

Use WrapHandle to select the handlers you want to track:

r := httprouter.New()
r.GET("/", Index)
r.GET("/hello/:name", pphttprouter.WrapHandle(hello))

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WrapHandle

func WrapHandle(handler httprouter.Handle) httprouter.Handle

WrapHandle wraps the given httprouter handler and adds the pinpoint.Tracer to the request's context. By using the pinpoint.FromContext function, this tracer can be obtained.

Types

type Router

type Router struct {
	*httprouter.Router
}

func New

func New() *Router

New returns a new Router which will instrument all added httprouter.Router handlers.

func (*Router) DELETE

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

func (*Router) GET

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

func (*Router) HEAD

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

func (*Router) Handle

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

func (*Router) Handler

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

func (*Router) HandlerFunc

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

func (*Router) OPTIONS

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

func (*Router) PATCH

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

func (*Router) POST

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

func (*Router) PUT

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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