Opentelemetry for gorm
- support tracing gorm by Hook
Create
Query
Delete
Update
Row
Raw
- Collect DB Status
- Use logrus replace gorm default logger
- Use hook to report span message
- Out-of-the-box default opentelemetry provider
- Support setting via environment variables
package main
import(
"gorm.io/gorm/logger"
"gorm.io/plugin/opentelemetry/logging/logrus"
)
func init(){
logger := logger.New(
logrus.NewWriter(),
logger.Config{
SlowThreshold: time.Millisecond,
LogLevel: logger.Warn,
Colorful: false,
},
)
db, err := gorm.Open(sqlite.Open("file::memory:?cache=shared"),&gorm.Config{Logger: logger})
}
package main
import(
"gorm.io/plugin/opentelemetry/tracing"
)
func init(){
db, err := gorm.Open(sqlite.Open("file::memory:?cache=shared"), &gorm.Config{})
if err != nil {
panic(err)
}
if err := db.Use(tracing.NewPlugin()); err != nil {
panic(err)
}
}
package main
import(
"gorm.io/plugin/opentelemetry/tracing"
)
func init(){
db, err := gorm.Open(sqlite.Open("file::memory:?cache=shared"), &gorm.Config{})
if err != nil {
panic(err)
}
if err := db.Use(tracing.NewPlugin(tracing.WithoutMetrics())); err != nil {
panic(err)
}
}
See examples