splunkgorm

package module
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: Apache-2.0 Imports: 2 Imported by: 1

README

Splunk Instrumentation for github.com/jinzhu/gorm

Go Reference

This package provides instrumentation for the github.com/jinzhu/gorm package. The instrumentation is provided by wrapping the splunksql instrumentation.

Getting Started

To start using this instrumentation, replace the use of the gorm.Open function Open from this package. The returned *gorm.DB can then be use as normal with the gorm package.

An example of this can be found here.

Documentation

Overview

Package splunkgorm provides instrumentation for the github.com/jinzhu/gorm package.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open

func Open(driverName, dataSourceName string, opts ...splunksql.Option) (*gorm.DB, error)

Open opens a traced gorm database connection specified by its database driver name and a driver-specific data source name. The driver must already be registered by the driver package.

Example
package main

import (
	"log"

	"github.com/jinzhu/gorm"

	"github.com/signalfx/splunk-otel-go/instrumentation/github.com/jinzhu/gorm/splunkgorm"
)

func main() {
	// This assumes the instrumented driver,
	// "github.com/signalfx/splunk-otel-go/instrumentation/github.com/jackc/pgx/splunkpgx",
	// is imported. That will ensure the driver and the instrumentation setup
	// for the driver are registered with the appropriate packages.
	db, err := splunkgorm.Open("pgx", "postgres://localhost/db")
	if err != nil {
		log.Fatal(err)
	}
	defer func() {
		if err := db.Close(); err != nil {
			log.Printf("failed to close db: %v", err)
		}
	}()

	user := struct {
		gorm.Model
		Name string
	}{}

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

Types

This section is empty.

Jump to

Keyboard shortcuts

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