sqltrace
A low-code intrusion library that provides SQL tracing capabilities, suitable for any relational database (Sqlite3, MySQL, Oracle, SQL Server PostgreSQL, TiDB, etc.) and ORM libraries for various relational database (gorm, xorm, sqlx, etc.)
😜 installation
go get -u github.com/chenquan/sqltrace
👏 how to use
native
package main
import (
"context"
"database/sql"
"fmt"
"github.com/chenquan/sqltrace"
"github.com/mattn/go-sqlite3"
_ "github.com/mattn/go-sqlite3"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/trace"
)
func main() {
// Create a sqlite3 driver with link tracking
driver := sqltrace.NewDriver(sqltrace.Config{
Name: "sqlite3_trace",
DataSourceName: "sqlite3",
Endpoint: "http://localhost:14268/api/traces",
Sampler: 1,
Batcher: "jaeger",
}, &sqlite3.SQLiteDriver{})
defer sqltrace.StopAgent()
// register new driver
sql.Register("sqlite3_trace", driver)
// open database
db, err := sql.Open("sqlite3_trace", "identifier.sqlite")
if err != nil {
panic(err)
}
tracer := otel.
…