Wrapper
Wrapper is a developer friendly toolkit, which will provide a set of wrapper to integrate 3rd Open Source Project with ezbuy codebase easily and efficiently.
- Make middleware intergration internally and standardly
- Build a proxy between 3rd and ezbuy codebase
Now database tracer provides a jaeger tracer client to trace SQL query context . Here are some sample usages for different go database package users.
You can find the full sample usage in test file as well.
For sqlx users
wp := database.NewMySQLTracerWrapper()
originExecContextFunc := database.ExecContextFunc(func(ctx context.Context, query string, args ...interface{}) (sql.Result, error) {
db, err:= sqlx.Connect("mysql","test:test@(localhost:3306)/test")
if err != nil { // handle error
}
return db.ExecContext(ctx, query, args...)
})
res,err := wp.WrapExecContext(originExecContextFunc,sql,args...)
if err != nil{
// handle error
}
// handle res
For redis-orm users
redis-orm users will do exactly nothing with this incoming changes , we will inject it in the generate code, and also ,we will add a set of db functions with context.
All you need to do is just type go get -u github.com/ezbuy/redis-orm
To speak more generally, database tracer Wrapper accept a Query/ExecContextFunc and return you the same Query/ExecContextFunc(with tracer internal).
So, all sql packages which provide the Query/ExecContextFunc can add the jaeger tracer within one simple function.
- Hide select columns:
database.IgnoreSelectColumnsOption
- Show real args instead of
?
:database.RawQueryOption
- More custmized options are welcome.
// how to use options
type myQueryBuilder struct{}
func (qb myQueryBuilder) QueryBuilder()func(query string, args ...interface{}) string{
return func(query string,args ...interface{}) string{
var res string
// handle query and args
return res
}
}
mqb:= myQueryBuilder{}
wp:= database.NewMySQLTracerWrapper(database.RawQueryOption,database.IgnoreSelectColumnsOption,mqb)
Issues and PRs are welcome.