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 ContextFromDB ¶
ContextFromDB returns any context previously attached to db using WithContext, otherwise returning context.Background.
func Open ¶
Open opens a new (traced) database connection. The used dialect must be formerly registered using (github.com/zleague/dd-trace-go/contrib/database/sql).Register.
Example ¶
package main import ( "log" "github.com/jinzhu/gorm" "github.com/lib/pq" sqltrace "github.com/zleague/dd-trace-go/contrib/database/sql" gormtrace "github.com/zleague/dd-trace-go/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) }
Output:
func WithCallbacks ¶
WithCallbacks registers callbacks to the gorm.DB for tracing. It should be called once, after opening the db. The callbacks are triggered by Create, Update, Delete, Query and RowQuery operations.
Types ¶
type Option ¶
type Option func(*config)
Option represents an option that can be passed to Register, Open or OpenDB.
func WithAnalytics ¶
WithAnalytics enables Trace Analytics for all started spans.
func WithAnalyticsRate ¶
WithAnalyticsRate sets the sampling rate for Trace Analytics events correlated to started spans.
func WithCustomTag ¶
WithCustomTag will cause the given tagFn to be evaluated after executing a query and attach the result to the span tagged by the key.
func WithErrorCheck ¶
WithErrorCheck specifies a function fn which determines whether the passed error should be marked as an error. The fn is called whenever a gorm operation finishes with an error
func WithServiceName ¶
WithServiceName sets the given service name when registering a driver, or opening a database connection.