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?

OpenTelemetryopen in new window is an open source observability framework for OpenTelemetry tracingopen in new window, logsopen in new window, and metricsopen in new window.

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 competitorsopen 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 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 alternativeopen in new window that supports distributed tracing, metrics, and logs. You can use it to monitor applications and troubleshoot issues.

Uptrace Overview

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 demoopen in new window (no login required) or running it locally with Dockeropen in new window. The source code is available on GitHubopen in new window.

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 APIopen in new window.

Last Updated: