Still using Jaeger/Sentry? Uptrace is an open source distributed tracing tool that uses OpenTelemetry to monitor performance, errors, and logs.
GORM OpenTelemetry Instrumentation
Installation
To install GORM OpenTelemetry instrumentation:
go get github.com/uptrace/opentelemetry-go-extra/otelgorm
Usage
To instrument GORM, you need to install the plugin provided by otelgorm:
import (
"github.com/uptrace/opentelemetry-go-extra/otelgorm"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
db, err := gorm.Open(sqlite.Open("file::memory:?cache=shared"), &gorm.Config{})
if err != nil {
panic(err)
}
if err := db.Use(otelgorm.NewPlugin()); err != nil {
panic(err)
}
And then use db.WithContext(ctx)
to propagate the active span via context:
var num int
if err := db.WithContext(ctx).Raw("SELECT 42").Scan(&num).Error; err != nil {
panic(err)
}
What's next?
Next, instrument more operations, for example, database queries, errors, and logs. You can also learn about OpenTelemetry Go Tracing API to create your own instrumentations.
Popular instrumentations:
See also: