🔧 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:
@@ -6,17 +6,31 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"dance-lessons-coach/pkg/config"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// createTestConfig creates a test configuration with telemetry disabled
|
||||
func createTestConfig() *config.Config {
|
||||
return &config.Config{
|
||||
Telemetry: config.TelemetryConfig{
|
||||
Enabled: false,
|
||||
Persistence: config.PersistenceTelemetryConfig{
|
||||
Enabled: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func TestSQLiteRepository(t *testing.T) {
|
||||
t.Run("CRUD operations", func(t *testing.T) {
|
||||
// Create a temporary database
|
||||
dbPath := "test_db.sqlite"
|
||||
defer os.Remove(dbPath)
|
||||
|
||||
repo, err := NewSQLiteRepository(dbPath)
|
||||
cfg := createTestConfig()
|
||||
repo, err := NewSQLiteRepository(dbPath, cfg)
|
||||
require.NoError(t, err)
|
||||
defer repo.Close()
|
||||
|
||||
@@ -92,7 +106,8 @@ func TestAuthService(t *testing.T) {
|
||||
dbPath := "test_auth_db.sqlite"
|
||||
defer os.Remove(dbPath)
|
||||
|
||||
repo, err := NewSQLiteRepository(dbPath)
|
||||
cfg := createTestConfig()
|
||||
repo, err := NewSQLiteRepository(dbPath, cfg)
|
||||
require.NoError(t, err)
|
||||
defer repo.Close()
|
||||
|
||||
@@ -162,7 +177,8 @@ func TestPasswordResetService(t *testing.T) {
|
||||
dbPath := "test_reset_db.sqlite"
|
||||
defer os.Remove(dbPath)
|
||||
|
||||
repo, err := NewSQLiteRepository(dbPath)
|
||||
cfg := createTestConfig()
|
||||
repo, err := NewSQLiteRepository(dbPath, cfg)
|
||||
require.NoError(t, err)
|
||||
defer repo.Close()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user