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/atgopg
    
  2. Configure Atatus and Set Up Database Connection

    copy
    icon/buttons/copy
    import (
        "github.com/go-pg/pg"
        "github.com/go-pg/pg/orm"
    
        "go.atatus.com/agent/"
        "go.atatus.com/agent/module/atgopg"
    )
    
    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")
    
        // Connect to PostgreSQL using go-pg
        db := pg.Connect(&pg.Options{
            Addr:     "localhost:5432",
            User:     "postgres",
            Password: "password",
            Database: "mydb",
        })
    
        // Instrument the database for tracing
        atgopg.Instrument(db)
    
    }
    
    func handleRequest(w http.ResponseWriter, req *http.Request) {
        // Use DB with context to get Database metrics  
        dbi:=db.WithContext(req.Context())
    
        user := &User{Name: "Atatus User"}
        _, err := dbi.Model(user).Insert()
        ...
    }
    
  3. Clean Up Dependencies

    copy
    icon/buttons/copy

    go mod tidy
    
  4. Run the Application

    copy
    icon/buttons/copy

    go run main.go