Configuration
Customize SDK behavior with configuration options.
All Options
import statly "github.com/KodyDennon/statly-go"
statly.Init(statly.Options{
// Required
DSN: "https://[email protected]/your-org",
// Optional
Environment: "production", // Environment name
Release: "1.2.3", // App version
Debug: false, // Enable debug logging
SampleRate: 1.0, // 0.0-1.0, event sampling
MaxBreadcrumbs: 100, // Max breadcrumbs stored
ServerName: "", // Server identifier (default: hostname)
FlushTimeout: 5 * time.Second, // Timeout for flush operations
BeforeSend: myCallback, // Modify/filter events
Transport: nil, // Custom transport
})Option Reference
DSN
Required. Your Data Source Name containing API key and organization.
DSN: "https://[email protected]/acme"Format: https://<api-key>@statly.live/<org-slug>
Environment
Environment name for filtering events in the dashboard.
Environment: "production" // or "staging", "development"Release
Your application version. Used for release tracking.
Release: "1.2.3" // or commit hashDebug
Enable verbose logging for troubleshooting.
Debug: trueLogs SDK initialization, event capture, and transport activity to stdout.
SampleRate
Probability that an event will be sent (0.0 to 1.0).
SampleRate: 0.5 // Send 50% of eventsUses math/rand for sampling.
MaxBreadcrumbs
Maximum number of breadcrumbs to store per event.
MaxBreadcrumbs: 50 // Default: 100Oldest breadcrumbs are dropped when limit is reached.
ServerName
Server identifier. Defaults to os.Hostname().
ServerName: "api-server-1"FlushTimeout
Timeout for flush operations.
FlushTimeout: 10 * time.Second // Default: 5sBeforeSend
Callback to modify or drop events before sending.
BeforeSend: func(event *statly.Event) *statly.Event {
// Drop events from test users
if event.User != nil && event.User.Email == "[email protected]" {
return nil
}
// Remove sensitive data
if event.Extra != nil {
delete(event.Extra, "password")
}
return event
}Return nil to drop the event.
Transport
Custom transport for sending events.
// Use synchronous transport (useful for CLI tools)
Transport: statly.NewSyncTransport(statly.TransportOptions{
DSN: "...",
MaxRetries: 3,
})Runtime Configuration
Some settings can be changed after initialization:
import statly "github.com/KodyDennon/statly-go"
statly.Init(statly.Options{DSN: "..."})
// Set user context
statly.SetUser(statly.User{
ID: "user_123",
Email: "[email protected]",
Username: "johndoe",
})
// Add tags
statly.SetTag("feature", "checkout")
statly.SetTags(map[string]string{
"region": "us-east",
"plan": "enterprise",
})
// Add extra data
statly.SetExtra("request_id", "abc123")Environment Variables
Common pattern for configuration:
import (
"os"
statly "github.com/KodyDennon/statly-go"
)
func main() {
statly.Init(statly.Options{
DSN: os.Getenv("STATLY_DSN"),
Environment: os.Getenv("ENVIRONMENT"),
Release: os.Getenv("GIT_SHA"),
Debug: os.Getenv("DEBUG") == "true",
})
defer statly.Close()
}