Documentation
¶
Overview ¶
Package sql provides functions to trace the database/sql package (https://golang.org/pkg/database/sql). It will automatically augment operations such as connections, statements and transactions with tracing.
We start by telling the package which driver we will be using. For example, if we are using "github.com/lib/pq", we would do as follows:
sqltrace.Register("pq", pq.Driver{}) db, err := sqltrace.Open("pq", "postgres://pqgotest:password@localhost...")
The rest of our application would continue as usual, but with tracing enabled.
Index ¶
- func Open(driverName, dataSourceName string, opts ...Option) (*sql.DB, error)
- func OpenDB(c driver.Connector, opts ...Option) *sql.DB
- func Register(driverName string, driver driver.Driver, opts ...RegisterOption)
- func WithSpanTags(ctx context.Context, tags map[string]string) context.Context
- type Option
- type RegisterOption
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Open ¶
Open returns connection to a DB using the traced version of the given driver. In order for Open to work, the driver must first be registered using Register. If this did not occur, Open will return an error.
func OpenDB ¶
OpenDB returns connection to a DB using the traced version of the given driver. In order for OpenDB to work, the driver must first be registered using Register. If this did not occur, OpenDB will panic.
func Register ¶
func Register(driverName string, driver driver.Driver, opts ...RegisterOption)
Register tells the sql integration package about the driver that we will be tracing. It must be called before Open, if that connection is to be traced. It uses the driverName suffixed with ".db" as the default service name.
Types ¶
type Option ¶
type Option func(*config)
Option represents an option that can be passed to Register, Open or OpenDB.
func WithAnalytics ¶
WithAnalytics enables Trace Analytics for all started spans.
func WithAnalyticsRate ¶
WithAnalyticsRate sets the sampling rate for Trace Analytics events correlated to started spans.
func WithChildSpansOnly ¶
func WithChildSpansOnly() Option
WithChildSpansOnly causes spans to be created only when there is an existing parent span in the Context.
func WithDSN ¶
WithDSN allows the data source name (DSN) to be provided when using OpenDB and a driver.Connector. The value is used to automatically set tags on spans.
func WithSQLCommentInjection ¶
func WithSQLCommentInjection(mode tracer.SQLCommentInjectionMode) Option
WithSQLCommentInjection enables injection of tags as sql comments on traced queries. This includes dynamic values like span id, trace id and sampling priority which can make queries unique for some cache implementations. Use WithStaticTagsCommentInjection if this is a concern.
func WithServiceName ¶
WithServiceName sets the given service name when registering a driver, or opening a database connection.
type RegisterOption ¶
type RegisterOption = Option
RegisterOption has been deprecated in favor of Option.