ppgin

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

ppgin

This package instruments the gin-gonic/gin package.

Installation

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

Usage

PkgGoDev

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

r := gin.Default()
r.Use(ppgin.Middleware())

Use WrapHandler to select the handlers you want to track:

r.GET("/external", ppgin.WrapHandler(extCall))

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.

package main

import (
    "github.com/gin-gonic/gin"
    "github.com/pinpoint-apm/pinpoint-go-agent"
    "github.com/pinpoint-apm/pinpoint-go-agent/plugin/gin"
)

func endpoint(c *gin.Context) {
    c.Writer.WriteString("endpoint")
}

func main() {
    ... //setup agent
	
    router := gin.Default()
    router.Use(ppgin.Middleware())

    router.GET("/endpoint", endpoint)
    router.Run(":8000")
}

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 ppgin instruments the gin-gonic/gin package (https://github.com/gin-gonic/gin).

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

r := gin.Default()
r.Use(ppgin.Middleware())

Use WrapHandler to select the handlers you want to track:

r.GET("/external", ppgin.WrapHandler(extCall))

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware() gin.HandlerFunc

Middleware returns a gin middleware that creates a pinpoint.Tracer that instruments the gin handler function.

func WrapHandler

func WrapHandler(handler gin.HandlerFunc) gin.HandlerFunc

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

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