Install

Install on Go

Install the Sankofa Go SDK and instrument net/http or any framework with context-aware tracking.

The Sankofa Go SDK lives at github.com/sankofa-hq/sankofa_sdk_go and is imported as sankofacatch. It focuses on Catch — error capture, transactions, profiling — with net/http middleware. Server-side flag and config evaluation is not built in; the SDK accepts optional ReadFlagSnapshot / ReadConfigSnapshot callbacks so captured error events can include flag context.

Requirements

  • Go 1.22+
  • Module-aware project (go.mod present)

1. Add the package

bash
go get github.com/sankofa-hq/sankofa_sdk_go@latest

Verify the import path resolves:

bash
go list -m github.com/sankofa-hq/sankofa_sdk_go

2. Construct a client

The SDK does not use a global singleton by default — you construct a client and inject it where it's needed. This makes it straightforward to use in tests and shared libraries.

Gomain.go
package main

import (
  "context"
  "log"
  "os"

  "github.com/sankofa-hq/sankofa_sdk_go/sankofa"
)

func main() {
  client, err := sankofa.New(sankofa.Config{
      APIKey:      os.Getenv("SANKOFA_KEY"),
      Endpoint:    "https://api.sankofa.dev",
      Release:     os.Getenv("RELEASE_SHA"),
      Environment: os.Getenv("ENV"),
  })
  if err != nil {
      log.Fatalf("sankofa init: %v", err)
  }
  defer client.Close(context.Background())

  // ... start the server
}

client.Close flushes the queue and waits for in-flight uploads — call it from a graceful-shutdown handler so events aren't dropped on exit.

Config options

APIKeystringRequired
Your project's server-side API key.
Endpointstringdefault https://api.sankofa.dev
Server base URL.
Releasestring
Commit SHA or version tag — used to group source-mapped errors.
Environmentstringdefault production
Free-form label (development, staging, production).
FlushIntervaltime.Durationdefault 5s
How often queued events are uploaded.
MaxQueueSizeintdefault 1024
Maximum events queued in memory before dropping.
HTTPClient*http.Client
Override the underlying HTTP client (for proxies, custom TLS, etc.).

3. Wire HTTP middleware

The package exposes a net/http middleware that captures request context (method, path, status) and attaches it to every event emitted while serving the request.

Gomain.go
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  client.Track(r.Context(), sankofa.Event{
      Name: "homepage_visited",
      Properties: map[string]any{"path": r.URL.Path},
  })
  fmt.Fprintln(w, "ok")
})

handler := sankofa.HTTPMiddleware(client)(mux)
http.ListenAndServe(":3000", handler)

The middleware is framework-agnostic — wrap any http.Handler with it. Echo, Gin, Chi, and Fiber all expose adapters that fit the http.Handler shape.

4. Verify the install

Go
client.Track(context.Background(), sankofa.Event{
  Name:       "install_check",
  DistinctID: "test-user",
  Properties: map[string]any{"from": "go-quickstart"},
})

Open app.sankofa.devLive events. Within a few seconds you'll see the event with a go source label and the runtime version captured under default properties.

What's next

Edit this page on GitHub