Ashkar for Go
Connect the SDK to your Go service and send your first event.
Ready in: About 6 minutes1. Add the module
Run this from the root of your Go module.
go get github.com/ashkarhq/ashkar/packages/go-sdk2. Connect Ashkar to your service
Create one client when the service starts and close it during shutdown.
package main
import (
"log"
"os"
ashkar "github.com/ashkarhq/ashkar/packages/go-sdk"
)
func main() {
client, err := ashkar.New(ashkar.Config{
ProjectKey: os.Getenv("ASHKAR_SERVER_KEY"),
Endpoint: "https://app.ashkarhq.ir",
Environment: "production",
Release: "api@1.0.0",
StartWorker: true,
})
if err != nil {
log.Fatal(err)
}
defer client.Close()
// Start your service here.
}3. Send a test error
Capture a test message and finish delivery before the program exits.
package main
import (
"fmt"
"log"
"os"
"time"
ashkar "github.com/ashkarhq/ashkar/packages/go-sdk"
)
func main() {
client, err := ashkar.New(ashkar.Config{
ProjectKey: os.Getenv("ASHKAR_SERVER_KEY"),
})
if err != nil {
log.Fatal(err)
}
defer client.Close()
eventID := client.CaptureMessage("Ashkar Go test", "error")
if !client.Flush(2 * time.Second) {
log.Fatal("Ashkar test event was not sent")
}
fmt.Println(eventID)
}4. Check the result in Issues
Look for “Ashkar Go test” in the project. You can now add CaptureError or your framework middleware.
Your project should be connected now.
Open Issues and confirm the test error arrived. You can add the rest when you need it.