Go Agent 2.8

Released on: 
Tuesday, June 11, 2019 - 14:19

2.8.0

New Features

  • Introduce support for databases using database/sql. This new functionality allows you to instrument MySQL, PostgreSQL, and SQLite calls without manually creating DatastoreSegments.
Database Library Supported Integration Package
go-sql-driver/mysql _integrations/nrmysql
lib/pq _integrations/nrpq
mattn/go-sqlite3 _integrations/nrsqlite3

Using these database integration packages is easy! First replace the driver with our integration version:

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

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

Second, use the ExecContext, QueryContext, and QueryRowContext methods of sql.DB, sql.Conn, sql.Tx, and sql.Stmt and provide a transaction-containing context. Calls to Exec, Query, and QueryRow do not get instrumented.

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

If you are using a database/sql database not listed above, you can write your own instrumentation for it using InstrumentSQLConnector, InstrumentSQLDriver, and SQLDriverSegmentBuilder. The integration packages act as examples of how to do this.

For more information, see the Go agent documentation on instrumenting datastore segments.

Bug Fixes