Documentation
¶
Index ¶
- Constants
- func RecordStats(db PoolStats, opts ...StatsOption) error
- type Option
- func WithAttributes(attrs ...attribute.KeyValue) Optiondeprecated
- func WithDisableConnectionDetailsInAttributes() Option
- func WithDisableQuerySpanNamePrefix() Option
- func WithDisableSQLStatementInAttributes() Option
- func WithIncludeQueryParameters() Option
- func WithMeterAttributes(attrs ...attribute.KeyValue) Option
- func WithMeterProvider(provider metric.MeterProvider) Option
- func WithSpanNameFunc(fn SpanNameFunc) Option
- func WithTracerAttributes(attrs ...attribute.KeyValue) Option
- func WithTracerProvider(provider trace.TracerProvider) Option
- func WithTrimSQLInSpanName() Option
- type PoolStats
- type SpanNameFunc
- type StatsOption
- type Tracer
- func (t *Tracer) TraceAcquireEnd(ctx context.Context, _ *pgxpool.Pool, data pgxpool.TraceAcquireEndData)
- func (t *Tracer) TraceAcquireStart(ctx context.Context, pool *pgxpool.Pool, data pgxpool.TraceAcquireStartData) context.Context
- 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 ( // RowsAffectedKey represents the number of rows affected. RowsAffectedKey = attribute.Key("pgx.rows_affected") // QueryParametersKey represents the query parameters. QueryParametersKey = attribute.Key("pgx.query.parameters") // 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") // PGXOperationTypeKey represents the pgx tracer operation type PGXOperationTypeKey = attribute.Key("pgx.operation.type") // DBClientOperationErrorsKey represents the count of operation errors DBClientOperationErrorsKey = attribute.Key("db.client.operation.errors") )
Variables ¶
This section is empty.
Functions ¶
func RecordStats ¶ added in v0.8.0
func RecordStats(db PoolStats, opts ...StatsOption) error
RecordStats records database statistics for provided pgxpool.Pool at a default 1 second interval unless otherwise specified by the WithMinimumReadDBStatsInterval StatsOption.
Types ¶
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option specifies instrumentation configuration options.
func WithAttributes
deprecated
func WithDisableConnectionDetailsInAttributes ¶ added in v0.9.0
func WithDisableConnectionDetailsInAttributes() Option
WithDisableConnectionDetailsInAttributes will disable logging the connection details. in the span's attributes.
func WithDisableQuerySpanNamePrefix ¶ added in v0.6.0
func WithDisableQuerySpanNamePrefix() Option
WithDisableQuerySpanNamePrefix will disable the default prefix for the span name. By default, the span name is prefixed with "batch query" or "query".
func WithDisableSQLStatementInAttributes ¶ added in v0.4.0
func WithDisableSQLStatementInAttributes() Option
WithDisableSQLStatementInAttributes will disable logging the SQL statement in the span's attributes.
func WithIncludeQueryParameters ¶ added in v0.4.0
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 WithMeterAttributes ¶ added in v0.8.0
WithMeterAttributes specifies additional attributes to be added to metrics.
func WithMeterProvider ¶ added in v0.8.0
func WithMeterProvider(provider metric.MeterProvider) Option
WithMeterProvider specifies a meter provider to use for creating a meter. If none is specified, the global provider is used.
func WithSpanNameFunc ¶ added in v0.5.0
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 WithTracerAttributes ¶ added in v0.8.0
WithTracerAttributes specifies additional attributes to be added to spans.
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 PoolStats ¶ added in v0.9.2
PoolStats is an interface that provides access to the pgxpool.Pool's statistics.
type SpanNameFunc ¶ added in v0.5.0
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 StatsOption ¶ added in v0.8.0
type StatsOption interface {
// contains filtered or unexported methods
}
StatsOption allows for managing RecordStats configuration using functional options.
func WithMinimumReadDBStatsInterval ¶ added in v0.8.0
func WithMinimumReadDBStatsInterval(interval time.Duration) StatsOption
WithMinimumReadDBStatsInterval sets the minimum interval between calls to db.Stats(). Negative values are ignored.
func WithStatsAttributes ¶ added in v0.8.0
func WithStatsAttributes(attrs ...attribute.KeyValue) StatsOption
WithStatsAttributes specifies additional attributes to be added to pgx stat metrics.
func WithStatsMeterProvider ¶ added in v0.8.0
func WithStatsMeterProvider(provider metric.MeterProvider) StatsOption
WithStatsMeterProvider sets meter provider to use for pgx stat metric collection.
type Tracer ¶
type Tracer struct {
// contains filtered or unexported fields
}
Tracer is a wrapper around the pgx tracer interfaces which instrument queries with both tracing and metrics. Use NewTracer to create a new instance.
func (*Tracer) TraceAcquireEnd ¶ added in v0.7.0
func (t *Tracer) TraceAcquireEnd(ctx context.Context, _ *pgxpool.Pool, data pgxpool.TraceAcquireEndData)
TraceAcquireEnd is called when a connection has been acquired.
func (*Tracer) TraceAcquireStart ¶ added in v0.7.0
func (t *Tracer) TraceAcquireStart(ctx context.Context, pool *pgxpool.Pool, data pgxpool.TraceAcquireStartData) context.Context
TraceAcquireStart is called at the beginning of Acquire. The returned context is used for the rest of the call and will be passed to the TraceAcquireEnd.
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.