splunksqlx

package module
v1.15.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2024 License: Apache-2.0 Imports: 2 Imported by: 1

README

Splunk Instrumentation for github.com/jmoiron/sqlx

Go Reference

This package provides instrumentation for the github.com/jmoiron/sqlx package. The instrumentation is provided by wrapping the splunksql instrumentation.

Getting Started

To start using this instrumentation, replace the use of the sqlx.Open and sqlx.Connect kind of functions with the equivalent from this package. The returned values can then be use as normal with the sqlx package.

An example of this can be found here.

Documentation

Overview

Package splunksqlx provides instrumentation for the github.com/jmoiron/sqlx package.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect(driverName, dataSourceName string, opts ...splunksql.Option) (*sqlx.DB, error)

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

func MustConnect(driverName, dataSourceName string, opts ...splunksql.Option) *sqlx.DB

MustConnect is the same as Connect, but panics on error.

func MustOpen

func MustOpen(driverName, dataSourceName string, opts ...splunksql.Option) *sqlx.DB

MustOpen is the same as Open, but panics on error.

func Open

func Open(driverName, dataSourceName string, opts ...splunksql.Option) (*sqlx.DB, error)

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/signalfx/splunk-otel-go/instrumentation/github.com/jmoiron/sqlx/splunksqlx"
)

func main() {
	// This assumes the instrumented driver,
	// "github.com/signalfx/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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL