Skip to content

Commit

Permalink
fix: log database connections from go runtime (#3253)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvmakine authored Oct 31, 2024
1 parent 3039a2e commit e6c0b2f
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions go-runtime/ftl/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"go.opentelemetry.io/otel/attribute"
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"

"github.com/TBD54566975/ftl/internal/log"
"github.com/TBD54566975/ftl/internal/modulecontext"
)

Expand All @@ -28,11 +29,15 @@ func PostgresDatabase(name string) Database {
Name: name,
DBType: modulecontext.DBTypePostgres,
db: once.Once(func(ctx context.Context) (*sql.DB, error) {
logger := log.FromContext(ctx)

provider := modulecontext.FromContext(ctx).CurrentContext()
dsn, err := provider.GetDatabase(name, modulecontext.DBTypePostgres)
if err != nil {
return nil, fmt.Errorf("failed to get database %q: %w", name, err)
}

logger.Debugf("Opening database: %s", name)
db, err := otelsql.Open("pgx", dsn)
if err != nil {
return nil, fmt.Errorf("failed to open database %q: %w", name, err)
Expand Down

0 comments on commit e6c0b2f

Please sign in to comment.