Monitor Gorilla Mux with OpenTelemetry
gorilla/mux implements a request router and dispatcher for matching incoming requests to their respective handler. It is one of the oldest and most popular routers for Golang.
Learn how you to monitor and optimize Gorilla performance using OpenTelemetry Gorilla Mux instrumentation.
What is OpenTelemetry?
OpenTelemetry is an open source observability framework for OpenTelemetry tracing, logs, and metrics.
OpenTelemetry allows developers to collect and export telemetry data in a vendor-agnostic manner. With OpenTelemetry, you can instrument your application once and then add or change vendors without changing the instrumentation, for example, here is a list of popular DataDog competitors that support OpenTelemetry.
OpenTelemetry is available for most programming languages and provides interoperability across different languages and environments.
Gorilla instrumentation
To install otelmux 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 a Grafana alternative 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.