Go SDK

Error tracking SDK for Go applications.

Go 1.18+

Installation

go get github.com/hymns/alertiqo-go

Basic Setup

package main

import (
    "github.com/hymns/alertiqo-go"
)

func main() {
    client := alertiqo.New(alertiqo.Config{
        APIKey:      "your-api-key",
        Endpoint:    "https://alertiqo.io",
        Environment: "production",
        Release:     "1.0.0",
    })

    client.Init()

    // Your application code...
}

Usage

Capture Exceptions

err := someFunction()
if err != nil {
    client.CaptureException(err)
}

Capture Messages

client.CaptureMessage("User completed checkout", "info")

Add Breadcrumbs

client.AddBreadcrumb(
    "User clicked button",
    "user-action",
    "info",
    map[string]interface{}{"buttonId": "submit-btn"},
)

Set User Context

client.SetUser(&alertiqo.User{
    ID:       "12345",
    Email:    "[email protected]",
    Username: "johndoe",
})

Set Tags

client.SetTag("page", "checkout")
client.SetTags(map[string]string{
    "feature": "payments",
    "version": "2.1.0",
})

Recover from Panics

func handler() {
    defer client.Recover()
    
    // Code that might panic...
    panic("something went wrong")
}

HTTP Middleware

package main

import (
    "net/http"
    "github.com/hymns/alertiqo-go"
)

func main() {
    client := alertiqo.New(alertiqo.Config{
        APIKey:   "your-api-key",
        Endpoint: "https://alertiqo.io",
    })
    client.Init()

    mux := http.NewServeMux()
    mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        w.Write([]byte("Hello World"))
    })

    // Wrap with middleware
    handler := client.HTTPMiddleware(mux)
    http.ListenAndServe(":8080", handler)
}

Configuration Options

client := alertiqo.New(alertiqo.Config{
    // Required
    APIKey:   "your-api-key",
    Endpoint: "https://alertiqo.io",
    
    // Optional
    Environment:     "production",  // Default: GO_ENV or "production"
    Release:         "1.0.0",
    Tags:            map[string]string{"app": "myapp"},
    CaptureUnhandled: false,        // Auto-capture panics (default: false)
    
    // Filter/modify errors before sending
    BeforeSend: func(report *alertiqo.Report) *alertiqo.Report {
        // Return nil to skip sending
        return report
    },
})

API Reference

Method Description
Init() Initialize error handlers
CaptureException(err, additionalTags...) Capture an exception
CaptureMessage(message, level) Capture a message
AddBreadcrumb(message, category, level, data) Add a breadcrumb
SetUser(user) Set user context
SetTag(key, value) Set a single tag
SetTags(tags) Set multiple tags
Recover() Recover from panics and capture them
HTTPMiddleware(handler) HTTP middleware for panic recovery