Documentation ¶
Index ¶
- Constants
- Variables
- func NewTraceLogger(opts ...LoggerOption) *tracelog.TraceLog
- func RecordStats(db *pgxpool.Pool, opts ...MeterOption) error
- type LogLevelConverter
- type Logger
- type LoggerOption
- type Meter
- type MeterOption
- type MeterOptionFunc
- type Option
- type ResourceConfig
- type SpanNameFunc
- type Tracer
- func (t *Tracer) TraceBatchEnd(ctx context.Context, _ *pgx.Conn, data pgx.TraceBatchEndData)
- func (t *Tracer) TraceBatchQuery(ctx context.Context, conn *pgx.Conn, data pgx.TraceBatchQueryData)
- func (t *Tracer) TraceBatchStart(ctx context.Context, conn *pgx.Conn, data pgx.TraceBatchStartData) context.Context
- func (t *Tracer) TraceConnectEnd(ctx context.Context, data pgx.TraceConnectEndData)
- func (t *Tracer) TraceConnectStart(ctx context.Context, data pgx.TraceConnectStartData) context.Context
- func (t *Tracer) TraceCopyFromEnd(ctx context.Context, _ *pgx.Conn, data pgx.TraceCopyFromEndData)
- func (t *Tracer) TraceCopyFromStart(ctx context.Context, conn *pgx.Conn, data pgx.TraceCopyFromStartData) context.Context
- func (t *Tracer) TracePrepareEnd(ctx context.Context, _ *pgx.Conn, data pgx.TracePrepareEndData)
- func (t *Tracer) TracePrepareStart(ctx context.Context, conn *pgx.Conn, data pgx.TracePrepareStartData) context.Context
- func (t *Tracer) TraceQueryEnd(ctx context.Context, _ *pgx.Conn, data pgx.TraceQueryEndData)
- func (t *Tracer) TraceQueryStart(ctx context.Context, conn *pgx.Conn, data pgx.TraceQueryStartData) context.Context
Constants ¶
const ( DBMaxConnLifetimeKey = "db.max_conn_lifetime" DBMaxConnIdleTimeKey = "db.max_conn_idle_time" DBMaxConnsKey = "db.max_conns" DBMinConnsKey = "db.min_conns" DBHealthCheckPeriodKey = "db.health_check_period" DBStatementCacheCapacityKey = "db.statement_cache_capacity" DBDescriptionCacheCapacityKey = "db.description_cache_capacity" DBHostKey = "db.host" DBPortKey = "db.port" DBUserKey = "db.user" DBConnectTimeoutKey = "db.connect_timeout" DBKerberosSrvNameKey = "db.kerberos_srv_name" DBKerberosSpnKey = "db.kerberos_spn" )
const ( LevelTrace slog.Level = -8 LevelNone slog.Level = 12 )
const ( UnitDimensionless = "1" UnitBytes = "By" UnitMilliseconds = "ms" )
const ( // RowsAffectedKey represents the number of rows affected. RowsAffectedKey = attribute.Key("pgx.rows_affected") // QueryParametersKey represents the query parameters. QueryParametersKey = attribute.Key("pgx.query.parameters") // BatchSizeKey represents the batch size. BatchSizeKey = attribute.Key("pgx.batch.size") // PrepareStmtNameKey represents the prepared statement name. PrepareStmtNameKey = attribute.Key("pgx.prepare_stmt.name") // SQLStateKey represents PostgreSQL error code, // see https://www.postgresql.org/docs/current/errcodes-appendix.html. SQLStateKey = attribute.Key("pgx.sql_state") )
Variables ¶
var LevelNames = map[slog.Level]string{ LevelTrace: "TRACE", LevelNone: "NONE", }
Functions ¶
func NewTraceLogger ¶
func NewTraceLogger(opts ...LoggerOption) *tracelog.TraceLog
NewTraceLogger creates a new trace logger.
func RecordStats ¶
func RecordStats(db *pgxpool.Pool, opts ...MeterOption) error
RecordStats records database statistics for provided pgxpool.Pool at the provided interval.
Types ¶
type LogLevelConverter ¶
type LoggerOption ¶
type LoggerOption func(*Logger)
func WithLogLevel ¶
func WithLogLevel(level slog.Level) LoggerOption
WithLogLevel sets the log level.
func WithLogLevelConverter ¶
func WithLogLevelConverter(c LogLevelConverter) LoggerOption
WithLogLevelConverter sets the log level converter.
type MeterOption ¶
type MeterOption interface {
// contains filtered or unexported methods
}
MeterOption allows for managing otelsql configuration using functional options.
func WithMeterProvider ¶
func WithMeterProvider(p metric.MeterProvider) MeterOption
WithMeterProvider sets meter provider.
func WithMinimumReadDBStatsInterval ¶
func WithMinimumReadDBStatsInterval(interval time.Duration) MeterOption
WithMinimumReadDBStatsInterval sets the minimum interval between calls to db.Stats(). Negative values are ignored.
type MeterOptionFunc ¶
type MeterOptionFunc func(o *Meter)
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option specifies instrumentation configuration options.
func WithAttributes ¶
WithAttributes specifies additional attributes to be added to the span.
func WithDisableSQLStatementInAttributes ¶
func WithDisableSQLStatementInAttributes() Option
WithDisableSQLStatementInAttributes will disable logging the SQL statement in the span's attributes.
func WithIncludeQueryParameters ¶
func WithIncludeQueryParameters() Option
WithIncludeQueryParameters includes the SQL query parameters in the span attribute with key pgx.query.parameters. This is implicitly disabled if WithDisableSQLStatementInAttributes is used.
func WithSpanNameFunc ¶
func WithSpanNameFunc(fn SpanNameFunc) Option
WithSpanNameFunc will use the provided function to generate the span name for a SQL statement. The function will be called with the SQL statement as a parameter.
By default, the whole SQL statement is used as a span name, where applicable.
func WithTracerProvider ¶
func WithTracerProvider(provider trace.TracerProvider) Option
WithTracerProvider specifies a tracer provider to use for creating a tracer. If none is specified, the global provider is used.
func WithTrimSQLInSpanName ¶
func WithTrimSQLInSpanName() Option
WithTrimSQLInSpanName will use the SQL statement's first word as the span name. By default, the whole SQL statement is used as a span name, where applicable.
type ResourceConfig ¶
type SpanNameFunc ¶
SpanNameFunc is a function that can be used to generate a span name for a SQL. The function will be called with the SQL statement as a parameter.
type Tracer ¶
type Tracer struct {
// contains filtered or unexported fields
}
Tracer is a wrapper around the pgx tracer interfaces which instrument queries.
func (*Tracer) TraceBatchEnd ¶
TraceBatchEnd is called at the end of SendBatch calls.
func (*Tracer) TraceBatchQuery ¶
TraceBatchQuery is called at the after each query in a batch.
func (*Tracer) TraceBatchStart ¶
func (t *Tracer) TraceBatchStart(ctx context.Context, conn *pgx.Conn, data pgx.TraceBatchStartData) context.Context
TraceBatchStart is called at the beginning of SendBatch calls. The returned context is used for the rest of the call and will be passed to TraceBatchQuery and TraceBatchEnd.
func (*Tracer) TraceConnectEnd ¶
TraceConnectEnd is called at the end of Connect and ConnectConfig calls.
func (*Tracer) TraceConnectStart ¶
func (t *Tracer) TraceConnectStart(ctx context.Context, data pgx.TraceConnectStartData) context.Context
TraceConnectStart is called at the beginning of Connect and ConnectConfig calls. The returned context is used for the rest of the call and will be passed to TraceConnectEnd.
func (*Tracer) TraceCopyFromEnd ¶
TraceCopyFromEnd is called at the end of CopyFrom calls.
func (*Tracer) TraceCopyFromStart ¶
func (t *Tracer) TraceCopyFromStart(ctx context.Context, conn *pgx.Conn, data pgx.TraceCopyFromStartData) context.Context
TraceCopyFromStart is called at the beginning of CopyFrom calls. The returned context is used for the rest of the call and will be passed to TraceCopyFromEnd.
func (*Tracer) TracePrepareEnd ¶
TracePrepareEnd is called at the end of Prepare calls.
func (*Tracer) TracePrepareStart ¶
func (t *Tracer) TracePrepareStart(ctx context.Context, conn *pgx.Conn, data pgx.TracePrepareStartData) context.Context
TracePrepareStart is called at the beginning of Prepare calls. The returned context is used for the rest of the call and will be passed to TracePrepareEnd.
func (*Tracer) TraceQueryEnd ¶
TraceQueryEnd is called at the end of Query, QueryRow, and Exec calls.
func (*Tracer) TraceQueryStart ¶
func (t *Tracer) TraceQueryStart(ctx context.Context, conn *pgx.Conn, data pgx.TraceQueryStartData) context.Context
TraceQueryStart is called at the beginning of Query, QueryRow, and Exec calls. The returned context is used for the rest of the call and will be passed to TraceQueryEnd.