nrpgx

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 11 Imported by: 8

README

v3/integrations/nrpgx GoDoc

Package nrpgx instruments https://github.com/jackc/pgx/v4.

import "github.com/newrelic/go-agent/v3/integrations/nrpgx"

For more information, see godocs.

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/newrelic/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/newrelic/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.

Directories

Path Synopsis
example
sqlx Module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL