Documentation Go SDK
5 min read | June 24, 2026
Tutorial

Go SDK

Astralog’s Go SDK is built for high-performance and high-concurrency systems. It uses a non-blocking background worker and a Fail-Open architecture that protects your server’s RAM if the network is saturated.

View on GitHub

Installation

Install the package via go get:

go get github.com/astralog-cloud/astralog-go

Initialization

Initialize the client once in your main.go. It automatically spawns a background worker that flushes events asynchronously.

// main.go
package main

import "github.com/astralog-cloud/astralog-go"

func main() {
    client, _ := astralog.NewClient(astralog.Config{
        APIKey: "ast_sk_live_xxxxxxxxxxxxx",
    })
    
    // Ensures remaining events are sent before process exit
    defer client.Close()

    // Your code here...
}

Logging API Reference

All logging methods accept a message string and an optional map[string]interface{} for structured metadata.

1. client.Info()

Use for general system events, successful actions, or checkpoints.

client.Info("User logged in", map[string]interface{}{
    "user_id": "usr_99283",
    "ip": "192.168.1.1",
})

2. client.Warn()

Use for non-fatal issues, retries, or rate limits approaching.

client.Warn("Rate limit approaching", map[string]interface{}{
    "tenant_id": "org_123",
    "remaining_quota": 5,
})

3. client.Error()

Use for exceptions, fatal crashes, or 5xx HTTP responses.

client.Error("Database connection failed", map[string]interface{}{
    "db_host": "10.0.0.5",
    "error_msg": err.Error(),
})

4. client.Debug()

Use for verbose information that helps during active development or deep troubleshooting.

client.Debug("Cache miss, querying DB", map[string]interface{}{
    "cache_key": "user_profile_99283",
    "latency_ms": 12.4,
})

5. client.Event()

The underlying raw method. Allows you to specify custom event levels dynamically.

client.Event("critical", "System overheating", map[string]interface{}{
    "temperature": 95,
})

Distributed Tracing

Astralog automatically promotes the trace_id property. If you include it in your metadata, ClickHouse will index it for instantaneous multi-service correlation.

client.Info("Processing payment", map[string]interface{}{
    "trace_id": "req-8f72-11a9",
    "amount": 49.99,
})