Documentation
¶
Index ¶
- func ContextWithTable(ctx context.Context, table string) context.Context
- func Enabled(config config.Config) bool
- func WrapBuilder(inner contractsdb.Builder, inst *Instrument) contractsdb.Builder
- func WrapTxBuilder(inner contractsdb.TxBuilder, inst *Instrument) contractsdb.TxBuilder
- type Instrument
- func (r *Instrument) Active() bool
- func (r *Instrument) EndSpan(ctx context.Context, span trace.Span, start time.Time, query, table string, ...)
- func (r *Instrument) SetDB(db *sql.DB)
- func (r *Instrument) Shutdown()
- func (r *Instrument) StartSpan(ctx context.Context, name string) (context.Context, trace.Span)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextWithTable ¶
ContextWithTable tags ctx with the collection a query targets so the wrapped builder can set db.collection.name for structured queries. Raw SQL omits it.
func WrapBuilder ¶
func WrapBuilder(inner contractsdb.Builder, inst *Instrument) contractsdb.Builder
WrapBuilder wraps a query builder with telemetry. The wrapper resolves telemetry lazily and no-ops until it is active.
func WrapTxBuilder ¶
func WrapTxBuilder(inner contractsdb.TxBuilder, inst *Instrument) contractsdb.TxBuilder
WrapTxBuilder wraps a transaction builder with telemetry.
Types ¶
type Instrument ¶
type Instrument struct {
// contains filtered or unexported fields
}
func NewInstrument ¶
func NewInstrument(pool contractsdatabase.Pool, connection string, resolver contractstelemetry.Resolver) *Instrument
func (*Instrument) Active ¶
func (r *Instrument) Active() bool
Active reports whether this instrument can record anything: telemetry is enabled and a resolver is configured. A nil instrument is never active, so callers may test one they obtained without a separate nil check.
func (*Instrument) EndSpan ¶
func (r *Instrument) EndSpan(ctx context.Context, span trace.Span, start time.Time, query, table string, rows int64, err error, resolverMode string)
EndSpan closes a span StartSpan opened, recording the statement, its table, the rows it returned and the error it raised. A nil receiver records nothing, which is what a connection with telemetry disabled carries.
func (*Instrument) SetDB ¶
func (r *Instrument) SetDB(db *sql.DB)
SetDB stores the primary writer's *sql.DB for pool metrics. Pool metrics cover the writer pool only: replica pools belong to the read/write resolver and expose no sql.DBStats.
func (*Instrument) Shutdown ¶
func (r *Instrument) Shutdown()
Shutdown unregisters the pool-metrics callback and clears the resolved telemetry so the next use re-resolves against the current provider.