nrpgx

package module
v1.0.1-0...-0a94385 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

README

v3/integrations/nrpq GoDoc

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

import "github.com/oldfritter/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/oldfritter/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 oldfritter.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 := oldfritter.NewContext(context.Background(), txn)
row := db.QueryRowContext(ctx, "SELECT count(*) FROM pg_catalog.pg_tables")

A working example is shown here: https://github.com/oldfritter/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