Documentation ¶
Index ¶
- Constants
- func Connect(ctx context.Context, connString string, opts ...Option) (*pgx.Conn, error)
- func ConnectConfig(ctx context.Context, connConfig *pgx.ConnConfig, opts ...Option) (*pgx.Conn, error)
- func ConnectWithOptions(ctx context.Context, connString string, options pgx.ParseConfigOptions, ...) (*pgx.Conn, error)
- func NewPool(ctx context.Context, connString string, opts ...Option) (*pgxpool.Pool, error)
- func NewPoolWithConfig(ctx context.Context, config *pgxpool.Config, opts ...Option) (*pgxpool.Pool, error)
- type Batchdeprecated
- type Option
- func WithPoolStats() Option
- func WithServiceName(name string) Option
- func WithTraceAcquire(enabled bool) Option
- func WithTraceBatch(enabled bool) Option
- func WithTraceConnect(enabled bool) Option
- func WithTraceCopyFrom(enabled bool) Option
- func WithTracePrepare(enabled bool) Option
- func WithTraceQuery(enabled bool) Option
Examples ¶
Constants ¶
const ( AcquireCount = tracerPrefix + "pgx.pool.connections.acquire" AcquireDuration = tracerPrefix + "pgx.pool.connections.acquire_duration" AcquiredConns = tracerPrefix + "pgx.pool.connections.acquired_conns" CanceledAcquireCount = tracerPrefix + "pgx.pool.connections.canceled_acquire" ConstructingConns = tracerPrefix + "pgx.pool.connections.constructing_conns" EmptyAcquireCount = tracerPrefix + "pgx.pool.connections.empty_acquire" IdleConns = tracerPrefix + "pgx.pool.connections.idle_conns" MaxConns = tracerPrefix + "pgx.pool.connections.max_conns" TotalConns = tracerPrefix + "pgx.pool.connections.total_conns" NewConnsCount = tracerPrefix + "pgx.pool.connections.new_conns" MaxLifetimeDestroyCount = tracerPrefix + "pgx.pool.connections.max_lifetime_destroy" MaxIdleDestroyCount = tracerPrefix + "pgx.pool.connections.max_idle_destroy" )
Variables ¶
This section is empty.
Functions ¶
func Connect ¶
Connect is equivalent to pgx.Connect providing a connection augmented with tracing.
Example ¶
ctx := context.TODO() // The package exposes the same connect functions as the regular pgx.v5 library // which sets up a tracer and connects as usual. db, err := pgxtrace.Connect(ctx, "postgres://pqgotest:password@localhost/pqgotest?sslmode=disable") if err != nil { log.Fatal(err) } defer db.Close(ctx) // Any calls made to the database will be traced as expected. rows, err := db.Query(ctx, "SELECT name FROM users WHERE age=$1", 27) if err != nil { log.Fatal(err) } defer rows.Close() // This enables you to use PostgresSQL specific functions implemented by pgx.v5. numbers := []int{1, 2, 3} copyFromSource := pgx.CopyFromSlice(len(numbers), func(i int) ([]any, error) { return []any{numbers[i]}, nil }) _, err = db.CopyFrom(ctx, []string{"numbers"}, []string{"number"}, copyFromSource) if err != nil { log.Fatal(err) }
Output:
func ConnectConfig ¶
func ConnectConfig(ctx context.Context, connConfig *pgx.ConnConfig, opts ...Option) (*pgx.Conn, error)
ConnectConfig is equivalent to pgx.ConnectConfig providing a connection augmented with tracing.
func ConnectWithOptions ¶ added in v1.69.1
func ConnectWithOptions(ctx context.Context, connString string, options pgx.ParseConfigOptions, tracerOpts ...Option) (*pgx.Conn, error)
ConnectWithOptions is equivalent to pgx.ConnectWithOptions providing a connection augmented with tracing.
Types ¶
type Batch
deprecated
type Batch = pgx.Batch
Deprecated: this type is unused internally so it will be removed in a future release, please use pgx.Batch instead.
type Option ¶
type Option func(*config)
func WithPoolStats ¶ added in v1.67.0
func WithPoolStats() Option
WithPoolStats enables polling of pgxpool.Stat metrics ref: https://pkg.go.dev/github.com/jackc/pgx/v5/pgxpool#Stat These metrics are submitted to Datadog and are not billed as custom metrics
func WithServiceName ¶
WithServiceName sets the service name to use for all spans.
func WithTraceAcquire ¶ added in v1.67.0
WithTraceAcquire enables tracing pgxpool connection acquire calls.
func WithTraceBatch ¶
WithTraceBatch enables tracing batched operations (i.e. pgx.Batch{}).
func WithTraceConnect ¶
WithTraceConnect enables tracing calls to Connect and ConnectConfig.
pgx.Connect(ctx, "postgres://user:pass@example.com:5432/dbname", pgx.WithTraceConnect())
func WithTraceCopyFrom ¶
WithTraceCopyFrom enables tracing pgx.CopyFrom calls.
func WithTracePrepare ¶
WithTracePrepare enables tracing prepared statements.
conn, err := pgx.Connect(ctx, "postgres://user:pass@example.com:5432/dbname", pgx.WithTraceConnect()) if err != nil { // handle err } defer conn.Close(ctx) _, err := conn.Prepare(ctx, "stmt", "select $1::integer") row, err := conn.QueryRow(ctx, "stmt", 1)
func WithTraceQuery ¶
WithTraceQuery enables tracing query operations.