Star us on GitHub
Star
Menu

gorilla mux Quick Start

Learn how to set up highlight.io monitoring on your Go gorilla/mux backend.

1

Configure client-side Highlight. (optional)

If you're using Highlight on the frontend for your application, make sure you've initialized it correctly and followed the fullstack mapping guide.

2

Install the Highlight Go SDK.

Install the highlight-go package with go get.

go get -u github.com/highlight/highlight/sdk/highlight-go
Copy
3

Initialize the Highlight Go SDK.

highlight.Start starts a goroutine for recording and sending backend traces and errors. Setting your project id lets Highlight record errors for background tasks and processes that aren't associated with a frontend session.

import ( "github.com/highlight/highlight/sdk/highlight-go" ) func main() { // ... highlight.SetProjectID("<YOUR_PROJECT_ID>") highlight.Start( highlight.WithServiceName("my-app"), highlight.WithServiceVersion("git-sha"), ) defer highlight.Stop() // ... }
Copy
4

Add the Highlight gorilla/mux error handler.

H.NewGraphqlTracer provides a middleware you can add to your Golang Mux handler to automatically record and send GraphQL resolver errors to Highlight.

import ( highlightGorillaMux "github.com/highlight/highlight/sdk/highlight-go/middleware/gorillamux" ) func main() { // ... r := mux.NewRouter() r.Use(highlightGorillaMux.Middleware) // ... }
Copy
5

Record custom errors. (optional)

If you want to explicitly send an error to Highlight, you can use the highlight.RecordError method.

highlight.RecordError(ctx, err, attribute.String("key", "value"))
Copy
6

Verify your errors are being recorded.

Make a call to highlight.RecordError to see the resulting error in Highlight.

func TestErrorHandler(w http.ResponseWriter, r *http.Request) { highlight.RecordError(r.Context(), errors.New("a test error is being thrown!")) }
Copy
7

Verify your backend logs are being recorded.

Visit the highlight logs portal and check that backend logs are coming in.

8

Verify your backend traces are being recorded.

Visit the highlight traces portal and check that backend traces are coming in.