Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/go-gorm/opentelemetry
opentelemetry for gorm
https://github.com/go-gorm/opentelemetry
gorm logger metrics opentelemetry trace
Last synced: 2 days ago
JSON representation
opentelemetry for gorm
- Host: GitHub
- URL: https://github.com/go-gorm/opentelemetry
- Owner: go-gorm
- License: mit
- Created: 2022-07-07T02:04:30.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-12-11T01:05:35.000Z (23 days ago)
- Last Synced: 2024-12-25T04:05:03.939Z (9 days ago)
- Topics: gorm, logger, metrics, opentelemetry, trace
- Language: Go
- Homepage:
- Size: 490 KB
- Stars: 97
- Watchers: 3
- Forks: 25
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# opentelemetry
[Opentelemetry](https://opentelemetry.io/) for [gorm](https://github.com/go-gorm/gorm)
## Feature
### Tracing
- support tracing gorm by Hook `Create` `Query` `Delete` `Update` `Row` `Raw`
### Metrics
- Collect DB Status
### Logging
- Use logrus replace gorm default logger
- Use hook to report span message
### Provider
- Out-of-the-box default opentelemetry provider
- Support setting via environment variables## How to Use ?
### Set logger
~~~go
package mainimport(
"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})
}
~~~
### Set tracing and metrics~~~go
package mainimport(
"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)
}
}
~~~### Set only tracing
~~~go
package mainimport(
"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)
}
}
~~~### More info
See [examples](examples/)