nrmysql

package
v3.19.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2022 License: Apache-2.0 Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package nrmysql instruments https://github.com/go-sql-driver/mysql.

Use this package to instrument your MySQL 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 mysql driver.

If your code is using sql.Open like this:

import (
	_ "github.com/go-sql-driver/mysql"
)

func main() {
	db, err := sql.Open("mysql", "user@unix(/path/to/socket)/dbname")
}

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

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

func main() {
	db, err := sql.Open("nrmysql", "user@unix(/path/to/socket)/dbname")
}

2. Provide a context containing a newrelic.Transaction to all exec and query methods on sql.DB, sql.Conn, sql.Tx, and sql.Stmt. 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 tables")

Do this:

ctx := newrelic.NewContext(context.Background(), txn)
row := db.QueryRowContext(ctx, "SELECT count(*) from tables")

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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