Star us on GitHub
Star
Menu

Golang SDK API Reference

Golang SDK

Highlight's Golang SDK makes it easy to monitor errors and logs on your Golang backend.

Just getting started?

Check out our getting started guide to get up and running quickly.

H.Start()

Starts the background goroutine for transmitting metrics and errors.

H.Start()
Copy

H.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
ctx := context.Background() ... H.startWithContext(ctx)
Copy

H.Stop()

Stop the Highlight client. Does not wait for all un-flushed data to be sent.

H.Stop()
Copy

H.SetProjectID()

Configure your Highlight project ID. See the setup page for your project.

Method Parameters
H.SetProjectID("YOUR_PROJECT_ID")
Copy

H.RecordError()

Record errors thrown in your backend.

Method Parameters
ctx := context.Background() result, err := myOperation(ctx) if err != nil { H.RecordError(ctx, err) }
Copy

H.RecordMetric()

Record metrics from your backend to be visualized in Highlight charts.

Method Parameters
start := time.Now() defer func() { H.RecordMetric( ctx, "my.operation.duration-s", time.Since(start).Seconds(), ) }()
Copy

H.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) }
Copy