gorm

package
v0.0.0-...-869dfa3 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Overview

Package gorm provides an OpenTelemetry instrumentation for the GORM library.

More information: https://github.com/go-gorm/opentelemetry

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Logger

func Logger(log xlog.Logger, slow uint) glog.Interface

Logger returns a GORM log handler that uses the provided base logger to report operations. The `slow` parameter can be used to define the threshold to tag slow operations in ms; if not provided a default value of 200 will be used.

func Open

func Open(driver, conn string) (*sql.DB, error)

Open provides a wrapper around the standard sql.Open function to enable SQL commenter instrumentation. When used with GORM the returned `*sql.DB` instance can be used as `gorm.ConnPool`

More information: https://google.github.io/sqlcommenter/go/database_sql/

func Plugin

func Plugin(opts ...Option) gorm.Plugin

Plugin can be used to instrument any application using GORM. To register the plugin symply call `db.Use`.

plg := otelGorm.Plugin(otelGorm.WithIgnoredError(context.Canceled))
db.Use(plg)

Types

type Option

type Option func(p *plugin)

Option defines a function that configures the plugin behavior.

func WithAttributes

func WithAttributes(attrs map[string]interface{}) Option

WithAttributes register additional attributes that will be used when creating spans.

func WithDBName

func WithDBName(name string) Option

WithDBName configures a db.name attribute.

func WithIgnoredError

func WithIgnoredError(errors ...error) Option

WithIgnoredError registered errors that should be ignored by the plugin when reporting spans. This is useful to avoid unnecessary reports for common errors like "record not found" or "no rows".

func WithQueryFormatter

func WithQueryFormatter(queryFormatter func(query string) string) Option

WithQueryFormatter configures a query formatter.

func WithoutMetrics

func WithoutMetrics() Option

WithoutMetrics prevents DBStats metrics from being reported.

func WithoutQueryVariables

func WithoutQueryVariables() Option

WithoutQueryVariables configures the db.statement attribute to exclude query variables.

Jump to

Keyboard shortcuts

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