Installation steps

  1. Install Atatus Go Agent and SQL Modules

    copy
    icon/buttons/copy
    go get go.atatus.com/agent
    go get go.atatus.com/agent/module/atsql/pq
    go get go.atatus.com/agent/module/atsql
    
  2. Configure Atatus and Set Up Database Connection

    We support multiple SQL drivers. Below is a sample integration using the atsql module.

    Supported Drivers

    • github.com/lib/pq → atsql/pq
    • github.com/jackc/pgx/v4/stdlib → atsql/pgxv4
    • github.com/go-sql-driver/mysql → atsql/mysql
    • github.com/mattn/go-sqlite3 → atsql/sqlite3

    Example: PostgreSQL Integration

    copy
    icon/buttons/copy
    import (
        "database/sql"
    
        "go.atatus.com/agent"
        "go.atatus.com/agent/module/atsql"
        _ "go.atatus.com/agent/module/atsql/pgxv4"
        _ "go.atatus.com/agent/module/atsql/pq"
        _ "go.atatus.com/agent/module/atsql/mysql"
    )
    
    func main() {
        // Initialize tracer
        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")
    
        // PostgreSQL Example For pq driver
        dsn := "postgres://user:password@localhost:5432/mydb?sslmode=disable"
        db, _ := atsql.Open("postgres", dsn)
    
        // Use DB with context to get Database metrics
        _ = db.QueryContext(ctx, "SELECT 'Hello from PostgreSQL with Atatus!'").Scan(&greeting)
    
        // PostgreSQL Example For pgxv4 driver
        pgDsn := "postgres://user:password@localhost:5432/mydb?sslmode=disable"
        pgDB, err := atsql.Open("pgxv4", pgDsn) //  the driver name Should be  "pgxv4" for pgxv4 driver
    
        // Use DB with context to get Database metrics
        _ = pgDB.QueryRowContext(ctx, "SELECT 'Hello from PostgreSQL with Atatus!'").Scan(&greeting)
    
        // MySQL example
        myDsn := "user:password@tcp(localhost:3306)/mydb"
        myDB, err := atsql.Open("mysql", myDsn)
    
        // Use DB with context to get Database metrics
        _ = myDB.QueryRowContext(ctx, "SELECT 'Hello from MySQL with Atatus!'").Scan(&greeting)
    
    }
    

    Example: SQLite3 In-Memory Integration

    copy
    icon/buttons/copy
    import (
        "database/sql"
    
        "go.atatus.com/agent/"
        "go.atatus.com/at/module/atsql"
        _ "go.atatus.com/at/module/atsql/sqlite3"
    )
    
    func main() {
        // Initialize tracer
        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")
    
        db, err := atsql.Open("sqlite3", ":memory:")
        ...
    
        // Use DB with context to get Database metrics
        _, err = db.ExecContext(ctx, "CREATE TABLE foo (id INTEGER PRIMARY KEY, name TEXT)")
    }
    
  3. Clean Up Dependencies

    copy
    icon/buttons/copy

    go mod tidy
    
  4. Run the Application

    copy
    icon/buttons/copy

    go run main.go