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 NamedValueChecker
- type RowsColumnTypeScanType
- type WrapperOption
- func WithAllWrapperOptions() WrapperOption
- func WithOptions(options wrapper) WrapperOption
- func WithWrapperAllowRoot(v bool) WrapperOption
- func WithWrapperDefaultAttributes(v []attribute.KeyValue) WrapperOption
- func WithWrapperDisableErrSkip(v bool) WrapperOption
- func WithWrapperInstanceName(v string) WrapperOption
- func WithWrapperLastInsertID(v bool) WrapperOption
- func WithWrapperPing(v bool) WrapperOption
- func WithWrapperQuery(v bool) WrapperOption
- func WithWrapperQueryParams(v bool) WrapperOption
- func WithWrapperRowsAffected(v bool) WrapperOption
- func WithWrapperRowsClose(v bool) WrapperOption
- func WithWrapperRowsNext(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.Version() )
var (
MeasureLatencyMs, _ = Meter().Int64Histogram("go_sql_client_latency_milliseconds",
metric.WithDescription("The latency of calls in milliseconds."),
metric.WithUnit(uMilliseconds))
MeasureOpenConnections, _ = Meter().Int64Histogram("go_sql_connections_open",
metric.WithDescription("Count of open connections in the pool."),
metric.WithUnit(uDimensionless))
MeasureIdleConnections, _ = Meter().Int64Histogram("go_sql_connections_idle",
metric.WithDescription("Count of idle connections in the pool."),
metric.WithUnit(uDimensionless))
MeasureActiveConnections, _ = Meter().Int64Histogram("go_sql_connections_active",
metric.WithDescription("Count of active connections in the pool."),
metric.WithUnit(uDimensionless))
MeasureWaitCount, _ = Meter().Int64Histogram("go_sql_connections_wait_count",
metric.WithDescription("The total number of connections waited for."),
metric.WithUnit(uDimensionless))
MeasureWaitDuration, _ = Meter().Int64Histogram("go_sql_connections_wait_duration_milliseconds",
metric.WithDescription("The total time blocked waiting for a new connection."),
metric.WithUnit(uMilliseconds))
MeasureIdleClosed, _ = Meter().Int64Histogram("go_sql_connections_idle_closed",
metric.WithDescription("The total number of connections closed due to SetMaxIdleConns."),
metric.WithUnit(uDimensionless))
MeasureLifetimeClosed, _ = Meter().Int64Histogram("go_sql_connections_lifetime_closed",
metric.WithDescription("The total number of connections closed due to SetConnMaxLifetime."),
metric.WithUnit(uDimensionless))
)
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 NamedValueChecker ¶ added in v1.2.89
type NamedValueChecker = driver.NamedValueChecker
type RowsColumnTypeScanType ¶ added in v1.2.89
type RowsColumnTypeScanType = driver.RowsColumnTypeScanType
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 WithOptions ¶
func WithOptions(options wrapper) WrapperOption
WithOptions sets our otlpsql tracing middleware options through a single WrapperOptions object.
func WithWrapperAllowRoot ¶ added in v1.2.89
func WithWrapperAllowRoot(v bool) WrapperOption
WithWrapperAllowRoot sets AllowRoot in wrapper. AllowRoot, if set to true, will allow otlpsql to create root spans in absence of existing spans or even context. Default is to not trace otlpsql calls if no existing parent span is found in context or when using methods not taking context.
func WithWrapperDefaultAttributes ¶ added in v1.2.89
func WithWrapperDefaultAttributes(v []attribute.KeyValue) WrapperOption
WithWrapperDefaultAttributes sets DefaultAttributes in wrapper. DefaultAttributes will be set to each span as default.
func WithWrapperDisableErrSkip ¶ added in v1.2.89
func WithWrapperDisableErrSkip(v bool) WrapperOption
WithWrapperDisableErrSkip sets DisableErrSkip in wrapper. DisableErrSkip, if set to true, will suppress driver.ErrSkip errors in spans.
func WithWrapperInstanceName ¶ added in v1.2.89
func WithWrapperInstanceName(v string) WrapperOption
WithWrapperInstanceName sets InstanceName in wrapper. InstanceName identifies database.
func WithWrapperLastInsertID ¶ added in v1.2.89
func WithWrapperLastInsertID(v bool) WrapperOption
WithWrapperLastInsertID sets LastInsertID in wrapper. LastInsertID, if set to true, will enable the creation of spans on LastInsertId calls.
func WithWrapperPing ¶ added in v1.2.89
func WithWrapperPing(v bool) WrapperOption
WithWrapperPing sets Ping in wrapper. Ping, if set to true, will enable the creation of spans on Ping requests.
func WithWrapperQuery ¶ added in v1.2.89
func WithWrapperQuery(v bool) WrapperOption
WithWrapperQuery sets Query in wrapper. Query, if set to true, will enable recording of sql queries in spans. Only allow this if it is safe to have queries recorded with respect to security.
func WithWrapperQueryParams ¶ added in v1.2.89
func WithWrapperQueryParams(v bool) WrapperOption
WithWrapperQueryParams sets QueryParams in wrapper. QueryParams, if set to true, will enable recording of parameters used with parametrized queries. Only allow this if it is safe to have parameters recorded with respect to security. This setting is a noop if the Query option is set to false.
func WithWrapperRowsAffected ¶ added in v1.2.89
func WithWrapperRowsAffected(v bool) WrapperOption
WithWrapperRowsAffected sets RowsAffected in wrapper. RowsAffected, if set to true, will enable the creation of spans on RowsAffected calls.
func WithWrapperRowsClose ¶ added in v1.2.89
func WithWrapperRowsClose(v bool) WrapperOption
WithWrapperRowsClose sets RowsClose in wrapper. RowsClose, if set to true, will enable the creation of spans on RowsClose calls.
func WithWrapperRowsNext ¶ added in v1.2.89
func WithWrapperRowsNext(v bool) WrapperOption
WithWrapperRowsNext sets RowsNext in wrapper. RowsNext, if set to true, will enable the creation of spans on RowsNext calls. This can result in many spans.
type WrapperOptionFunc ¶
type WrapperOptionFunc func(*wrapper)
WrapperOptionFunc wraps a function that modifies wrapper into an implementation of the WrapperOption interface.