Monitor Gin performance with OpenTelemetry
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 Gin?
Gin is a lightweight web framework for building web applications and APIs in the Go programming language. It provides a minimalist and fast approach to building web applications, emphasizing simplicity, performance, and ease of use.
Gin's simplicity and performance make it a popular choice for building web applications and APIs in Go. It provides a solid foundation for developing scalable and efficient web services while maintaining a straightforward and intuitive API.
What is OpenTelemetry?
OpenTelemetry is an open source observability framework that helps developers instrument, generate, collect, and export telemetry data from software applications.
OpenTelemetry provides a unified set of APIs, libraries, and instrumentation tools for capturing and transmitting traces, metrics, and logs to effectively monitor and troubleshoot distributed systems.
The primary goal of OpenTelemetry is to provide a standardized and vendor-agnostic approach to instrumenting applications for observability. It aims to simplify the process of collecting telemetry data by providing a single, consistent API and providing integration with various OpenTelemetry backends.
Gin instrumentation
Gin OpenTelemetry instrumentation allows developers to easily add observability to their Gin applications, providing insights into application performance, behavior, and usage patterns.
OpenTelemetry Gin 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"))
Once your Gin application is instrumented with OpenTelemetry and telemetry data is exported, you can use observability tools compatible with your chosen OpenTelemetry backend to visualize distributed traces, analyze performance metrics, and gain insight into the behavior of your application.
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 a DataDog competitor that supports distributed tracing, metrics, and logs. You can use it to monitor applications and troubleshoot issues.
Uptrace comes with an intuitive query builder, rich dashboards, alerting rules with notifications, and integrations for most languages and frameworks.
Uptrace can process billions of spans and metrics on a single server and allows you to monitor your applications at 10x lower cost.
In just a few minutes, you can try Uptrace by visiting the cloud demo (no login required) or running it locally with Docker. The source code is available on GitHub.
What's next?
Next, instrument more operations to get a more detailed picture. Try to prioritize network calls, disk operations, database queries, error and logs.
You can also create your own instrumentations using OpenTelemetry Go Tracing API.