instagorm

package module
v1.10.1 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: MIT Imports: 4 Imported by: 0

README

Instana instrumentation for gorm

This module provides Instana instrumentation for database operations using gorm library.

GoDoc

Installation

To add the module to your go.mod file run the following command in your project directory:

$ go get github.com/instana/go-sensor/instrumentation/instagorm

Usage

// create a sensor
sensor := instana.NewSensor("gorm-sensor")

dsn := "<relevant DSN information for the database>"

// example here uses sqlite driver
db, err := gorm.Open(sqlite.Open(dsn), &gorm.Config{})

// instrument the GORM database handle
instagorm.Instrument(db, sensor, dsn)

...

Documentation

Overview

Package instagorm provides instrumentation for the gorm library.

Example
// (c) Copyright IBM Corp. 2023

//go:build go1.18
// +build go1.18

package main

import (
	instana "github.com/instana/go-sensor"
	"github.com/instana/go-sensor/instrumentation/instagorm"
	"gorm.io/driver/sqlite"
	"gorm.io/gorm"
)

func main() {
	s := instana.NewSensor("go-sensor-gorm")

	dsn := "<DSN information for database>"

	db, err := gorm.Open(sqlite.Open(dsn), &gorm.Config{})
	if err != nil {
		panic("failed to connect database")
	}

	instagorm.Instrument(db, s, dsn)

	if err = db.AutoMigrate(&student{}); err != nil {
		panic("failed to migrate the schema")
	}

	db.Create(&student{Name: "Alex", RollNumber: 32})
}

type student struct {
	gorm.Model
	Name       string
	RollNumber uint
}
Output:

Index

Examples

Constants

View Source
const Version = "1.10.1"

Version is the instrumentation module semantic version

Variables

This section is empty.

Functions

func Instrument

func Instrument(db *gorm.DB, s instana.TracerLogger, dsn string)

Instrument adds instrumentation for the specified gorm database instance.

Types

This section is empty.

Jump to

Keyboard shortcuts

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