The Atatus Go Profiler helps troubleshoot Go application issues and detect performance bottlenecks before they affect users. It continuously captures function call stacks and runtime metrics in production to identify slow functions, excessive CPU usage, goroutine leaks, high memory allocations, and inefficient resource usage.
Installation & Setup
Step 1: Install the Go Modules
Install the Atatus APM and profiler modules and import them in your application:
copy
go get go.atatus.com/agent
go get go.atatus.com/agent/profiler
copy
import (
"time"
"go.atatus.com/agent"
"go.atatus.com/agent/profiler"
)
Step 2: Initialize APM and the Profiler
Atatus APM is required for profiling. Initialize the Atatus APM tracer first, and then start the profiler in your main() function:
copy
func main() {
// Initialize Atatus APM tracer
tracer := atatus.DefaultTracer
// Initialize the Atatus Profiler after APM
err := profiler.Start(
profiler.WithLogLevel("none"),
profiler.WithPeriod(10 * time.Second),
profiler.WithUploadTimeout(10 * time.Second),
profiler.WithProfileTypes(
profiler.CPUProfile,
profiler.GoroutineProfile,
profiler.BlockProfile,
profiler.HeapProfile,
profiler.MetricsProfile,
profiler.MutexProfile,
),
)
if err != nil {
panic(err)
}
defer profiler.Stop()
// Your application code starts here
}
Step 3: Configure Environment Variables and Start Your Application
Set the required Atatus environment variables before starting your Go application:
copy
export ATATUS_LICENSE_KEY="your License key"
export ATATUS_APP_NAME="Your-Service-Name"
# Restart your Go application
Optional Environment Variables
copy
export ATATUS_ENVIRONMENT="production"
export ATATUS_APP_VERSION="1.0.0"
For on-premise or custom server endpoints:
copy
# Set on-premise server URL
export ATATUS_SERVER_URL="https://atatus-observability.mycompany.com"
# Or configure a dedicated profiling server URL
export ATATUS_PROFILING_SERVER_URL="https://profiling-rx.mycompany.com"
Supported Profile Types
| Profile Type | Constant |
|---|---|
| CPU | profiler.CPUProfile |
| Goroutine | profiler.GoroutineProfile |
| Block (Delay) | profiler.BlockProfile |
| Heap (Memory) | profiler.HeapProfile |
| Metrics | profiler.MetricsProfile |
| Mutex (Lock) | profiler.MutexProfile |
+1-415-800-4104