Backend: Error Monitoring
Go
JS
Python
Backend: Logging
Fullstack Frameworks
Next.JS
Self Host & Local Dev
Menu
chi
Learn how to set up highlight.io on your Go chi backend.
1
Set up your frontend Highlight snippet.
This backend SDK requires one of the Highlight frontend SDKs to be installed, so please make sure you've followed the fullstack mapping guide first.
H.init("<YOUR_PROJECT_ID>", {
tracingOrigins: ['localhost', 'example.myapp.com/backend'],
networkRecording: {
enabled: true,
recordHeadersAndBody: true,
},
});
2
Install the Highlight Go SDK.
Install the highlight-go
package with go get
.
go get -u github.com/highlight/highlight/sdk/highlight-go
3
Initialize the Highlight Go SDK.
H.Start
starts a goroutine for recording and sending backend errors. Setting your project id lets Highlight record errors for background tasks and processes that aren't associated with a frontend session.
import (
H "github.com/highlight/highlight/sdk/highlight-go"
)
func main() {
// ...
H.SetProjectID("<YOUR_PROJECT_ID>")
H.Start()
defer H.Stop()
// ...
}
4
Add the Highlight middleware.
highlightChi.Middleware
is a Go Chi compatible middleware.
import (
highlightChi "github.com/highlight/highlight/sdk/highlight-go/middleware/chi"
)
func main() {
// ...
r := chi.NewRouter()
r.Use(highlightChi.Middleware)
// ...
}
5
Record custom errors. (optional)
If you want to explicitly send an error to Highlight, you can use the H.RecordError
method.
H.RecordError(ctx, err, attribute.String("key", "value"))
6
Verify your errors are being recorded.
Make a call to H.RecordError
to see the resulting error in Highlight.
func TestErrorHandler(w http.ResponseWriter, r *http.Request) {
H.RecordError(r.Context(), errors.New("a test error is being thrown!"))
}
7
Set up logging.
Start sending logs to Highlight! Follow the logging setup guide to get started.