Documentation ¶
Index ¶
- func EnableDetailedBatchMode()
- type Conn
- func (c *Conn) Begin(ctx context.Context) (pgx.Tx, error)
- func (c *Conn) BeginFunc(ctx context.Context, f func(pgx.Tx) error) error
- func (c *Conn) BeginTx(ctx context.Context, txOptions pgx.TxOptions) (pgx.Tx, error)
- func (c *Conn) BeginTxFunc(ctx context.Context, txOptions pgx.TxOptions, f func(pgx.Tx) error) error
- func (c *Conn) CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, ...) (int64, error)
- func (c *Conn) Exec(ctx context.Context, sql string, arguments ...interface{}) (pgconn.CommandTag, error)
- func (c *Conn) Ping(ctx context.Context) error
- func (c *Conn) Prepare(ctx context.Context, name, sql string) (*pgconn.StatementDescription, error)
- func (c *Conn) Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)
- func (c *Conn) QueryFunc(ctx context.Context, sql string, args []interface{}, scans []interface{}, ...) (pgconn.CommandTag, error)
- func (c *Conn) QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row
- func (c *Conn) SendBatch(ctx context.Context, b *pgx.Batch) pgx.BatchResults
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnableDetailedBatchMode ¶
func EnableDetailedBatchMode()
EnableDetailedBatchMode allows reporting detailed information about sql statements when executing sql in batches.
Types ¶
type Conn ¶
type Conn struct { *pgx.Conn // contains filtered or unexported fields }
Conn wraps *pgx.Conn and adds tracing to it.
func Connect ¶
Connect establishes a connection with a PostgreSQL server using connection string and returns instrumented connection.
func ConnectConfig ¶
func ConnectConfig(ctx context.Context, sensor *instana.Sensor, connConfig *pgx.ConnConfig) (*Conn, error)
ConnectConfig establishes a connection with a PostgreSQL server using configuration struct and returns instrumented connection.
func (*Conn) Begin ¶
Begin wraps (*pgx.Conn).Begin method and adds tracing to it.
Example ¶
databaseUrl := "postgres://postgres:mysecretpassword@localhost/postgres" sensor := instana.NewSensor("pgx-example-begin") conf, err := pgx.ParseConfig(databaseUrl) if err != nil { log.Fatalln(err.Error()) } ctx := context.Background() conn, err := instapgx.ConnectConfig(ctx, sensor, conf) if err != nil { log.Fatalln(err.Error()) } tx, err := conn.Begin(ctx) if err != nil { log.Fatalln(err.Error()) } err = tx.Commit(ctx) if err != nil { _ = tx.Rollback(ctx) log.Fatalln(err.Error()) }
Output:
func (*Conn) BeginFunc ¶
BeginFunc wraps (*pgx.Conn).BeginFunc method and adds tracing to it.
Example ¶
databaseUrl := "postgres://postgres:mysecretpassword@localhost/postgres" sensor := instana.NewSensor("pgx-example-begin-func") conf, err := pgx.ParseConfig(databaseUrl) if err != nil { log.Fatalln(err.Error()) } ctx := context.Background() conn, err := instapgx.ConnectConfig(ctx, sensor, conf) if err != nil { log.Fatalln(err.Error()) } err = conn.BeginFunc(ctx, func(tx pgx.Tx) error { var a, b int _, err = tx.QueryFunc( ctx, "select n, n * 2 from generate_series(1, $1) n", []interface{}{3}, []interface{}{&a, &b}, func(pgx.QueryFuncRow) error { return nil }, ) return err }) if err != nil { log.Fatalln(err.Error()) }
Output:
func (*Conn) BeginTxFunc ¶
func (c *Conn) BeginTxFunc(ctx context.Context, txOptions pgx.TxOptions, f func(pgx.Tx) error) error
BeginTxFunc wraps (*pgx.Conn).BeginTxFunc method and adds tracing to it.
func (*Conn) CopyFrom ¶
func (c *Conn) CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error)
CopyFrom wraps (*pgx.Conn).CopyFrom method and adds tracing to it. It doesn't provide details of the call.
func (*Conn) Exec ¶
func (c *Conn) Exec(ctx context.Context, sql string, arguments ...interface{}) (pgconn.CommandTag, error)
Exec wraps (*pgx.Conn).Exec method and adds tracing to it.
Example ¶
databaseUrl := "postgres://postgres:mysecretpassword@localhost/postgres" sensor := instana.NewSensor("pgx-example-exec") conf, err := pgx.ParseConfig(databaseUrl) if err != nil { log.Fatalln(err.Error()) } ctx := context.Background() conn, err := instapgx.ConnectConfig(ctx, sensor, conf) if err != nil { log.Fatalln(err.Error()) } _, err = conn.Exec(ctx, "VACUUM (VERBOSE, ANALYZE)") if err != nil { log.Fatalln(err.Error()) }
Output:
func (*Conn) Ping ¶
Ping wraps (*pgx.Conn).Ping method and adds tracing to it.
Example ¶
databaseUrl := "postgres://postgres:mysecretpassword@localhost/postgres" sensor := instana.NewSensor("pgx-example-ping") conf, err := pgx.ParseConfig(databaseUrl) if err != nil { log.Fatalln(err.Error()) } ctx := context.Background() conn, err := instapgx.ConnectConfig(ctx, sensor, conf) if err != nil { log.Fatalln(err.Error()) } err = conn.Ping(ctx) if err != nil { log.Fatalln(err.Error()) }
Output:
func (*Conn) Prepare ¶
Prepare wraps (*pgx.Conn).Prepare method and adds tracing to it.
Example ¶
databaseUrl := "postgres://postgres:mysecretpassword@localhost/postgres" sensor := instana.NewSensor("pgx-example-prepare") conf, err := pgx.ParseConfig(databaseUrl) if err != nil { log.Fatalln(err.Error()) } ctx := context.Background() conn, err := instapgx.ConnectConfig(ctx, sensor, conf) if err != nil { log.Fatalln(err.Error()) } _, err = conn.Prepare(ctx, "mystatement", "select name, statement from pg_prepared_statements") if err != nil { log.Fatalln(err.Error()) }
Output:
func (*Conn) Query ¶
Query wraps (*pgx.Conn).Query method and adds tracing to it.
Example ¶
databaseUrl := "postgres://postgres:mysecretpassword@localhost/postgres" sensor := instana.NewSensor("pgx-example-query") conf, err := pgx.ParseConfig(databaseUrl) if err != nil { log.Fatalln(err.Error()) } ctx := context.Background() conn, err := instapgx.ConnectConfig(ctx, sensor, conf) if err != nil { log.Fatalln(err.Error()) } row := conn.QueryRow(ctx, "select name, statement from pg_prepared_statements") var name, stmt string err = row.Scan(&name, &stmt) if err != nil { log.Fatalln(err.Error()) }
Output:
func (*Conn) QueryFunc ¶
func (c *Conn) QueryFunc(ctx context.Context, sql string, args []interface{}, scans []interface{}, f func(pgx.QueryFuncRow) error) (pgconn.CommandTag, error)
QueryFunc wraps (*pgx.Conn).QueryFunc method and adds tracing to it.
Example ¶
databaseUrl := "postgres://postgres:mysecretpassword@localhost/postgres" sensor := instana.NewSensor("pgx-example-query-func") conf, err := pgx.ParseConfig(databaseUrl) if err != nil { log.Fatalln(err.Error()) } ctx := context.Background() conn, err := instapgx.ConnectConfig(ctx, sensor, conf) if err != nil { log.Fatalln(err.Error()) } var a, b int _, err = conn.QueryFunc( ctx, "select n, n * 2 from generate_series(1, $1) n", []interface{}{3}, []interface{}{&a, &b}, func(pgx.QueryFuncRow) error { return nil }, ) if err != nil { log.Fatalln(err.Error()) }
Output:
func (*Conn) QueryRow ¶
QueryRow wraps (*pgx.Conn).QueryRow method and adds tracing to it. It requires to calling Scan method on the returned row to finish a span.
func (*Conn) SendBatch ¶
SendBatch wraps (*pgx.Conn).SendBatch method and adds tracing to it. Call the EnableDetailedBatchMode(), to have sql statements in the span. Amount of the sql statements that might be reported are limited.
Example ¶
databaseUrl := "postgres://postgres:mysecretpassword@localhost/postgres" sensor := instana.NewSensor("pgx-example-send-batch") conf, err := pgx.ParseConfig(databaseUrl) if err != nil { log.Fatalln(err.Error()) } ctx := context.Background() conn, err := instapgx.ConnectConfig(ctx, sensor, conf) if err != nil { log.Fatalln(err.Error()) } instapgx.EnableDetailedBatchMode() b := &pgx.Batch{} b.Queue("select name, statement from pg_prepared_statements") b.Queue("select n, n * 2 from generate_series(1, $1) n", 1) br := conn.SendBatch(ctx, b) _, err = br.Query() if err != nil { log.Fatalln(err.Error()) } _, err = br.Exec() if err != nil { log.Fatalln(err.Error()) } err = br.Close() if err != nil { log.Fatalln(err.Error()) }
Output: