Documentation
¶
Overview ¶
Package gin provides functions to trace the gin-gonic/gin package (https://github.com/gin-gonic/gin).
Example ¶
To start tracing requests, add the trace middleware to your Gin router.
package main
import (
gintrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/gin-gonic/gin"
"github.com/gin-gonic/gin"
)
func main() {
// Create a gin.Engine
r := gin.New()
// Use the tracer middleware with your desired service name.
r.Use(gintrace.Middleware("my-web-app"))
// Set up some endpoints.
r.GET("/hello", func(c *gin.Context) {
c.String(200, "hello world!")
})
// And start gathering request traces.
r.Run(":8080")
}
Example (SpanFromContext) ¶
package main
import (
gintrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/gin-gonic/gin"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
r.Use(gintrace.Middleware("image-encoder"))
r.GET("/image/encode", func(c *gin.Context) {
ctx := c.Request.Context()
// create a child span to track operation timing.
encodeSpan, _ := tracer.StartSpanFromContext(ctx, "image.encode")
// encode a image
encodeSpan.Finish()
c.String(200, "ok!")
})
}
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HTML ¶
HTML will trace the rendering of the template as a child of the span in the given context.
Example ¶
package main
import (
gintrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/gin-gonic/gin"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
r.Use(gintrace.Middleware("my-web-app"))
r.LoadHTMLGlob("templates/*")
r.GET("/index", func(c *gin.Context) {
// render the html and trace the execution time.
gintrace.HTML(c, 200, "index.tmpl", gin.H{
"title": "Main website",
})
})
}
func Middleware ¶
func Middleware(service string) gin.HandlerFunc
Middleware returns middleware that will trace incoming requests. The last parameter is optional and can be used to pass a custom tracer.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.