apmsql

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

README

apmsql

Package apmsql provides a wrapper for database/sql/driver.Drivers for tracing database operations as spans of a transaction traced by Elastic APM.

To instrument a driver, you can simply swap your application's calls to sql.Register and sql.Open to apmsql.Register and apmsql.Open respectively. The apmsql.Register function accepts zero or more options to influence how tracing is performed.

Documentation

Overview

Package apmsql provides wrappers for tracing SQL query spans.

Index

Constants

View Source
const DriverPrefix = "elasticapm/"

DriverPrefix should be used as a driver name prefix when registering via sql.Register.

Variables

This section is empty.

Functions

func Open

func Open(driverName, dataSourceName string) (*sql.DB, error)

Open opens a database with the given driver and data source names, as in sql.Open. The driver name should be one registered via the Register function in this package.

func Register

func Register(name string, driver driver.Driver, opts ...WrapOption)

Register registers a traced version of the given driver.

The name and driver values should be the same as given to sql.Register: the name of the driver (e.g. "postgres"), and the driver (e.g. &github.com/lib/pq.Driver{}).

func Wrap

func Wrap(driver driver.Driver, opts ...WrapOption) driver.Driver

Wrap wraps a database/sql/driver.Driver such that the driver's database methods are traced. The tracer will be obtained from the context supplied to methods that accept it.

Types

type DSNInfo

type DSNInfo struct {
	// Database is the name of the specific database identified by the DSN.
	Database string

	// User is the username that the DSN specifies for authenticating the
	// database connection.
	User string
}

DSNInfo contains information from a database-specific data source name.

type DSNParserFunc

type DSNParserFunc func(dsn string) DSNInfo

DSNParserFunc is the type of a function that can be used for parsing a data source name, and returning the corresponding Info.

type WrapOption

type WrapOption func(*tracingDriver)

WrapOption is an option that can be supplied to Wrap.

func WithDSNParser

func WithDSNParser(f DSNParserFunc) WrapOption

WithDSNParser returns a WrapOption which sets the function to use for parsing the data source name. If WithDSNParser is not supplied to Wrap, the function to use will be inferred from the driver name.

func WithDriverName

func WithDriverName(name string) WrapOption

WithDriverName returns a WrapOption which sets the underlying driver name to the specified value. If WithDriverName is not supplied to Wrap, the driver name will be inferred from the driver supplied to Wrap.

Directories

Path Synopsis
Package apmmysql registers the "mysql" driver with apmsql, so that you can trace go-sql-driver/mysql database connections.
Package apmmysql registers the "mysql" driver with apmsql, so that you can trace go-sql-driver/mysql database connections.
Package apmpq registers the "postgres" driver with apmsql, so that you can trace lib/pq database connections.
Package apmpq registers the "postgres" driver with apmsql, so that you can trace lib/pq database connections.
Package apmsqlite3 registers the "sqlite3" driver with apmsql, so that you can trace sqlite3 database connections.
Package apmsqlite3 registers the "sqlite3" driver with apmsql, so that you can trace sqlite3 database connections.

Jump to

Keyboard shortcuts

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