Go SDK
Go SDK
A client and an slog handler.
Install
go get github.com/logstreem/logstreem-gopackage main
import (
"context"
"os"
"github.com/logstreem/logstreem-go"
)
func main() {
client, err := logstreem.New(logstreem.Options{
Token: os.Getenv("LOGSTREEM_TOKEN"),
Dataset: "api-gateway-prod",
})
if err != nil {
panic(err)
}
defer client.Close() // flushes
client.Log(map[string]any{
"level": "error",
"service": "checkout",
"status": 503,
"latency": 3814,
})
res, err := client.Query(context.Background(), `
['api-gateway-prod']
| where status >= 500
| summarize errors = count() by service
`)
if err != nil {
panic(err)
}
for _, row := range res.Rows {
println(row["service"].(string))
}
}defer Close() is not optional
Close() flushes the buffer. Without it, a short-lived process — a job, a Lambda, a CLI — exits with its events still in memory.