Instrumenting Gin with OpenTelemetry


To install otelgin:

go get


You can instrument Gin router by installing OpenTelemetry middleware:

router := gin.Default()

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's next?

Next, instrument more operations, for example, database queries, errors, and logs. You can also learn about OpenTelemetry API to create your own instrumentations.