Documentation ¶
Overview ¶
Package nrpgx instruments https://github.com/jackc/pgx/v4.
Use this package to instrument your PostgreSQL calls using the pgx library.
USING WITH PGX AS A DATABASE/SQL DRIVER
The pgx library may be used as a database/sql driver rather than making direct calls into pgx itself. In this scenario, just use the nrpgx integration in place of the pgx driver. In other words, if your code without New Relic's agent looks like this:
import ( "database/sql" _ "github.com/jackc/pgx/v4/stdlib" ) func main() { db, err := sql.Open("pgx", "user=pqgotest dbname=pqgotest sslmode=verify-full") }
Then change the side-effect import to this package, and open "nrpgx" instead:
import ( "database/sql" _ "github.com/Easypay/go-agent/v3/integrations/nrpgx" ) func main() { db, err := sql.Open("nrpgx", "user=pqgotest dbname=pqgotest sslmode=verify-full") }
Next, provide a context containing a newrelic.Transaction to all exec and query methods on sql.DB, sql.Conn, and sql.Tx. This requires using the context methods ExecContext, QueryContext, and QueryRowContext in place of Exec, Query, and QueryRow respectively. For example, instead of the following:
row := db.QueryRow("SELECT count(*) FROM pg_catalog.pg_tables")
Do this:
ctx := newrelic.NewContext(context.Background(), txn) row := db.QueryRowContext(ctx, "SELECT count(*) FROM pg_catalog.pg_tables")
A working example is shown here: https://github.com/Easypay/go-agent/tree/master/v3/integrations/nrpgx/example/sql_compat/main.go
USING WITH DIRECT PGX CALLS WITHOUT DATABASE/SQL
This mode of operation is not supported by the nrpgx integration at this time.