Documentation
¶
Overview ¶
Package otelx wraps OpenTelemetry trace setup with configuration from config so the rest of the service doesn't need to know about OTel's surface area.
Settings are loaded via config.GetConfig().OpenTelemetry (or config.Setup). Tracing is disabled when OTEL_TRACES_EXPORTER=otlp and OTLP endpoint is empty. Set OTEL_TRACES_EXPORTER=gcp to export directly to Google Cloud Trace via ADC.
Index ¶
- func GORMEnabled(cfg config.OpenTelemetryConfiguration) bool
- func Init(ctx context.Context, cfg config.OpenTelemetryConfiguration) (func(context.Context) error, bool)
- func LoadConfig() config.OpenTelemetryConfiguration
- func RegisterGORM(db *gorm.DB, opts GORMOptions) error
- func TracingEnabled(cfg config.OpenTelemetryConfiguration) bool
- type GORMOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GORMEnabled ¶
func GORMEnabled(cfg config.OpenTelemetryConfiguration) bool
GORMEnabled reports whether GORM instrumentation should be registered from config.
func Init ¶
func Init(ctx context.Context, cfg config.OpenTelemetryConfiguration) (func(context.Context) error, bool)
Init configures the global OpenTelemetry TracerProvider. Returns a shutdown function and a boolean (enabled). When tracing is not configured we report "off" and proceed silently; when configured but invalid we log and treat as "off".
func LoadConfig ¶
func LoadConfig() config.OpenTelemetryConfiguration
LoadConfig returns OpenTelemetry settings from the global config package.
func RegisterGORM ¶
func RegisterGORM(db *gorm.DB, opts GORMOptions) error
RegisterGORM installs the official GORM OpenTelemetry plugin on db. Call after otelx.Init so spans use the configured TracerProvider.
func TracingEnabled ¶
func TracingEnabled(cfg config.OpenTelemetryConfiguration) bool
TracingEnabled reports whether tracing export is configured.
Types ¶
type GORMOptions ¶
type GORMOptions struct {
// DBSystem sets the db.system semantic convention (e.g. mysql, postgresql).
DBSystem string
// Metrics enables DB pool metrics from the plugin. Default false (tracing only).
Metrics bool
}
GORMOptions configures OpenTelemetry instrumentation for a *gorm.DB instance.