This package instruments the go-sql-driver/mysql package.
$ go get github.com/pinpoint-apm/pinpoint-go-agent/plugin/mysql
import "github.com/pinpoint-apm/pinpoint-go-agent/plugin/mysql"
This package instruments the mysql driver calls. Use this package's driver in place of the mysql driver.
db, err := sql.Open("mysql-pinpoint", "root:p123@tcp(127.0.0.1:3306)/information_schema")
It is necessary to pass the context containing the pinpoint.Tracer to all exec and query methods on SQL driver.
ctx := pinpoint.NewContext(context.Background(), tracer)
row := db.QueryRowContext(ctx, "SELECT count(*) from tables")
import (
"database/sql"
"github.com/pinpoint-apm/pinpoint-go-agent"
_ "github.com/pinpoint-apm/pinpoint-go-agent/plugin/mysql"
)
func query(w http.ResponseWriter, r *http.Request) {
db, err := sql.Open("mysql-pinpoint", "root:p123@tcp(127.0.0.1:3306)/information_schema")
row := db.QueryRowContext(r.Context(), "SELECT count(*) from tables")
var count int
row.Scan(&count)
fmt.Println("number of tables in information_schema", count)
}