Documentation ¶
Overview ¶
Package otelsql provides traces and metrics for database/sql drivers.
Index ¶
- func ContextWithQuery(ctx context.Context, query string) context.Context
- func QueryFromContext(ctx context.Context) string
- func RecordStats(db *sql.DB, opts ...StatsOption) error
- func Register(driverName string, options ...DriverOption) (string, error)
- func RegisterWithSource(driverName string, source string, options ...DriverOption) (string, error)
- func SemVersion() string
- func Version() string
- func Wrap(d driver.Driver, opts ...DriverOption) driver.Driver
- type DriverOption
- func AllowRoot() DriverOption
- func ConvertErrorToSpanStatus(f errorToSpanStatus) DriverOption
- func DisableErrSkip() DriverOption
- func TraceAll() DriverOption
- func TraceLastInsertID() DriverOption
- func TracePing() DriverOption
- func TraceQuery(f queryTracer) DriverOption
- func TraceQueryWithArgs() DriverOption
- func TraceQueryWithoutArgs() DriverOption
- func TraceRowsAffected() DriverOption
- func TraceRowsClose() DriverOption
- func TraceRowsNext() DriverOption
- func WithSpanNameFormatter(f spanNameFormatter) DriverOption
- func WithTracerProvider(p trace.TracerProvider) DriverOption
- type Option
- type StatsOption
- type TraceOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextWithQuery ¶
ContextWithQuery attaches the query to the parent context.
func QueryFromContext ¶
QueryFromContext gets the query from context.
func RecordStats ¶
func RecordStats(db *sql.DB, opts ...StatsOption) error
RecordStats records database statistics for provided sql.DB at the provided interval.
func Register ¶
func Register(driverName string, options ...DriverOption) (string, error)
Register initializes and registers our otelsql wrapped database driver identified by its driverName and using provided options. 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 options for different connections.
func RegisterWithSource ¶
func RegisterWithSource(driverName string, source string, options ...DriverOption) (string, error)
RegisterWithSource initializes and registers our otelsql wrapped database driver identified by its driverName, using provided options.
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 options for different connections.
func SemVersion ¶
func SemVersion() string
SemVersion is the semantic version to be supplied to tracer/meter creation.
Types ¶
type DriverOption ¶
type DriverOption interface {
// contains filtered or unexported methods
}
DriverOption allows for managing otelsql configuration using functional options.
func AllowRoot ¶
func AllowRoot() DriverOption
AllowRoot allows otelsql to create root spans in absence of existing spans or even context.
Default is to not trace otelsql calls if no existing parent span is found in context or when using methods not taking context.
func ConvertErrorToSpanStatus ¶
func ConvertErrorToSpanStatus(f errorToSpanStatus) DriverOption
ConvertErrorToSpanStatus sets a custom error converter.
func DisableErrSkip ¶
func DisableErrSkip() DriverOption
DisableErrSkip suppresses driver.ErrSkip errors in spans if set to true.
func TraceLastInsertID ¶
func TraceLastInsertID() DriverOption
TraceLastInsertID enables the creation of spans on LastInsertId calls.
func TracePing ¶
func TracePing() DriverOption
TracePing enables the creation of spans on Ping requests.
func TraceQuery ¶
func TraceQuery(f queryTracer) DriverOption
TraceQuery sets a custom function that will return a list of attributes to add to the spans with a given query and args.
For example:
otelsql.TraceQuery(func(sql string, args []driver.NamedValue) []attribute.KeyValue { attrs := make([]attribute.KeyValue, 0) attrs = append(attrs, semconv.DBStatementKey.String(sql)) for _, arg := range args { if arg.Name != "password" { attrs = append(attrs, sqlattribute.FromNamedValue(arg)) } } return attrs })
func TraceQueryWithArgs ¶
func TraceQueryWithArgs() DriverOption
TraceQueryWithArgs will add to the spans the given sql query and all arguments.
func TraceQueryWithoutArgs ¶
func TraceQueryWithoutArgs() DriverOption
TraceQueryWithoutArgs will add to the spans the given sql query without any arguments.
func TraceRowsAffected ¶
func TraceRowsAffected() DriverOption
TraceRowsAffected enables the creation of spans on RowsAffected calls.
func TraceRowsClose ¶
func TraceRowsClose() DriverOption
TraceRowsClose enables the creation of spans on RowsClose calls.
func TraceRowsNext ¶
func TraceRowsNext() DriverOption
TraceRowsNext enables the creation of spans on RowsNext calls. This can result in many spans.
func WithSpanNameFormatter ¶
func WithSpanNameFormatter(f spanNameFormatter) DriverOption
WithSpanNameFormatter sets tracer provider.
func WithTracerProvider ¶
func WithTracerProvider(p trace.TracerProvider) DriverOption
WithTracerProvider sets tracer provider.
type Option ¶
type Option interface { DriverOption StatsOption }
Option allows for managing otelsql configuration using functional options.
func WithDatabaseName ¶
WithDatabaseName sets database name.
func WithDefaultAttributes ¶
WithDefaultAttributes will be set to each span as default.
func WithInstanceName ¶
WithInstanceName sets database instance name.
func WithMeterProvider ¶
func WithMeterProvider(p metric.MeterProvider) Option
WithMeterProvider sets meter provider.
func WithSystem ¶
WithSystem sets database system name. See: semconv.DBSystemKey.
type StatsOption ¶
type StatsOption interface {
// contains filtered or unexported methods
}
StatsOption allows for managing otelsql configuration using functional options.
func WithMinimumReadDBStatsInterval ¶
func WithMinimumReadDBStatsInterval(interval time.Duration) StatsOption
WithMinimumReadDBStatsInterval sets the minimum interval between calls to db.Stats(). Negative values are ignored.
type TraceOptions ¶
type TraceOptions struct { // AllowRoot, if set to true, will allow otelsql to create root spans in absence of existing spans or even context. // // Default is to not trace otelsql calls if no existing parent span is found in context or when using methods not taking context. AllowRoot bool // Ping, if set to true, will enable the creation of spans on Ping requests. Ping bool // RowsNext, if set to true, will enable the creation of spans on RowsNext calls. This can result in many spans. RowsNext bool // RowsClose, if set to true, will enable the creation of spans on RowsClose calls. RowsClose bool // RowsAffected, if set to true, will enable the creation of spans on RowsAffected calls. RowsAffected bool // LastInsertID, if set to true, will enable the creation of spans on LastInsertId calls. LastInsertID bool // contains filtered or unexported fields }
TraceOptions are options to enable the creations of spans on sql calls.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package attribute provides functionalities for converting database values to attributes.
|
Package attribute provides functionalities for converting database values to attributes. |
internal
|
|
test/assert
Package assert provides asserter closures.
|
Package assert provides asserter closures. |
test/oteltest
Package oteltest provides functionalities for testing otelsql.
|
Package oteltest provides functionalities for testing otelsql. |
test/sqlmock
Package sqlmock provides functionalities for mocking a sql.DB connection.
|
Package sqlmock provides functionalities for mocking a sql.DB connection. |
tests
|
|
mssql
Module
|
|
postgres
Module
|
|
suite
Module
|