Documentation ¶
Overview ¶
Package splunksqlx provides instrumentation for the github.com/jmoiron/sqlx package.
Index ¶
- func Connect(driverName, dataSourceName string, opts ...splunksql.Option) (*sqlx.DB, error)
- func MustConnect(driverName, dataSourceName string, opts ...splunksql.Option) *sqlx.DB
- func MustOpen(driverName, dataSourceName string, opts ...splunksql.Option) *sqlx.DB
- func Open(driverName, dataSourceName string, opts ...splunksql.Option) (*sqlx.DB, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Connect ¶
Connect connects to a database with a traced connection and verifies with a ping. The driver used to connect must already be registered by the driver package.
func MustConnect ¶
MustConnect is the same as Connect, but panics on error.
func Open ¶
Open opens a new (traced) connection to the database using the given driver and source. The driver must already be registered by the driver package.
Example ¶
package main import ( "log" "github.com/jmoiron/sqlx" "github.com/unionai/splunk-otel-go/instrumentation/github.com/jmoiron/sqlx/splunksqlx" ) func main() { // This assumes the instrumented driver, // "github.com/unionai/splunk-otel-go/instrumentation/github.com/jackc/pgx/splunkpgx", // is imported. That will ensure the driver and the instrumentation setup // for the driver are registered with the appropriate packages. db, err := splunksqlx.Open("pgx", "postgres://localhost/db") if err != nil { log.Print(err) return } defer db.Close() // All calls through the sqlx API are now traced. query, args, err := sqlx.In("SELECT * FROM users WHERE level IN (?);", []int{4, 6, 7}) if err != nil { log.Print(err) return } query = db.Rebind(query) rows, err := db.Queryx(query, args...) //nolint:sqlclosecheck // False positive: https://github.com/ryanrolds/sqlclosecheck/issues/35. if err != nil { log.Print(err) return } defer rows.Close() /* ... */ }
Output:
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.