gorm

package module
v0.0.0-...-97eb9a2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 3, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

README

gorm <github.com/Heer0/gorm>

Package gorm provides a means of instrumenting GORM database operations.

To trace GORM operations, import the appropriate apmgorm/dialects package (instead of the gorm/dialects package), and use apmgorm.Open (instead of gorm.Open). The parameters are exactly the same.

Once you have a *gorm.DB from apmgorm.Open, you can call apmgorm.WithContext to propagate a context containing a transaction to the operations:

import (
    apmgorm "github.com/Heer0/gorm"
    _ "github.com/Heer0/gorm/dialects/mysql"
)

func main() {
	db, err := apmgorm.Open("mysql", "")
	...
	db = apmgorm.WithContext(ctx, db)
	db.Find(...) // creates a "SELECT FROM <foo>" span
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open

func Open(dialect string, args ...interface{}) (*gorm.DB, error)

Open returns a *gorm.DB for the given dialect and arguments. The returned *gorm.DB will have callbacks registered with RegisterCallbacks, such that CRUD operations will be reported as spans.

Open accepts the following signatures:

  • a datasource name (i.e. the second argument to sql.Open)
  • a driver name and a datasource name
  • a *sql.DB, or some other type with the same interface

If a driver and datasource name are supplied, and the appropriate apmgorm/dialects package has been imported (or the driver has otherwise been registered with apmsql), then the datasource name will be parsed for inclusion in the span context.

func RegisterCallbacks

func RegisterCallbacks(db *gorm.DB)

RegisterCallbacks registers callbacks on db for reporting spans to Elastic APM. This is called automatically by apmgorm.Open; it is provided for cases where a *gorm.DB is acquired by other means.

func WithContext

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

WithContext returns a copy of db with ctx recorded for use by the callbacks registered via RegisterCallbacks.

Types

This section is empty.

Directories

Path Synopsis
dialects

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL