Star us on GitHub


Learn how to set up on your Go gqlgen backend.
Add `tracingOrigins` to your client 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', ''], networkRecording: { enabled: true, recordHeadersAndBody: true, }, });
Install the Highlight Go SDK.

Install the highlight-go package with go get.

go get -u
Initialize the Highlight Go SDK.

highlight.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 ( "" ) func main() { // ... highlight.SetProjectID("<YOUR_PROJECT_ID>") highlight.Start( highlight.WithServiceName("my-app"), highlight.WithServiceVersion("git-sha"), ) defer highlight.Stop() // ... }
Add the Highlight gqlgen error handler.

highlight.NewGraphqlTracer provides a middleware you can add to your GraphQL handler to automatically record and send GraphQL resolver errors to Highlight. Calling .WithRequestFieldLogging() will also emit highlight logs for each graphql operation, giving you a wayto search across all graphql requests to your backend.

import ( "" ) func main() { // ... server := handler.New(...) // call with WithRequestFieldLogging() to emit highlight logs for each graphql operation // useful for tracing which graphql operations are called as part of which frontend sessions server.Use(highlight.NewGraphqlTracer("your-backend-service-name").WithRequestFieldLogging()) // capture panics emitted by graphql handlers in highlight server.SetRecoverFunc(highlight.GraphQLRecoverFunc()) // format logs on errors thrown by your graphql handlers server.SetErrorPresenter(highlight.GraphQLErrorPresenter("my-gql-service")) // ... }
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"))
Verify your errors are being recorded.

Now that you've set up the Middleware, verify that the backend error handling works by consuming an error from your handler. This is as easy as having a route handler return an error.

Set up logging.

Start sending logs to Highlight! Follow the logging setup guide to get started.