nrpq

package
v3.15.1+incompatible Latest Latest
Warning

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

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

README

_integrations/nrpq GoDoc

Package nrpq instruments https://github.com/lib/pq.

import "github.com/newrelic/go-agent/_integrations/nrpq"

For more information, see godocs.

Documentation

Overview

Package nrpq instruments https://github.com/lib/pq.

Use this package to instrument your PostgreSQL calls without having to manually create DatastoreSegments. This is done in a two step process:

1. Use this package's driver in place of the postgres driver.

If your code is using sql.Open like this:

import (
	_ "github.com/lib/pq"
)

func main() {
	db, err := sql.Open("postgres", "user=pqgotest dbname=pqgotest sslmode=verify-full")
}

Then change the side-effect import to this package, and open "nrpostgres" instead:

import (
	_ "github.com/newrelic/go-agent/_integrations/nrpq"
)

func main() {
	db, err := sql.Open("nrpostgres", "user=pqgotest dbname=pqgotest sslmode=verify-full")
}

If your code is using pq.NewConnector, simply use nrpq.NewConnector instead.

2. 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")

Unfortunately, sql.Stmt exec and query calls are not supported since pq.stmt does not have ExecContext and QueryContext methods (as of June 2019, see https://github.com/lib/pq/pull/768).

A working example is shown here: https://github.com/newrelic/go-agent/tree/master/_integrations/nrpq/example/main.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewConnector

func NewConnector(dsn string) (driver.Connector, error)

NewConnector can be used in place of pq.NewConnector to get an instrumented PostgreSQL connector.

Types

This section is empty.

Directories

Path Synopsis
sqlx
An application that illustrates how to instrument jmoiron/sqlx with DatastoreSegments To run this example, be sure the environment varible NEW_RELIC_LICENSE_KEY is set to your license key.
An application that illustrates how to instrument jmoiron/sqlx with DatastoreSegments To run this example, be sure the environment varible NEW_RELIC_LICENSE_KEY is set to your license key.

Jump to

Keyboard shortcuts

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