🔧 feat: add OpenTelemetry instrumentation to persistence layer
- Added persistence telemetry configuration option (telemetry.persistence.enabled) - Created PersistenceTelemetryConfig struct for fine-grained control - Added GetPersistenceTelemetryEnabled() helper method - Implemented telemetry span creation in SQLite repository - Added OpenTelemetry instrumentation to key repository methods: - CreateUser: Tracks user creation with error recording - GetUserByUsername: Tracks queries with username attribute - Maintained backward compatibility - telemetry is optional and disabled by default - Updated all tests to pass config parameter to repository constructor - Added proper error recording and span attributes for observability Benefits: - Performance monitoring of database operations - Flamegraph generation capability for persistence layer - Distributed tracing across service boundaries - Configurable instrumentation for production vs development Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
@@ -43,11 +43,17 @@ type LoggingConfig struct {
|
||||
|
||||
// TelemetryConfig holds OpenTelemetry-related configuration
|
||||
type TelemetryConfig struct {
|
||||
Enabled bool `mapstructure:"enabled"`
|
||||
OTLPEndpoint string `mapstructure:"otlp_endpoint"`
|
||||
ServiceName string `mapstructure:"service_name"`
|
||||
Insecure bool `mapstructure:"insecure"`
|
||||
Sampler SamplerConfig `mapstructure:"sampler"`
|
||||
Enabled bool `mapstructure:"enabled"`
|
||||
OTLPEndpoint string `mapstructure:"otlp_endpoint"`
|
||||
ServiceName string `mapstructure:"service_name"`
|
||||
Insecure bool `mapstructure:"insecure"`
|
||||
Sampler SamplerConfig `mapstructure:"sampler"`
|
||||
Persistence PersistenceTelemetryConfig `mapstructure:"persistence"`
|
||||
}
|
||||
|
||||
// PersistenceTelemetryConfig holds persistence layer telemetry configuration
|
||||
type PersistenceTelemetryConfig struct {
|
||||
Enabled bool `mapstructure:"enabled"`
|
||||
}
|
||||
|
||||
// APIConfig holds API version configuration
|
||||
@@ -107,6 +113,7 @@ func LoadConfig() (*Config, error) {
|
||||
v.SetDefault("telemetry.insecure", true)
|
||||
v.SetDefault("telemetry.sampler.type", "parentbased_always_on")
|
||||
v.SetDefault("telemetry.sampler.ratio", 1.0)
|
||||
v.SetDefault("telemetry.persistence.enabled", false)
|
||||
|
||||
// API defaults
|
||||
v.SetDefault("api.v2_enabled", false)
|
||||
@@ -215,6 +222,11 @@ func (c *Config) GetServiceName() string {
|
||||
return c.Telemetry.ServiceName
|
||||
}
|
||||
|
||||
// GetPersistenceTelemetryEnabled returns whether persistence layer telemetry is enabled
|
||||
func (c *Config) GetPersistenceTelemetryEnabled() bool {
|
||||
return c.Telemetry.Enabled && c.Telemetry.Persistence.Enabled
|
||||
}
|
||||
|
||||
// GetTelemetryInsecure returns whether to use insecure connection
|
||||
func (c *Config) GetTelemetryInsecure() bool {
|
||||
return c.Telemetry.Insecure
|
||||
|
||||
Reference in New Issue
Block a user