Gin OpenTelemetry instrumentation example
Quickstart
Install
otelgin
instrumentation:
go get go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin
Then install the OpenTelemetry middleware:
router := gin.Default()
router.Use(otelgin.Middleware("service-name"))
To propagate active span through the app, use context.Context
from the http.Request
(not
gin.Context
). To measure HTML template rendering, use otelgin.HTML
helper.
Example
To run this example:
UPTRACE_DSN="https://<token>@api.uptrace.dev/<project_id>" go run main.go
Then open http://localhost:9999