sqlx

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2017 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package sqlxtraced provides a traced version of the "jmoiron/sqlx" package For more information about the API, see https://godoc.org/github.com/DataDog/dd-trace-go/tracer/contrib/sqltraced.

Example

The API to trace sqlx calls is the same as sqltraced. See https://godoc.org/github.com/DataDog/dd-trace-go/tracer/contrib/sqltraced for more information on how to use it.

package main

import (
	"github.com/jmoiron/sqlx"
	"github.com/lib/pq"

	sqlxtrace "github.com/DataDog/dd-trace-go/contrib/jmoiron/sqlx"
)

func main() {
	// OpenTraced will first register a traced version of the driver and then will return the sqlx.DB object
	// that holds the connection with the database.
	// The third argument is used to specify the name of the service under which traces will appear in the Datadog app.
	db, _ := sqlxtrace.OpenTraced(&pq.Driver{}, "postgres://pqgotest:password@localhost/pqgotest?sslmode=disable", "web-backend")

	// All calls through sqlx API will then be traced.
	query, args, _ := sqlx.In("SELECT * FROM users WHERE level IN (?);", []int{4, 6, 7})
	query = db.Rebind(query)
	rows, _ := db.Query(query, args...)
	defer rows.Close()
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open

func Open(driverName, dataSourceName, service string) (*sqlx.DB, error)

Open returns a traced version of *sqlx.DB.

func OpenTraced

func OpenTraced(driver driver.Driver, dataSourceName, service string, trcv ...*tracer.Tracer) (*sqlx.DB, error)

OpenTraced will first register the traced version of the `driver` if not yet registered and will then open a connection with it. This is usually the only function to use when there is no need for the granularity offered by Register and Open. The last argument is optional and allows you to pass a custom tracer.

func Register

func Register(driverName string, driver driver.Driver, trcv ...*tracer.Tracer)

Register registers a traced version of `driver`.

Types

This section is empty.

Jump to

Keyboard shortcuts

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