Provides OpenTelemetry instrumentation for the jackc/pgx library.
- go 1.18 (or higher)
- pgx v5 (or higher)
Install the library:
go get github.com/exaring/otelpgx
Create the tracer as part of your connection:
cfg, err := pgxpool.ParseConfig(connString)
if err != nil {
return nil, fmt.Errorf("create connection pool: %w", err)
}
cfg.ConnConfig.Tracer = otelpgx.NewTracer()
conn, err := pgxpool.NewWithConfig(ctx, cfg)
if err != nil {
return nil, fmt.Errorf("connect to database: %w", err)
}
See options.go for the full list of options.