otgorm

package module
v0.0.0-...-ced7795 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2020 License: MIT Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

opentracing gorm

OpenTracing instrumentation for GORM.

Install

go get -u github.com/smacker/opentracing-gorm

Usage

  1. Call otgorm.AddGormCallbacks(db) with an instance of your *gorm.DB.
  2. Clone db db = otgorm.SetSpanToGorm(ctx, db) with a span.

Example:

var gDB *gorm.DB

func init() {
    gDB = initDB()
}

func initDB() *gorm.DB {
    db, err := gorm.Open("sqlite3", ":memory:")
    if err != nil {
        panic(err)
    }
    // register callbacks must be called for a root instance of your gorm.DB
    otgorm.AddGormCallbacks(db)
    return db
}

func Handler(ctx context.Context) {
    span, ctx := opentracing.StartSpanFromContext(ctx, "handler")
    defer span.Finish()

    // clone db with proper context
    db := otgorm.SetSpanToGorm(ctx, gDB)

    // sql query
    db.First
}

Call to the Handler function would create sql span with table name, sql method and sql statement as a child of handler span.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddGormCallbacks

func AddGormCallbacks(db *gorm.DB)

AddGormCallbacks adds callbacks for tracing, you should call SetSpanToGorm to make them work

func SetSpanToGorm

func SetSpanToGorm(ctx context.Context, db *gorm.DB) *gorm.DB

SetSpanToGorm sets span to gorm settings, returns cloned DB

Types

This section is empty.

Jump to

Keyboard shortcuts

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