ppchi

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: 4 Imported by: 0

README

ppchi

This package instruments the go-chi/chi package.

Installation

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

Usage

PkgGoDev

This package instruments inbound requests handled by a chi.Router. Register the Middleware as the middleware of the router to trace all handlers:

r := chi.NewRouter()
r.Use(ppchi.Middleware())

Use WrapHandler or WrapHandlerFunc to select the handlers you want to track:

r.Get("/hello", ppchi.WrapHandlerFunc(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 (
    "net/http"

    "github.com/go-chi/chi"
    "github.com/pinpoint-apm/pinpoint-go-agent"
    "github.com/pinpoint-apm/pinpoint-go-agent/plugin/chi"
)

func hello(w http.ResponseWriter, r *http.Request) {
    io.WriteString(w, "hello world")
}

func main() {
    ... //setup agent
	
    r := chi.NewRouter()
    r.Use(ppchi.Middleware())
    
    r.Get("/hello", hello)
    http.ListenAndServe(":8000", r)
}

Full Example Source

This package supports URL Statistics feature. It aggregates response times, successes and failures for each router pattern.

Config Options

Documentation

Overview

Package ppchi instruments the go-chi/chi package (https://github.com/go-chi/chi).

This package instruments inbound requests handled by a chi.Router. Register the Middleware as the middleware of the router to trace all handlers:

r := chi.NewRouter()
r.Use(ppchi.Middleware())

Use WrapHandler or WrapHandlerFunc to select the handlers you want to track:

r.Get("/hello", ppchi.WrapHandlerFunc(hello))

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware() func(http.Handler) http.Handler

Middleware returns a chi middleware that creates a pinpoint.Tracer that instruments the http handler.

func WrapHandler

func WrapHandler(handler http.Handler) http.Handler

WrapHandler wraps the given http handler.

func WrapHandlerFunc

func WrapHandlerFunc(f func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request)

WrapHandlerFunc wraps the given http handler function.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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