instrumentedsql

package module
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2020 License: MIT Imports: 8 Imported by: 50

README

GoDoc

instrumentedsql

A sql driver that will wrap any other driver and log/trace all its calls

How to use

Please see the documentation and examples

Go version support

The aim is to support all versions of Go starting at 1.9, when the various context methods we require to function were introduced Go 1.8 is unfortunately not supported due to lack of support in Google's tracing package, though it can probably be made to work.

The build_all.sh script uses GVM to load every version of go and verify that the library builds and passes its tests.

Roadmap

The project is largely in maintenance mode, new contributions and bugfixes are welcomed and reviewed promptly, but it is largely considered done and ready for production usage. When new versions of Go are released, any new driver interfaces can be added, PRs are welcomed for this.

Contributing

PRs and issues are welcomed and will be responded to in a timely fashion, please contribute!

Contributors will contain all people (not companies) that have contributed to the project. LICENSE will list all copyright holders.

Documentation

Index

Constants

View Source
const (
	OpSQLPrepare          = "sql-prepare"
	OpSQLConnExec         = "sql-conn-exec"
	OpSQLConnQuery        = "sql-conn-query"
	OpSQLStmtExec         = "sql-stmt-exec"
	OpSQLStmtQuery        = "sql-stmt-query"
	OpSQLStmtClose        = "sql-stmt-close"
	OpSQLTxBegin          = "sql-tx-begin"
	OpSQLTxCommit         = "sql-tx-commit"
	OpSQLTxRollback       = "sql-tx-rollback"
	OpSQLResLastInsertID  = "sql-res-lastInsertId"
	OpSQLResRowsAffected  = "sql-res-rowsAffected"
	OpSQLRowsNext         = "sql-rows-next"
	OpSQLPing             = "sql-ping"
	OpSQLDummyPing        = "sql-dummy-ping"
	OpSQLConnectorConnect = "sql-connector-connect"
)

The possible op values passed to the logger and used for child span names

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger interface {
	Log(ctx context.Context, msg string, keyvals ...interface{})
}

Logger is the interface needed to be implemented by any logging implementation we use, see also NewFuncLogger

type LoggerFunc

type LoggerFunc func(ctx context.Context, msg string, keyvals ...interface{})

LoggerFunc is an adapter which allows a function to be used as a Logger.

func (LoggerFunc) Log

func (f LoggerFunc) Log(ctx context.Context, msg string, keyvals ...interface{})

Log calls f(ctx, msg, keyvals...).

type Opt

type Opt func(*opts)

Opt is a functional option type for the wrapped driver

func WithIncludeArgs

func WithIncludeArgs() Opt

WithIncludeArgs will make it so that query arguments are included in logging and tracing This is the default, but can be used to override WithOmitArgs

func WithLogger

func WithLogger(l Logger) Opt

WithLogger sets the logger of the wrapped driver to the provided logger

func WithOmitArgs

func WithOmitArgs() Opt

WithOmitArgs will make it so that query arguments are omitted from logging and tracing

func WithOpsExcluded

func WithOpsExcluded(ops ...string) Opt

WithOpsExcluded excludes some of OpSQL that are not required

func WithTracer

func WithTracer(t Tracer) Opt

WithTracer sets the tracer of the wrapped driver to the provided tracer

type Span

type Span interface {
	NewChild(string) Span
	SetLabel(k, v string)
	SetError(err error)
	Finish()
}

Span is part of the interface needed to be implemented by any tracing implementation we use

type Tracer

type Tracer interface {
	GetSpan(ctx context.Context) Span
}

Tracer is the interface needed to be implemented by any tracing implementation we use

type WrappedDriver added in v1.1.2

type WrappedDriver struct {
	// contains filtered or unexported fields
}

WrappedDriver wraps a driver and adds instrumentation. Use WrapDriver to create a new WrappedDriver.

func WrapDriver

func WrapDriver(driver driver.Driver, opts ...Opt) WrappedDriver

WrapDriver will wrap the passed SQL driver and return a new sql driver that uses it and also logs and traces calls using the passed logger and tracer The returned driver will still have to be registered with the sql package before it can be used.

Important note: Seeing as the context passed into the various instrumentation calls this package calls, Any call without a context passed will not be instrumented. Please be sure to use the ___Context() and BeginTx() function calls added in Go 1.8 instead of the older calls which do not accept a context.

func (WrappedDriver) Open added in v1.1.2

func (d WrappedDriver) Open(name string) (driver.Conn, error)

Open implements the database/sql/driver.Driver interface for WrappedDriver.

func (WrappedDriver) OpenConnector added in v1.1.2

func (d WrappedDriver) OpenConnector(name string) (driver.Connector, error)

Directories

Path Synopsis
google module
opencensus module
opentracing module
xray module

Jump to

Keyboard shortcuts

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