Installation steps

  1. Install Atatus Go Agent and Required Modules

    copy
    icon/buttons/copy
    go get go.atatus.com/agent
    go get go.atatus.com/agent/module/atgormv2/driver/mysql
    
  2. Configure Atatus and Set Up Database Connection

    copy
    icon/buttons/copy
    import (
        "gorm.io/gorm"
    
        "go.atatus.com/agent"
        "go.atatus.com/agent/module/atgormv2/driver/mysql"
    )
    
    func main() {
    
        // Initialize Atatus tracer with values from environment
        tracer := atatus.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")
    
        // Set up database connection using Atatus GORM driver (atgormv2)
        dsn := "MYSQL_DSN" // e.g. "user:pass@tcp(host:port)/dbname?parseTime=true&loc=Local"
        dialector := mysql.Open(dsn)
    
        // Wrap GORM config to use Atatus driver
        db, err := gorm.Open(dialector, &gorm.Config{})
        ...
    }
    
    func handleRequest(w http.ResponseWriter, req *http.Request) {
        // Use DB with context to get Database metrics  
        dbi:=db.WithContext(req.Context())
    
        if err := dbi.Find(&result).Error; err != nil {
            log.Printf("query error: %v", err)
        }
        ...
    }
    
  3. Clean Up Dependencies

    copy
    icon/buttons/copy

    go mod tidy
    
  4. Run the Application

    copy
    icon/buttons/copy

    go run main.go