dd-trace-go.v1: gopkg.in/DataDog/dd-trace-go.v1/contrib/jinzhu/gorm Index | Examples | Files

package gorm

import "gopkg.in/DataDog/dd-trace-go.v1/contrib/jinzhu/gorm"

Package gorm provides helper functions for tracing the jinzhu/gorm package (https://github.com/jinzhu/gorm).



Package Files

gorm.go option.go

func ContextFromDB Uses

func ContextFromDB(db *gorm.DB) context.Context

ContextFromDB returns any context previously attached to db using WithContext, otherwise returning context.Background.

func Open Uses

func Open(dialect, source string, opts ...Option) (*gorm.DB, error)

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.


// 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 {

user := struct {
    Name string

// All calls through gorm.DB are now traced.
db.Where("name = ?", "jinzhu").First(&user)

func WithCallbacks Uses

func WithCallbacks(db *gorm.DB, opts ...Option) *gorm.DB

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.

func WithContext Uses

func WithContext(ctx context.Context, db *gorm.DB) *gorm.DB

WithContext attaches the specified context to the given db. The context will be used as a basis for creating new spans. An example use case is providing a context which contains a span to be used as a parent.

type Option Uses

type Option func(*config)

Option represents an option that can be passed to Register, Open or OpenDB.

func WithAnalytics Uses

func WithAnalytics(on bool) Option

WithAnalytics enables Trace Analytics for all started spans.

func WithAnalyticsRate Uses

func WithAnalyticsRate(rate float64) Option

WithAnalyticsRate sets the sampling rate for Trace Analytics events correlated to started spans.

func WithServiceName Uses

func WithServiceName(name string) Option

WithServiceName sets the given service name when registering a driver, or opening a database connection.

Package gorm imports 9 packages (graph). Updated 2020-08-05. Refresh now. Tools for package owners.