gorilla mux
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,
},
});
Install the highlight-go
package with go get
.
go get -u github.com/highlight/highlight/sdk/highlight-go
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()
// ...
}
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)
// ...
}
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"))
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!"))
}
Start sending logs to Highlight! Follow the logging setup guide to get started.