Installation steps
Install Atatus Go Agent and framework module
copygo get go.atatus.com/agent go get go.atatus.com/agent/module/athttp"
Set up tracer and add Atatus middleware
copyimport ( net/http atatus "go.atatus.com/agent" "go.atatus.com/agent/module/athttp" ) func main() { // Initialize Atatus tracer using environment variables tracer := at.DefaultTracer tracer.Service.LicenseKey = os.Getenv("ATATUS_LICENSE_KEY") tracer.Service.AppName = os.Getenv("ATATUS_APP_NAME") tracer.Service.Tracing = os.Getenv("ATATUS_TRACING") tracer.Service.Analytics = os.Getenv("ATATUS_ANALYTICS") // Register HTTP handlers with Atatus APM monitoring using athttp.Wrap http.Handle("/api/example1", athttp.Wrap(http.HandlerFunc(handleRequest))) // Start the HTTP server log.Fatal(http.ListenAndServe(":8000", nil)) } func handleRequest(w http.ResponseWriter, r *http.Request) { // The context from r.Context() should be propagated to downstream operations, // such as database queries and external HTTP API calls ctx := r.Context() _ = db.QueryContext(ctx, "SELECT 'Atatus!'").Scan(&greeting) }
Note:Before running your application, make sure these environment variables are set in your terminal or .env file:
copyexport ATATUS_LICENSE_KEY=<your_atatus_license_key> export ATATUS_APP_NAME=<your_application_name> export ATATUS_TRACING=true export ATATUS_ANALYTICS=true
Clean Up and Sync Dependencies
copygo mod tidy
Run the Application
copygo run main.go