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 ¶
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 ¶
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.