Monitor Gorilla Mux with OpenTelemetry
gorilla/mux implements a request router and dispatcher for matching incoming requests to their respective handler. It one of the oldest and most popular routers for Golang.
This article explains how you can monitor and optimize Gorilla Mux performance using OpenTelemetry observability framework.
What is OpenTelemetry?
OpenTelemetry is an open-source observability framework for distributed tracing (including logs and errors) and OpenTelemetry metrics.
Otel allows developers 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, here is a list popular DataDog alternatives that support OpenTelemetry.
OpenTelemetry is available for most programming languages and provides interoperability across different languages and environments.
Gorilla instrumentation
To install Gorilla Mux OpenTelemetry instrumentation:
go get go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux
Usage
You can instrument Gorilla Mux router by installing OpenTelemetry middleware:
import (
"github.com/gorilla/mux"
"go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux"
)
router := mux.NewRouter()
router.Use(otelmux.Middleware("service-name"))
What is Uptrace?
Uptrace is an open source APM for OpenTelemetry with an intuitive query builder, rich dashboards, automatic alerts, and integrations for most languages and frameworks.
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: