OpenTelemetry Gorilla Mux monitoring [otelmux]

Vladimir Mihailenco
July 30, 2024
2 min read

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 that aims to standardize and simplify the collection, processing, and export of telemetry data from applications and systems.

OpenTelemetry supports multiple programming languages and platforms, making it suitable for a wide range of applications and environments.

OpenTelemetry enables developers to instrument their code and collect telemetry data, which can then be exported to various OpenTelemetry backends or observability platforms for analysis and visualization. Understanding the OpenTelemetry architecture helps developers leverage its full potential with proper instrumentation and data collection strategies.

Gorilla instrumentation

To install otelmux instrumentation:

shell
go get go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux

Usage

You can instrument Gorilla Mux router by installing OpenTelemetry middleware:

go
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 OpenTelemetry APM 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 demo (no login required) or running it locally with Docker. The source code is available on GitHub.

What's next?

With Gorilla Mux instrumentation active, you can monitor HTTP endpoints, track request latencies, and debug distributed traces. For lower-level HTTP monitoring, see net/http instrumentation, or explore Gin for a more opinionated framework.