Skip to content

OpenTracing-compatible SQL driver wrapper for Golang

License

Notifications You must be signed in to change notification settings

QubitProducts/opentracing-sql

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenTracing-compatible SQL driver wrapper for Golang

This package is an implementation of a SQL driver wrapper with tracing capabilities, compatible with Opentracing API.

Usage

Register a new database driver by passing an instance created by calling NewTracingDriver:

var driver *sql.Driver
var tracer opentracing.Tracer
// init driver, tracer.
...
sql.Register("opentracing-sql", otsql.NewTracingDriver(driver, tracer))
db, err := sql.Open("opentracing-sql", ...)
// use db handle as usual.

By default, runtime-based naming function will be used, which will set the span name according to the name of the function being called (e.g. conn.QueryContext).

It's also possible to specify your own naming function:

otsql.NewTracingDriver(driver, tracer, otsql.SpanNameFunction(customNameFunction))

Name function format:

type SpanNameFunc func(context.Context) string

Note that only calls to context-aware DB functions will be traced (e.g. db.QueryContext).

Comparison with existing packages

There is an existing package https://github.com/ExpansiveWorlds/instrumentedsql which uses the same approach by wrapping an existing driver with a tracer, however the current implementation provides the following features:

  • Pass custom naming function to name spans according to your needs.
  • Option to enable/disable logging of SQL queries.

The following features from instrumentedsql package are not supported:

  • Passing a custom logger.
  • Support of cloud.google.com/go/trace.
  • Don't log exact query args.
  • Creating spans for LastInsertId, RowsAffected.

Documentation

GoDoc documentation

References

OpenTracing project

About

OpenTracing-compatible SQL driver wrapper for Golang

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%