Monitor Gin performance with OpenTelemetry
OpenTelemetry Gin allows developers to easily add observability to their Gin applications, providing insights into application performance, behavior, and usage patterns.
Gin is one of the fastest full-featured web frameworks for Go. Gin allows you to build web applications and microservices in Go.
OpenTelemetry Gin can help developers monitor and diagnose issues with their Gin applications, and can provide valuable insights into the behavior of the applications in production.
What is OpenTelemetry?
OpenTelemetry is an open source and vendor-neutral API for OpenTelemetry tracing (including logs and errors) and OpenTelemetry metrics.
Otel specifies how to collect and export telemetry data in a vendor agnostic way. With OpenTelemetry, you can instrument your application once and then add or change vendors without changing the instrumentation, for example, many open source tracing tools already support OpenTelemetry.
OpenTelemetry is available for most programming languages and provides interoperability across different languages and environments.
Gin instrumentation
OpenTelemetry Gin is be easy to use and provides a simple API for instrumenting Gin applications, making it possible for developers to quickly add observability to their applications without having to write a lot of code.
To install otelgin instrumentation:
go get go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin
Usage
You can instrument Gin router by installing OpenTelemetry middleware:
import (
"github.com/gin-gonic/gin"
"go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin"
)
router := gin.Default()
router.Use(otelgin.Middleware("service-name"))
Instrumenting templates rendering
To instrument templates rendering, use otelgin.HTML
helper:
import "go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin"
func exampleHandler(c *gin.Context) {
otelgin.HTML(c, http.StatusOK, indexTmpl, gin.H{
"foo": "bar",
})
}
What is Uptrace?
Uptrace is an open source APM for OpenTelemetry that helps developers pinpoint failures and find performance bottlenecks. Uptrace can process billions of spans on a single server and allows to monitor your software at 10x lower cost.
You can get started with Uptrace by downloading a DEB/RPM package or a pre-compiled Go binary.
What's next?
Next, instrument more operations, for example, database queries, errors, and logs. You can also learn about OpenTelemetry Go Tracing API to create your own instrumentations.
Popular instrumentations:
See also: