beeline-go: github.com/honeycombio/beeline-go/wrappers/hnysqlx Index | Examples | Files

package hnysqlx

import "github.com/honeycombio/beeline-go/wrappers/hnysqlx"

Package hnysqlx wraps `jmoiron/sqlx` to emit one Honeycomb event per DB call.

After opening a DB connection, replace the *sqlx.DB object with a *hnysqlx.DB object. The *hnysqlx.DB struct implements all the same functions as the normal *sqlx.DB struct, and emits an event to Honeycomb with details about the SQL event made.

If you're using transactions, named statements, and so on, there will be a similar swap of `*sqlx` to `*hnysqlx` for each of the additional types you're using.

Additionally, if hnysqlx is used in conjunction with one of the Honeycomb HTTP wrappers *and* you're using the context-aware versions of the SQL calls, the trace ID picked up in the HTTP event will appear in the SQL event. This will ensure you can track any SQL call back to the HTTP event that triggered it.

It is strongly suggested that you use the context-aware version of all calls whenever possible; doing so not only lets you cancel your database calls, but dramatically increases the value of the SQL isntrumentation by letting you tie it back to individual HTTP requests.

If you need to differentiate multiple DB connections, there is a *libhoney.Builder associated with the *hnysqlx.DB (as well as with transactions and statements). Adding fields to this builder will add those fields to all events generated from that DB connection.

Code:

// Initialize beeline. The only required field is WriteKey.
beeline.Init(beeline.Config{
    WriteKey: "abcabc123123",
    Dataset:  "sqlx",
    // for demonstration, send the event to STDOUT intead of Honeycomb.
    // Remove the STDOUT setting when filling in a real write key.
    STDOUT: true,
})
// and make sure we close to force flushing all pending events before shutdown
defer beeline.Close()

// open a regular sqlx connection
odb, err := sqlx.Open("mysql", "root:@tcp(127.0.0.1)/donut")
if err != nil {
    fmt.Println("connection err")
}

// replace it with a wrapped hnysqlx.DB
db := hnysqlx.WrapDB(odb)
// and start up a trace for these statements to join
ctx, span := beeline.StartSpan(context.Background(), "start")
defer span.Send()

db.MustExecContext(ctx, "insert into flavors (flavor) values ('rose')")
fv := "rose"
rows, err := db.QueryxContext(ctx, "SELECT id FROM flavors WHERE flavor=?", fv)
if err != nil {
    log.Fatal(err)
}
defer rows.Close()
for rows.Next() {
    var id int
    if err := rows.Scan(&id); err != nil {
        log.Fatal(err)
    }
    fmt.Printf("%d is %s\n", id, fv)
}
if err := rows.Err(); err != nil {
    log.Fatal(err)
}

Index

Examples

Package Files

doc.go sqlx.go

type DB Uses

type DB struct {

    // Builder is available in case you wish to add fields to every SQL event
    // that will be created.
    Builder *libhoney.Builder

    Mapper *reflectx.Mapper
    // contains filtered or unexported fields
}

func WrapDB Uses

func WrapDB(s *sqlx.DB) *DB

func (*DB) BeginTxx Uses

func (db *DB) BeginTxx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)

func (*DB) Beginx Uses

func (db *DB) Beginx() (*Tx, error)

func (*DB) Close Uses

func (db *DB) Close() error

not implemented in the wrapper - should just fall through to the superclass

func (*DB) Driver Uses

func (db *DB) Driver() driver.Driver

func (*DB) Exec Uses

func (db *DB) Exec(query string, args ...interface{}) (sql.Result, error)

func (*DB) ExecContext Uses

func (db *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

func (*DB) Get Uses

func (db *DB) Get(dest interface{}, query string, args ...interface{}) error

func (*DB) GetContext Uses

func (db *DB) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

func (*DB) MapperFunc Uses

func (db *DB) MapperFunc(mf func(string) string)

func (*DB) MustBegin Uses

func (db *DB) MustBegin() *Tx

func (*DB) MustBeginTx Uses

func (db *DB) MustBeginTx(ctx context.Context, opts *sql.TxOptions) *Tx

func (*DB) MustExec Uses

func (db *DB) MustExec(query string, args ...interface{}) sql.Result

func (*DB) MustExecContext Uses

func (db *DB) MustExecContext(ctx context.Context, query string, args ...interface{}) sql.Result

func (*DB) NamedExec Uses

func (db *DB) NamedExec(query string, arg interface{}) (sql.Result, error)

func (*DB) NamedExecContext Uses

func (db *DB) NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error)

func (*DB) NamedQuery Uses

func (db *DB) NamedQuery(query string, arg interface{}) (*sqlx.Rows, error)

func (*DB) NamedQueryContext Uses

func (db *DB) NamedQueryContext(ctx context.Context, query string, arg interface{}) (*sqlx.Rows, error)

func (*DB) Ping Uses

func (db *DB) Ping() error

func (*DB) PingContext Uses

func (db *DB) PingContext(ctx context.Context) error

func (*DB) PrepareNamed Uses

func (db *DB) PrepareNamed(query string) (*NamedStmt, error)

func (*DB) PrepareNamedContext Uses

func (db *DB) PrepareNamedContext(ctx context.Context, query string) (*NamedStmt, error)

func (*DB) Preparex Uses

func (db *DB) Preparex(query string) (*Stmt, error)

func (*DB) PreparexContext Uses

func (db *DB) PreparexContext(ctx context.Context, query string) (*Stmt, error)

func (*DB) Query Uses

func (db *DB) Query(query string, args ...interface{}) (*sql.Rows, error)

func (*DB) QueryContext Uses

func (db *DB) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

func (*DB) QueryRow Uses

func (db *DB) QueryRow(query string, args ...interface{}) *sql.Row

func (*DB) QueryRowContext Uses

func (db *DB) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row

func (*DB) QueryRowx Uses

func (db *DB) QueryRowx(query string, args ...interface{}) *sqlx.Row

func (*DB) QueryRowxContext Uses

func (db *DB) QueryRowxContext(ctx context.Context, query string, args ...interface{}) *sqlx.Row

func (*DB) Queryx Uses

func (db *DB) Queryx(query string, args ...interface{}) (*sqlx.Rows, error)

func (*DB) QueryxContext Uses

func (db *DB) QueryxContext(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error)

func (*DB) Rebind Uses

func (db *DB) Rebind(query string) string

func (*DB) Select Uses

func (db *DB) Select(dest interface{}, query string, args ...interface{}) error

func (*DB) SelectContext Uses

func (db *DB) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

func (*DB) SetConnMaxLifetime Uses

func (db *DB) SetConnMaxLifetime(d time.Duration)

func (*DB) SetMaxIdleConns Uses

func (db *DB) SetMaxIdleConns(n int)

func (*DB) SetMaxOpenConns Uses

func (db *DB) SetMaxOpenConns(n int)

func (*DB) Stats Uses

func (db *DB) Stats() sql.DBStats

type NamedStmt Uses

type NamedStmt struct {
    Builder *libhoney.Builder
    // contains filtered or unexported fields
}

func (*NamedStmt) Close Uses

func (n *NamedStmt) Close() error

func (*NamedStmt) Exec Uses

func (n *NamedStmt) Exec(arg interface{}) (sql.Result, error)

func (*NamedStmt) ExecContext Uses

func (n *NamedStmt) ExecContext(ctx context.Context, arg interface{}) (sql.Result, error)

func (*NamedStmt) Get Uses

func (n *NamedStmt) Get(dest interface{}, arg interface{}) error

func (*NamedStmt) GetContext Uses

func (n *NamedStmt) GetContext(ctx context.Context, dest interface{}, arg interface{}) error

func (*NamedStmt) GetWrappedNamedStmt Uses

func (n *NamedStmt) GetWrappedNamedStmt() *sqlx.NamedStmt

func (*NamedStmt) MustExec Uses

func (n *NamedStmt) MustExec(arg interface{}) sql.Result

func (*NamedStmt) MustExecContext Uses

func (n *NamedStmt) MustExecContext(ctx context.Context, arg interface{}) sql.Result

func (*NamedStmt) Query Uses

func (n *NamedStmt) Query(arg interface{}) (*sql.Rows, error)

func (*NamedStmt) QueryContext Uses

func (n *NamedStmt) QueryContext(ctx context.Context, arg interface{}) (*sql.Rows, error)

func (*NamedStmt) QueryRow Uses

func (n *NamedStmt) QueryRow(arg interface{}) *sqlx.Row

func (*NamedStmt) QueryRowContext Uses

func (n *NamedStmt) QueryRowContext(ctx context.Context, arg interface{}) *sqlx.Row

func (*NamedStmt) QueryRowx Uses

func (n *NamedStmt) QueryRowx(arg interface{}) *sqlx.Row

func (*NamedStmt) QueryRowxContext Uses

func (n *NamedStmt) QueryRowxContext(ctx context.Context, arg interface{}) *sqlx.Row

func (*NamedStmt) Queryx Uses

func (n *NamedStmt) Queryx(arg interface{}) (*sqlx.Rows, error)

func (*NamedStmt) QueryxContext Uses

func (n *NamedStmt) QueryxContext(ctx context.Context, arg interface{}) (*sqlx.Rows, error)

func (*NamedStmt) Select Uses

func (n *NamedStmt) Select(dest interface{}, arg interface{}) error

func (*NamedStmt) SelectContext Uses

func (n *NamedStmt) SelectContext(ctx context.Context, dest interface{}, arg interface{}) error

func (*NamedStmt) Unsafe Uses

func (n *NamedStmt) Unsafe() *NamedStmt

type Stmt Uses

type Stmt struct {
    Builder *libhoney.Builder
    Mapper  *reflectx.Mapper
    // contains filtered or unexported fields
}

func (*Stmt) Get Uses

func (s *Stmt) Get(dest interface{}, args ...interface{}) error

func (*Stmt) GetContext Uses

func (s *Stmt) GetContext(ctx context.Context, dest interface{}, args ...interface{}) error

func (*Stmt) MustExec Uses

func (s *Stmt) MustExec(args ...interface{}) sql.Result

func (*Stmt) MustExecContext Uses

func (s *Stmt) MustExecContext(ctx context.Context, args ...interface{}) sql.Result

func (*Stmt) QueryRowx Uses

func (s *Stmt) QueryRowx(args ...interface{}) *sqlx.Row

func (*Stmt) QueryRowxContext Uses

func (s *Stmt) QueryRowxContext(ctx context.Context, args ...interface{}) *sqlx.Row

func (*Stmt) Queryx Uses

func (s *Stmt) Queryx(args ...interface{}) (*sqlx.Rows, error)

func (*Stmt) QueryxContext Uses

func (s *Stmt) QueryxContext(ctx context.Context, args ...interface{}) (*sqlx.Rows, error)

func (*Stmt) Select Uses

func (s *Stmt) Select(dest interface{}, args ...interface{}) error

func (*Stmt) SelectContext Uses

func (s *Stmt) SelectContext(ctx context.Context, dest interface{}, args ...interface{}) error

func (*Stmt) Unsafe Uses

func (s *Stmt) Unsafe() *Stmt

type Tx Uses

type Tx struct {
    Builder *libhoney.Builder
    Mapper  *reflectx.Mapper
    // contains filtered or unexported fields
}

func (*Tx) BindNamed Uses

func (tx *Tx) BindNamed(query string, arg interface{}) (string, []interface{}, error)

func (*Tx) Commit Uses

func (tx *Tx) Commit() error

func (*Tx) CommitContext Uses

func (tx *Tx) CommitContext(ctx context.Context) error

CommitContext is the same as `Commit`, but is passed a context to ensure that commits show up as part of a parent trace

func (*Tx) DriverName Uses

func (tx *Tx) DriverName() string

func (*Tx) Exec Uses

func (tx *Tx) Exec(query string, args ...interface{}) (sql.Result, error)

func (*Tx) ExecContext Uses

func (tx *Tx) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

func (*Tx) Get Uses

func (tx *Tx) Get(dest interface{}, query string, args ...interface{}) error

func (*Tx) GetContext Uses

func (tx *Tx) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

func (*Tx) GetWrappedTx Uses

func (tx *Tx) GetWrappedTx() *sqlx.Tx

func (*Tx) MustExec Uses

func (tx *Tx) MustExec(query string, args ...interface{}) sql.Result

func (*Tx) MustExecContext Uses

func (tx *Tx) MustExecContext(ctx context.Context, query string, args ...interface{}) sql.Result

func (*Tx) NamedExec Uses

func (tx *Tx) NamedExec(query string, arg interface{}) (sql.Result, error)

func (*Tx) NamedExecContext Uses

func (tx *Tx) NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error)

func (*Tx) NamedQuery Uses

func (tx *Tx) NamedQuery(query string, arg interface{}) (*sqlx.Rows, error)

func (*Tx) NamedQueryContext Uses

func (tx *Tx) NamedQueryContext(ctx context.Context, query string, arg interface{}) (*sqlx.Rows, error)

func (*Tx) NamedStmt Uses

func (tx *Tx) NamedStmt(stmt *NamedStmt) *NamedStmt

func (*Tx) NamedStmtContext Uses

func (tx *Tx) NamedStmtContext(ctx context.Context, stmt *NamedStmt) *NamedStmt

func (*Tx) PrepareNamed Uses

func (tx *Tx) PrepareNamed(query string) (*NamedStmt, error)

func (*Tx) PrepareNamedContext Uses

func (tx *Tx) PrepareNamedContext(ctx context.Context, query string) (*NamedStmt, error)

func (*Tx) Preparex Uses

func (tx *Tx) Preparex(query string) (*Stmt, error)

func (*Tx) PreparexContext Uses

func (tx *Tx) PreparexContext(ctx context.Context, query string) (*Stmt, error)

func (*Tx) Query Uses

func (tx *Tx) Query(query string, args ...interface{}) (*sql.Rows, error)

func (*Tx) QueryContext Uses

func (tx *Tx) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

func (*Tx) QueryRow Uses

func (tx *Tx) QueryRow(query string, args ...interface{}) *sql.Row

func (*Tx) QueryRowContext Uses

func (tx *Tx) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row

func (*Tx) QueryRowx Uses

func (tx *Tx) QueryRowx(query string, args ...interface{}) *sqlx.Row

func (*Tx) QueryRowxContext Uses

func (tx *Tx) QueryRowxContext(ctx context.Context, query string, args ...interface{}) *sqlx.Row

func (*Tx) Queryx Uses

func (tx *Tx) Queryx(query string, args ...interface{}) (*sqlx.Rows, error)

func (*Tx) QueryxContext Uses

func (tx *Tx) QueryxContext(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error)

func (*Tx) Rebind Uses

func (tx *Tx) Rebind(query string) string

func (*Tx) Rollback Uses

func (tx *Tx) Rollback() error

func (*Tx) RollbackContext Uses

func (tx *Tx) RollbackContext(ctx context.Context) error

func (*Tx) Select Uses

func (tx *Tx) Select(dest interface{}, query string, args ...interface{}) error

func (*Tx) SelectContext Uses

func (tx *Tx) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

func (*Tx) Stmtx Uses

func (tx *Tx) Stmtx(stmt *Stmt) *Stmt

func (*Tx) StmtxContext Uses

func (tx *Tx) StmtxContext(ctx context.Context, stmt *Stmt) *Stmt

func (*Tx) Unsafe Uses

func (tx *Tx) Unsafe() *Tx

Package hnysqlx imports 10 packages (graph) and is imported by 3 packages. Updated 2018-09-13. Refresh now. Tools for package owners.