Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/smacker/opentracing-gorm
OpenTracing instrumentation for GORM.
https://github.com/smacker/opentracing-gorm
golang gorm opentracing
Last synced: 12 days ago
JSON representation
OpenTracing instrumentation for GORM.
- Host: GitHub
- URL: https://github.com/smacker/opentracing-gorm
- Owner: smacker
- License: mit
- Created: 2017-07-06T08:09:46.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-08-18T09:44:09.000Z (over 4 years ago)
- Last Synced: 2024-11-02T02:42:33.371Z (19 days ago)
- Topics: golang, gorm, opentracing
- Language: Go
- Homepage:
- Size: 9.77 KB
- Stars: 47
- Watchers: 3
- Forks: 32
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# opentracing gorm
[OpenTracing](http://opentracing.io/) instrumentation for [GORM](http://gorm.io/).
## 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:
```go
var gDB *gorm.DBfunc 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](LICENSE)