Monitor Gin performance with OpenTelemetry

OpenTelemetry Gin

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?

OpenTelemetryopen in new window 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 tracesopen in new window, metricsopen in new window, and logsopen in new window 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 backendsopen in new window.

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


You can instrument Gin router by installing OpenTelemetry middleware:

import (

router := gin.Default()

Once your Gin application is instrumented with OpenTelemetry and telemetry data is exported, you can use observability tools compatible with your chosen OpenTelemetry backendopen in new window 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 ""

func exampleHandler(c *gin.Context) {
	otelgin.HTML(c, http.StatusOK, indexTmpl, gin.H{
		"foo": "bar",

What is Uptrace?

Uptrace is a DataDog competitoropen in new window that supports distributed tracing, metrics, and logs. You can use it to monitor applications and troubleshoot issues.

Uptrace Overview

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 demoopen in new window (no login required) or running it locally with Dockeropen in new window. The source code is available on GitHubopen in new window.

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 APIopen in new window.

Last Updated: