Go SDK - net/http & fasthttp
net/http and fasthttp. Requires Go 1.21+.
Install
go get github.com/kohicorp/kohi-goSet your env vars:
KOHI_PROJECT_KEY=pk_your_project_keyKOHI_SECRET_KEY=your_secret_keynet/http
Wrap your mux with kohi.NetHTTPMiddleware(monitor) as the outermost layer.
import kohi "github.com/kohicorp/kohi-go"
monitor, err := kohi.New(kohi.Config{ ProjectKey: os.Getenv("KOHI_PROJECT_KEY"), SecretKey: os.Getenv("KOHI_SECRET_KEY"),})if err != nil { log.Fatal(err) }defer monitor.Close()
mux := http.NewServeMux()// add your routes...http.ListenAndServe(":8080", kohi.NetHTTPMiddleware(monitor)(mux))fasthttp
Wrap your handler with kohi.FastHTTPMiddleware(monitor) as the outermost layer.
import kohi "github.com/kohicorp/kohi-go"
monitor, err := kohi.New(kohi.Config{ ProjectKey: os.Getenv("KOHI_PROJECT_KEY"), SecretKey: os.Getenv("KOHI_SECRET_KEY"),})if err != nil { log.Fatal(err) }defer monitor.Close()
handler := kohi.FastHTTPMiddleware(monitor)(yourHandler)fasthttp.ListenAndServe(":8080", handler)Error tracking
Panics and 5xx responses are captured automatically by both middlewares. Panics are re-raised after capture so your recovery middleware still works.
To capture errors manually:
if err := doSomething(); err != nil { monitor.CaptureException(err)}CaptureException(err error) records the error type, message, and a full stack trace. Both middlewares also auto-capture 5xx responses.
See configuration reference for all available options, security & privacy for redacted fields, or troubleshooting if something isn’t working.