Documentation
¶
Overview ¶
Package gorm provides helper functions for tracing the jinzhu/gorm package (https://github.com/jinzhu/gorm).
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Open ¶
Open opens a new (traced) database connection. The used dialect must be formerly registered using (gopkg.in/DataDog/dd-trace-go.v1/contrib/database/sql).Register.
Example ¶
package main
import (
"log"
"github.com/jinzhu/gorm"
"github.com/lib/pq"
sqltrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/database/sql"
gormtrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/jinzhu/gorm"
)
func main() {
// Register augments the provided driver with tracing, enabling it to be loaded by gormtrace.Open.
sqltrace.Register("postgres", &pq.Driver{}, sqltrace.WithServiceName("my-service"))
// Open the registered driver, allowing all uses of the returned *gorm.DB to be traced.
db, err := gormtrace.Open("postgres", "postgres://pqgotest:password@localhost/pqgotest?sslmode=disable")
defer db.Close()
if err != nil {
log.Fatal(err)
}
user := struct {
gorm.Model
Name string
}{}
// All calls through gorm.DB are now traced.
db.Where("name = ?", "jinzhu").First(&user)
}
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.