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?

OpenTelemetryopen in new window is an open-source observability framework for distributed tracingopen in new window (including logs and errors) and OpenTelemetry metricsopen in new window.

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 alternativesopen in new window 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 APMopen in new window for OpenTelemetry with an intuitive query builder, rich dashboards, automatic alerts, and integrations for most languages and frameworks.

You can get startedopen in new window with Uptrace by downloading a DEB/RPM package or a pre-compiled Go binary.

What's next?

Next, instrumentopen in new window more operations, for example, database queries, errors, and logs. You can also learn about OpenTelemetry Go Tracing APIopen in new window to create your own instrumentations.

Popular instrumentations:

Last Updated: