Go SDK API Reference
Go SDK
Highlight's Go SDK makes it easy to monitor errors and logs on your Go backend.
Just getting started?
Check out our getting started guide to get up and running quickly.
highlight.Start()
Starts the background goroutine for transmitting metrics and errors.
Options
highlight.Start(
highlight.WithProjectID("<YOUR_PROJECT_ID>"),
highlight.WithSamplingRate(1.),
highlight.WithServiceName("my-app"),
highlight.WithServiceVersion("git-sha"),
highlight.WithEnvironment(util.EnvironmentName()),
)
highlight.StartWithContext()
StartWithContext is used to start the Highlight client's collection service, but allows the user to pass in their own context.Context. This allows the user kill the highlight worker by canceling their context.CancelFunc.
Method Parameters
Options
ctx := context.Background()
...
highlight.startWithContext(ctx,
highlight.WithServiceName("my-app"),
highlight.WithServiceVersion("git-sha"),
)
highlight.Stop()
Stop the Highlight client. Does not wait for all un-flushed data to be sent.
highlight.Stop()
highlight.SetProjectID()
Configure your Highlight project ID. See the setup page for your project.
Method Parameters
highlight.SetProjectID("<YOUR_PROJECT_ID>")
highlight.RecordError()
Record errors thrown in your backend.
Method Parameters
ctx := context.Background()
result, err := myOperation(ctx)
if err != nil {
highlight.RecordError(ctx, err)
}
highlight.RecordMetric()
Record metrics from your backend to be visualized in Highlight charts.
Method Parameters
start := time.Now()
defer func() {
highlight.RecordMetric(
ctx, "my.operation.duration-s", time.Since(start).Seconds(),
)
}()
highlight.InterceptRequest()
Called under the hood by our middleware web backend handlers to extract the request context. Use this if you are using the raw http server package and need to setup the Highlight context.
Method Parameters
func Middleware(next http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
ctx := highlight.InterceptRequest(r)
r = r.WithContext(ctx)
highlight.MarkBackendSetup(r.Context())
next.ServeHTTP(w, r)
}
return http.HandlerFunc(fn)
}
highlight.NewGraphqlTracer()
An http middleware for tracing GraphQL servers.
Configuration
import ghandler "github.com/99designs/gqlgen/graphql/handler"
privateServer := ghandler.New(privategen.NewExecutableSchema(...)
server.Use(highlight.NewGraphqlTracer(string(util.PrivateGraph)).WithRequestFieldLogging())
highlight.GraphQLRecoverFunc()
A gqlgen recover function to capture panics.
Configuration
import ghandler "github.com/99designs/gqlgen/graphql/handler"
privateServer := ghandler.New(privategen.NewExecutableSchema(...)
server.SetRecoverFunc(highlight.GraphQLRecoverFunc())
highlight.GraphQLErrorPresenter()
A gqlgen error presenter.
Configuration
import ghandler "github.com/99designs/gqlgen/graphql/handler"
privateServer := ghandler.New(privategen.NewExecutableSchema(...)
privateServer.SetErrorPresenter(highlight.GraphQLErrorPresenter("private"))