tracer

package
v0.0.0-...-edb1025 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package tracer provides a GORM plugin for distributed tracing using OpenTelemetry.

The tracer plugin creates OpenTelemetry spans for each database operation, recording SQL queries, table names, operation types, and errors as span attributes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Plugin

type Plugin struct {
	// contains filtered or unexported fields
}

Plugin is the GORM tracer plugin.

func New

func New(tracer trace.Tracer) *Plugin

New creates a new tracer plugin.

The tracer parameter should be an OpenTelemetry trace.Tracer. If nil, a default tracer from the global provider will be used.

Example:

import (
    "go.opentelemetry.io/otel"
    tracerplugin "github.com/codesjoy/pkg/basic/xgorm/plugin/tracer"
)

tracer := otel.Tracer("gorm")
tracerPlugin := tracerplugin.New(tracer)
db.Use(tracerPlugin)

func (*Plugin) Initialize

func (p *Plugin) Initialize(db *gorm.DB) error

Initialize registers before/after callbacks for each GORM operation type (create, query, update, delete, raw, row) so that spans are started before execution and ended after execution.

func (*Plugin) Name

func (p *Plugin) Name() string

Name returns the name of the plugin.

Jump to

Keyboard shortcuts

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