Help us shape the future of Go! Take the 2026 Go Developer Survey

database

package
v1.20.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithTable

func ContextWithTable(ctx context.Context, table string) context.Context

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 Enabled

func Enabled(config config.Config) bool

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.

func (*Instrument) StartSpan

func (r *Instrument) StartSpan(ctx context.Context, name string) (context.Context, trace.Span)

StartSpan opens a statement span for a query the framework is about to run. It is the exported form of startSpan, for the ORM's own executor: statements are compiled and run by the framework now, so there is no driver callback left to hang the span on.

Jump to

Keyboard shortcuts

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