Documentation
¶
Index ¶
- Variables
- func Meter() metric.Meter
- func RecordStats(db *sql.DB, interval time.Duration) (fnStop func())
- func Register(driverName string, options ...WrapperOption) (string, error)
- func RegisterWithSource(driverName string, source string, options ...WrapperOption) (string, error)
- func Wrap(d driver.Driver, options ...WrapperOption) driver.Driver
- func WrapConn(c driver.Conn, options ...WrapperOption) driver.Conn
- func WrapConnector(dc driver.Connector, options ...WrapperOption) driver.Connector
- type EmptyWrapperOption
- type WrapperOption
- func WithAllWrapperOptions() WrapperOption
- func WithAllowRoot(v bool) WrapperOption
- func WithDisableErrSkip(v bool) WrapperOption
- func WithInstanceName(v string) WrapperOption
- func WithLastInsertID(v bool) WrapperOption
- func WithOptions(options wrapper) WrapperOption
- func WithPing(v bool) WrapperOption
- func WithQuery(v bool) WrapperOption
- func WithQueryParams(v bool) WrapperOption
- func WithRowsAffected(v bool) WrapperOption
- func WithRowsClose(v bool) WrapperOption
- func WithRowsNext(v bool) WrapperOption
- type WrapperOptionFunc
Constants ¶
This section is empty.
Variables ¶
var ( // GoSQLInstance is the SQL instance name. GoSQLInstance = attribute.Key("go_sql_instance") // GoSQLMethod is the SQL method called. GoSQLMethod = attribute.Key("go_sql_method") // GoSQLError is the error received while calling a SQL method. GoSQLError = attribute.Key("go_sql_error") // GoSQLStatus identifies success vs. error from the SQL method response. GoSQLStatus = attribute.Key("go_sql_status") )
The following tags are applied to stats recorded by this package.
var ( // InstrumentationName is the name of this instrumentation package. InstrumentationName = "go.sql" // InstrumentationVersion is the version of this instrumentation package. InstrumentationVersion = otelcontrib.SemVersion() )
var ( MeasureLatencyMs = metric.Must(Meter()).NewInt64Histogram("go_sql_client_latency_milliseconds", metric.WithDescription("The latency of calls in milliseconds."), metric.WithUnit(unit.Milliseconds)) MeasureOpenConnections = metric.Must(Meter()).NewInt64Histogram("go_sql_connections_open", metric.WithDescription("Count of open connections in the pool."), metric.WithUnit(unit.Dimensionless)) MeasureIdleConnections = metric.Must(Meter()).NewInt64Histogram("go_sql_connections_idle", metric.WithDescription("Count of idle connections in the pool."), metric.WithUnit(unit.Dimensionless)) MeasureActiveConnections = metric.Must(Meter()).NewInt64Histogram("go_sql_connections_active", metric.WithDescription("Count of active connections in the pool."), metric.WithUnit(unit.Dimensionless)) MeasureWaitCount = metric.Must(Meter()).NewInt64Histogram("go_sql_connections_wait_count", metric.WithDescription("The total number of connections waited for."), metric.WithUnit(unit.Dimensionless)) MeasureWaitDuration = metric.Must(Meter()).NewInt64Histogram("go_sql_connections_wait_duration_milliseconds", metric.WithDescription("The total time blocked waiting for a new connection."), metric.WithUnit(unit.Milliseconds)) MeasureIdleClosed = metric.Must(Meter()).NewInt64Histogram("go_sql_connections_idle_closed", metric.WithDescription("The total number of connections closed due to SetMaxIdleConns."), metric.WithUnit(unit.Dimensionless)) MeasureLifetimeClosed = metric.Must(Meter()).NewInt64Histogram("go_sql_connections_lifetime_closed", metric.WithDescription("The total number of connections closed due to SetConnMaxLifetime."), metric.WithUnit(unit.Dimensionless)) )
The following measures are supported for use in custom views.
var AllWrapperOptions = wrapper{ AllowRoot: true, Ping: true, RowsNext: true, RowsClose: true, RowsAffected: true, LastInsertID: true, Query: true, QueryParams: true, DefaultAttributes: []attribute.KeyValue{attribute.String("db.type", "sql")}, }
AllWrapperOptions has all tracing options enabled.
var PostCall func(ctx context.Context, err error, elapse time.Duration, attrs ...attribute.KeyValue)
PostCall called after sql executed, designed such for logger to print details
Functions ¶
func RecordStats ¶
RecordStats records database statistics for provided sql.DB at the provided interval.
func Register ¶
func Register(driverName string, options ...WrapperOption) (string, error)
Register initializes and registers our otelsql wrapped database driver identified by its driverName and using provided TraceOptions. On success it returns the generated driverName to use when calling sql.Open. It is possible to register multiple wrappers for the same database driver if needing different TraceOptions for different connections.
func RegisterWithSource ¶
func RegisterWithSource(driverName string, source string, options ...WrapperOption) (string, error)
RegisterWithSource initializes and registers our otelsql wrapped database driver identified by its driverName, using provided TraceOptions. source is useful if some drivers do not accept the empty string when opening the DB. On success it returns the generated driverName to use when calling sql.Open. It is possible to register multiple wrappers for the same database driver if needing different TraceOptions for different connections.
func Wrap ¶
func Wrap(d driver.Driver, options ...WrapperOption) driver.Driver
Wrap takes an SQL driver and wraps it with OpenCensus instrumentation.
func WrapConn ¶
func WrapConn(c driver.Conn, options ...WrapperOption) driver.Conn
WrapConn allows an existing driver.Conn to be wrapped by sql.
func WrapConnector ¶
func WrapConnector(dc driver.Connector, options ...WrapperOption) driver.Connector
WrapConnector allows wrapping a database driver.Connector which eliminates the need to register otlpsql as an available driver.Driver.
Types ¶
type EmptyWrapperOption ¶
type EmptyWrapperOption struct{}
EmptyWrapperOption does not alter the configuration. It can be embedded in another structure to build custom options.
This API is EXPERIMENTAL.
type WrapperOption ¶
type WrapperOption interface {
// contains filtered or unexported methods
}
A WrapperOption sets options.
func WithAllWrapperOptions ¶
func WithAllWrapperOptions() WrapperOption
WithAllWrapperOptions enables all available trace options.
func WithAllowRoot ¶
func WithAllowRoot(v bool) WrapperOption
WithAllowRoot sets AllowRoot in wrapper.
func WithDisableErrSkip ¶
func WithDisableErrSkip(v bool) WrapperOption
WithDisableErrSkip sets DisableErrSkip in wrapper.
func WithInstanceName ¶
func WithInstanceName(v string) WrapperOption
WithInstanceName sets InstanceName in wrapper.
func WithLastInsertID ¶
func WithLastInsertID(v bool) WrapperOption
WithLastInsertID sets LastInsertID in wrapper.
func WithOptions ¶
func WithOptions(options wrapper) WrapperOption
WithOptions sets our otlpsql tracing middleware options through a single WrapperOptions object.
func WithQueryParams ¶
func WithQueryParams(v bool) WrapperOption
WithQueryParams sets QueryParams in wrapper.
func WithRowsAffected ¶
func WithRowsAffected(v bool) WrapperOption
WithRowsAffected sets RowsAffected in wrapper.
func WithRowsClose ¶
func WithRowsClose(v bool) WrapperOption
WithRowsClose sets RowsClose in wrapper.
type WrapperOptionFunc ¶
type WrapperOptionFunc func(*wrapper)
WrapperOptionFunc wraps a function that modifies wrapper into an implementation of the WrapperOption interface.